Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
Chandler Carruth | d201210 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP___LOCALE |
| 11 | #define _LIBCPP___LOCALE |
| 12 | |
| 13 | #include <__config> |
Louis Dionne | 73912b2 | 2020-11-04 15:01:25 -0500 | [diff] [blame] | 14 | #include <__availability> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 15 | #include <string> |
| 16 | #include <memory> |
| 17 | #include <utility> |
| 18 | #include <mutex> |
| 19 | #include <cstdint> |
| 20 | #include <cctype> |
Howard Hinnant | 155c2af | 2010-05-24 17:49:41 +0000 | [diff] [blame] | 21 | #include <locale.h> |
Eric Fiselier | bb999f9 | 2017-05-31 22:14:05 +0000 | [diff] [blame] | 22 | #if defined(_LIBCPP_MSVCRT_LIKE) |
Thomas Anderson | 094acbc | 2019-03-27 18:09:30 +0000 | [diff] [blame] | 23 | # include <cstring> |
Howard Hinnant | ae0f80b | 2011-09-29 20:33:10 +0000 | [diff] [blame] | 24 | # include <support/win32/locale_win32.h> |
Xiang Xiao | 8552923 | 2020-11-18 16:16:18 -0500 | [diff] [blame] | 25 | #elif defined(__NuttX__) |
| 26 | # include <support/nuttx/xlocale.h> |
Muiez Ahmed | af108fb | 2020-11-10 09:54:03 -0500 | [diff] [blame] | 27 | #elif defined(_AIX) || defined(__MVS__) |
Howard Hinnant | ea38295 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 28 | # include <support/ibm/xlocale.h> |
Marshall Clow | 3477ec9 | 2014-07-10 15:20:28 +0000 | [diff] [blame] | 29 | #elif defined(__ANDROID__) |
Saleem Abdulrasool | ac039f3 | 2018-04-13 18:14:57 +0000 | [diff] [blame] | 30 | # include <support/android/locale_bionic.h> |
Eric Fiselier | 7274c65 | 2014-11-25 21:57:41 +0000 | [diff] [blame] | 31 | #elif defined(__sun__) |
Eric Fiselier | 90adc20 | 2015-01-23 22:22:36 +0000 | [diff] [blame] | 32 | # include <xlocale.h> |
Eric Fiselier | 7274c65 | 2014-11-25 21:57:41 +0000 | [diff] [blame] | 33 | # include <support/solaris/xlocale.h> |
Sergey Dmitrouk | 9935bd4 | 2014-12-12 08:36:16 +0000 | [diff] [blame] | 34 | #elif defined(_NEWLIB_VERSION) |
| 35 | # include <support/newlib/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__) |
| 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. |
| 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) |
| 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 | b5ae3a7 | 2020-10-02 14:29:48 -0400 | [diff] [blame] | 340 | _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<char>) |
| 341 | _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<wchar_t>) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 342 | |
| 343 | // template <class CharT> class collate_byname; |
| 344 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 345 | template <class _CharT> class _LIBCPP_TEMPLATE_VIS collate_byname; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 346 | |
| 347 | template <> |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 348 | class _LIBCPP_TYPE_VIS collate_byname<char> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 349 | : public collate<char> |
| 350 | { |
| 351 | locale_t __l; |
| 352 | public: |
| 353 | typedef char char_type; |
| 354 | typedef basic_string<char_type> string_type; |
| 355 | |
| 356 | explicit collate_byname(const char* __n, size_t __refs = 0); |
| 357 | explicit collate_byname(const string& __n, size_t __refs = 0); |
| 358 | |
| 359 | protected: |
| 360 | ~collate_byname(); |
| 361 | virtual int do_compare(const char_type* __lo1, const char_type* __hi1, |
| 362 | const char_type* __lo2, const char_type* __hi2) const; |
| 363 | virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const; |
| 364 | }; |
| 365 | |
| 366 | template <> |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 367 | class _LIBCPP_TYPE_VIS collate_byname<wchar_t> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 368 | : public collate<wchar_t> |
| 369 | { |
| 370 | locale_t __l; |
| 371 | public: |
| 372 | typedef wchar_t char_type; |
| 373 | typedef basic_string<char_type> string_type; |
| 374 | |
| 375 | explicit collate_byname(const char* __n, size_t __refs = 0); |
| 376 | explicit collate_byname(const string& __n, size_t __refs = 0); |
| 377 | |
| 378 | protected: |
| 379 | ~collate_byname(); |
| 380 | |
| 381 | virtual int do_compare(const char_type* __lo1, const char_type* __hi1, |
| 382 | const char_type* __lo2, const char_type* __hi2) const; |
| 383 | virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const; |
| 384 | }; |
| 385 | |
| 386 | template <class _CharT, class _Traits, class _Allocator> |
| 387 | bool |
| 388 | locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x, |
| 389 | const basic_string<_CharT, _Traits, _Allocator>& __y) const |
| 390 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 391 | return _VSTD::use_facet<_VSTD::collate<_CharT> >(*this).compare( |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 392 | __x.data(), __x.data() + __x.size(), |
| 393 | __y.data(), __y.data() + __y.size()) < 0; |
| 394 | } |
| 395 | |
| 396 | // template <class charT> class ctype |
| 397 | |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 398 | class _LIBCPP_TYPE_VIS ctype_base |
Howard Hinnant | 9833cad | 2010-09-21 18:58:51 +0000 | [diff] [blame] | 399 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 400 | public: |
Xiang Xiao | a0562e9 | 2020-11-11 15:30:21 -0500 | [diff] [blame] | 401 | #if defined(_LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE) |
| 402 | typedef unsigned long mask; |
| 403 | static const mask space = 1<<0; |
| 404 | static const mask print = 1<<1; |
| 405 | static const mask cntrl = 1<<2; |
| 406 | static const mask upper = 1<<3; |
| 407 | static const mask lower = 1<<4; |
| 408 | static const mask alpha = 1<<5; |
| 409 | static const mask digit = 1<<6; |
| 410 | static const mask punct = 1<<7; |
| 411 | static const mask xdigit = 1<<8; |
| 412 | static const mask blank = 1<<9; |
| 413 | #if defined(__BIONIC__) |
| 414 | // Historically this was a part of regex_traits rather than ctype_base. The |
| 415 | // historical value of the constant is preserved for ABI compatibility. |
| 416 | static const mask __regex_word = 0x8000; |
| 417 | #else |
| 418 | static const mask __regex_word = 1<<10; |
| 419 | #endif // defined(__BIONIC__) |
| 420 | #elif defined(__GLIBC__) |
Alexis Hunt | 92b0c81 | 2011-07-09 00:56:23 +0000 | [diff] [blame] | 421 | typedef unsigned short mask; |
Howard Hinnant | 155c2af | 2010-05-24 17:49:41 +0000 | [diff] [blame] | 422 | static const mask space = _ISspace; |
| 423 | static const mask print = _ISprint; |
| 424 | static const mask cntrl = _IScntrl; |
| 425 | static const mask upper = _ISupper; |
| 426 | static const mask lower = _ISlower; |
| 427 | static const mask alpha = _ISalpha; |
| 428 | static const mask digit = _ISdigit; |
| 429 | static const mask punct = _ISpunct; |
| 430 | static const mask xdigit = _ISxdigit; |
| 431 | static const mask blank = _ISblank; |
Mikhail Maltsev | 014ed06 | 2019-06-14 09:04:16 +0000 | [diff] [blame] | 432 | #if defined(__mips__) |
Mikhail Maltsev | 12eb5af | 2019-08-20 10:19:55 +0000 | [diff] [blame] | 433 | static const mask __regex_word = static_cast<mask>(_ISbit(15)); |
Mikhail Maltsev | 014ed06 | 2019-06-14 09:04:16 +0000 | [diff] [blame] | 434 | #else |
| 435 | static const mask __regex_word = 0x80; |
| 436 | #endif |
Eric Fiselier | bb999f9 | 2017-05-31 22:14:05 +0000 | [diff] [blame] | 437 | #elif defined(_LIBCPP_MSVCRT_LIKE) |
Howard Hinnant | d7a7863 | 2011-09-29 13:33:15 +0000 | [diff] [blame] | 438 | typedef unsigned short mask; |
Howard Hinnant | dd0d702 | 2011-09-22 19:10:18 +0000 | [diff] [blame] | 439 | static const mask space = _SPACE; |
| 440 | static const mask print = _BLANK|_PUNCT|_ALPHA|_DIGIT; |
| 441 | static const mask cntrl = _CONTROL; |
| 442 | static const mask upper = _UPPER; |
| 443 | static const mask lower = _LOWER; |
| 444 | static const mask alpha = _ALPHA; |
| 445 | static const mask digit = _DIGIT; |
| 446 | static const mask punct = _PUNCT; |
| 447 | static const mask xdigit = _HEX; |
| 448 | static const mask blank = _BLANK; |
Mikhail Maltsev | 014ed06 | 2019-06-14 09:04:16 +0000 | [diff] [blame] | 449 | static const mask __regex_word = 0x80; |
Jonathan Roelofs | ae9ab25 | 2015-03-11 17:00:28 +0000 | [diff] [blame] | 450 | # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT |
Dan Albert | ebdf28b | 2015-03-11 00:51:06 +0000 | [diff] [blame] | 451 | #elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) |
JF Bastien | 0c265d8 | 2015-02-25 22:16:46 +0000 | [diff] [blame] | 452 | # ifdef __APPLE__ |
David Chisnall | 1d58106 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 453 | typedef __uint32_t mask; |
JF Bastien | 0c265d8 | 2015-02-25 22:16:46 +0000 | [diff] [blame] | 454 | # elif defined(__FreeBSD__) |
David Chisnall | 1d58106 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 455 | typedef unsigned long mask; |
Vasileios Kalintiris | c5dd894 | 2015-11-24 10:24:54 +0000 | [diff] [blame] | 456 | # elif defined(__EMSCRIPTEN__) || defined(__NetBSD__) |
Howard Hinnant | 942dbd2 | 2013-03-29 18:27:28 +0000 | [diff] [blame] | 457 | typedef unsigned short mask; |
JF Bastien | 0c265d8 | 2015-02-25 22:16:46 +0000 | [diff] [blame] | 458 | # endif |
David Chisnall | 1d58106 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 459 | static const mask space = _CTYPE_S; |
| 460 | static const mask print = _CTYPE_R; |
| 461 | static const mask cntrl = _CTYPE_C; |
| 462 | static const mask upper = _CTYPE_U; |
| 463 | static const mask lower = _CTYPE_L; |
| 464 | static const mask alpha = _CTYPE_A; |
| 465 | static const mask digit = _CTYPE_D; |
| 466 | static const mask punct = _CTYPE_P; |
| 467 | static const mask xdigit = _CTYPE_X; |
Dan Albert | 2dca407 | 2014-07-23 19:32:03 +0000 | [diff] [blame] | 468 | |
Joerg Sonnenberger | 153e416 | 2013-05-17 21:17:34 +0000 | [diff] [blame] | 469 | # if defined(__NetBSD__) |
| 470 | static const mask blank = _CTYPE_BL; |
Mikhail Maltsev | 014ed06 | 2019-06-14 09:04:16 +0000 | [diff] [blame] | 471 | // NetBSD defines classes up to 0x2000 |
| 472 | // see sys/ctype_bits.h, _CTYPE_Q |
| 473 | static const mask __regex_word = 0x8000; |
Joerg Sonnenberger | 153e416 | 2013-05-17 21:17:34 +0000 | [diff] [blame] | 474 | # else |
David Chisnall | 1d58106 | 2011-09-21 08:39:44 +0000 | [diff] [blame] | 475 | static const mask blank = _CTYPE_B; |
Mikhail Maltsev | 014ed06 | 2019-06-14 09:04:16 +0000 | [diff] [blame] | 476 | static const mask __regex_word = 0x80; |
Joerg Sonnenberger | 153e416 | 2013-05-17 21:17:34 +0000 | [diff] [blame] | 477 | # endif |
Howard Hinnant | a47505d | 2013-08-30 14:42:39 +0000 | [diff] [blame] | 478 | #elif defined(__sun__) || defined(_AIX) |
David Chisnall | 8074c34 | 2012-02-29 13:05:08 +0000 | [diff] [blame] | 479 | typedef unsigned int mask; |
| 480 | static const mask space = _ISSPACE; |
| 481 | static const mask print = _ISPRINT; |
| 482 | static const mask cntrl = _ISCNTRL; |
| 483 | static const mask upper = _ISUPPER; |
| 484 | static const mask lower = _ISLOWER; |
| 485 | static const mask alpha = _ISALPHA; |
| 486 | static const mask digit = _ISDIGIT; |
| 487 | static const mask punct = _ISPUNCT; |
| 488 | static const mask xdigit = _ISXDIGIT; |
| 489 | static const mask blank = _ISBLANK; |
Mikhail Maltsev | 014ed06 | 2019-06-14 09:04:16 +0000 | [diff] [blame] | 490 | static const mask __regex_word = 0x80; |
JF Bastien | 0c265d8 | 2015-02-25 22:16:46 +0000 | [diff] [blame] | 491 | #elif defined(_NEWLIB_VERSION) |
| 492 | // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h. |
| 493 | typedef char mask; |
| 494 | static const mask space = _S; |
| 495 | static const mask print = _P | _U | _L | _N | _B; |
| 496 | static const mask cntrl = _C; |
| 497 | static const mask upper = _U; |
| 498 | static const mask lower = _L; |
| 499 | static const mask alpha = _U | _L; |
| 500 | static const mask digit = _N; |
| 501 | static const mask punct = _P; |
| 502 | static const mask xdigit = _X | _N; |
| 503 | static const mask blank = _B; |
Mikhail Maltsev | 014ed06 | 2019-06-14 09:04:16 +0000 | [diff] [blame] | 504 | static const mask __regex_word = 0x80; |
Jonathan Roelofs | ae9ab25 | 2015-03-11 17:00:28 +0000 | [diff] [blame] | 505 | # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT |
| 506 | # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA |
| 507 | # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT |
JF Bastien | 0c265d8 | 2015-02-25 22:16:46 +0000 | [diff] [blame] | 508 | #else |
Xiang Xiao | a0562e9 | 2020-11-11 15:30:21 -0500 | [diff] [blame] | 509 | # 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] | 510 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 511 | static const mask alnum = alpha | digit; |
| 512 | static const mask graph = alnum | punct; |
| 513 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 514 | _LIBCPP_INLINE_VISIBILITY ctype_base() {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 515 | }; |
| 516 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 517 | template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 518 | |
| 519 | template <> |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 520 | class _LIBCPP_TYPE_VIS ctype<wchar_t> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 521 | : public locale::facet, |
| 522 | public ctype_base |
| 523 | { |
| 524 | public: |
| 525 | typedef wchar_t char_type; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 526 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 527 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 528 | explicit ctype(size_t __refs = 0) |
| 529 | : locale::facet(__refs) {} |
| 530 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 531 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 532 | bool is(mask __m, char_type __c) const |
| 533 | { |
| 534 | return do_is(__m, __c); |
| 535 | } |
| 536 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 537 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 538 | const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const |
| 539 | { |
| 540 | return do_is(__low, __high, __vec); |
| 541 | } |
| 542 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 543 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 544 | const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const |
| 545 | { |
| 546 | return do_scan_is(__m, __low, __high); |
| 547 | } |
| 548 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 549 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 550 | const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const |
| 551 | { |
| 552 | return do_scan_not(__m, __low, __high); |
| 553 | } |
| 554 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 555 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 556 | char_type toupper(char_type __c) const |
| 557 | { |
| 558 | return do_toupper(__c); |
| 559 | } |
| 560 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 561 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 562 | const char_type* toupper(char_type* __low, const char_type* __high) const |
| 563 | { |
| 564 | return do_toupper(__low, __high); |
| 565 | } |
| 566 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 567 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 568 | char_type tolower(char_type __c) const |
| 569 | { |
| 570 | return do_tolower(__c); |
| 571 | } |
| 572 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 573 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 574 | const char_type* tolower(char_type* __low, const char_type* __high) const |
| 575 | { |
| 576 | return do_tolower(__low, __high); |
| 577 | } |
| 578 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 579 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 580 | char_type widen(char __c) const |
| 581 | { |
| 582 | return do_widen(__c); |
| 583 | } |
| 584 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 585 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 586 | const char* widen(const char* __low, const char* __high, char_type* __to) const |
| 587 | { |
| 588 | return do_widen(__low, __high, __to); |
| 589 | } |
| 590 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 591 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 592 | char narrow(char_type __c, char __dfault) const |
| 593 | { |
| 594 | return do_narrow(__c, __dfault); |
| 595 | } |
| 596 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 597 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 598 | const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const |
| 599 | { |
| 600 | return do_narrow(__low, __high, __dfault, __to); |
| 601 | } |
| 602 | |
| 603 | static locale::id id; |
| 604 | |
| 605 | protected: |
| 606 | ~ctype(); |
| 607 | virtual bool do_is(mask __m, char_type __c) const; |
| 608 | virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const; |
| 609 | virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const; |
| 610 | virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const; |
| 611 | virtual char_type do_toupper(char_type) const; |
| 612 | virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; |
| 613 | virtual char_type do_tolower(char_type) const; |
| 614 | virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; |
| 615 | virtual char_type do_widen(char) const; |
| 616 | virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const; |
| 617 | virtual char do_narrow(char_type, char __dfault) const; |
| 618 | virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const; |
| 619 | }; |
| 620 | |
| 621 | template <> |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 622 | class _LIBCPP_TYPE_VIS ctype<char> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 623 | : public locale::facet, public ctype_base |
| 624 | { |
| 625 | const mask* __tab_; |
| 626 | bool __del_; |
| 627 | public: |
| 628 | typedef char char_type; |
| 629 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 630 | 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] | 631 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 632 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 633 | bool is(mask __m, char_type __c) const |
| 634 | { |
Marshall Clow | 11de487 | 2013-10-21 14:41:05 +0000 | [diff] [blame] | 635 | return isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) !=0 : false; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 636 | } |
| 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 | const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const |
| 640 | { |
| 641 | for (; __low != __high; ++__low, ++__vec) |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 642 | *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 643 | return __low; |
| 644 | } |
| 645 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 646 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 647 | const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const |
| 648 | { |
| 649 | for (; __low != __high; ++__low) |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 650 | if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 651 | break; |
| 652 | return __low; |
| 653 | } |
| 654 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 655 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 656 | const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const |
| 657 | { |
| 658 | for (; __low != __high; ++__low) |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 659 | if (!(isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 660 | break; |
| 661 | return __low; |
| 662 | } |
| 663 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 664 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 665 | char_type toupper(char_type __c) const |
| 666 | { |
| 667 | return do_toupper(__c); |
| 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 | const char_type* toupper(char_type* __low, const char_type* __high) const |
| 672 | { |
| 673 | return do_toupper(__low, __high); |
| 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 | char_type tolower(char_type __c) const |
| 678 | { |
| 679 | return do_tolower(__c); |
| 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 | const char_type* tolower(char_type* __low, const char_type* __high) const |
| 684 | { |
| 685 | return do_tolower(__low, __high); |
| 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 | char_type widen(char __c) const |
| 690 | { |
| 691 | return do_widen(__c); |
| 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 | const char* widen(const char* __low, const char* __high, char_type* __to) const |
| 696 | { |
| 697 | return do_widen(__low, __high, __to); |
| 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 | char narrow(char_type __c, char __dfault) const |
| 702 | { |
| 703 | return do_narrow(__c, __dfault); |
| 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 | const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const |
| 708 | { |
| 709 | return do_narrow(__low, __high, __dfault, __to); |
| 710 | } |
| 711 | |
| 712 | static locale::id id; |
| 713 | |
Howard Hinnant | 155c2af | 2010-05-24 17:49:41 +0000 | [diff] [blame] | 714 | #ifdef _CACHED_RUNES |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 715 | static const size_t table_size = _CACHED_RUNES; |
Howard Hinnant | 155c2af | 2010-05-24 17:49:41 +0000 | [diff] [blame] | 716 | #else |
| 717 | static const size_t table_size = 256; // FIXME: Don't hardcode this. |
| 718 | #endif |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 719 | _LIBCPP_INLINE_VISIBILITY const mask* table() const _NOEXCEPT {return __tab_;} |
Howard Hinnant | 7c9e573 | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 720 | static const mask* classic_table() _NOEXCEPT; |
Vasileios Kalintiris | c5dd894 | 2015-11-24 10:24:54 +0000 | [diff] [blame] | 721 | #if defined(__GLIBC__) || defined(__EMSCRIPTEN__) |
Alexis Hunt | 92b0c81 | 2011-07-09 00:56:23 +0000 | [diff] [blame] | 722 | static const int* __classic_upper_table() _NOEXCEPT; |
| 723 | static const int* __classic_lower_table() _NOEXCEPT; |
Alexis Hunt | 5a4dd56 | 2011-07-09 01:09:31 +0000 | [diff] [blame] | 724 | #endif |
Joerg Sonnenberger | 153e416 | 2013-05-17 21:17:34 +0000 | [diff] [blame] | 725 | #if defined(__NetBSD__) |
| 726 | static const short* __classic_upper_table() _NOEXCEPT; |
| 727 | static const short* __classic_lower_table() _NOEXCEPT; |
| 728 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 729 | |
| 730 | protected: |
| 731 | ~ctype(); |
| 732 | virtual char_type do_toupper(char_type __c) const; |
| 733 | virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; |
| 734 | virtual char_type do_tolower(char_type __c) const; |
| 735 | virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; |
| 736 | virtual char_type do_widen(char __c) const; |
| 737 | virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const; |
| 738 | virtual char do_narrow(char_type __c, char __dfault) const; |
| 739 | virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const; |
| 740 | }; |
| 741 | |
| 742 | // template <class CharT> class ctype_byname; |
| 743 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 744 | template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype_byname; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 745 | |
| 746 | template <> |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 747 | class _LIBCPP_TYPE_VIS ctype_byname<char> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 748 | : public ctype<char> |
| 749 | { |
| 750 | locale_t __l; |
| 751 | |
| 752 | public: |
| 753 | explicit ctype_byname(const char*, size_t = 0); |
| 754 | explicit ctype_byname(const string&, size_t = 0); |
| 755 | |
| 756 | protected: |
| 757 | ~ctype_byname(); |
| 758 | virtual char_type do_toupper(char_type) const; |
| 759 | virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; |
| 760 | virtual char_type do_tolower(char_type) const; |
| 761 | virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; |
| 762 | }; |
| 763 | |
| 764 | template <> |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 765 | class _LIBCPP_TYPE_VIS ctype_byname<wchar_t> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 766 | : public ctype<wchar_t> |
| 767 | { |
| 768 | locale_t __l; |
| 769 | |
| 770 | public: |
| 771 | explicit ctype_byname(const char*, size_t = 0); |
| 772 | explicit ctype_byname(const string&, size_t = 0); |
| 773 | |
| 774 | protected: |
| 775 | ~ctype_byname(); |
| 776 | virtual bool do_is(mask __m, char_type __c) const; |
| 777 | virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const; |
| 778 | virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const; |
| 779 | virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const; |
| 780 | virtual char_type do_toupper(char_type) const; |
| 781 | virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; |
| 782 | virtual char_type do_tolower(char_type) const; |
| 783 | virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; |
| 784 | virtual char_type do_widen(char) const; |
| 785 | virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const; |
| 786 | virtual char do_narrow(char_type, char __dfault) const; |
| 787 | virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const; |
| 788 | }; |
| 789 | |
| 790 | template <class _CharT> |
| 791 | inline _LIBCPP_INLINE_VISIBILITY |
| 792 | bool |
| 793 | isspace(_CharT __c, const locale& __loc) |
| 794 | { |
| 795 | return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c); |
| 796 | } |
| 797 | |
| 798 | template <class _CharT> |
| 799 | inline _LIBCPP_INLINE_VISIBILITY |
| 800 | bool |
| 801 | isprint(_CharT __c, const locale& __loc) |
| 802 | { |
| 803 | return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c); |
| 804 | } |
| 805 | |
| 806 | template <class _CharT> |
| 807 | inline _LIBCPP_INLINE_VISIBILITY |
| 808 | bool |
| 809 | iscntrl(_CharT __c, const locale& __loc) |
| 810 | { |
| 811 | return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c); |
| 812 | } |
| 813 | |
| 814 | template <class _CharT> |
| 815 | inline _LIBCPP_INLINE_VISIBILITY |
| 816 | bool |
| 817 | isupper(_CharT __c, const locale& __loc) |
| 818 | { |
| 819 | return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c); |
| 820 | } |
| 821 | |
| 822 | template <class _CharT> |
| 823 | inline _LIBCPP_INLINE_VISIBILITY |
| 824 | bool |
| 825 | islower(_CharT __c, const locale& __loc) |
| 826 | { |
| 827 | return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c); |
| 828 | } |
| 829 | |
| 830 | template <class _CharT> |
| 831 | inline _LIBCPP_INLINE_VISIBILITY |
| 832 | bool |
| 833 | isalpha(_CharT __c, const locale& __loc) |
| 834 | { |
| 835 | return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c); |
| 836 | } |
| 837 | |
| 838 | template <class _CharT> |
| 839 | inline _LIBCPP_INLINE_VISIBILITY |
| 840 | bool |
| 841 | isdigit(_CharT __c, const locale& __loc) |
| 842 | { |
| 843 | return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c); |
| 844 | } |
| 845 | |
| 846 | template <class _CharT> |
| 847 | inline _LIBCPP_INLINE_VISIBILITY |
| 848 | bool |
| 849 | ispunct(_CharT __c, const locale& __loc) |
| 850 | { |
| 851 | return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c); |
| 852 | } |
| 853 | |
| 854 | template <class _CharT> |
| 855 | inline _LIBCPP_INLINE_VISIBILITY |
| 856 | bool |
| 857 | isxdigit(_CharT __c, const locale& __loc) |
| 858 | { |
| 859 | return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c); |
| 860 | } |
| 861 | |
| 862 | template <class _CharT> |
| 863 | inline _LIBCPP_INLINE_VISIBILITY |
| 864 | bool |
| 865 | isalnum(_CharT __c, const locale& __loc) |
| 866 | { |
| 867 | return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c); |
| 868 | } |
| 869 | |
| 870 | template <class _CharT> |
| 871 | inline _LIBCPP_INLINE_VISIBILITY |
| 872 | bool |
| 873 | isgraph(_CharT __c, const locale& __loc) |
| 874 | { |
| 875 | return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c); |
| 876 | } |
| 877 | |
| 878 | template <class _CharT> |
| 879 | inline _LIBCPP_INLINE_VISIBILITY |
| 880 | _CharT |
| 881 | toupper(_CharT __c, const locale& __loc) |
| 882 | { |
| 883 | return use_facet<ctype<_CharT> >(__loc).toupper(__c); |
| 884 | } |
| 885 | |
| 886 | template <class _CharT> |
| 887 | inline _LIBCPP_INLINE_VISIBILITY |
| 888 | _CharT |
| 889 | tolower(_CharT __c, const locale& __loc) |
| 890 | { |
| 891 | return use_facet<ctype<_CharT> >(__loc).tolower(__c); |
| 892 | } |
| 893 | |
| 894 | // codecvt_base |
| 895 | |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 896 | class _LIBCPP_TYPE_VIS codecvt_base |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 897 | { |
| 898 | public: |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 899 | _LIBCPP_INLINE_VISIBILITY codecvt_base() {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 900 | enum result {ok, partial, error, noconv}; |
| 901 | }; |
| 902 | |
| 903 | // template <class internT, class externT, class stateT> class codecvt; |
| 904 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 905 | template <class _InternT, class _ExternT, class _StateT> class _LIBCPP_TEMPLATE_VIS codecvt; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 906 | |
| 907 | // template <> class codecvt<char, char, mbstate_t> |
| 908 | |
| 909 | template <> |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 910 | class _LIBCPP_TYPE_VIS codecvt<char, char, mbstate_t> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 911 | : public locale::facet, |
| 912 | public codecvt_base |
| 913 | { |
| 914 | public: |
| 915 | typedef char intern_type; |
| 916 | typedef char extern_type; |
| 917 | typedef mbstate_t state_type; |
| 918 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 919 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 920 | explicit codecvt(size_t __refs = 0) |
| 921 | : locale::facet(__refs) {} |
| 922 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 923 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 924 | result out(state_type& __st, |
| 925 | const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, |
| 926 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const |
| 927 | { |
| 928 | return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); |
| 929 | } |
| 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 unshift(state_type& __st, |
| 933 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const |
| 934 | { |
| 935 | return do_unshift(__st, __to, __to_end, __to_nxt); |
| 936 | } |
| 937 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 938 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 939 | result in(state_type& __st, |
| 940 | const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, |
| 941 | intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const |
| 942 | { |
| 943 | return do_in(__st, __frm, __frm_end, __frm_nxt, __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 | 7c9e573 | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 947 | int encoding() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 948 | { |
| 949 | return do_encoding(); |
| 950 | } |
| 951 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 952 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7c9e573 | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 953 | bool always_noconv() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 954 | { |
| 955 | return do_always_noconv(); |
| 956 | } |
| 957 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 958 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 959 | int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const |
| 960 | { |
| 961 | return do_length(__st, __frm, __end, __mx); |
| 962 | } |
| 963 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 964 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7c9e573 | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 965 | int max_length() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 966 | { |
| 967 | return do_max_length(); |
| 968 | } |
| 969 | |
| 970 | static locale::id id; |
| 971 | |
| 972 | protected: |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 973 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 974 | explicit codecvt(const char*, size_t __refs = 0) |
| 975 | : locale::facet(__refs) {} |
| 976 | |
| 977 | ~codecvt(); |
| 978 | |
| 979 | virtual result do_out(state_type& __st, |
| 980 | const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, |
| 981 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; |
| 982 | virtual result do_in(state_type& __st, |
| 983 | const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, |
| 984 | intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; |
| 985 | virtual result do_unshift(state_type& __st, |
| 986 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; |
Howard Hinnant | 7c9e573 | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 987 | virtual int do_encoding() const _NOEXCEPT; |
| 988 | virtual bool do_always_noconv() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 989 | 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] | 990 | virtual int do_max_length() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 991 | }; |
| 992 | |
| 993 | // template <> class codecvt<wchar_t, char, mbstate_t> |
| 994 | |
| 995 | template <> |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 996 | class _LIBCPP_TYPE_VIS codecvt<wchar_t, char, mbstate_t> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 997 | : public locale::facet, |
| 998 | public codecvt_base |
| 999 | { |
| 1000 | locale_t __l; |
| 1001 | public: |
| 1002 | typedef wchar_t intern_type; |
| 1003 | typedef char extern_type; |
| 1004 | typedef mbstate_t state_type; |
| 1005 | |
| 1006 | explicit codecvt(size_t __refs = 0); |
| 1007 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1008 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1009 | result out(state_type& __st, |
| 1010 | const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, |
| 1011 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const |
| 1012 | { |
| 1013 | return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); |
| 1014 | } |
| 1015 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1016 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1017 | result unshift(state_type& __st, |
| 1018 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const |
| 1019 | { |
| 1020 | return do_unshift(__st, __to, __to_end, __to_nxt); |
| 1021 | } |
| 1022 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1023 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1024 | result in(state_type& __st, |
| 1025 | const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, |
| 1026 | intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const |
| 1027 | { |
| 1028 | return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); |
| 1029 | } |
| 1030 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1031 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7c9e573 | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 1032 | int encoding() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1033 | { |
| 1034 | return do_encoding(); |
| 1035 | } |
| 1036 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1037 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7c9e573 | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 1038 | bool always_noconv() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1039 | { |
| 1040 | return do_always_noconv(); |
| 1041 | } |
| 1042 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1043 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1044 | int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const |
| 1045 | { |
| 1046 | return do_length(__st, __frm, __end, __mx); |
| 1047 | } |
| 1048 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1049 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7c9e573 | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 1050 | int max_length() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1051 | { |
| 1052 | return do_max_length(); |
| 1053 | } |
| 1054 | |
| 1055 | static locale::id id; |
| 1056 | |
| 1057 | protected: |
| 1058 | explicit codecvt(const char*, size_t __refs = 0); |
| 1059 | |
| 1060 | ~codecvt(); |
| 1061 | |
| 1062 | virtual result do_out(state_type& __st, |
| 1063 | const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, |
| 1064 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; |
| 1065 | virtual result do_in(state_type& __st, |
| 1066 | const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, |
| 1067 | intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; |
| 1068 | virtual result do_unshift(state_type& __st, |
| 1069 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; |
Howard Hinnant | 7c9e573 | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 1070 | virtual int do_encoding() const _NOEXCEPT; |
| 1071 | virtual bool do_always_noconv() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1072 | 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] | 1073 | virtual int do_max_length() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1074 | }; |
| 1075 | |
Marek Kurdej | 718b62c | 2020-12-02 08:57:02 +0100 | [diff] [blame] | 1076 | // template <> class codecvt<char16_t, char, mbstate_t> // deprecated in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1077 | |
| 1078 | template <> |
Marek Kurdej | 718b62c | 2020-12-02 08:57:02 +0100 | [diff] [blame] | 1079 | class _LIBCPP_TYPE_VIS _LIBCPP_DEPRECATED_IN_CXX20 codecvt<char16_t, char, mbstate_t> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1080 | : public locale::facet, |
| 1081 | public codecvt_base |
| 1082 | { |
| 1083 | public: |
| 1084 | typedef char16_t intern_type; |
| 1085 | typedef char extern_type; |
| 1086 | typedef mbstate_t state_type; |
| 1087 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1088 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1089 | explicit codecvt(size_t __refs = 0) |
| 1090 | : locale::facet(__refs) {} |
| 1091 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1092 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1093 | result out(state_type& __st, |
| 1094 | const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, |
| 1095 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const |
| 1096 | { |
| 1097 | return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); |
| 1098 | } |
| 1099 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1100 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1101 | result unshift(state_type& __st, |
| 1102 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const |
| 1103 | { |
| 1104 | return do_unshift(__st, __to, __to_end, __to_nxt); |
| 1105 | } |
| 1106 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1107 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1108 | result in(state_type& __st, |
| 1109 | const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, |
| 1110 | intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const |
| 1111 | { |
| 1112 | return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); |
| 1113 | } |
| 1114 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1115 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7c9e573 | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 1116 | int encoding() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1117 | { |
| 1118 | return do_encoding(); |
| 1119 | } |
| 1120 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1121 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7c9e573 | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 1122 | bool always_noconv() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1123 | { |
| 1124 | return do_always_noconv(); |
| 1125 | } |
| 1126 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1127 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1128 | int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const |
| 1129 | { |
| 1130 | return do_length(__st, __frm, __end, __mx); |
| 1131 | } |
| 1132 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1133 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7c9e573 | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 1134 | int max_length() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1135 | { |
| 1136 | return do_max_length(); |
| 1137 | } |
| 1138 | |
| 1139 | static locale::id id; |
| 1140 | |
| 1141 | protected: |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1142 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1143 | explicit codecvt(const char*, size_t __refs = 0) |
| 1144 | : locale::facet(__refs) {} |
| 1145 | |
| 1146 | ~codecvt(); |
| 1147 | |
| 1148 | virtual result do_out(state_type& __st, |
| 1149 | const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, |
| 1150 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; |
| 1151 | virtual result do_in(state_type& __st, |
| 1152 | const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, |
| 1153 | intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; |
| 1154 | virtual result do_unshift(state_type& __st, |
| 1155 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; |
Howard Hinnant | 7c9e573 | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 1156 | virtual int do_encoding() const _NOEXCEPT; |
| 1157 | virtual bool do_always_noconv() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1158 | 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] | 1159 | virtual int do_max_length() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1160 | }; |
| 1161 | |
Marek Kurdej | 718b62c | 2020-12-02 08:57:02 +0100 | [diff] [blame] | 1162 | #ifndef _LIBCPP_NO_HAS_CHAR8_T |
| 1163 | |
| 1164 | // template <> class codecvt<char16_t, char8_t, mbstate_t> // C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1165 | |
| 1166 | template <> |
Marek Kurdej | 718b62c | 2020-12-02 08:57:02 +0100 | [diff] [blame] | 1167 | class _LIBCPP_TYPE_VIS codecvt<char16_t, char8_t, mbstate_t> |
| 1168 | : public locale::facet, |
| 1169 | public codecvt_base |
| 1170 | { |
| 1171 | public: |
| 1172 | typedef char16_t intern_type; |
| 1173 | typedef char8_t extern_type; |
| 1174 | typedef mbstate_t state_type; |
| 1175 | |
| 1176 | _LIBCPP_INLINE_VISIBILITY |
| 1177 | explicit codecvt(size_t __refs = 0) |
| 1178 | : locale::facet(__refs) {} |
| 1179 | |
| 1180 | _LIBCPP_INLINE_VISIBILITY |
| 1181 | result out(state_type& __st, |
| 1182 | const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, |
| 1183 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const |
| 1184 | { |
| 1185 | return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); |
| 1186 | } |
| 1187 | |
| 1188 | _LIBCPP_INLINE_VISIBILITY |
| 1189 | result unshift(state_type& __st, |
| 1190 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const |
| 1191 | { |
| 1192 | return do_unshift(__st, __to, __to_end, __to_nxt); |
| 1193 | } |
| 1194 | |
| 1195 | _LIBCPP_INLINE_VISIBILITY |
| 1196 | result in(state_type& __st, |
| 1197 | const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, |
| 1198 | intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const |
| 1199 | { |
| 1200 | return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); |
| 1201 | } |
| 1202 | |
| 1203 | _LIBCPP_INLINE_VISIBILITY |
| 1204 | int encoding() const _NOEXCEPT |
| 1205 | { |
| 1206 | return do_encoding(); |
| 1207 | } |
| 1208 | |
| 1209 | _LIBCPP_INLINE_VISIBILITY |
| 1210 | bool always_noconv() const _NOEXCEPT |
| 1211 | { |
| 1212 | return do_always_noconv(); |
| 1213 | } |
| 1214 | |
| 1215 | _LIBCPP_INLINE_VISIBILITY |
| 1216 | int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const |
| 1217 | { |
| 1218 | return do_length(__st, __frm, __end, __mx); |
| 1219 | } |
| 1220 | |
| 1221 | _LIBCPP_INLINE_VISIBILITY |
| 1222 | int max_length() const _NOEXCEPT |
| 1223 | { |
| 1224 | return do_max_length(); |
| 1225 | } |
| 1226 | |
| 1227 | static locale::id id; |
| 1228 | |
| 1229 | protected: |
| 1230 | _LIBCPP_INLINE_VISIBILITY |
| 1231 | explicit codecvt(const char*, size_t __refs = 0) |
| 1232 | : locale::facet(__refs) {} |
| 1233 | |
| 1234 | ~codecvt(); |
| 1235 | |
| 1236 | virtual result do_out(state_type& __st, |
| 1237 | const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, |
| 1238 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; |
| 1239 | virtual result do_in(state_type& __st, |
| 1240 | const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, |
| 1241 | intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; |
| 1242 | virtual result do_unshift(state_type& __st, |
| 1243 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; |
| 1244 | virtual int do_encoding() const _NOEXCEPT; |
| 1245 | virtual bool do_always_noconv() const _NOEXCEPT; |
| 1246 | virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; |
| 1247 | virtual int do_max_length() const _NOEXCEPT; |
| 1248 | }; |
| 1249 | |
| 1250 | #endif |
| 1251 | |
| 1252 | // template <> class codecvt<char32_t, char, mbstate_t> // deprecated in C++20 |
| 1253 | |
| 1254 | template <> |
| 1255 | class _LIBCPP_TYPE_VIS _LIBCPP_DEPRECATED_IN_CXX20 codecvt<char32_t, char, mbstate_t> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1256 | : public locale::facet, |
| 1257 | public codecvt_base |
| 1258 | { |
| 1259 | public: |
| 1260 | typedef char32_t intern_type; |
| 1261 | typedef char extern_type; |
| 1262 | typedef mbstate_t state_type; |
| 1263 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1264 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1265 | explicit codecvt(size_t __refs = 0) |
| 1266 | : locale::facet(__refs) {} |
| 1267 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1268 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1269 | result out(state_type& __st, |
| 1270 | const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, |
| 1271 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const |
| 1272 | { |
| 1273 | return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); |
| 1274 | } |
| 1275 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1276 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1277 | result unshift(state_type& __st, |
| 1278 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const |
| 1279 | { |
| 1280 | return do_unshift(__st, __to, __to_end, __to_nxt); |
| 1281 | } |
| 1282 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1283 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1284 | result in(state_type& __st, |
| 1285 | const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, |
| 1286 | intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const |
| 1287 | { |
| 1288 | return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); |
| 1289 | } |
| 1290 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1291 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7c9e573 | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 1292 | int encoding() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1293 | { |
| 1294 | return do_encoding(); |
| 1295 | } |
| 1296 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1297 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7c9e573 | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 1298 | bool always_noconv() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1299 | { |
| 1300 | return do_always_noconv(); |
| 1301 | } |
| 1302 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1303 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1304 | int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const |
| 1305 | { |
| 1306 | return do_length(__st, __frm, __end, __mx); |
| 1307 | } |
| 1308 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1309 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7c9e573 | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 1310 | int max_length() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1311 | { |
| 1312 | return do_max_length(); |
| 1313 | } |
| 1314 | |
| 1315 | static locale::id id; |
| 1316 | |
| 1317 | protected: |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1318 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1319 | explicit codecvt(const char*, size_t __refs = 0) |
| 1320 | : locale::facet(__refs) {} |
| 1321 | |
| 1322 | ~codecvt(); |
| 1323 | |
| 1324 | virtual result do_out(state_type& __st, |
| 1325 | const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, |
| 1326 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; |
| 1327 | virtual result do_in(state_type& __st, |
| 1328 | const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, |
| 1329 | intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; |
| 1330 | virtual result do_unshift(state_type& __st, |
| 1331 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; |
Howard Hinnant | 7c9e573 | 2011-05-31 15:34:58 +0000 | [diff] [blame] | 1332 | virtual int do_encoding() const _NOEXCEPT; |
| 1333 | virtual bool do_always_noconv() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1334 | 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] | 1335 | virtual int do_max_length() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1336 | }; |
| 1337 | |
Marek Kurdej | 718b62c | 2020-12-02 08:57:02 +0100 | [diff] [blame] | 1338 | #ifndef _LIBCPP_NO_HAS_CHAR8_T |
| 1339 | |
| 1340 | // template <> class codecvt<char32_t, char8_t, mbstate_t> // C++20 |
| 1341 | |
| 1342 | template <> |
| 1343 | class _LIBCPP_TYPE_VIS codecvt<char32_t, char8_t, mbstate_t> |
| 1344 | : public locale::facet, |
| 1345 | public codecvt_base |
| 1346 | { |
| 1347 | public: |
| 1348 | typedef char32_t intern_type; |
| 1349 | typedef char8_t extern_type; |
| 1350 | typedef mbstate_t state_type; |
| 1351 | |
| 1352 | _LIBCPP_INLINE_VISIBILITY |
| 1353 | explicit codecvt(size_t __refs = 0) |
| 1354 | : locale::facet(__refs) {} |
| 1355 | |
| 1356 | _LIBCPP_INLINE_VISIBILITY |
| 1357 | result out(state_type& __st, |
| 1358 | const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, |
| 1359 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const |
| 1360 | { |
| 1361 | return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); |
| 1362 | } |
| 1363 | |
| 1364 | _LIBCPP_INLINE_VISIBILITY |
| 1365 | result unshift(state_type& __st, |
| 1366 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const |
| 1367 | { |
| 1368 | return do_unshift(__st, __to, __to_end, __to_nxt); |
| 1369 | } |
| 1370 | |
| 1371 | _LIBCPP_INLINE_VISIBILITY |
| 1372 | result in(state_type& __st, |
| 1373 | const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, |
| 1374 | intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const |
| 1375 | { |
| 1376 | return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); |
| 1377 | } |
| 1378 | |
| 1379 | _LIBCPP_INLINE_VISIBILITY |
| 1380 | int encoding() const _NOEXCEPT |
| 1381 | { |
| 1382 | return do_encoding(); |
| 1383 | } |
| 1384 | |
| 1385 | _LIBCPP_INLINE_VISIBILITY |
| 1386 | bool always_noconv() const _NOEXCEPT |
| 1387 | { |
| 1388 | return do_always_noconv(); |
| 1389 | } |
| 1390 | |
| 1391 | _LIBCPP_INLINE_VISIBILITY |
| 1392 | int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const |
| 1393 | { |
| 1394 | return do_length(__st, __frm, __end, __mx); |
| 1395 | } |
| 1396 | |
| 1397 | _LIBCPP_INLINE_VISIBILITY |
| 1398 | int max_length() const _NOEXCEPT |
| 1399 | { |
| 1400 | return do_max_length(); |
| 1401 | } |
| 1402 | |
| 1403 | static locale::id id; |
| 1404 | |
| 1405 | protected: |
| 1406 | _LIBCPP_INLINE_VISIBILITY |
| 1407 | explicit codecvt(const char*, size_t __refs = 0) |
| 1408 | : locale::facet(__refs) {} |
| 1409 | |
| 1410 | ~codecvt(); |
| 1411 | |
| 1412 | virtual result do_out(state_type& __st, |
| 1413 | const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt, |
| 1414 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; |
| 1415 | virtual result do_in(state_type& __st, |
| 1416 | const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt, |
| 1417 | intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const; |
| 1418 | virtual result do_unshift(state_type& __st, |
| 1419 | extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; |
| 1420 | virtual int do_encoding() const _NOEXCEPT; |
| 1421 | virtual bool do_always_noconv() const _NOEXCEPT; |
| 1422 | virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; |
| 1423 | virtual int do_max_length() const _NOEXCEPT; |
| 1424 | }; |
| 1425 | |
| 1426 | #endif |
| 1427 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1428 | // template <class _InternT, class _ExternT, class _StateT> class codecvt_byname |
| 1429 | |
| 1430 | template <class _InternT, class _ExternT, class _StateT> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1431 | class _LIBCPP_TEMPLATE_VIS codecvt_byname |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1432 | : public codecvt<_InternT, _ExternT, _StateT> |
| 1433 | { |
| 1434 | public: |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1435 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1436 | explicit codecvt_byname(const char* __nm, size_t __refs = 0) |
| 1437 | : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {} |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1438 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1439 | explicit codecvt_byname(const string& __nm, size_t __refs = 0) |
| 1440 | : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {} |
| 1441 | protected: |
| 1442 | ~codecvt_byname(); |
| 1443 | }; |
| 1444 | |
Marek Kurdej | 718b62c | 2020-12-02 08:57:02 +0100 | [diff] [blame] | 1445 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1446 | template <class _InternT, class _ExternT, class _StateT> |
| 1447 | codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname() |
| 1448 | { |
| 1449 | } |
Marek Kurdej | 718b62c | 2020-12-02 08:57:02 +0100 | [diff] [blame] | 1450 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1451 | |
Louis Dionne | b5ae3a7 | 2020-10-02 14:29:48 -0400 | [diff] [blame] | 1452 | _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char, mbstate_t>) |
| 1453 | _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>) |
Marek Kurdej | 718b62c | 2020-12-02 08:57:02 +0100 | [diff] [blame] | 1454 | _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DEPRECATED_IN_CXX20 codecvt_byname<char16_t, char, mbstate_t>) // deprecated in C++20 |
| 1455 | _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DEPRECATED_IN_CXX20 codecvt_byname<char32_t, char, mbstate_t>) // deprecated in C++20 |
| 1456 | #ifndef _LIBCPP_NO_HAS_CHAR8_T |
| 1457 | _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char8_t, mbstate_t>) // C++20 |
| 1458 | _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char8_t, mbstate_t>) // C++20 |
| 1459 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1460 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1461 | template <size_t _Np> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1462 | struct __narrow_to_utf8 |
| 1463 | { |
| 1464 | template <class _OutputIterator, class _CharT> |
| 1465 | _OutputIterator |
| 1466 | operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const; |
| 1467 | }; |
| 1468 | |
| 1469 | template <> |
| 1470 | struct __narrow_to_utf8<8> |
| 1471 | { |
| 1472 | template <class _OutputIterator, class _CharT> |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1473 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1474 | _OutputIterator |
| 1475 | operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const |
| 1476 | { |
| 1477 | for (; __wb < __we; ++__wb, ++__s) |
| 1478 | *__s = *__wb; |
| 1479 | return __s; |
| 1480 | } |
| 1481 | }; |
| 1482 | |
Marek Kurdej | 718b62c | 2020-12-02 08:57:02 +0100 | [diff] [blame] | 1483 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1484 | template <> |
Louis Dionne | 5254b37 | 2018-10-25 12:13:43 +0000 | [diff] [blame] | 1485 | struct _LIBCPP_TEMPLATE_VIS __narrow_to_utf8<16> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1486 | : public codecvt<char16_t, char, mbstate_t> |
| 1487 | { |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1488 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1489 | __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {} |
Marek Kurdej | 718b62c | 2020-12-02 08:57:02 +0100 | [diff] [blame] | 1490 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1491 | |
Louis Dionne | 5254b37 | 2018-10-25 12:13:43 +0000 | [diff] [blame] | 1492 | _LIBCPP_EXPORTED_FROM_ABI ~__narrow_to_utf8(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1493 | |
| 1494 | template <class _OutputIterator, class _CharT> |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1495 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1496 | _OutputIterator |
| 1497 | operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const |
| 1498 | { |
| 1499 | result __r = ok; |
| 1500 | mbstate_t __mb; |
| 1501 | while (__wb < __we && __r != error) |
| 1502 | { |
| 1503 | const int __sz = 32; |
| 1504 | char __buf[__sz]; |
| 1505 | char* __bn; |
| 1506 | const char16_t* __wn = (const char16_t*)__wb; |
| 1507 | __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn, |
| 1508 | __buf, __buf+__sz, __bn); |
| 1509 | if (__r == codecvt_base::error || __wn == (const char16_t*)__wb) |
| 1510 | __throw_runtime_error("locale not supported"); |
| 1511 | for (const char* __p = __buf; __p < __bn; ++__p, ++__s) |
| 1512 | *__s = *__p; |
| 1513 | __wb = (const _CharT*)__wn; |
| 1514 | } |
| 1515 | return __s; |
| 1516 | } |
| 1517 | }; |
| 1518 | |
Marek Kurdej | 718b62c | 2020-12-02 08:57:02 +0100 | [diff] [blame] | 1519 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1520 | template <> |
Louis Dionne | 5254b37 | 2018-10-25 12:13:43 +0000 | [diff] [blame] | 1521 | struct _LIBCPP_TEMPLATE_VIS __narrow_to_utf8<32> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1522 | : public codecvt<char32_t, char, mbstate_t> |
| 1523 | { |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1524 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1525 | __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {} |
Marek Kurdej | 718b62c | 2020-12-02 08:57:02 +0100 | [diff] [blame] | 1526 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1527 | |
Louis Dionne | 5254b37 | 2018-10-25 12:13:43 +0000 | [diff] [blame] | 1528 | _LIBCPP_EXPORTED_FROM_ABI ~__narrow_to_utf8(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1529 | |
| 1530 | template <class _OutputIterator, class _CharT> |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1531 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1532 | _OutputIterator |
| 1533 | operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const |
| 1534 | { |
| 1535 | result __r = ok; |
| 1536 | mbstate_t __mb; |
| 1537 | while (__wb < __we && __r != error) |
| 1538 | { |
| 1539 | const int __sz = 32; |
| 1540 | char __buf[__sz]; |
| 1541 | char* __bn; |
| 1542 | const char32_t* __wn = (const char32_t*)__wb; |
| 1543 | __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn, |
| 1544 | __buf, __buf+__sz, __bn); |
| 1545 | if (__r == codecvt_base::error || __wn == (const char32_t*)__wb) |
| 1546 | __throw_runtime_error("locale not supported"); |
| 1547 | for (const char* __p = __buf; __p < __bn; ++__p, ++__s) |
| 1548 | *__s = *__p; |
| 1549 | __wb = (const _CharT*)__wn; |
| 1550 | } |
| 1551 | return __s; |
| 1552 | } |
| 1553 | }; |
| 1554 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1555 | template <size_t _Np> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1556 | struct __widen_from_utf8 |
| 1557 | { |
| 1558 | template <class _OutputIterator> |
| 1559 | _OutputIterator |
| 1560 | operator()(_OutputIterator __s, const char* __nb, const char* __ne) const; |
| 1561 | }; |
| 1562 | |
| 1563 | template <> |
| 1564 | struct __widen_from_utf8<8> |
| 1565 | { |
| 1566 | template <class _OutputIterator> |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1567 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1568 | _OutputIterator |
| 1569 | operator()(_OutputIterator __s, const char* __nb, const char* __ne) const |
| 1570 | { |
| 1571 | for (; __nb < __ne; ++__nb, ++__s) |
| 1572 | *__s = *__nb; |
| 1573 | return __s; |
| 1574 | } |
| 1575 | }; |
| 1576 | |
Marek Kurdej | 718b62c | 2020-12-02 08:57:02 +0100 | [diff] [blame] | 1577 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1578 | template <> |
Louis Dionne | 5254b37 | 2018-10-25 12:13:43 +0000 | [diff] [blame] | 1579 | struct _LIBCPP_TEMPLATE_VIS __widen_from_utf8<16> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1580 | : public codecvt<char16_t, char, mbstate_t> |
| 1581 | { |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1582 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1583 | __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {} |
Marek Kurdej | 718b62c | 2020-12-02 08:57:02 +0100 | [diff] [blame] | 1584 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1585 | |
Louis Dionne | 5254b37 | 2018-10-25 12:13:43 +0000 | [diff] [blame] | 1586 | _LIBCPP_EXPORTED_FROM_ABI ~__widen_from_utf8(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1587 | |
| 1588 | template <class _OutputIterator> |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1589 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1590 | _OutputIterator |
| 1591 | operator()(_OutputIterator __s, const char* __nb, const char* __ne) const |
| 1592 | { |
| 1593 | result __r = ok; |
| 1594 | mbstate_t __mb; |
| 1595 | while (__nb < __ne && __r != error) |
| 1596 | { |
| 1597 | const int __sz = 32; |
| 1598 | char16_t __buf[__sz]; |
| 1599 | char16_t* __bn; |
| 1600 | const char* __nn = __nb; |
| 1601 | __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn, |
| 1602 | __buf, __buf+__sz, __bn); |
| 1603 | if (__r == codecvt_base::error || __nn == __nb) |
| 1604 | __throw_runtime_error("locale not supported"); |
| 1605 | for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s) |
Martin Storsjö | 971fc1c | 2020-10-27 13:01:54 +0200 | [diff] [blame] | 1606 | *__s = *__p; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1607 | __nb = __nn; |
| 1608 | } |
| 1609 | return __s; |
| 1610 | } |
| 1611 | }; |
| 1612 | |
Marek Kurdej | 718b62c | 2020-12-02 08:57:02 +0100 | [diff] [blame] | 1613 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1614 | template <> |
Louis Dionne | 5254b37 | 2018-10-25 12:13:43 +0000 | [diff] [blame] | 1615 | struct _LIBCPP_TEMPLATE_VIS __widen_from_utf8<32> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1616 | : public codecvt<char32_t, char, mbstate_t> |
| 1617 | { |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1618 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1619 | __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {} |
Marek Kurdej | 718b62c | 2020-12-02 08:57:02 +0100 | [diff] [blame] | 1620 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1621 | |
Louis Dionne | 5254b37 | 2018-10-25 12:13:43 +0000 | [diff] [blame] | 1622 | _LIBCPP_EXPORTED_FROM_ABI ~__widen_from_utf8(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1623 | |
| 1624 | template <class _OutputIterator> |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1625 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1626 | _OutputIterator |
| 1627 | operator()(_OutputIterator __s, const char* __nb, const char* __ne) const |
| 1628 | { |
| 1629 | result __r = ok; |
| 1630 | mbstate_t __mb; |
| 1631 | while (__nb < __ne && __r != error) |
| 1632 | { |
| 1633 | const int __sz = 32; |
| 1634 | char32_t __buf[__sz]; |
| 1635 | char32_t* __bn; |
| 1636 | const char* __nn = __nb; |
| 1637 | __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn, |
| 1638 | __buf, __buf+__sz, __bn); |
| 1639 | if (__r == codecvt_base::error || __nn == __nb) |
| 1640 | __throw_runtime_error("locale not supported"); |
| 1641 | for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s) |
Martin Storsjö | 971fc1c | 2020-10-27 13:01:54 +0200 | [diff] [blame] | 1642 | *__s = *__p; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1643 | __nb = __nn; |
| 1644 | } |
| 1645 | return __s; |
| 1646 | } |
| 1647 | }; |
| 1648 | |
| 1649 | // template <class charT> class numpunct |
| 1650 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1651 | template <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1652 | |
| 1653 | template <> |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 1654 | class _LIBCPP_TYPE_VIS numpunct<char> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1655 | : public locale::facet |
| 1656 | { |
| 1657 | public: |
| 1658 | typedef char char_type; |
| 1659 | typedef basic_string<char_type> string_type; |
| 1660 | |
| 1661 | explicit numpunct(size_t __refs = 0); |
| 1662 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1663 | _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();} |
| 1664 | _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();} |
| 1665 | _LIBCPP_INLINE_VISIBILITY string grouping() const {return do_grouping();} |
| 1666 | _LIBCPP_INLINE_VISIBILITY string_type truename() const {return do_truename();} |
| 1667 | _LIBCPP_INLINE_VISIBILITY string_type falsename() const {return do_falsename();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1668 | |
| 1669 | static locale::id id; |
| 1670 | |
| 1671 | protected: |
| 1672 | ~numpunct(); |
| 1673 | virtual char_type do_decimal_point() const; |
| 1674 | virtual char_type do_thousands_sep() const; |
| 1675 | virtual string do_grouping() const; |
| 1676 | virtual string_type do_truename() const; |
| 1677 | virtual string_type do_falsename() const; |
| 1678 | |
| 1679 | char_type __decimal_point_; |
| 1680 | char_type __thousands_sep_; |
| 1681 | string __grouping_; |
| 1682 | }; |
| 1683 | |
| 1684 | template <> |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 1685 | class _LIBCPP_TYPE_VIS numpunct<wchar_t> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1686 | : public locale::facet |
| 1687 | { |
| 1688 | public: |
| 1689 | typedef wchar_t char_type; |
| 1690 | typedef basic_string<char_type> string_type; |
| 1691 | |
| 1692 | explicit numpunct(size_t __refs = 0); |
| 1693 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1694 | _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();} |
| 1695 | _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();} |
| 1696 | _LIBCPP_INLINE_VISIBILITY string grouping() const {return do_grouping();} |
| 1697 | _LIBCPP_INLINE_VISIBILITY string_type truename() const {return do_truename();} |
| 1698 | _LIBCPP_INLINE_VISIBILITY string_type falsename() const {return do_falsename();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1699 | |
| 1700 | static locale::id id; |
| 1701 | |
| 1702 | protected: |
| 1703 | ~numpunct(); |
| 1704 | virtual char_type do_decimal_point() const; |
| 1705 | virtual char_type do_thousands_sep() const; |
| 1706 | virtual string do_grouping() const; |
| 1707 | virtual string_type do_truename() const; |
| 1708 | virtual string_type do_falsename() const; |
| 1709 | |
| 1710 | char_type __decimal_point_; |
| 1711 | char_type __thousands_sep_; |
| 1712 | string __grouping_; |
| 1713 | }; |
| 1714 | |
| 1715 | // template <class charT> class numpunct_byname |
| 1716 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1717 | template <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct_byname; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1718 | |
| 1719 | template <> |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 1720 | class _LIBCPP_TYPE_VIS numpunct_byname<char> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1721 | : public numpunct<char> |
| 1722 | { |
| 1723 | public: |
| 1724 | typedef char char_type; |
| 1725 | typedef basic_string<char_type> string_type; |
| 1726 | |
| 1727 | explicit numpunct_byname(const char* __nm, size_t __refs = 0); |
| 1728 | explicit numpunct_byname(const string& __nm, size_t __refs = 0); |
| 1729 | |
| 1730 | protected: |
| 1731 | ~numpunct_byname(); |
| 1732 | |
| 1733 | private: |
| 1734 | void __init(const char*); |
| 1735 | }; |
| 1736 | |
| 1737 | template <> |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 1738 | class _LIBCPP_TYPE_VIS numpunct_byname<wchar_t> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1739 | : public numpunct<wchar_t> |
| 1740 | { |
| 1741 | public: |
| 1742 | typedef wchar_t char_type; |
| 1743 | typedef basic_string<char_type> string_type; |
| 1744 | |
| 1745 | explicit numpunct_byname(const char* __nm, size_t __refs = 0); |
| 1746 | explicit numpunct_byname(const string& __nm, size_t __refs = 0); |
| 1747 | |
| 1748 | protected: |
| 1749 | ~numpunct_byname(); |
| 1750 | |
| 1751 | private: |
| 1752 | void __init(const char*); |
| 1753 | }; |
| 1754 | |
| 1755 | _LIBCPP_END_NAMESPACE_STD |
| 1756 | |
| 1757 | #endif // _LIBCPP___LOCALE |