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
00040 #ifndef _CPP_BITS_CHAR_TRAITS_H
00041 #define _CPP_BITS_CHAR_TRAITS_H 1
00042
00043 #pragma GCC system_header
00044
00045 #include <cstring>
00046 #include <bits/fpos.h>
00047
00048 namespace std
00049 {
00053 template<class _CharT>
00054 struct char_traits
00055 {
00056 typedef _CharT char_type;
00057
00058 typedef unsigned long int_type;
00059 typedef streampos pos_type;
00060 typedef streamoff off_type;
00061 typedef mbstate_t state_type;
00062
00063 static void
00064 assign(char_type& __c1, const char_type& __c2);
00065
00066 static bool
00067 eq(const char_type& __c1, const char_type& __c2);
00068
00069 static bool
00070 lt(const char_type& __c1, const char_type& __c2);
00071
00072 static int
00073 compare(const char_type* __s1, const char_type* __s2, size_t __n);
00074
00075 static size_t
00076 length(const char_type* __s);
00077
00078 static const char_type*
00079 find(const char_type* __s, size_t __n, const char_type& __a);
00080
00081 static char_type*
00082 move(char_type* __s1, const char_type* __s2, size_t __n);
00083
00084 static char_type*
00085 copy(char_type* __s1, const char_type* __s2, size_t __n);
00086
00087 static char_type*
00088 assign(char_type* __s, size_t __n, char_type __a);
00089
00090 static char_type
00091 to_char_type(const int_type& __c);
00092
00093 static int_type
00094 to_int_type(const char_type& __c);
00095
00096 static bool
00097 eq_int_type(const int_type& __c1, const int_type& __c2);
00098
00099 static int_type
00100 eof();
00101
00102 static int_type
00103 not_eof(const int_type& __c);
00104 };
00105
00106
00108 template<>
00109 struct char_traits<char>
00110 {
00111 typedef char char_type;
00112 typedef int int_type;
00113 typedef streampos pos_type;
00114 typedef streamoff off_type;
00115 typedef mbstate_t state_type;
00116
00117 static void
00118 assign(char_type& __c1, const char_type& __c2)
00119 { __c1 = __c2; }
00120
00121 static bool
00122 eq(const char_type& __c1, const char_type& __c2)
00123 { return __c1 == __c2; }
00124
00125 static bool
00126 lt(const char_type& __c1, const char_type& __c2)
00127 { return __c1 < __c2; }
00128
00129 static int
00130 compare(const char_type* __s1, const char_type* __s2, size_t __n)
00131 { return memcmp(__s1, __s2, __n); }
00132
00133 static size_t
00134 length(const char_type* __s)
00135 { return strlen(__s); }
00136
00137 static const char_type*
00138 find(const char_type* __s, size_t __n, const char_type& __a)
00139 { return static_cast<const char_type*>(memchr(__s, __a, __n)); }
00140
00141 static char_type*
00142 move(char_type* __s1, const char_type* __s2, size_t __n)
00143 { return static_cast<char_type*>(memmove(__s1, __s2, __n)); }
00144
00145 static char_type*
00146 copy(char_type* __s1, const char_type* __s2, size_t __n)
00147 { return static_cast<char_type*>(memcpy(__s1, __s2, __n)); }
00148
00149 static char_type*
00150 assign(char_type* __s, size_t __n, char_type __a)
00151 { return static_cast<char_type*>(memset(__s, __a, __n)); }
00152
00153 static char_type
00154 to_char_type(const int_type& __c)
00155 { return static_cast<char_type>(__c); }
00156
00157
00158
00159 static int_type
00160 to_int_type(const char_type& __c)
00161 { return static_cast<int_type>(static_cast<unsigned char>(__c)); }
00162
00163 static bool
00164 eq_int_type(const int_type& __c1, const int_type& __c2)
00165 { return __c1 == __c2; }
00166
00167 static int_type
00168 eof() { return static_cast<int_type>(EOF); }
00169
00170 static int_type
00171 not_eof(const int_type& __c)
00172 { return (__c == eof()) ? 0 : __c; }
00173 };
00174
00175
00176 #ifdef _GLIBCPP_USE_WCHAR_T
00177 template<>
00178 struct char_traits<wchar_t>
00179 {
00180 typedef wchar_t char_type;
00181 typedef wint_t int_type;
00182 typedef streamoff off_type;
00183 typedef wstreampos pos_type;
00184 typedef mbstate_t state_type;
00185
00186 static void
00187 assign(char_type& __c1, const char_type& __c2)
00188 { __c1 = __c2; }
00189
00190 static bool
00191 eq(const char_type& __c1, const char_type& __c2)
00192 { return __c1 == __c2; }
00193
00194 static bool
00195 lt(const char_type& __c1, const char_type& __c2)
00196 { return __c1 < __c2; }
00197
00198 static int
00199 compare(const char_type* __s1, const char_type* __s2, size_t __n)
00200 { return wmemcmp(__s1, __s2, __n); }
00201
00202 static size_t
00203 length(const char_type* __s)
00204 { return wcslen(__s); }
00205
00206 static const char_type*
00207 find(const char_type* __s, size_t __n, const char_type& __a)
00208 { return wmemchr(__s, __a, __n); }
00209
00210 static char_type*
00211 move(char_type* __s1, const char_type* __s2, int_type __n)
00212 { return wmemmove(__s1, __s2, __n); }
00213
00214 static char_type*
00215 copy(char_type* __s1, const char_type* __s2, size_t __n)
00216 { return wmemcpy(__s1, __s2, __n); }
00217
00218 static char_type*
00219 assign(char_type* __s, size_t __n, char_type __a)
00220 { return wmemset(__s, __a, __n); }
00221
00222 static char_type
00223 to_char_type(const int_type& __c) { return char_type(__c); }
00224
00225 static int_type
00226 to_int_type(const char_type& __c) { return int_type(__c); }
00227
00228 static bool
00229 eq_int_type(const int_type& __c1, const int_type& __c2)
00230 { return __c1 == __c2; }
00231
00232 static int_type
00233 eof() { return static_cast<int_type>(WEOF); }
00234
00235 static int_type
00236 not_eof(const int_type& __c)
00237 { return eq_int_type(__c, eof()) ? 0 : __c; }
00238 };
00239 #endif //_GLIBCPP_USE_WCHAR_T
00240
00241 template<typename _CharT, typename _Traits>
00242 struct _Char_traits_match
00243 {
00244 _CharT _M_c;
00245 _Char_traits_match(_CharT const& __c) : _M_c(__c) { }
00246
00247 bool
00248 operator()(_CharT const& __a) { return _Traits::eq(_M_c, __a); }
00249 };
00250 }
00251
00252 #endif