00001
00002
00003 #include "ace/OS_NS_wchar.h"
00004
00005 ACE_RCSID(ace, OS_NS_wchar, "$Id: OS_NS_wchar.cpp 76543 2007-01-24 12:33:06Z johnnyw $")
00006
00007 #if !defined (ACE_HAS_INLINED_OSCALLS)
00008 # include "ace/OS_NS_wchar.inl"
00009 #endif
00010
00011 #if defined (ACE_HAS_WCHAR)
00012 # include "ace/OS_NS_ctype.h"
00013 # include "ace/OS_NS_string.h"
00014 #endif
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00054
00055 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSCAT)
00056 wchar_t *
00057 ACE_OS::wcscat_emulation (wchar_t *destination,
00058 const wchar_t *source)
00059 {
00060 wchar_t *save = destination;
00061
00062 for (; *destination; ++destination);
00063 while ((*destination++ = *source++));
00064 return save;
00065 }
00066 #endif
00067
00068 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSCHR)
00069 wchar_t *
00070 ACE_OS::wcschr_emulation (const wchar_t *string, wchar_t c)
00071 {
00072 for (;*string ; ++string)
00073 if (*string == c)
00074 return const_cast<wchar_t *> (string);
00075
00076 return 0;
00077 }
00078 #endif
00079
00080 #if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSCMP)
00081 int
00082 ACE_OS::wcscmp_emulation (const ACE_WCHAR_T *string1,
00083 const ACE_WCHAR_T *string2)
00084 {
00085 while (*string1 == *string2++)
00086 if (*string1++ == 0)
00087 return (0);
00088 return (*string1 - *--string2);
00089 }
00090 #endif
00091
00092 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSCPY)
00093 wchar_t *
00094 ACE_OS::wcscpy_emulation (wchar_t *destination,
00095 const wchar_t *source)
00096 {
00097 wchar_t *save = destination;
00098
00099 for (; (*destination = *source); ++source, ++destination);
00100 return save;
00101 }
00102 #endif
00103
00104 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSCSPN)
00105 size_t
00106 ACE_OS::wcscspn_emulation (const wchar_t *s, const wchar_t *reject)
00107 {
00108 const wchar_t *scan = 0;
00109 const wchar_t *rej_scan = 0;
00110 int count = 0;
00111
00112 for (scan = s; *scan; scan++)
00113 {
00114
00115 for (rej_scan = reject; *rej_scan; rej_scan++)
00116 if (*scan == *rej_scan)
00117 return count;
00118
00119 count++;
00120 }
00121
00122 return count;
00123 }
00124 #endif
00125
00126 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSICMP)
00127 int
00128 ACE_OS::wcsicmp_emulation (const wchar_t *s, const wchar_t *t)
00129 {
00130 const wchar_t *scan1 = s;
00131 const wchar_t *scan2 = t;
00132
00133 while (*scan1 != 0
00134 && ACE_OS::ace_towlower (*scan1)
00135 == ACE_OS::ace_towlower (*scan2))
00136 {
00137 ++scan1;
00138 ++scan2;
00139 }
00140
00141
00142
00143
00144
00145 if (*scan1 == '\0' && *scan2 == '\0')
00146 return 0;
00147 else if (*scan1 == '\0')
00148 return -1;
00149 else if (*scan2 == '\0')
00150 return 1;
00151 else
00152 return ACE_OS::ace_tolower (*scan1) - ACE_OS::ace_towlower (*scan2);
00153 }
00154 #endif
00155
00156 #if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSLEN)
00157 size_t
00158 ACE_OS::wcslen_emulation (const ACE_WCHAR_T *string)
00159 {
00160 const ACE_WCHAR_T *s;
00161
00162 for (s = string; *s; ++s)
00163 continue;
00164
00165 return s - string;
00166 }
00167 #endif
00168
00169 #if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSNCAT)
00170 ACE_WCHAR_T *
00171 ACE_OS::wcsncat_emulation (ACE_WCHAR_T *destination,
00172 const ACE_WCHAR_T *source,
00173 size_t count)
00174 {
00175 if (count != 0)
00176 {
00177 ACE_WCHAR_T *d = destination;
00178 const ACE_WCHAR_T *s = source;
00179
00180 while (*d != 0)
00181 d++;
00182
00183 do
00184 {
00185 if ((*d = *s++) == 0)
00186 break;
00187
00188 d++;
00189 } while (--count != 0);
00190
00191 *d = 0;
00192 }
00193
00194 return destination;
00195 }
00196 #endif
00197
00198 #if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSNCMP)
00199 int
00200 ACE_OS::wcsncmp_emulation (const ACE_WCHAR_T *s1,
00201 const ACE_WCHAR_T *s2,
00202 size_t len)
00203 {
00204 if (len == 0)
00205 return 0;
00206
00207 do
00208 {
00209 if (*s1 != *s2++)
00210 return (*s1 - *--s2);
00211 if (*s1++ == 0)
00212 break;
00213 } while (--len != 0);
00214
00215 return 0;
00216 }
00217 #endif
00218
00219 #if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSNCPY)
00220 ACE_WCHAR_T *
00221 ACE_OS::wcsncpy_emulation (ACE_WCHAR_T *destination,
00222 const ACE_WCHAR_T *source,
00223 size_t len)
00224 {
00225 if (len != 0)
00226 {
00227 ACE_WCHAR_T *d = destination;
00228 const ACE_WCHAR_T *s = source;
00229
00230 do
00231 {
00232 if ((*d++ = *s++) == 0)
00233 {
00234
00235 while (--len != 0)
00236 *d++ = 0;
00237 break;
00238 }
00239 } while (--len != 0);
00240 }
00241
00242 return destination;
00243 }
00244 #endif
00245
00246 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSNICMP)
00247 int
00248 ACE_OS::wcsnicmp_emulation (const wchar_t *s,
00249 const wchar_t *t,
00250 size_t len)
00251 {
00252 const wchar_t *scan1 = s;
00253 const wchar_t *scan2 = t;
00254 size_t count = 0;
00255
00256 while (count++ < len
00257 && *scan1 != 0
00258 && ACE_OS::ace_towlower (*scan1)
00259 == ACE_OS::ace_towlower (*scan2))
00260 {
00261 ++scan1;
00262 ++scan2;
00263 }
00264
00265 if (count > len)
00266 return 0;
00267
00268
00269
00270
00271
00272 if (*scan1 == '\0' && *scan2 == '\0')
00273 return 0;
00274 else if (*scan1 == '\0')
00275 return -1;
00276 else if (*scan2 == '\0')
00277 return 1;
00278 else
00279 return ACE_OS::ace_towlower (*scan1) - ACE_OS::ace_towlower (*scan2);
00280 }
00281 #endif
00282
00283 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSPBRK)
00284 wchar_t *
00285 ACE_OS::wcspbrk_emulation (const wchar_t *string,
00286 const wchar_t *charset)
00287 {
00288 const wchar_t *scanp;
00289 int c, sc;
00290
00291 while ((c = *string++) != 0)
00292 {
00293 for (scanp = charset; (sc = *scanp++) != 0;)
00294 if (sc == c)
00295 return const_cast<wchar_t *> (string - 1);
00296 }
00297
00298 return 0;
00299 }
00300 #endif
00301
00302 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSRCHR)
00303 const wchar_t *
00304 ACE_OS::wcsrchr_emulation (const wchar_t *s, wint_t c)
00305 {
00306 const wchar_t *p = s + ACE_OS::strlen (s);
00307
00308 while (*p != static_cast<wchar_t> (c))
00309 if (p == s)
00310 return 0;
00311 else
00312 p--;
00313
00314 return p;
00315 }
00316
00317 wchar_t *
00318 ACE_OS::wcsrchr_emulation (wchar_t *s, wint_t c)
00319 {
00320 wchar_t *p = s + ACE_OS::strlen (s);
00321
00322 while (*p != static_cast<wchar_t> (c))
00323 if (p == s)
00324 return 0;
00325 else
00326 p--;
00327
00328 return p;
00329 }
00330 #endif
00331
00332 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSSPN)
00333 size_t
00334 ACE_OS::wcsspn_emulation (const wchar_t *string,
00335 const wchar_t *charset)
00336 {
00337 const wchar_t *p = string;
00338 const wchar_t *spanp;
00339 wchar_t c, sc;
00340
00341
00342 cont:
00343 c = *p++;
00344 for (spanp = charset; (sc = *spanp++) != 0;)
00345 if (sc == c)
00346 goto cont;
00347 return (p - 1 - string);
00348 }
00349 #endif
00350
00351 #if defined (ACE_HAS_WCHAR) && defined (ACE_LACKS_WCSSTR)
00352 wchar_t *
00353 ACE_OS::wcsstr_emulation (const wchar_t *string,
00354 const wchar_t *charset)
00355 {
00356 wchar_t c, sc;
00357 size_t len;
00358
00359 if ((c = *charset++) != 0)
00360 {
00361 len = ACE_OS::strlen (charset);
00362 do
00363 {
00364 do
00365 {
00366 if ((sc = *string++) == 0)
00367 return 0;
00368 } while (sc != c);
00369 } while (ACE_OS::strncmp (string, charset, len) != 0);
00370 string--;
00371 }
00372
00373 return const_cast<wchar_t *> (string);
00374 }
00375 #endif
00376
00377 ACE_END_VERSIONED_NAMESPACE_DECL