3 //=============================================================================
7 * @author Darrell Brunsch <brunsch@uci.edu>
9 //=============================================================================
14 #include "ace/config-macros.h"
16 #if !defined (ACE_LACKS_PRAGMA_ONCE)
18 #endif /* ACE_LACKS_PRAGMA_ONCE */
20 #if defined (ACE_HAS_XPG4_MULTIBYTE_CHAR)
21 # if !defined (ACE_HAS_WCHAR)
22 # define ACE_HAS_WCHAR
24 # include /**/ <wchar.h>
25 #endif /* ACE_HAS_XPG4_MULTIBYTE_CHAR */
27 #if defined (ACE_HAS_WCHAR)
28 # if defined (ACE_VXWORKS)
29 # include /**/ <types/vxTypes.h> /* For wchar_t */
30 # include /**/ <stdlib.h> /* For mbstowcs, etc. */
31 # include /**/ <string.h> /* For strlen */
32 # if !defined (__RTP__)
33 # define wint_t unsigned int /* VxWorks has wchar_t but not wint_t */
35 # include /**/ <wchar.h>
36 # include /**/ <wctype.h>
38 # elif defined (ACE_OPENVMS)
39 # include /**/ <wchar.h>
40 # include /**/ <wctype.h>
41 # elif defined (ACE_HAS_STANDARD_CPP_LIBRARY) && \
42 (ACE_HAS_STANDARD_CPP_LIBRARY != 0)
43 # include /**/ <cwchar>
44 # include /**/ <cwctype>
45 # elif defined (ACE_HAS_WINCE)
46 # include /**/ <wtypes.h>
48 # include /**/ <wchar.h>
49 # endif /* ACE_HAS_STANDARD_CPP_LIBRARY */
50 #endif /* ACE_HAS_WCHAR */
52 #if defined (ACE_HAS_ICONV)
53 # include /**/ <iconv.h>
54 # if !defined (ACE_MAX_ICONV_BUFFER)
55 # define ACE_MAX_ICONV_BUFFER 16*1024
57 #endif /* ACE_HAS_ICONV */
59 #if defined (ACE_USES_STD_NAMESPACE_FOR_STDC_LIB) && \
60 (ACE_USES_STD_NAMESPACE_FOR_STDC_LIB != 0)
62 #endif /* ACE_USES_STD_NAMESPACE_FOR_STDC_LIB */
64 // This makes the somewhat dubious assumption that if a platform lacks
65 // a native wchar_t type, then it will typedef it as unsigned short.
66 #if defined (ACE_HAS_WCHAR) && !defined (ACE_LACKS_NATIVE_WCHAR_T)
67 # if !defined (ACE_WSTRING_HAS_USHORT_SUPPORT)
68 # define ACE_WSTRING_HAS_USHORT_SUPPORT
69 # endif /* ACE_WSTRING_HAS_USHORT_SUPPORT */
70 #endif /* ACE_HAS_WCHAR && !ACE_LACKS_NATIVE_WCHAR_T */
72 // Set the default behaviour for ACE_TEXT_WIDE to use the L-prefix
73 #if !defined (ACE_USES_L_PREFIX)
74 # define ACE_USES_L_PREFIX 1
75 #endif /* ACE_USES_L_PREFIX */
77 // Define the unicode/wchar related macros correctly
79 # if !defined (ACE_TEXT_WIDE)
80 # if (ACE_USES_L_PREFIX == 1)
81 # define ACE_TEXT_WIDE_I(STRING) L##STRING
82 # else /* ACE_USES_L_PREFIX */
83 # define ACE_TEXT_WIDE_I(STRING) STRING
84 # endif /* ACE_USES_L_PREFIX */
85 # define ACE_TEXT_WIDE(STRING) ACE_TEXT_WIDE_I (STRING)
86 # endif /* ACE_TEXT_WIDE */
88 #if defined (ACE_USES_WCHAR)
89 typedef wchar_t ACE_TCHAR
;
90 typedef char ACE_ANTI_TCHAR
;
91 # define ACE_TEXT(STRING) ACE_TEXT_WIDE (STRING)
92 # define ACE_TEXT_ALWAYS_CHAR(STRING) ACE_Wide_To_Ascii (STRING).char_rep ()
93 # define ACE_TEXT_ALWAYS_WCHAR(STRING) STRING
94 # define ACE_TEXT_CHAR_TO_TCHAR(STRING) ACE_Ascii_To_Wide (STRING).wchar_rep ()
95 # define ACE_TEXT_WCHAR_TO_TCHAR(STRING) STRING
96 # define ACE_TEXT_ANTI_TO_TCHAR(STRING) ACE_Ascii_To_Wide (STRING).wchar_rep ()
97 #else /* ACE_USES_WCHAR */
98 typedef char ACE_TCHAR
;
99 typedef wchar_t ACE_ANTI_TCHAR
;
100 # define ACE_TEXT(STRING) STRING
101 # define ACE_TEXT_ALWAYS_CHAR(STRING) STRING
102 # define ACE_TEXT_ALWAYS_WCHAR(STRING) ACE_Ascii_To_Wide (STRING).wchar_rep ()
103 # define ACE_TEXT_CHAR_TO_TCHAR(STRING) STRING
104 # define ACE_TEXT_WCHAR_TO_TCHAR(STRING) ACE_Wide_To_Ascii (STRING).char_rep ()
105 # define ACE_TEXT_ANTI_TO_TCHAR(STRING) ACE_Wide_To_Ascii (STRING).char_rep ()
106 #endif /* ACE_USES_WCHAR */
108 // The OS_String module defines some wide-char functions that are not
109 // universally available. In particular, they're not part of the
110 // XPG4 Worldwide Portability Interface wide-character string handling
111 // functions. So, if ACE_HAS_XPG4_MULTIBYTE_CHAR is defined, note that
112 // these functions are missing.
113 #if defined (ACE_HAS_XPG4_MULTIBYTE_CHAR)
115 # if !defined (ACE_LACKS_ITOW)
116 # define ACE_LACKS_ITOW
119 # if !defined (ACE_LACKS_WCSICMP)
120 # define ACE_LACKS_WCSICMP
123 # if !defined (ACE_LACKS_WCSNICMP)
124 # define ACE_LACKS_WCSNICMP
127 # if !defined (ACE_LACKS_WCSDUP)
128 # define ACE_LACKS_WCSDUP
131 #endif /* ACE_HAS_XPG4_MULTIBYTE_CHAR */
133 #if defined ACE_HAS_WCHAR
135 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
138 * @class ACE_Wide_To_Ascii
140 * @brief A lightweight wchar* to char* string conversion class.
142 * The purpose of this class is to perform conversion from
143 * wchar* to char* strings. It is not intended for general
146 class ACE_Wide_To_Ascii
149 /// Constructor must take a wchar string.
150 ACE_Wide_To_Ascii (const wchar_t *s
);
152 /// Destructor will free up the memory.
153 ~ACE_Wide_To_Ascii (void);
155 /// Return the internal char* representation.
156 char *char_rep (void);
158 /// Converts an wchar_t string to ascii and returns a new string.
159 static char *convert (const wchar_t *wstr
);
162 /// Internal pointer to the converted string.
165 #if defined (ACE_HAS_ICONV)
166 static iconv_t ACE_Wide_To_Ascii_iconv_env
;
167 #endif /* ACE_HAS_ICONV */
169 /// Disallow these operation.
170 ACE_Wide_To_Ascii (void);
171 ACE_Wide_To_Ascii (ACE_Wide_To_Ascii
&);
172 ACE_Wide_To_Ascii
& operator= (ACE_Wide_To_Ascii
&);
176 * @class ACE_Ascii_To_Wide
178 * @brief A lightweight char* to wchar* string conversion class.
180 * The purpose of this class is to perform conversion from
181 * char* to wchar* strings. It is not intended for general
184 class ACE_Ascii_To_Wide
187 /// Constructor must take a wchar string.
188 ACE_Ascii_To_Wide (const char *s
);
190 /// Destructor will free up the memory.
191 ~ACE_Ascii_To_Wide (void);
193 /// Return the internal wchar* representation.
194 wchar_t *wchar_rep (void);
196 /// Converts an char string to unicode/wide and returns a new string.
197 static wchar_t *convert (const char *str
);
200 /// Internal pointer to the converted string.
203 #if defined (ACE_HAS_ICONV)
204 static iconv_t ACE_Ascii_To_Wide_iconv_env
;
205 #endif /* ACE_HAS_ICONV */
207 /// Disallow these operation.
208 ACE_Ascii_To_Wide (void);
209 ACE_Ascii_To_Wide (ACE_Ascii_To_Wide
&);
210 ACE_Ascii_To_Wide
operator= (ACE_Ascii_To_Wide
&);
213 ACE_END_VERSIONED_NAMESPACE_DECL
215 #endif /* ACE_HAS_WCHAR */
217 #if defined (ACE_WIN32)
218 #if defined (ACE_USES_WCHAR)
219 #define ACE_LPSTR LPWSTR
220 #define ACE_TEXT_SERVICE_TABLE_ENTRY SERVICE_TABLE_ENTRYW
221 #define ACE_TEXT_STARTUPINFO STARTUPINFOW
222 #define ACE_TEXT_WIN32_FIND_DATA WIN32_FIND_DATAW
223 #define ACE_TEXT_OSVERSIONINFO OSVERSIONINFOW
224 #define ACE_TEXT_EXPLICIT_ACCESS EXPLICIT_ACCESS_W
226 #define ACE_TEXT_CreateEvent ::CreateEventW
227 #define ACE_TEXT_CreateFile ::CreateFileW
228 #define ACE_TEXT_CreateFileMapping ::CreateFileMappingW
229 #define ACE_TEXT_CreateMutex ::CreateMutexW
230 #define ACE_TEXT_CreateProcess ::CreateProcessW
231 #define ACE_TEXT_CreateProcessAsUser ::CreateProcessAsUserW
232 #define ACE_TEXT_CreateSemaphore ::CreateSemaphoreW
233 #define ACE_TEXT_CreateService ::CreateServiceW
234 #define ACE_TEXT_ExpandEnvironmentStrings ::ExpandEnvironmentStringsW
235 #define ACE_TEXT_FindFirstChangeNotification ::FindFirstChangeNotificationW
236 #define ACE_TEXT_FindFirstFile ::FindFirstFileW
237 #define ACE_TEXT_FindNextFile ::FindNextFileW
238 #define ACE_TEXT_FormatMessage ::FormatMessageW
239 #define ACE_TEXT_FreeEnvironmentStrings ::FreeEnvironmentStringsW
240 #define ACE_TEXT_GetComputerName ::GetComputerNameW
241 #define ACE_TEXT_GetEnvironmentStrings ::GetEnvironmentStringsW
242 #define ACE_TEXT_GetFileAttributes ::GetFileAttributesW
243 #define ACE_TEXT_GetModuleFileName ::GetModuleFileNameW
244 #define ACE_TEXT_GetTempPath ::GetTempPathW
245 #define ACE_TEXT_GetUserName ::GetUserNameW
246 #define ACE_TEXT_GetUserNameEx ::GetUserNameExW
247 #define ACE_TEXT_GetVersionEx ::GetVersionExW
248 #define ACE_TEXT_LoadLibrary ::LoadLibraryW
249 #define ACE_TEXT_MoveFileEx ::MoveFileExW
250 #define ACE_TEXT_WaitNamedPipe ::WaitNamedPipeW
251 #define ACE_TEXT_OpenFileMapping ::OpenFileMappingW
252 #define ACE_TEXT_OpenSCManager ::OpenSCManagerW
253 #define ACE_TEXT_OpenService ::OpenServiceW
254 #define ACE_TEXT_OutputDebugString ::OutputDebugStringW
255 #define ACE_TEXT_RegisterEventSource ::RegisterEventSourceW
256 #define ACE_TEXT_RegisterServiceCtrlHandler ::RegisterServiceCtrlHandlerW
257 #define ACE_TEXT_RegConnectRegistry ::RegConnectRegistryW
258 #define ACE_TEXT_RegCreateKeyEx ::RegCreateKeyExW
259 #define ACE_TEXT_RegDeleteKey ::RegDeleteKeyW
260 #define ACE_TEXT_RegDeleteValue ::RegDeleteValueW
261 #define ACE_TEXT_RegEnumKeyEx ::RegEnumKeyExW
262 #define ACE_TEXT_RegEnumValue ::RegEnumValueW
263 #define ACE_TEXT_RegCreateKey ::RegCreateKeyW
264 #define ACE_TEXT_RegOpenKey ::RegOpenKeyW
265 #define ACE_TEXT_RegOpenKeyEx ::RegOpenKeyExW
266 #define ACE_TEXT_RegQueryValueEx ::RegQueryValueExW
267 #define ACE_TEXT_RegSetValueEx ::RegSetValueExW
268 #define ACE_TEXT_ReportEvent ::ReportEventW
269 #define ACE_TEXT_SearchPath ::SearchPathW
270 #define ACE_TEXT_StartService ::StartServiceW
271 #define ACE_TEXT_StartServiceCtrlDispatcher ::StartServiceCtrlDispatcherW
272 #define ACE_TEXT_SetFileSecurity ::SetFileSecurityW
273 #define ACE_TEXT_SetEntriesInAcl ::SetEntriesInAclW
274 #define ACE_TEXT_PdhExpandCounterPath ::PdhExpandCounterPathW
275 #define ACE_TEXT_PdhOpenQuery ::PdhOpenQueryW
276 #define ACE_TEXT_PdhAddCounter ::PdhAddCounterW
277 #define ACE_TEXT_gai_strerror ::gai_strerrorW
279 #else /* ACE_USES_WCHAR */
280 #define ACE_LPSTR LPSTR
281 #define ACE_TEXT_SERVICE_TABLE_ENTRY SERVICE_TABLE_ENTRYA
282 #define ACE_TEXT_STARTUPINFO STARTUPINFOA
283 #define ACE_TEXT_WIN32_FIND_DATA WIN32_FIND_DATAA
284 #define ACE_TEXT_OSVERSIONINFO OSVERSIONINFOA
285 #define ACE_TEXT_EXPLICIT_ACCESS EXPLICIT_ACCESS_A
287 #define ACE_TEXT_CreateEvent ::CreateEventA
288 #define ACE_TEXT_CreateFile ::CreateFileA
289 #define ACE_TEXT_CreateFileMapping ::CreateFileMappingA
290 #define ACE_TEXT_CreateMutex ::CreateMutexA
291 #define ACE_TEXT_CreateProcess ::CreateProcessA
292 #define ACE_TEXT_CreateProcessAsUser ::CreateProcessAsUserA
293 #define ACE_TEXT_CreateSemaphore ::CreateSemaphoreA
294 #define ACE_TEXT_CreateService ::CreateServiceA
295 #define ACE_TEXT_ExpandEnvironmentStrings ::ExpandEnvironmentStringsA
296 #define ACE_TEXT_FindFirstChangeNotification ::FindFirstChangeNotificationA
297 #define ACE_TEXT_FindFirstFile ::FindFirstFileA
298 #define ACE_TEXT_FindNextFile ::FindNextFileA
299 #define ACE_TEXT_FormatMessage ::FormatMessageA
300 #define ACE_TEXT_FreeEnvironmentStrings ::FreeEnvironmentStringsA
301 #define ACE_TEXT_GetComputerName ::GetComputerNameA
302 #define ACE_TEXT_GetEnvironmentStrings ::GetEnvironmentStringsA
303 #define ACE_TEXT_GetFileAttributes ::GetFileAttributesA
304 #define ACE_TEXT_GetModuleFileName ::GetModuleFileNameA
305 #define ACE_TEXT_GetTempPath ::GetTempPathA
306 #define ACE_TEXT_GetUserName ::GetUserNameA
307 #define ACE_TEXT_GetUserNameEx ::GetUserNameExA
308 #define ACE_TEXT_GetVersionEx ::GetVersionExA
309 #define ACE_TEXT_LoadLibrary ::LoadLibraryA
310 #define ACE_TEXT_MoveFileEx ::MoveFileExA
311 #define ACE_TEXT_WaitNamedPipe ::WaitNamedPipeA
312 #define ACE_TEXT_OpenFileMapping ::OpenFileMappingA
313 #define ACE_TEXT_OpenSCManager ::OpenSCManagerA
314 #define ACE_TEXT_OpenService ::OpenServiceA
315 #define ACE_TEXT_OutputDebugString ::OutputDebugStringA
316 #define ACE_TEXT_RegisterEventSource ::RegisterEventSourceA
317 #define ACE_TEXT_RegisterServiceCtrlHandler ::RegisterServiceCtrlHandlerA
318 #define ACE_TEXT_RegConnectRegistry ::RegConnectRegistryA
319 #define ACE_TEXT_RegCreateKeyEx ::RegCreateKeyExA
320 #define ACE_TEXT_RegDeleteKey ::RegDeleteKeyA
321 #define ACE_TEXT_RegDeleteValue ::RegDeleteValueA
322 #define ACE_TEXT_RegEnumKeyEx ::RegEnumKeyExA
323 #define ACE_TEXT_RegEnumValue ::RegEnumValueA
324 #define ACE_TEXT_RegCreateKey ::RegCreateKeyA
325 #define ACE_TEXT_RegOpenKey ::RegOpenKeyA
326 #define ACE_TEXT_RegOpenKeyEx ::RegOpenKeyExA
327 #define ACE_TEXT_RegQueryValueEx ::RegQueryValueExA
328 #define ACE_TEXT_RegSetValueEx ::RegSetValueExA
329 #define ACE_TEXT_ReportEvent ::ReportEventA
330 #define ACE_TEXT_SearchPath ::SearchPathA
331 #define ACE_TEXT_StartService ::StartServiceA
332 #define ACE_TEXT_StartServiceCtrlDispatcher ::StartServiceCtrlDispatcherA
333 #define ACE_TEXT_SetFileSecurity ::SetFileSecurityA
334 #define ACE_TEXT_SetEntriesInAcl ::SetEntriesInAclA
335 #define ACE_TEXT_PdhExpandCounterPath ::PdhExpandCounterPathA
336 #define ACE_TEXT_PdhOpenQuery ::PdhOpenQueryA
337 #define ACE_TEXT_PdhAddCounter ::PdhAddCounterA
338 #define ACE_TEXT_gai_strerror ::gai_strerrorA
339 #endif /* ACE_USES_WCHAR */
340 #endif /* ACE_WIN32 */
342 #include "ace/ace_wchar.inl"
344 #endif /* ACE_WCHAR_H */