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 #ifndef lestes__std___ucn_traits_hh___included
00029 #define lestes__std___ucn_traits_hh___included
00030
00031
00032
00033
00034
00035 #include <cstdlib>
00036 #include <string>
00037 #include <lestes/common.hh>
00038 #include <lestes/std/character.hh>
00039
00040
00041 package(std);
00042
00043
00044
00045
00046 template<>
00047 struct char_traits< ::lestes::std::ucn > {
00048 typedef ::lestes::std::ucn char_type;
00049
00050 typedef ::lestes::lc_host_uint_least32 int_type;
00051 typedef streampos pos_type;
00052 typedef streamoff off_type;
00053 typedef mbstate_t state_type;
00054
00055 static void
00056 assign(char_type& c1, const char_type& c2)
00057 {
00058 c1 = c2;
00059 }
00060
00061 static bool
00062 eq(const char_type& c1, const char_type& c2)
00063 {
00064 return c1 == c2;
00065 }
00066
00067 static bool
00068 lt(const char_type& c1, const char_type& c2)
00069 {
00070 return c1 < c2;
00071 }
00072
00073 static int
00074 compare(const char_type* s1, const char_type* s2, size_t n)
00075 {
00076 while (n && *s1 == *s2) {
00077 s1++;
00078 s2++;
00079 n--;
00080 }
00081 return (n == 0) ? 0 : (*s1 > *s2) ? 1 : -1;
00082 }
00083
00084 static size_t
00085 length(const char_type* s)
00086 {
00087 size_t n = 0;
00088 while (*s++)
00089 n++;
00090
00091 return n;
00092 }
00093
00094 static const char_type*
00095 find(const char_type* s, size_t n, const char_type& a)
00096 {
00097 while (n--) {
00098 if (*s == a)
00099 return s;
00100 s++;
00101 }
00102
00103 return static_cast<const char_type*>(0);
00104 }
00105
00106 static char_type*
00107 move(char_type* s1, const char_type* s2, size_t n)
00108 {
00109 return static_cast<char_type*>(memmove(s1,s2,n * sizeof(char_type)));
00110 }
00111
00112 static char_type*
00113 copy(char_type* s1, const char_type* s2, size_t n)
00114 {
00115 std::copy(s2,s2 + n,s1);
00116 return s1;
00117 }
00118
00119 static char_type*
00120 assign(char_type* s, size_t n, char_type a)
00121 {
00122 fill_n(s,n,a);
00123 return s;
00124 }
00125
00126 static char_type
00127 to_char_type(const int_type& c)
00128 {
00129 return static_cast<char_type>(c);
00130 }
00131
00132 static int_type
00133 to_int_type(const char_type& c)
00134 {
00135 return static_cast<int_type>(c);
00136 }
00137
00138 static bool
00139 eq_int_type(const int_type& c1, const int_type& c2)
00140 {
00141 return c1 == c2;
00142 }
00143
00144 static int_type
00145 eof(void)
00146 {
00147 return ~static_cast<int_type>(0);
00148 }
00149
00150 static int_type
00151 not_eof(const int_type& c)
00152 {
00153 return (c == eof()) ? 0 : c;
00154 }
00155 };
00156
00157 end_package(std);
00158
00159 #endif
00160