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