| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- | 
|  | 2 | //===----------------------------------------------------------------------===// | 
|  | 3 | // | 
| Howard Hinnant | 5b08a8a | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | //                     The LLVM Compiler Infrastructure | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // | 
| Howard Hinnant | 412dbeb | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open | 
|  | 7 | // Source Licenses. See LICENSE.TXT for details. | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // | 
|  | 9 | //===----------------------------------------------------------------------===// | 
|  | 10 |  | 
|  | 11 | #ifndef _LIBCPP___LOCALE | 
|  | 12 | #define _LIBCPP___LOCALE | 
|  | 13 |  | 
|  | 14 | #include <__config> | 
|  | 15 | #include <string> | 
|  | 16 | #include <memory> | 
|  | 17 | #include <utility> | 
|  | 18 | #include <mutex> | 
|  | 19 | #include <cstdint> | 
|  | 20 | #include <cctype> | 
| Howard Hinnant | 128ba71 | 2010-05-24 17:49:41 +0000 | [diff] [blame] | 21 | #include <locale.h> | 
| Howard Hinnant | 3c78ca0 | 2011-09-22 19:10:18 +0000 | [diff] [blame^] | 22 | #if _WIN32 | 
|  | 23 | # include <support/win32/locale.h> | 
|  | 24 | #else  // _WIN32 | 
|  | 25 | # include <xlocale.h> | 
|  | 26 | #endif  // _WIN32 | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 27 |  | 
|  | 28 | #pragma GCC system_header | 
|  | 29 |  | 
|  | 30 | _LIBCPP_BEGIN_NAMESPACE_STD | 
|  | 31 |  | 
|  | 32 | class locale; | 
|  | 33 |  | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 34 | template <class _Facet> bool has_facet(const locale&) _NOEXCEPT; | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 35 | template <class _Facet> const _Facet& use_facet(const locale&); | 
|  | 36 |  | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 37 | class _LIBCPP_VISIBLE locale | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 38 | { | 
|  | 39 | public: | 
|  | 40 | // types: | 
|  | 41 | class facet; | 
|  | 42 | class id; | 
|  | 43 |  | 
|  | 44 | typedef int category; | 
|  | 45 | static const category // values assigned here are for exposition only | 
|  | 46 | none     = 0, | 
|  | 47 | collate  = LC_COLLATE_MASK, | 
|  | 48 | ctype    = LC_CTYPE_MASK, | 
|  | 49 | monetary = LC_MONETARY_MASK, | 
|  | 50 | numeric  = LC_NUMERIC_MASK, | 
|  | 51 | time     = LC_TIME_MASK, | 
|  | 52 | messages = LC_MESSAGES_MASK, | 
|  | 53 | all = collate | ctype | monetary | numeric | time | messages; | 
|  | 54 |  | 
|  | 55 | // construct/copy/destroy: | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 56 | locale()  _NOEXCEPT; | 
|  | 57 | locale(const locale&)  _NOEXCEPT; | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 58 | explicit locale(const char*); | 
|  | 59 | explicit locale(const string&); | 
|  | 60 | locale(const locale&, const char*, category); | 
|  | 61 | locale(const locale&, const string&, category); | 
| Howard Hinnant | c950e77 | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 62 | template <class _Facet> | 
|  | 63 | _LIBCPP_INLINE_VISIBILITY locale(const locale&, _Facet*); | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 64 | locale(const locale&, const locale&, category); | 
|  | 65 |  | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 66 | ~locale(); | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 67 |  | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 68 | const locale& operator=(const locale&)  _NOEXCEPT; | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 69 |  | 
|  | 70 | template <class _Facet> locale combine(const locale&) const; | 
|  | 71 |  | 
|  | 72 | // locale operations: | 
|  | 73 | string name() const; | 
|  | 74 | bool operator==(const locale&) const; | 
|  | 75 | bool operator!=(const locale& __y) const {return !(*this == __y);} | 
|  | 76 | template <class _CharT, class _Traits, class _Allocator> | 
|  | 77 | bool operator()(const basic_string<_CharT, _Traits, _Allocator>&, | 
|  | 78 | const basic_string<_CharT, _Traits, _Allocator>&) const; | 
|  | 79 |  | 
|  | 80 | // global locale objects: | 
|  | 81 | static locale global(const locale&); | 
|  | 82 | static const locale& classic(); | 
|  | 83 |  | 
|  | 84 | private: | 
|  | 85 | class __imp; | 
|  | 86 | __imp* __locale_; | 
|  | 87 |  | 
|  | 88 | void __install_ctor(const locale&, facet*, long); | 
|  | 89 | static locale& __global(); | 
|  | 90 | bool has_facet(id&) const; | 
|  | 91 | const facet* use_facet(id&) const; | 
|  | 92 |  | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 93 | template <class _Facet> friend bool has_facet(const locale&)  _NOEXCEPT; | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 94 | template <class _Facet> friend const _Facet& use_facet(const locale&); | 
|  | 95 | }; | 
|  | 96 |  | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 97 | class _LIBCPP_VISIBLE locale::facet | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 98 | : public __shared_count | 
|  | 99 | { | 
|  | 100 | protected: | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 101 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 102 | explicit facet(size_t __refs = 0) | 
|  | 103 | : __shared_count(static_cast<long>(__refs)-1) {} | 
|  | 104 |  | 
|  | 105 | virtual ~facet(); | 
|  | 106 |  | 
|  | 107 | //    facet(const facet&) = delete;     // effectively done in __shared_count | 
|  | 108 | //    void operator=(const facet&) = delete; | 
|  | 109 | private: | 
| Howard Hinnant | 3739fe7 | 2011-05-28 14:41:13 +0000 | [diff] [blame] | 110 | virtual void __on_zero_shared() _NOEXCEPT; | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 111 | }; | 
|  | 112 |  | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 113 | class _LIBCPP_VISIBLE locale::id | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 114 | { | 
|  | 115 | once_flag      __flag_; | 
|  | 116 | int32_t        __id_; | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 117 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 118 | static int32_t __next_id; | 
|  | 119 | public: | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 120 | _LIBCPP_INLINE_VISIBILITY id() {} | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 121 | private: | 
|  | 122 | void __init(); | 
|  | 123 | void operator=(const id&); // = delete; | 
|  | 124 | id(const id&); // = delete; | 
|  | 125 | public:  // only needed for tests | 
|  | 126 | long __get(); | 
|  | 127 |  | 
|  | 128 | friend class locale; | 
|  | 129 | friend class locale::__imp; | 
|  | 130 | }; | 
|  | 131 |  | 
|  | 132 | template <class _Facet> | 
|  | 133 | inline _LIBCPP_INLINE_VISIBILITY | 
|  | 134 | locale::locale(const locale& __other, _Facet* __f) | 
|  | 135 | { | 
|  | 136 | __install_ctor(__other, __f, __f ? __f->id.__get() : 0); | 
|  | 137 | } | 
|  | 138 |  | 
|  | 139 | template <class _Facet> | 
|  | 140 | locale | 
|  | 141 | locale::combine(const locale& __other) const | 
|  | 142 | { | 
| Howard Hinnant | 54b409f | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 143 | #ifndef _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 144 | if (!_VSTD::has_facet<_Facet>(__other)) | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 145 | throw runtime_error("locale::combine: locale missing facet"); | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 146 | #endif  // _LIBCPP_NO_EXCEPTIONS | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 147 | return locale(*this, &const_cast<_Facet&>(_VSTD::use_facet<_Facet>(__other))); | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 148 | } | 
|  | 149 |  | 
|  | 150 | template <class _Facet> | 
|  | 151 | inline _LIBCPP_INLINE_VISIBILITY | 
|  | 152 | bool | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 153 | has_facet(const locale& __l)  _NOEXCEPT | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 154 | { | 
|  | 155 | return __l.has_facet(_Facet::id); | 
|  | 156 | } | 
|  | 157 |  | 
|  | 158 | template <class _Facet> | 
|  | 159 | inline _LIBCPP_INLINE_VISIBILITY | 
|  | 160 | const _Facet& | 
|  | 161 | use_facet(const locale& __l) | 
|  | 162 | { | 
|  | 163 | return static_cast<const _Facet&>(*__l.use_facet(_Facet::id)); | 
|  | 164 | } | 
|  | 165 |  | 
|  | 166 | // template <class _CharT> class collate; | 
|  | 167 |  | 
|  | 168 | template <class _CharT> | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 169 | class _LIBCPP_VISIBLE collate | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 170 | : public locale::facet | 
|  | 171 | { | 
|  | 172 | public: | 
|  | 173 | typedef _CharT char_type; | 
|  | 174 | typedef basic_string<char_type> string_type; | 
|  | 175 |  | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 176 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 177 | explicit collate(size_t __refs = 0) | 
|  | 178 | : locale::facet(__refs) {} | 
|  | 179 |  | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 180 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 181 | int compare(const char_type* __lo1, const char_type* __hi1, | 
|  | 182 | const char_type* __lo2, const char_type* __hi2) const | 
|  | 183 | { | 
|  | 184 | return do_compare(__lo1, __hi1, __lo2, __hi2); | 
|  | 185 | } | 
|  | 186 |  | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 187 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 188 | string_type transform(const char_type* __lo, const char_type* __hi) const | 
|  | 189 | { | 
|  | 190 | return do_transform(__lo, __hi); | 
|  | 191 | } | 
|  | 192 |  | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 193 | _LIBCPP_INLINE_VISIBILITY | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 194 | long hash(const char_type* __lo, const char_type* __hi) const | 
|  | 195 | { | 
|  | 196 | return do_hash(__lo, __hi); | 
|  | 197 | } | 
|  | 198 |  | 
|  | 199 | static locale::id id; | 
|  | 200 |  | 
|  | 201 | protected: | 
|  | 202 | ~collate(); | 
|  | 203 | virtual int do_compare(const char_type* __lo1, const char_type* __hi1, | 
|  | 204 | const char_type* __lo2, const char_type* __hi2) const; | 
|  | 205 | virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const | 
|  | 206 | {return string_type(__lo, __hi);} | 
|  | 207 | virtual long do_hash(const char_type* __lo, const char_type* __hi) const; | 
|  | 208 | }; | 
|  | 209 |  | 
|  | 210 | template <class _CharT> locale::id collate<_CharT>::id; | 
|  | 211 |  | 
|  | 212 | template <class _CharT> | 
|  | 213 | collate<_CharT>::~collate() | 
|  | 214 | { | 
|  | 215 | } | 
|  | 216 |  | 
|  | 217 | template <class _CharT> | 
|  | 218 | int | 
|  | 219 | collate<_CharT>::do_compare(const char_type* __lo1, const char_type* __hi1, | 
|  | 220 | const char_type* __lo2, const char_type* __hi2) const | 
|  | 221 | { | 
|  | 222 | for (; __lo2 != __hi2; ++__lo1, ++__lo2) | 
|  | 223 | { | 
|  | 224 | if (__lo1 == __hi1 || *__lo1 < *__lo2) | 
|  | 225 | return -1; | 
|  | 226 | if (*__lo2 < *__lo1) | 
|  | 227 | return 1; | 
|  | 228 | } | 
|  | 229 | return __lo1 != __hi1; | 
|  | 230 | } | 
|  | 231 |  | 
|  | 232 | template <class _CharT> | 
|  | 233 | long | 
|  | 234 | collate<_CharT>::do_hash(const char_type* lo, const char_type* hi) const | 
|  | 235 | { | 
|  | 236 | size_t h = 0; | 
|  | 237 | const size_t sr = __CHAR_BIT__ * sizeof(size_t) - 8; | 
|  | 238 | const size_t mask = size_t(0xF) << (sr + 4); | 
|  | 239 | for(const char_type* p = lo; p != hi; ++p) | 
|  | 240 | { | 
|  | 241 | h = (h << 4) + *p; | 
|  | 242 | size_t g = h & mask; | 
|  | 243 | h ^= g | (g >> sr); | 
|  | 244 | } | 
|  | 245 | return static_cast<long>(h); | 
|  | 246 | } | 
|  | 247 |  | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 248 | extern template class _LIBCPP_VISIBLE collate<char>; | 
|  | 249 | extern template class _LIBCPP_VISIBLE collate<wchar_t>; | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 250 |  | 
|  | 251 | // template <class CharT> class collate_byname; | 
|  | 252 |  | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 253 | template <class _CharT> class _LIBCPP_VISIBLE collate_byname; | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 254 |  | 
|  | 255 | template <> | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 256 | class _LIBCPP_VISIBLE collate_byname<char> | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 257 | : public collate<char> | 
|  | 258 | { | 
|  | 259 | locale_t __l; | 
|  | 260 | public: | 
|  | 261 | typedef char char_type; | 
|  | 262 | typedef basic_string<char_type> string_type; | 
|  | 263 |  | 
|  | 264 | explicit collate_byname(const char* __n, size_t __refs = 0); | 
|  | 265 | explicit collate_byname(const string& __n, size_t __refs = 0); | 
|  | 266 |  | 
|  | 267 | protected: | 
|  | 268 | ~collate_byname(); | 
|  | 269 | virtual int do_compare(const char_type* __lo1, const char_type* __hi1, | 
|  | 270 | const char_type* __lo2, const char_type* __hi2) const; | 
|  | 271 | virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const; | 
|  | 272 | }; | 
|  | 273 |  | 
|  | 274 | template <> | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 275 | class _LIBCPP_VISIBLE collate_byname<wchar_t> | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 276 | : public collate<wchar_t> | 
|  | 277 | { | 
|  | 278 | locale_t __l; | 
|  | 279 | public: | 
|  | 280 | typedef wchar_t char_type; | 
|  | 281 | typedef basic_string<char_type> string_type; | 
|  | 282 |  | 
|  | 283 | explicit collate_byname(const char* __n, size_t __refs = 0); | 
|  | 284 | explicit collate_byname(const string& __n, size_t __refs = 0); | 
|  | 285 |  | 
|  | 286 | protected: | 
|  | 287 | ~collate_byname(); | 
|  | 288 |  | 
|  | 289 | virtual int do_compare(const char_type* __lo1, const char_type* __hi1, | 
|  | 290 | const char_type* __lo2, const char_type* __hi2) const; | 
|  | 291 | virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const; | 
|  | 292 | }; | 
|  | 293 |  | 
|  | 294 | template <class _CharT, class _Traits, class _Allocator> | 
|  | 295 | bool | 
|  | 296 | locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x, | 
|  | 297 | const basic_string<_CharT, _Traits, _Allocator>& __y) const | 
|  | 298 | { | 
| Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 299 | return _VSTD::use_facet<_VSTD::collate<_CharT> >(*this).compare( | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 300 | __x.data(), __x.data() + __x.size(), | 
|  | 301 | __y.data(), __y.data() + __y.size()) < 0; | 
|  | 302 | } | 
|  | 303 |  | 
|  | 304 | // template <class charT> class ctype | 
|  | 305 |  | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 306 | class _LIBCPP_VISIBLE ctype_base | 
|  | 307 | { | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 308 | public: | 
| David Chisnall | 8972813 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 309 | #if __GLIBC__ | 
| Alexis Hunt | 3f60bca | 2011-07-09 00:56:23 +0000 | [diff] [blame] | 310 | typedef unsigned short mask; | 
| Howard Hinnant | 128ba71 | 2010-05-24 17:49:41 +0000 | [diff] [blame] | 311 | static const mask space  = _ISspace; | 
|  | 312 | static const mask print  = _ISprint; | 
|  | 313 | static const mask cntrl  = _IScntrl; | 
|  | 314 | static const mask upper  = _ISupper; | 
|  | 315 | static const mask lower  = _ISlower; | 
|  | 316 | static const mask alpha  = _ISalpha; | 
|  | 317 | static const mask digit  = _ISdigit; | 
|  | 318 | static const mask punct  = _ISpunct; | 
|  | 319 | static const mask xdigit = _ISxdigit; | 
|  | 320 | static const mask blank  = _ISblank; | 
| Howard Hinnant | 3c78ca0 | 2011-09-22 19:10:18 +0000 | [diff] [blame^] | 321 | #elif _WIN32 | 
|  | 322 | typedef unsigned __int32 mask; | 
|  | 323 | static const mask space  = _SPACE; | 
|  | 324 | static const mask print  = _BLANK|_PUNCT|_ALPHA|_DIGIT; | 
|  | 325 | static const mask cntrl  = _CONTROL; | 
|  | 326 | static const mask upper  = _UPPER; | 
|  | 327 | static const mask lower  = _LOWER; | 
|  | 328 | static const mask alpha  = _ALPHA; | 
|  | 329 | static const mask digit  = _DIGIT; | 
|  | 330 | static const mask punct  = _PUNCT; | 
|  | 331 | static const mask xdigit = _HEX; | 
|  | 332 | static const mask blank  = _BLANK; | 
|  | 333 | #else  // __GLIBC__ || _WIN32 | 
| David Chisnall | 8972813 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 334 | #if __APPLE__ | 
|  | 335 | typedef __uint32_t mask; | 
|  | 336 | #elif __FreeBSD__ | 
|  | 337 | typedef unsigned long mask; | 
|  | 338 | #endif | 
|  | 339 | static const mask space  = _CTYPE_S; | 
|  | 340 | static const mask print  = _CTYPE_R; | 
|  | 341 | static const mask cntrl  = _CTYPE_C; | 
|  | 342 | static const mask upper  = _CTYPE_U; | 
|  | 343 | static const mask lower  = _CTYPE_L; | 
|  | 344 | static const mask alpha  = _CTYPE_A; | 
|  | 345 | static const mask digit  = _CTYPE_D; | 
|  | 346 | static const mask punct  = _CTYPE_P; | 
|  | 347 | static const mask xdigit = _CTYPE_X; | 
|  | 348 | static const mask blank  = _CTYPE_B; | 
| Howard Hinnant | 3c78ca0 | 2011-09-22 19:10:18 +0000 | [diff] [blame^] | 349 | #endif  // __GLIBC__ || _WIN32 | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 350 | static const mask alnum  = alpha | digit; | 
|  | 351 | static const mask graph  = alnum | punct; | 
|  | 352 |  | 
|  | 353 | _LIBCPP_ALWAYS_INLINE ctype_base() {} | 
|  | 354 | }; | 
|  | 355 |  | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 356 | template <class _CharT> class _LIBCPP_VISIBLE ctype; | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 357 |  | 
|  | 358 | template <> | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 359 | class _LIBCPP_VISIBLE ctype<wchar_t> | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 360 | : public locale::facet, | 
|  | 361 | public ctype_base | 
|  | 362 | { | 
|  | 363 | public: | 
|  | 364 | typedef wchar_t char_type; | 
| Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 365 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 366 | _LIBCPP_ALWAYS_INLINE | 
|  | 367 | explicit ctype(size_t __refs = 0) | 
|  | 368 | : locale::facet(__refs) {} | 
|  | 369 |  | 
|  | 370 | _LIBCPP_ALWAYS_INLINE | 
|  | 371 | bool is(mask __m, char_type __c) const | 
|  | 372 | { | 
|  | 373 | return do_is(__m, __c); | 
|  | 374 | } | 
|  | 375 |  | 
|  | 376 | _LIBCPP_ALWAYS_INLINE | 
|  | 377 | const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const | 
|  | 378 | { | 
|  | 379 | return do_is(__low, __high, __vec); | 
|  | 380 | } | 
|  | 381 |  | 
|  | 382 | _LIBCPP_ALWAYS_INLINE | 
|  | 383 | const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const | 
|  | 384 | { | 
|  | 385 | return do_scan_is(__m, __low, __high); | 
|  | 386 | } | 
|  | 387 |  | 
|  | 388 | _LIBCPP_ALWAYS_INLINE | 
|  | 389 | const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const | 
|  | 390 | { | 
|  | 391 | return do_scan_not(__m, __low, __high); | 
|  | 392 | } | 
|  | 393 |  | 
|  | 394 | _LIBCPP_ALWAYS_INLINE | 
|  | 395 | char_type toupper(char_type __c) const | 
|  | 396 | { | 
|  | 397 | return do_toupper(__c); | 
|  | 398 | } | 
|  | 399 |  | 
|  | 400 | _LIBCPP_ALWAYS_INLINE | 
|  | 401 | const char_type* toupper(char_type* __low, const char_type* __high) const | 
|  | 402 | { | 
|  | 403 | return do_toupper(__low, __high); | 
|  | 404 | } | 
|  | 405 |  | 
|  | 406 | _LIBCPP_ALWAYS_INLINE | 
|  | 407 | char_type tolower(char_type __c) const | 
|  | 408 | { | 
|  | 409 | return do_tolower(__c); | 
|  | 410 | } | 
|  | 411 |  | 
|  | 412 | _LIBCPP_ALWAYS_INLINE | 
|  | 413 | const char_type* tolower(char_type* __low, const char_type* __high) const | 
|  | 414 | { | 
|  | 415 | return do_tolower(__low, __high); | 
|  | 416 | } | 
|  | 417 |  | 
|  | 418 | _LIBCPP_ALWAYS_INLINE | 
|  | 419 | char_type widen(char __c) const | 
|  | 420 | { | 
|  | 421 | return do_widen(__c); | 
|  | 422 | } | 
|  | 423 |  | 
|  | 424 | _LIBCPP_ALWAYS_INLINE | 
|  | 425 | const char* widen(const char* __low, const char* __high, char_type* __to) const | 
|  | 426 | { | 
|  | 427 | return do_widen(__low, __high, __to); | 
|  | 428 | } | 
|  | 429 |  | 
|  | 430 | _LIBCPP_ALWAYS_INLINE | 
|  | 431 | char narrow(char_type __c, char __dfault) const | 
|  | 432 | { | 
|  | 433 | return do_narrow(__c, __dfault); | 
|  | 434 | } | 
|  | 435 |  | 
|  | 436 | _LIBCPP_ALWAYS_INLINE | 
|  | 437 | const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const | 
|  | 438 | { | 
|  | 439 | return do_narrow(__low, __high, __dfault, __to); | 
|  | 440 | } | 
|  | 441 |  | 
|  | 442 | static locale::id id; | 
|  | 443 |  | 
|  | 444 | protected: | 
|  | 445 | ~ctype(); | 
|  | 446 | virtual bool do_is(mask __m, char_type __c) const; | 
|  | 447 | virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const; | 
|  | 448 | virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const; | 
|  | 449 | virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const; | 
|  | 450 | virtual char_type do_toupper(char_type) const; | 
|  | 451 | virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; | 
|  | 452 | virtual char_type do_tolower(char_type) const; | 
|  | 453 | virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; | 
|  | 454 | virtual char_type do_widen(char) const; | 
|  | 455 | virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const; | 
|  | 456 | virtual char do_narrow(char_type, char __dfault) const; | 
|  | 457 | virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const; | 
|  | 458 | }; | 
|  | 459 |  | 
|  | 460 | template <> | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 461 | class _LIBCPP_VISIBLE ctype<char> | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 462 | : public locale::facet, public ctype_base | 
|  | 463 | { | 
|  | 464 | const mask* __tab_; | 
|  | 465 | bool        __del_; | 
|  | 466 | public: | 
|  | 467 | typedef char char_type; | 
|  | 468 |  | 
|  | 469 | explicit ctype(const mask* __tab = 0, bool __del = false, size_t __refs = 0); | 
|  | 470 |  | 
|  | 471 | _LIBCPP_ALWAYS_INLINE | 
|  | 472 | bool is(mask __m, char_type __c) const | 
|  | 473 | { | 
|  | 474 | return isascii(__c) ? __tab_[__c] & __m : false; | 
|  | 475 | } | 
|  | 476 |  | 
|  | 477 | _LIBCPP_ALWAYS_INLINE | 
|  | 478 | const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const | 
|  | 479 | { | 
|  | 480 | for (; __low != __high; ++__low, ++__vec) | 
|  | 481 | *__vec = isascii(*__low) ? __tab_[*__low] : 0; | 
|  | 482 | return __low; | 
|  | 483 | } | 
|  | 484 |  | 
|  | 485 | _LIBCPP_ALWAYS_INLINE | 
|  | 486 | const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const | 
|  | 487 | { | 
|  | 488 | for (; __low != __high; ++__low) | 
|  | 489 | if (isascii(*__low) && (__tab_[*__low] & __m)) | 
|  | 490 | break; | 
|  | 491 | return __low; | 
|  | 492 | } | 
|  | 493 |  | 
|  | 494 | _LIBCPP_ALWAYS_INLINE | 
|  | 495 | const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const | 
|  | 496 | { | 
|  | 497 | for (; __low != __high; ++__low) | 
|  | 498 | if (!(isascii(*__low) && (__tab_[*__low] & __m))) | 
|  | 499 | break; | 
|  | 500 | return __low; | 
|  | 501 | } | 
|  | 502 |  | 
|  | 503 | _LIBCPP_ALWAYS_INLINE | 
|  | 504 | char_type toupper(char_type __c) const | 
|  | 505 | { | 
|  | 506 | return do_toupper(__c); | 
|  | 507 | } | 
|  | 508 |  | 
|  | 509 | _LIBCPP_ALWAYS_INLINE | 
|  | 510 | const char_type* toupper(char_type* __low, const char_type* __high) const | 
|  | 511 | { | 
|  | 512 | return do_toupper(__low, __high); | 
|  | 513 | } | 
|  | 514 |  | 
|  | 515 | _LIBCPP_ALWAYS_INLINE | 
|  | 516 | char_type tolower(char_type __c) const | 
|  | 517 | { | 
|  | 518 | return do_tolower(__c); | 
|  | 519 | } | 
|  | 520 |  | 
|  | 521 | _LIBCPP_ALWAYS_INLINE | 
|  | 522 | const char_type* tolower(char_type* __low, const char_type* __high) const | 
|  | 523 | { | 
|  | 524 | return do_tolower(__low, __high); | 
|  | 525 | } | 
|  | 526 |  | 
|  | 527 | _LIBCPP_ALWAYS_INLINE | 
|  | 528 | char_type widen(char __c) const | 
|  | 529 | { | 
|  | 530 | return do_widen(__c); | 
|  | 531 | } | 
|  | 532 |  | 
|  | 533 | _LIBCPP_ALWAYS_INLINE | 
|  | 534 | const char* widen(const char* __low, const char* __high, char_type* __to) const | 
|  | 535 | { | 
|  | 536 | return do_widen(__low, __high, __to); | 
|  | 537 | } | 
|  | 538 |  | 
|  | 539 | _LIBCPP_ALWAYS_INLINE | 
|  | 540 | char narrow(char_type __c, char __dfault) const | 
|  | 541 | { | 
|  | 542 | return do_narrow(__c, __dfault); | 
|  | 543 | } | 
|  | 544 |  | 
|  | 545 | _LIBCPP_ALWAYS_INLINE | 
|  | 546 | const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const | 
|  | 547 | { | 
|  | 548 | return do_narrow(__low, __high, __dfault, __to); | 
|  | 549 | } | 
|  | 550 |  | 
|  | 551 | static locale::id id; | 
|  | 552 |  | 
| Howard Hinnant | 128ba71 | 2010-05-24 17:49:41 +0000 | [diff] [blame] | 553 | #ifdef _CACHED_RUNES | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 554 | static const size_t table_size = _CACHED_RUNES; | 
| Howard Hinnant | 128ba71 | 2010-05-24 17:49:41 +0000 | [diff] [blame] | 555 | #else | 
|  | 556 | static const size_t table_size = 256;  // FIXME: Don't hardcode this. | 
|  | 557 | #endif | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 558 | _LIBCPP_ALWAYS_INLINE const mask* table() const  _NOEXCEPT {return __tab_;} | 
|  | 559 | static const mask* classic_table()  _NOEXCEPT; | 
| Alexis Hunt | f023519 | 2011-07-09 01:09:31 +0000 | [diff] [blame] | 560 | #ifndef _LIBCPP_STABLE_APPLE_ABI | 
| Alexis Hunt | 3f60bca | 2011-07-09 00:56:23 +0000 | [diff] [blame] | 561 | static const int* __classic_upper_table() _NOEXCEPT; | 
|  | 562 | static const int* __classic_lower_table() _NOEXCEPT; | 
| Alexis Hunt | f023519 | 2011-07-09 01:09:31 +0000 | [diff] [blame] | 563 | #endif | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 564 |  | 
|  | 565 | protected: | 
|  | 566 | ~ctype(); | 
|  | 567 | virtual char_type do_toupper(char_type __c) const; | 
|  | 568 | virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; | 
|  | 569 | virtual char_type do_tolower(char_type __c) const; | 
|  | 570 | virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; | 
|  | 571 | virtual char_type do_widen(char __c) const; | 
|  | 572 | virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const; | 
|  | 573 | virtual char do_narrow(char_type __c, char __dfault) const; | 
|  | 574 | virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const; | 
|  | 575 | }; | 
|  | 576 |  | 
|  | 577 | // template <class CharT> class ctype_byname; | 
|  | 578 |  | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 579 | template <class _CharT> class _LIBCPP_VISIBLE ctype_byname; | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 580 |  | 
|  | 581 | template <> | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 582 | class _LIBCPP_VISIBLE ctype_byname<char> | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 583 | : public ctype<char> | 
|  | 584 | { | 
|  | 585 | locale_t __l; | 
|  | 586 |  | 
|  | 587 | public: | 
|  | 588 | explicit ctype_byname(const char*, size_t = 0); | 
|  | 589 | explicit ctype_byname(const string&, size_t = 0); | 
|  | 590 |  | 
|  | 591 | protected: | 
|  | 592 | ~ctype_byname(); | 
|  | 593 | virtual char_type do_toupper(char_type) const; | 
|  | 594 | virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; | 
|  | 595 | virtual char_type do_tolower(char_type) const; | 
|  | 596 | virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; | 
|  | 597 | }; | 
|  | 598 |  | 
|  | 599 | template <> | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 600 | class _LIBCPP_VISIBLE ctype_byname<wchar_t> | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 601 | : public ctype<wchar_t> | 
|  | 602 | { | 
|  | 603 | locale_t __l; | 
|  | 604 |  | 
|  | 605 | public: | 
|  | 606 | explicit ctype_byname(const char*, size_t = 0); | 
|  | 607 | explicit ctype_byname(const string&, size_t = 0); | 
|  | 608 |  | 
|  | 609 | protected: | 
|  | 610 | ~ctype_byname(); | 
|  | 611 | virtual bool do_is(mask __m, char_type __c) const; | 
|  | 612 | virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const; | 
|  | 613 | virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const; | 
|  | 614 | virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const; | 
|  | 615 | virtual char_type do_toupper(char_type) const; | 
|  | 616 | virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; | 
|  | 617 | virtual char_type do_tolower(char_type) const; | 
|  | 618 | virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; | 
|  | 619 | virtual char_type do_widen(char) const; | 
|  | 620 | virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const; | 
|  | 621 | virtual char do_narrow(char_type, char __dfault) const; | 
|  | 622 | virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const; | 
|  | 623 | }; | 
|  | 624 |  | 
|  | 625 | template <class _CharT> | 
|  | 626 | inline _LIBCPP_INLINE_VISIBILITY | 
|  | 627 | bool | 
|  | 628 | isspace(_CharT __c, const locale& __loc) | 
|  | 629 | { | 
|  | 630 | return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c); | 
|  | 631 | } | 
|  | 632 |  | 
|  | 633 | template <class _CharT> | 
|  | 634 | inline _LIBCPP_INLINE_VISIBILITY | 
|  | 635 | bool | 
|  | 636 | isprint(_CharT __c, const locale& __loc) | 
|  | 637 | { | 
|  | 638 | return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c); | 
|  | 639 | } | 
|  | 640 |  | 
|  | 641 | template <class _CharT> | 
|  | 642 | inline _LIBCPP_INLINE_VISIBILITY | 
|  | 643 | bool | 
|  | 644 | iscntrl(_CharT __c, const locale& __loc) | 
|  | 645 | { | 
|  | 646 | return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c); | 
|  | 647 | } | 
|  | 648 |  | 
|  | 649 | template <class _CharT> | 
|  | 650 | inline _LIBCPP_INLINE_VISIBILITY | 
|  | 651 | bool | 
|  | 652 | isupper(_CharT __c, const locale& __loc) | 
|  | 653 | { | 
|  | 654 | return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c); | 
|  | 655 | } | 
|  | 656 |  | 
|  | 657 | template <class _CharT> | 
|  | 658 | inline _LIBCPP_INLINE_VISIBILITY | 
|  | 659 | bool | 
|  | 660 | islower(_CharT __c, const locale& __loc) | 
|  | 661 | { | 
|  | 662 | return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c); | 
|  | 663 | } | 
|  | 664 |  | 
|  | 665 | template <class _CharT> | 
|  | 666 | inline _LIBCPP_INLINE_VISIBILITY | 
|  | 667 | bool | 
|  | 668 | isalpha(_CharT __c, const locale& __loc) | 
|  | 669 | { | 
|  | 670 | return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c); | 
|  | 671 | } | 
|  | 672 |  | 
|  | 673 | template <class _CharT> | 
|  | 674 | inline _LIBCPP_INLINE_VISIBILITY | 
|  | 675 | bool | 
|  | 676 | isdigit(_CharT __c, const locale& __loc) | 
|  | 677 | { | 
|  | 678 | return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c); | 
|  | 679 | } | 
|  | 680 |  | 
|  | 681 | template <class _CharT> | 
|  | 682 | inline _LIBCPP_INLINE_VISIBILITY | 
|  | 683 | bool | 
|  | 684 | ispunct(_CharT __c, const locale& __loc) | 
|  | 685 | { | 
|  | 686 | return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c); | 
|  | 687 | } | 
|  | 688 |  | 
|  | 689 | template <class _CharT> | 
|  | 690 | inline _LIBCPP_INLINE_VISIBILITY | 
|  | 691 | bool | 
|  | 692 | isxdigit(_CharT __c, const locale& __loc) | 
|  | 693 | { | 
|  | 694 | return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c); | 
|  | 695 | } | 
|  | 696 |  | 
|  | 697 | template <class _CharT> | 
|  | 698 | inline _LIBCPP_INLINE_VISIBILITY | 
|  | 699 | bool | 
|  | 700 | isalnum(_CharT __c, const locale& __loc) | 
|  | 701 | { | 
|  | 702 | return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c); | 
|  | 703 | } | 
|  | 704 |  | 
|  | 705 | template <class _CharT> | 
|  | 706 | inline _LIBCPP_INLINE_VISIBILITY | 
|  | 707 | bool | 
|  | 708 | isgraph(_CharT __c, const locale& __loc) | 
|  | 709 | { | 
|  | 710 | return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c); | 
|  | 711 | } | 
|  | 712 |  | 
|  | 713 | template <class _CharT> | 
|  | 714 | inline _LIBCPP_INLINE_VISIBILITY | 
|  | 715 | _CharT | 
|  | 716 | toupper(_CharT __c, const locale& __loc) | 
|  | 717 | { | 
|  | 718 | return use_facet<ctype<_CharT> >(__loc).toupper(__c); | 
|  | 719 | } | 
|  | 720 |  | 
|  | 721 | template <class _CharT> | 
|  | 722 | inline _LIBCPP_INLINE_VISIBILITY | 
|  | 723 | _CharT | 
|  | 724 | tolower(_CharT __c, const locale& __loc) | 
|  | 725 | { | 
|  | 726 | return use_facet<ctype<_CharT> >(__loc).tolower(__c); | 
|  | 727 | } | 
|  | 728 |  | 
|  | 729 | // codecvt_base | 
|  | 730 |  | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 731 | class _LIBCPP_VISIBLE codecvt_base | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 732 | { | 
|  | 733 | public: | 
|  | 734 | _LIBCPP_ALWAYS_INLINE codecvt_base() {} | 
|  | 735 | enum result {ok, partial, error, noconv}; | 
|  | 736 | }; | 
|  | 737 |  | 
|  | 738 | // template <class internT, class externT, class stateT> class codecvt; | 
|  | 739 |  | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 740 | template <class _InternT, class _ExternT, class _StateT> class _LIBCPP_VISIBLE codecvt; | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 741 |  | 
|  | 742 | // template <> class codecvt<char, char, mbstate_t> | 
|  | 743 |  | 
|  | 744 | template <> | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 745 | class _LIBCPP_VISIBLE codecvt<char, char, mbstate_t> | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 746 | : public locale::facet, | 
|  | 747 | public codecvt_base | 
|  | 748 | { | 
|  | 749 | public: | 
|  | 750 | typedef char      intern_type; | 
|  | 751 | typedef char      extern_type; | 
|  | 752 | typedef mbstate_t state_type; | 
|  | 753 |  | 
|  | 754 | _LIBCPP_ALWAYS_INLINE | 
|  | 755 | explicit codecvt(size_t __refs = 0) | 
|  | 756 | : locale::facet(__refs) {} | 
|  | 757 |  | 
|  | 758 | _LIBCPP_ALWAYS_INLINE | 
|  | 759 | result out(state_type& __st, | 
|  | 760 | const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, | 
|  | 761 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const | 
|  | 762 | { | 
|  | 763 | return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); | 
|  | 764 | } | 
|  | 765 |  | 
|  | 766 | _LIBCPP_ALWAYS_INLINE | 
|  | 767 | result unshift(state_type& __st, | 
|  | 768 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const | 
|  | 769 | { | 
|  | 770 | return do_unshift(__st, __to, __to_end, __to_nxt); | 
|  | 771 | } | 
|  | 772 |  | 
|  | 773 | _LIBCPP_ALWAYS_INLINE | 
|  | 774 | result in(state_type& __st, | 
|  | 775 | const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, | 
|  | 776 | intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const | 
|  | 777 | { | 
|  | 778 | return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); | 
|  | 779 | } | 
|  | 780 |  | 
|  | 781 | _LIBCPP_ALWAYS_INLINE | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 782 | int encoding() const  _NOEXCEPT | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 783 | { | 
|  | 784 | return do_encoding(); | 
|  | 785 | } | 
|  | 786 |  | 
|  | 787 | _LIBCPP_ALWAYS_INLINE | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 788 | bool always_noconv() const  _NOEXCEPT | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 789 | { | 
|  | 790 | return do_always_noconv(); | 
|  | 791 | } | 
|  | 792 |  | 
|  | 793 | _LIBCPP_ALWAYS_INLINE | 
|  | 794 | int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const | 
|  | 795 | { | 
|  | 796 | return do_length(__st, __frm, __end, __mx); | 
|  | 797 | } | 
|  | 798 |  | 
|  | 799 | _LIBCPP_ALWAYS_INLINE | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 800 | int max_length() const  _NOEXCEPT | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 801 | { | 
|  | 802 | return do_max_length(); | 
|  | 803 | } | 
|  | 804 |  | 
|  | 805 | static locale::id id; | 
|  | 806 |  | 
|  | 807 | protected: | 
|  | 808 | _LIBCPP_ALWAYS_INLINE | 
|  | 809 | explicit codecvt(const char*, size_t __refs = 0) | 
|  | 810 | : locale::facet(__refs) {} | 
|  | 811 |  | 
|  | 812 | ~codecvt(); | 
|  | 813 |  | 
|  | 814 | virtual result do_out(state_type& __st, | 
|  | 815 | const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, | 
|  | 816 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; | 
|  | 817 | virtual result do_in(state_type& __st, | 
|  | 818 | const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, | 
|  | 819 | intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; | 
|  | 820 | virtual result do_unshift(state_type& __st, | 
|  | 821 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 822 | virtual int do_encoding() const  _NOEXCEPT; | 
|  | 823 | virtual bool do_always_noconv() const  _NOEXCEPT; | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 824 | virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const; | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 825 | virtual int do_max_length() const  _NOEXCEPT; | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 826 | }; | 
|  | 827 |  | 
|  | 828 | // template <> class codecvt<wchar_t, char, mbstate_t> | 
|  | 829 |  | 
|  | 830 | template <> | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 831 | class _LIBCPP_VISIBLE codecvt<wchar_t, char, mbstate_t> | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 832 | : public locale::facet, | 
|  | 833 | public codecvt_base | 
|  | 834 | { | 
|  | 835 | locale_t __l; | 
|  | 836 | public: | 
|  | 837 | typedef wchar_t   intern_type; | 
|  | 838 | typedef char      extern_type; | 
|  | 839 | typedef mbstate_t state_type; | 
|  | 840 |  | 
|  | 841 | explicit codecvt(size_t __refs = 0); | 
|  | 842 |  | 
|  | 843 | _LIBCPP_ALWAYS_INLINE | 
|  | 844 | result out(state_type& __st, | 
|  | 845 | const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, | 
|  | 846 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const | 
|  | 847 | { | 
|  | 848 | return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); | 
|  | 849 | } | 
|  | 850 |  | 
|  | 851 | _LIBCPP_ALWAYS_INLINE | 
|  | 852 | result unshift(state_type& __st, | 
|  | 853 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const | 
|  | 854 | { | 
|  | 855 | return do_unshift(__st, __to, __to_end, __to_nxt); | 
|  | 856 | } | 
|  | 857 |  | 
|  | 858 | _LIBCPP_ALWAYS_INLINE | 
|  | 859 | result in(state_type& __st, | 
|  | 860 | const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, | 
|  | 861 | intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const | 
|  | 862 | { | 
|  | 863 | return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); | 
|  | 864 | } | 
|  | 865 |  | 
|  | 866 | _LIBCPP_ALWAYS_INLINE | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 867 | int encoding() const  _NOEXCEPT | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 868 | { | 
|  | 869 | return do_encoding(); | 
|  | 870 | } | 
|  | 871 |  | 
|  | 872 | _LIBCPP_ALWAYS_INLINE | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 873 | bool always_noconv() const  _NOEXCEPT | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 874 | { | 
|  | 875 | return do_always_noconv(); | 
|  | 876 | } | 
|  | 877 |  | 
|  | 878 | _LIBCPP_ALWAYS_INLINE | 
|  | 879 | int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const | 
|  | 880 | { | 
|  | 881 | return do_length(__st, __frm, __end, __mx); | 
|  | 882 | } | 
|  | 883 |  | 
|  | 884 | _LIBCPP_ALWAYS_INLINE | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 885 | int max_length() const  _NOEXCEPT | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 886 | { | 
|  | 887 | return do_max_length(); | 
|  | 888 | } | 
|  | 889 |  | 
|  | 890 | static locale::id id; | 
|  | 891 |  | 
|  | 892 | protected: | 
|  | 893 | explicit codecvt(const char*, size_t __refs = 0); | 
|  | 894 |  | 
|  | 895 | ~codecvt(); | 
|  | 896 |  | 
|  | 897 | virtual result do_out(state_type& __st, | 
|  | 898 | const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, | 
|  | 899 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; | 
|  | 900 | virtual result do_in(state_type& __st, | 
|  | 901 | const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, | 
|  | 902 | intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; | 
|  | 903 | virtual result do_unshift(state_type& __st, | 
|  | 904 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 905 | virtual int do_encoding() const  _NOEXCEPT; | 
|  | 906 | virtual bool do_always_noconv() const  _NOEXCEPT; | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 907 | virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 908 | virtual int do_max_length() const  _NOEXCEPT; | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 909 | }; | 
|  | 910 |  | 
|  | 911 | // template <> class codecvt<char16_t, char, mbstate_t> | 
|  | 912 |  | 
|  | 913 | template <> | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 914 | class _LIBCPP_VISIBLE codecvt<char16_t, char, mbstate_t> | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 915 | : public locale::facet, | 
|  | 916 | public codecvt_base | 
|  | 917 | { | 
|  | 918 | public: | 
|  | 919 | typedef char16_t  intern_type; | 
|  | 920 | typedef char      extern_type; | 
|  | 921 | typedef mbstate_t state_type; | 
|  | 922 |  | 
|  | 923 | _LIBCPP_ALWAYS_INLINE | 
|  | 924 | explicit codecvt(size_t __refs = 0) | 
|  | 925 | : locale::facet(__refs) {} | 
|  | 926 |  | 
|  | 927 | _LIBCPP_ALWAYS_INLINE | 
|  | 928 | result out(state_type& __st, | 
|  | 929 | const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, | 
|  | 930 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const | 
|  | 931 | { | 
|  | 932 | return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); | 
|  | 933 | } | 
|  | 934 |  | 
|  | 935 | _LIBCPP_ALWAYS_INLINE | 
|  | 936 | result unshift(state_type& __st, | 
|  | 937 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const | 
|  | 938 | { | 
|  | 939 | return do_unshift(__st, __to, __to_end, __to_nxt); | 
|  | 940 | } | 
|  | 941 |  | 
|  | 942 | _LIBCPP_ALWAYS_INLINE | 
|  | 943 | result in(state_type& __st, | 
|  | 944 | const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, | 
|  | 945 | intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const | 
|  | 946 | { | 
|  | 947 | return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); | 
|  | 948 | } | 
|  | 949 |  | 
|  | 950 | _LIBCPP_ALWAYS_INLINE | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 951 | int encoding() const  _NOEXCEPT | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 952 | { | 
|  | 953 | return do_encoding(); | 
|  | 954 | } | 
|  | 955 |  | 
|  | 956 | _LIBCPP_ALWAYS_INLINE | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 957 | bool always_noconv() const  _NOEXCEPT | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 958 | { | 
|  | 959 | return do_always_noconv(); | 
|  | 960 | } | 
|  | 961 |  | 
|  | 962 | _LIBCPP_ALWAYS_INLINE | 
|  | 963 | int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const | 
|  | 964 | { | 
|  | 965 | return do_length(__st, __frm, __end, __mx); | 
|  | 966 | } | 
|  | 967 |  | 
|  | 968 | _LIBCPP_ALWAYS_INLINE | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 969 | int max_length() const  _NOEXCEPT | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 970 | { | 
|  | 971 | return do_max_length(); | 
|  | 972 | } | 
|  | 973 |  | 
|  | 974 | static locale::id id; | 
|  | 975 |  | 
|  | 976 | protected: | 
|  | 977 | _LIBCPP_ALWAYS_INLINE | 
|  | 978 | explicit codecvt(const char*, size_t __refs = 0) | 
|  | 979 | : locale::facet(__refs) {} | 
|  | 980 |  | 
|  | 981 | ~codecvt(); | 
|  | 982 |  | 
|  | 983 | virtual result do_out(state_type& __st, | 
|  | 984 | const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, | 
|  | 985 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; | 
|  | 986 | virtual result do_in(state_type& __st, | 
|  | 987 | const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, | 
|  | 988 | intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; | 
|  | 989 | virtual result do_unshift(state_type& __st, | 
|  | 990 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 991 | virtual int do_encoding() const  _NOEXCEPT; | 
|  | 992 | virtual bool do_always_noconv() const  _NOEXCEPT; | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 993 | virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 994 | virtual int do_max_length() const  _NOEXCEPT; | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 995 | }; | 
|  | 996 |  | 
|  | 997 | // template <> class codecvt<char32_t, char, mbstate_t> | 
|  | 998 |  | 
|  | 999 | template <> | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 1000 | class _LIBCPP_VISIBLE codecvt<char32_t, char, mbstate_t> | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1001 | : public locale::facet, | 
|  | 1002 | public codecvt_base | 
|  | 1003 | { | 
|  | 1004 | public: | 
|  | 1005 | typedef char32_t  intern_type; | 
|  | 1006 | typedef char      extern_type; | 
|  | 1007 | typedef mbstate_t state_type; | 
|  | 1008 |  | 
|  | 1009 | _LIBCPP_ALWAYS_INLINE | 
|  | 1010 | explicit codecvt(size_t __refs = 0) | 
|  | 1011 | : locale::facet(__refs) {} | 
|  | 1012 |  | 
|  | 1013 | _LIBCPP_ALWAYS_INLINE | 
|  | 1014 | result out(state_type& __st, | 
|  | 1015 | const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, | 
|  | 1016 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const | 
|  | 1017 | { | 
|  | 1018 | return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); | 
|  | 1019 | } | 
|  | 1020 |  | 
|  | 1021 | _LIBCPP_ALWAYS_INLINE | 
|  | 1022 | result unshift(state_type& __st, | 
|  | 1023 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const | 
|  | 1024 | { | 
|  | 1025 | return do_unshift(__st, __to, __to_end, __to_nxt); | 
|  | 1026 | } | 
|  | 1027 |  | 
|  | 1028 | _LIBCPP_ALWAYS_INLINE | 
|  | 1029 | result in(state_type& __st, | 
|  | 1030 | const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, | 
|  | 1031 | intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const | 
|  | 1032 | { | 
|  | 1033 | return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); | 
|  | 1034 | } | 
|  | 1035 |  | 
|  | 1036 | _LIBCPP_ALWAYS_INLINE | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 1037 | int encoding() const  _NOEXCEPT | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1038 | { | 
|  | 1039 | return do_encoding(); | 
|  | 1040 | } | 
|  | 1041 |  | 
|  | 1042 | _LIBCPP_ALWAYS_INLINE | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 1043 | bool always_noconv() const  _NOEXCEPT | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1044 | { | 
|  | 1045 | return do_always_noconv(); | 
|  | 1046 | } | 
|  | 1047 |  | 
|  | 1048 | _LIBCPP_ALWAYS_INLINE | 
|  | 1049 | int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const | 
|  | 1050 | { | 
|  | 1051 | return do_length(__st, __frm, __end, __mx); | 
|  | 1052 | } | 
|  | 1053 |  | 
|  | 1054 | _LIBCPP_ALWAYS_INLINE | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 1055 | int max_length() const  _NOEXCEPT | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1056 | { | 
|  | 1057 | return do_max_length(); | 
|  | 1058 | } | 
|  | 1059 |  | 
|  | 1060 | static locale::id id; | 
|  | 1061 |  | 
|  | 1062 | protected: | 
|  | 1063 | _LIBCPP_ALWAYS_INLINE | 
|  | 1064 | explicit codecvt(const char*, size_t __refs = 0) | 
|  | 1065 | : locale::facet(__refs) {} | 
|  | 1066 |  | 
|  | 1067 | ~codecvt(); | 
|  | 1068 |  | 
|  | 1069 | virtual result do_out(state_type& __st, | 
|  | 1070 | const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, | 
|  | 1071 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; | 
|  | 1072 | virtual result do_in(state_type& __st, | 
|  | 1073 | const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, | 
|  | 1074 | intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; | 
|  | 1075 | virtual result do_unshift(state_type& __st, | 
|  | 1076 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 1077 | virtual int do_encoding() const  _NOEXCEPT; | 
|  | 1078 | virtual bool do_always_noconv() const  _NOEXCEPT; | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1079 | virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; | 
| Howard Hinnant | b5d866d | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 1080 | virtual int do_max_length() const  _NOEXCEPT; | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1081 | }; | 
|  | 1082 |  | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1083 | // template <class _InternT, class _ExternT, class _StateT> class codecvt_byname | 
|  | 1084 |  | 
|  | 1085 | template <class _InternT, class _ExternT, class _StateT> | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 1086 | class _LIBCPP_VISIBLE codecvt_byname | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1087 | : public codecvt<_InternT, _ExternT, _StateT> | 
|  | 1088 | { | 
|  | 1089 | public: | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 1090 | _LIBCPP_ALWAYS_INLINE | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1091 | explicit codecvt_byname(const char* __nm, size_t __refs = 0) | 
|  | 1092 | : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {} | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 1093 | _LIBCPP_ALWAYS_INLINE | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1094 | explicit codecvt_byname(const string& __nm, size_t __refs = 0) | 
|  | 1095 | : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {} | 
|  | 1096 | protected: | 
|  | 1097 | ~codecvt_byname(); | 
|  | 1098 | }; | 
|  | 1099 |  | 
|  | 1100 | template <class _InternT, class _ExternT, class _StateT> | 
|  | 1101 | codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname() | 
|  | 1102 | { | 
|  | 1103 | } | 
|  | 1104 |  | 
|  | 1105 | extern template class codecvt_byname<char, char, mbstate_t>; | 
|  | 1106 | extern template class codecvt_byname<wchar_t, char, mbstate_t>; | 
|  | 1107 | extern template class codecvt_byname<char16_t, char, mbstate_t>; | 
|  | 1108 | extern template class codecvt_byname<char32_t, char, mbstate_t>; | 
|  | 1109 |  | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 1110 | _LIBCPP_VISIBLE void __throw_runtime_error(const char*); | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1111 |  | 
|  | 1112 | template <size_t _N> | 
|  | 1113 | struct __narrow_to_utf8 | 
|  | 1114 | { | 
|  | 1115 | template <class _OutputIterator, class _CharT> | 
|  | 1116 | _OutputIterator | 
|  | 1117 | operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const; | 
|  | 1118 | }; | 
|  | 1119 |  | 
|  | 1120 | template <> | 
|  | 1121 | struct __narrow_to_utf8<8> | 
|  | 1122 | { | 
|  | 1123 | template <class _OutputIterator, class _CharT> | 
|  | 1124 | _LIBCPP_ALWAYS_INLINE | 
|  | 1125 | _OutputIterator | 
|  | 1126 | operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const | 
|  | 1127 | { | 
|  | 1128 | for (; __wb < __we; ++__wb, ++__s) | 
|  | 1129 | *__s = *__wb; | 
|  | 1130 | return __s; | 
|  | 1131 | } | 
|  | 1132 | }; | 
|  | 1133 |  | 
|  | 1134 | template <> | 
|  | 1135 | struct __narrow_to_utf8<16> | 
|  | 1136 | : public codecvt<char16_t, char, mbstate_t> | 
|  | 1137 | { | 
|  | 1138 | _LIBCPP_ALWAYS_INLINE | 
|  | 1139 | __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {} | 
|  | 1140 |  | 
|  | 1141 | ~__narrow_to_utf8(); | 
|  | 1142 |  | 
|  | 1143 | template <class _OutputIterator, class _CharT> | 
|  | 1144 | _LIBCPP_ALWAYS_INLINE | 
|  | 1145 | _OutputIterator | 
|  | 1146 | operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const | 
|  | 1147 | { | 
|  | 1148 | result __r = ok; | 
|  | 1149 | mbstate_t __mb; | 
|  | 1150 | while (__wb < __we && __r != error) | 
|  | 1151 | { | 
|  | 1152 | const int __sz = 32; | 
|  | 1153 | char __buf[__sz]; | 
|  | 1154 | char* __bn; | 
|  | 1155 | const char16_t* __wn = (const char16_t*)__wb; | 
|  | 1156 | __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn, | 
|  | 1157 | __buf, __buf+__sz, __bn); | 
|  | 1158 | if (__r == codecvt_base::error || __wn == (const char16_t*)__wb) | 
|  | 1159 | __throw_runtime_error("locale not supported"); | 
|  | 1160 | for (const char* __p = __buf; __p < __bn; ++__p, ++__s) | 
|  | 1161 | *__s = *__p; | 
|  | 1162 | __wb = (const _CharT*)__wn; | 
|  | 1163 | } | 
|  | 1164 | return __s; | 
|  | 1165 | } | 
|  | 1166 | }; | 
|  | 1167 |  | 
|  | 1168 | template <> | 
|  | 1169 | struct __narrow_to_utf8<32> | 
|  | 1170 | : public codecvt<char32_t, char, mbstate_t> | 
|  | 1171 | { | 
|  | 1172 | _LIBCPP_ALWAYS_INLINE | 
|  | 1173 | __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {} | 
|  | 1174 |  | 
|  | 1175 | ~__narrow_to_utf8(); | 
|  | 1176 |  | 
|  | 1177 | template <class _OutputIterator, class _CharT> | 
|  | 1178 | _LIBCPP_ALWAYS_INLINE | 
|  | 1179 | _OutputIterator | 
|  | 1180 | operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const | 
|  | 1181 | { | 
|  | 1182 | result __r = ok; | 
|  | 1183 | mbstate_t __mb; | 
|  | 1184 | while (__wb < __we && __r != error) | 
|  | 1185 | { | 
|  | 1186 | const int __sz = 32; | 
|  | 1187 | char __buf[__sz]; | 
|  | 1188 | char* __bn; | 
|  | 1189 | const char32_t* __wn = (const char32_t*)__wb; | 
|  | 1190 | __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn, | 
|  | 1191 | __buf, __buf+__sz, __bn); | 
|  | 1192 | if (__r == codecvt_base::error || __wn == (const char32_t*)__wb) | 
|  | 1193 | __throw_runtime_error("locale not supported"); | 
|  | 1194 | for (const char* __p = __buf; __p < __bn; ++__p, ++__s) | 
|  | 1195 | *__s = *__p; | 
|  | 1196 | __wb = (const _CharT*)__wn; | 
|  | 1197 | } | 
|  | 1198 | return __s; | 
|  | 1199 | } | 
|  | 1200 | }; | 
|  | 1201 |  | 
|  | 1202 | template <size_t _N> | 
|  | 1203 | struct __widen_from_utf8 | 
|  | 1204 | { | 
|  | 1205 | template <class _OutputIterator> | 
|  | 1206 | _OutputIterator | 
|  | 1207 | operator()(_OutputIterator __s, const char* __nb, const char* __ne) const; | 
|  | 1208 | }; | 
|  | 1209 |  | 
|  | 1210 | template <> | 
|  | 1211 | struct __widen_from_utf8<8> | 
|  | 1212 | { | 
|  | 1213 | template <class _OutputIterator> | 
|  | 1214 | _LIBCPP_ALWAYS_INLINE | 
|  | 1215 | _OutputIterator | 
|  | 1216 | operator()(_OutputIterator __s, const char* __nb, const char* __ne) const | 
|  | 1217 | { | 
|  | 1218 | for (; __nb < __ne; ++__nb, ++__s) | 
|  | 1219 | *__s = *__nb; | 
|  | 1220 | return __s; | 
|  | 1221 | } | 
|  | 1222 | }; | 
|  | 1223 |  | 
|  | 1224 | template <> | 
|  | 1225 | struct __widen_from_utf8<16> | 
|  | 1226 | : public codecvt<char16_t, char, mbstate_t> | 
|  | 1227 | { | 
|  | 1228 | _LIBCPP_ALWAYS_INLINE | 
|  | 1229 | __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {} | 
|  | 1230 |  | 
|  | 1231 | ~__widen_from_utf8(); | 
|  | 1232 |  | 
|  | 1233 | template <class _OutputIterator> | 
|  | 1234 | _LIBCPP_ALWAYS_INLINE | 
|  | 1235 | _OutputIterator | 
|  | 1236 | operator()(_OutputIterator __s, const char* __nb, const char* __ne) const | 
|  | 1237 | { | 
|  | 1238 | result __r = ok; | 
|  | 1239 | mbstate_t __mb; | 
|  | 1240 | while (__nb < __ne && __r != error) | 
|  | 1241 | { | 
|  | 1242 | const int __sz = 32; | 
|  | 1243 | char16_t __buf[__sz]; | 
|  | 1244 | char16_t* __bn; | 
|  | 1245 | const char* __nn = __nb; | 
|  | 1246 | __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn, | 
|  | 1247 | __buf, __buf+__sz, __bn); | 
|  | 1248 | if (__r == codecvt_base::error || __nn == __nb) | 
|  | 1249 | __throw_runtime_error("locale not supported"); | 
|  | 1250 | for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s) | 
|  | 1251 | *__s = (wchar_t)*__p; | 
|  | 1252 | __nb = __nn; | 
|  | 1253 | } | 
|  | 1254 | return __s; | 
|  | 1255 | } | 
|  | 1256 | }; | 
|  | 1257 |  | 
|  | 1258 | template <> | 
|  | 1259 | struct __widen_from_utf8<32> | 
|  | 1260 | : public codecvt<char32_t, char, mbstate_t> | 
|  | 1261 | { | 
|  | 1262 | _LIBCPP_ALWAYS_INLINE | 
|  | 1263 | __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {} | 
|  | 1264 |  | 
|  | 1265 | ~__widen_from_utf8(); | 
|  | 1266 |  | 
|  | 1267 | template <class _OutputIterator> | 
|  | 1268 | _LIBCPP_ALWAYS_INLINE | 
|  | 1269 | _OutputIterator | 
|  | 1270 | operator()(_OutputIterator __s, const char* __nb, const char* __ne) const | 
|  | 1271 | { | 
|  | 1272 | result __r = ok; | 
|  | 1273 | mbstate_t __mb; | 
|  | 1274 | while (__nb < __ne && __r != error) | 
|  | 1275 | { | 
|  | 1276 | const int __sz = 32; | 
|  | 1277 | char32_t __buf[__sz]; | 
|  | 1278 | char32_t* __bn; | 
|  | 1279 | const char* __nn = __nb; | 
|  | 1280 | __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn, | 
|  | 1281 | __buf, __buf+__sz, __bn); | 
|  | 1282 | if (__r == codecvt_base::error || __nn == __nb) | 
|  | 1283 | __throw_runtime_error("locale not supported"); | 
|  | 1284 | for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s) | 
|  | 1285 | *__s = (wchar_t)*__p; | 
|  | 1286 | __nb = __nn; | 
|  | 1287 | } | 
|  | 1288 | return __s; | 
|  | 1289 | } | 
|  | 1290 | }; | 
|  | 1291 |  | 
|  | 1292 | // template <class charT> class numpunct | 
|  | 1293 |  | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 1294 | template <class _CharT> class _LIBCPP_VISIBLE numpunct; | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1295 |  | 
|  | 1296 | template <> | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 1297 | class _LIBCPP_VISIBLE numpunct<char> | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1298 | : public locale::facet | 
|  | 1299 | { | 
|  | 1300 | public: | 
|  | 1301 | typedef char char_type; | 
|  | 1302 | typedef basic_string<char_type> string_type; | 
|  | 1303 |  | 
|  | 1304 | explicit numpunct(size_t __refs = 0); | 
|  | 1305 |  | 
|  | 1306 | _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();} | 
|  | 1307 | _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();} | 
|  | 1308 | _LIBCPP_ALWAYS_INLINE string grouping() const         {return do_grouping();} | 
|  | 1309 | _LIBCPP_ALWAYS_INLINE string_type truename() const    {return do_truename();} | 
|  | 1310 | _LIBCPP_ALWAYS_INLINE string_type falsename() const   {return do_falsename();} | 
|  | 1311 |  | 
|  | 1312 | static locale::id id; | 
|  | 1313 |  | 
|  | 1314 | protected: | 
|  | 1315 | ~numpunct(); | 
|  | 1316 | virtual char_type do_decimal_point() const; | 
|  | 1317 | virtual char_type do_thousands_sep() const; | 
|  | 1318 | virtual string do_grouping() const; | 
|  | 1319 | virtual string_type do_truename() const; | 
|  | 1320 | virtual string_type do_falsename() const; | 
|  | 1321 |  | 
|  | 1322 | char_type __decimal_point_; | 
|  | 1323 | char_type __thousands_sep_; | 
|  | 1324 | string __grouping_; | 
|  | 1325 | }; | 
|  | 1326 |  | 
|  | 1327 | template <> | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 1328 | class _LIBCPP_VISIBLE numpunct<wchar_t> | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1329 | : public locale::facet | 
|  | 1330 | { | 
|  | 1331 | public: | 
|  | 1332 | typedef wchar_t char_type; | 
|  | 1333 | typedef basic_string<char_type> string_type; | 
|  | 1334 |  | 
|  | 1335 | explicit numpunct(size_t __refs = 0); | 
|  | 1336 |  | 
|  | 1337 | _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();} | 
|  | 1338 | _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();} | 
|  | 1339 | _LIBCPP_ALWAYS_INLINE string grouping() const         {return do_grouping();} | 
|  | 1340 | _LIBCPP_ALWAYS_INLINE string_type truename() const    {return do_truename();} | 
|  | 1341 | _LIBCPP_ALWAYS_INLINE string_type falsename() const   {return do_falsename();} | 
|  | 1342 |  | 
|  | 1343 | static locale::id id; | 
|  | 1344 |  | 
|  | 1345 | protected: | 
|  | 1346 | ~numpunct(); | 
|  | 1347 | virtual char_type do_decimal_point() const; | 
|  | 1348 | virtual char_type do_thousands_sep() const; | 
|  | 1349 | virtual string do_grouping() const; | 
|  | 1350 | virtual string_type do_truename() const; | 
|  | 1351 | virtual string_type do_falsename() const; | 
|  | 1352 |  | 
|  | 1353 | char_type __decimal_point_; | 
|  | 1354 | char_type __thousands_sep_; | 
|  | 1355 | string __grouping_; | 
|  | 1356 | }; | 
|  | 1357 |  | 
|  | 1358 | // template <class charT> class numpunct_byname | 
|  | 1359 |  | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 1360 | template <class charT> class _LIBCPP_VISIBLE numpunct_byname; | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1361 |  | 
|  | 1362 | template <> | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 1363 | class _LIBCPP_VISIBLE numpunct_byname<char> | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1364 | : public numpunct<char> | 
|  | 1365 | { | 
|  | 1366 | public: | 
|  | 1367 | typedef char char_type; | 
|  | 1368 | typedef basic_string<char_type> string_type; | 
|  | 1369 |  | 
|  | 1370 | explicit numpunct_byname(const char* __nm, size_t __refs = 0); | 
|  | 1371 | explicit numpunct_byname(const string& __nm, size_t __refs = 0); | 
|  | 1372 |  | 
|  | 1373 | protected: | 
|  | 1374 | ~numpunct_byname(); | 
|  | 1375 |  | 
|  | 1376 | private: | 
|  | 1377 | void __init(const char*); | 
|  | 1378 | }; | 
|  | 1379 |  | 
|  | 1380 | template <> | 
| Howard Hinnant | 35ae4a2 | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 1381 | class _LIBCPP_VISIBLE numpunct_byname<wchar_t> | 
| Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1382 | : public numpunct<wchar_t> | 
|  | 1383 | { | 
|  | 1384 | public: | 
|  | 1385 | typedef wchar_t char_type; | 
|  | 1386 | typedef basic_string<char_type> string_type; | 
|  | 1387 |  | 
|  | 1388 | explicit numpunct_byname(const char* __nm, size_t __refs = 0); | 
|  | 1389 | explicit numpunct_byname(const string& __nm, size_t __refs = 0); | 
|  | 1390 |  | 
|  | 1391 | protected: | 
|  | 1392 | ~numpunct_byname(); | 
|  | 1393 |  | 
|  | 1394 | private: | 
|  | 1395 | void __init(const char*); | 
|  | 1396 | }; | 
|  | 1397 |  | 
|  | 1398 | _LIBCPP_END_NAMESPACE_STD | 
|  | 1399 |  | 
|  | 1400 | #endif  // _LIBCPP___LOCALE |