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