1 #include "ace/OS_NS_wchar.h"
3 #if !defined (ACE_HAS_INLINED_OSCALLS)
4 # include "ace/OS_NS_wchar.inl"
5 #endif /* ACE_HAS_INLINED_OSCALLS */
7 #if defined (ACE_HAS_WCHAR)
8 # include "ace/OS_NS_ctype.h"
9 # include "ace/OS_NS_string.h"
10 #endif /* ACE_HAS_WCHAR */
12 // The following wcs*_emulation methods were created based on BSD code:
14 * Copyright (c) 1991, 1993
15 * The Regents of the University of California. All rights reserved.
17 * This code is derived from software contributed to Berkeley by
18 * James W. Williams of NASA Goddard Space Flight Center.
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
23 * 1. Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 * 2. Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
28 * 3. All advertising materials mentioning features or use of this software
29 * must display the following acknowledgement:
30 * This product includes software developed by the University of
31 * California, Berkeley and its contributors.
32 * 4. Neither the name of the University nor the names of its contributors
33 * may be used to endorse or promote products derived from this software
34 * without specific prior written permission.
36 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
37 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
40 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
41 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
42 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
44 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
45 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
49 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
51 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSCAT)
53 ACE_OS::wcscat_emulation (wchar_t *destination
,
54 const wchar_t *source
)
56 wchar_t *save
= destination
;
58 for (; *destination
; ++destination
);
59 while ((*destination
++ = *source
++));
62 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSCAT */
64 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSCHR)
66 ACE_OS::wcschr_emulation (const wchar_t *string
, wchar_t c
)
68 for (;*string
; ++string
)
70 return const_cast<wchar_t *> (string
);
74 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSCHR */
76 #if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSCMP)
78 ACE_OS::wcscmp_emulation (const ACE_WCHAR_T
*string1
,
79 const ACE_WCHAR_T
*string2
)
81 while (*string1
== *string2
++)
84 return (*string1
- *--string2
);
86 #endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSCMP */
88 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSCPY)
90 ACE_OS::wcscpy_emulation (wchar_t *destination
,
91 const wchar_t *source
)
93 wchar_t *save
= destination
;
95 for (; (*destination
= *source
); ++source
, ++destination
);
98 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSCPY */
100 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSCSPN)
102 ACE_OS::wcscspn_emulation (const wchar_t *s
, const wchar_t *reject
)
104 const wchar_t *scan
= 0;
105 const wchar_t *rej_scan
= 0;
108 for (scan
= s
; *scan
; scan
++)
111 for (rej_scan
= reject
; *rej_scan
; rej_scan
++)
112 if (*scan
== *rej_scan
)
120 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSCSPN */
122 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSICMP)
124 ACE_OS::wcsicmp_emulation (const wchar_t *s
, const wchar_t *t
)
126 const wchar_t *scan1
= s
;
127 const wchar_t *scan2
= t
;
130 && ACE_OS::ace_towlower (*scan1
)
131 == ACE_OS::ace_towlower (*scan2
))
137 // The following case analysis is necessary so that characters which
138 // look negative collate low against normal characters but high
139 // against the end-of-string NUL.
141 if (*scan1
== '\0' && *scan2
== '\0')
143 else if (*scan1
== '\0')
145 else if (*scan2
== '\0')
148 return ACE_OS::ace_tolower (*scan1
) - ACE_OS::ace_towlower (*scan2
);
150 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSICMP */
152 #if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSLEN)
154 ACE_OS::wcslen_emulation (const ACE_WCHAR_T
*string
)
156 const ACE_WCHAR_T
*s
= 0;
158 for (s
= string
; *s
; ++s
)
163 #endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSLEN */
165 #if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSNCAT)
167 ACE_OS::wcsncat_emulation (ACE_WCHAR_T
*destination
,
168 const ACE_WCHAR_T
*source
,
173 ACE_WCHAR_T
*d
= destination
;
174 const ACE_WCHAR_T
*s
= source
;
181 if ((*d
= *s
++) == 0)
185 } while (--count
!= 0);
192 #endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSCAT */
194 #if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSNCMP)
196 ACE_OS::wcsncmp_emulation (const ACE_WCHAR_T
*s1
,
197 const ACE_WCHAR_T
*s2
,
206 return (*s1
- *--s2
);
209 } while (--len
!= 0);
213 #endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSNCMP */
215 #if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSNCPY)
217 ACE_OS::wcsncpy_emulation (ACE_WCHAR_T
*destination
,
218 const ACE_WCHAR_T
*source
,
223 ACE_WCHAR_T
*d
= destination
;
224 const ACE_WCHAR_T
*s
= source
;
228 if ((*d
++ = *s
++) == 0)
230 // NUL pad the remaining n-1 bytes
235 } while (--len
!= 0);
240 #endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSNCPY */
242 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSNICMP)
244 ACE_OS::wcsnicmp_emulation (const wchar_t *s
,
248 const wchar_t *scan1
= s
;
249 const wchar_t *scan2
= t
;
254 && ACE_OS::ace_towlower (*scan1
)
255 == ACE_OS::ace_towlower (*scan2
))
264 // The following case analysis is necessary so that characters which
265 // look negative collate low against normal characters but high
266 // against the end-of-string NUL.
268 if (*scan1
== '\0' && *scan2
== '\0')
270 else if (*scan1
== '\0')
272 else if (*scan2
== '\0')
275 return ACE_OS::ace_towlower (*scan1
) - ACE_OS::ace_towlower (*scan2
);
277 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSNICMP */
279 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSPBRK)
281 ACE_OS::wcspbrk_emulation (const wchar_t *string
,
282 const wchar_t *charset
)
284 const wchar_t *scanp
= 0;
287 while ((c
= *string
++) != 0)
289 for (scanp
= charset
; (sc
= *scanp
++) != 0;)
291 return const_cast<wchar_t *> (string
- 1);
296 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSPBRK */
298 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSRCHR)
300 ACE_OS::wcsrchr_emulation (const wchar_t *s
, wint_t c
)
302 const wchar_t *p
= s
+ ACE_OS::strlen (s
);
304 while (*p
!= static_cast<wchar_t> (c
))
314 ACE_OS::wcsrchr_emulation (wchar_t *s
, wint_t c
)
316 wchar_t *p
= s
+ ACE_OS::strlen (s
);
318 while (*p
!= static_cast<wchar_t> (c
))
326 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSRCHR */
328 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSSPN)
330 ACE_OS::wcsspn_emulation (const wchar_t *string
,
331 const wchar_t *charset
)
333 const wchar_t *p
= string
;
334 const wchar_t *spanp
= 0;
337 // Skip any characters in charset, excluding the terminating \0.
340 for (spanp
= charset
; (sc
= *spanp
++) != 0;)
343 return (p
- 1 - string
);
345 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSSPN */
347 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSSTR)
349 ACE_OS::wcsstr_emulation (const wchar_t *string
,
350 const wchar_t *charset
)
355 if ((c
= *charset
++) != 0)
357 len
= ACE_OS::strlen (charset
);
362 if ((sc
= *string
++) == 0)
365 } while (ACE_OS::strncmp (string
, charset
, len
) != 0);
369 return const_cast<wchar_t *> (string
);
371 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSSTR */
373 ACE_END_VERSIONED_NAMESPACE_DECL