Correct feature names
[ACE_TAO.git] / ACE / ace / OS_NS_wchar.cpp
blobaa914be249ba70de0e08d4248f5ccb205ddc782f
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++)
111 for (rej_scan = reject; *rej_scan; rej_scan++)
112 if (*scan == *rej_scan)
113 return count;
115 count++;
118 return count;
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;
129 while (*scan1 != 0
130 && ACE_OS::ace_towlower (*scan1)
131 == ACE_OS::ace_towlower (*scan2))
133 ++scan1;
134 ++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')
142 return 0;
143 else if (*scan1 == '\0')
144 return -1;
145 else if (*scan2 == '\0')
146 return 1;
147 else
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)
153 size_t
154 ACE_OS::wcslen_emulation (const ACE_WCHAR_T *string)
156 const ACE_WCHAR_T *s = 0;
158 for (s = string; *s; ++s)
159 continue;
161 return s - string;
163 #endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSLEN */
165 #if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSNCAT)
166 ACE_WCHAR_T *
167 ACE_OS::wcsncat_emulation (ACE_WCHAR_T *destination,
168 const ACE_WCHAR_T *source,
169 size_t count)
171 if (count != 0)
173 ACE_WCHAR_T *d = destination;
174 const ACE_WCHAR_T *s = source;
176 while (*d != 0)
177 ++d;
181 if ((*d = *s++) == 0)
182 break;
184 ++d;
185 } while (--count != 0);
187 *d = 0;
190 return destination;
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,
198 size_t len)
200 if (len == 0)
201 return 0;
205 if (*s1 != *s2++)
206 return (*s1 - *--s2);
207 if (*s1++ == 0)
208 break;
209 } while (--len != 0);
211 return 0;
213 #endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSNCMP */
215 #if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSNCPY)
216 ACE_WCHAR_T *
217 ACE_OS::wcsncpy_emulation (ACE_WCHAR_T *destination,
218 const ACE_WCHAR_T *source,
219 size_t len)
221 if (len != 0)
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
231 while (--len != 0)
232 *d++ = 0;
233 break;
235 } while (--len != 0);
238 return destination;
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,
245 const wchar_t *t,
246 size_t len)
248 const wchar_t *scan1 = s;
249 const wchar_t *scan2 = t;
250 size_t count = 0;
252 while (count++ < len
253 && *scan1 != 0
254 && ACE_OS::ace_towlower (*scan1)
255 == ACE_OS::ace_towlower (*scan2))
257 ++scan1;
258 ++scan2;
261 if (count > len)
262 return 0;
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')
269 return 0;
270 else if (*scan1 == '\0')
271 return -1;
272 else if (*scan2 == '\0')
273 return 1;
274 else
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)
280 wchar_t *
281 ACE_OS::wcspbrk_emulation (const wchar_t *string,
282 const wchar_t *charset)
284 const wchar_t *scanp = 0;
285 int c, sc;
287 while ((c = *string++) != 0)
289 for (scanp = charset; (sc = *scanp++) != 0;)
290 if (sc == c)
291 return const_cast<wchar_t *> (string - 1);
294 return 0;
296 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSPBRK */
298 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSRCHR)
299 const wchar_t *
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))
305 if (p == s)
306 return 0;
307 else
308 p--;
310 return p;
313 wchar_t *
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))
319 if (p == s)
320 return 0;
321 else
322 p--;
324 return p;
326 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSRCHR */
328 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSSPN)
329 size_t
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;
335 wchar_t c, sc;
337 // Skip any characters in charset, excluding the terminating \0.
338 cont:
339 c = *p++;
340 for (spanp = charset; (sc = *spanp++) != 0;)
341 if (sc == c)
342 goto cont;
343 return (p - 1 - string);
345 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSSPN */
347 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSSTR)
348 wchar_t *
349 ACE_OS::wcsstr_emulation (const wchar_t *string,
350 const wchar_t *charset)
352 wchar_t c, sc;
353 size_t len;
355 if ((c = *charset++) != 0)
357 len = ACE_OS::strlen (charset);
362 if ((sc = *string++) == 0)
363 return 0;
364 } while (sc != c);
365 } while (ACE_OS::strncmp (string, charset, len) != 0);
366 string--;
369 return const_cast<wchar_t *> (string);
371 #endif /* ACE_HAS_WCHAR && ACE_LACKS_WCSSTR */
373 ACE_END_VERSIONED_NAMESPACE_DECL