00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef _CPP_BITS_CHAR_TRAITS_H
00035 #define _CPP_BITS_CHAR_TRAITS_H 1
00036
00037 #pragma GCC system_header
00038
00039 #include <bits/std_cstring.h>
00040 #include <bits/fpos.h>
00041
00042 namespace std
00043 {
00047 template<class _CharT>
00048 struct char_traits
00049 {
00050 typedef _CharT char_type;
00051 typedef unsigned long int_type;
00052 typedef streampos pos_type;
00053 typedef streamoff off_type;
00054 typedef mbstate_t state_type;
00055
00057 static void
00058 assign(char_type& __c1, const char_type& __c2)
00059 { __c1 = __c2; }
00060
00062 static bool
00063 eq(const char_type& __c1, const char_type& __c2)
00064 { return __c1 == __c2; }
00065
00067 static bool
00068 lt(const char_type& __c1, const char_type& __c2)
00069 { return __c1 < __c2; }
00070
00072 static int
00073 compare(const char_type* __s1, const char_type* __s2, size_t __n)
00074 {
00075 for (size_t __i = 0; __i < __n; ++__i)
00076 if (!eq(__s1[__i], __s2[__i]))
00077 return lt(__s1[__i], __s2[__i]) ? -1 : 1;
00078 return 0;
00079 }
00080
00082 static size_t
00083 length(const char_type* __s)
00084 {
00085 const char_type* __p = __s;
00086 while (*__p) ++__p;
00087 return (__p - __s);
00088 }
00089
00091 static const char_type*
00092 find(const char_type* __s, size_t __n, const char_type& __a)
00093 {
00094 for (const char_type* __p = __s; size_t(__p - __s) < __n; ++__p)
00095 if (*__p == __a) return __p;
00096 return 0;
00097 }
00098
00100 static char_type*
00101 move(char_type* __s1, const char_type* __s2, size_t __n)
00102 { return (char_type*) memmove(__s1, __s2, __n * sizeof(char_type)); }
00103
00105 static char_type*
00106 copy(char_type* __s1, const char_type* __s2, size_t __n)
00107 { return (char_type*) memcpy(__s1, __s2, __n * sizeof(char_type)); }
00108
00110 static char_type*
00111 assign(char_type* __s, size_t __n, char_type __a)
00112 {
00113 for (char_type* __p = __s; __p < __s + __n; ++__p)
00114 assign(*__p, __a);
00115 return __s;
00116 }
00117
00119 static char_type
00120 to_char_type(const int_type& __c)
00121 { return char_type(__c); }
00122
00124 static int_type
00125 to_int_type(const char_type& __c) { return int_type(__c); }
00126
00128 static bool
00129 eq_int_type(const int_type& __c1, const int_type& __c2)
00130 { return __c1 == __c2; }
00131
00133 static int_type
00134 eof() { return static_cast<int_type>(-1); }
00135
00137 static int_type
00138 not_eof(const int_type& __c)
00139 { return eq_int_type(__c, eof()) ? int_type(0) : __c; }
00140 };
00141
00142
00145 template<>
00146 struct char_traits<char>
00147 {
00148 typedef char char_type;
00149 typedef int int_type;
00150 typedef streampos pos_type;
00151 typedef streamoff off_type;
00152 typedef mbstate_t state_type;
00153
00155 static void
00156 assign(char_type& __c1, const char_type& __c2)
00157 { __c1 = __c2; }
00158
00160 static bool
00161 eq(const char_type& __c1, const char_type& __c2)
00162 { return __c1 == __c2; }
00163
00165 static bool
00166 lt(const char_type& __c1, const char_type& __c2)
00167 { return __c1 < __c2; }
00168
00170 static int
00171 compare(const char_type* __s1, const char_type* __s2, size_t __n)
00172 { return memcmp(__s1, __s2, __n); }
00173
00175 static size_t
00176 length(const char_type* __s)
00177 { return strlen(__s); }
00178
00180 static const char_type*
00181 find(const char_type* __s, size_t __n, const char_type& __a)
00182 { return static_cast<const char_type*>(memchr(__s, __a, __n)); }
00183
00185 static char_type*
00186 move(char_type* __s1, const char_type* __s2, size_t __n)
00187 { return static_cast<char_type*>(memmove(__s1, __s2, __n)); }
00188
00190 static char_type*
00191 copy(char_type* __s1, const char_type* __s2, size_t __n)
00192 { return static_cast<char_type*>(memcpy(__s1, __s2, __n)); }
00193
00195 static char_type*
00196 assign(char_type* __s, size_t __n, char_type __a)
00197 { return static_cast<char_type*>(memset(__s, __a, __n)); }
00198
00200 static char_type
00201 to_char_type(const int_type& __c)
00202 { return static_cast<char_type>(__c); }
00203
00206 static int_type
00207 to_int_type(const char_type& __c)
00208 { return static_cast<int_type>(static_cast<unsigned char>(__c)); }
00209
00211 static bool
00212 eq_int_type(const int_type& __c1, const int_type& __c2)
00213 { return __c1 == __c2; }
00214
00216 static int_type
00217 eof() { return static_cast<int_type>(EOF); }
00218
00220 static int_type
00221 not_eof(const int_type& __c)
00222 { return (__c == eof()) ? 0 : __c; }
00223 };
00224
00225
00226 #ifdef _GLIBCPP_USE_WCHAR_T
00229 template<>
00230 struct char_traits<wchar_t>
00231 {
00232 typedef wchar_t char_type;
00233 typedef wint_t int_type;
00234 typedef streamoff off_type;
00235 typedef wstreampos pos_type;
00236 typedef mbstate_t state_type;
00237
00239 static void
00240 assign(char_type& __c1, const char_type& __c2)
00241 { __c1 = __c2; }
00242
00244 static bool
00245 eq(const char_type& __c1, const char_type& __c2)
00246 { return __c1 == __c2; }
00247
00249 static bool
00250 lt(const char_type& __c1, const char_type& __c2)
00251 { return __c1 < __c2; }
00252
00254 static int
00255 compare(const char_type* __s1, const char_type* __s2, size_t __n)
00256 { return wmemcmp(__s1, __s2, __n); }
00257
00259 static size_t
00260 length(const char_type* __s)
00261 { return wcslen(__s); }
00262
00264 static const char_type*
00265 find(const char_type* __s, size_t __n, const char_type& __a)
00266 { return wmemchr(__s, __a, __n); }
00267
00269 static char_type*
00270 move(char_type* __s1, const char_type* __s2, int_type __n)
00271 { return wmemmove(__s1, __s2, __n); }
00272
00274 static char_type*
00275 copy(char_type* __s1, const char_type* __s2, size_t __n)
00276 { return wmemcpy(__s1, __s2, __n); }
00277
00279 static char_type*
00280 assign(char_type* __s, size_t __n, char_type __a)
00281 { return wmemset(__s, __a, __n); }
00282
00284 static char_type
00285 to_char_type(const int_type& __c) { return char_type(__c); }
00286
00288 static int_type
00289 to_int_type(const char_type& __c) { return int_type(__c); }
00290
00292 static bool
00293 eq_int_type(const int_type& __c1, const int_type& __c2)
00294 { return __c1 == __c2; }
00295
00297 static int_type
00298 eof() { return static_cast<int_type>(WEOF); }
00299
00301 static int_type
00302 not_eof(const int_type& __c)
00303 { return eq_int_type(__c, eof()) ? 0 : __c; }
00304 };
00305 #endif //_GLIBCPP_USE_WCHAR_T
00306
00308 template<typename _CharT, typename _Traits>
00309 struct _Char_traits_match
00310 {
00311 _CharT _M_c;
00312 _Char_traits_match(_CharT const& __c) : _M_c(__c) { }
00313
00314 bool
00315 operator()(_CharT const& __a) { return _Traits::eq(_M_c, __a); }
00316 };
00317
00318 }
00319
00320 #endif