Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / OS_NS_wchar.cpp
blob5d8e684be3831fb9cff11ca26183d0054665ed53
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:
13 /*-
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
22 * are met:
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
46 * SUCH DAMAGE.
49 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
51 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSCAT)
52 wchar_t *
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++));
60 return save;
62 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSCAT */
64 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSCHR)
65 wchar_t *
66 ACE_OS::wcschr_emulation (const wchar_t *string, wchar_t c)
68 for (;*string ; ++string)
69 if (*string == c)
70 return const_cast<wchar_t *> (string);
72 return 0;
74 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSCHR */
76 #if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSCMP)
77 int
78 ACE_OS::wcscmp_emulation (const ACE_WCHAR_T *string1,
79 const ACE_WCHAR_T *string2)
81 while (*string1 == *string2++)
82 if (*string1++ == 0)
83 return 0;
84 return (*string1 - *--string2);
86 #endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSCMP */
88 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSCPY)
89 wchar_t *
90 ACE_OS::wcscpy_emulation (wchar_t *destination,
91 const wchar_t *source)
93 wchar_t *save = destination;
95 for (; (*destination = *source); ++source, ++destination);
96 return save;
98 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSCPY */
100 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSCSPN)
101 size_t
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;
106 int count = 0;
108 for (scan = s; *scan; scan++)
110 for (rej_scan = reject; *rej_scan; rej_scan++)
111 if (*scan == *rej_scan)
112 return count;
114 count++;
117 return count;
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;
128 while (*scan1 != 0
129 && ACE_OS::ace_towlower (*scan1)
130 == ACE_OS::ace_towlower (*scan2))
132 ++scan1;
133 ++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')
141 return 0;
142 else if (*scan1 == '\0')
143 return -1;
144 else if (*scan2 == '\0')
145 return 1;
146 else
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)
152 size_t
153 ACE_OS::wcslen_emulation (const ACE_WCHAR_T *string)
155 const ACE_WCHAR_T *s = 0;
157 for (s = string; *s; ++s)
158 continue;
160 return s - string;
162 #endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSLEN */
164 #if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSNCAT)
165 ACE_WCHAR_T *
166 ACE_OS::wcsncat_emulation (ACE_WCHAR_T *destination,
167 const ACE_WCHAR_T *source,
168 size_t count)
170 if (count != 0)
172 ACE_WCHAR_T *d = destination;
173 const ACE_WCHAR_T *s = source;
175 while (*d != 0)
176 ++d;
180 if ((*d = *s++) == 0)
181 break;
183 ++d;
184 } while (--count != 0);
186 *d = 0;
189 return destination;
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,
197 size_t len)
199 if (len == 0)
200 return 0;
204 if (*s1 != *s2++)
205 return (*s1 - *--s2);
206 if (*s1++ == 0)
207 break;
208 } while (--len != 0);
210 return 0;
212 #endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSNCMP */
214 #if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSNCPY)
215 ACE_WCHAR_T *
216 ACE_OS::wcsncpy_emulation (ACE_WCHAR_T *destination,
217 const ACE_WCHAR_T *source,
218 size_t len)
220 if (len != 0)
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
230 while (--len != 0)
231 *d++ = 0;
232 break;
234 } while (--len != 0);
237 return destination;
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,
244 const wchar_t *t,
245 size_t len)
247 const wchar_t *scan1 = s;
248 const wchar_t *scan2 = t;
249 size_t count = 0;
251 while (count++ < len
252 && *scan1 != 0
253 && ACE_OS::ace_towlower (*scan1)
254 == ACE_OS::ace_towlower (*scan2))
256 ++scan1;
257 ++scan2;
260 if (count > len)
261 return 0;
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')
268 return 0;
269 else if (*scan1 == '\0')
270 return -1;
271 else if (*scan2 == '\0')
272 return 1;
273 else
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)
279 wchar_t *
280 ACE_OS::wcspbrk_emulation (const wchar_t *string,
281 const wchar_t *charset)
283 const wchar_t *scanp = 0;
284 int c, sc;
286 while ((c = *string++) != 0)
288 for (scanp = charset; (sc = *scanp++) != 0;)
289 if (sc == c)
290 return const_cast<wchar_t *> (string - 1);
293 return 0;
295 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSPBRK */
297 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSRCHR)
298 const wchar_t *
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))
304 if (p == s)
305 return 0;
306 else
307 p--;
309 return p;
312 wchar_t *
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))
318 if (p == s)
319 return 0;
320 else
321 p--;
323 return p;
325 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSRCHR */
327 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSSPN)
328 size_t
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;
334 wchar_t c, sc;
336 // Skip any characters in charset, excluding the terminating \0.
337 cont:
338 c = *p++;
339 for (spanp = charset; (sc = *spanp++) != 0;)
340 if (sc == c)
341 goto cont;
342 return (p - 1 - string);
344 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSSPN */
346 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSSTR)
347 wchar_t *
348 ACE_OS::wcsstr_emulation (const wchar_t *string,
349 const wchar_t *charset)
351 wchar_t c, sc;
352 size_t len;
354 if ((c = *charset++) != 0)
356 len = ACE_OS::strlen (charset);
361 if ((sc = *string++) == 0)
362 return 0;
363 } while (sc != c);
364 } while (ACE_OS::strncmp (string, charset, len) != 0);
365 string--;
368 return const_cast<wchar_t *> (string);
370 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSSTR */
372 ACE_END_VERSIONED_NAMESPACE_DECL