36 #ifndef _CHAR_TRAITS_H
37 #define _CHAR_TRAITS_H 1
39 #pragma GCC system_header
45 #ifndef _GLIBCXX_STDIO_MACROS
47 # define _CHAR_TRAITS_EOF EOF
49 # define _CHAR_TRAITS_EOF (-1)
52 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
64 template<typename _CharT>
67 typedef unsigned long int_type;
70 typedef std::mbstate_t state_type;
89 template<
typename _CharT>
92 typedef _CharT char_type;
93 typedef typename _Char_types<_CharT>::int_type int_type;
95 typedef typename _Char_types<_CharT>::off_type off_type;
96 typedef typename _Char_types<_CharT>::state_type state_type;
99 assign(char_type& __c1,
const char_type& __c2)
103 eq(
const char_type& __c1,
const char_type& __c2)
104 {
return __c1 == __c2; }
107 lt(
const char_type& __c1,
const char_type& __c2)
108 {
return __c1 < __c2; }
111 compare(
const char_type* __s1,
const char_type* __s2, std::size_t __n);
114 length(
const char_type* __s);
116 static const char_type*
117 find(
const char_type* __s, std::size_t __n,
const char_type& __a);
120 move(char_type* __s1,
const char_type* __s2, std::size_t __n);
123 copy(char_type* __s1,
const char_type* __s2, std::size_t __n);
126 assign(char_type* __s, std::size_t __n, char_type __a);
129 to_char_type(
const int_type& __c)
130 {
return static_cast<char_type
>(__c); }
133 to_int_type(
const char_type& __c)
134 {
return static_cast<int_type
>(__c); }
137 eq_int_type(
const int_type& __c1,
const int_type& __c2)
138 {
return __c1 == __c2; }
142 {
return static_cast<int_type
>(_CHAR_TRAITS_EOF); }
145 not_eof(
const int_type& __c)
146 {
return !eq_int_type(__c, eof()) ? __c : to_int_type(char_type()); }
149 template<
typename _CharT>
152 compare(
const char_type* __s1,
const char_type* __s2, std::size_t __n)
154 for (std::size_t __i = 0; __i < __n; ++__i)
155 if (lt(__s1[__i], __s2[__i]))
157 else if (lt(__s2[__i], __s1[__i]))
162 template<
typename _CharT>
164 char_traits<_CharT>::
165 length(
const char_type* __p)
168 while (!eq(__p[__i], char_type()))
173 template<
typename _CharT>
174 const typename char_traits<_CharT>::char_type*
175 char_traits<_CharT>::
176 find(
const char_type* __s, std::size_t __n,
const char_type& __a)
178 for (std::size_t __i = 0; __i < __n; ++__i)
179 if (eq(__s[__i], __a))
184 template<
typename _CharT>
185 typename char_traits<_CharT>::char_type*
186 char_traits<_CharT>::
187 move(char_type* __s1,
const char_type* __s2, std::size_t __n)
189 return static_cast<_CharT*
>(__builtin_memmove(__s1, __s2,
190 __n *
sizeof(char_type)));
193 template<
typename _CharT>
194 typename char_traits<_CharT>::char_type*
195 char_traits<_CharT>::
196 copy(char_type* __s1,
const char_type* __s2, std::size_t __n)
199 std::copy(__s2, __s2 + __n, __s1);
203 template<
typename _CharT>
204 typename char_traits<_CharT>::char_type*
205 char_traits<_CharT>::
206 assign(char_type* __s, std::size_t __n, char_type __a)
213 _GLIBCXX_END_NAMESPACE
215 _GLIBCXX_BEGIN_NAMESPACE(std)
230 template<class _CharT>
239 typedef char char_type;
240 typedef int int_type;
243 typedef mbstate_t state_type;
246 assign(char_type& __c1,
const char_type& __c2)
250 eq(
const char_type& __c1,
const char_type& __c2)
251 {
return __c1 == __c2; }
254 lt(
const char_type& __c1,
const char_type& __c2)
255 {
return __c1 < __c2; }
258 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
259 {
return __builtin_memcmp(__s1, __s2, __n); }
262 length(
const char_type* __s)
263 {
return __builtin_strlen(__s); }
265 static const char_type*
266 find(
const char_type* __s,
size_t __n,
const char_type& __a)
267 {
return static_cast<const char_type*
>(__builtin_memchr(__s, __a, __n)); }
270 move(char_type* __s1,
const char_type* __s2,
size_t __n)
271 {
return static_cast<char_type*
>(__builtin_memmove(__s1, __s2, __n)); }
274 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
275 {
return static_cast<char_type*
>(__builtin_memcpy(__s1, __s2, __n)); }
278 assign(char_type* __s,
size_t __n, char_type __a)
279 {
return static_cast<char_type*
>(__builtin_memset(__s, __a, __n)); }
282 to_char_type(
const int_type& __c)
283 {
return static_cast<char_type
>(__c); }
288 to_int_type(
const char_type& __c)
289 {
return static_cast<int_type
>(
static_cast<unsigned char>(__c)); }
292 eq_int_type(
const int_type& __c1,
const int_type& __c2)
293 {
return __c1 == __c2; }
297 {
return static_cast<int_type
>(_CHAR_TRAITS_EOF); }
300 not_eof(
const int_type& __c)
301 {
return (__c == eof()) ? 0 : __c; }
305 #ifdef _GLIBCXX_USE_WCHAR_T
310 typedef wchar_t char_type;
311 typedef wint_t int_type;
314 typedef mbstate_t state_type;
317 assign(char_type& __c1,
const char_type& __c2)
321 eq(
const char_type& __c1,
const char_type& __c2)
322 {
return __c1 == __c2; }
325 lt(
const char_type& __c1,
const char_type& __c2)
326 {
return __c1 < __c2; }
329 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
330 {
return wmemcmp(__s1, __s2, __n); }
333 length(
const char_type* __s)
334 {
return wcslen(__s); }
336 static const char_type*
337 find(
const char_type* __s,
size_t __n,
const char_type& __a)
338 {
return wmemchr(__s, __a, __n); }
341 move(char_type* __s1,
const char_type* __s2,
size_t __n)
342 {
return wmemmove(__s1, __s2, __n); }
345 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
346 {
return wmemcpy(__s1, __s2, __n); }
349 assign(char_type* __s,
size_t __n, char_type __a)
350 {
return wmemset(__s, __a, __n); }
353 to_char_type(
const int_type& __c)
354 {
return char_type(__c); }
357 to_int_type(
const char_type& __c)
358 {
return int_type(__c); }
361 eq_int_type(
const int_type& __c1,
const int_type& __c2)
362 {
return __c1 == __c2; }
366 {
return static_cast<int_type
>(WEOF); }
369 not_eof(
const int_type& __c)
370 {
return eq_int_type(__c, eof()) ? 0 : __c; }
372 #endif //_GLIBCXX_USE_WCHAR_T
374 _GLIBCXX_END_NAMESPACE
376 #if (defined(__GXX_EXPERIMENTAL_CXX0X__) \
377 && defined(_GLIBCXX_USE_C99_STDINT_TR1))
381 _GLIBCXX_BEGIN_NAMESPACE(std)
386 typedef char16_t char_type;
387 typedef uint_least16_t int_type;
390 typedef mbstate_t state_type;
393 assign(char_type& __c1,
const char_type& __c2)
397 eq(
const char_type& __c1,
const char_type& __c2)
398 {
return __c1 == __c2; }
401 lt(
const char_type& __c1,
const char_type& __c2)
402 {
return __c1 < __c2; }
405 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
407 for (
size_t __i = 0; __i < __n; ++__i)
408 if (lt(__s1[__i], __s2[__i]))
410 else if (lt(__s2[__i], __s1[__i]))
416 length(
const char_type* __s)
419 while (!eq(__s[__i], char_type()))
424 static const char_type*
425 find(
const char_type* __s,
size_t __n,
const char_type& __a)
427 for (
size_t __i = 0; __i < __n; ++__i)
428 if (eq(__s[__i], __a))
434 move(char_type* __s1,
const char_type* __s2,
size_t __n)
436 return (static_cast<char_type*>
437 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
441 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
443 return (static_cast<char_type*>
444 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
448 assign(char_type* __s,
size_t __n, char_type __a)
450 for (
size_t __i = 0; __i < __n; ++__i)
451 assign(__s[__i], __a);
456 to_char_type(
const int_type& __c)
457 {
return char_type(__c); }
460 to_int_type(
const char_type& __c)
461 {
return int_type(__c); }
464 eq_int_type(
const int_type& __c1,
const int_type& __c2)
465 {
return __c1 == __c2; }
469 {
return static_cast<int_type
>(-1); }
472 not_eof(
const int_type& __c)
473 {
return eq_int_type(__c, eof()) ? 0 : __c; }
477 struct char_traits<char32_t>
479 typedef char32_t char_type;
480 typedef uint_least32_t int_type;
483 typedef mbstate_t state_type;
486 assign(char_type& __c1,
const char_type& __c2)
490 eq(
const char_type& __c1,
const char_type& __c2)
491 {
return __c1 == __c2; }
494 lt(
const char_type& __c1,
const char_type& __c2)
495 {
return __c1 < __c2; }
498 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
500 for (
size_t __i = 0; __i < __n; ++__i)
501 if (lt(__s1[__i], __s2[__i]))
503 else if (lt(__s2[__i], __s1[__i]))
509 length(
const char_type* __s)
512 while (!eq(__s[__i], char_type()))
517 static const char_type*
518 find(
const char_type* __s,
size_t __n,
const char_type& __a)
520 for (
size_t __i = 0; __i < __n; ++__i)
521 if (eq(__s[__i], __a))
527 move(char_type* __s1,
const char_type* __s2,
size_t __n)
529 return (static_cast<char_type*>
530 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
534 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
536 return (static_cast<char_type*>
537 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
541 assign(char_type* __s,
size_t __n, char_type __a)
543 for (
size_t __i = 0; __i < __n; ++__i)
544 assign(__s[__i], __a);
549 to_char_type(
const int_type& __c)
550 {
return char_type(__c); }
553 to_int_type(
const char_type& __c)
554 {
return int_type(__c); }
557 eq_int_type(
const int_type& __c1,
const int_type& __c2)
558 {
return __c1 == __c2; }
562 {
return static_cast<int_type
>(-1); }
565 not_eof(
const int_type& __c)
566 {
return eq_int_type(__c, eof()) ? 0 : __c; }
569 _GLIBCXX_END_NAMESPACE
573 #undef _CHAR_TRAITS_EOF
575 #endif // _CHAR_TRAITS_H