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;
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; }
104 compare(
const char_type* __s1,
const char_type* __s2, std::size_t __n);
107 length(
const char_type* __s);
109 static 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()); }
142 template<
typename _CharT>
145 compare(
const char_type* __s1,
const char_type* __s2, std::size_t __n)
147 for (std::size_t __i = 0; __i < __n; ++__i)
148 if (lt(__s1[__i], __s2[__i]))
150 else if (lt(__s2[__i], __s1[__i]))
155 template<
typename _CharT>
158 length(
const char_type* __p)
161 while (!eq(__p[__i], char_type()))
166 template<
typename _CharT>
167 const typename char_traits<_CharT>::char_type*
169 find(
const char_type* __s, std::size_t __n,
const char_type& __a)
171 for (std::size_t __i = 0; __i < __n; ++__i)
172 if (eq(__s[__i], __a))
177 template<
typename _CharT>
178 typename char_traits<_CharT>::char_type*
180 move(char_type* __s1,
const char_type* __s2, std::size_t __n)
182 return static_cast<_CharT*
>(__builtin_memmove(__s1, __s2,
183 __n *
sizeof(char_type)));
186 template<
typename _CharT>
187 typename char_traits<_CharT>::char_type*
189 copy(char_type* __s1,
const char_type* __s2, std::size_t __n)
192 std::copy(__s2, __s2 + __n, __s1);
196 template<
typename _CharT>
197 typename char_traits<_CharT>::char_type*
199 assign(char_type* __s, std::size_t __n, char_type __a)
202 std::fill_n(__s, __n, __a);
206 _GLIBCXX_END_NAMESPACE_VERSION
209 namespace std _GLIBCXX_VISIBILITY(default)
211 _GLIBCXX_BEGIN_NAMESPACE_VERSION
226 template<
class _CharT>
235 typedef char char_type;
236 typedef int int_type;
239 typedef mbstate_t state_type;
242 assign(char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
245 static _GLIBCXX_CONSTEXPR
bool 246 eq(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
247 {
return __c1 == __c2; }
249 static _GLIBCXX_CONSTEXPR
bool 250 lt(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
253 return (static_cast<unsigned char>(__c1)
254 < static_cast<unsigned char>(__c2));
258 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
262 return __builtin_memcmp(__s1, __s2, __n);
266 length(
const char_type* __s)
267 {
return __builtin_strlen(__s); }
269 static const char_type*
270 find(
const char_type* __s,
size_t __n,
const char_type& __a)
274 return static_cast<const char_type*
>(__builtin_memchr(__s, __a, __n));
278 move(char_type* __s1,
const char_type* __s2,
size_t __n)
282 return static_cast<char_type*
>(__builtin_memmove(__s1, __s2, __n));
286 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
290 return static_cast<char_type*
>(__builtin_memcpy(__s1, __s2, __n));
294 assign(char_type* __s,
size_t __n, char_type __a)
298 return static_cast<char_type*
>(__builtin_memset(__s, __a, __n));
301 static _GLIBCXX_CONSTEXPR char_type
302 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
303 {
return static_cast<char_type
>(__c); }
307 static _GLIBCXX_CONSTEXPR int_type
308 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
309 {
return static_cast<int_type
>(
static_cast<unsigned char>(__c)); }
311 static _GLIBCXX_CONSTEXPR
bool 312 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
313 {
return __c1 == __c2; }
315 static _GLIBCXX_CONSTEXPR int_type
316 eof() _GLIBCXX_NOEXCEPT
317 {
return static_cast<int_type
>(_GLIBCXX_STDIO_EOF); }
319 static _GLIBCXX_CONSTEXPR int_type
320 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
321 {
return (__c == eof()) ? 0 : __c; }
325 #ifdef _GLIBCXX_USE_WCHAR_T 330 typedef wchar_t char_type;
331 typedef wint_t int_type;
334 typedef mbstate_t state_type;
337 assign(char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
340 static _GLIBCXX_CONSTEXPR
bool 341 eq(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
342 {
return __c1 == __c2; }
344 static _GLIBCXX_CONSTEXPR
bool 345 lt(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
346 {
return __c1 < __c2; }
349 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
353 return wmemcmp(__s1, __s2, __n);
357 length(
const char_type* __s)
358 {
return wcslen(__s); }
360 static const char_type*
361 find(
const char_type* __s,
size_t __n,
const char_type& __a)
365 return wmemchr(__s, __a, __n);
369 move(char_type* __s1,
const char_type* __s2,
size_t __n)
373 return wmemmove(__s1, __s2, __n);
377 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
381 return wmemcpy(__s1, __s2, __n);
385 assign(char_type* __s,
size_t __n, char_type __a)
389 return wmemset(__s, __a, __n);
392 static _GLIBCXX_CONSTEXPR char_type
393 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
394 {
return char_type(__c); }
396 static _GLIBCXX_CONSTEXPR int_type
397 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
398 {
return int_type(__c); }
400 static _GLIBCXX_CONSTEXPR
bool 401 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
402 {
return __c1 == __c2; }
404 static _GLIBCXX_CONSTEXPR int_type
405 eof() _GLIBCXX_NOEXCEPT
406 {
return static_cast<int_type
>(WEOF); }
408 static _GLIBCXX_CONSTEXPR int_type
409 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
410 {
return eq_int_type(__c, eof()) ? 0 : __c; }
412 #endif //_GLIBCXX_USE_WCHAR_T 414 _GLIBCXX_END_NAMESPACE_VERSION
417 #if ((__cplusplus >= 201103L) \ 418 && defined(_GLIBCXX_USE_C99_STDINT_TR1)) 422 namespace std _GLIBCXX_VISIBILITY(default)
424 _GLIBCXX_BEGIN_NAMESPACE_VERSION
429 typedef char16_t char_type;
430 typedef uint_least16_t int_type;
433 typedef mbstate_t state_type;
436 assign(char_type& __c1,
const char_type& __c2) noexcept
439 static constexpr
bool 440 eq(
const char_type& __c1,
const char_type& __c2) noexcept
441 {
return __c1 == __c2; }
443 static constexpr
bool 444 lt(
const char_type& __c1,
const char_type& __c2) noexcept
445 {
return __c1 < __c2; }
448 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
450 for (
size_t __i = 0; __i < __n; ++__i)
451 if (lt(__s1[__i], __s2[__i]))
453 else if (lt(__s2[__i], __s1[__i]))
459 length(
const char_type* __s)
462 while (!eq(__s[__i], char_type()))
467 static const char_type*
468 find(
const char_type* __s,
size_t __n,
const char_type& __a)
470 for (
size_t __i = 0; __i < __n; ++__i)
471 if (eq(__s[__i], __a))
477 move(char_type* __s1,
const char_type* __s2,
size_t __n)
481 return (static_cast<char_type*>
482 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
486 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
490 return (static_cast<char_type*>
491 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
495 assign(char_type* __s,
size_t __n, char_type __a)
497 for (
size_t __i = 0; __i < __n; ++__i)
498 assign(__s[__i], __a);
502 static constexpr char_type
503 to_char_type(
const int_type& __c) noexcept
504 {
return char_type(__c); }
506 static constexpr int_type
507 to_int_type(
const char_type& __c) noexcept
508 {
return int_type(__c); }
510 static constexpr
bool 511 eq_int_type(
const int_type& __c1,
const int_type& __c2) noexcept
512 {
return __c1 == __c2; }
514 static constexpr int_type
516 {
return static_cast<int_type
>(-1); }
518 static constexpr int_type
519 not_eof(
const int_type& __c) noexcept
520 {
return eq_int_type(__c, eof()) ? 0 : __c; }
526 typedef char32_t char_type;
527 typedef uint_least32_t int_type;
530 typedef mbstate_t state_type;
533 assign(char_type& __c1,
const char_type& __c2) noexcept
536 static constexpr
bool 537 eq(
const char_type& __c1,
const char_type& __c2) noexcept
538 {
return __c1 == __c2; }
540 static constexpr
bool 541 lt(
const char_type& __c1,
const char_type& __c2) noexcept
542 {
return __c1 < __c2; }
545 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
547 for (
size_t __i = 0; __i < __n; ++__i)
548 if (lt(__s1[__i], __s2[__i]))
550 else if (lt(__s2[__i], __s1[__i]))
556 length(
const char_type* __s)
559 while (!eq(__s[__i], char_type()))
564 static const char_type*
565 find(
const char_type* __s,
size_t __n,
const char_type& __a)
567 for (
size_t __i = 0; __i < __n; ++__i)
568 if (eq(__s[__i], __a))
574 move(char_type* __s1,
const char_type* __s2,
size_t __n)
578 return (static_cast<char_type*>
579 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
583 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
587 return (static_cast<char_type*>
588 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
592 assign(char_type* __s,
size_t __n, char_type __a)
594 for (
size_t __i = 0; __i < __n; ++__i)
595 assign(__s[__i], __a);
599 static constexpr char_type
600 to_char_type(
const int_type& __c) noexcept
601 {
return char_type(__c); }
603 static constexpr int_type
604 to_int_type(
const char_type& __c) noexcept
605 {
return int_type(__c); }
607 static constexpr
bool 608 eq_int_type(
const int_type& __c1,
const int_type& __c2) noexcept
609 {
return __c1 == __c2; }
611 static constexpr int_type
613 {
return static_cast<int_type
>(-1); }
615 static constexpr int_type
616 not_eof(
const int_type& __c) noexcept
617 {
return eq_int_type(__c, eof()) ? 0 : __c; }
620 _GLIBCXX_END_NAMESPACE_VERSION
625 #endif // _CHAR_TRAITS_H
ISO C++ entities toplevel namespace is std.
Mapping from character type to associated types.
GNU extensions for public use.
Basis for explicit traits specializations.
Class representing stream positions.
long long streamoff
Type used by fpos, char_traits<char>, and char_traits<wchar_t>.
Base class used to implement std::char_traits.