ace_wchar.inl

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // ace_wchar.inl,v 4.16 2006/05/30 10:57:22 jwillemsen Exp
00004 
00005 // These are always inlined
00006 // FUZZ: disable check_for_inline
00007 
00008 #if defined (ACE_HAS_WCHAR)
00009 
00010 #if !defined (ACE_WIN32)
00011 #  include /**/ <string.h>             // Need to see strlen()
00012 #endif /* ACE_WIN32 */
00013 
00014 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00015 
00016 inline
00017 ACE_Wide_To_Ascii::~ACE_Wide_To_Ascii (void)
00018 {
00019   delete [] this->s_;
00020 }
00021 
00022 inline char *
00023 ACE_Wide_To_Ascii::char_rep (void)
00024 {
00025   return this->s_;
00026 }
00027 
00028 inline char *
00029 ACE_Wide_To_Ascii::convert (const wchar_t *wstr)
00030 {
00031   // Short circuit null pointer case
00032   if (wstr == 0)
00033     return 0;
00034 
00035 # if defined (ACE_WIN32)
00036   UINT cp = GetACP ();
00037   int len = ::WideCharToMultiByte (cp,
00038                                    0,
00039                                    wstr,
00040                                    -1,
00041                                    0,
00042                                    0,
00043                                    0,
00044                                    0);
00045 # elif defined (ACE_LACKS_WCSLEN)
00046   const wchar_t *wtemp = wstr;
00047   while (wtemp != 0)
00048     ++wtemp;
00049 
00050   int len = wtemp - wstr + 1;
00051 # else  /* ACE_WIN32 */
00052   size_t len = ::wcslen (wstr) + 1;
00053 # endif /* ACE_WIN32 */
00054 
00055   char *str = new char[len];
00056 
00057 # if defined (ACE_WIN32)
00058   ::WideCharToMultiByte (cp, 0, wstr, -1, str, len, 0, 0);
00059 # elif defined (ACE_VXWORKS)
00060   ::wcstombs (str, wstr, len);
00061 # else /* ACE_WIN32 */
00062   for (size_t i = 0; i < len; i++)
00063     {
00064       wchar_t *t = const_cast <wchar_t *> (wstr);
00065       str[i] = static_cast<char> (*(t + i));
00066     }
00067 # endif /* ACE_WIN32 */
00068   return str;
00069 }
00070 
00071 inline
00072 ACE_Wide_To_Ascii::ACE_Wide_To_Ascii (const wchar_t *s)
00073   : s_ (ACE_Wide_To_Ascii::convert (s))
00074 {
00075 }
00076 
00077 inline
00078 ACE_Ascii_To_Wide::~ACE_Ascii_To_Wide (void)
00079 {
00080   delete [] this->s_;
00081 }
00082 
00083 inline wchar_t *
00084 ACE_Ascii_To_Wide::wchar_rep (void)
00085 {
00086   return this->s_;
00087 }
00088 
00089 inline wchar_t *
00090 ACE_Ascii_To_Wide::convert (const char *str)
00091 {
00092   // Short circuit null pointer case
00093   if (str == 0)
00094     return 0;
00095 
00096 # if defined (ACE_WIN32)
00097   UINT cp = GetACP ();
00098   int len = ::MultiByteToWideChar (cp, 0, str, -1, 0, 0);
00099 # else /* ACE_WIN32 */
00100   size_t len = strlen (str) + 1;
00101 # endif /* ACE_WIN32 */
00102 
00103   wchar_t *wstr = new wchar_t[len];
00104 
00105 # if defined (ACE_WIN32)
00106   ::MultiByteToWideChar (cp, 0, str, -1, wstr, len);
00107 # elif defined (ACE_VXWORKS)
00108   ::mbstowcs (wstr, str, len);
00109 # else /* ACE_WIN32 */
00110   for (size_t i = 0; i < len; i++)
00111     {
00112       char *t = const_cast<char *> (str);
00113       wstr[i] = static_cast<wchar_t> (*((unsigned char*)(t + i)));
00114     }
00115 # endif /* ACE_WIN32 */
00116   return wstr;
00117 }
00118 
00119 inline
00120 ACE_Ascii_To_Wide::ACE_Ascii_To_Wide (const char *s)
00121   : s_ (ACE_Ascii_To_Wide::convert (s))
00122 {
00123 }
00124 
00125 ACE_END_VERSIONED_NAMESPACE_DECL
00126 
00127 #endif /* ACE_HAS_WCHAR */

Generated on Thu Nov 9 09:41:45 2006 for ACE by doxygen 1.3.6