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