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