34 #ifndef _CHAR_TRAITS_H 35 #define _CHAR_TRAITS_H 1 37 #pragma GCC system_header 43 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
45 _GLIBCXX_BEGIN_NAMESPACE_VERSION
57 template<
typename _CharT>
60 typedef unsigned long int_type;
63 typedef std::mbstate_t state_type;
82 template<
typename _CharT>
85 typedef _CharT char_type;
86 typedef typename _Char_types<_CharT>::int_type int_type;
88 typedef typename _Char_types<_CharT>::off_type off_type;
89 typedef typename _Char_types<_CharT>::state_type state_type;
91 static _GLIBCXX14_CONSTEXPR
void 92 assign(char_type& __c1,
const char_type& __c2)
95 static _GLIBCXX_CONSTEXPR
bool 96 eq(
const char_type& __c1,
const char_type& __c2)
97 {
return __c1 == __c2; }
99 static _GLIBCXX_CONSTEXPR
bool 100 lt(
const char_type& __c1,
const char_type& __c2)
101 {
return __c1 < __c2; }
103 static _GLIBCXX14_CONSTEXPR
int 104 compare(
const char_type* __s1,
const char_type* __s2, std::size_t __n);
106 static _GLIBCXX14_CONSTEXPR std::size_t
107 length(
const char_type* __s);
109 static _GLIBCXX14_CONSTEXPR
const char_type*
110 find(
const char_type* __s, std::size_t __n,
const char_type& __a);
113 move(char_type* __s1,
const char_type* __s2, std::size_t __n);
116 copy(char_type* __s1,
const char_type* __s2, std::size_t __n);
119 assign(char_type* __s, std::size_t __n, char_type __a);
121 static _GLIBCXX_CONSTEXPR char_type
122 to_char_type(
const int_type& __c)
123 {
return static_cast<char_type
>(__c); }
125 static _GLIBCXX_CONSTEXPR int_type
126 to_int_type(
const char_type& __c)
127 {
return static_cast<int_type
>(__c); }
129 static _GLIBCXX_CONSTEXPR
bool 130 eq_int_type(
const int_type& __c1,
const int_type& __c2)
131 {
return __c1 == __c2; }
133 static _GLIBCXX_CONSTEXPR int_type
135 {
return static_cast<int_type
>(_GLIBCXX_STDIO_EOF); }
137 static _GLIBCXX_CONSTEXPR int_type
138 not_eof(
const int_type& __c)
139 {
return !eq_int_type(__c, eof()) ? __c : to_int_type(char_type()); }
144 template<
typename _CharT>
145 _GLIBCXX14_CONSTEXPR
int 147 compare(
const char_type* __s1,
const char_type* __s2, std::size_t __n)
149 for (std::size_t __i = 0; __i < __n; ++__i)
150 if (lt(__s1[__i], __s2[__i]))
152 else if (lt(__s2[__i], __s1[__i]))
157 template<
typename _CharT>
158 _GLIBCXX14_CONSTEXPR std::size_t
160 length(
const char_type* __p)
163 while (!eq(__p[__i], char_type()))
168 template<
typename _CharT>
169 _GLIBCXX14_CONSTEXPR
const typename char_traits<_CharT>::char_type*
171 find(
const char_type* __s, std::size_t __n,
const char_type& __a)
173 for (std::size_t __i = 0; __i < __n; ++__i)
174 if (eq(__s[__i], __a))
179 template<
typename _CharT>
180 typename char_traits<_CharT>::char_type*
182 move(char_type* __s1,
const char_type* __s2, std::size_t __n)
184 return static_cast<_CharT*
>(__builtin_memmove(__s1, __s2,
185 __n *
sizeof(char_type)));
188 template<
typename _CharT>
189 typename char_traits<_CharT>::char_type*
191 copy(char_type* __s1,
const char_type* __s2, std::size_t __n)
194 std::copy(__s2, __s2 + __n, __s1);
198 template<
typename _CharT>
199 typename char_traits<_CharT>::char_type*
201 assign(char_type* __s, std::size_t __n, char_type __a)
204 std::fill_n(__s, __n, __a);
208 _GLIBCXX_END_NAMESPACE_VERSION
211 namespace std _GLIBCXX_VISIBILITY(default)
213 _GLIBCXX_BEGIN_NAMESPACE_VERSION
228 template<
class _CharT>
237 typedef char char_type;
238 typedef int int_type;
241 typedef mbstate_t state_type;
243 static _GLIBCXX17_CONSTEXPR
void 244 assign(char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
247 static _GLIBCXX_CONSTEXPR
bool 248 eq(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
249 {
return __c1 == __c2; }
251 static _GLIBCXX_CONSTEXPR
bool 252 lt(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
255 return (static_cast<unsigned char>(__c1)
256 < static_cast<unsigned char>(__c2));
260 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
264 return __builtin_memcmp(__s1, __s2, __n);
268 length(
const char_type* __s)
269 {
return __builtin_strlen(__s); }
271 static const char_type*
272 find(
const char_type* __s,
size_t __n,
const char_type& __a)
276 return static_cast<const char_type*
>(__builtin_memchr(__s, __a, __n));
280 move(char_type* __s1,
const char_type* __s2,
size_t __n)
284 return static_cast<char_type*
>(__builtin_memmove(__s1, __s2, __n));
288 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
292 return static_cast<char_type*
>(__builtin_memcpy(__s1, __s2, __n));
296 assign(char_type* __s,
size_t __n, char_type __a)
300 return static_cast<char_type*
>(__builtin_memset(__s, __a, __n));
303 static _GLIBCXX_CONSTEXPR char_type
304 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
305 {
return static_cast<char_type
>(__c); }
309 static _GLIBCXX_CONSTEXPR int_type
310 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
311 {
return static_cast<int_type
>(
static_cast<unsigned char>(__c)); }
313 static _GLIBCXX_CONSTEXPR
bool 314 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
315 {
return __c1 == __c2; }
317 static _GLIBCXX_CONSTEXPR int_type
318 eof() _GLIBCXX_NOEXCEPT
319 {
return static_cast<int_type
>(_GLIBCXX_STDIO_EOF); }
321 static _GLIBCXX_CONSTEXPR int_type
322 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
323 {
return (__c == eof()) ? 0 : __c; }
327 #ifdef _GLIBCXX_USE_WCHAR_T 332 typedef wchar_t char_type;
333 typedef wint_t int_type;
336 typedef mbstate_t state_type;
338 static _GLIBCXX17_CONSTEXPR
void 339 assign(char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
342 static _GLIBCXX_CONSTEXPR
bool 343 eq(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
344 {
return __c1 == __c2; }
346 static _GLIBCXX_CONSTEXPR
bool 347 lt(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
348 {
return __c1 < __c2; }
351 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
355 return wmemcmp(__s1, __s2, __n);
359 length(
const char_type* __s)
360 {
return wcslen(__s); }
362 static const char_type*
363 find(
const char_type* __s,
size_t __n,
const char_type& __a)
367 return wmemchr(__s, __a, __n);
371 move(char_type* __s1,
const char_type* __s2,
size_t __n)
375 return wmemmove(__s1, __s2, __n);
379 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
383 return wmemcpy(__s1, __s2, __n);
387 assign(char_type* __s,
size_t __n, char_type __a)
391 return wmemset(__s, __a, __n);
394 static _GLIBCXX_CONSTEXPR char_type
395 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
396 {
return char_type(__c); }
398 static _GLIBCXX_CONSTEXPR int_type
399 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
400 {
return int_type(__c); }
402 static _GLIBCXX_CONSTEXPR
bool 403 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
404 {
return __c1 == __c2; }
406 static _GLIBCXX_CONSTEXPR int_type
407 eof() _GLIBCXX_NOEXCEPT
408 {
return static_cast<int_type
>(WEOF); }
410 static _GLIBCXX_CONSTEXPR int_type
411 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
412 {
return eq_int_type(__c, eof()) ? 0 : __c; }
414 #endif //_GLIBCXX_USE_WCHAR_T 416 _GLIBCXX_END_NAMESPACE_VERSION
419 #if ((__cplusplus >= 201103L) \ 420 && defined(_GLIBCXX_USE_C99_STDINT_TR1)) 424 namespace std _GLIBCXX_VISIBILITY(default)
426 _GLIBCXX_BEGIN_NAMESPACE_VERSION
431 typedef char16_t char_type;
432 typedef uint_least16_t int_type;
435 typedef mbstate_t state_type;
437 static _GLIBCXX17_CONSTEXPR
void 438 assign(char_type& __c1,
const char_type& __c2) noexcept
441 static constexpr
bool 442 eq(
const char_type& __c1,
const char_type& __c2) noexcept
443 {
return __c1 == __c2; }
445 static constexpr
bool 446 lt(
const char_type& __c1,
const char_type& __c2) noexcept
447 {
return __c1 < __c2; }
449 static _GLIBCXX17_CONSTEXPR
int 450 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
452 for (
size_t __i = 0; __i < __n; ++__i)
453 if (lt(__s1[__i], __s2[__i]))
455 else if (lt(__s2[__i], __s1[__i]))
460 static _GLIBCXX17_CONSTEXPR
size_t 461 length(
const char_type* __s)
464 while (!eq(__s[__i], char_type()))
469 static _GLIBCXX17_CONSTEXPR
const char_type*
470 find(
const char_type* __s,
size_t __n,
const char_type& __a)
472 for (
size_t __i = 0; __i < __n; ++__i)
473 if (eq(__s[__i], __a))
479 move(char_type* __s1,
const char_type* __s2,
size_t __n)
483 return (static_cast<char_type*>
484 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
488 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
492 return (static_cast<char_type*>
493 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
497 assign(char_type* __s,
size_t __n, char_type __a)
499 for (
size_t __i = 0; __i < __n; ++__i)
500 assign(__s[__i], __a);
504 static constexpr char_type
505 to_char_type(
const int_type& __c) noexcept
506 {
return char_type(__c); }
508 static constexpr int_type
509 to_int_type(
const char_type& __c) noexcept
510 {
return int_type(__c); }
512 static constexpr
bool 513 eq_int_type(
const int_type& __c1,
const int_type& __c2) noexcept
514 {
return __c1 == __c2; }
516 static constexpr int_type
518 {
return static_cast<int_type
>(-1); }
520 static constexpr int_type
521 not_eof(
const int_type& __c) noexcept
522 {
return eq_int_type(__c, eof()) ? 0 : __c; }
528 typedef char32_t char_type;
529 typedef uint_least32_t int_type;
532 typedef mbstate_t state_type;
534 static _GLIBCXX17_CONSTEXPR
void 535 assign(char_type& __c1,
const char_type& __c2) noexcept
538 static constexpr
bool 539 eq(
const char_type& __c1,
const char_type& __c2) noexcept
540 {
return __c1 == __c2; }
542 static constexpr
bool 543 lt(
const char_type& __c1,
const char_type& __c2) noexcept
544 {
return __c1 < __c2; }
546 static _GLIBCXX17_CONSTEXPR
int 547 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
549 for (
size_t __i = 0; __i < __n; ++__i)
550 if (lt(__s1[__i], __s2[__i]))
552 else if (lt(__s2[__i], __s1[__i]))
557 static _GLIBCXX17_CONSTEXPR
size_t 558 length(
const char_type* __s)
561 while (!eq(__s[__i], char_type()))
566 static _GLIBCXX17_CONSTEXPR
const char_type*
567 find(
const char_type* __s,
size_t __n,
const char_type& __a)
569 for (
size_t __i = 0; __i < __n; ++__i)
570 if (eq(__s[__i], __a))
576 move(char_type* __s1,
const char_type* __s2,
size_t __n)
580 return (static_cast<char_type*>
581 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
585 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
589 return (static_cast<char_type*>
590 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
594 assign(char_type* __s,
size_t __n, char_type __a)
596 for (
size_t __i = 0; __i < __n; ++__i)
597 assign(__s[__i], __a);
601 static constexpr char_type
602 to_char_type(
const int_type& __c) noexcept
603 {
return char_type(__c); }
605 static constexpr int_type
606 to_int_type(
const char_type& __c) noexcept
607 {
return int_type(__c); }
609 static constexpr
bool 610 eq_int_type(
const int_type& __c1,
const int_type& __c2) noexcept
611 {
return __c1 == __c2; }
613 static constexpr int_type
615 {
return static_cast<int_type
>(-1); }
617 static constexpr int_type
618 not_eof(
const int_type& __c) noexcept
619 {
return eq_int_type(__c, eof()) ? 0 : __c; }
622 _GLIBCXX_END_NAMESPACE_VERSION
627 #endif // _CHAR_TRAITS_H
Base class used to implement std::char_traits.
ISO C++ entities toplevel namespace is std.
GNU extensions for public use.
Mapping from character type to associated types.
Class representing stream positions.
Basis for explicit traits specializations.
long long streamoff
Type used by fpos, char_traits<char>, and char_traits<wchar_t>.