| 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_LOCALE |
| 11 | #define _LIBCPP_LOCALE |
| 12 | |
| 13 | /* |
| 14 | locale synopsis |
| 15 | |
| 16 | namespace std |
| 17 | { |
| 18 | |
| 19 | class locale |
| 20 | { |
| 21 | public: |
| 22 | // types: |
| 23 | class facet; |
| 24 | class id; |
| 25 | |
| 26 | typedef int category; |
| 27 | static const category // values assigned here are for exposition only |
| 28 | none = 0x000, |
| 29 | collate = 0x010, |
| 30 | ctype = 0x020, |
| 31 | monetary = 0x040, |
| 32 | numeric = 0x080, |
| 33 | time = 0x100, |
| 34 | messages = 0x200, |
| 35 | all = collate | ctype | monetary | numeric | time | messages; |
| 36 | |
| 37 | // construct/copy/destroy: |
| 38 | locale() noexcept; |
| 39 | locale(const locale& other) noexcept; |
| 40 | explicit locale(const char* std_name); |
| 41 | explicit locale(const string& std_name); |
| 42 | locale(const locale& other, const char* std_name, category); |
| 43 | locale(const locale& other, const string& std_name, category); |
| 44 | template <class Facet> locale(const locale& other, Facet* f); |
| 45 | locale(const locale& other, const locale& one, category); |
| 46 | |
| 47 | ~locale(); // not virtual |
| 48 | |
| 49 | const locale& operator=(const locale& other) noexcept; |
| 50 | |
| 51 | template <class Facet> locale combine(const locale& other) const; |
| 52 | |
| 53 | // locale operations: |
| 54 | basic_string<char> name() const; |
| 55 | bool operator==(const locale& other) const; |
| 56 | bool operator!=(const locale& other) const; // removed C++20 |
| 57 | template <class charT, class Traits, class Allocator> |
| 58 | bool operator()(const basic_string<charT,Traits,Allocator>& s1, |
| 59 | const basic_string<charT,Traits,Allocator>& s2) const; |
| 60 | |
| 61 | // global locale objects: |
| 62 | static locale global(const locale&); |
| 63 | static const locale& classic(); |
| 64 | }; |
| 65 | |
| 66 | template <class Facet> const Facet& use_facet(const locale&); |
| 67 | template <class Facet> bool has_facet(const locale&) noexcept; |
| 68 | |
| 69 | // 22.3.3, convenience interfaces: |
| 70 | template <class charT> bool isspace (charT c, const locale& loc); |
| 71 | template <class charT> bool isprint (charT c, const locale& loc); |
| 72 | template <class charT> bool iscntrl (charT c, const locale& loc); |
| 73 | template <class charT> bool isupper (charT c, const locale& loc); |
| 74 | template <class charT> bool islower (charT c, const locale& loc); |
| 75 | template <class charT> bool isalpha (charT c, const locale& loc); |
| 76 | template <class charT> bool isdigit (charT c, const locale& loc); |
| 77 | template <class charT> bool ispunct (charT c, const locale& loc); |
| 78 | template <class charT> bool isxdigit(charT c, const locale& loc); |
| 79 | template <class charT> bool isalnum (charT c, const locale& loc); |
| 80 | template <class charT> bool isgraph (charT c, const locale& loc); |
| 81 | template <class charT> charT toupper(charT c, const locale& loc); |
| 82 | template <class charT> charT tolower(charT c, const locale& loc); |
| 83 | |
| 84 | template<class Codecvt, class Elem = wchar_t, |
| 85 | class Wide_alloc = allocator<Elem>, |
| 86 | class Byte_alloc = allocator<char>> |
| 87 | class wstring_convert // Removed in C++26 |
| 88 | { |
| 89 | public: |
| 90 | typedef basic_string<char, char_traits<char>, Byte_alloc> byte_string; |
| 91 | typedef basic_string<Elem, char_traits<Elem>, Wide_alloc> wide_string; |
| 92 | typedef typename Codecvt::state_type state_type; |
| 93 | typedef typename wide_string::traits_type::int_type int_type; |
| 94 | |
| 95 | wstring_convert(Codecvt* pcvt = new Codecvt); // before C++14 |
| 96 | explicit wstring_convert(Codecvt* pcvt = new Codecvt); // before C++20 |
| 97 | wstring_convert() : wstring_convert(new Codecvt) {} // C++20 |
| 98 | explicit wstring_convert(Codecvt* pcvt); // C++20 |
| 99 | |
| 100 | wstring_convert(Codecvt* pcvt, state_type state); |
| 101 | explicit wstring_convert(const byte_string& byte_err, // explicit in C++14 |
| 102 | const wide_string& wide_err = wide_string()); |
| 103 | wstring_convert(const wstring_convert&) = delete; // C++14 |
| 104 | wstring_convert & operator=(const wstring_convert &) = delete; // C++14 |
| 105 | ~wstring_convert(); |
| 106 | |
| 107 | wide_string from_bytes(char byte); |
| 108 | wide_string from_bytes(const char* ptr); |
| 109 | wide_string from_bytes(const byte_string& str); |
| 110 | wide_string from_bytes(const char* first, const char* last); |
| 111 | |
| 112 | byte_string to_bytes(Elem wchar); |
| 113 | byte_string to_bytes(const Elem* wptr); |
| 114 | byte_string to_bytes(const wide_string& wstr); |
| 115 | byte_string to_bytes(const Elem* first, const Elem* last); |
| 116 | |
| 117 | size_t converted() const; // noexcept in C++14 |
| 118 | state_type state() const; |
| 119 | }; |
| 120 | |
| 121 | template <class Codecvt, class Elem = wchar_t, class Tr = char_traits<Elem>> |
| 122 | class wbuffer_convert // Removed in C++26 |
| 123 | : public basic_streambuf<Elem, Tr> |
| 124 | { |
| 125 | public: |
| 126 | typedef typename Tr::state_type state_type; |
| 127 | |
| 128 | wbuffer_convert(streambuf* bytebuf = 0, Codecvt* pcvt = new Codecvt, |
| 129 | state_type state = state_type()); // before C++14 |
| 130 | explicit wbuffer_convert(streambuf* bytebuf = nullptr, Codecvt* pcvt = new Codecvt, |
| 131 | state_type state = state_type()); // before C++20 |
| 132 | wbuffer_convert() : wbuffer_convert(nullptr) {} // C++20 |
| 133 | explicit wbuffer_convert(streambuf* bytebuf, Codecvt* pcvt = new Codecvt, |
| 134 | state_type state = state_type()); // C++20 |
| 135 | |
| 136 | wbuffer_convert(const wbuffer_convert&) = delete; // C++14 |
| 137 | wbuffer_convert & operator=(const wbuffer_convert &) = delete; // C++14 |
| 138 | ~wbuffer_convert(); // C++14 |
| 139 | |
| 140 | streambuf* rdbuf() const; |
| 141 | streambuf* rdbuf(streambuf* bytebuf); |
| 142 | |
| 143 | state_type state() const; |
| 144 | }; |
| 145 | |
| 146 | // 22.4.1 and 22.4.1.3, ctype: |
| 147 | class ctype_base; |
| 148 | template <class charT> class ctype; |
| 149 | template <> class ctype<char>; // specialization |
| 150 | template <class charT> class ctype_byname; |
| 151 | template <> class ctype_byname<char>; // specialization |
| 152 | |
| 153 | class codecvt_base; |
| 154 | template <class internT, class externT, class stateT> class codecvt; |
| 155 | template <class internT, class externT, class stateT> class codecvt_byname; |
| 156 | |
| 157 | // 22.4.2 and 22.4.3, numeric: |
| 158 | template <class charT, class InputIterator> class num_get; |
| 159 | template <class charT, class OutputIterator> class num_put; |
| 160 | template <class charT> class numpunct; |
| 161 | template <class charT> class numpunct_byname; |
| 162 | |
| 163 | // 22.4.4, col lation: |
| 164 | template <class charT> class collate; |
| 165 | template <class charT> class collate_byname; |
| 166 | |
| 167 | // 22.4.5, date and time: |
| 168 | class time_base; |
| 169 | template <class charT, class InputIterator> class time_get; |
| 170 | template <class charT, class InputIterator> class time_get_byname; |
| 171 | template <class charT, class OutputIterator> class time_put; |
| 172 | template <class charT, class OutputIterator> class time_put_byname; |
| 173 | |
| 174 | // 22.4.6, money: |
| 175 | class money_base; |
| 176 | template <class charT, class InputIterator> class money_get; |
| 177 | template <class charT, class OutputIterator> class money_put; |
| 178 | template <class charT, bool Intl> class moneypunct; |
| 179 | template <class charT, bool Intl> class moneypunct_byname; |
| 180 | |
| 181 | // 22.4.7, message retrieval: |
| 182 | class messages_base; |
| 183 | template <class charT> class messages; |
| 184 | template <class charT> class messages_byname; |
| 185 | |
| 186 | } // std |
| 187 | |
| 188 | */ |
| 189 | |
| 190 | #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
| 191 | # include <__cxx03/locale> |
| 192 | #else |
| 193 | # include <__config> |
| 194 | |
| 195 | # if _LIBCPP_HAS_LOCALIZATION |
| 196 | |
| 197 | # include <__algorithm/copy.h> |
| 198 | # include <__algorithm/equal.h> |
| 199 | # include <__algorithm/find.h> |
| 200 | # include <__algorithm/max.h> |
| 201 | # include <__algorithm/reverse.h> |
| 202 | # include <__algorithm/unwrap_iter.h> |
| 203 | # include <__assert> |
| 204 | # include <__charconv/to_chars_integral.h> |
| 205 | # include <__charconv/traits.h> |
| 206 | # include <__iterator/access.h> |
| 207 | # include <__iterator/back_insert_iterator.h> |
| 208 | # include <__iterator/istreambuf_iterator.h> |
| 209 | # include <__iterator/ostreambuf_iterator.h> |
| 210 | # include <__locale> |
| 211 | # include <__locale_dir/pad_and_output.h> |
| 212 | # include <__memory/addressof.h> |
| 213 | # include <__memory/unique_ptr.h> |
| 214 | # include <__new/exceptions.h> |
| 215 | # include <__system_error/errc.h> |
| 216 | # include <__type_traits/make_unsigned.h> |
| 217 | # include <cerrno> |
| 218 | # include <cstdio> |
| 219 | # include <cstdlib> |
| 220 | # include <ctime> |
| 221 | # include <ios> |
| 222 | # include <limits> |
| 223 | # include <streambuf> |
| 224 | # include <version> |
| 225 | |
| 226 | // TODO: Properly qualify calls now that the locale base API defines functions instead of macros |
| 227 | // NOLINTBEGIN(libcpp-robust-against-adl) |
| 228 | |
| 229 | # if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) |
| 230 | // Most unix variants have catopen. These are the specific ones that don't. |
| 231 | # if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION) && !defined(__EMSCRIPTEN__) |
| 232 | # define _LIBCPP_HAS_CATOPEN 1 |
| 233 | # include <nl_types.h> |
| 234 | # else |
| 235 | # define _LIBCPP_HAS_CATOPEN 0 |
| 236 | # endif |
| 237 | # else |
| 238 | # define _LIBCPP_HAS_CATOPEN 0 |
| 239 | # endif |
| 240 | |
| 241 | # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 242 | # pragma GCC system_header |
| 243 | # endif |
| 244 | |
| 245 | _LIBCPP_PUSH_MACROS |
| 246 | # include <__undef_macros> |
| 247 | |
| 248 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 249 | |
| 250 | # if defined(__APPLE__) || defined(__FreeBSD__) |
| 251 | # define _LIBCPP_GET_C_LOCALE 0 |
| 252 | # elif defined(__NetBSD__) |
| 253 | # define _LIBCPP_GET_C_LOCALE LC_C_LOCALE |
| 254 | # else |
| 255 | # define _LIBCPP_GET_C_LOCALE __cloc() |
| 256 | // Get the C locale object |
| 257 | _LIBCPP_EXPORTED_FROM_ABI __locale::__locale_t __cloc(); |
| 258 | # define __cloc_defined |
| 259 | # endif |
| 260 | |
| 261 | // __scan_keyword |
| 262 | // Scans [__b, __e) until a match is found in the basic_strings range |
| 263 | // [__kb, __ke) or until it can be shown that there is no match in [__kb, __ke). |
| 264 | // __b will be incremented (visibly), consuming CharT until a match is found |
| 265 | // or proved to not exist. A keyword may be "", in which will match anything. |
| 266 | // If one keyword is a prefix of another, and the next CharT in the input |
| 267 | // might match another keyword, the algorithm will attempt to find the longest |
| 268 | // matching keyword. If the longer matching keyword ends up not matching, then |
| 269 | // no keyword match is found. If no keyword match is found, __ke is returned |
| 270 | // and failbit is set in __err. |
| 271 | // Else an iterator pointing to the matching keyword is found. If more than |
| 272 | // one keyword matches, an iterator to the first matching keyword is returned. |
| 273 | // If on exit __b == __e, eofbit is set in __err. If __case_sensitive is false, |
| 274 | // __ct is used to force to lower case before comparing characters. |
| 275 | // Examples: |
| 276 | // Keywords: "a", "abb" |
| 277 | // If the input is "a", the first keyword matches and eofbit is set. |
| 278 | // If the input is "abc", no match is found and "ab" are consumed. |
| 279 | template <class _InputIterator, class _ForwardIterator, class _Ctype> |
| 280 | _LIBCPP_HIDE_FROM_ABI _ForwardIterator __scan_keyword( |
| 281 | _InputIterator& __b, |
| 282 | _InputIterator __e, |
| 283 | _ForwardIterator __kb, |
| 284 | _ForwardIterator __ke, |
| 285 | const _Ctype& __ct, |
| 286 | ios_base::iostate& __err, |
| 287 | bool __case_sensitive = true) { |
| 288 | typedef typename iterator_traits<_InputIterator>::value_type _CharT; |
| 289 | size_t __nkw = static_cast<size_t>(std::distance(__kb, __ke)); |
| 290 | const unsigned char __doesnt_match = '\0'; |
| 291 | const unsigned char __might_match = '\1'; |
| 292 | const unsigned char __does_match = '\2'; |
| 293 | unsigned char __statbuf[100]; |
| 294 | unsigned char* __status = __statbuf; |
| 295 | unique_ptr<unsigned char, void (*)(void*)> __stat_hold(nullptr, free); |
| 296 | if (__nkw > sizeof(__statbuf)) { |
| 297 | __status = (unsigned char*)malloc(size: __nkw); |
| 298 | if (__status == nullptr) |
| 299 | std::__throw_bad_alloc(); |
| 300 | __stat_hold.reset(p: __status); |
| 301 | } |
| 302 | size_t __n_might_match = __nkw; // At this point, any keyword might match |
| 303 | size_t __n_does_match = 0; // but none of them definitely do |
| 304 | // Initialize all statuses to __might_match, except for "" keywords are __does_match |
| 305 | unsigned char* __st = __status; |
| 306 | for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void)++__st) { |
| 307 | if (!__ky->empty()) |
| 308 | *__st = __might_match; |
| 309 | else { |
| 310 | *__st = __does_match; |
| 311 | --__n_might_match; |
| 312 | ++__n_does_match; |
| 313 | } |
| 314 | } |
| 315 | // While there might be a match, test keywords against the next CharT |
| 316 | for (size_t __indx = 0; __b != __e && __n_might_match > 0; ++__indx) { |
| 317 | // Peek at the next CharT but don't consume it |
| 318 | _CharT __c = *__b; |
| 319 | if (!__case_sensitive) |
| 320 | __c = __ct.toupper(__c); |
| 321 | bool __consume = false; |
| 322 | // For each keyword which might match, see if the __indx character is __c |
| 323 | // If a match if found, consume __c |
| 324 | // If a match is found, and that is the last character in the keyword, |
| 325 | // then that keyword matches. |
| 326 | // If the keyword doesn't match this character, then change the keyword |
| 327 | // to doesn't match |
| 328 | __st = __status; |
| 329 | for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void)++__st) { |
| 330 | if (*__st == __might_match) { |
| 331 | _CharT __kc = (*__ky)[__indx]; |
| 332 | if (!__case_sensitive) |
| 333 | __kc = __ct.toupper(__kc); |
| 334 | if (__c == __kc) { |
| 335 | __consume = true; |
| 336 | if (__ky->size() == __indx + 1) { |
| 337 | *__st = __does_match; |
| 338 | --__n_might_match; |
| 339 | ++__n_does_match; |
| 340 | } |
| 341 | } else { |
| 342 | *__st = __doesnt_match; |
| 343 | --__n_might_match; |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | // consume if we matched a character |
| 348 | if (__consume) { |
| 349 | ++__b; |
| 350 | // If we consumed a character and there might be a matched keyword that |
| 351 | // was marked matched on a previous iteration, then such keywords |
| 352 | // which are now marked as not matching. |
| 353 | if (__n_might_match + __n_does_match > 1) { |
| 354 | __st = __status; |
| 355 | for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void)++__st) { |
| 356 | if (*__st == __does_match && __ky->size() != __indx + 1) { |
| 357 | *__st = __doesnt_match; |
| 358 | --__n_does_match; |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | } |
| 364 | // We've exited the loop because we hit eof and/or we have no more "might matches". |
| 365 | if (__b == __e) |
| 366 | __err |= ios_base::eofbit; |
| 367 | // Return the first matching result |
| 368 | for (__st = __status; __kb != __ke; ++__kb, (void)++__st) |
| 369 | if (*__st == __does_match) |
| 370 | break; |
| 371 | if (__kb == __ke) |
| 372 | __err |= ios_base::failbit; |
| 373 | return __kb; |
| 374 | } |
| 375 | |
| 376 | struct _LIBCPP_EXPORTED_FROM_ABI __num_get_base { |
| 377 | static const int __num_get_buf_sz = 40; |
| 378 | |
| 379 | static int __get_base(ios_base&); |
| 380 | static const char __src[33]; // "0123456789abcdefABCDEFxX+-pPiInN" |
| 381 | // count of leading characters in __src used for parsing integers ("012..X+-") |
| 382 | static const size_t __int_chr_cnt = 26; |
| 383 | // count of leading characters in __src used for parsing floating-point values ("012..-pP") |
| 384 | static const size_t __fp_chr_cnt = 28; |
| 385 | }; |
| 386 | |
| 387 | _LIBCPP_EXPORTED_FROM_ABI void |
| 388 | __check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end, ios_base::iostate& __err); |
| 389 | |
| 390 | template <class _CharT> |
| 391 | struct __num_get : protected __num_get_base { |
| 392 | static string __stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point, _CharT& __thousands_sep); |
| 393 | |
| 394 | static int __stage2_float_loop( |
| 395 | _CharT __ct, |
| 396 | bool& __in_units, |
| 397 | char& __exp, |
| 398 | char* __a, |
| 399 | char*& __a_end, |
| 400 | _CharT __decimal_point, |
| 401 | _CharT __thousands_sep, |
| 402 | const string& __grouping, |
| 403 | unsigned* __g, |
| 404 | unsigned*& __g_end, |
| 405 | unsigned& __dc, |
| 406 | _CharT* __atoms); |
| 407 | |
| 408 | [[__deprecated__("This exists only for ABI compatibility" )]] static string |
| 409 | __stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep); |
| 410 | static int __stage2_int_loop( |
| 411 | _CharT __ct, |
| 412 | int __base, |
| 413 | char* __a, |
| 414 | char*& __a_end, |
| 415 | unsigned& __dc, |
| 416 | _CharT __thousands_sep, |
| 417 | const string& __grouping, |
| 418 | unsigned* __g, |
| 419 | unsigned*& __g_end, |
| 420 | _CharT* __atoms); |
| 421 | |
| 422 | _LIBCPP_HIDE_FROM_ABI static string __stage2_int_prep(ios_base& __iob, _CharT& __thousands_sep) { |
| 423 | locale __loc = __iob.getloc(); |
| 424 | const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc); |
| 425 | __thousands_sep = __np.thousands_sep(); |
| 426 | return __np.grouping(); |
| 427 | } |
| 428 | |
| 429 | _LIBCPP_HIDE_FROM_ABI const _CharT* __do_widen(ios_base& __iob, _CharT* __atoms) const { |
| 430 | return __do_widen_p(__iob, __atoms); |
| 431 | } |
| 432 | |
| 433 | private: |
| 434 | template <typename _Tp> |
| 435 | _LIBCPP_HIDE_FROM_ABI const _Tp* __do_widen_p(ios_base& __iob, _Tp* __atoms) const { |
| 436 | locale __loc = __iob.getloc(); |
| 437 | use_facet<ctype<_Tp> >(__loc).widen(__src, __src + __int_chr_cnt, __atoms); |
| 438 | return __atoms; |
| 439 | } |
| 440 | |
| 441 | _LIBCPP_HIDE_FROM_ABI const char* __do_widen_p(ios_base& __iob, char* __atoms) const { |
| 442 | (void)__iob; |
| 443 | (void)__atoms; |
| 444 | return __src; |
| 445 | } |
| 446 | }; |
| 447 | |
| 448 | template <class _CharT> |
| 449 | string __num_get<_CharT>::__stage2_float_prep( |
| 450 | ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point, _CharT& __thousands_sep) { |
| 451 | locale __loc = __iob.getloc(); |
| 452 | std::use_facet<ctype<_CharT> >(__loc).widen(__src, __src + __fp_chr_cnt, __atoms); |
| 453 | const numpunct<_CharT>& __np = std::use_facet<numpunct<_CharT> >(__loc); |
| 454 | __decimal_point = __np.decimal_point(); |
| 455 | __thousands_sep = __np.thousands_sep(); |
| 456 | return __np.grouping(); |
| 457 | } |
| 458 | |
| 459 | template <class _CharT> |
| 460 | int __num_get<_CharT>::__stage2_int_loop( |
| 461 | _CharT __ct, |
| 462 | int __base, |
| 463 | char* __a, |
| 464 | char*& __a_end, |
| 465 | unsigned& __dc, |
| 466 | _CharT __thousands_sep, |
| 467 | const string& __grouping, |
| 468 | unsigned* __g, |
| 469 | unsigned*& __g_end, |
| 470 | _CharT* __atoms) { |
| 471 | if (__a_end == __a && (__ct == __atoms[24] || __ct == __atoms[25])) { |
| 472 | *__a_end++ = __ct == __atoms[24] ? '+' : '-'; |
| 473 | __dc = 0; |
| 474 | return 0; |
| 475 | } |
| 476 | if (__grouping.size() != 0 && __ct == __thousands_sep) { |
| 477 | if (__g_end - __g < __num_get_buf_sz) { |
| 478 | *__g_end++ = __dc; |
| 479 | __dc = 0; |
| 480 | } |
| 481 | return 0; |
| 482 | } |
| 483 | ptrdiff_t __f = std::find(__atoms, __atoms + __int_chr_cnt, __ct) - __atoms; |
| 484 | if (__f >= 24) |
| 485 | return -1; |
| 486 | switch (__base) { |
| 487 | case 8: |
| 488 | case 10: |
| 489 | if (__f >= __base) |
| 490 | return -1; |
| 491 | break; |
| 492 | case 16: |
| 493 | if (__f < 22) |
| 494 | break; |
| 495 | if (__a_end != __a && __a_end - __a <= 2 && __a_end[-1] == '0') { |
| 496 | __dc = 0; |
| 497 | *__a_end++ = __src[__f]; |
| 498 | return 0; |
| 499 | } |
| 500 | return -1; |
| 501 | } |
| 502 | *__a_end++ = __src[__f]; |
| 503 | ++__dc; |
| 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | template <class _CharT> |
| 508 | int __num_get<_CharT>::__stage2_float_loop( |
| 509 | _CharT __ct, |
| 510 | bool& __in_units, |
| 511 | char& __exp, |
| 512 | char* __a, |
| 513 | char*& __a_end, |
| 514 | _CharT __decimal_point, |
| 515 | _CharT __thousands_sep, |
| 516 | const string& __grouping, |
| 517 | unsigned* __g, |
| 518 | unsigned*& __g_end, |
| 519 | unsigned& __dc, |
| 520 | _CharT* __atoms) { |
| 521 | if (__ct == __decimal_point) { |
| 522 | if (!__in_units) |
| 523 | return -1; |
| 524 | __in_units = false; |
| 525 | *__a_end++ = '.'; |
| 526 | if (__grouping.size() != 0 && __g_end - __g < __num_get_buf_sz) |
| 527 | *__g_end++ = __dc; |
| 528 | return 0; |
| 529 | } |
| 530 | if (__ct == __thousands_sep && __grouping.size() != 0) { |
| 531 | if (!__in_units) |
| 532 | return -1; |
| 533 | if (__g_end - __g < __num_get_buf_sz) { |
| 534 | *__g_end++ = __dc; |
| 535 | __dc = 0; |
| 536 | } |
| 537 | return 0; |
| 538 | } |
| 539 | ptrdiff_t __f = std::find(__atoms, __atoms + __num_get_base::__fp_chr_cnt, __ct) - __atoms; |
| 540 | if (__f >= static_cast<ptrdiff_t>(__num_get_base::__fp_chr_cnt)) |
| 541 | return -1; |
| 542 | char __x = __src[__f]; |
| 543 | if (__x == '-' || __x == '+') { |
| 544 | if (__a_end == __a || (std::toupper(c: __a_end[-1]) == std::toupper(c: __exp))) { |
| 545 | *__a_end++ = __x; |
| 546 | return 0; |
| 547 | } |
| 548 | return -1; |
| 549 | } |
| 550 | if (__x == 'x' || __x == 'X') |
| 551 | __exp = 'P'; |
| 552 | else if (std::toupper(c: __x) == __exp) { |
| 553 | __exp = std::tolower(c: __exp); |
| 554 | if (__in_units) { |
| 555 | __in_units = false; |
| 556 | if (__grouping.size() != 0 && __g_end - __g < __num_get_buf_sz) |
| 557 | *__g_end++ = __dc; |
| 558 | } |
| 559 | } |
| 560 | *__a_end++ = __x; |
| 561 | if (__f >= 22) |
| 562 | return 0; |
| 563 | ++__dc; |
| 564 | return 0; |
| 565 | } |
| 566 | |
| 567 | extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<char>; |
| 568 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 569 | extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<wchar_t>; |
| 570 | # endif |
| 571 | |
| 572 | template <class _Tp> |
| 573 | _LIBCPP_HIDE_FROM_ABI _Tp __do_strtod(const char* __a, char** __p2); |
| 574 | |
| 575 | template <> |
| 576 | inline _LIBCPP_HIDE_FROM_ABI float __do_strtod<float>(const char* __a, char** __p2) { |
| 577 | return __locale::__strtof(nptr: __a, endptr: __p2, _LIBCPP_GET_C_LOCALE); |
| 578 | } |
| 579 | |
| 580 | template <> |
| 581 | inline _LIBCPP_HIDE_FROM_ABI double __do_strtod<double>(const char* __a, char** __p2) { |
| 582 | return __locale::__strtod(nptr: __a, endptr: __p2, _LIBCPP_GET_C_LOCALE); |
| 583 | } |
| 584 | |
| 585 | template <> |
| 586 | inline _LIBCPP_HIDE_FROM_ABI long double __do_strtod<long double>(const char* __a, char** __p2) { |
| 587 | return __locale::__strtold(nptr: __a, endptr: __p2, _LIBCPP_GET_C_LOCALE); |
| 588 | } |
| 589 | |
| 590 | template <class _Tp> |
| 591 | _LIBCPP_HIDE_FROM_ABI _Tp __num_get_float(const char* __a, const char* __a_end, ios_base::iostate& __err) { |
| 592 | if (__a != __a_end) { |
| 593 | __libcpp_remove_reference_t<decltype(errno)> __save_errno = errno; |
| 594 | errno = 0; |
| 595 | char* __p2; |
| 596 | _Tp __ld = std::__do_strtod<_Tp>(__a, &__p2); |
| 597 | __libcpp_remove_reference_t<decltype(errno)> __current_errno = errno; |
| 598 | if (__current_errno == 0) |
| 599 | errno = __save_errno; |
| 600 | if (__p2 != __a_end) { |
| 601 | __err = ios_base::failbit; |
| 602 | return 0; |
| 603 | } else if (__current_errno == ERANGE) |
| 604 | __err = ios_base::failbit; |
| 605 | return __ld; |
| 606 | } |
| 607 | __err = ios_base::failbit; |
| 608 | return 0; |
| 609 | } |
| 610 | |
| 611 | template <class _Tp> |
| 612 | _LIBCPP_HIDE_FROM_ABI _Tp |
| 613 | __num_get_signed_integral(const char* __a, const char* __a_end, ios_base::iostate& __err, int __base) { |
| 614 | if (__a != __a_end) { |
| 615 | __libcpp_remove_reference_t<decltype(errno)> __save_errno = errno; |
| 616 | errno = 0; |
| 617 | char* __p2; |
| 618 | long long __ll = __locale::__strtoll(nptr: __a, endptr: &__p2, __base, _LIBCPP_GET_C_LOCALE); |
| 619 | __libcpp_remove_reference_t<decltype(errno)> __current_errno = errno; |
| 620 | if (__current_errno == 0) |
| 621 | errno = __save_errno; |
| 622 | if (__p2 != __a_end) { |
| 623 | __err = ios_base::failbit; |
| 624 | return 0; |
| 625 | } else if (__current_errno == ERANGE || __ll < numeric_limits<_Tp>::min() || numeric_limits<_Tp>::max() < __ll) { |
| 626 | __err = ios_base::failbit; |
| 627 | if (__ll > 0) |
| 628 | return numeric_limits<_Tp>::max(); |
| 629 | else |
| 630 | return numeric_limits<_Tp>::min(); |
| 631 | } |
| 632 | return static_cast<_Tp>(__ll); |
| 633 | } |
| 634 | __err = ios_base::failbit; |
| 635 | return 0; |
| 636 | } |
| 637 | |
| 638 | template <class _Tp> |
| 639 | _LIBCPP_HIDE_FROM_ABI _Tp |
| 640 | __num_get_unsigned_integral(const char* __a, const char* __a_end, ios_base::iostate& __err, int __base) { |
| 641 | if (__a != __a_end) { |
| 642 | const bool __negate = *__a == '-'; |
| 643 | if (__negate && ++__a == __a_end) { |
| 644 | __err = ios_base::failbit; |
| 645 | return 0; |
| 646 | } |
| 647 | __libcpp_remove_reference_t<decltype(errno)> __save_errno = errno; |
| 648 | errno = 0; |
| 649 | char* __p2; |
| 650 | unsigned long long __ll = __locale::__strtoull(nptr: __a, endptr: &__p2, __base, _LIBCPP_GET_C_LOCALE); |
| 651 | __libcpp_remove_reference_t<decltype(errno)> __current_errno = errno; |
| 652 | if (__current_errno == 0) |
| 653 | errno = __save_errno; |
| 654 | if (__p2 != __a_end) { |
| 655 | __err = ios_base::failbit; |
| 656 | return 0; |
| 657 | } else if (__current_errno == ERANGE || numeric_limits<_Tp>::max() < __ll) { |
| 658 | __err = ios_base::failbit; |
| 659 | return numeric_limits<_Tp>::max(); |
| 660 | } |
| 661 | _Tp __res = static_cast<_Tp>(__ll); |
| 662 | if (__negate) |
| 663 | __res = -__res; |
| 664 | return __res; |
| 665 | } |
| 666 | __err = ios_base::failbit; |
| 667 | return 0; |
| 668 | } |
| 669 | |
| 670 | template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> > |
| 671 | class num_get : public locale::facet, private __num_get<_CharT> { |
| 672 | public: |
| 673 | typedef _CharT char_type; |
| 674 | typedef _InputIterator iter_type; |
| 675 | |
| 676 | _LIBCPP_HIDE_FROM_ABI explicit num_get(size_t __refs = 0) : locale::facet(__refs) {} |
| 677 | |
| 678 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 679 | get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, bool& __v) const { |
| 680 | return do_get(__b, __e, __iob, __err, __v); |
| 681 | } |
| 682 | |
| 683 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 684 | get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long& __v) const { |
| 685 | return do_get(__b, __e, __iob, __err, __v); |
| 686 | } |
| 687 | |
| 688 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 689 | get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long long& __v) const { |
| 690 | return do_get(__b, __e, __iob, __err, __v); |
| 691 | } |
| 692 | |
| 693 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 694 | get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned short& __v) const { |
| 695 | return do_get(__b, __e, __iob, __err, __v); |
| 696 | } |
| 697 | |
| 698 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 699 | get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned int& __v) const { |
| 700 | return do_get(__b, __e, __iob, __err, __v); |
| 701 | } |
| 702 | |
| 703 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 704 | get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned long& __v) const { |
| 705 | return do_get(__b, __e, __iob, __err, __v); |
| 706 | } |
| 707 | |
| 708 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 709 | get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned long long& __v) const { |
| 710 | return do_get(__b, __e, __iob, __err, __v); |
| 711 | } |
| 712 | |
| 713 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 714 | get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, float& __v) const { |
| 715 | return do_get(__b, __e, __iob, __err, __v); |
| 716 | } |
| 717 | |
| 718 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 719 | get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, double& __v) const { |
| 720 | return do_get(__b, __e, __iob, __err, __v); |
| 721 | } |
| 722 | |
| 723 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 724 | get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long double& __v) const { |
| 725 | return do_get(__b, __e, __iob, __err, __v); |
| 726 | } |
| 727 | |
| 728 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 729 | get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, void*& __v) const { |
| 730 | return do_get(__b, __e, __iob, __err, __v); |
| 731 | } |
| 732 | |
| 733 | static locale::id id; |
| 734 | |
| 735 | protected: |
| 736 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~num_get() override {} |
| 737 | |
| 738 | template <class _Fp> |
| 739 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 740 | __do_get_floating_point(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Fp& __v) const { |
| 741 | // Stage 1, nothing to do |
| 742 | // Stage 2 |
| 743 | char_type __atoms[__num_get_base::__fp_chr_cnt]; |
| 744 | char_type __decimal_point; |
| 745 | char_type __thousands_sep; |
| 746 | string __grouping = this->__stage2_float_prep(__iob, __atoms, __decimal_point, __thousands_sep); |
| 747 | string __buf; |
| 748 | __buf.resize(n: __buf.capacity()); |
| 749 | char* __a = &__buf[0]; |
| 750 | char* __a_end = __a; |
| 751 | unsigned __g[__num_get_base::__num_get_buf_sz]; |
| 752 | unsigned* __g_end = __g; |
| 753 | unsigned __dc = 0; |
| 754 | bool __in_units = true; |
| 755 | char __exp = 'E'; |
| 756 | bool __is_leading_parsed = false; |
| 757 | for (; __b != __e; ++__b) { |
| 758 | if (__a_end == __a + __buf.size()) { |
| 759 | size_t __tmp = __buf.size(); |
| 760 | __buf.resize(n: 2 * __buf.size()); |
| 761 | __buf.resize(n: __buf.capacity()); |
| 762 | __a = &__buf[0]; |
| 763 | __a_end = __a + __tmp; |
| 764 | } |
| 765 | if (this->__stage2_float_loop( |
| 766 | *__b, |
| 767 | __in_units, |
| 768 | __exp, |
| 769 | __a, |
| 770 | __a_end, |
| 771 | __decimal_point, |
| 772 | __thousands_sep, |
| 773 | __grouping, |
| 774 | __g, |
| 775 | __g_end, |
| 776 | __dc, |
| 777 | __atoms)) |
| 778 | break; |
| 779 | |
| 780 | // the leading character excluding the sign must be a decimal digit |
| 781 | if (!__is_leading_parsed) { |
| 782 | if (__a_end - __a >= 1 && __a[0] != '-' && __a[0] != '+') { |
| 783 | if (('0' <= __a[0] && __a[0] <= '9') || __a[0] == '.') |
| 784 | __is_leading_parsed = true; |
| 785 | else |
| 786 | break; |
| 787 | } else if (__a_end - __a >= 2 && (__a[0] == '-' || __a[0] == '+')) { |
| 788 | if (('0' <= __a[1] && __a[1] <= '9') || __a[1] == '.') |
| 789 | __is_leading_parsed = true; |
| 790 | else |
| 791 | break; |
| 792 | } |
| 793 | } |
| 794 | } |
| 795 | if (__grouping.size() != 0 && __in_units && __g_end - __g < __num_get_base::__num_get_buf_sz) |
| 796 | *__g_end++ = __dc; |
| 797 | // Stage 3 |
| 798 | __v = std::__num_get_float<_Fp>(__a, __a_end, __err); |
| 799 | // Digit grouping checked |
| 800 | __check_grouping(__grouping, __g, __g_end, __err); |
| 801 | // EOF checked |
| 802 | if (__b == __e) |
| 803 | __err |= ios_base::eofbit; |
| 804 | return __b; |
| 805 | } |
| 806 | |
| 807 | template <class _Signed> |
| 808 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 809 | __do_get_signed(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Signed& __v) const { |
| 810 | // Stage 1 |
| 811 | int __base = this->__get_base(__iob); |
| 812 | // Stage 2 |
| 813 | char_type __thousands_sep; |
| 814 | const int __atoms_size = __num_get_base::__int_chr_cnt; |
| 815 | char_type __atoms1[__atoms_size]; |
| 816 | const char_type* __atoms = this->__do_widen(__iob, __atoms1); |
| 817 | string __grouping = this->__stage2_int_prep(__iob, __thousands_sep); |
| 818 | string __buf; |
| 819 | __buf.resize(n: __buf.capacity()); |
| 820 | char* __a = &__buf[0]; |
| 821 | char* __a_end = __a; |
| 822 | unsigned __g[__num_get_base::__num_get_buf_sz]; |
| 823 | unsigned* __g_end = __g; |
| 824 | unsigned __dc = 0; |
| 825 | for (; __b != __e; ++__b) { |
| 826 | if (__a_end == __a + __buf.size()) { |
| 827 | size_t __tmp = __buf.size(); |
| 828 | __buf.resize(n: 2 * __buf.size()); |
| 829 | __buf.resize(n: __buf.capacity()); |
| 830 | __a = &__buf[0]; |
| 831 | __a_end = __a + __tmp; |
| 832 | } |
| 833 | if (this->__stage2_int_loop( |
| 834 | *__b, |
| 835 | __base, |
| 836 | __a, |
| 837 | __a_end, |
| 838 | __dc, |
| 839 | __thousands_sep, |
| 840 | __grouping, |
| 841 | __g, |
| 842 | __g_end, |
| 843 | const_cast<char_type*>(__atoms))) |
| 844 | break; |
| 845 | } |
| 846 | if (__grouping.size() != 0 && __g_end - __g < __num_get_base::__num_get_buf_sz) |
| 847 | *__g_end++ = __dc; |
| 848 | // Stage 3 |
| 849 | __v = std::__num_get_signed_integral<_Signed>(__a, __a_end, __err, __base); |
| 850 | // Digit grouping checked |
| 851 | __check_grouping(__grouping, __g, __g_end, __err); |
| 852 | // EOF checked |
| 853 | if (__b == __e) |
| 854 | __err |= ios_base::eofbit; |
| 855 | return __b; |
| 856 | } |
| 857 | |
| 858 | template <class _Unsigned> |
| 859 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 860 | __do_get_unsigned(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, _Unsigned& __v) const { |
| 861 | // Stage 1 |
| 862 | int __base = this->__get_base(__iob); |
| 863 | // Stage 2 |
| 864 | char_type __thousands_sep; |
| 865 | const int __atoms_size = __num_get_base::__int_chr_cnt; |
| 866 | char_type __atoms1[__atoms_size]; |
| 867 | const char_type* __atoms = this->__do_widen(__iob, __atoms1); |
| 868 | string __grouping = this->__stage2_int_prep(__iob, __thousands_sep); |
| 869 | string __buf; |
| 870 | __buf.resize(n: __buf.capacity()); |
| 871 | char* __a = &__buf[0]; |
| 872 | char* __a_end = __a; |
| 873 | unsigned __g[__num_get_base::__num_get_buf_sz]; |
| 874 | unsigned* __g_end = __g; |
| 875 | unsigned __dc = 0; |
| 876 | for (; __b != __e; ++__b) { |
| 877 | if (__a_end == __a + __buf.size()) { |
| 878 | size_t __tmp = __buf.size(); |
| 879 | __buf.resize(n: 2 * __buf.size()); |
| 880 | __buf.resize(n: __buf.capacity()); |
| 881 | __a = &__buf[0]; |
| 882 | __a_end = __a + __tmp; |
| 883 | } |
| 884 | if (this->__stage2_int_loop( |
| 885 | *__b, |
| 886 | __base, |
| 887 | __a, |
| 888 | __a_end, |
| 889 | __dc, |
| 890 | __thousands_sep, |
| 891 | __grouping, |
| 892 | __g, |
| 893 | __g_end, |
| 894 | const_cast<char_type*>(__atoms))) |
| 895 | break; |
| 896 | } |
| 897 | if (__grouping.size() != 0 && __g_end - __g < __num_get_base::__num_get_buf_sz) |
| 898 | *__g_end++ = __dc; |
| 899 | // Stage 3 |
| 900 | __v = std::__num_get_unsigned_integral<_Unsigned>(__a, __a_end, __err, __base); |
| 901 | // Digit grouping checked |
| 902 | __check_grouping(__grouping, __g, __g_end, __err); |
| 903 | // EOF checked |
| 904 | if (__b == __e) |
| 905 | __err |= ios_base::eofbit; |
| 906 | return __b; |
| 907 | } |
| 908 | |
| 909 | virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, bool& __v) const; |
| 910 | |
| 911 | virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long& __v) const { |
| 912 | return this->__do_get_signed(__b, __e, __iob, __err, __v); |
| 913 | } |
| 914 | |
| 915 | virtual iter_type |
| 916 | do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long long& __v) const { |
| 917 | return this->__do_get_signed(__b, __e, __iob, __err, __v); |
| 918 | } |
| 919 | |
| 920 | virtual iter_type |
| 921 | do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned short& __v) const { |
| 922 | return this->__do_get_unsigned(__b, __e, __iob, __err, __v); |
| 923 | } |
| 924 | |
| 925 | virtual iter_type |
| 926 | do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned int& __v) const { |
| 927 | return this->__do_get_unsigned(__b, __e, __iob, __err, __v); |
| 928 | } |
| 929 | |
| 930 | virtual iter_type |
| 931 | do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned long& __v) const { |
| 932 | return this->__do_get_unsigned(__b, __e, __iob, __err, __v); |
| 933 | } |
| 934 | |
| 935 | virtual iter_type |
| 936 | do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, unsigned long long& __v) const { |
| 937 | return this->__do_get_unsigned(__b, __e, __iob, __err, __v); |
| 938 | } |
| 939 | |
| 940 | virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, float& __v) const { |
| 941 | return this->__do_get_floating_point(__b, __e, __iob, __err, __v); |
| 942 | } |
| 943 | |
| 944 | virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, double& __v) const { |
| 945 | return this->__do_get_floating_point(__b, __e, __iob, __err, __v); |
| 946 | } |
| 947 | |
| 948 | virtual iter_type |
| 949 | do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, long double& __v) const { |
| 950 | return this->__do_get_floating_point(__b, __e, __iob, __err, __v); |
| 951 | } |
| 952 | |
| 953 | virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, void*& __v) const; |
| 954 | }; |
| 955 | |
| 956 | template <class _CharT, class _InputIterator> |
| 957 | locale::id num_get<_CharT, _InputIterator>::id; |
| 958 | |
| 959 | template <class _CharT, class _InputIterator> |
| 960 | _InputIterator num_get<_CharT, _InputIterator>::do_get( |
| 961 | iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, bool& __v) const { |
| 962 | if ((__iob.flags() & ios_base::boolalpha) == 0) { |
| 963 | long __lv = -1; |
| 964 | __b = do_get(__b, __e, __iob, __err, __lv); |
| 965 | switch (__lv) { |
| 966 | case 0: |
| 967 | __v = false; |
| 968 | break; |
| 969 | case 1: |
| 970 | __v = true; |
| 971 | break; |
| 972 | default: |
| 973 | __v = true; |
| 974 | __err = ios_base::failbit; |
| 975 | break; |
| 976 | } |
| 977 | return __b; |
| 978 | } |
| 979 | const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__iob.getloc()); |
| 980 | const numpunct<_CharT>& __np = std::use_facet<numpunct<_CharT> >(__iob.getloc()); |
| 981 | typedef typename numpunct<_CharT>::string_type string_type; |
| 982 | const string_type __names[2] = {__np.truename(), __np.falsename()}; |
| 983 | const string_type* __i = std::__scan_keyword(__b, __e, __names, __names + 2, __ct, __err); |
| 984 | __v = __i == __names; |
| 985 | return __b; |
| 986 | } |
| 987 | |
| 988 | template <class _CharT, class _InputIterator> |
| 989 | _InputIterator num_get<_CharT, _InputIterator>::do_get( |
| 990 | iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, void*& __v) const { |
| 991 | // Stage 1 |
| 992 | int __base = 16; |
| 993 | // Stage 2 |
| 994 | char_type __atoms[__num_get_base::__int_chr_cnt]; |
| 995 | char_type __thousands_sep = char_type(); |
| 996 | string __grouping; |
| 997 | std::use_facet<ctype<_CharT> >(__iob.getloc()) |
| 998 | .widen(__num_get_base::__src, __num_get_base::__src + __num_get_base::__int_chr_cnt, __atoms); |
| 999 | string __buf; |
| 1000 | __buf.resize(n: __buf.capacity()); |
| 1001 | char* __a = &__buf[0]; |
| 1002 | char* __a_end = __a; |
| 1003 | unsigned __g[__num_get_base::__num_get_buf_sz]; |
| 1004 | unsigned* __g_end = __g; |
| 1005 | unsigned __dc = 0; |
| 1006 | for (; __b != __e; ++__b) { |
| 1007 | if (__a_end == __a + __buf.size()) { |
| 1008 | size_t __tmp = __buf.size(); |
| 1009 | __buf.resize(n: 2 * __buf.size()); |
| 1010 | __buf.resize(n: __buf.capacity()); |
| 1011 | __a = &__buf[0]; |
| 1012 | __a_end = __a + __tmp; |
| 1013 | } |
| 1014 | if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, __thousands_sep, __grouping, __g, __g_end, __atoms)) |
| 1015 | break; |
| 1016 | } |
| 1017 | // Stage 3 |
| 1018 | __buf.resize(n: __a_end - __a); |
| 1019 | if (__locale::__sscanf(s: __buf.c_str(), _LIBCPP_GET_C_LOCALE, format: "%p" , &__v) != 1) |
| 1020 | __err = ios_base::failbit; |
| 1021 | // EOF checked |
| 1022 | if (__b == __e) |
| 1023 | __err |= ios_base::eofbit; |
| 1024 | return __b; |
| 1025 | } |
| 1026 | |
| 1027 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<char>; |
| 1028 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 1029 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<wchar_t>; |
| 1030 | # endif |
| 1031 | |
| 1032 | struct _LIBCPP_EXPORTED_FROM_ABI __num_put_base { |
| 1033 | protected: |
| 1034 | static void __format_int(char* __fmt, const char* __len, bool __signd, ios_base::fmtflags __flags); |
| 1035 | static bool __format_float(char* __fmt, const char* __len, ios_base::fmtflags __flags); |
| 1036 | static char* __identify_padding(char* __nb, char* __ne, const ios_base& __iob); |
| 1037 | }; |
| 1038 | |
| 1039 | template <class _CharT> |
| 1040 | struct __num_put : protected __num_put_base { |
| 1041 | static void __widen_and_group_int( |
| 1042 | char* __nb, char* __np, char* __ne, _CharT* __ob, _CharT*& __op, _CharT*& __oe, const locale& __loc); |
| 1043 | static void __widen_and_group_float( |
| 1044 | char* __nb, char* __np, char* __ne, _CharT* __ob, _CharT*& __op, _CharT*& __oe, const locale& __loc); |
| 1045 | }; |
| 1046 | |
| 1047 | template <class _CharT> |
| 1048 | void __num_put<_CharT>::__widen_and_group_int( |
| 1049 | char* __nb, char* __np, char* __ne, _CharT* __ob, _CharT*& __op, _CharT*& __oe, const locale& __loc) { |
| 1050 | const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__loc); |
| 1051 | const numpunct<_CharT>& __npt = std::use_facet<numpunct<_CharT> >(__loc); |
| 1052 | string __grouping = __npt.grouping(); |
| 1053 | if (__grouping.empty()) { |
| 1054 | __ct.widen(__nb, __ne, __ob); |
| 1055 | __oe = __ob + (__ne - __nb); |
| 1056 | } else { |
| 1057 | __oe = __ob; |
| 1058 | char* __nf = __nb; |
| 1059 | if (*__nf == '-' || *__nf == '+') |
| 1060 | *__oe++ = __ct.widen(*__nf++); |
| 1061 | if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' || __nf[1] == 'X')) { |
| 1062 | *__oe++ = __ct.widen(*__nf++); |
| 1063 | *__oe++ = __ct.widen(*__nf++); |
| 1064 | } |
| 1065 | std::reverse(first: __nf, last: __ne); |
| 1066 | _CharT __thousands_sep = __npt.thousands_sep(); |
| 1067 | unsigned __dc = 0; |
| 1068 | unsigned __dg = 0; |
| 1069 | for (char* __p = __nf; __p < __ne; ++__p) { |
| 1070 | if (static_cast<unsigned>(__grouping[__dg]) > 0 && __dc == static_cast<unsigned>(__grouping[__dg])) { |
| 1071 | *__oe++ = __thousands_sep; |
| 1072 | __dc = 0; |
| 1073 | if (__dg < __grouping.size() - 1) |
| 1074 | ++__dg; |
| 1075 | } |
| 1076 | *__oe++ = __ct.widen(*__p); |
| 1077 | ++__dc; |
| 1078 | } |
| 1079 | std::reverse(__ob + (__nf - __nb), __oe); |
| 1080 | } |
| 1081 | if (__np == __ne) |
| 1082 | __op = __oe; |
| 1083 | else |
| 1084 | __op = __ob + (__np - __nb); |
| 1085 | } |
| 1086 | |
| 1087 | template <class _CharT> |
| 1088 | void __num_put<_CharT>::__widen_and_group_float( |
| 1089 | char* __nb, char* __np, char* __ne, _CharT* __ob, _CharT*& __op, _CharT*& __oe, const locale& __loc) { |
| 1090 | const ctype<_CharT>& __ct = std::use_facet<ctype<_CharT> >(__loc); |
| 1091 | const numpunct<_CharT>& __npt = std::use_facet<numpunct<_CharT> >(__loc); |
| 1092 | string __grouping = __npt.grouping(); |
| 1093 | __oe = __ob; |
| 1094 | char* __nf = __nb; |
| 1095 | if (*__nf == '-' || *__nf == '+') |
| 1096 | *__oe++ = __ct.widen(*__nf++); |
| 1097 | char* __ns; |
| 1098 | if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' || __nf[1] == 'X')) { |
| 1099 | *__oe++ = __ct.widen(*__nf++); |
| 1100 | *__oe++ = __ct.widen(*__nf++); |
| 1101 | for (__ns = __nf; __ns < __ne; ++__ns) |
| 1102 | if (!__locale::__isxdigit(c: *__ns, _LIBCPP_GET_C_LOCALE)) |
| 1103 | break; |
| 1104 | } else { |
| 1105 | for (__ns = __nf; __ns < __ne; ++__ns) |
| 1106 | if (!__locale::__isdigit(c: *__ns, _LIBCPP_GET_C_LOCALE)) |
| 1107 | break; |
| 1108 | } |
| 1109 | if (__grouping.empty()) { |
| 1110 | __ct.widen(__nf, __ns, __oe); |
| 1111 | __oe += __ns - __nf; |
| 1112 | } else { |
| 1113 | std::reverse(first: __nf, last: __ns); |
| 1114 | _CharT __thousands_sep = __npt.thousands_sep(); |
| 1115 | unsigned __dc = 0; |
| 1116 | unsigned __dg = 0; |
| 1117 | for (char* __p = __nf; __p < __ns; ++__p) { |
| 1118 | if (__grouping[__dg] > 0 && __dc == static_cast<unsigned>(__grouping[__dg])) { |
| 1119 | *__oe++ = __thousands_sep; |
| 1120 | __dc = 0; |
| 1121 | if (__dg < __grouping.size() - 1) |
| 1122 | ++__dg; |
| 1123 | } |
| 1124 | *__oe++ = __ct.widen(*__p); |
| 1125 | ++__dc; |
| 1126 | } |
| 1127 | std::reverse(__ob + (__nf - __nb), __oe); |
| 1128 | } |
| 1129 | for (__nf = __ns; __nf < __ne; ++__nf) { |
| 1130 | if (*__nf == '.') { |
| 1131 | *__oe++ = __npt.decimal_point(); |
| 1132 | ++__nf; |
| 1133 | break; |
| 1134 | } else |
| 1135 | *__oe++ = __ct.widen(*__nf); |
| 1136 | } |
| 1137 | __ct.widen(__nf, __ne, __oe); |
| 1138 | __oe += __ne - __nf; |
| 1139 | if (__np == __ne) |
| 1140 | __op = __oe; |
| 1141 | else |
| 1142 | __op = __ob + (__np - __nb); |
| 1143 | } |
| 1144 | |
| 1145 | extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<char>; |
| 1146 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 1147 | extern template struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<wchar_t>; |
| 1148 | # endif |
| 1149 | |
| 1150 | template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> > |
| 1151 | class num_put : public locale::facet, private __num_put<_CharT> { |
| 1152 | public: |
| 1153 | typedef _CharT char_type; |
| 1154 | typedef _OutputIterator iter_type; |
| 1155 | |
| 1156 | _LIBCPP_HIDE_FROM_ABI explicit num_put(size_t __refs = 0) : locale::facet(__refs) {} |
| 1157 | |
| 1158 | _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, bool __v) const { |
| 1159 | return do_put(__s, __iob, __fl, __v); |
| 1160 | } |
| 1161 | |
| 1162 | _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, long __v) const { |
| 1163 | return do_put(__s, __iob, __fl, __v); |
| 1164 | } |
| 1165 | |
| 1166 | _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, long long __v) const { |
| 1167 | return do_put(__s, __iob, __fl, __v); |
| 1168 | } |
| 1169 | |
| 1170 | _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long __v) const { |
| 1171 | return do_put(__s, __iob, __fl, __v); |
| 1172 | } |
| 1173 | |
| 1174 | _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long long __v) const { |
| 1175 | return do_put(__s, __iob, __fl, __v); |
| 1176 | } |
| 1177 | |
| 1178 | _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, double __v) const { |
| 1179 | return do_put(__s, __iob, __fl, __v); |
| 1180 | } |
| 1181 | |
| 1182 | _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, long double __v) const { |
| 1183 | return do_put(__s, __iob, __fl, __v); |
| 1184 | } |
| 1185 | |
| 1186 | _LIBCPP_HIDE_FROM_ABI iter_type put(iter_type __s, ios_base& __iob, char_type __fl, const void* __v) const { |
| 1187 | return do_put(__s, __iob, __fl, __v); |
| 1188 | } |
| 1189 | |
| 1190 | static locale::id id; |
| 1191 | |
| 1192 | protected: |
| 1193 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~num_put() override {} |
| 1194 | |
| 1195 | virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, bool __v) const; |
| 1196 | virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, long __v) const; |
| 1197 | virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, long long __v) const; |
| 1198 | virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long) const; |
| 1199 | virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long long) const; |
| 1200 | virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, double __v) const; |
| 1201 | virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, long double __v) const; |
| 1202 | virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, const void* __v) const; |
| 1203 | |
| 1204 | template <class _Integral> |
| 1205 | _LIBCPP_HIDE_FROM_ABI inline _OutputIterator |
| 1206 | __do_put_integral(iter_type __s, ios_base& __iob, char_type __fl, _Integral __v) const; |
| 1207 | |
| 1208 | template <class _Float> |
| 1209 | _LIBCPP_HIDE_FROM_ABI inline _OutputIterator |
| 1210 | __do_put_floating_point(iter_type __s, ios_base& __iob, char_type __fl, _Float __v, char const* __len) const; |
| 1211 | }; |
| 1212 | |
| 1213 | template <class _CharT, class _OutputIterator> |
| 1214 | locale::id num_put<_CharT, _OutputIterator>::id; |
| 1215 | |
| 1216 | template <class _CharT, class _OutputIterator> |
| 1217 | _OutputIterator |
| 1218 | num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, bool __v) const { |
| 1219 | if ((__iob.flags() & ios_base::boolalpha) == 0) |
| 1220 | return do_put(__s, __iob, __fl, (unsigned long)__v); |
| 1221 | const numpunct<char_type>& __np = std::use_facet<numpunct<char_type> >(__iob.getloc()); |
| 1222 | typedef typename numpunct<char_type>::string_type string_type; |
| 1223 | string_type __nm = __v ? __np.truename() : __np.falsename(); |
| 1224 | for (typename string_type::iterator __i = __nm.begin(); __i != __nm.end(); ++__i, ++__s) |
| 1225 | *__s = *__i; |
| 1226 | return __s; |
| 1227 | } |
| 1228 | |
| 1229 | template <class _CharT, class _OutputIterator> |
| 1230 | template <class _Integral> |
| 1231 | _LIBCPP_HIDE_FROM_ABI inline _OutputIterator num_put<_CharT, _OutputIterator>::__do_put_integral( |
| 1232 | iter_type __s, ios_base& __iob, char_type __fl, _Integral __v) const { |
| 1233 | // Stage 1 - Get number in narrow char |
| 1234 | |
| 1235 | // Worst case is octal, with showbase enabled. Note that octal is always |
| 1236 | // printed as an unsigned value. |
| 1237 | using _Unsigned = typename make_unsigned<_Integral>::type; |
| 1238 | _LIBCPP_CONSTEXPR const unsigned __buffer_size = |
| 1239 | (numeric_limits<_Unsigned>::digits / 3) // 1 char per 3 bits |
| 1240 | + ((numeric_limits<_Unsigned>::digits % 3) != 0) // round up |
| 1241 | + 2; // base prefix + terminating null character |
| 1242 | |
| 1243 | char __char_buffer[__buffer_size]; |
| 1244 | char* __buffer_ptr = __char_buffer; |
| 1245 | |
| 1246 | auto __flags = __iob.flags(); |
| 1247 | |
| 1248 | auto __basefield = (__flags & ios_base::basefield); |
| 1249 | |
| 1250 | // Extract base |
| 1251 | int __base = 10; |
| 1252 | if (__basefield == ios_base::oct) |
| 1253 | __base = 8; |
| 1254 | else if (__basefield == ios_base::hex) |
| 1255 | __base = 16; |
| 1256 | |
| 1257 | // Print '-' and make the argument unsigned |
| 1258 | auto __uval = std::__to_unsigned_like(__v); |
| 1259 | if (__basefield != ios_base::oct && __basefield != ios_base::hex && __v < 0) { |
| 1260 | *__buffer_ptr++ = '-'; |
| 1261 | __uval = std::__complement(__uval); |
| 1262 | } |
| 1263 | |
| 1264 | // Maybe add '+' prefix |
| 1265 | if (std::is_signed<_Integral>::value && (__flags & ios_base::showpos) && __basefield != ios_base::oct && |
| 1266 | __basefield != ios_base::hex && __v >= 0) |
| 1267 | *__buffer_ptr++ = '+'; |
| 1268 | |
| 1269 | // Add base prefix |
| 1270 | if (__v != 0 && __flags & ios_base::showbase) { |
| 1271 | if (__basefield == ios_base::oct) { |
| 1272 | *__buffer_ptr++ = '0'; |
| 1273 | } else if (__basefield == ios_base::hex) { |
| 1274 | *__buffer_ptr++ = '0'; |
| 1275 | *__buffer_ptr++ = (__flags & ios_base::uppercase ? 'X' : 'x'); |
| 1276 | } |
| 1277 | } |
| 1278 | |
| 1279 | auto __res = std::__to_chars_integral(__buffer_ptr, __char_buffer + __buffer_size, __uval, __base); |
| 1280 | _LIBCPP_ASSERT_INTERNAL(__res.__ec == std::errc(0), "to_chars: invalid maximum buffer size computed?" ); |
| 1281 | |
| 1282 | // Make letters uppercase |
| 1283 | if (__flags & ios_base::hex && __flags & ios_base::uppercase) { |
| 1284 | for (; __buffer_ptr != __res.__ptr; ++__buffer_ptr) |
| 1285 | *__buffer_ptr = std::__hex_to_upper(c: *__buffer_ptr); |
| 1286 | } |
| 1287 | |
| 1288 | char* __np = this->__identify_padding(__char_buffer, __res.__ptr, __iob); |
| 1289 | // Stage 2 - Widen __nar while adding thousands separators |
| 1290 | char_type __o[2 * (__buffer_size - 1) - 1]; |
| 1291 | char_type* __op; // pad here |
| 1292 | char_type* __oe; // end of output |
| 1293 | this->__widen_and_group_int(__char_buffer, __np, __res.__ptr, __o, __op, __oe, __iob.getloc()); |
| 1294 | // [__o, __oe) contains thousands_sep'd wide number |
| 1295 | // Stage 3 & 4 |
| 1296 | return std::__pad_and_output(__s, __o, __op, __oe, __iob, __fl); |
| 1297 | } |
| 1298 | |
| 1299 | template <class _CharT, class _OutputIterator> |
| 1300 | _OutputIterator |
| 1301 | num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, long __v) const { |
| 1302 | return this->__do_put_integral(__s, __iob, __fl, __v); |
| 1303 | } |
| 1304 | |
| 1305 | template <class _CharT, class _OutputIterator> |
| 1306 | _OutputIterator |
| 1307 | num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, long long __v) const { |
| 1308 | return this->__do_put_integral(__s, __iob, __fl, __v); |
| 1309 | } |
| 1310 | |
| 1311 | template <class _CharT, class _OutputIterator> |
| 1312 | _OutputIterator |
| 1313 | num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long __v) const { |
| 1314 | return this->__do_put_integral(__s, __iob, __fl, __v); |
| 1315 | } |
| 1316 | |
| 1317 | template <class _CharT, class _OutputIterator> |
| 1318 | _OutputIterator |
| 1319 | num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, unsigned long long __v) const { |
| 1320 | return this->__do_put_integral(__s, __iob, __fl, __v); |
| 1321 | } |
| 1322 | |
| 1323 | template <class _CharT, class _OutputIterator> |
| 1324 | template <class _Float> |
| 1325 | _LIBCPP_HIDE_FROM_ABI inline _OutputIterator num_put<_CharT, _OutputIterator>::__do_put_floating_point( |
| 1326 | iter_type __s, ios_base& __iob, char_type __fl, _Float __v, char const* __len) const { |
| 1327 | // Stage 1 - Get number in narrow char |
| 1328 | char __fmt[8] = {'%', 0}; |
| 1329 | bool __specify_precision = this->__format_float(__fmt + 1, __len, __iob.flags()); |
| 1330 | const unsigned __nbuf = 30; |
| 1331 | char __nar[__nbuf]; |
| 1332 | char* __nb = __nar; |
| 1333 | int __nc; |
| 1334 | _LIBCPP_DIAGNOSTIC_PUSH |
| 1335 | _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wformat-nonliteral" ) |
| 1336 | _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral" ) |
| 1337 | if (__specify_precision) |
| 1338 | __nc = __locale::__snprintf(s: __nb, n: __nbuf, _LIBCPP_GET_C_LOCALE, format: __fmt, (int)__iob.precision(), __v); |
| 1339 | else |
| 1340 | __nc = __locale::__snprintf(s: __nb, n: __nbuf, _LIBCPP_GET_C_LOCALE, format: __fmt, __v); |
| 1341 | unique_ptr<char, void (*)(void*)> __nbh(nullptr, free); |
| 1342 | if (__nc > static_cast<int>(__nbuf - 1)) { |
| 1343 | if (__specify_precision) |
| 1344 | __nc = __locale::__asprintf(s: &__nb, _LIBCPP_GET_C_LOCALE, format: __fmt, (int)__iob.precision(), __v); |
| 1345 | else |
| 1346 | __nc = __locale::__asprintf(s: &__nb, _LIBCPP_GET_C_LOCALE, format: __fmt, __v); |
| 1347 | if (__nc == -1) |
| 1348 | std::__throw_bad_alloc(); |
| 1349 | __nbh.reset(p: __nb); |
| 1350 | } |
| 1351 | _LIBCPP_DIAGNOSTIC_POP |
| 1352 | char* __ne = __nb + __nc; |
| 1353 | char* __np = this->__identify_padding(__nb, __ne, __iob); |
| 1354 | // Stage 2 - Widen __nar while adding thousands separators |
| 1355 | char_type __o[2 * (__nbuf - 1) - 1]; |
| 1356 | char_type* __ob = __o; |
| 1357 | unique_ptr<char_type, void (*)(void*)> __obh(0, free); |
| 1358 | if (__nb != __nar) { |
| 1359 | __ob = (char_type*)malloc(size: 2 * static_cast<size_t>(__nc) * sizeof(char_type)); |
| 1360 | if (__ob == 0) |
| 1361 | std::__throw_bad_alloc(); |
| 1362 | __obh.reset(__ob); |
| 1363 | } |
| 1364 | char_type* __op; // pad here |
| 1365 | char_type* __oe; // end of output |
| 1366 | this->__widen_and_group_float(__nb, __np, __ne, __ob, __op, __oe, __iob.getloc()); |
| 1367 | // [__o, __oe) contains thousands_sep'd wide number |
| 1368 | // Stage 3 & 4 |
| 1369 | __s = std::__pad_and_output(__s, __ob, __op, __oe, __iob, __fl); |
| 1370 | return __s; |
| 1371 | } |
| 1372 | |
| 1373 | template <class _CharT, class _OutputIterator> |
| 1374 | _OutputIterator |
| 1375 | num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, double __v) const { |
| 1376 | return this->__do_put_floating_point(__s, __iob, __fl, __v, "" ); |
| 1377 | } |
| 1378 | |
| 1379 | template <class _CharT, class _OutputIterator> |
| 1380 | _OutputIterator |
| 1381 | num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, long double __v) const { |
| 1382 | return this->__do_put_floating_point(__s, __iob, __fl, __v, "L" ); |
| 1383 | } |
| 1384 | |
| 1385 | template <class _CharT, class _OutputIterator> |
| 1386 | _OutputIterator |
| 1387 | num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, char_type __fl, const void* __v) const { |
| 1388 | auto __flags = __iob.flags(); |
| 1389 | __iob.flags(fmtfl: (__flags & ~ios_base::basefield & ~ios_base::uppercase) | ios_base::hex | ios_base::showbase); |
| 1390 | auto __res = __do_put_integral(__s, __iob, __fl, reinterpret_cast<uintptr_t>(__v)); |
| 1391 | __iob.flags(fmtfl: __flags); |
| 1392 | return __res; |
| 1393 | } |
| 1394 | |
| 1395 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<char>; |
| 1396 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 1397 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<wchar_t>; |
| 1398 | # endif |
| 1399 | |
| 1400 | template <class _CharT, class _InputIterator> |
| 1401 | _LIBCPP_HIDE_FROM_ABI int __get_up_to_n_digits( |
| 1402 | _InputIterator& __b, _InputIterator __e, ios_base::iostate& __err, const ctype<_CharT>& __ct, int __n) { |
| 1403 | // Precondition: __n >= 1 |
| 1404 | if (__b == __e) { |
| 1405 | __err |= ios_base::eofbit | ios_base::failbit; |
| 1406 | return 0; |
| 1407 | } |
| 1408 | // get first digit |
| 1409 | _CharT __c = *__b; |
| 1410 | if (!__ct.is(ctype_base::digit, __c)) { |
| 1411 | __err |= ios_base::failbit; |
| 1412 | return 0; |
| 1413 | } |
| 1414 | int __r = __ct.narrow(__c, 0) - '0'; |
| 1415 | for (++__b, (void)--__n; __b != __e && __n > 0; ++__b, (void)--__n) { |
| 1416 | // get next digit |
| 1417 | __c = *__b; |
| 1418 | if (!__ct.is(ctype_base::digit, __c)) |
| 1419 | return __r; |
| 1420 | __r = __r * 10 + __ct.narrow(__c, 0) - '0'; |
| 1421 | } |
| 1422 | if (__b == __e) |
| 1423 | __err |= ios_base::eofbit; |
| 1424 | return __r; |
| 1425 | } |
| 1426 | |
| 1427 | class _LIBCPP_EXPORTED_FROM_ABI time_base { |
| 1428 | public: |
| 1429 | enum dateorder { no_order, dmy, mdy, ymd, ydm }; |
| 1430 | }; |
| 1431 | |
| 1432 | template <class _CharT> |
| 1433 | class __time_get_c_storage { |
| 1434 | protected: |
| 1435 | typedef basic_string<_CharT> string_type; |
| 1436 | |
| 1437 | virtual const string_type* __weeks() const; |
| 1438 | virtual const string_type* __months() const; |
| 1439 | virtual const string_type* __am_pm() const; |
| 1440 | virtual const string_type& __c() const; |
| 1441 | virtual const string_type& __r() const; |
| 1442 | virtual const string_type& __x() const; |
| 1443 | virtual const string_type& __X() const; |
| 1444 | |
| 1445 | _LIBCPP_HIDE_FROM_ABI ~__time_get_c_storage() {} |
| 1446 | }; |
| 1447 | |
| 1448 | template <> |
| 1449 | _LIBCPP_EXPORTED_FROM_ABI const string* __time_get_c_storage<char>::__weeks() const; |
| 1450 | template <> |
| 1451 | _LIBCPP_EXPORTED_FROM_ABI const string* __time_get_c_storage<char>::__months() const; |
| 1452 | template <> |
| 1453 | _LIBCPP_EXPORTED_FROM_ABI const string* __time_get_c_storage<char>::__am_pm() const; |
| 1454 | template <> |
| 1455 | _LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__c() const; |
| 1456 | template <> |
| 1457 | _LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__r() const; |
| 1458 | template <> |
| 1459 | _LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__x() const; |
| 1460 | template <> |
| 1461 | _LIBCPP_EXPORTED_FROM_ABI const string& __time_get_c_storage<char>::__X() const; |
| 1462 | |
| 1463 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 1464 | template <> |
| 1465 | _LIBCPP_EXPORTED_FROM_ABI const wstring* __time_get_c_storage<wchar_t>::__weeks() const; |
| 1466 | template <> |
| 1467 | _LIBCPP_EXPORTED_FROM_ABI const wstring* __time_get_c_storage<wchar_t>::__months() const; |
| 1468 | template <> |
| 1469 | _LIBCPP_EXPORTED_FROM_ABI const wstring* __time_get_c_storage<wchar_t>::__am_pm() const; |
| 1470 | template <> |
| 1471 | _LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__c() const; |
| 1472 | template <> |
| 1473 | _LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__r() const; |
| 1474 | template <> |
| 1475 | _LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__x() const; |
| 1476 | template <> |
| 1477 | _LIBCPP_EXPORTED_FROM_ABI const wstring& __time_get_c_storage<wchar_t>::__X() const; |
| 1478 | # endif |
| 1479 | |
| 1480 | template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> > |
| 1481 | class time_get : public locale::facet, public time_base, private __time_get_c_storage<_CharT> { |
| 1482 | public: |
| 1483 | typedef _CharT char_type; |
| 1484 | typedef _InputIterator iter_type; |
| 1485 | typedef time_base::dateorder dateorder; |
| 1486 | typedef basic_string<char_type> string_type; |
| 1487 | |
| 1488 | _LIBCPP_HIDE_FROM_ABI explicit time_get(size_t __refs = 0) : locale::facet(__refs) {} |
| 1489 | |
| 1490 | _LIBCPP_HIDE_FROM_ABI dateorder date_order() const { return this->do_date_order(); } |
| 1491 | |
| 1492 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 1493 | get_time(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const { |
| 1494 | return do_get_time(__b, __e, __iob, __err, __tm); |
| 1495 | } |
| 1496 | |
| 1497 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 1498 | get_date(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const { |
| 1499 | return do_get_date(__b, __e, __iob, __err, __tm); |
| 1500 | } |
| 1501 | |
| 1502 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 1503 | get_weekday(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const { |
| 1504 | return do_get_weekday(__b, __e, __iob, __err, __tm); |
| 1505 | } |
| 1506 | |
| 1507 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 1508 | get_monthname(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const { |
| 1509 | return do_get_monthname(__b, __e, __iob, __err, __tm); |
| 1510 | } |
| 1511 | |
| 1512 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 1513 | get_year(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const { |
| 1514 | return do_get_year(__b, __e, __iob, __err, __tm); |
| 1515 | } |
| 1516 | |
| 1517 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 1518 | get(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm, char __fmt, char __mod = 0) |
| 1519 | const { |
| 1520 | return do_get(__b, __e, __iob, __err, __tm, __fmt, __mod); |
| 1521 | } |
| 1522 | |
| 1523 | iter_type |
| 1524 | get(iter_type __b, |
| 1525 | iter_type __e, |
| 1526 | ios_base& __iob, |
| 1527 | ios_base::iostate& __err, |
| 1528 | tm* __tm, |
| 1529 | const char_type* __fmtb, |
| 1530 | const char_type* __fmte) const; |
| 1531 | |
| 1532 | static locale::id id; |
| 1533 | |
| 1534 | protected: |
| 1535 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~time_get() override {} |
| 1536 | |
| 1537 | virtual dateorder do_date_order() const; |
| 1538 | virtual iter_type |
| 1539 | do_get_time(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const; |
| 1540 | virtual iter_type |
| 1541 | do_get_date(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const; |
| 1542 | virtual iter_type |
| 1543 | do_get_weekday(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const; |
| 1544 | virtual iter_type |
| 1545 | do_get_monthname(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const; |
| 1546 | virtual iter_type |
| 1547 | do_get_year(iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const; |
| 1548 | virtual iter_type do_get( |
| 1549 | iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm, char __fmt, char __mod) const; |
| 1550 | |
| 1551 | private: |
| 1552 | void __get_white_space(iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const; |
| 1553 | void __get_percent(iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const; |
| 1554 | |
| 1555 | void __get_weekdayname( |
| 1556 | int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const; |
| 1557 | void __get_monthname( |
| 1558 | int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const; |
| 1559 | void __get_day(int& __d, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const; |
| 1560 | void |
| 1561 | __get_month(int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const; |
| 1562 | void |
| 1563 | __get_year(int& __y, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const; |
| 1564 | void |
| 1565 | __get_year4(int& __y, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const; |
| 1566 | void |
| 1567 | __get_hour(int& __d, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const; |
| 1568 | void |
| 1569 | __get_12_hour(int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const; |
| 1570 | void |
| 1571 | __get_am_pm(int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const; |
| 1572 | void |
| 1573 | __get_minute(int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const; |
| 1574 | void |
| 1575 | __get_second(int& __s, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const; |
| 1576 | void |
| 1577 | __get_weekday(int& __w, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const; |
| 1578 | void __get_day_year_num( |
| 1579 | int& __w, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const; |
| 1580 | }; |
| 1581 | |
| 1582 | template <class _CharT, class _InputIterator> |
| 1583 | locale::id time_get<_CharT, _InputIterator>::id; |
| 1584 | |
| 1585 | // time_get primitives |
| 1586 | |
| 1587 | template <class _CharT, class _InputIterator> |
| 1588 | void time_get<_CharT, _InputIterator>::__get_weekdayname( |
| 1589 | int& __w, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const { |
| 1590 | // Note: ignoring case comes from the POSIX strptime spec |
| 1591 | const string_type* __wk = this->__weeks(); |
| 1592 | ptrdiff_t __i = std::__scan_keyword(__b, __e, __wk, __wk + 14, __ct, __err, false) - __wk; |
| 1593 | if (__i < 14) |
| 1594 | __w = __i % 7; |
| 1595 | } |
| 1596 | |
| 1597 | template <class _CharT, class _InputIterator> |
| 1598 | void time_get<_CharT, _InputIterator>::__get_monthname( |
| 1599 | int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const { |
| 1600 | // Note: ignoring case comes from the POSIX strptime spec |
| 1601 | const string_type* __month = this->__months(); |
| 1602 | ptrdiff_t __i = std::__scan_keyword(__b, __e, __month, __month + 24, __ct, __err, false) - __month; |
| 1603 | if (__i < 24) |
| 1604 | __m = __i % 12; |
| 1605 | } |
| 1606 | |
| 1607 | template <class _CharT, class _InputIterator> |
| 1608 | void time_get<_CharT, _InputIterator>::__get_day( |
| 1609 | int& __d, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const { |
| 1610 | int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2); |
| 1611 | if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 31) |
| 1612 | __d = __t; |
| 1613 | else |
| 1614 | __err |= ios_base::failbit; |
| 1615 | } |
| 1616 | |
| 1617 | template <class _CharT, class _InputIterator> |
| 1618 | void time_get<_CharT, _InputIterator>::__get_month( |
| 1619 | int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const { |
| 1620 | int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2) - 1; |
| 1621 | if (!(__err & ios_base::failbit) && 0 <= __t && __t <= 11) |
| 1622 | __m = __t; |
| 1623 | else |
| 1624 | __err |= ios_base::failbit; |
| 1625 | } |
| 1626 | |
| 1627 | template <class _CharT, class _InputIterator> |
| 1628 | void time_get<_CharT, _InputIterator>::__get_year( |
| 1629 | int& __y, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const { |
| 1630 | int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 4); |
| 1631 | if (!(__err & ios_base::failbit)) { |
| 1632 | if (__t < 69) |
| 1633 | __t += 2000; |
| 1634 | else if (69 <= __t && __t <= 99) |
| 1635 | __t += 1900; |
| 1636 | __y = __t - 1900; |
| 1637 | } |
| 1638 | } |
| 1639 | |
| 1640 | template <class _CharT, class _InputIterator> |
| 1641 | void time_get<_CharT, _InputIterator>::__get_year4( |
| 1642 | int& __y, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const { |
| 1643 | int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 4); |
| 1644 | if (!(__err & ios_base::failbit)) |
| 1645 | __y = __t - 1900; |
| 1646 | } |
| 1647 | |
| 1648 | template <class _CharT, class _InputIterator> |
| 1649 | void time_get<_CharT, _InputIterator>::__get_hour( |
| 1650 | int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const { |
| 1651 | int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2); |
| 1652 | if (!(__err & ios_base::failbit) && __t <= 23) |
| 1653 | __h = __t; |
| 1654 | else |
| 1655 | __err |= ios_base::failbit; |
| 1656 | } |
| 1657 | |
| 1658 | template <class _CharT, class _InputIterator> |
| 1659 | void time_get<_CharT, _InputIterator>::__get_12_hour( |
| 1660 | int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const { |
| 1661 | int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2); |
| 1662 | if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 12) |
| 1663 | __h = __t; |
| 1664 | else |
| 1665 | __err |= ios_base::failbit; |
| 1666 | } |
| 1667 | |
| 1668 | template <class _CharT, class _InputIterator> |
| 1669 | void time_get<_CharT, _InputIterator>::__get_minute( |
| 1670 | int& __m, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const { |
| 1671 | int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2); |
| 1672 | if (!(__err & ios_base::failbit) && __t <= 59) |
| 1673 | __m = __t; |
| 1674 | else |
| 1675 | __err |= ios_base::failbit; |
| 1676 | } |
| 1677 | |
| 1678 | template <class _CharT, class _InputIterator> |
| 1679 | void time_get<_CharT, _InputIterator>::__get_second( |
| 1680 | int& __s, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const { |
| 1681 | int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 2); |
| 1682 | if (!(__err & ios_base::failbit) && __t <= 60) |
| 1683 | __s = __t; |
| 1684 | else |
| 1685 | __err |= ios_base::failbit; |
| 1686 | } |
| 1687 | |
| 1688 | template <class _CharT, class _InputIterator> |
| 1689 | void time_get<_CharT, _InputIterator>::__get_weekday( |
| 1690 | int& __w, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const { |
| 1691 | int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 1); |
| 1692 | if (!(__err & ios_base::failbit) && __t <= 6) |
| 1693 | __w = __t; |
| 1694 | else |
| 1695 | __err |= ios_base::failbit; |
| 1696 | } |
| 1697 | |
| 1698 | template <class _CharT, class _InputIterator> |
| 1699 | void time_get<_CharT, _InputIterator>::__get_day_year_num( |
| 1700 | int& __d, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const { |
| 1701 | int __t = std::__get_up_to_n_digits(__b, __e, __err, __ct, 3); |
| 1702 | if (!(__err & ios_base::failbit) && __t <= 365) |
| 1703 | __d = __t; |
| 1704 | else |
| 1705 | __err |= ios_base::failbit; |
| 1706 | } |
| 1707 | |
| 1708 | template <class _CharT, class _InputIterator> |
| 1709 | void time_get<_CharT, _InputIterator>::__get_white_space( |
| 1710 | iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const { |
| 1711 | for (; __b != __e && __ct.is(ctype_base::space, *__b); ++__b) |
| 1712 | ; |
| 1713 | if (__b == __e) |
| 1714 | __err |= ios_base::eofbit; |
| 1715 | } |
| 1716 | |
| 1717 | template <class _CharT, class _InputIterator> |
| 1718 | void time_get<_CharT, _InputIterator>::__get_am_pm( |
| 1719 | int& __h, iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const { |
| 1720 | const string_type* __ap = this->__am_pm(); |
| 1721 | if (__ap[0].size() + __ap[1].size() == 0) { |
| 1722 | __err |= ios_base::failbit; |
| 1723 | return; |
| 1724 | } |
| 1725 | ptrdiff_t __i = std::__scan_keyword(__b, __e, __ap, __ap + 2, __ct, __err, false) - __ap; |
| 1726 | if (__i == 0 && __h == 12) |
| 1727 | __h = 0; |
| 1728 | else if (__i == 1 && __h < 12) |
| 1729 | __h += 12; |
| 1730 | } |
| 1731 | |
| 1732 | template <class _CharT, class _InputIterator> |
| 1733 | void time_get<_CharT, _InputIterator>::__get_percent( |
| 1734 | iter_type& __b, iter_type __e, ios_base::iostate& __err, const ctype<char_type>& __ct) const { |
| 1735 | if (__b == __e) { |
| 1736 | __err |= ios_base::eofbit | ios_base::failbit; |
| 1737 | return; |
| 1738 | } |
| 1739 | if (__ct.narrow(*__b, 0) != '%') |
| 1740 | __err |= ios_base::failbit; |
| 1741 | else if (++__b == __e) |
| 1742 | __err |= ios_base::eofbit; |
| 1743 | } |
| 1744 | |
| 1745 | // time_get end primitives |
| 1746 | |
| 1747 | template <class _CharT, class _InputIterator> |
| 1748 | _InputIterator time_get<_CharT, _InputIterator>::get( |
| 1749 | iter_type __b, |
| 1750 | iter_type __e, |
| 1751 | ios_base& __iob, |
| 1752 | ios_base::iostate& __err, |
| 1753 | tm* __tm, |
| 1754 | const char_type* __fmtb, |
| 1755 | const char_type* __fmte) const { |
| 1756 | const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc()); |
| 1757 | __err = ios_base::goodbit; |
| 1758 | while (__fmtb != __fmte && __err == ios_base::goodbit) { |
| 1759 | if (__b == __e) { |
| 1760 | __err = ios_base::failbit; |
| 1761 | break; |
| 1762 | } |
| 1763 | if (__ct.narrow(*__fmtb, 0) == '%') { |
| 1764 | if (++__fmtb == __fmte) { |
| 1765 | __err = ios_base::failbit; |
| 1766 | break; |
| 1767 | } |
| 1768 | char __cmd = __ct.narrow(*__fmtb, 0); |
| 1769 | char __opt = '\0'; |
| 1770 | if (__cmd == 'E' || __cmd == '0') { |
| 1771 | if (++__fmtb == __fmte) { |
| 1772 | __err = ios_base::failbit; |
| 1773 | break; |
| 1774 | } |
| 1775 | __opt = __cmd; |
| 1776 | __cmd = __ct.narrow(*__fmtb, 0); |
| 1777 | } |
| 1778 | __b = do_get(__b, __e, __iob, __err, __tm, fmt: __cmd, mod: __opt); |
| 1779 | ++__fmtb; |
| 1780 | } else if (__ct.is(ctype_base::space, *__fmtb)) { |
| 1781 | for (++__fmtb; __fmtb != __fmte && __ct.is(ctype_base::space, *__fmtb); ++__fmtb) |
| 1782 | ; |
| 1783 | for (; __b != __e && __ct.is(ctype_base::space, *__b); ++__b) |
| 1784 | ; |
| 1785 | } else if (__ct.toupper(*__b) == __ct.toupper(*__fmtb)) { |
| 1786 | ++__b; |
| 1787 | ++__fmtb; |
| 1788 | } else |
| 1789 | __err = ios_base::failbit; |
| 1790 | } |
| 1791 | if (__b == __e) |
| 1792 | __err |= ios_base::eofbit; |
| 1793 | return __b; |
| 1794 | } |
| 1795 | |
| 1796 | template <class _CharT, class _InputIterator> |
| 1797 | typename time_get<_CharT, _InputIterator>::dateorder time_get<_CharT, _InputIterator>::do_date_order() const { |
| 1798 | return mdy; |
| 1799 | } |
| 1800 | |
| 1801 | template <class _CharT, class _InputIterator> |
| 1802 | _InputIterator time_get<_CharT, _InputIterator>::do_get_time( |
| 1803 | iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const { |
| 1804 | const char_type __fmt[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'}; |
| 1805 | return get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt) / sizeof(__fmt[0])); |
| 1806 | } |
| 1807 | |
| 1808 | template <class _CharT, class _InputIterator> |
| 1809 | _InputIterator time_get<_CharT, _InputIterator>::do_get_date( |
| 1810 | iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const { |
| 1811 | const string_type& __fmt = this->__x(); |
| 1812 | return get(__b, __e, __iob, __err, __tm, __fmt.data(), __fmt.data() + __fmt.size()); |
| 1813 | } |
| 1814 | |
| 1815 | template <class _CharT, class _InputIterator> |
| 1816 | _InputIterator time_get<_CharT, _InputIterator>::do_get_weekday( |
| 1817 | iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const { |
| 1818 | const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc()); |
| 1819 | __get_weekdayname(w&: __tm->tm_wday, __b, __e, __err, __ct); |
| 1820 | return __b; |
| 1821 | } |
| 1822 | |
| 1823 | template <class _CharT, class _InputIterator> |
| 1824 | _InputIterator time_get<_CharT, _InputIterator>::do_get_monthname( |
| 1825 | iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const { |
| 1826 | const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc()); |
| 1827 | __get_monthname(m&: __tm->tm_mon, __b, __e, __err, __ct); |
| 1828 | return __b; |
| 1829 | } |
| 1830 | |
| 1831 | template <class _CharT, class _InputIterator> |
| 1832 | _InputIterator time_get<_CharT, _InputIterator>::do_get_year( |
| 1833 | iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm) const { |
| 1834 | const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc()); |
| 1835 | __get_year(y&: __tm->tm_year, __b, __e, __err, __ct); |
| 1836 | return __b; |
| 1837 | } |
| 1838 | |
| 1839 | template <class _CharT, class _InputIterator> |
| 1840 | _InputIterator time_get<_CharT, _InputIterator>::do_get( |
| 1841 | iter_type __b, iter_type __e, ios_base& __iob, ios_base::iostate& __err, tm* __tm, char __fmt, char) const { |
| 1842 | __err = ios_base::goodbit; |
| 1843 | const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc()); |
| 1844 | switch (__fmt) { |
| 1845 | case 'a': |
| 1846 | case 'A': |
| 1847 | __get_weekdayname(w&: __tm->tm_wday, __b, __e, __err, __ct); |
| 1848 | break; |
| 1849 | case 'b': |
| 1850 | case 'B': |
| 1851 | case 'h': |
| 1852 | __get_monthname(m&: __tm->tm_mon, __b, __e, __err, __ct); |
| 1853 | break; |
| 1854 | case 'c': { |
| 1855 | const string_type& __fm = this->__c(); |
| 1856 | __b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size()); |
| 1857 | } break; |
| 1858 | case 'd': |
| 1859 | case 'e': |
| 1860 | __get_day(d&: __tm->tm_mday, __b, __e, __err, __ct); |
| 1861 | break; |
| 1862 | case 'D': { |
| 1863 | const char_type __fm[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'}; |
| 1864 | __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0])); |
| 1865 | } break; |
| 1866 | case 'F': { |
| 1867 | const char_type __fm[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd'}; |
| 1868 | __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0])); |
| 1869 | } break; |
| 1870 | case 'H': |
| 1871 | __get_hour(h&: __tm->tm_hour, __b, __e, __err, __ct); |
| 1872 | break; |
| 1873 | case 'I': |
| 1874 | __get_12_hour(h&: __tm->tm_hour, __b, __e, __err, __ct); |
| 1875 | break; |
| 1876 | case 'j': |
| 1877 | __get_day_year_num(d&: __tm->tm_yday, __b, __e, __err, __ct); |
| 1878 | break; |
| 1879 | case 'm': |
| 1880 | __get_month(m&: __tm->tm_mon, __b, __e, __err, __ct); |
| 1881 | break; |
| 1882 | case 'M': |
| 1883 | __get_minute(m&: __tm->tm_min, __b, __e, __err, __ct); |
| 1884 | break; |
| 1885 | case 'n': |
| 1886 | case 't': |
| 1887 | __get_white_space(__b, __e, __err, __ct); |
| 1888 | break; |
| 1889 | case 'p': |
| 1890 | __get_am_pm(h&: __tm->tm_hour, __b, __e, __err, __ct); |
| 1891 | break; |
| 1892 | case 'r': { |
| 1893 | const char_type __fm[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'}; |
| 1894 | __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0])); |
| 1895 | } break; |
| 1896 | case 'R': { |
| 1897 | const char_type __fm[] = {'%', 'H', ':', '%', 'M'}; |
| 1898 | __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0])); |
| 1899 | } break; |
| 1900 | case 'S': |
| 1901 | __get_second(s&: __tm->tm_sec, __b, __e, __err, __ct); |
| 1902 | break; |
| 1903 | case 'T': { |
| 1904 | const char_type __fm[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'}; |
| 1905 | __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm) / sizeof(__fm[0])); |
| 1906 | } break; |
| 1907 | case 'w': |
| 1908 | __get_weekday(w&: __tm->tm_wday, __b, __e, __err, __ct); |
| 1909 | break; |
| 1910 | case 'x': |
| 1911 | return do_get_date(__b, __e, __iob, __err, __tm); |
| 1912 | case 'X': { |
| 1913 | const string_type& __fm = this->__X(); |
| 1914 | __b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size()); |
| 1915 | } break; |
| 1916 | case 'y': |
| 1917 | __get_year(y&: __tm->tm_year, __b, __e, __err, __ct); |
| 1918 | break; |
| 1919 | case 'Y': |
| 1920 | __get_year4(y&: __tm->tm_year, __b, __e, __err, __ct); |
| 1921 | break; |
| 1922 | case '%': |
| 1923 | __get_percent(__b, __e, __err, __ct); |
| 1924 | break; |
| 1925 | default: |
| 1926 | __err |= ios_base::failbit; |
| 1927 | } |
| 1928 | return __b; |
| 1929 | } |
| 1930 | |
| 1931 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<char>; |
| 1932 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 1933 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<wchar_t>; |
| 1934 | # endif |
| 1935 | |
| 1936 | class _LIBCPP_EXPORTED_FROM_ABI __time_get { |
| 1937 | protected: |
| 1938 | __locale::__locale_t __loc_; |
| 1939 | |
| 1940 | __time_get(const char* __nm); |
| 1941 | __time_get(const string& __nm); |
| 1942 | ~__time_get(); |
| 1943 | }; |
| 1944 | |
| 1945 | template <class _CharT> |
| 1946 | class __time_get_storage : public __time_get { |
| 1947 | protected: |
| 1948 | typedef basic_string<_CharT> string_type; |
| 1949 | |
| 1950 | string_type __weeks_[14]; |
| 1951 | string_type __months_[24]; |
| 1952 | string_type __am_pm_[2]; |
| 1953 | string_type __c_; |
| 1954 | string_type __r_; |
| 1955 | string_type __x_; |
| 1956 | string_type __X_; |
| 1957 | |
| 1958 | explicit __time_get_storage(const char* __nm); |
| 1959 | explicit __time_get_storage(const string& __nm); |
| 1960 | |
| 1961 | _LIBCPP_HIDE_FROM_ABI ~__time_get_storage() {} |
| 1962 | |
| 1963 | time_base::dateorder __do_date_order() const; |
| 1964 | |
| 1965 | private: |
| 1966 | void init(const ctype<_CharT>&); |
| 1967 | string_type __analyze(char __fmt, const ctype<_CharT>&); |
| 1968 | }; |
| 1969 | |
| 1970 | # define _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(_CharT) \ |
| 1971 | template <> \ |
| 1972 | _LIBCPP_EXPORTED_FROM_ABI time_base::dateorder __time_get_storage<_CharT>::__do_date_order() const; \ |
| 1973 | template <> \ |
| 1974 | _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const char*); \ |
| 1975 | template <> \ |
| 1976 | _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const string&); \ |
| 1977 | template <> \ |
| 1978 | _LIBCPP_EXPORTED_FROM_ABI void __time_get_storage<_CharT>::init(const ctype<_CharT>&); \ |
| 1979 | template <> \ |
| 1980 | _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::string_type __time_get_storage<_CharT>::__analyze( \ |
| 1981 | char, const ctype<_CharT>&); \ |
| 1982 | extern template _LIBCPP_EXPORTED_FROM_ABI time_base::dateorder __time_get_storage<_CharT>::__do_date_order() \ |
| 1983 | const; \ |
| 1984 | extern template _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const char*); \ |
| 1985 | extern template _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::__time_get_storage(const string&); \ |
| 1986 | extern template _LIBCPP_EXPORTED_FROM_ABI void __time_get_storage<_CharT>::init(const ctype<_CharT>&); \ |
| 1987 | extern template _LIBCPP_EXPORTED_FROM_ABI __time_get_storage<_CharT>::string_type \ |
| 1988 | __time_get_storage<_CharT>::__analyze(char, const ctype<_CharT>&); \ |
| 1989 | /**/ |
| 1990 | |
| 1991 | _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(char) |
| 1992 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 1993 | _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(wchar_t) |
| 1994 | # endif |
| 1995 | # undef _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION |
| 1996 | |
| 1997 | template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> > |
| 1998 | class time_get_byname : public time_get<_CharT, _InputIterator>, private __time_get_storage<_CharT> { |
| 1999 | public: |
| 2000 | typedef time_base::dateorder dateorder; |
| 2001 | typedef _InputIterator iter_type; |
| 2002 | typedef _CharT char_type; |
| 2003 | typedef basic_string<char_type> string_type; |
| 2004 | |
| 2005 | _LIBCPP_HIDE_FROM_ABI explicit time_get_byname(const char* __nm, size_t __refs = 0) |
| 2006 | : time_get<_CharT, _InputIterator>(__refs), __time_get_storage<_CharT>(__nm) {} |
| 2007 | _LIBCPP_HIDE_FROM_ABI explicit time_get_byname(const string& __nm, size_t __refs = 0) |
| 2008 | : time_get<_CharT, _InputIterator>(__refs), __time_get_storage<_CharT>(__nm) {} |
| 2009 | |
| 2010 | protected: |
| 2011 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~time_get_byname() override {} |
| 2012 | |
| 2013 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL dateorder do_date_order() const override { return this->__do_date_order(); } |
| 2014 | |
| 2015 | private: |
| 2016 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type* __weeks() const override { return this->__weeks_; } |
| 2017 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type* __months() const override { return this->__months_; } |
| 2018 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type* __am_pm() const override { return this->__am_pm_; } |
| 2019 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type& __c() const override { return this->__c_; } |
| 2020 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type& __r() const override { return this->__r_; } |
| 2021 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type& __x() const override { return this->__x_; } |
| 2022 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL const string_type& __X() const override { return this->__X_; } |
| 2023 | }; |
| 2024 | |
| 2025 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<char>; |
| 2026 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 2027 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<wchar_t>; |
| 2028 | # endif |
| 2029 | |
| 2030 | class _LIBCPP_EXPORTED_FROM_ABI __time_put { |
| 2031 | __locale::__locale_t __loc_; |
| 2032 | |
| 2033 | protected: |
| 2034 | _LIBCPP_HIDE_FROM_ABI __time_put() : __loc_(_LIBCPP_GET_C_LOCALE) {} |
| 2035 | __time_put(const char* __nm); |
| 2036 | __time_put(const string& __nm); |
| 2037 | ~__time_put(); |
| 2038 | void __do_put(char* __nb, char*& __ne, const tm* __tm, char __fmt, char __mod) const; |
| 2039 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 2040 | void __do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm, char __fmt, char __mod) const; |
| 2041 | # endif |
| 2042 | }; |
| 2043 | |
| 2044 | template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> > |
| 2045 | class time_put : public locale::facet, private __time_put { |
| 2046 | public: |
| 2047 | typedef _CharT char_type; |
| 2048 | typedef _OutputIterator iter_type; |
| 2049 | |
| 2050 | _LIBCPP_HIDE_FROM_ABI explicit time_put(size_t __refs = 0) : locale::facet(__refs) {} |
| 2051 | |
| 2052 | iter_type |
| 2053 | put(iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm, const char_type* __pb, const char_type* __pe) |
| 2054 | const; |
| 2055 | |
| 2056 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 2057 | put(iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm, char __fmt, char __mod = 0) const { |
| 2058 | return do_put(__s, __iob, __fl, __tm, __fmt, __mod); |
| 2059 | } |
| 2060 | |
| 2061 | static locale::id id; |
| 2062 | |
| 2063 | protected: |
| 2064 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~time_put() override {} |
| 2065 | virtual iter_type do_put(iter_type __s, ios_base&, char_type, const tm* __tm, char __fmt, char __mod) const; |
| 2066 | |
| 2067 | _LIBCPP_HIDE_FROM_ABI explicit time_put(const char* __nm, size_t __refs) : locale::facet(__refs), __time_put(__nm) {} |
| 2068 | _LIBCPP_HIDE_FROM_ABI explicit time_put(const string& __nm, size_t __refs) |
| 2069 | : locale::facet(__refs), __time_put(__nm) {} |
| 2070 | }; |
| 2071 | |
| 2072 | template <class _CharT, class _OutputIterator> |
| 2073 | locale::id time_put<_CharT, _OutputIterator>::id; |
| 2074 | |
| 2075 | template <class _CharT, class _OutputIterator> |
| 2076 | _OutputIterator time_put<_CharT, _OutputIterator>::put( |
| 2077 | iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm, const char_type* __pb, const char_type* __pe) |
| 2078 | const { |
| 2079 | const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__iob.getloc()); |
| 2080 | for (; __pb != __pe; ++__pb) { |
| 2081 | if (__ct.narrow(*__pb, 0) == '%') { |
| 2082 | if (++__pb == __pe) { |
| 2083 | *__s++ = __pb[-1]; |
| 2084 | break; |
| 2085 | } |
| 2086 | char __mod = 0; |
| 2087 | char __fmt = __ct.narrow(*__pb, 0); |
| 2088 | if (__fmt == 'E' || __fmt == 'O') { |
| 2089 | if (++__pb == __pe) { |
| 2090 | *__s++ = __pb[-2]; |
| 2091 | *__s++ = __pb[-1]; |
| 2092 | break; |
| 2093 | } |
| 2094 | __mod = __fmt; |
| 2095 | __fmt = __ct.narrow(*__pb, 0); |
| 2096 | } |
| 2097 | __s = do_put(__s, __iob, __fl, __tm, __fmt, __mod); |
| 2098 | } else |
| 2099 | *__s++ = *__pb; |
| 2100 | } |
| 2101 | return __s; |
| 2102 | } |
| 2103 | |
| 2104 | template <class _CharT, class _OutputIterator> |
| 2105 | _OutputIterator time_put<_CharT, _OutputIterator>::do_put( |
| 2106 | iter_type __s, ios_base&, char_type, const tm* __tm, char __fmt, char __mod) const { |
| 2107 | char_type __nar[100]; |
| 2108 | char_type* __nb = __nar; |
| 2109 | char_type* __ne = __nb + 100; |
| 2110 | __do_put(__nb, __ne, __tm, __fmt, __mod); |
| 2111 | return std::copy(__nb, __ne, __s); |
| 2112 | } |
| 2113 | |
| 2114 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<char>; |
| 2115 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 2116 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<wchar_t>; |
| 2117 | # endif |
| 2118 | |
| 2119 | template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> > |
| 2120 | class time_put_byname : public time_put<_CharT, _OutputIterator> { |
| 2121 | public: |
| 2122 | _LIBCPP_HIDE_FROM_ABI explicit time_put_byname(const char* __nm, size_t __refs = 0) |
| 2123 | : time_put<_CharT, _OutputIterator>(__nm, __refs) {} |
| 2124 | |
| 2125 | _LIBCPP_HIDE_FROM_ABI explicit time_put_byname(const string& __nm, size_t __refs = 0) |
| 2126 | : time_put<_CharT, _OutputIterator>(__nm, __refs) {} |
| 2127 | |
| 2128 | protected: |
| 2129 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~time_put_byname() override {} |
| 2130 | }; |
| 2131 | |
| 2132 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<char>; |
| 2133 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 2134 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<wchar_t>; |
| 2135 | # endif |
| 2136 | |
| 2137 | // money_base |
| 2138 | |
| 2139 | class _LIBCPP_EXPORTED_FROM_ABI money_base { |
| 2140 | public: |
| 2141 | enum part { none, space, symbol, sign, value }; |
| 2142 | struct pattern { |
| 2143 | char field[4]; |
| 2144 | }; |
| 2145 | |
| 2146 | _LIBCPP_HIDE_FROM_ABI money_base() {} |
| 2147 | }; |
| 2148 | |
| 2149 | // moneypunct |
| 2150 | |
| 2151 | template <class _CharT, bool _International = false> |
| 2152 | class moneypunct : public locale::facet, public money_base { |
| 2153 | public: |
| 2154 | typedef _CharT char_type; |
| 2155 | typedef basic_string<char_type> string_type; |
| 2156 | |
| 2157 | _LIBCPP_HIDE_FROM_ABI explicit moneypunct(size_t __refs = 0) : locale::facet(__refs) {} |
| 2158 | |
| 2159 | _LIBCPP_HIDE_FROM_ABI char_type decimal_point() const { return do_decimal_point(); } |
| 2160 | _LIBCPP_HIDE_FROM_ABI char_type thousands_sep() const { return do_thousands_sep(); } |
| 2161 | _LIBCPP_HIDE_FROM_ABI string grouping() const { return do_grouping(); } |
| 2162 | _LIBCPP_HIDE_FROM_ABI string_type curr_symbol() const { return do_curr_symbol(); } |
| 2163 | _LIBCPP_HIDE_FROM_ABI string_type positive_sign() const { return do_positive_sign(); } |
| 2164 | _LIBCPP_HIDE_FROM_ABI string_type negative_sign() const { return do_negative_sign(); } |
| 2165 | _LIBCPP_HIDE_FROM_ABI int frac_digits() const { return do_frac_digits(); } |
| 2166 | _LIBCPP_HIDE_FROM_ABI pattern pos_format() const { return do_pos_format(); } |
| 2167 | _LIBCPP_HIDE_FROM_ABI pattern neg_format() const { return do_neg_format(); } |
| 2168 | |
| 2169 | static locale::id id; |
| 2170 | static const bool intl = _International; |
| 2171 | |
| 2172 | protected: |
| 2173 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~moneypunct() override {} |
| 2174 | |
| 2175 | virtual char_type do_decimal_point() const { return numeric_limits<char_type>::max(); } |
| 2176 | virtual char_type do_thousands_sep() const { return numeric_limits<char_type>::max(); } |
| 2177 | virtual string do_grouping() const { return string(); } |
| 2178 | virtual string_type do_curr_symbol() const { return string_type(); } |
| 2179 | virtual string_type do_positive_sign() const { return string_type(); } |
| 2180 | virtual string_type do_negative_sign() const { return string_type(1, '-'); } |
| 2181 | virtual int do_frac_digits() const { return 0; } |
| 2182 | virtual pattern do_pos_format() const { |
| 2183 | pattern __p = {.field: {symbol, sign, none, value}}; |
| 2184 | return __p; |
| 2185 | } |
| 2186 | virtual pattern do_neg_format() const { |
| 2187 | pattern __p = {.field: {symbol, sign, none, value}}; |
| 2188 | return __p; |
| 2189 | } |
| 2190 | }; |
| 2191 | |
| 2192 | template <class _CharT, bool _International> |
| 2193 | locale::id moneypunct<_CharT, _International>::id; |
| 2194 | |
| 2195 | template <class _CharT, bool _International> |
| 2196 | const bool moneypunct<_CharT, _International>::intl; |
| 2197 | |
| 2198 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, false>; |
| 2199 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, true>; |
| 2200 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 2201 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, false>; |
| 2202 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, true>; |
| 2203 | # endif |
| 2204 | |
| 2205 | // moneypunct_byname |
| 2206 | |
| 2207 | template <class _CharT, bool _International = false> |
| 2208 | class moneypunct_byname : public moneypunct<_CharT, _International> { |
| 2209 | public: |
| 2210 | typedef money_base::pattern pattern; |
| 2211 | typedef _CharT char_type; |
| 2212 | typedef basic_string<char_type> string_type; |
| 2213 | |
| 2214 | _LIBCPP_HIDE_FROM_ABI explicit moneypunct_byname(const char* __nm, size_t __refs = 0) |
| 2215 | : moneypunct<_CharT, _International>(__refs) { |
| 2216 | init(__nm); |
| 2217 | } |
| 2218 | |
| 2219 | _LIBCPP_HIDE_FROM_ABI explicit moneypunct_byname(const string& __nm, size_t __refs = 0) |
| 2220 | : moneypunct<_CharT, _International>(__refs) { |
| 2221 | init(__nm.c_str()); |
| 2222 | } |
| 2223 | |
| 2224 | protected: |
| 2225 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~moneypunct_byname() override {} |
| 2226 | |
| 2227 | char_type do_decimal_point() const override { return __decimal_point_; } |
| 2228 | char_type do_thousands_sep() const override { return __thousands_sep_; } |
| 2229 | string do_grouping() const override { return __grouping_; } |
| 2230 | string_type do_curr_symbol() const override { return __curr_symbol_; } |
| 2231 | string_type do_positive_sign() const override { return __positive_sign_; } |
| 2232 | string_type do_negative_sign() const override { return __negative_sign_; } |
| 2233 | int do_frac_digits() const override { return __frac_digits_; } |
| 2234 | pattern do_pos_format() const override { return __pos_format_; } |
| 2235 | pattern do_neg_format() const override { return __neg_format_; } |
| 2236 | |
| 2237 | private: |
| 2238 | char_type __decimal_point_; |
| 2239 | char_type __thousands_sep_; |
| 2240 | string __grouping_; |
| 2241 | string_type __curr_symbol_; |
| 2242 | string_type __positive_sign_; |
| 2243 | string_type __negative_sign_; |
| 2244 | int __frac_digits_; |
| 2245 | pattern __pos_format_; |
| 2246 | pattern __neg_format_; |
| 2247 | |
| 2248 | void init(const char*); |
| 2249 | }; |
| 2250 | |
| 2251 | template <> |
| 2252 | _LIBCPP_EXPORTED_FROM_ABI void moneypunct_byname<char, false>::init(const char*); |
| 2253 | template <> |
| 2254 | _LIBCPP_EXPORTED_FROM_ABI void moneypunct_byname<char, true>::init(const char*); |
| 2255 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, false>; |
| 2256 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, true>; |
| 2257 | |
| 2258 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 2259 | template <> |
| 2260 | _LIBCPP_EXPORTED_FROM_ABI void moneypunct_byname<wchar_t, false>::init(const char*); |
| 2261 | template <> |
| 2262 | _LIBCPP_EXPORTED_FROM_ABI void moneypunct_byname<wchar_t, true>::init(const char*); |
| 2263 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, false>; |
| 2264 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, true>; |
| 2265 | # endif |
| 2266 | |
| 2267 | // money_get |
| 2268 | |
| 2269 | template <class _CharT> |
| 2270 | class __money_get { |
| 2271 | protected: |
| 2272 | typedef _CharT char_type; |
| 2273 | typedef basic_string<char_type> string_type; |
| 2274 | |
| 2275 | _LIBCPP_HIDE_FROM_ABI __money_get() {} |
| 2276 | |
| 2277 | static void __gather_info( |
| 2278 | bool __intl, |
| 2279 | const locale& __loc, |
| 2280 | money_base::pattern& __pat, |
| 2281 | char_type& __dp, |
| 2282 | char_type& __ts, |
| 2283 | string& __grp, |
| 2284 | string_type& __sym, |
| 2285 | string_type& __psn, |
| 2286 | string_type& __nsn, |
| 2287 | int& __fd); |
| 2288 | }; |
| 2289 | |
| 2290 | template <class _CharT> |
| 2291 | void __money_get<_CharT>::__gather_info( |
| 2292 | bool __intl, |
| 2293 | const locale& __loc, |
| 2294 | money_base::pattern& __pat, |
| 2295 | char_type& __dp, |
| 2296 | char_type& __ts, |
| 2297 | string& __grp, |
| 2298 | string_type& __sym, |
| 2299 | string_type& __psn, |
| 2300 | string_type& __nsn, |
| 2301 | int& __fd) { |
| 2302 | if (__intl) { |
| 2303 | const moneypunct<char_type, true>& __mp = std::use_facet<moneypunct<char_type, true> >(__loc); |
| 2304 | __pat = __mp.neg_format(); |
| 2305 | __nsn = __mp.negative_sign(); |
| 2306 | __psn = __mp.positive_sign(); |
| 2307 | __dp = __mp.decimal_point(); |
| 2308 | __ts = __mp.thousands_sep(); |
| 2309 | __grp = __mp.grouping(); |
| 2310 | __sym = __mp.curr_symbol(); |
| 2311 | __fd = __mp.frac_digits(); |
| 2312 | } else { |
| 2313 | const moneypunct<char_type, false>& __mp = std::use_facet<moneypunct<char_type, false> >(__loc); |
| 2314 | __pat = __mp.neg_format(); |
| 2315 | __nsn = __mp.negative_sign(); |
| 2316 | __psn = __mp.positive_sign(); |
| 2317 | __dp = __mp.decimal_point(); |
| 2318 | __ts = __mp.thousands_sep(); |
| 2319 | __grp = __mp.grouping(); |
| 2320 | __sym = __mp.curr_symbol(); |
| 2321 | __fd = __mp.frac_digits(); |
| 2322 | } |
| 2323 | } |
| 2324 | |
| 2325 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<char>; |
| 2326 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 2327 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<wchar_t>; |
| 2328 | # endif |
| 2329 | |
| 2330 | template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> > |
| 2331 | class money_get : public locale::facet, private __money_get<_CharT> { |
| 2332 | public: |
| 2333 | typedef _CharT char_type; |
| 2334 | typedef _InputIterator iter_type; |
| 2335 | typedef basic_string<char_type> string_type; |
| 2336 | |
| 2337 | _LIBCPP_HIDE_FROM_ABI explicit money_get(size_t __refs = 0) : locale::facet(__refs) {} |
| 2338 | |
| 2339 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 2340 | get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, long double& __v) const { |
| 2341 | return do_get(__b, __e, __intl, __iob, __err, __v); |
| 2342 | } |
| 2343 | |
| 2344 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 2345 | get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, string_type& __v) const { |
| 2346 | return do_get(__b, __e, __intl, __iob, __err, __v); |
| 2347 | } |
| 2348 | |
| 2349 | static locale::id id; |
| 2350 | |
| 2351 | protected: |
| 2352 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~money_get() override {} |
| 2353 | |
| 2354 | virtual iter_type |
| 2355 | do_get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, long double& __v) const; |
| 2356 | virtual iter_type |
| 2357 | do_get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, string_type& __v) const; |
| 2358 | |
| 2359 | private: |
| 2360 | static bool __do_get( |
| 2361 | iter_type& __b, |
| 2362 | iter_type __e, |
| 2363 | bool __intl, |
| 2364 | const locale& __loc, |
| 2365 | ios_base::fmtflags __flags, |
| 2366 | ios_base::iostate& __err, |
| 2367 | bool& __neg, |
| 2368 | const ctype<char_type>& __ct, |
| 2369 | unique_ptr<char_type, void (*)(void*)>& __wb, |
| 2370 | char_type*& __wn, |
| 2371 | char_type* __we); |
| 2372 | }; |
| 2373 | |
| 2374 | template <class _CharT, class _InputIterator> |
| 2375 | locale::id money_get<_CharT, _InputIterator>::id; |
| 2376 | |
| 2377 | _LIBCPP_EXPORTED_FROM_ABI void __do_nothing(void*); |
| 2378 | |
| 2379 | template <class _Tp> |
| 2380 | _LIBCPP_HIDE_FROM_ABI void __double_or_nothing(unique_ptr<_Tp, void (*)(void*)>& __b, _Tp*& __n, _Tp*& __e) { |
| 2381 | bool __owns = __b.get_deleter() != __do_nothing; |
| 2382 | size_t __cur_cap = static_cast<size_t>(__e - __b.get()) * sizeof(_Tp); |
| 2383 | size_t __new_cap = __cur_cap < numeric_limits<size_t>::max() / 2 ? 2 * __cur_cap : numeric_limits<size_t>::max(); |
| 2384 | if (__new_cap == 0) |
| 2385 | __new_cap = sizeof(_Tp); |
| 2386 | size_t __n_off = static_cast<size_t>(__n - __b.get()); |
| 2387 | _Tp* __t = (_Tp*)std::realloc(ptr: __owns ? __b.get() : 0, size: __new_cap); |
| 2388 | if (__t == 0) |
| 2389 | std::__throw_bad_alloc(); |
| 2390 | if (__owns) |
| 2391 | __b.release(); |
| 2392 | else |
| 2393 | std::memcpy(dest: __t, src: __b.get(), n: __cur_cap); |
| 2394 | __b = unique_ptr<_Tp, void (*)(void*)>(__t, free); |
| 2395 | __new_cap /= sizeof(_Tp); |
| 2396 | __n = __b.get() + __n_off; |
| 2397 | __e = __b.get() + __new_cap; |
| 2398 | } |
| 2399 | |
| 2400 | // true == success |
| 2401 | template <class _CharT, class _InputIterator> |
| 2402 | bool money_get<_CharT, _InputIterator>::__do_get( |
| 2403 | iter_type& __b, |
| 2404 | iter_type __e, |
| 2405 | bool __intl, |
| 2406 | const locale& __loc, |
| 2407 | ios_base::fmtflags __flags, |
| 2408 | ios_base::iostate& __err, |
| 2409 | bool& __neg, |
| 2410 | const ctype<char_type>& __ct, |
| 2411 | unique_ptr<char_type, void (*)(void*)>& __wb, |
| 2412 | char_type*& __wn, |
| 2413 | char_type* __we) { |
| 2414 | if (__b == __e) { |
| 2415 | __err |= ios_base::failbit; |
| 2416 | return false; |
| 2417 | } |
| 2418 | const unsigned __bz = 100; |
| 2419 | unsigned __gbuf[__bz]; |
| 2420 | unique_ptr<unsigned, void (*)(void*)> __gb(__gbuf, __do_nothing); |
| 2421 | unsigned* __gn = __gb.get(); |
| 2422 | unsigned* __ge = __gn + __bz; |
| 2423 | money_base::pattern __pat; |
| 2424 | char_type __dp; |
| 2425 | char_type __ts; |
| 2426 | string __grp; |
| 2427 | string_type __sym; |
| 2428 | string_type __psn; |
| 2429 | string_type __nsn; |
| 2430 | // Capture the spaces read into money_base::{space,none} so they |
| 2431 | // can be compared to initial spaces in __sym. |
| 2432 | string_type __spaces; |
| 2433 | int __fd; |
| 2434 | __money_get<_CharT>::__gather_info(__intl, __loc, __pat, __dp, __ts, __grp, __sym, __psn, __nsn, __fd); |
| 2435 | const string_type* __trailing_sign = 0; |
| 2436 | __wn = __wb.get(); |
| 2437 | for (unsigned __p = 0; __p < 4 && __b != __e; ++__p) { |
| 2438 | switch (__pat.field[__p]) { |
| 2439 | case money_base::space: |
| 2440 | if (__p != 3) { |
| 2441 | if (__ct.is(ctype_base::space, *__b)) |
| 2442 | __spaces.push_back(*__b++); |
| 2443 | else { |
| 2444 | __err |= ios_base::failbit; |
| 2445 | return false; |
| 2446 | } |
| 2447 | } |
| 2448 | [[__fallthrough__]]; |
| 2449 | case money_base::none: |
| 2450 | if (__p != 3) { |
| 2451 | while (__b != __e && __ct.is(ctype_base::space, *__b)) |
| 2452 | __spaces.push_back(*__b++); |
| 2453 | } |
| 2454 | break; |
| 2455 | case money_base::sign: |
| 2456 | if (__psn.size() > 0 && *__b == __psn[0]) { |
| 2457 | ++__b; |
| 2458 | __neg = false; |
| 2459 | if (__psn.size() > 1) |
| 2460 | __trailing_sign = std::addressof(__psn); |
| 2461 | break; |
| 2462 | } |
| 2463 | if (__nsn.size() > 0 && *__b == __nsn[0]) { |
| 2464 | ++__b; |
| 2465 | __neg = true; |
| 2466 | if (__nsn.size() > 1) |
| 2467 | __trailing_sign = std::addressof(__nsn); |
| 2468 | break; |
| 2469 | } |
| 2470 | if (__psn.size() > 0 && __nsn.size() > 0) { // sign is required |
| 2471 | __err |= ios_base::failbit; |
| 2472 | return false; |
| 2473 | } |
| 2474 | if (__psn.size() == 0 && __nsn.size() == 0) |
| 2475 | // locale has no way of specifying a sign. Use the initial value of __neg as a default |
| 2476 | break; |
| 2477 | __neg = (__nsn.size() == 0); |
| 2478 | break; |
| 2479 | case money_base::symbol: { |
| 2480 | bool __more_needed = |
| 2481 | __trailing_sign || (__p < 2) || (__p == 2 && __pat.field[3] != static_cast<char>(money_base::none)); |
| 2482 | bool __sb = (__flags & ios_base::showbase) != 0; |
| 2483 | if (__sb || __more_needed) { |
| 2484 | typename string_type::const_iterator __sym_space_end = __sym.begin(); |
| 2485 | if (__p > 0 && (__pat.field[__p - 1] == money_base::none || __pat.field[__p - 1] == money_base::space)) { |
| 2486 | // Match spaces we've already read against spaces at |
| 2487 | // the beginning of __sym. |
| 2488 | while (__sym_space_end != __sym.end() && __ct.is(ctype_base::space, *__sym_space_end)) |
| 2489 | ++__sym_space_end; |
| 2490 | const size_t __num_spaces = __sym_space_end - __sym.begin(); |
| 2491 | if (__num_spaces > __spaces.size() || |
| 2492 | !std::equal(__spaces.end() - __num_spaces, __spaces.end(), __sym.begin())) { |
| 2493 | // No match. Put __sym_space_end back at the |
| 2494 | // beginning of __sym, which will prevent a |
| 2495 | // match in the next loop. |
| 2496 | __sym_space_end = __sym.begin(); |
| 2497 | } |
| 2498 | } |
| 2499 | typename string_type::const_iterator __sym_curr_char = __sym_space_end; |
| 2500 | while (__sym_curr_char != __sym.end() && __b != __e && *__b == *__sym_curr_char) { |
| 2501 | ++__b; |
| 2502 | ++__sym_curr_char; |
| 2503 | } |
| 2504 | if (__sb && __sym_curr_char != __sym.end()) { |
| 2505 | __err |= ios_base::failbit; |
| 2506 | return false; |
| 2507 | } |
| 2508 | } |
| 2509 | } break; |
| 2510 | case money_base::value: { |
| 2511 | unsigned __ng = 0; |
| 2512 | for (; __b != __e; ++__b) { |
| 2513 | char_type __c = *__b; |
| 2514 | if (__ct.is(ctype_base::digit, __c)) { |
| 2515 | if (__wn == __we) |
| 2516 | std::__double_or_nothing(__wb, __wn, __we); |
| 2517 | *__wn++ = __c; |
| 2518 | ++__ng; |
| 2519 | } else if (__grp.size() > 0 && __ng > 0 && __c == __ts) { |
| 2520 | if (__gn == __ge) |
| 2521 | std::__double_or_nothing(b&: __gb, n&: __gn, e&: __ge); |
| 2522 | *__gn++ = __ng; |
| 2523 | __ng = 0; |
| 2524 | } else |
| 2525 | break; |
| 2526 | } |
| 2527 | if (__gb.get() != __gn && __ng > 0) { |
| 2528 | if (__gn == __ge) |
| 2529 | std::__double_or_nothing(b&: __gb, n&: __gn, e&: __ge); |
| 2530 | *__gn++ = __ng; |
| 2531 | } |
| 2532 | if (__fd > 0) { |
| 2533 | if (__b == __e || *__b != __dp) { |
| 2534 | __err |= ios_base::failbit; |
| 2535 | return false; |
| 2536 | } |
| 2537 | for (++__b; __fd > 0; --__fd, ++__b) { |
| 2538 | if (__b == __e || !__ct.is(ctype_base::digit, *__b)) { |
| 2539 | __err |= ios_base::failbit; |
| 2540 | return false; |
| 2541 | } |
| 2542 | if (__wn == __we) |
| 2543 | std::__double_or_nothing(__wb, __wn, __we); |
| 2544 | *__wn++ = *__b; |
| 2545 | } |
| 2546 | } |
| 2547 | if (__wn == __wb.get()) { |
| 2548 | __err |= ios_base::failbit; |
| 2549 | return false; |
| 2550 | } |
| 2551 | } break; |
| 2552 | } |
| 2553 | } |
| 2554 | if (__trailing_sign) { |
| 2555 | for (unsigned __i = 1; __i < __trailing_sign->size(); ++__i, ++__b) { |
| 2556 | if (__b == __e || *__b != (*__trailing_sign)[__i]) { |
| 2557 | __err |= ios_base::failbit; |
| 2558 | return false; |
| 2559 | } |
| 2560 | } |
| 2561 | } |
| 2562 | if (__gb.get() != __gn) { |
| 2563 | ios_base::iostate __et = ios_base::goodbit; |
| 2564 | __check_grouping(grouping: __grp, g: __gb.get(), g_end: __gn, err&: __et); |
| 2565 | if (__et) { |
| 2566 | __err |= ios_base::failbit; |
| 2567 | return false; |
| 2568 | } |
| 2569 | } |
| 2570 | return true; |
| 2571 | } |
| 2572 | |
| 2573 | template <class _CharT, class _InputIterator> |
| 2574 | _InputIterator money_get<_CharT, _InputIterator>::do_get( |
| 2575 | iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, long double& __v) const { |
| 2576 | const int __bz = 100; |
| 2577 | char_type __wbuf[__bz]; |
| 2578 | unique_ptr<char_type, void (*)(void*)> __wb(__wbuf, __do_nothing); |
| 2579 | char_type* __wn; |
| 2580 | char_type* __we = __wbuf + __bz; |
| 2581 | locale __loc = __iob.getloc(); |
| 2582 | const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__loc); |
| 2583 | bool __neg = false; |
| 2584 | if (__do_get(__b, __e, __intl, __loc, flags: __iob.flags(), __err, __neg, __ct, __wb, __wn, __we)) { |
| 2585 | const char __src[] = "0123456789" ; |
| 2586 | char_type __atoms[sizeof(__src) - 1]; |
| 2587 | __ct.widen(__src, __src + (sizeof(__src) - 1), __atoms); |
| 2588 | char __nbuf[__bz]; |
| 2589 | char* __nc = __nbuf; |
| 2590 | const char* __nc_in = __nc; |
| 2591 | unique_ptr<char, void (*)(void*)> __h(nullptr, free); |
| 2592 | if (__wn - __wb.get() > __bz - 2) { |
| 2593 | __h.reset(p: (char*)malloc(size: static_cast<size_t>(__wn - __wb.get() + 2))); |
| 2594 | if (__h.get() == nullptr) |
| 2595 | std::__throw_bad_alloc(); |
| 2596 | __nc = __h.get(); |
| 2597 | __nc_in = __nc; |
| 2598 | } |
| 2599 | if (__neg) |
| 2600 | *__nc++ = '-'; |
| 2601 | for (const char_type* __w = __wb.get(); __w < __wn; ++__w, ++__nc) |
| 2602 | *__nc = __src[std::find(__atoms, std::end(__atoms), *__w) - __atoms]; |
| 2603 | *__nc = char(); |
| 2604 | if (sscanf(s: __nc_in, format: "%Lf" , &__v) != 1) |
| 2605 | std::__throw_runtime_error("money_get error" ); |
| 2606 | } |
| 2607 | if (__b == __e) |
| 2608 | __err |= ios_base::eofbit; |
| 2609 | return __b; |
| 2610 | } |
| 2611 | |
| 2612 | template <class _CharT, class _InputIterator> |
| 2613 | _InputIterator money_get<_CharT, _InputIterator>::do_get( |
| 2614 | iter_type __b, iter_type __e, bool __intl, ios_base& __iob, ios_base::iostate& __err, string_type& __v) const { |
| 2615 | const int __bz = 100; |
| 2616 | char_type __wbuf[__bz]; |
| 2617 | unique_ptr<char_type, void (*)(void*)> __wb(__wbuf, __do_nothing); |
| 2618 | char_type* __wn; |
| 2619 | char_type* __we = __wbuf + __bz; |
| 2620 | locale __loc = __iob.getloc(); |
| 2621 | const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__loc); |
| 2622 | bool __neg = false; |
| 2623 | if (__do_get(__b, __e, __intl, __loc, flags: __iob.flags(), __err, __neg, __ct, __wb, __wn, __we)) { |
| 2624 | __v.clear(); |
| 2625 | if (__neg) |
| 2626 | __v.push_back(__ct.widen('-')); |
| 2627 | char_type __z = __ct.widen('0'); |
| 2628 | char_type* __w; |
| 2629 | for (__w = __wb.get(); __w < __wn - 1; ++__w) |
| 2630 | if (*__w != __z) |
| 2631 | break; |
| 2632 | __v.append(__w, __wn); |
| 2633 | } |
| 2634 | if (__b == __e) |
| 2635 | __err |= ios_base::eofbit; |
| 2636 | return __b; |
| 2637 | } |
| 2638 | |
| 2639 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<char>; |
| 2640 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 2641 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<wchar_t>; |
| 2642 | # endif |
| 2643 | |
| 2644 | // money_put |
| 2645 | |
| 2646 | template <class _CharT> |
| 2647 | class __money_put { |
| 2648 | protected: |
| 2649 | typedef _CharT char_type; |
| 2650 | typedef basic_string<char_type> string_type; |
| 2651 | |
| 2652 | _LIBCPP_HIDE_FROM_ABI __money_put() {} |
| 2653 | |
| 2654 | static void __gather_info( |
| 2655 | bool __intl, |
| 2656 | bool __neg, |
| 2657 | const locale& __loc, |
| 2658 | money_base::pattern& __pat, |
| 2659 | char_type& __dp, |
| 2660 | char_type& __ts, |
| 2661 | string& __grp, |
| 2662 | string_type& __sym, |
| 2663 | string_type& __sn, |
| 2664 | int& __fd); |
| 2665 | static void __format( |
| 2666 | char_type* __mb, |
| 2667 | char_type*& __mi, |
| 2668 | char_type*& __me, |
| 2669 | ios_base::fmtflags __flags, |
| 2670 | const char_type* __db, |
| 2671 | const char_type* __de, |
| 2672 | const ctype<char_type>& __ct, |
| 2673 | bool __neg, |
| 2674 | const money_base::pattern& __pat, |
| 2675 | char_type __dp, |
| 2676 | char_type __ts, |
| 2677 | const string& __grp, |
| 2678 | const string_type& __sym, |
| 2679 | const string_type& __sn, |
| 2680 | int __fd); |
| 2681 | }; |
| 2682 | |
| 2683 | template <class _CharT> |
| 2684 | void __money_put<_CharT>::__gather_info( |
| 2685 | bool __intl, |
| 2686 | bool __neg, |
| 2687 | const locale& __loc, |
| 2688 | money_base::pattern& __pat, |
| 2689 | char_type& __dp, |
| 2690 | char_type& __ts, |
| 2691 | string& __grp, |
| 2692 | string_type& __sym, |
| 2693 | string_type& __sn, |
| 2694 | int& __fd) { |
| 2695 | if (__intl) { |
| 2696 | const moneypunct<char_type, true>& __mp = std::use_facet<moneypunct<char_type, true> >(__loc); |
| 2697 | if (__neg) { |
| 2698 | __pat = __mp.neg_format(); |
| 2699 | __sn = __mp.negative_sign(); |
| 2700 | } else { |
| 2701 | __pat = __mp.pos_format(); |
| 2702 | __sn = __mp.positive_sign(); |
| 2703 | } |
| 2704 | __dp = __mp.decimal_point(); |
| 2705 | __ts = __mp.thousands_sep(); |
| 2706 | __grp = __mp.grouping(); |
| 2707 | __sym = __mp.curr_symbol(); |
| 2708 | __fd = __mp.frac_digits(); |
| 2709 | } else { |
| 2710 | const moneypunct<char_type, false>& __mp = std::use_facet<moneypunct<char_type, false> >(__loc); |
| 2711 | if (__neg) { |
| 2712 | __pat = __mp.neg_format(); |
| 2713 | __sn = __mp.negative_sign(); |
| 2714 | } else { |
| 2715 | __pat = __mp.pos_format(); |
| 2716 | __sn = __mp.positive_sign(); |
| 2717 | } |
| 2718 | __dp = __mp.decimal_point(); |
| 2719 | __ts = __mp.thousands_sep(); |
| 2720 | __grp = __mp.grouping(); |
| 2721 | __sym = __mp.curr_symbol(); |
| 2722 | __fd = __mp.frac_digits(); |
| 2723 | } |
| 2724 | } |
| 2725 | |
| 2726 | template <class _CharT> |
| 2727 | void __money_put<_CharT>::__format( |
| 2728 | char_type* __mb, |
| 2729 | char_type*& __mi, |
| 2730 | char_type*& __me, |
| 2731 | ios_base::fmtflags __flags, |
| 2732 | const char_type* __db, |
| 2733 | const char_type* __de, |
| 2734 | const ctype<char_type>& __ct, |
| 2735 | bool __neg, |
| 2736 | const money_base::pattern& __pat, |
| 2737 | char_type __dp, |
| 2738 | char_type __ts, |
| 2739 | const string& __grp, |
| 2740 | const string_type& __sym, |
| 2741 | const string_type& __sn, |
| 2742 | int __fd) { |
| 2743 | __me = __mb; |
| 2744 | for (char __p : __pat.field) { |
| 2745 | switch (__p) { |
| 2746 | case money_base::none: |
| 2747 | __mi = __me; |
| 2748 | break; |
| 2749 | case money_base::space: |
| 2750 | __mi = __me; |
| 2751 | *__me++ = __ct.widen(' '); |
| 2752 | break; |
| 2753 | case money_base::sign: |
| 2754 | if (!__sn.empty()) |
| 2755 | *__me++ = __sn[0]; |
| 2756 | break; |
| 2757 | case money_base::symbol: |
| 2758 | if (!__sym.empty() && (__flags & ios_base::showbase)) |
| 2759 | __me = std::copy(__sym.begin(), __sym.end(), __me); |
| 2760 | break; |
| 2761 | case money_base::value: { |
| 2762 | // remember start of value so we can reverse it |
| 2763 | char_type* __t = __me; |
| 2764 | // find beginning of digits |
| 2765 | if (__neg) |
| 2766 | ++__db; |
| 2767 | // find end of digits |
| 2768 | const char_type* __d; |
| 2769 | for (__d = __db; __d < __de; ++__d) |
| 2770 | if (!__ct.is(ctype_base::digit, *__d)) |
| 2771 | break; |
| 2772 | // print fractional part |
| 2773 | if (__fd > 0) { |
| 2774 | int __f; |
| 2775 | for (__f = __fd; __d > __db && __f > 0; --__f) |
| 2776 | *__me++ = *--__d; |
| 2777 | char_type __z = __f > 0 ? __ct.widen('0') : char_type(); |
| 2778 | for (; __f > 0; --__f) |
| 2779 | *__me++ = __z; |
| 2780 | *__me++ = __dp; |
| 2781 | } |
| 2782 | // print units part |
| 2783 | if (__d == __db) { |
| 2784 | *__me++ = __ct.widen('0'); |
| 2785 | } else { |
| 2786 | unsigned __ng = 0; |
| 2787 | unsigned __ig = 0; |
| 2788 | unsigned __gl = __grp.empty() ? numeric_limits<unsigned>::max() : static_cast<unsigned>(__grp[__ig]); |
| 2789 | while (__d != __db) { |
| 2790 | if (__ng == __gl) { |
| 2791 | *__me++ = __ts; |
| 2792 | __ng = 0; |
| 2793 | if (++__ig < __grp.size()) |
| 2794 | __gl = __grp[__ig] == numeric_limits<char>::max() |
| 2795 | ? numeric_limits<unsigned>::max() |
| 2796 | : static_cast<unsigned>(__grp[__ig]); |
| 2797 | } |
| 2798 | *__me++ = *--__d; |
| 2799 | ++__ng; |
| 2800 | } |
| 2801 | } |
| 2802 | // reverse it |
| 2803 | std::reverse(__t, __me); |
| 2804 | } break; |
| 2805 | } |
| 2806 | } |
| 2807 | // print rest of sign, if any |
| 2808 | if (__sn.size() > 1) |
| 2809 | __me = std::copy(__sn.begin() + 1, __sn.end(), __me); |
| 2810 | // set alignment |
| 2811 | if ((__flags & ios_base::adjustfield) == ios_base::left) |
| 2812 | __mi = __me; |
| 2813 | else if ((__flags & ios_base::adjustfield) != ios_base::internal) |
| 2814 | __mi = __mb; |
| 2815 | } |
| 2816 | |
| 2817 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<char>; |
| 2818 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 2819 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<wchar_t>; |
| 2820 | # endif |
| 2821 | |
| 2822 | template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> > |
| 2823 | class money_put : public locale::facet, private __money_put<_CharT> { |
| 2824 | public: |
| 2825 | typedef _CharT char_type; |
| 2826 | typedef _OutputIterator iter_type; |
| 2827 | typedef basic_string<char_type> string_type; |
| 2828 | |
| 2829 | _LIBCPP_HIDE_FROM_ABI explicit money_put(size_t __refs = 0) : locale::facet(__refs) {} |
| 2830 | |
| 2831 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 2832 | put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, long double __units) const { |
| 2833 | return do_put(__s, __intl, __iob, __fl, __units); |
| 2834 | } |
| 2835 | |
| 2836 | _LIBCPP_HIDE_FROM_ABI iter_type |
| 2837 | put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, const string_type& __digits) const { |
| 2838 | return do_put(__s, __intl, __iob, __fl, __digits); |
| 2839 | } |
| 2840 | |
| 2841 | static locale::id id; |
| 2842 | |
| 2843 | protected: |
| 2844 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~money_put() override {} |
| 2845 | |
| 2846 | virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, long double __units) const; |
| 2847 | virtual iter_type |
| 2848 | do_put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, const string_type& __digits) const; |
| 2849 | }; |
| 2850 | |
| 2851 | template <class _CharT, class _OutputIterator> |
| 2852 | locale::id money_put<_CharT, _OutputIterator>::id; |
| 2853 | |
| 2854 | template <class _CharT, class _OutputIterator> |
| 2855 | _OutputIterator money_put<_CharT, _OutputIterator>::do_put( |
| 2856 | iter_type __s, bool __intl, ios_base& __iob, char_type __fl, long double __units) const { |
| 2857 | // convert to char |
| 2858 | const size_t __bs = 100; |
| 2859 | char __buf[__bs]; |
| 2860 | char* __bb = __buf; |
| 2861 | char_type __digits[__bs]; |
| 2862 | char_type* __db = __digits; |
| 2863 | int __n = snprintf(s: __bb, maxlen: __bs, format: "%.0Lf" , __units); |
| 2864 | unique_ptr<char, void (*)(void*)> __hn(nullptr, free); |
| 2865 | unique_ptr<char_type, void (*)(void*)> __hd(0, free); |
| 2866 | // secure memory for digit storage |
| 2867 | if (static_cast<size_t>(__n) > __bs - 1) { |
| 2868 | __n = __locale::__asprintf(s: &__bb, _LIBCPP_GET_C_LOCALE, format: "%.0Lf" , __units); |
| 2869 | if (__n == -1) |
| 2870 | std::__throw_bad_alloc(); |
| 2871 | __hn.reset(p: __bb); |
| 2872 | __hd.reset((char_type*)malloc(size: static_cast<size_t>(__n) * sizeof(char_type))); |
| 2873 | if (__hd == nullptr) |
| 2874 | std::__throw_bad_alloc(); |
| 2875 | __db = __hd.get(); |
| 2876 | } |
| 2877 | // gather info |
| 2878 | locale __loc = __iob.getloc(); |
| 2879 | const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__loc); |
| 2880 | __ct.widen(__bb, __bb + __n, __db); |
| 2881 | bool __neg = __n > 0 && __bb[0] == '-'; |
| 2882 | money_base::pattern __pat; |
| 2883 | char_type __dp; |
| 2884 | char_type __ts; |
| 2885 | string __grp; |
| 2886 | string_type __sym; |
| 2887 | string_type __sn; |
| 2888 | int __fd; |
| 2889 | this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd); |
| 2890 | // secure memory for formatting |
| 2891 | char_type __mbuf[__bs]; |
| 2892 | char_type* __mb = __mbuf; |
| 2893 | unique_ptr<char_type, void (*)(void*)> __hw(0, free); |
| 2894 | size_t __exn = __n > __fd ? (static_cast<size_t>(__n) - static_cast<size_t>(__fd)) * 2 + __sn.size() + __sym.size() + |
| 2895 | static_cast<size_t>(__fd) + 1 |
| 2896 | : __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 2; |
| 2897 | if (__exn > __bs) { |
| 2898 | __hw.reset((char_type*)malloc(size: __exn * sizeof(char_type))); |
| 2899 | __mb = __hw.get(); |
| 2900 | if (__mb == 0) |
| 2901 | std::__throw_bad_alloc(); |
| 2902 | } |
| 2903 | // format |
| 2904 | char_type* __mi; |
| 2905 | char_type* __me; |
| 2906 | this->__format( |
| 2907 | __mb, __mi, __me, __iob.flags(), __db, __db + __n, __ct, __neg, __pat, __dp, __ts, __grp, __sym, __sn, __fd); |
| 2908 | return std::__pad_and_output(__s, __mb, __mi, __me, __iob, __fl); |
| 2909 | } |
| 2910 | |
| 2911 | template <class _CharT, class _OutputIterator> |
| 2912 | _OutputIterator money_put<_CharT, _OutputIterator>::do_put( |
| 2913 | iter_type __s, bool __intl, ios_base& __iob, char_type __fl, const string_type& __digits) const { |
| 2914 | // gather info |
| 2915 | locale __loc = __iob.getloc(); |
| 2916 | const ctype<char_type>& __ct = std::use_facet<ctype<char_type> >(__loc); |
| 2917 | bool __neg = __digits.size() > 0 && __digits[0] == __ct.widen('-'); |
| 2918 | money_base::pattern __pat; |
| 2919 | char_type __dp; |
| 2920 | char_type __ts; |
| 2921 | string __grp; |
| 2922 | string_type __sym; |
| 2923 | string_type __sn; |
| 2924 | int __fd; |
| 2925 | this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd); |
| 2926 | // secure memory for formatting |
| 2927 | char_type __mbuf[100]; |
| 2928 | char_type* __mb = __mbuf; |
| 2929 | unique_ptr<char_type, void (*)(void*)> __h(0, free); |
| 2930 | size_t __exn = |
| 2931 | static_cast<int>(__digits.size()) > __fd |
| 2932 | ? (__digits.size() - static_cast<size_t>(__fd)) * 2 + __sn.size() + __sym.size() + static_cast<size_t>(__fd) + |
| 2933 | 1 |
| 2934 | : __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 2; |
| 2935 | if (__exn > 100) { |
| 2936 | __h.reset((char_type*)malloc(size: __exn * sizeof(char_type))); |
| 2937 | __mb = __h.get(); |
| 2938 | if (__mb == 0) |
| 2939 | std::__throw_bad_alloc(); |
| 2940 | } |
| 2941 | // format |
| 2942 | char_type* __mi; |
| 2943 | char_type* __me; |
| 2944 | this->__format( |
| 2945 | __mb, |
| 2946 | __mi, |
| 2947 | __me, |
| 2948 | __iob.flags(), |
| 2949 | __digits.data(), |
| 2950 | __digits.data() + __digits.size(), |
| 2951 | __ct, |
| 2952 | __neg, |
| 2953 | __pat, |
| 2954 | __dp, |
| 2955 | __ts, |
| 2956 | __grp, |
| 2957 | __sym, |
| 2958 | __sn, |
| 2959 | __fd); |
| 2960 | return std::__pad_and_output(__s, __mb, __mi, __me, __iob, __fl); |
| 2961 | } |
| 2962 | |
| 2963 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<char>; |
| 2964 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 2965 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<wchar_t>; |
| 2966 | # endif |
| 2967 | |
| 2968 | // messages |
| 2969 | |
| 2970 | class _LIBCPP_EXPORTED_FROM_ABI messages_base { |
| 2971 | public: |
| 2972 | typedef intptr_t catalog; |
| 2973 | |
| 2974 | _LIBCPP_HIDE_FROM_ABI messages_base() {} |
| 2975 | }; |
| 2976 | |
| 2977 | template <class _CharT> |
| 2978 | class messages : public locale::facet, public messages_base { |
| 2979 | public: |
| 2980 | typedef _CharT char_type; |
| 2981 | typedef basic_string<_CharT> string_type; |
| 2982 | |
| 2983 | _LIBCPP_HIDE_FROM_ABI explicit messages(size_t __refs = 0) : locale::facet(__refs) {} |
| 2984 | |
| 2985 | _LIBCPP_HIDE_FROM_ABI catalog open(const basic_string<char>& __nm, const locale& __loc) const { |
| 2986 | return do_open(__nm, __loc); |
| 2987 | } |
| 2988 | |
| 2989 | _LIBCPP_HIDE_FROM_ABI string_type get(catalog __c, int __set, int __msgid, const string_type& __dflt) const { |
| 2990 | return do_get(__c, __set, __msgid, __dflt); |
| 2991 | } |
| 2992 | |
| 2993 | _LIBCPP_HIDE_FROM_ABI void close(catalog __c) const { do_close(__c); } |
| 2994 | |
| 2995 | static locale::id id; |
| 2996 | |
| 2997 | protected: |
| 2998 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~messages() override {} |
| 2999 | |
| 3000 | virtual catalog do_open(const basic_string<char>&, const locale&) const; |
| 3001 | virtual string_type do_get(catalog, int __set, int __msgid, const string_type& __dflt) const; |
| 3002 | virtual void do_close(catalog) const; |
| 3003 | }; |
| 3004 | |
| 3005 | template <class _CharT> |
| 3006 | locale::id messages<_CharT>::id; |
| 3007 | |
| 3008 | template <class _CharT> |
| 3009 | typename messages<_CharT>::catalog messages<_CharT>::do_open(const basic_string<char>& __nm, const locale&) const { |
| 3010 | # if _LIBCPP_HAS_CATOPEN |
| 3011 | return (catalog)catopen(cat_name: __nm.c_str(), NL_CAT_LOCALE); |
| 3012 | # else // !_LIBCPP_HAS_CATOPEN |
| 3013 | (void)__nm; |
| 3014 | return -1; |
| 3015 | # endif // _LIBCPP_HAS_CATOPEN |
| 3016 | } |
| 3017 | |
| 3018 | template <class _CharT> |
| 3019 | typename messages<_CharT>::string_type |
| 3020 | messages<_CharT>::do_get(catalog __c, int __set, int __msgid, const string_type& __dflt) const { |
| 3021 | # if _LIBCPP_HAS_CATOPEN |
| 3022 | string __ndflt; |
| 3023 | __narrow_to_utf8<sizeof(char_type) * __CHAR_BIT__>()( |
| 3024 | std::back_inserter(x&: __ndflt), __dflt.c_str(), __dflt.c_str() + __dflt.size()); |
| 3025 | nl_catd __cat = (nl_catd)__c; |
| 3026 | static_assert(sizeof(catalog) >= sizeof(nl_catd), "Unexpected nl_catd type" ); |
| 3027 | char* __n = catgets(catalog: __cat, __set, number: __msgid, string: __ndflt.c_str()); |
| 3028 | string_type __w; |
| 3029 | __widen_from_utf8<sizeof(char_type) * __CHAR_BIT__>()(std::back_inserter(__w), __n, __n + std::strlen(s: __n)); |
| 3030 | return __w; |
| 3031 | # else // !_LIBCPP_HAS_CATOPEN |
| 3032 | (void)__c; |
| 3033 | (void)__set; |
| 3034 | (void)__msgid; |
| 3035 | return __dflt; |
| 3036 | # endif // _LIBCPP_HAS_CATOPEN |
| 3037 | } |
| 3038 | |
| 3039 | template <class _CharT> |
| 3040 | void messages<_CharT>::do_close(catalog __c) const { |
| 3041 | # if _LIBCPP_HAS_CATOPEN |
| 3042 | catclose(catalog: (nl_catd)__c); |
| 3043 | # else // !_LIBCPP_HAS_CATOPEN |
| 3044 | (void)__c; |
| 3045 | # endif // _LIBCPP_HAS_CATOPEN |
| 3046 | } |
| 3047 | |
| 3048 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<char>; |
| 3049 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 3050 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<wchar_t>; |
| 3051 | # endif |
| 3052 | |
| 3053 | template <class _CharT> |
| 3054 | class messages_byname : public messages<_CharT> { |
| 3055 | public: |
| 3056 | typedef messages_base::catalog catalog; |
| 3057 | typedef basic_string<_CharT> string_type; |
| 3058 | |
| 3059 | _LIBCPP_HIDE_FROM_ABI explicit messages_byname(const char*, size_t __refs = 0) : messages<_CharT>(__refs) {} |
| 3060 | |
| 3061 | _LIBCPP_HIDE_FROM_ABI explicit messages_byname(const string&, size_t __refs = 0) : messages<_CharT>(__refs) {} |
| 3062 | |
| 3063 | protected: |
| 3064 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~messages_byname() override {} |
| 3065 | }; |
| 3066 | |
| 3067 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<char>; |
| 3068 | # if _LIBCPP_HAS_WIDE_CHARACTERS |
| 3069 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<wchar_t>; |
| 3070 | # endif |
| 3071 | |
| 3072 | # if _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_WSTRING_CONVERT) |
| 3073 | |
| 3074 | template <class _Codecvt, |
| 3075 | class _Elem = wchar_t, |
| 3076 | class _WideAlloc = allocator<_Elem>, |
| 3077 | class _ByteAlloc = allocator<char> > |
| 3078 | class _LIBCPP_DEPRECATED_IN_CXX17 wstring_convert { |
| 3079 | public: |
| 3080 | typedef basic_string<char, char_traits<char>, _ByteAlloc> byte_string; |
| 3081 | typedef basic_string<_Elem, char_traits<_Elem>, _WideAlloc> wide_string; |
| 3082 | typedef typename _Codecvt::state_type state_type; |
| 3083 | typedef typename wide_string::traits_type::int_type int_type; |
| 3084 | |
| 3085 | private: |
| 3086 | byte_string __byte_err_string_; |
| 3087 | wide_string __wide_err_string_; |
| 3088 | _Codecvt* __cvtptr_; |
| 3089 | state_type __cvtstate_; |
| 3090 | size_t __cvtcount_; |
| 3091 | |
| 3092 | public: |
| 3093 | # ifndef _LIBCPP_CXX03_LANG |
| 3094 | _LIBCPP_HIDE_FROM_ABI wstring_convert() : wstring_convert(new _Codecvt) {} |
| 3095 | _LIBCPP_HIDE_FROM_ABI explicit wstring_convert(_Codecvt* __pcvt); |
| 3096 | # else |
| 3097 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_EXPLICIT_SINCE_CXX14 wstring_convert(_Codecvt* __pcvt = new _Codecvt); |
| 3098 | # endif |
| 3099 | |
| 3100 | _LIBCPP_HIDE_FROM_ABI wstring_convert(_Codecvt* __pcvt, state_type __state); |
| 3101 | _LIBCPP_EXPLICIT_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI |
| 3102 | wstring_convert(const byte_string& __byte_err, const wide_string& __wide_err = wide_string()); |
| 3103 | # ifndef _LIBCPP_CXX03_LANG |
| 3104 | _LIBCPP_HIDE_FROM_ABI wstring_convert(wstring_convert&& __wc); |
| 3105 | # endif |
| 3106 | _LIBCPP_HIDE_FROM_ABI ~wstring_convert(); |
| 3107 | |
| 3108 | wstring_convert(const wstring_convert& __wc) = delete; |
| 3109 | wstring_convert& operator=(const wstring_convert& __wc) = delete; |
| 3110 | |
| 3111 | _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(char __byte) { return from_bytes(&__byte, &__byte + 1); } |
| 3112 | _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(const char* __ptr) { |
| 3113 | return from_bytes(__ptr, __ptr + char_traits<char>::length(s: __ptr)); |
| 3114 | } |
| 3115 | _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(const byte_string& __str) { |
| 3116 | return from_bytes(__str.data(), __str.data() + __str.size()); |
| 3117 | } |
| 3118 | _LIBCPP_HIDE_FROM_ABI wide_string from_bytes(const char* __first, const char* __last); |
| 3119 | |
| 3120 | _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(_Elem __wchar) { return to_bytes(std::addressof(__wchar), std::addressof(__wchar) + 1); } |
| 3121 | _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(const _Elem* __wptr) { |
| 3122 | return to_bytes(__wptr, __wptr + char_traits<_Elem>::length(__wptr)); |
| 3123 | } |
| 3124 | _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(const wide_string& __wstr) { |
| 3125 | return to_bytes(__wstr.data(), __wstr.data() + __wstr.size()); |
| 3126 | } |
| 3127 | _LIBCPP_HIDE_FROM_ABI byte_string to_bytes(const _Elem* __first, const _Elem* __last); |
| 3128 | |
| 3129 | _LIBCPP_HIDE_FROM_ABI size_t converted() const _NOEXCEPT { return __cvtcount_; } |
| 3130 | _LIBCPP_HIDE_FROM_ABI state_type state() const { return __cvtstate_; } |
| 3131 | }; |
| 3132 | |
| 3133 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
| 3134 | template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc> |
| 3135 | inline wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::wstring_convert(_Codecvt* __pcvt) |
| 3136 | : __cvtptr_(__pcvt), __cvtstate_(), __cvtcount_(0) {} |
| 3137 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
| 3138 | |
| 3139 | template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc> |
| 3140 | inline wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::wstring_convert(_Codecvt* __pcvt, state_type __state) |
| 3141 | : __cvtptr_(__pcvt), __cvtstate_(__state), __cvtcount_(0) {} |
| 3142 | |
| 3143 | template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc> |
| 3144 | wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::wstring_convert( |
| 3145 | const byte_string& __byte_err, const wide_string& __wide_err) |
| 3146 | : __byte_err_string_(__byte_err), __wide_err_string_(__wide_err), __cvtstate_(), __cvtcount_(0) { |
| 3147 | __cvtptr_ = new _Codecvt; |
| 3148 | } |
| 3149 | |
| 3150 | # ifndef _LIBCPP_CXX03_LANG |
| 3151 | |
| 3152 | template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc> |
| 3153 | inline wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::wstring_convert(wstring_convert&& __wc) |
| 3154 | : __byte_err_string_(std::move(__wc.__byte_err_string_)), |
| 3155 | __wide_err_string_(std::move(__wc.__wide_err_string_)), |
| 3156 | __cvtptr_(__wc.__cvtptr_), |
| 3157 | __cvtstate_(__wc.__cvtstate_), |
| 3158 | __cvtcount_(__wc.__cvtcount_) { |
| 3159 | __wc.__cvtptr_ = nullptr; |
| 3160 | } |
| 3161 | |
| 3162 | # endif // _LIBCPP_CXX03_LANG |
| 3163 | |
| 3164 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
| 3165 | template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc> |
| 3166 | wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::~wstring_convert() { |
| 3167 | delete __cvtptr_; |
| 3168 | } |
| 3169 | |
| 3170 | template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc> |
| 3171 | typename wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::wide_string |
| 3172 | wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::from_bytes(const char* __frm, const char* __frm_end) { |
| 3173 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
| 3174 | __cvtcount_ = 0; |
| 3175 | if (__cvtptr_ != nullptr) { |
| 3176 | wide_string __ws(2 * (__frm_end - __frm), _Elem()); |
| 3177 | if (__frm != __frm_end) |
| 3178 | __ws.resize(__ws.capacity()); |
| 3179 | codecvt_base::result __r = codecvt_base::ok; |
| 3180 | state_type __st = __cvtstate_; |
| 3181 | if (__frm != __frm_end) { |
| 3182 | _Elem* __to = std::addressof(__ws[0]); |
| 3183 | _Elem* __to_end = __to + __ws.size(); |
| 3184 | const char* __frm_nxt; |
| 3185 | do { |
| 3186 | _Elem* __to_nxt; |
| 3187 | __r = __cvtptr_->in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); |
| 3188 | __cvtcount_ += __frm_nxt - __frm; |
| 3189 | if (__frm_nxt == __frm) { |
| 3190 | __r = codecvt_base::error; |
| 3191 | } else if (__r == codecvt_base::noconv) { |
| 3192 | __ws.resize(__to - std::addressof(__ws[0])); |
| 3193 | // This only gets executed if _Elem is char |
| 3194 | __ws.append((const _Elem*)__frm, (const _Elem*)__frm_end); |
| 3195 | __frm = __frm_nxt; |
| 3196 | __r = codecvt_base::ok; |
| 3197 | } else if (__r == codecvt_base::ok) { |
| 3198 | __ws.resize(__to_nxt - std::addressof(__ws[0])); |
| 3199 | __frm = __frm_nxt; |
| 3200 | } else if (__r == codecvt_base::partial) { |
| 3201 | ptrdiff_t __s = __to_nxt - std::addressof(__ws[0]); |
| 3202 | __ws.resize(2 * __s); |
| 3203 | __to = std::addressof(__ws[0]) + __s; |
| 3204 | __to_end = std::addressof(__ws[0]) + __ws.size(); |
| 3205 | __frm = __frm_nxt; |
| 3206 | } |
| 3207 | } while (__r == codecvt_base::partial && __frm_nxt < __frm_end); |
| 3208 | } |
| 3209 | if (__r == codecvt_base::ok) |
| 3210 | return __ws; |
| 3211 | } |
| 3212 | |
| 3213 | if (__wide_err_string_.empty()) |
| 3214 | std::__throw_range_error(msg: "wstring_convert: from_bytes error" ); |
| 3215 | |
| 3216 | return __wide_err_string_; |
| 3217 | } |
| 3218 | |
| 3219 | template <class _Codecvt, class _Elem, class _WideAlloc, class _ByteAlloc> |
| 3220 | typename wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::byte_string |
| 3221 | wstring_convert<_Codecvt, _Elem, _WideAlloc, _ByteAlloc>::to_bytes(const _Elem* __frm, const _Elem* __frm_end) { |
| 3222 | __cvtcount_ = 0; |
| 3223 | if (__cvtptr_ != nullptr) { |
| 3224 | byte_string __bs(2 * (__frm_end - __frm), char()); |
| 3225 | if (__frm != __frm_end) |
| 3226 | __bs.resize(__bs.capacity()); |
| 3227 | codecvt_base::result __r = codecvt_base::ok; |
| 3228 | state_type __st = __cvtstate_; |
| 3229 | if (__frm != __frm_end) { |
| 3230 | char* __to = std::addressof(__bs[0]); |
| 3231 | char* __to_end = __to + __bs.size(); |
| 3232 | const _Elem* __frm_nxt; |
| 3233 | do { |
| 3234 | char* __to_nxt; |
| 3235 | __r = __cvtptr_->out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); |
| 3236 | __cvtcount_ += __frm_nxt - __frm; |
| 3237 | if (__frm_nxt == __frm) { |
| 3238 | __r = codecvt_base::error; |
| 3239 | } else if (__r == codecvt_base::noconv) { |
| 3240 | __bs.resize(__to - std::addressof(__bs[0])); |
| 3241 | // This only gets executed if _Elem is char |
| 3242 | __bs.append((const char*)__frm, (const char*)__frm_end); |
| 3243 | __frm = __frm_nxt; |
| 3244 | __r = codecvt_base::ok; |
| 3245 | } else if (__r == codecvt_base::ok) { |
| 3246 | __bs.resize(__to_nxt - std::addressof(__bs[0])); |
| 3247 | __frm = __frm_nxt; |
| 3248 | } else if (__r == codecvt_base::partial) { |
| 3249 | ptrdiff_t __s = __to_nxt - std::addressof(__bs[0]); |
| 3250 | __bs.resize(2 * __s); |
| 3251 | __to = std::addressof(__bs[0]) + __s; |
| 3252 | __to_end = std::addressof(__bs[0]) + __bs.size(); |
| 3253 | __frm = __frm_nxt; |
| 3254 | } |
| 3255 | } while (__r == codecvt_base::partial && __frm_nxt < __frm_end); |
| 3256 | } |
| 3257 | if (__r == codecvt_base::ok) { |
| 3258 | size_t __s = __bs.size(); |
| 3259 | __bs.resize(__bs.capacity()); |
| 3260 | char* __to = std::addressof(__bs[0]) + __s; |
| 3261 | char* __to_end = __to + __bs.size(); |
| 3262 | do { |
| 3263 | char* __to_nxt; |
| 3264 | __r = __cvtptr_->unshift(__st, __to, __to_end, __to_nxt); |
| 3265 | if (__r == codecvt_base::noconv) { |
| 3266 | __bs.resize(__to - std::addressof(__bs[0])); |
| 3267 | __r = codecvt_base::ok; |
| 3268 | } else if (__r == codecvt_base::ok) { |
| 3269 | __bs.resize(__to_nxt - std::addressof(__bs[0])); |
| 3270 | } else if (__r == codecvt_base::partial) { |
| 3271 | ptrdiff_t __sp = __to_nxt - std::addressof(__bs[0]); |
| 3272 | __bs.resize(2 * __sp); |
| 3273 | __to = std::addressof(__bs[0]) + __sp; |
| 3274 | __to_end = std::addressof(__bs[0]) + __bs.size(); |
| 3275 | } |
| 3276 | } while (__r == codecvt_base::partial); |
| 3277 | if (__r == codecvt_base::ok) |
| 3278 | return __bs; |
| 3279 | } |
| 3280 | } |
| 3281 | |
| 3282 | if (__byte_err_string_.empty()) |
| 3283 | std::__throw_range_error(msg: "wstring_convert: to_bytes error" ); |
| 3284 | |
| 3285 | return __byte_err_string_; |
| 3286 | } |
| 3287 | |
| 3288 | template <class _Codecvt, class _Elem = wchar_t, class _Tr = char_traits<_Elem> > |
| 3289 | class _LIBCPP_DEPRECATED_IN_CXX17 wbuffer_convert : public basic_streambuf<_Elem, _Tr> { |
| 3290 | public: |
| 3291 | // types: |
| 3292 | typedef _Elem char_type; |
| 3293 | typedef _Tr traits_type; |
| 3294 | typedef typename traits_type::int_type int_type; |
| 3295 | typedef typename traits_type::pos_type pos_type; |
| 3296 | typedef typename traits_type::off_type off_type; |
| 3297 | typedef typename _Codecvt::state_type state_type; |
| 3298 | |
| 3299 | private: |
| 3300 | char* __extbuf_; |
| 3301 | const char* __extbufnext_; |
| 3302 | const char* __extbufend_; |
| 3303 | char __extbuf_min_[8]; |
| 3304 | size_t __ebs_; |
| 3305 | char_type* __intbuf_; |
| 3306 | size_t __ibs_; |
| 3307 | streambuf* __bufptr_; |
| 3308 | _Codecvt* __cv_; |
| 3309 | state_type __st_; |
| 3310 | ios_base::openmode __cm_; |
| 3311 | bool __owns_eb_; |
| 3312 | bool __owns_ib_; |
| 3313 | bool __always_noconv_; |
| 3314 | |
| 3315 | public: |
| 3316 | # ifndef _LIBCPP_CXX03_LANG |
| 3317 | _LIBCPP_HIDE_FROM_ABI wbuffer_convert() : wbuffer_convert(nullptr) {} |
| 3318 | explicit _LIBCPP_HIDE_FROM_ABI |
| 3319 | wbuffer_convert(streambuf* __bytebuf, _Codecvt* __pcvt = new _Codecvt, state_type __state = state_type()); |
| 3320 | # else |
| 3321 | _LIBCPP_EXPLICIT_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI |
| 3322 | wbuffer_convert(streambuf* __bytebuf = nullptr, _Codecvt* __pcvt = new _Codecvt, state_type __state = state_type()); |
| 3323 | # endif |
| 3324 | |
| 3325 | _LIBCPP_HIDE_FROM_ABI ~wbuffer_convert(); |
| 3326 | |
| 3327 | _LIBCPP_HIDE_FROM_ABI streambuf* rdbuf() const { return __bufptr_; } |
| 3328 | _LIBCPP_HIDE_FROM_ABI streambuf* rdbuf(streambuf* __bytebuf) { |
| 3329 | streambuf* __r = __bufptr_; |
| 3330 | __bufptr_ = __bytebuf; |
| 3331 | return __r; |
| 3332 | } |
| 3333 | |
| 3334 | wbuffer_convert(const wbuffer_convert&) = delete; |
| 3335 | wbuffer_convert& operator=(const wbuffer_convert&) = delete; |
| 3336 | |
| 3337 | _LIBCPP_HIDE_FROM_ABI state_type state() const { return __st_; } |
| 3338 | |
| 3339 | protected: |
| 3340 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual int_type underflow(); |
| 3341 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual int_type pbackfail(int_type __c = traits_type::eof()); |
| 3342 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual int_type overflow(int_type __c = traits_type::eof()); |
| 3343 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual basic_streambuf<char_type, traits_type>* setbuf(char_type* __s, streamsize __n); |
| 3344 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual pos_type |
| 3345 | seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __wch = ios_base::in | ios_base::out); |
| 3346 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual pos_type |
| 3347 | seekpos(pos_type __sp, ios_base::openmode __wch = ios_base::in | ios_base::out); |
| 3348 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual int sync(); |
| 3349 | |
| 3350 | private: |
| 3351 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL bool __read_mode(); |
| 3352 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL void __write_mode(); |
| 3353 | _LIBCPP_HIDE_FROM_ABI_VIRTUAL wbuffer_convert* __close(); |
| 3354 | }; |
| 3355 | |
| 3356 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
| 3357 | template <class _Codecvt, class _Elem, class _Tr> |
| 3358 | wbuffer_convert<_Codecvt, _Elem, _Tr>::wbuffer_convert(streambuf* __bytebuf, _Codecvt* __pcvt, state_type __state) |
| 3359 | : __extbuf_(nullptr), |
| 3360 | __extbufnext_(nullptr), |
| 3361 | __extbufend_(nullptr), |
| 3362 | __ebs_(0), |
| 3363 | __intbuf_(0), |
| 3364 | __ibs_(0), |
| 3365 | __bufptr_(__bytebuf), |
| 3366 | __cv_(__pcvt), |
| 3367 | __st_(__state), |
| 3368 | __cm_(0), |
| 3369 | __owns_eb_(false), |
| 3370 | __owns_ib_(false), |
| 3371 | __always_noconv_(__cv_ ? __cv_->always_noconv() : false) { |
| 3372 | setbuf(s: 0, n: 4096); |
| 3373 | } |
| 3374 | |
| 3375 | template <class _Codecvt, class _Elem, class _Tr> |
| 3376 | wbuffer_convert<_Codecvt, _Elem, _Tr>::~wbuffer_convert() { |
| 3377 | __close(); |
| 3378 | delete __cv_; |
| 3379 | if (__owns_eb_) |
| 3380 | delete[] __extbuf_; |
| 3381 | if (__owns_ib_) |
| 3382 | delete[] __intbuf_; |
| 3383 | } |
| 3384 | |
| 3385 | template <class _Codecvt, class _Elem, class _Tr> |
| 3386 | typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type wbuffer_convert<_Codecvt, _Elem, _Tr>::underflow() { |
| 3387 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
| 3388 | if (__cv_ == 0 || __bufptr_ == nullptr) |
| 3389 | return traits_type::eof(); |
| 3390 | bool __initial = __read_mode(); |
| 3391 | char_type __1buf; |
| 3392 | if (this->gptr() == 0) |
| 3393 | this->setg(std::addressof(__1buf), std::addressof(__1buf) + 1, std::addressof(__1buf) + 1); |
| 3394 | const size_t __unget_sz = __initial ? 0 : std::min<size_t>((this->egptr() - this->eback()) / 2, 4); |
| 3395 | int_type __c = traits_type::eof(); |
| 3396 | if (this->gptr() == this->egptr()) { |
| 3397 | std::memmove(dest: this->eback(), src: this->egptr() - __unget_sz, n: __unget_sz * sizeof(char_type)); |
| 3398 | if (__always_noconv_) { |
| 3399 | streamsize __nmemb = static_cast<streamsize>(this->egptr() - this->eback() - __unget_sz); |
| 3400 | __nmemb = __bufptr_->sgetn(s: (char*)this->eback() + __unget_sz, n: __nmemb); |
| 3401 | if (__nmemb != 0) { |
| 3402 | this->setg(this->eback(), this->eback() + __unget_sz, this->eback() + __unget_sz + __nmemb); |
| 3403 | __c = *this->gptr(); |
| 3404 | } |
| 3405 | } else { |
| 3406 | if (__extbufend_ != __extbufnext_) { |
| 3407 | _LIBCPP_ASSERT_NON_NULL(__extbufnext_ != nullptr, "underflow moving from nullptr" ); |
| 3408 | _LIBCPP_ASSERT_NON_NULL(__extbuf_ != nullptr, "underflow moving into nullptr" ); |
| 3409 | std::memmove(dest: __extbuf_, src: __extbufnext_, n: __extbufend_ - __extbufnext_); |
| 3410 | } |
| 3411 | __extbufnext_ = __extbuf_ + (__extbufend_ - __extbufnext_); |
| 3412 | __extbufend_ = __extbuf_ + (__extbuf_ == __extbuf_min_ ? sizeof(__extbuf_min_) : __ebs_); |
| 3413 | streamsize __nmemb = std::min(a: static_cast<streamsize>(this->egptr() - this->eback() - __unget_sz), |
| 3414 | b: static_cast<streamsize>(__extbufend_ - __extbufnext_)); |
| 3415 | codecvt_base::result __r; |
| 3416 | // FIXME: Do we ever need to restore the state here? |
| 3417 | // state_type __svs = __st_; |
| 3418 | streamsize __nr = __bufptr_->sgetn(s: const_cast<char*>(__extbufnext_), n: __nmemb); |
| 3419 | if (__nr != 0) { |
| 3420 | __extbufend_ = __extbufnext_ + __nr; |
| 3421 | char_type* __inext; |
| 3422 | __r = __cv_->in( |
| 3423 | __st_, __extbuf_, __extbufend_, __extbufnext_, this->eback() + __unget_sz, this->egptr(), __inext); |
| 3424 | if (__r == codecvt_base::noconv) { |
| 3425 | this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, (char_type*)const_cast<char*>(__extbufend_)); |
| 3426 | __c = *this->gptr(); |
| 3427 | } else if (__inext != this->eback() + __unget_sz) { |
| 3428 | this->setg(this->eback(), this->eback() + __unget_sz, __inext); |
| 3429 | __c = *this->gptr(); |
| 3430 | } |
| 3431 | } |
| 3432 | } |
| 3433 | } else |
| 3434 | __c = *this->gptr(); |
| 3435 | if (this->eback() == std::addressof(__1buf)) |
| 3436 | this->setg(0, 0, 0); |
| 3437 | return __c; |
| 3438 | } |
| 3439 | |
| 3440 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
| 3441 | template <class _Codecvt, class _Elem, class _Tr> |
| 3442 | typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type |
| 3443 | wbuffer_convert<_Codecvt, _Elem, _Tr>::pbackfail(int_type __c) { |
| 3444 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
| 3445 | if (__cv_ != 0 && __bufptr_ && this->eback() < this->gptr()) { |
| 3446 | if (traits_type::eq_int_type(__c, traits_type::eof())) { |
| 3447 | this->gbump(-1); |
| 3448 | return traits_type::not_eof(__c); |
| 3449 | } |
| 3450 | if (traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) { |
| 3451 | this->gbump(-1); |
| 3452 | *this->gptr() = traits_type::to_char_type(__c); |
| 3453 | return __c; |
| 3454 | } |
| 3455 | } |
| 3456 | return traits_type::eof(); |
| 3457 | } |
| 3458 | |
| 3459 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
| 3460 | template <class _Codecvt, class _Elem, class _Tr> |
| 3461 | typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type wbuffer_convert<_Codecvt, _Elem, _Tr>::overflow(int_type __c) { |
| 3462 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
| 3463 | if (__cv_ == 0 || !__bufptr_) |
| 3464 | return traits_type::eof(); |
| 3465 | __write_mode(); |
| 3466 | char_type __1buf; |
| 3467 | char_type* __pb_save = this->pbase(); |
| 3468 | char_type* __epb_save = this->epptr(); |
| 3469 | if (!traits_type::eq_int_type(__c, traits_type::eof())) { |
| 3470 | if (this->pptr() == 0) |
| 3471 | this->setp(std::addressof(__1buf), std::addressof(__1buf) + 1); |
| 3472 | *this->pptr() = traits_type::to_char_type(__c); |
| 3473 | this->pbump(1); |
| 3474 | } |
| 3475 | if (this->pptr() != this->pbase()) { |
| 3476 | if (__always_noconv_) { |
| 3477 | streamsize __nmemb = static_cast<streamsize>(this->pptr() - this->pbase()); |
| 3478 | if (__bufptr_->sputn(s: (const char*)this->pbase(), n: __nmemb) != __nmemb) |
| 3479 | return traits_type::eof(); |
| 3480 | } else { |
| 3481 | char* __extbe = __extbuf_; |
| 3482 | codecvt_base::result __r; |
| 3483 | do { |
| 3484 | const char_type* __e; |
| 3485 | __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e, __extbuf_, __extbuf_ + __ebs_, __extbe); |
| 3486 | if (__e == this->pbase()) |
| 3487 | return traits_type::eof(); |
| 3488 | if (__r == codecvt_base::noconv) { |
| 3489 | streamsize __nmemb = static_cast<size_t>(this->pptr() - this->pbase()); |
| 3490 | if (__bufptr_->sputn(s: (const char*)this->pbase(), n: __nmemb) != __nmemb) |
| 3491 | return traits_type::eof(); |
| 3492 | } else if (__r == codecvt_base::ok || __r == codecvt_base::partial) { |
| 3493 | streamsize __nmemb = static_cast<size_t>(__extbe - __extbuf_); |
| 3494 | if (__bufptr_->sputn(s: __extbuf_, n: __nmemb) != __nmemb) |
| 3495 | return traits_type::eof(); |
| 3496 | if (__r == codecvt_base::partial) { |
| 3497 | this->setp(const_cast<char_type*>(__e), this->pptr()); |
| 3498 | this->__pbump(this->epptr() - this->pbase()); |
| 3499 | } |
| 3500 | } else |
| 3501 | return traits_type::eof(); |
| 3502 | } while (__r == codecvt_base::partial); |
| 3503 | } |
| 3504 | this->setp(__pb_save, __epb_save); |
| 3505 | } |
| 3506 | return traits_type::not_eof(__c); |
| 3507 | } |
| 3508 | |
| 3509 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
| 3510 | template <class _Codecvt, class _Elem, class _Tr> |
| 3511 | basic_streambuf<_Elem, _Tr>* wbuffer_convert<_Codecvt, _Elem, _Tr>::setbuf(char_type* __s, streamsize __n) { |
| 3512 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
| 3513 | this->setg(0, 0, 0); |
| 3514 | this->setp(0, 0); |
| 3515 | if (__owns_eb_) |
| 3516 | delete[] __extbuf_; |
| 3517 | if (__owns_ib_) |
| 3518 | delete[] __intbuf_; |
| 3519 | __ebs_ = __n; |
| 3520 | if (__ebs_ > sizeof(__extbuf_min_)) { |
| 3521 | if (__always_noconv_ && __s) { |
| 3522 | __extbuf_ = (char*)__s; |
| 3523 | __owns_eb_ = false; |
| 3524 | } else { |
| 3525 | __extbuf_ = new char[__ebs_]; |
| 3526 | __owns_eb_ = true; |
| 3527 | } |
| 3528 | } else { |
| 3529 | __extbuf_ = __extbuf_min_; |
| 3530 | __ebs_ = sizeof(__extbuf_min_); |
| 3531 | __owns_eb_ = false; |
| 3532 | } |
| 3533 | if (!__always_noconv_) { |
| 3534 | __ibs_ = max<streamsize>(a: __n, b: sizeof(__extbuf_min_)); |
| 3535 | if (__s && __ibs_ >= sizeof(__extbuf_min_)) { |
| 3536 | __intbuf_ = __s; |
| 3537 | __owns_ib_ = false; |
| 3538 | } else { |
| 3539 | __intbuf_ = new char_type[__ibs_]; |
| 3540 | __owns_ib_ = true; |
| 3541 | } |
| 3542 | } else { |
| 3543 | __ibs_ = 0; |
| 3544 | __intbuf_ = 0; |
| 3545 | __owns_ib_ = false; |
| 3546 | } |
| 3547 | return this; |
| 3548 | } |
| 3549 | |
| 3550 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
| 3551 | template <class _Codecvt, class _Elem, class _Tr> |
| 3552 | typename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type |
| 3553 | wbuffer_convert<_Codecvt, _Elem, _Tr>::seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __om) { |
| 3554 | int __width = __cv_->encoding(); |
| 3555 | if (__cv_ == 0 || !__bufptr_ || (__width <= 0 && __off != 0) || sync()) |
| 3556 | return pos_type(off_type(-1)); |
| 3557 | // __width > 0 || __off == 0, now check __way |
| 3558 | if (__way != ios_base::beg && __way != ios_base::cur && __way != ios_base::end) |
| 3559 | return pos_type(off_type(-1)); |
| 3560 | pos_type __r = __bufptr_->pubseekoff(off: __width * __off, __way, which: __om); |
| 3561 | __r.state(__st_); |
| 3562 | return __r; |
| 3563 | } |
| 3564 | |
| 3565 | template <class _Codecvt, class _Elem, class _Tr> |
| 3566 | typename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type |
| 3567 | wbuffer_convert<_Codecvt, _Elem, _Tr>::seekpos(pos_type __sp, ios_base::openmode __wch) { |
| 3568 | if (__cv_ == 0 || !__bufptr_ || sync()) |
| 3569 | return pos_type(off_type(-1)); |
| 3570 | if (__bufptr_->pubseekpos(__sp, which: __wch) == pos_type(off_type(-1))) |
| 3571 | return pos_type(off_type(-1)); |
| 3572 | return __sp; |
| 3573 | } |
| 3574 | |
| 3575 | template <class _Codecvt, class _Elem, class _Tr> |
| 3576 | int wbuffer_convert<_Codecvt, _Elem, _Tr>::sync() { |
| 3577 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
| 3578 | if (__cv_ == 0 || !__bufptr_) |
| 3579 | return 0; |
| 3580 | if (__cm_ & ios_base::out) { |
| 3581 | if (this->pptr() != this->pbase()) |
| 3582 | if (overflow() == traits_type::eof()) |
| 3583 | return -1; |
| 3584 | codecvt_base::result __r; |
| 3585 | do { |
| 3586 | char* __extbe; |
| 3587 | __r = __cv_->unshift(__st_, __extbuf_, __extbuf_ + __ebs_, __extbe); |
| 3588 | streamsize __nmemb = static_cast<streamsize>(__extbe - __extbuf_); |
| 3589 | if (__bufptr_->sputn(s: __extbuf_, n: __nmemb) != __nmemb) |
| 3590 | return -1; |
| 3591 | } while (__r == codecvt_base::partial); |
| 3592 | if (__r == codecvt_base::error) |
| 3593 | return -1; |
| 3594 | if (__bufptr_->pubsync()) |
| 3595 | return -1; |
| 3596 | } else if (__cm_ & ios_base::in) { |
| 3597 | off_type __c; |
| 3598 | if (__always_noconv_) |
| 3599 | __c = this->egptr() - this->gptr(); |
| 3600 | else { |
| 3601 | int __width = __cv_->encoding(); |
| 3602 | __c = __extbufend_ - __extbufnext_; |
| 3603 | if (__width > 0) |
| 3604 | __c += __width * (this->egptr() - this->gptr()); |
| 3605 | else { |
| 3606 | if (this->gptr() != this->egptr()) { |
| 3607 | std::reverse(this->gptr(), this->egptr()); |
| 3608 | codecvt_base::result __r; |
| 3609 | const char_type* __e = this->gptr(); |
| 3610 | char* __extbe; |
| 3611 | do { |
| 3612 | __r = __cv_->out(__st_, __e, this->egptr(), __e, __extbuf_, __extbuf_ + __ebs_, __extbe); |
| 3613 | switch (__r) { |
| 3614 | case codecvt_base::noconv: |
| 3615 | __c += this->egptr() - this->gptr(); |
| 3616 | break; |
| 3617 | case codecvt_base::ok: |
| 3618 | case codecvt_base::partial: |
| 3619 | __c += __extbe - __extbuf_; |
| 3620 | break; |
| 3621 | default: |
| 3622 | return -1; |
| 3623 | } |
| 3624 | } while (__r == codecvt_base::partial); |
| 3625 | } |
| 3626 | } |
| 3627 | } |
| 3628 | if (__bufptr_->pubseekoff(off: -__c, way: ios_base::cur, which: __cm_) == pos_type(off_type(-1))) |
| 3629 | return -1; |
| 3630 | this->setg(0, 0, 0); |
| 3631 | __cm_ = 0; |
| 3632 | } |
| 3633 | return 0; |
| 3634 | } |
| 3635 | |
| 3636 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
| 3637 | template <class _Codecvt, class _Elem, class _Tr> |
| 3638 | bool wbuffer_convert<_Codecvt, _Elem, _Tr>::__read_mode() { |
| 3639 | if (!(__cm_ & ios_base::in)) { |
| 3640 | this->setp(0, 0); |
| 3641 | if (__always_noconv_) |
| 3642 | this->setg((char_type*)__extbuf_, (char_type*)__extbuf_ + __ebs_, (char_type*)__extbuf_ + __ebs_); |
| 3643 | else |
| 3644 | this->setg(__intbuf_, __intbuf_ + __ibs_, __intbuf_ + __ibs_); |
| 3645 | __cm_ = ios_base::in; |
| 3646 | return true; |
| 3647 | } |
| 3648 | return false; |
| 3649 | } |
| 3650 | |
| 3651 | template <class _Codecvt, class _Elem, class _Tr> |
| 3652 | void wbuffer_convert<_Codecvt, _Elem, _Tr>::__write_mode() { |
| 3653 | if (!(__cm_ & ios_base::out)) { |
| 3654 | this->setg(0, 0, 0); |
| 3655 | if (__ebs_ > sizeof(__extbuf_min_)) { |
| 3656 | if (__always_noconv_) |
| 3657 | this->setp((char_type*)__extbuf_, (char_type*)__extbuf_ + (__ebs_ - 1)); |
| 3658 | else |
| 3659 | this->setp(__intbuf_, __intbuf_ + (__ibs_ - 1)); |
| 3660 | } else |
| 3661 | this->setp(0, 0); |
| 3662 | __cm_ = ios_base::out; |
| 3663 | } |
| 3664 | } |
| 3665 | |
| 3666 | template <class _Codecvt, class _Elem, class _Tr> |
| 3667 | wbuffer_convert<_Codecvt, _Elem, _Tr>* wbuffer_convert<_Codecvt, _Elem, _Tr>::__close() { |
| 3668 | wbuffer_convert* __rt = nullptr; |
| 3669 | if (__cv_ != nullptr && __bufptr_ != nullptr) { |
| 3670 | __rt = this; |
| 3671 | if ((__cm_ & ios_base::out) && sync()) |
| 3672 | __rt = nullptr; |
| 3673 | } |
| 3674 | return __rt; |
| 3675 | } |
| 3676 | |
| 3677 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
| 3678 | |
| 3679 | # endif // _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_WSTRING_CONVERT) |
| 3680 | |
| 3681 | _LIBCPP_END_NAMESPACE_STD |
| 3682 | |
| 3683 | _LIBCPP_POP_MACROS |
| 3684 | |
| 3685 | // NOLINTEND(libcpp-robust-against-adl) |
| 3686 | |
| 3687 | # endif // _LIBCPP_HAS_LOCALIZATION |
| 3688 | |
| 3689 | # if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 |
| 3690 | # include <atomic> |
| 3691 | # include <concepts> |
| 3692 | # include <cstdarg> |
| 3693 | # include <iterator> |
| 3694 | # include <mutex> |
| 3695 | # include <optional> |
| 3696 | # include <stdexcept> |
| 3697 | # include <type_traits> |
| 3698 | # include <typeinfo> |
| 3699 | # endif |
| 3700 | #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
| 3701 | |
| 3702 | #endif // _LIBCPP_LOCALE |
| 3703 | |