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