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