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