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