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
++)
110 for (rej_scan
= reject
; *rej_scan
; rej_scan
++)
111 if (*scan
== *rej_scan
)
119 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSCSPN */
121 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSICMP)
123 ACE_OS::wcsicmp_emulation (const wchar_t *s
, const wchar_t *t
)
125 const wchar_t *scan1
= s
;
126 const wchar_t *scan2
= t
;
129 && ACE_OS::ace_towlower (*scan1
)
130 == ACE_OS::ace_towlower (*scan2
))
136 // The following case analysis is necessary so that characters which
137 // look negative collate low against normal characters but high
138 // against the end-of-string NUL.
140 if (*scan1
== '\0' && *scan2
== '\0')
142 else if (*scan1
== '\0')
144 else if (*scan2
== '\0')
147 return ACE_OS::ace_tolower (*scan1
) - ACE_OS::ace_towlower (*scan2
);
149 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSICMP */
151 #if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSLEN)
153 ACE_OS::wcslen_emulation (const ACE_WCHAR_T
*string
)
155 const ACE_WCHAR_T
*s
= 0;
157 for (s
= string
; *s
; ++s
)
162 #endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSLEN */
164 #if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSNCAT)
166 ACE_OS::wcsncat_emulation (ACE_WCHAR_T
*destination
,
167 const ACE_WCHAR_T
*source
,
172 ACE_WCHAR_T
*d
= destination
;
173 const ACE_WCHAR_T
*s
= source
;
180 if ((*d
= *s
++) == 0)
184 } while (--count
!= 0);
191 #endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSCAT */
193 #if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSNCMP)
195 ACE_OS::wcsncmp_emulation (const ACE_WCHAR_T
*s1
,
196 const ACE_WCHAR_T
*s2
,
205 return (*s1
- *--s2
);
208 } while (--len
!= 0);
212 #endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSNCMP */
214 #if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSNCPY)
216 ACE_OS::wcsncpy_emulation (ACE_WCHAR_T
*destination
,
217 const ACE_WCHAR_T
*source
,
222 ACE_WCHAR_T
*d
= destination
;
223 const ACE_WCHAR_T
*s
= source
;
227 if ((*d
++ = *s
++) == 0)
229 // NUL pad the remaining n-1 bytes
234 } while (--len
!= 0);
239 #endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSNCPY */
241 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSNICMP)
243 ACE_OS::wcsnicmp_emulation (const wchar_t *s
,
247 const wchar_t *scan1
= s
;
248 const wchar_t *scan2
= t
;
253 && ACE_OS::ace_towlower (*scan1
)
254 == ACE_OS::ace_towlower (*scan2
))
263 // The following case analysis is necessary so that characters which
264 // look negative collate low against normal characters but high
265 // against the end-of-string NUL.
267 if (*scan1
== '\0' && *scan2
== '\0')
269 else if (*scan1
== '\0')
271 else if (*scan2
== '\0')
274 return ACE_OS::ace_towlower (*scan1
) - ACE_OS::ace_towlower (*scan2
);
276 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSNICMP */
278 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSPBRK)
280 ACE_OS::wcspbrk_emulation (const wchar_t *string
,
281 const wchar_t *charset
)
283 const wchar_t *scanp
= 0;
286 while ((c
= *string
++) != 0)
288 for (scanp
= charset
; (sc
= *scanp
++) != 0;)
290 return const_cast<wchar_t *> (string
- 1);
295 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSPBRK */
297 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSRCHR)
299 ACE_OS::wcsrchr_emulation (const wchar_t *s
, wint_t c
)
301 const wchar_t *p
= s
+ ACE_OS::strlen (s
);
303 while (*p
!= static_cast<wchar_t> (c
))
313 ACE_OS::wcsrchr_emulation (wchar_t *s
, wint_t c
)
315 wchar_t *p
= s
+ ACE_OS::strlen (s
);
317 while (*p
!= static_cast<wchar_t> (c
))
325 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSRCHR */
327 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSSPN)
329 ACE_OS::wcsspn_emulation (const wchar_t *string
,
330 const wchar_t *charset
)
332 const wchar_t *p
= string
;
333 const wchar_t *spanp
= 0;
336 // Skip any characters in charset, excluding the terminating \0.
339 for (spanp
= charset
; (sc
= *spanp
++) != 0;)
342 return (p
- 1 - string
);
344 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSSPN */
346 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSSTR)
348 ACE_OS::wcsstr_emulation (const wchar_t *string
,
349 const wchar_t *charset
)
354 if ((c
= *charset
++) != 0)
356 len
= ACE_OS::strlen (charset
);
361 if ((sc
= *string
++) == 0)
364 } while (ACE_OS::strncmp (string
, charset
, len
) != 0);
368 return const_cast<wchar_t *> (string
);
370 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSSTR */
372 ACE_END_VERSIONED_NAMESPACE_DECL