2 * Copyright 2001-2009 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file xmltooling/char_traits.h
20 * Traits template for basic_string<unsigned short> instantiation on strict compilers.
23 #ifndef __xmltooling_chartraits_h__
24 #define __xmltooling_chartraits_h__
26 #include <xmltooling/base.h>
31 namespace xmltooling {
35 template <class _CharT>
38 typedef unsigned long int_type;
39 typedef std::streampos pos_type;
40 typedef std::streamoff off_type;
41 typedef std::mbstate_t state_type;
45 template<typename _CharT>
48 typedef _CharT char_type;
49 typedef typename _Char_types<_CharT>::int_type int_type;
50 typedef typename _Char_types<_CharT>::pos_type pos_type;
51 typedef typename _Char_types<_CharT>::off_type off_type;
52 typedef typename _Char_types<_CharT>::state_type state_type;
55 assign(char_type& __c1, const char_type& __c2)
59 eq(const char_type& __c1, const char_type& __c2)
60 { return __c1 == __c2; }
63 lt(const char_type& __c1, const char_type& __c2)
64 { return __c1 < __c2; }
67 compare(const char_type* __s1, const char_type* __s2, std::size_t __n);
70 length(const char_type* __s);
72 static const char_type*
73 find(const char_type* __s, std::size_t __n, const char_type& __a);
76 move(char_type* __s1, const char_type* __s2, std::size_t __n);
79 copy(char_type* __s1, const char_type* __s2, std::size_t __n);
82 assign(char_type* __s, std::size_t __n, char_type __a);
85 to_char_type(const int_type& __c)
86 { return static_cast<char_type>(__c); }
89 to_int_type(const char_type& __c)
90 { return static_cast<int_type>(__c); }
93 eq_int_type(const int_type& __c1, const int_type& __c2)
94 { return __c1 == __c2; }
98 { return static_cast<int_type>(EOF); }
101 not_eof(const int_type& __c)
102 { return !eq_int_type(__c, eof()) ? __c : to_int_type(char_type()); }
105 template<typename _CharT>
107 char_traits<_CharT>::
108 compare(const char_type* __s1, const char_type* __s2, std::size_t __n)
110 for (size_t __i = 0; __i < __n; ++__i)
111 if (lt(__s1[__i], __s2[__i]))
113 else if (lt(__s2[__i], __s1[__i]))
118 template<typename _CharT>
120 char_traits<_CharT>::
121 length(const char_type* __p)
124 while (!eq(__p[__i], char_type()))
129 template<typename _CharT>
130 const typename char_traits<_CharT>::char_type*
131 char_traits<_CharT>::
132 find(const char_type* __s, std::size_t __n, const char_type& __a)
134 for (std::size_t __i = 0; __i < __n; ++__i)
135 if (eq(__s[__i], __a))
140 template<typename _CharT>
141 typename char_traits<_CharT>::char_type*
142 char_traits<_CharT>::
143 move(char_type* __s1, const char_type* __s2, std::size_t __n)
145 return static_cast<_CharT*>(std::memmove(__s1, __s2,
146 __n * sizeof(char_type)));
149 template<typename _CharT>
150 typename char_traits<_CharT>::char_type*
151 char_traits<_CharT>::
152 copy(char_type* __s1, const char_type* __s2, std::size_t __n)
154 std::copy(__s2, __s2 + __n, __s1);
158 template<typename _CharT>
159 typename char_traits<_CharT>::char_type*
160 char_traits<_CharT>::
161 assign(char_type* __s, std::size_t __n, char_type __a)
163 std::fill_n(__s, __n, __a);
170 #endif // __xmltooling_chartraits_h__