[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / dep / ACE_wrappers / ace / OS_NS_string.inl
blob8b9d15f30ac024e51ac3e9b6a2513b1edfa63eb0
1 // -*- C++ -*-
2 //
3 // $Id: OS_NS_string.inl 80826 2008-03-04 14:51:23Z wotte $
5 // OS_NS_wchar.h is only needed to get the emulation methods.
6 // Perhaps they should be moved.  dhinton
7 #include "ace/OS_NS_wchar.h"
8 #include "ace/os_include/os_string.h"
10 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
12 ACE_INLINE const void *
13 ACE_OS::memchr (const void *s, int c, size_t len)
15 #if !defined (ACE_LACKS_MEMCHR)
16   return ::memchr (s, c, len);
17 #else /* ACE_LACKS_MEMCHR */
18   return ACE_OS::memchr_emulation (s, c, len);
19 #endif /* !ACE_LACKS_MEMCHR */
22 ACE_INLINE void *
23 ACE_OS::memchr (void *s, int c, size_t len)
25   return const_cast<void *> (ACE_OS::memchr (static_cast<const void *> (s),
26                                              c,
27                                              len));
30 ACE_INLINE int
31 ACE_OS::memcmp (const void *t, const void *s, size_t len)
33   return ::memcmp (t, s, len);
36 ACE_INLINE void *
37 ACE_OS::memcpy (void *t, const void *s, size_t len)
39 #if defined (ACE_HAS_MEMCPY_LOOP_UNROLL)
40   return fast_memcpy (t, s, len);
41 #else
42   return ::memcpy (t, s, len);
43 #endif /* ACE_HAS_MEMCPY_LOOP_UNROLL */
46 ACE_INLINE void *
47 ACE_OS::memmove (void *t, const void *s, size_t len)
49   return ::memmove (t, s, len);
52 ACE_INLINE void *
53 ACE_OS::memset (void *s, int c, size_t len)
55 #if defined (ACE_HAS_SLOW_MEMSET)
56   // This section requires a high optimization level (-xO4 with SunCC)
57   // in order to actually be inlined.
58   char* ptr = static_cast<char*> (s);
59   switch (len)
60     {
61     case 16:
62       ptr[15] = c;
63     case 15:
64       ptr[14] = c;
65     case 14:
66       ptr[13] = c;
67     case 13:
68       ptr[12] = c;
69     case 12:
70       ptr[11] = c;
71     case 11:
72       ptr[10] = c;
73     case 10:
74       ptr[9] = c;
75     case 9:
76       ptr[8] = c;
77     case 8:
78       ptr[7] = c;
79     case 7:
80       ptr[6] = c;
81     case 6:
82       ptr[5] = c;
83     case 5:
84       ptr[4] = c;
85     case 4:
86       ptr[3] = c;
87     case 3:
88       ptr[2] = c;
89     case 2:
90       ptr[1] = c;
91     case 1:
92       ptr[0] = c;
93       break;
94     default:
95       for (size_t i = 0; i < len; ++i)
96         {
97           ptr[i] = c;
98         }
99     }
101   return s;
102 #else
103   return ::memset (s, c, len);
104 #endif /* ACE_HAS_SLOW_MEMSET */
107 ACE_INLINE char *
108 ACE_OS::strcat (char *s, const char *t)
110   return ::strcat (s, t);
113 #if defined (ACE_HAS_WCHAR)
114 ACE_INLINE wchar_t *
115 ACE_OS::strcat (wchar_t *s, const wchar_t *t)
117 #  if defined (ACE_LACKS_WCSCAT)
118   return ACE_OS::wcscat_emulation (s, t);
119 #  else /* ACE_LACKS_WCSCAT */
120   return ::wcscat (s, t);
121 #  endif /* ACE_LACKS_WCSCAT */
123 #endif /* ACE_HAS_WCHAR */
125 ACE_INLINE const char *
126 ACE_OS::strchr (const char *s, int c)
128   return const_cast <const char *> (::strchr (s, c));
131 #if defined (ACE_HAS_WCHAR)
132 ACE_INLINE const wchar_t *
133 ACE_OS::strchr (const wchar_t *s, wchar_t c)
135 #  if defined (ACE_LACKS_WCSCHR)
136   return ACE_OS::wcschr_emulation (s, c);
137 #  else /* ACE_LACKS_WCSCHR */
138   return ::wcschr (s, c);
139 #  endif /* ACE_LACKS_WCSCHR */
141 #endif /* ACE_HAS_WCHAR */
143 ACE_INLINE char *
144 ACE_OS::strchr (char *s, int c)
146   return ::strchr (s, c);
149 #if defined (ACE_HAS_WCHAR)
150 ACE_INLINE wchar_t *
151 ACE_OS::strchr (wchar_t *s, wchar_t c)
153   return
154     const_cast<wchar_t *> (ACE_OS::strchr (const_cast<const wchar_t *> (s),
155                                            c));
157 #endif /* ACE_HAS_WCHAR */
159 ACE_INLINE int
160 ACE_OS::strcmp (const char *s, const char *t)
162   return ::strcmp (s, t);
165 ACE_INLINE int
166 ACE_OS::strcmp (const ACE_WCHAR_T *s, const ACE_WCHAR_T *t)
168 #  if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSCMP)
169   return ACE_OS::wcscmp_emulation (s, t);
170 #  else /* !ACE_HAS_WCHAR || ACE_LACKS_WCSCMP */
171   return ::wcscmp (s, t);
172 #  endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSCMP */
175 ACE_INLINE char *
176 ACE_OS::strcpy (char *s, const char *t)
178   return ::strcpy (s, t);
181 #if defined (ACE_HAS_WCHAR)
182 ACE_INLINE wchar_t *
183 ACE_OS::strcpy (wchar_t *s, const wchar_t *t)
185 #  if defined (ACE_LACKS_WCSCPY)
186   return ACE_OS::wcscpy_emulation (s, t);
187 #  else /* ACE_LACKS_WCSCPY */
188   return ::wcscpy (s, t);
189 #  endif /* ACE_LACKS_WCSCPY */
191 #endif /* ACE_HAS_WCHAR */
193 ACE_INLINE size_t
194 ACE_OS::strcspn (const char *s, const char *reject)
196   return ::strcspn (s, reject);
199 #if defined (ACE_HAS_WCHAR)
200 ACE_INLINE size_t
201 ACE_OS::strcspn (const wchar_t *s, const wchar_t *reject)
203 #  if defined (ACE_LACKS_WCSCSPN)
204   return ACE_OS::wcscspn_emulation (s, reject);
205 #  else /* ACE_LACKS_WCSCSPN */
206   return ::wcscspn (s, reject);
207 #  endif /* ACE_LACKS_WCSCSPN */
209 #endif /* ACE_HAS_WCHAR */
211 ACE_INLINE char *
212 ACE_OS::strdup (const char *s)
214 #  if (defined (ACE_LACKS_STRDUP) && !defined(ACE_STRDUP_EQUIVALENT)) \
215   || defined (ACE_HAS_STRDUP_EMULATION)
216   return ACE_OS::strdup_emulation (s);
217 #  elif defined (ACE_STRDUP_EQUIVALENT)
218   return ACE_STRDUP_EQUIVALENT (s);
219 #  elif defined (ACE_HAS_NONCONST_STRDUP)
220   return ::strdup (const_cast<char *> (s));
221 #else
222   return ::strdup (s);
223 #  endif /* (ACE_LACKS_STRDUP && !ACE_STRDUP_EQUIVALENT) || ... */
226 #if defined (ACE_HAS_WCHAR)
227 ACE_INLINE wchar_t *
228 ACE_OS::strdup (const wchar_t *s)
230 #  if (defined (ACE_LACKS_WCSDUP) && !defined (ACE_WCSDUP_EQUIVALENT)) \
231   || defined (ACE_HAS_WCSDUMP_EMULATION)
232   return ACE_OS::strdup_emulation (s);
233 #  elif defined (ACE_WCSDUP_EQUIVALENT)
234   return ACE_WCSDUP_EQUIVALENT (s);
235 #  elif defined (ACE_HAS_NONCONST_WCSDUP)
236   return ::wcsdup (const_cast<wchar_t*> (s));
237 #  else
238   return ::wcsdup (s);
239 #  endif /* (ACE_LACKS_WCSDUP && !ACE_WCSDUP_EQUIVALENT) || ... */
241 #endif /* ACE_HAS_WCHAR */
243 ACE_INLINE size_t
244 ACE_OS::strlen (const char *s)
246   return ::strlen (s);
249 ACE_INLINE size_t
250 ACE_OS::strlen (const ACE_WCHAR_T *s)
252 # if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSLEN)
253   return ACE_OS::wcslen_emulation (s);
254 # else  /* !ACE_HAS_WCHAR || ACE_LACKS_WCSLEN */
255   return ::wcslen (s);
256 # endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSLEN */
259 ACE_INLINE char *
260 ACE_OS::strncat (char *s, const char *t, size_t len)
262 #if 0 /* defined (ACE_HAS_TR24731_2005_CRT) */
263   strncat_s (s, len + 1, t, _TRUNCATE);
264   return s;
265 #else
266   return ::strncat (s, t, len);
267 #endif /* ACE_HAS_TR24731_2005_CRT */
270 ACE_INLINE ACE_WCHAR_T *
271 ACE_OS::strncat (ACE_WCHAR_T *s, const ACE_WCHAR_T *t, size_t len)
273 #  if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSNCAT)
274   return ACE_OS::wcsncat_emulation (s, t, len);
275 #  elif 0 /* defined (ACE_HAS_TR24731_2005_CRT) */
276   wcsncat_s (s, len + 1, t, _TRUNCATE);
277   return s;
278 #  else /* !ACE_HAS_WCHAR || ACE_LACKS_WCSNCAT */
279   return ::wcsncat (s, t, len);
280 #  endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSNCAT */
283 ACE_INLINE char *
284 ACE_OS::strnchr (char *s, int c, size_t len)
286   return const_cast<char *> (ACE_OS::strnchr (static_cast<const char *> (s),
287                                               c,
288                                               len));
291 ACE_INLINE ACE_WCHAR_T *
292 ACE_OS::strnchr (ACE_WCHAR_T *s, ACE_WCHAR_T c, size_t len)
294   return
295     const_cast<ACE_WCHAR_T *> (ACE_OS::strnchr (
296                                  const_cast<const ACE_WCHAR_T *> (s),
297                                  c,
298                                  len));
301 ACE_INLINE int
302 ACE_OS::strncmp (const char *s, const char *t, size_t len)
304   return ::strncmp (s, t, len);
307 ACE_INLINE int
308 ACE_OS::strncmp (const ACE_WCHAR_T *s, const ACE_WCHAR_T *t, size_t len)
310 #  if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSNCMP)
311   return ACE_OS::wcsncmp_emulation (s, t, len);
312 #  else /* !ACE_HAS_WCHAR || ACE_LACKS_WCSNCMP */
313   return ::wcsncmp (s, t, len);
314 #  endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSNCMP */
317 ACE_INLINE char *
318 ACE_OS::strncpy (char *s, const char *t, size_t len)
320   return ::strncpy (s, t, len);
323 ACE_INLINE ACE_WCHAR_T *
324 ACE_OS::strncpy (ACE_WCHAR_T *s, const ACE_WCHAR_T *t, size_t len)
326 #  if !defined (ACE_HAS_WCHAR) || defined (ACE_LACKS_WCSNCPY)
327   return ACE_OS::wcsncpy_emulation (s, t, len);
328 #  else /* !ACE_HAS_WCHAR || ACE_LACKS_WCSNCPY */
329   return ::wcsncpy (s, t, len);
330 #  endif /* !ACE_HAS_WCHAR || ACE_LACKS_WCSNCPY */
333 ACE_INLINE size_t
334 ACE_OS::strnlen (const char *s, size_t maxlen)
336 #if defined (ACE_HAS_STRNLEN)
337   return ::strnlen (s, maxlen);
338 #else /* ACE_HAS_STRNLEN */
339   size_t i;
340   for (i = 0; i < maxlen; ++i)
341     if (s[i] == '\0')
342       break;
343   return i;
344 #endif /* ACE_HAS_STRNLEN */
347 ACE_INLINE size_t
348 ACE_OS::strnlen (const ACE_WCHAR_T *s, size_t maxlen)
350 #if defined (ACE_HAS_WCHAR) && defined (ACE_HAS_WCSNLEN)
351   return wcsnlen (s, maxlen);
352 #else /* ACE_HAS_WCSNLEN */
353   size_t i;
354   for (i = 0; i < maxlen; ++i)
355     if (s[i] == '\0')
356       break;
357   return i;
358 #endif /* ACE_HAS_WCSNLEN */
361 ACE_INLINE char *
362 ACE_OS::strnstr (char *s, const char *t, size_t len)
364   return
365     const_cast <char *> (ACE_OS::strnstr (const_cast <const char *> (s), t, len));
368 ACE_INLINE ACE_WCHAR_T *
369 ACE_OS::strnstr (ACE_WCHAR_T *s, const ACE_WCHAR_T *t, size_t len)
371   return
372     const_cast<ACE_WCHAR_T *> (ACE_OS::strnstr (
373                                  static_cast<const ACE_WCHAR_T *> (s),
374                                  t,
375                                  len));
378 ACE_INLINE const char *
379 ACE_OS::strpbrk (const char *s1, const char *s2)
381   return const_cast <const char *> (::strpbrk (s1, s2));
384 #if defined (ACE_HAS_WCHAR)
385 ACE_INLINE const wchar_t *
386 ACE_OS::strpbrk (const wchar_t *s, const wchar_t *t)
388 #  if defined (ACE_LACKS_WCSPBRK)
389   return ACE_OS::wcspbrk_emulation (s, t);
390 #  else /* ACE_LACKS_WCSPBRK */
391   return ::wcspbrk (s, t);
392 #  endif /* ACE_LACKS_WCSPBRK */
394 #endif /* ACE_HAS_WCHAR */
396 ACE_INLINE char *
397 ACE_OS::strpbrk (char *s1, const char *s2)
399   return ::strpbrk (s1, s2);
402 #if defined (ACE_HAS_WCHAR)
403 ACE_INLINE wchar_t *
404 ACE_OS::strpbrk (wchar_t *s, const wchar_t *t)
406   return const_cast<wchar_t *> (ACE_OS::strpbrk (
407                                   const_cast<const wchar_t *> (s), t));
409 #endif /* ACE_HAS_WCHAR */
411 ACE_INLINE const char *
412 ACE_OS::strrchr (const char *s, int c)
414 #if defined (ACE_LACKS_STRRCHR)
415   return ACE_OS::strrchr_emulation (s, c);
416 #else  /* ! ACE_LACKS_STRRCHR */
417   return (const char *) ::strrchr (s, c);
418 #endif /* ! ACE_LACKS_STRRCHR */
421 #if defined (ACE_HAS_WCHAR)
422 ACE_INLINE const wchar_t *
423 ACE_OS::strrchr (const wchar_t *s, wchar_t c)
425 #if defined (ACE_LACKS_WCSRCHR)
426   return ACE_OS::wcsrchr_emulation (s, c);
427 #else /* ! ACE_LACKS_WCSRCHR */
428   return const_cast <const wchar_t *> (::wcsrchr (s, c));
429 #endif /* ! ACE_LACKS_WCSRCHR */
431 #endif /* ACE_HAS_WCHAR */
433 ACE_INLINE char *
434 ACE_OS::strrchr (char *s, int c)
436 #if defined (ACE_LACKS_STRRCHR)
437   return ACE_OS::strrchr_emulation (s, c);
438 #else  /* ! ACE_LACKS_STRRCHR */
439   return ::strrchr (s, c);
440 #endif /* ! ACE_LACKS_STRRCHR */
443 #if defined (ACE_HAS_WCHAR)
444 ACE_INLINE wchar_t *
445 ACE_OS::strrchr (wchar_t *s, wchar_t c)
447   return const_cast<wchar_t *> (ACE_OS::strrchr (
448                      const_cast<const wchar_t *> (s), c));
450 #endif /* ACE_HAS_WCHAR */
452 ACE_INLINE size_t
453 ACE_OS::strspn (const char *s, const char *t)
455   return ::strspn (s, t);
458 #if defined (ACE_HAS_WCHAR)
459 ACE_INLINE size_t
460 ACE_OS::strspn (const wchar_t *s, const wchar_t *t)
462 #  if defined (ACE_LACKS_WCSSPN)
463   return ACE_OS::wcsspn_emulation (s, t);
464 #  else /* ACE_LACKS_WCSSPN */
465   return ::wcsspn (s, t);
466 #  endif /* ACE_LACKS_WCSSPN */
468 #endif /* ACE_HAS_WCHAR */
470 ACE_INLINE const char *
471 ACE_OS::strstr (const char *s, const char *t)
473   return (const char *) ::strstr (s, t);
476 #if defined (ACE_HAS_WCHAR)
477 ACE_INLINE const wchar_t *
478 ACE_OS::strstr (const wchar_t *s, const wchar_t *t)
480 #  if defined (ACE_LACKS_WCSSTR)
481   return ACE_OS::wcsstr_emulation (s, t);
482 #  elif defined (HPUX)
483   return const_cast <const wchar_t *> (::wcswcs (s, t));
484 #  else /* ACE_LACKS_WCSSTR */
485   return const_cast <const wchar_t *> (::wcsstr (s, t));
486 #  endif /* ACE_LACKS_WCSSTR */
488 #endif /* ACE_HAS_WCHAR */
490 ACE_INLINE char *
491 ACE_OS::strstr (char *s, const char *t)
493   return ::strstr (s, t);
496 #if defined (ACE_HAS_WCHAR)
497 ACE_INLINE wchar_t *
498 ACE_OS::strstr (wchar_t *s, const wchar_t *t)
500 #  if defined (ACE_LACKS_WCSSTR)
501   return ACE_OS::wcsstr_emulation (s, t);
502 #  elif defined (HPUX)
503   return ::wcswcs (s, t);
504 #  else /* ACE_LACKS_WCSSTR */
505   return ::wcsstr (s, t);
506 #  endif /* ACE_LACKS_WCSSTR */
508 #endif /* ACE_HAS_WCHAR */
510 ACE_INLINE char *
511 ACE_OS::strtok (char *s, const char *tokens)
513   return ::strtok (s, tokens);
516 #if defined (ACE_HAS_WCHAR) && !defined (ACE_LACKS_WCSTOK)
517 ACE_INLINE wchar_t *
518 ACE_OS::strtok (wchar_t *s, const wchar_t *tokens)
520 #if defined (ACE_HAS_3_PARAM_WCSTOK)
521   static wchar_t *lasts = 0;
522   return ::wcstok (s, tokens, &lasts);
523 #else
524   return ::wcstok (s, tokens);
525 #endif /* ACE_HAS_3_PARAM_WCSTOK */
527 #endif /* ACE_HAS_WCHAR && !ACE_LACKS_WCSTOK */
529 ACE_INLINE char *
530 ACE_OS::strtok_r (char *s, const char *tokens, char **lasts)
532 #if defined (ACE_HAS_TR24731_2005_CRT)
533   return strtok_s (s, tokens, lasts);
534 #elif defined (ACE_HAS_REENTRANT_FUNCTIONS) && !defined (ACE_LACKS_STRTOK_R)
535   return ::strtok_r (s, tokens, lasts);
536 #else
537   return ACE_OS::strtok_r_emulation (s, tokens, lasts);
538 #endif /* (ACE_HAS_REENTRANT_FUNCTIONS) */
541 #if defined (ACE_HAS_WCHAR)
542 ACE_INLINE wchar_t*
543 ACE_OS::strtok_r (ACE_WCHAR_T *s, const ACE_WCHAR_T *tokens, ACE_WCHAR_T **lasts)
545 #if defined (ACE_HAS_TR24731_2005_CRT)
546   return wcstok_s (s, tokens, lasts);
547 #elif defined (ACE_LACKS_WCSTOK)
548   return ACE_OS::strtok_r_emulation (s, tokens, lasts);
549 #else
550 #  if defined (ACE_HAS_3_PARAM_WCSTOK)
551   return ::wcstok (s, tokens, lasts);
552 #  else /* ACE_HAS_3_PARAM_WCSTOK */
553   *lasts = ::wcstok (s, tokens);
554   return *lasts;
555 #  endif /* ACE_HAS_3_PARAM_WCSTOK */
556 #endif  /* ACE_LACKS_WCSTOK */
558 #endif  // ACE_HAS_WCHAR
560 ACE_END_VERSIONED_NAMESPACE_DECL