2 // These are always inlined
3 // FUZZ: disable check_for_inline
5 #if defined (ACE_HAS_WCHAR)
7 #if !defined (ACE_WIN32)
8 # include /**/ <string.h> // Need to see strlen()
11 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
14 ACE_Wide_To_Ascii::~ACE_Wide_To_Ascii ()
20 ACE_Wide_To_Ascii::char_rep ()
26 ACE_Wide_To_Ascii::convert (const wchar_t *wstr)
28 // Short circuit null pointer case
32 # if defined (ACE_WIN32)
33 UINT const cp = GetACP (); // Codepage
34 int const len = ::WideCharToMultiByte (cp,
42 # elif defined (ACE_LACKS_WCSLEN)
43 const wchar_t * wtemp = wstr;
44 while ((*wtemp) != 0) // Hopefully the string is null terminated!
47 size_t const len = wtemp - wstr + 1;
48 # else /* ACE_WIN32 */
49 size_t const len = ::wcslen (wstr) + 1;
50 # endif /* ACE_WIN32 */
52 #if !defined (ACE_HAS_ICONV)
53 char *str = new char[len];
56 # if defined (ACE_WIN32)
57 ::WideCharToMultiByte (cp, 0, wstr, -1, str, len, 0, 0);
58 # elif defined (ACE_VXWORKS)
59 ::wcstombs (str, wstr, len);
60 # elif defined (ACE_HAS_ICONV)
61 wchar_t * wstri = const_cast<wchar_t*> (wstr);
62 size_t lensi = ACE_MAX_ICONV_BUFFER;
63 size_t lenwi = len * sizeof(wchar_t);
64 char buf[ACE_MAX_ICONV_BUFFER];
67 size_t hr = iconv (ACE_Wide_To_Ascii_iconv_env, (char**)&wstri, &lenwi, &stri, &lensi);
68 if ((hr==size_t(-1))||(lensi==ACE_MAX_ICONV_BUFFER))
70 char *str=new char[len];
71 for (size_t i = 0; i < len; i++)
73 wchar_t *t = const_cast <wchar_t *> (wstr);
74 str[i] = static_cast<char> (*(t + i));
79 char *str = new char[ACE_MAX_ICONV_BUFFER-lensi];
80 ::memcpy(str, buf, ACE_MAX_ICONV_BUFFER-lensi);
81 # else /* ACE_HAS_ICONV */
82 for (size_t i = 0; i < len; ++i)
84 wchar_t *t = const_cast <wchar_t *> (wstr);
85 str[i] = static_cast<char> (*(t + i));
87 # endif /* ACE_WIN32 */
92 ACE_Wide_To_Ascii::ACE_Wide_To_Ascii (const wchar_t *s)
94 #if defined(ACE_HAS_ICONV)
95 if (ACE_Wide_To_Ascii_iconv_env == 0)
97 ACE_Wide_To_Ascii_iconv_env = iconv_open("", "WCHAR_T");
100 s_ = ACE_Wide_To_Ascii::convert (s);
104 ACE_Ascii_To_Wide::~ACE_Ascii_To_Wide ()
110 ACE_Ascii_To_Wide::wchar_rep ()
116 ACE_Ascii_To_Wide::convert (const char *str)
118 // Short circuit null pointer case
122 # if defined (ACE_WIN32)
123 UINT const cp = GetACP (); // Codepage
124 int const len = ::MultiByteToWideChar (cp, 0, str, -1, 0, 0);
125 # else /* ACE_WIN32 */
126 size_t const len = strlen (str) + 1;
127 # endif /* ACE_WIN32 */
129 #if !defined (ACE_HAS_ICONV)
130 wchar_t *wstr = new wchar_t[len];
133 # if defined (ACE_WIN32)
134 ::MultiByteToWideChar (cp, 0, str, -1, wstr, len);
135 # elif defined (ACE_VXWORKS)
136 ::mbstowcs (wstr, str, len);
137 # elif defined (ACE_HAS_ICONV) /* ACE_VXWORKS */
138 char *stri = const_cast<char*>(str);
140 size_t lenwi = ACE_MAX_ICONV_BUFFER;
141 wchar_t buf[ACE_MAX_ICONV_BUFFER/sizeof(wchar_t)];
144 size_t hr=iconv(ACE_Ascii_To_Wide_iconv_env, &stri, &lensi, (char**)&wstri, &lenwi);
145 if((hr==size_t(-1))||(lenwi==ACE_MAX_ICONV_BUFFER)){
146 wchar_t *wstr=new wchar_t[len*sizeof(wchar_t)];
147 for (size_t i = 0; i < len; i++){
148 char *t = const_cast<char *> (str);
149 wstr[i] = static_cast<wchar_t> (*((unsigned char*)t + i));
154 wchar_t *wstr=new wchar_t[(ACE_MAX_ICONV_BUFFER-lenwi)/sizeof(wchar_t)];
155 ::memcpy(wstr,buf,ACE_MAX_ICONV_BUFFER-lenwi);
156 # else /* ACE_HAS_ICONV */
157 for (size_t i = 0; i < len; ++i)
159 char *t = const_cast<char *> (str);
160 wstr[i] = static_cast<wchar_t> (*((unsigned char*)(t + i)));
162 # endif /* ACE_WIN32 */
167 ACE_Ascii_To_Wide::ACE_Ascii_To_Wide (const char *s)
169 #if defined(ACE_HAS_ICONV)
170 if (ACE_Ascii_To_Wide_iconv_env == 0)
172 ACE_Ascii_To_Wide_iconv_env = iconv_open("WCHAR_T", "");
175 s_ = ACE_Ascii_To_Wide::convert (s);
178 ACE_END_VERSIONED_NAMESPACE_DECL
180 #endif /* ACE_HAS_WCHAR */