00001
00002
00003
00004
00005
00006
00007 #if defined (ACE_HAS_WCHAR)
00008
00009 #if !defined (ACE_WIN32)
00010 # include <string.h> // Need to see strlen()
00011 #endif
00012
00013 inline
00014 ACE_Wide_To_Ascii::~ACE_Wide_To_Ascii (void)
00015 {
00016 delete [] this->s_;
00017 }
00018
00019 inline char *
00020 ACE_Wide_To_Ascii::char_rep (void)
00021 {
00022 return this->s_;
00023 }
00024
00025 inline char *
00026 ACE_Wide_To_Ascii::convert (const wchar_t *wstr)
00027 {
00028
00029 if (wstr == 0)
00030 return 0;
00031
00032 # if defined (ACE_WIN32)
00033 int len = ::WideCharToMultiByte (CP_OEMCP,
00034 0,
00035 wstr,
00036 -1,
00037 0,
00038 0,
00039 0,
00040 0);
00041 # elif defined (ACE_LACKS_WCSLEN)
00042 const wchar_t *wtemp = wstr;
00043 while (wtemp != 0)
00044 ++wtemp;
00045
00046 int len = wtemp - wstr + 1;
00047 # else
00048 int len = ::wcslen (wstr) + 1;
00049 # endif
00050
00051 char *str = new char[len];
00052
00053 # if defined (ACE_WIN32)
00054 ::WideCharToMultiByte (CP_OEMCP, 0, wstr, -1, str, len, 0, 0);
00055 # elif defined (VXWORKS)
00056 ::wcstombs (str, wstr, len);
00057 # else
00058 for (int i = 0; i < len; i++)
00059 {
00060 wchar_t *t = ACE_const_cast (wchar_t *, wstr);
00061 str[i] = ACE_static_cast (char, *(t + i));
00062 }
00063 # endif
00064 return str;
00065 }
00066
00067 inline
00068 ACE_Wide_To_Ascii::ACE_Wide_To_Ascii (const wchar_t *s)
00069 : s_ (ACE_Wide_To_Ascii::convert (s))
00070 {
00071 }
00072
00073 inline
00074 ACE_Ascii_To_Wide::~ACE_Ascii_To_Wide (void)
00075 {
00076 delete [] this->s_;
00077 }
00078
00079 inline wchar_t *
00080 ACE_Ascii_To_Wide::wchar_rep (void)
00081 {
00082 return this->s_;
00083 }
00084
00085 inline wchar_t *
00086 ACE_Ascii_To_Wide::convert (const char *str)
00087 {
00088
00089 if (str == 0)
00090 return 0;
00091
00092 # if defined (ACE_WIN32)
00093 int len = ::MultiByteToWideChar (CP_OEMCP, 0, str, -1, 0, 0);
00094 # else
00095 int len = strlen (str) + 1;
00096 # endif
00097
00098 wchar_t *wstr = new wchar_t[len];
00099
00100 # if defined (ACE_WIN32)
00101 ::MultiByteToWideChar (CP_OEMCP, 0, str, -1, wstr, len);
00102 # elif defined (VXWORKS)
00103 ::mbstowcs (wstr, str, len);
00104 # else
00105 for (int i = 0; i < len; i++)
00106 {
00107 char *t = ACE_const_cast (char *, str);
00108 wstr[i] = ACE_static_cast (wchar_t, *(t + i));
00109 }
00110 # endif
00111 return wstr;
00112 }
00113
00114 inline
00115 ACE_Ascii_To_Wide::ACE_Ascii_To_Wide (const char *s)
00116 : s_ (ACE_Ascii_To_Wide::convert (s))
00117 {
00118 }
00119
00120 #endif