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