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