locale revision 242945
1227825Stheraven// -*- C++ -*- 2227825Stheraven//===-------------------------- locale ------------------------------------===// 3227825Stheraven// 4227825Stheraven// The LLVM Compiler Infrastructure 5227825Stheraven// 6227825Stheraven// This file is dual licensed under the MIT and the University of Illinois Open 7227825Stheraven// Source Licenses. See LICENSE.TXT for details. 8227825Stheraven// 9227825Stheraven//===----------------------------------------------------------------------===// 10227825Stheraven 11227825Stheraven#ifndef _LIBCPP_LOCALE 12227825Stheraven#define _LIBCPP_LOCALE 13227825Stheraven 14227825Stheraven/* 15227825Stheraven locale synopsis 16227825Stheraven 17227825Stheravennamespace std 18227825Stheraven{ 19227825Stheraven 20227825Stheravenclass locale 21227825Stheraven{ 22227825Stheravenpublic: 23227825Stheraven // types: 24227825Stheraven class facet; 25227825Stheraven class id; 26227825Stheraven 27227825Stheraven typedef int category; 28227825Stheraven static const category // values assigned here are for exposition only 29227825Stheraven none = 0x000, 30227825Stheraven collate = 0x010, 31227825Stheraven ctype = 0x020, 32227825Stheraven monetary = 0x040, 33227825Stheraven numeric = 0x080, 34227825Stheraven time = 0x100, 35227825Stheraven messages = 0x200, 36227825Stheraven all = collate | ctype | monetary | numeric | time | messages; 37227825Stheraven 38227825Stheraven // construct/copy/destroy: 39227825Stheraven locale() noexcept; 40227825Stheraven locale(const locale& other) noexcept; 41227825Stheraven explicit locale(const char* std_name); 42227825Stheraven explicit locale(const string& std_name); 43227825Stheraven locale(const locale& other, const char* std_name, category); 44227825Stheraven locale(const locale& other, const string& std_name, category); 45227825Stheraven template <class Facet> locale(const locale& other, Facet* f); 46227825Stheraven locale(const locale& other, const locale& one, category); 47227825Stheraven 48227825Stheraven ~locale(); // not virtual 49227825Stheraven 50227825Stheraven const locale& operator=(const locale& other) noexcept; 51227825Stheraven 52227825Stheraven template <class Facet> locale combine(const locale& other) const; 53227825Stheraven 54227825Stheraven // locale operations: 55227825Stheraven basic_string<char> name() const; 56227825Stheraven bool operator==(const locale& other) const; 57227825Stheraven bool operator!=(const locale& other) const; 58227825Stheraven template <class charT, class Traits, class Allocator> 59227825Stheraven bool operator()(const basic_string<charT,Traits,Allocator>& s1, 60227825Stheraven const basic_string<charT,Traits,Allocator>& s2) const; 61227825Stheraven 62227825Stheraven // global locale objects: 63227825Stheraven static locale global(const locale&); 64227825Stheraven static const locale& classic(); 65227825Stheraven}; 66227825Stheraven 67227825Stheraventemplate <class Facet> const Facet& use_facet(const locale&); 68227825Stheraventemplate <class Facet> bool has_facet(const locale&) noexcept; 69227825Stheraven 70227825Stheraven// 22.3.3, convenience interfaces: 71227825Stheraventemplate <class charT> bool isspace (charT c, const locale& loc); 72227825Stheraventemplate <class charT> bool isprint (charT c, const locale& loc); 73227825Stheraventemplate <class charT> bool iscntrl (charT c, const locale& loc); 74227825Stheraventemplate <class charT> bool isupper (charT c, const locale& loc); 75227825Stheraventemplate <class charT> bool islower (charT c, const locale& loc); 76227825Stheraventemplate <class charT> bool isalpha (charT c, const locale& loc); 77227825Stheraventemplate <class charT> bool isdigit (charT c, const locale& loc); 78227825Stheraventemplate <class charT> bool ispunct (charT c, const locale& loc); 79227825Stheraventemplate <class charT> bool isxdigit(charT c, const locale& loc); 80227825Stheraventemplate <class charT> bool isalnum (charT c, const locale& loc); 81227825Stheraventemplate <class charT> bool isgraph (charT c, const locale& loc); 82227825Stheraventemplate <class charT> charT toupper(charT c, const locale& loc); 83227825Stheraventemplate <class charT> charT tolower(charT c, const locale& loc); 84227825Stheraven 85227825Stheraventemplate<class Codecvt, class Elem = wchar_t, 86227825Stheraven class Wide_alloc = allocator<Elem>, 87227825Stheraven class Byte_alloc = allocator<char>> 88227825Stheravenclass wstring_convert 89227825Stheraven{ 90227825Stheravenpublic: 91227825Stheraven typedef basic_string<char, char_traits<char>, Byte_alloc> byte_string; 92227825Stheraven typedef basic_string<Elem, char_traits<Elem>, Wide_alloc> wide_string; 93227825Stheraven typedef typename Codecvt::state_type state_type; 94227825Stheraven typedef typename wide_string::traits_type::int_type int_type; 95227825Stheraven 96227825Stheraven wstring_convert(Codecvt* pcvt = new Codecvt); 97227825Stheraven wstring_convert(Codecvt* pcvt, state_type state); 98227825Stheraven wstring_convert(const byte_string& byte_err, 99227825Stheraven const wide_string& wide_err = wide_string()); 100227825Stheraven ~wstring_convert(); 101227825Stheraven 102227825Stheraven wide_string from_bytes(char byte); 103227825Stheraven wide_string from_bytes(const char* ptr); 104227825Stheraven wide_string from_bytes(const byte_string& str); 105227825Stheraven wide_string from_bytes(const char* first, const char* last); 106227825Stheraven 107227825Stheraven byte_string to_bytes(Elem wchar); 108227825Stheraven byte_string to_bytes(const Elem* wptr); 109227825Stheraven byte_string to_bytes(const wide_string& wstr); 110227825Stheraven byte_string to_bytes(const Elem* first, const Elem* last); 111227825Stheraven 112227825Stheraven size_t converted() const; 113227825Stheraven state_type state() const; 114227825Stheraven}; 115227825Stheraven 116227825Stheraventemplate <class Codecvt, class Elem = wchar_t, class Tr = char_traits<Elem>> 117227825Stheravenclass wbuffer_convert 118227825Stheraven : public basic_streambuf<Elem, Tr> 119227825Stheraven{ 120227825Stheravenpublic: 121227825Stheraven typedef typename Tr::state_type state_type; 122227825Stheraven 123227825Stheraven wbuffer_convert(streambuf* bytebuf = 0, Codecvt* pcvt = new Codecvt, 124227825Stheraven state_type state = state_type()); 125227825Stheraven 126227825Stheraven streambuf* rdbuf() const; 127227825Stheraven streambuf* rdbuf(streambuf* bytebuf); 128227825Stheraven 129227825Stheraven state_type state() const; 130227825Stheraven}; 131227825Stheraven 132227825Stheraven// 22.4.1 and 22.4.1.3, ctype: 133227825Stheravenclass ctype_base; 134227825Stheraventemplate <class charT> class ctype; 135227825Stheraventemplate <> class ctype<char>; // specialization 136227825Stheraventemplate <class charT> class ctype_byname; 137227825Stheraventemplate <> class ctype_byname<char>; // specialization 138227825Stheraven 139227825Stheravenclass codecvt_base; 140227825Stheraventemplate <class internT, class externT, class stateT> class codecvt; 141227825Stheraventemplate <class internT, class externT, class stateT> class codecvt_byname; 142227825Stheraven 143227825Stheraven// 22.4.2 and 22.4.3, numeric: 144227825Stheraventemplate <class charT, class InputIterator> class num_get; 145227825Stheraventemplate <class charT, class OutputIterator> class num_put; 146227825Stheraventemplate <class charT> class numpunct; 147227825Stheraventemplate <class charT> class numpunct_byname; 148227825Stheraven 149227825Stheraven// 22.4.4, col lation: 150227825Stheraventemplate <class charT> class collate; 151227825Stheraventemplate <class charT> class collate_byname; 152227825Stheraven 153227825Stheraven// 22.4.5, date and time: 154227825Stheravenclass time_base; 155227825Stheraventemplate <class charT, class InputIterator> class time_get; 156227825Stheraventemplate <class charT, class InputIterator> class time_get_byname; 157227825Stheraventemplate <class charT, class OutputIterator> class time_put; 158227825Stheraventemplate <class charT, class OutputIterator> class time_put_byname; 159227825Stheraven 160227825Stheraven// 22.4.6, money: 161227825Stheravenclass money_base; 162227825Stheraventemplate <class charT, class InputIterator> class money_get; 163227825Stheraventemplate <class charT, class OutputIterator> class money_put; 164227825Stheraventemplate <class charT, bool Intl> class moneypunct; 165227825Stheraventemplate <class charT, bool Intl> class moneypunct_byname; 166227825Stheraven 167227825Stheraven// 22.4.7, message retrieval: 168227825Stheravenclass messages_base; 169227825Stheraventemplate <class charT> class messages; 170227825Stheraventemplate <class charT> class messages_byname; 171227825Stheraven 172227825Stheraven} // std 173227825Stheraven 174227825Stheraven*/ 175227825Stheraven 176227825Stheraven#include <__config> 177227825Stheraven#include <__locale> 178227825Stheraven#include <algorithm> 179227825Stheraven#include <memory> 180227825Stheraven#include <ios> 181227825Stheraven#include <streambuf> 182227825Stheraven#include <iterator> 183227825Stheraven#include <limits> 184227825Stheraven#if !__APPLE__ 185227825Stheraven#include <cstdarg> 186227825Stheraven#endif 187227825Stheraven#include <cstdlib> 188227825Stheraven#include <ctime> 189227825Stheraven#if _WIN32 190227825Stheraven#include <support/win32/locale_win32.h> 191227825Stheraven#else // _WIN32 192227825Stheraven#include <nl_types.h> 193227825Stheraven#endif // !_WIN32 194227825Stheraven 195232950Stheraven#include <__undef_min_max> 196232950Stheraven 197227825Stheraven#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 198227825Stheraven#pragma GCC system_header 199227825Stheraven#endif 200227825Stheraven 201227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD 202227825Stheraven 203227825Stheraven#if __APPLE__ || __FreeBSD__ 204227825Stheraven# define _LIBCPP_GET_C_LOCALE 0 205227825Stheraven#else 206227825Stheraven# define _LIBCPP_GET_C_LOCALE __cloc() 207227825Stheraven // Get the C locale object 208227825Stheraven locale_t __cloc(); 209227825Stheraven#define __cloc_defined 210227825Stheraven#endif 211227825Stheraven 212227825Stheraventypedef _VSTD::remove_pointer<locale_t>::type __locale_struct; 213227825Stheraventypedef _VSTD::unique_ptr<__locale_struct, decltype(&freelocale)> __locale_unique_ptr; 214232950Stheraven#ifndef _LIBCPP_LOCALE__L_EXTENSIONS 215227825Stheraventypedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii; 216232950Stheraven#endif 217227825Stheraven 218227825Stheraven// OSX has nice foo_l() functions that let you turn off use of the global 219227825Stheraven// locale. Linux, not so much. The following functions avoid the locale when 220227825Stheraven// that's possible and otherwise do the wrong thing. FIXME. 221227825Stheraven#ifdef __linux__ 222227825Stheraven 223227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 224227825Stheravendecltype(MB_CUR_MAX_L(_VSTD::declval<locale_t>())) 225227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 226227825Stheraven__mb_cur_max_l(locale_t __l) 227227825Stheraven{ 228227825Stheraven return MB_CUR_MAX_L(__l); 229227825Stheraven} 230227825Stheraven#else // _LIBCPP_LOCALE__L_EXTENSIONS 231227825Stheraven_LIBCPP_ALWAYS_INLINE inline 232227825Stheravendecltype(MB_CUR_MAX) __mb_cur_max_l(locale_t __l) 233227825Stheraven{ 234227825Stheraven __locale_raii __current(uselocale(__l), uselocale); 235227825Stheraven return MB_CUR_MAX; 236227825Stheraven} 237227825Stheraven#endif // _LIBCPP_LOCALE__L_EXTENSIONS 238227825Stheraven 239227825Stheraven_LIBCPP_ALWAYS_INLINE inline 240227825Stheravenwint_t __btowc_l(int __c, locale_t __l) 241227825Stheraven{ 242227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 243227825Stheraven return btowc_l(__c, __l); 244227825Stheraven#else 245227825Stheraven __locale_raii __current(uselocale(__l), uselocale); 246227825Stheraven return btowc(__c); 247227825Stheraven#endif 248227825Stheraven} 249227825Stheraven 250227825Stheraven_LIBCPP_ALWAYS_INLINE inline 251227825Stheravenint __wctob_l(wint_t __c, locale_t __l) 252227825Stheraven{ 253227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 254227825Stheraven return wctob_l(__c, __l); 255227825Stheraven#else 256227825Stheraven __locale_raii __current(uselocale(__l), uselocale); 257227825Stheraven return wctob(__c); 258227825Stheraven#endif 259227825Stheraven} 260227825Stheraven 261227825Stheraven_LIBCPP_ALWAYS_INLINE inline 262227825Stheravensize_t __wcsnrtombs_l(char *__dest, const wchar_t **__src, size_t __nwc, 263227825Stheraven size_t __len, mbstate_t *__ps, locale_t __l) 264227825Stheraven{ 265227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 266227825Stheraven return wcsnrtombs_l(__dest, __src, __nwc, __len, __ps, __l); 267227825Stheraven#else 268227825Stheraven __locale_raii __current(uselocale(__l), uselocale); 269227825Stheraven return wcsnrtombs(__dest, __src, __nwc, __len, __ps); 270227825Stheraven#endif 271227825Stheraven} 272227825Stheraven 273227825Stheraven_LIBCPP_ALWAYS_INLINE inline 274227825Stheravensize_t __wcrtomb_l(char *__s, wchar_t __wc, mbstate_t *__ps, locale_t __l) 275227825Stheraven{ 276227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 277227825Stheraven return wcrtomb_l(__s, __wc, __ps, __l); 278227825Stheraven#else 279227825Stheraven __locale_raii __current(uselocale(__l), uselocale); 280227825Stheraven return wcrtomb(__s, __wc, __ps); 281227825Stheraven#endif 282227825Stheraven} 283227825Stheraven 284227825Stheraven_LIBCPP_ALWAYS_INLINE inline 285227825Stheravensize_t __mbsnrtowcs_l(wchar_t * __dest, const char **__src, size_t __nms, 286227825Stheraven size_t __len, mbstate_t *__ps, locale_t __l) 287227825Stheraven{ 288227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 289227825Stheraven return mbsnrtowcs_l(__dest, __src, __nms, __len, __ps, __l); 290227825Stheraven#else 291227825Stheraven __locale_raii __current(uselocale(__l), uselocale); 292227825Stheraven return mbsnrtowcs(__dest, __src, __nms, __len, __ps); 293227825Stheraven#endif 294227825Stheraven} 295227825Stheraven 296227825Stheraven_LIBCPP_ALWAYS_INLINE inline 297227825Stheravensize_t __mbrtowc_l(wchar_t *__pwc, const char *__s, size_t __n, 298227825Stheraven mbstate_t *__ps, locale_t __l) 299227825Stheraven{ 300227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 301227825Stheraven return mbrtowc_l(__pwc, __s, __n, __ps, __l); 302227825Stheraven#else 303227825Stheraven __locale_raii __current(uselocale(__l), uselocale); 304227825Stheraven return mbrtowc(__pwc, __s, __n, __ps); 305227825Stheraven#endif 306227825Stheraven} 307227825Stheraven 308227825Stheraven_LIBCPP_ALWAYS_INLINE inline 309227825Stheravenint __mbtowc_l(wchar_t *__pwc, const char *__pmb, size_t __max, locale_t __l) 310227825Stheraven{ 311227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 312227825Stheraven return mbtowc_l(__pwc, __pmb, __max, __l); 313227825Stheraven#else 314227825Stheraven __locale_raii __current(uselocale(__l), uselocale); 315227825Stheraven return mbtowc(__pwc, __pmb, __max); 316227825Stheraven#endif 317227825Stheraven} 318227825Stheraven 319227825Stheraven_LIBCPP_ALWAYS_INLINE inline 320227825Stheravensize_t __mbrlen_l(const char *__s, size_t __n, mbstate_t *__ps, locale_t __l) 321227825Stheraven{ 322227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 323227825Stheraven return mbrlen_l(__s, __n, __ps, __l); 324227825Stheraven#else 325227825Stheraven __locale_raii __current(uselocale(__l), uselocale); 326227825Stheraven return mbrlen(__s, __n, __ps); 327227825Stheraven#endif 328227825Stheraven} 329227825Stheraven 330227825Stheraven_LIBCPP_ALWAYS_INLINE inline 331227825Stheravenlconv *__localeconv_l(locale_t __l) 332227825Stheraven{ 333227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 334227825Stheraven return localeconv_l(__l); 335227825Stheraven#else 336227825Stheraven __locale_raii __current(uselocale(__l), uselocale); 337227825Stheraven return localeconv(); 338227825Stheraven#endif 339227825Stheraven} 340227825Stheraven 341227825Stheraven_LIBCPP_ALWAYS_INLINE inline 342227825Stheravensize_t __mbsrtowcs_l(wchar_t *__dest, const char **__src, size_t __len, 343227825Stheraven mbstate_t *__ps, locale_t __l) 344227825Stheraven{ 345227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 346227825Stheraven return mbsrtowcs_l(__dest, __src, __len, __ps, __l); 347227825Stheraven#else 348227825Stheraven __locale_raii __current(uselocale(__l), uselocale); 349227825Stheraven return mbsrtowcs(__dest, __src, __len, __ps); 350227825Stheraven#endif 351227825Stheraven} 352227825Stheraven 353227825Stheraven_LIBCPP_ALWAYS_INLINE inline 354227825Stheravenint __sprintf_l(char *__s, locale_t __l, const char *__format, ...) { 355227825Stheraven va_list __va; 356227825Stheraven va_start(__va, __format); 357227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 358227825Stheraven int __res = vsprintf_l(__s, __l, __format, __va); 359227825Stheraven#else 360227825Stheraven __locale_raii __current(uselocale(__l), uselocale); 361227825Stheraven int __res = vsprintf(__s, __format, __va); 362227825Stheraven#endif 363227825Stheraven va_end(__va); 364227825Stheraven return __res; 365227825Stheraven} 366227825Stheraven 367227825Stheraven_LIBCPP_ALWAYS_INLINE inline 368227825Stheravenint __snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...) { 369227825Stheraven va_list __va; 370227825Stheraven va_start(__va, __format); 371227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 372227825Stheraven int __res = vsnprintf_l(__s, __n, __l, __format, __va); 373227825Stheraven#else 374227825Stheraven __locale_raii __current(uselocale(__l), uselocale); 375227825Stheraven int __res = vsnprintf(__s, __n, __format, __va); 376227825Stheraven#endif 377227825Stheraven va_end(__va); 378227825Stheraven return __res; 379227825Stheraven} 380227825Stheraven 381227825Stheraven_LIBCPP_ALWAYS_INLINE inline 382227825Stheravenint __asprintf_l(char **__s, locale_t __l, const char *__format, ...) { 383227825Stheraven va_list __va; 384227825Stheraven va_start(__va, __format); 385227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 386227825Stheraven int __res = vasprintf_l(__s, __l, __format, __va); 387227825Stheraven#else 388227825Stheraven __locale_raii __current(uselocale(__l), uselocale); 389227825Stheraven int __res = vasprintf(__s, __format, __va); 390227825Stheraven#endif 391227825Stheraven va_end(__va); 392227825Stheraven return __res; 393227825Stheraven} 394227825Stheraven 395227825Stheraven_LIBCPP_ALWAYS_INLINE inline 396227825Stheravenint __sscanf_l(const char *__s, locale_t __l, const char *__format, ...) { 397227825Stheraven va_list __va; 398227825Stheraven va_start(__va, __format); 399227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 400227825Stheraven int __res = vsscanf_l(__s, __l, __format, __va); 401227825Stheraven#else 402227825Stheraven __locale_raii __current(uselocale(__l), uselocale); 403227825Stheraven int __res = vsscanf(__s, __format, __va); 404227825Stheraven#endif 405227825Stheraven va_end(__va); 406227825Stheraven return __res; 407227825Stheraven} 408227825Stheraven 409227825Stheraven#endif // __linux__ 410227825Stheraven 411227825Stheraven// __scan_keyword 412227825Stheraven// Scans [__b, __e) until a match is found in the basic_strings range 413227825Stheraven// [__kb, __ke) or until it can be shown that there is no match in [__kb, __ke). 414227825Stheraven// __b will be incremented (visibly), consuming CharT until a match is found 415227825Stheraven// or proved to not exist. A keyword may be "", in which will match anything. 416227825Stheraven// If one keyword is a prefix of another, and the next CharT in the input 417227825Stheraven// might match another keyword, the algorithm will attempt to find the longest 418227825Stheraven// matching keyword. If the longer matching keyword ends up not matching, then 419227825Stheraven// no keyword match is found. If no keyword match is found, __ke is returned 420227825Stheraven// and failbit is set in __err. 421227825Stheraven// Else an iterator pointing to the matching keyword is found. If more than 422227825Stheraven// one keyword matches, an iterator to the first matching keyword is returned. 423227825Stheraven// If on exit __b == __e, eofbit is set in __err. If __case_senstive is false, 424227825Stheraven// __ct is used to force to lower case before comparing characters. 425227825Stheraven// Examples: 426227825Stheraven// Keywords: "a", "abb" 427227825Stheraven// If the input is "a", the first keyword matches and eofbit is set. 428227825Stheraven// If the input is "abc", no match is found and "ab" are consumed. 429227825Stheraventemplate <class _InputIterator, class _ForwardIterator, class _Ctype> 430227825Stheraven_LIBCPP_HIDDEN 431227825Stheraven_ForwardIterator 432227825Stheraven__scan_keyword(_InputIterator& __b, _InputIterator __e, 433227825Stheraven _ForwardIterator __kb, _ForwardIterator __ke, 434227825Stheraven const _Ctype& __ct, ios_base::iostate& __err, 435227825Stheraven bool __case_sensitive = true) 436227825Stheraven{ 437227825Stheraven typedef typename iterator_traits<_InputIterator>::value_type _CharT; 438232950Stheraven size_t __nkw = static_cast<size_t>(_VSTD::distance(__kb, __ke)); 439227825Stheraven const unsigned char __doesnt_match = '\0'; 440227825Stheraven const unsigned char __might_match = '\1'; 441227825Stheraven const unsigned char __does_match = '\2'; 442227825Stheraven unsigned char __statbuf[100]; 443227825Stheraven unsigned char* __status = __statbuf; 444227825Stheraven unique_ptr<unsigned char, void(*)(void*)> __stat_hold(0, free); 445227825Stheraven if (__nkw > sizeof(__statbuf)) 446227825Stheraven { 447227825Stheraven __status = (unsigned char*)malloc(__nkw); 448227825Stheraven if (__status == 0) 449227825Stheraven __throw_bad_alloc(); 450227825Stheraven __stat_hold.reset(__status); 451227825Stheraven } 452227825Stheraven size_t __n_might_match = __nkw; // At this point, any keyword might match 453227825Stheraven size_t __n_does_match = 0; // but none of them definitely do 454227825Stheraven // Initialize all statuses to __might_match, except for "" keywords are __does_match 455227825Stheraven unsigned char* __st = __status; 456227825Stheraven for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, ++__st) 457227825Stheraven { 458227825Stheraven if (!__ky->empty()) 459227825Stheraven *__st = __might_match; 460227825Stheraven else 461227825Stheraven { 462227825Stheraven *__st = __does_match; 463227825Stheraven --__n_might_match; 464227825Stheraven ++__n_does_match; 465227825Stheraven } 466227825Stheraven } 467227825Stheraven // While there might be a match, test keywords against the next CharT 468227825Stheraven for (size_t __indx = 0; __b != __e && __n_might_match > 0; ++__indx) 469227825Stheraven { 470227825Stheraven // Peek at the next CharT but don't consume it 471227825Stheraven _CharT __c = *__b; 472227825Stheraven if (!__case_sensitive) 473227825Stheraven __c = __ct.toupper(__c); 474227825Stheraven bool __consume = false; 475227825Stheraven // For each keyword which might match, see if the __indx character is __c 476227825Stheraven // If a match if found, consume __c 477227825Stheraven // If a match is found, and that is the last character in the keyword, 478227825Stheraven // then that keyword matches. 479227825Stheraven // If the keyword doesn't match this character, then change the keyword 480227825Stheraven // to doesn't match 481227825Stheraven __st = __status; 482227825Stheraven for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, ++__st) 483227825Stheraven { 484227825Stheraven if (*__st == __might_match) 485227825Stheraven { 486227825Stheraven _CharT __kc = (*__ky)[__indx]; 487227825Stheraven if (!__case_sensitive) 488227825Stheraven __kc = __ct.toupper(__kc); 489227825Stheraven if (__c == __kc) 490227825Stheraven { 491227825Stheraven __consume = true; 492227825Stheraven if (__ky->size() == __indx+1) 493227825Stheraven { 494227825Stheraven *__st = __does_match; 495227825Stheraven --__n_might_match; 496227825Stheraven ++__n_does_match; 497227825Stheraven } 498227825Stheraven } 499227825Stheraven else 500227825Stheraven { 501227825Stheraven *__st = __doesnt_match; 502227825Stheraven --__n_might_match; 503227825Stheraven } 504227825Stheraven } 505227825Stheraven } 506227825Stheraven // consume if we matched a character 507227825Stheraven if (__consume) 508227825Stheraven { 509227825Stheraven ++__b; 510227825Stheraven // If we consumed a character and there might be a matched keyword that 511227825Stheraven // was marked matched on a previous iteration, then such keywords 512227825Stheraven // which are now marked as not matching. 513227825Stheraven if (__n_might_match + __n_does_match > 1) 514227825Stheraven { 515227825Stheraven __st = __status; 516227825Stheraven for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, ++__st) 517227825Stheraven { 518227825Stheraven if (*__st == __does_match && __ky->size() != __indx+1) 519227825Stheraven { 520227825Stheraven *__st = __doesnt_match; 521227825Stheraven --__n_does_match; 522227825Stheraven } 523227825Stheraven } 524227825Stheraven } 525227825Stheraven } 526227825Stheraven } 527227825Stheraven // We've exited the loop because we hit eof and/or we have no more "might matches". 528227825Stheraven if (__b == __e) 529227825Stheraven __err |= ios_base::eofbit; 530227825Stheraven // Return the first matching result 531227825Stheraven for (__st = __status; __kb != __ke; ++__kb, ++__st) 532227825Stheraven if (*__st == __does_match) 533227825Stheraven break; 534227825Stheraven if (__kb == __ke) 535227825Stheraven __err |= ios_base::failbit; 536227825Stheraven return __kb; 537227825Stheraven} 538227825Stheraven 539227825Stheravenstruct __num_get_base 540227825Stheraven{ 541227825Stheraven static const int __num_get_buf_sz = 40; 542227825Stheraven 543227825Stheraven static int __get_base(ios_base&); 544227825Stheraven static const char __src[33]; 545227825Stheraven}; 546227825Stheraven 547227825Stheravenvoid __check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end, 548227825Stheraven ios_base::iostate& __err); 549227825Stheraven 550227825Stheraventemplate <class _CharT> 551227825Stheravenstruct __num_get 552227825Stheraven : protected __num_get_base 553227825Stheraven{ 554227825Stheraven static string __stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep); 555227825Stheraven static string __stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point, 556227825Stheraven _CharT& __thousands_sep); 557227825Stheraven static int __stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end, 558227825Stheraven unsigned& __dc, _CharT __thousands_sep, const string& __grouping, 559227825Stheraven unsigned* __g, unsigned*& __g_end, _CharT* __atoms); 560227825Stheraven static int __stage2_float_loop(_CharT __ct, bool& __in_units, char& __exp, 561227825Stheraven char* __a, char*& __a_end, 562227825Stheraven _CharT __decimal_point, _CharT __thousands_sep, 563227825Stheraven const string& __grouping, unsigned* __g, 564227825Stheraven unsigned*& __g_end, unsigned& __dc, _CharT* __atoms); 565227825Stheraven}; 566227825Stheraven 567227825Stheraventemplate <class _CharT> 568227825Stheravenstring 569227825Stheraven__num_get<_CharT>::__stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep) 570227825Stheraven{ 571227825Stheraven locale __loc = __iob.getloc(); 572227825Stheraven use_facet<ctype<_CharT> >(__loc).widen(__src, __src + 26, __atoms); 573227825Stheraven const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc); 574227825Stheraven __thousands_sep = __np.thousands_sep(); 575227825Stheraven return __np.grouping(); 576227825Stheraven} 577227825Stheraven 578227825Stheraventemplate <class _CharT> 579227825Stheravenstring 580227825Stheraven__num_get<_CharT>::__stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point, 581227825Stheraven _CharT& __thousands_sep) 582227825Stheraven{ 583227825Stheraven locale __loc = __iob.getloc(); 584227825Stheraven use_facet<ctype<_CharT> >(__loc).widen(__src, __src + 32, __atoms); 585227825Stheraven const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc); 586227825Stheraven __decimal_point = __np.decimal_point(); 587227825Stheraven __thousands_sep = __np.thousands_sep(); 588227825Stheraven return __np.grouping(); 589227825Stheraven} 590227825Stheraven 591227825Stheraventemplate <class _CharT> 592227825Stheravenint 593227825Stheraven__num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end, 594227825Stheraven unsigned& __dc, _CharT __thousands_sep, const string& __grouping, 595227825Stheraven unsigned* __g, unsigned*& __g_end, _CharT* __atoms) 596227825Stheraven{ 597227825Stheraven if (__a_end == __a && (__ct == __atoms[24] || __ct == __atoms[25])) 598227825Stheraven { 599227825Stheraven *__a_end++ = __ct == __atoms[24] ? '+' : '-'; 600227825Stheraven __dc = 0; 601227825Stheraven return 0; 602227825Stheraven } 603232950Stheraven if (__grouping.size() != 0 && __ct == __thousands_sep) 604227825Stheraven { 605227825Stheraven if (__g_end-__g < __num_get_buf_sz) 606227825Stheraven { 607227825Stheraven *__g_end++ = __dc; 608227825Stheraven __dc = 0; 609227825Stheraven } 610227825Stheraven return 0; 611227825Stheraven } 612227825Stheraven ptrdiff_t __f = find(__atoms, __atoms + 26, __ct) - __atoms; 613227825Stheraven if (__f >= 24) 614227825Stheraven return -1; 615227825Stheraven switch (__base) 616227825Stheraven { 617227825Stheraven case 8: 618227825Stheraven case 10: 619227825Stheraven if (__f >= __base) 620227825Stheraven return -1; 621227825Stheraven break; 622227825Stheraven case 16: 623227825Stheraven if (__f < 22) 624227825Stheraven break; 625227825Stheraven if (__a_end != __a && __a_end - __a <= 2 && __a_end[-1] == '0') 626227825Stheraven { 627227825Stheraven __dc = 0; 628227825Stheraven *__a_end++ = __src[__f]; 629227825Stheraven return 0; 630227825Stheraven } 631227825Stheraven return -1; 632227825Stheraven } 633227825Stheraven if (__a_end-__a < __num_get_buf_sz - 1) 634227825Stheraven *__a_end++ = __src[__f]; 635227825Stheraven ++__dc; 636227825Stheraven return 0; 637227825Stheraven} 638227825Stheraven 639227825Stheraventemplate <class _CharT> 640227825Stheravenint 641227825Stheraven__num_get<_CharT>::__stage2_float_loop(_CharT __ct, bool& __in_units, char& __exp, char* __a, char*& __a_end, 642227825Stheraven _CharT __decimal_point, _CharT __thousands_sep, const string& __grouping, 643227825Stheraven unsigned* __g, unsigned*& __g_end, unsigned& __dc, _CharT* __atoms) 644227825Stheraven{ 645227825Stheraven if (__ct == __decimal_point) 646227825Stheraven { 647227825Stheraven if (!__in_units) 648227825Stheraven return -1; 649227825Stheraven __in_units = false; 650227825Stheraven *__a_end++ = '.'; 651227825Stheraven if (__grouping.size() != 0 && __g_end-__g < __num_get_buf_sz) 652227825Stheraven *__g_end++ = __dc; 653227825Stheraven return 0; 654227825Stheraven } 655227825Stheraven if (__ct == __thousands_sep && __grouping.size() != 0) 656227825Stheraven { 657227825Stheraven if (!__in_units) 658227825Stheraven return -1; 659227825Stheraven if (__g_end-__g < __num_get_buf_sz) 660227825Stheraven { 661227825Stheraven *__g_end++ = __dc; 662227825Stheraven __dc = 0; 663227825Stheraven } 664227825Stheraven return 0; 665227825Stheraven } 666227825Stheraven ptrdiff_t __f = find(__atoms, __atoms + 32, __ct) - __atoms; 667227825Stheraven if (__f >= 32) 668227825Stheraven return -1; 669227825Stheraven char __x = __src[__f]; 670232950Stheraven if (__x == '-' || __x == '+') 671232950Stheraven { 672232950Stheraven if (__a_end == __a || (__a_end[-1] & 0xDF) == __exp) 673232950Stheraven { 674232950Stheraven *__a_end++ = __x; 675232950Stheraven return 0; 676232950Stheraven } 677232950Stheraven return -1; 678232950Stheraven } 679227825Stheraven if (__a_end-__a < __num_get_buf_sz - 1) 680227825Stheraven *__a_end++ = __x; 681227825Stheraven if (__x == 'x' || __x == 'X') 682227825Stheraven __exp = 'P'; 683227825Stheraven else if ((__x & 0xDF) == __exp) 684227825Stheraven { 685227825Stheraven __in_units = false; 686227825Stheraven if (__grouping.size() != 0 && __g_end-__g < __num_get_buf_sz) 687227825Stheraven *__g_end++ = __dc; 688227825Stheraven } 689227825Stheraven if (__f >= 22) 690227825Stheraven return 0; 691227825Stheraven ++__dc; 692227825Stheraven return 0; 693227825Stheraven} 694227825Stheraven 695242945Stheraven_LIBCPP_EXTERN_TEMPLATE(struct __num_get<char>) 696242945Stheraven_LIBCPP_EXTERN_TEMPLATE(struct __num_get<wchar_t>) 697227825Stheraven 698227825Stheraventemplate <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> > 699227825Stheravenclass _LIBCPP_VISIBLE num_get 700227825Stheraven : public locale::facet, 701227825Stheraven private __num_get<_CharT> 702227825Stheraven{ 703227825Stheravenpublic: 704227825Stheraven typedef _CharT char_type; 705227825Stheraven typedef _InputIterator iter_type; 706227825Stheraven 707227825Stheraven _LIBCPP_ALWAYS_INLINE 708227825Stheraven explicit num_get(size_t __refs = 0) 709227825Stheraven : locale::facet(__refs) {} 710227825Stheraven 711227825Stheraven _LIBCPP_ALWAYS_INLINE 712227825Stheraven iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 713227825Stheraven ios_base::iostate& __err, bool& __v) const 714227825Stheraven { 715227825Stheraven return do_get(__b, __e, __iob, __err, __v); 716227825Stheraven } 717227825Stheraven 718227825Stheraven _LIBCPP_ALWAYS_INLINE 719227825Stheraven iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 720227825Stheraven ios_base::iostate& __err, long& __v) const 721227825Stheraven { 722227825Stheraven return do_get(__b, __e, __iob, __err, __v); 723227825Stheraven } 724227825Stheraven 725227825Stheraven _LIBCPP_ALWAYS_INLINE 726227825Stheraven iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 727227825Stheraven ios_base::iostate& __err, long long& __v) const 728227825Stheraven { 729227825Stheraven return do_get(__b, __e, __iob, __err, __v); 730227825Stheraven } 731227825Stheraven 732227825Stheraven _LIBCPP_ALWAYS_INLINE 733227825Stheraven iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 734227825Stheraven ios_base::iostate& __err, unsigned short& __v) const 735227825Stheraven { 736227825Stheraven return do_get(__b, __e, __iob, __err, __v); 737227825Stheraven } 738227825Stheraven 739227825Stheraven _LIBCPP_ALWAYS_INLINE 740227825Stheraven iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 741227825Stheraven ios_base::iostate& __err, unsigned int& __v) const 742227825Stheraven { 743227825Stheraven return do_get(__b, __e, __iob, __err, __v); 744227825Stheraven } 745227825Stheraven 746227825Stheraven _LIBCPP_ALWAYS_INLINE 747227825Stheraven iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 748227825Stheraven ios_base::iostate& __err, unsigned long& __v) const 749227825Stheraven { 750227825Stheraven return do_get(__b, __e, __iob, __err, __v); 751227825Stheraven } 752227825Stheraven 753227825Stheraven _LIBCPP_ALWAYS_INLINE 754227825Stheraven iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 755227825Stheraven ios_base::iostate& __err, unsigned long long& __v) const 756227825Stheraven { 757227825Stheraven return do_get(__b, __e, __iob, __err, __v); 758227825Stheraven } 759227825Stheraven 760227825Stheraven _LIBCPP_ALWAYS_INLINE 761227825Stheraven iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 762227825Stheraven ios_base::iostate& __err, float& __v) const 763227825Stheraven { 764227825Stheraven return do_get(__b, __e, __iob, __err, __v); 765227825Stheraven } 766227825Stheraven 767227825Stheraven _LIBCPP_ALWAYS_INLINE 768227825Stheraven iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 769227825Stheraven ios_base::iostate& __err, double& __v) const 770227825Stheraven { 771227825Stheraven return do_get(__b, __e, __iob, __err, __v); 772227825Stheraven } 773227825Stheraven 774227825Stheraven _LIBCPP_ALWAYS_INLINE 775227825Stheraven iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 776227825Stheraven ios_base::iostate& __err, long double& __v) const 777227825Stheraven { 778227825Stheraven return do_get(__b, __e, __iob, __err, __v); 779227825Stheraven } 780227825Stheraven 781227825Stheraven _LIBCPP_ALWAYS_INLINE 782227825Stheraven iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 783227825Stheraven ios_base::iostate& __err, void*& __v) const 784227825Stheraven { 785227825Stheraven return do_get(__b, __e, __iob, __err, __v); 786227825Stheraven } 787227825Stheraven 788227825Stheraven static locale::id id; 789227825Stheraven 790227825Stheravenprotected: 791227825Stheraven _LIBCPP_ALWAYS_INLINE 792227825Stheraven ~num_get() {} 793227825Stheraven 794227825Stheraven virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, 795227825Stheraven ios_base::iostate& __err, bool& __v) const; 796227825Stheraven virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, 797227825Stheraven ios_base::iostate& __err, long& __v) const; 798227825Stheraven virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, 799227825Stheraven ios_base::iostate& __err, long long& __v) const; 800227825Stheraven virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, 801227825Stheraven ios_base::iostate& __err, unsigned short& __v) const; 802227825Stheraven virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, 803227825Stheraven ios_base::iostate& __err, unsigned int& __v) const; 804227825Stheraven virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, 805227825Stheraven ios_base::iostate& __err, unsigned long& __v) const; 806227825Stheraven virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, 807227825Stheraven ios_base::iostate& __err, unsigned long long& __v) const; 808227825Stheraven virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, 809227825Stheraven ios_base::iostate& __err, float& __v) const; 810227825Stheraven virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, 811227825Stheraven ios_base::iostate& __err, double& __v) const; 812227825Stheraven virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, 813227825Stheraven ios_base::iostate& __err, long double& __v) const; 814227825Stheraven virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, 815227825Stheraven ios_base::iostate& __err, void*& __v) const; 816227825Stheraven}; 817227825Stheraven 818227825Stheraventemplate <class _CharT, class _InputIterator> 819227825Stheravenlocale::id 820227825Stheravennum_get<_CharT, _InputIterator>::id; 821227825Stheraven 822227825Stheraventemplate <class _Tp> 823227825Stheraven_Tp 824227825Stheraven__num_get_signed_integral(const char* __a, const char* __a_end, 825227825Stheraven ios_base::iostate& __err, int __base) 826227825Stheraven{ 827227825Stheraven if (__a != __a_end) 828227825Stheraven { 829227825Stheraven int __save_errno = errno; 830227825Stheraven errno = 0; 831227825Stheraven char *__p2; 832227825Stheraven long long __ll = strtoll_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE); 833227825Stheraven int __current_errno = errno; 834227825Stheraven if (__current_errno == 0) 835227825Stheraven errno = __save_errno; 836227825Stheraven if (__p2 != __a_end) 837227825Stheraven { 838227825Stheraven __err = ios_base::failbit; 839227825Stheraven return 0; 840227825Stheraven } 841227825Stheraven else if (__current_errno == ERANGE || 842227825Stheraven __ll < numeric_limits<_Tp>::min() || 843227825Stheraven numeric_limits<_Tp>::max() < __ll) 844227825Stheraven { 845227825Stheraven __err = ios_base::failbit; 846227825Stheraven if (__ll > 0) 847227825Stheraven return numeric_limits<_Tp>::max(); 848227825Stheraven else 849227825Stheraven return numeric_limits<_Tp>::min(); 850227825Stheraven } 851227825Stheraven return static_cast<_Tp>(__ll); 852227825Stheraven } 853227825Stheraven __err = ios_base::failbit; 854227825Stheraven return 0; 855227825Stheraven} 856227825Stheraven 857227825Stheraventemplate <class _Tp> 858227825Stheraven_Tp 859227825Stheraven__num_get_unsigned_integral(const char* __a, const char* __a_end, 860227825Stheraven ios_base::iostate& __err, int __base) 861227825Stheraven{ 862227825Stheraven if (__a != __a_end) 863227825Stheraven { 864227825Stheraven if (*__a == '-') 865227825Stheraven { 866227825Stheraven __err = ios_base::failbit; 867227825Stheraven return 0; 868227825Stheraven } 869227825Stheraven int __save_errno = errno; 870227825Stheraven errno = 0; 871227825Stheraven char *__p2; 872227825Stheraven unsigned long long __ll = strtoull_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE); 873227825Stheraven int __current_errno = errno; 874227825Stheraven if (__current_errno == 0) 875227825Stheraven errno = __save_errno; 876227825Stheraven if (__p2 != __a_end) 877227825Stheraven { 878227825Stheraven __err = ios_base::failbit; 879227825Stheraven return 0; 880227825Stheraven } 881227825Stheraven else if (__current_errno == ERANGE || 882227825Stheraven numeric_limits<_Tp>::max() < __ll) 883227825Stheraven { 884227825Stheraven __err = ios_base::failbit; 885227825Stheraven return numeric_limits<_Tp>::max(); 886227825Stheraven } 887227825Stheraven return static_cast<_Tp>(__ll); 888227825Stheraven } 889227825Stheraven __err = ios_base::failbit; 890227825Stheraven return 0; 891227825Stheraven} 892227825Stheraven 893227825Stheraventemplate <class _Tp> 894227825Stheraven_Tp 895227825Stheraven__num_get_float(const char* __a, const char* __a_end, ios_base::iostate& __err) 896227825Stheraven{ 897227825Stheraven if (__a != __a_end) 898227825Stheraven { 899227825Stheraven char *__p2; 900227825Stheraven long double __ld = strtold_l(__a, &__p2, _LIBCPP_GET_C_LOCALE); 901227825Stheraven if (__p2 != __a_end) 902227825Stheraven { 903227825Stheraven __err = ios_base::failbit; 904227825Stheraven return 0; 905227825Stheraven } 906227825Stheraven return static_cast<_Tp>(__ld); 907227825Stheraven } 908227825Stheraven __err = ios_base::failbit; 909227825Stheraven return 0; 910227825Stheraven} 911227825Stheraven 912227825Stheraventemplate <class _CharT, class _InputIterator> 913227825Stheraven_InputIterator 914227825Stheravennum_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, 915227825Stheraven ios_base& __iob, 916227825Stheraven ios_base::iostate& __err, 917227825Stheraven bool& __v) const 918227825Stheraven{ 919227825Stheraven if ((__iob.flags() & ios_base::boolalpha) == 0) 920227825Stheraven { 921227825Stheraven long __lv = -1; 922227825Stheraven __b = do_get(__b, __e, __iob, __err, __lv); 923227825Stheraven switch (__lv) 924227825Stheraven { 925227825Stheraven case 0: 926227825Stheraven __v = false; 927227825Stheraven break; 928227825Stheraven case 1: 929227825Stheraven __v = true; 930227825Stheraven break; 931227825Stheraven default: 932227825Stheraven __v = true; 933227825Stheraven __err = ios_base::failbit; 934227825Stheraven break; 935227825Stheraven } 936227825Stheraven return __b; 937227825Stheraven } 938227825Stheraven const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__iob.getloc()); 939227825Stheraven const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__iob.getloc()); 940227825Stheraven typedef typename numpunct<_CharT>::string_type string_type; 941227825Stheraven const string_type __names[2] = {__np.truename(), __np.falsename()}; 942227825Stheraven const string_type* __i = __scan_keyword(__b, __e, __names, __names+2, 943227825Stheraven __ct, __err); 944227825Stheraven __v = __i == __names; 945227825Stheraven return __b; 946227825Stheraven} 947227825Stheraven 948227825Stheraventemplate <class _CharT, class _InputIterator> 949227825Stheraven_InputIterator 950227825Stheravennum_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, 951227825Stheraven ios_base& __iob, 952227825Stheraven ios_base::iostate& __err, 953227825Stheraven long& __v) const 954227825Stheraven{ 955227825Stheraven // Stage 1 956227825Stheraven int __base = this->__get_base(__iob); 957227825Stheraven // Stage 2 958227825Stheraven char_type __atoms[26]; 959227825Stheraven char_type __thousands_sep; 960227825Stheraven string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); 961227825Stheraven char __a[__num_get_base::__num_get_buf_sz] = {0}; 962227825Stheraven char* __a_end = __a; 963227825Stheraven unsigned __g[__num_get_base::__num_get_buf_sz]; 964227825Stheraven unsigned* __g_end = __g; 965227825Stheraven unsigned __dc = 0; 966227825Stheraven for (; __b != __e; ++__b) 967227825Stheraven if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, 968227825Stheraven __thousands_sep, __grouping, __g, __g_end, 969227825Stheraven __atoms)) 970227825Stheraven break; 971227825Stheraven if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) 972227825Stheraven *__g_end++ = __dc; 973227825Stheraven // Stage 3 974227825Stheraven __v = __num_get_signed_integral<long>(__a, __a_end, __err, __base); 975227825Stheraven // Digit grouping checked 976227825Stheraven __check_grouping(__grouping, __g, __g_end, __err); 977227825Stheraven // EOF checked 978227825Stheraven if (__b == __e) 979227825Stheraven __err |= ios_base::eofbit; 980227825Stheraven return __b; 981227825Stheraven} 982227825Stheraven 983227825Stheraventemplate <class _CharT, class _InputIterator> 984227825Stheraven_InputIterator 985227825Stheravennum_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, 986227825Stheraven ios_base& __iob, 987227825Stheraven ios_base::iostate& __err, 988227825Stheraven long long& __v) const 989227825Stheraven{ 990227825Stheraven // Stage 1 991227825Stheraven int __base = this->__get_base(__iob); 992227825Stheraven // Stage 2 993227825Stheraven char_type __atoms[26]; 994227825Stheraven char_type __thousands_sep; 995227825Stheraven string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); 996227825Stheraven char __a[__num_get_base::__num_get_buf_sz] = {0}; 997227825Stheraven char* __a_end = __a; 998227825Stheraven unsigned __g[__num_get_base::__num_get_buf_sz]; 999227825Stheraven unsigned* __g_end = __g; 1000227825Stheraven unsigned __dc = 0; 1001227825Stheraven for (; __b != __e; ++__b) 1002227825Stheraven if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, 1003227825Stheraven __thousands_sep, __grouping, __g, __g_end, 1004227825Stheraven __atoms)) 1005227825Stheraven break; 1006227825Stheraven if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) 1007227825Stheraven *__g_end++ = __dc; 1008227825Stheraven // Stage 3 1009227825Stheraven __v = __num_get_signed_integral<long long>(__a, __a_end, __err, __base); 1010227825Stheraven // Digit grouping checked 1011227825Stheraven __check_grouping(__grouping, __g, __g_end, __err); 1012227825Stheraven // EOF checked 1013227825Stheraven if (__b == __e) 1014227825Stheraven __err |= ios_base::eofbit; 1015227825Stheraven return __b; 1016227825Stheraven} 1017227825Stheraven 1018227825Stheraventemplate <class _CharT, class _InputIterator> 1019227825Stheraven_InputIterator 1020227825Stheravennum_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, 1021227825Stheraven ios_base& __iob, 1022227825Stheraven ios_base::iostate& __err, 1023227825Stheraven unsigned short& __v) const 1024227825Stheraven{ 1025227825Stheraven // Stage 1 1026227825Stheraven int __base = this->__get_base(__iob); 1027227825Stheraven // Stage 2 1028227825Stheraven char_type __atoms[26]; 1029227825Stheraven char_type __thousands_sep; 1030227825Stheraven string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); 1031227825Stheraven char __a[__num_get_base::__num_get_buf_sz] = {0}; 1032227825Stheraven char* __a_end = __a; 1033227825Stheraven unsigned __g[__num_get_base::__num_get_buf_sz]; 1034227825Stheraven unsigned* __g_end = __g; 1035227825Stheraven unsigned __dc = 0; 1036227825Stheraven for (; __b != __e; ++__b) 1037227825Stheraven if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, 1038227825Stheraven __thousands_sep, __grouping, __g, __g_end, 1039227825Stheraven __atoms)) 1040227825Stheraven break; 1041227825Stheraven if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) 1042227825Stheraven *__g_end++ = __dc; 1043227825Stheraven // Stage 3 1044227825Stheraven __v = __num_get_unsigned_integral<unsigned short>(__a, __a_end, __err, __base); 1045227825Stheraven // Digit grouping checked 1046227825Stheraven __check_grouping(__grouping, __g, __g_end, __err); 1047227825Stheraven // EOF checked 1048227825Stheraven if (__b == __e) 1049227825Stheraven __err |= ios_base::eofbit; 1050227825Stheraven return __b; 1051227825Stheraven} 1052227825Stheraven 1053227825Stheraventemplate <class _CharT, class _InputIterator> 1054227825Stheraven_InputIterator 1055227825Stheravennum_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, 1056227825Stheraven ios_base& __iob, 1057227825Stheraven ios_base::iostate& __err, 1058227825Stheraven unsigned int& __v) const 1059227825Stheraven{ 1060227825Stheraven // Stage 1 1061227825Stheraven int __base = this->__get_base(__iob); 1062227825Stheraven // Stage 2 1063227825Stheraven char_type __atoms[26]; 1064227825Stheraven char_type __thousands_sep; 1065227825Stheraven string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); 1066227825Stheraven char __a[__num_get_base::__num_get_buf_sz] = {0}; 1067227825Stheraven char* __a_end = __a; 1068227825Stheraven unsigned __g[__num_get_base::__num_get_buf_sz]; 1069227825Stheraven unsigned* __g_end = __g; 1070227825Stheraven unsigned __dc = 0; 1071227825Stheraven for (; __b != __e; ++__b) 1072227825Stheraven if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, 1073227825Stheraven __thousands_sep, __grouping, __g, __g_end, 1074227825Stheraven __atoms)) 1075227825Stheraven break; 1076227825Stheraven if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) 1077227825Stheraven *__g_end++ = __dc; 1078227825Stheraven // Stage 3 1079227825Stheraven __v = __num_get_unsigned_integral<unsigned int>(__a, __a_end, __err, __base); 1080227825Stheraven // Digit grouping checked 1081227825Stheraven __check_grouping(__grouping, __g, __g_end, __err); 1082227825Stheraven // EOF checked 1083227825Stheraven if (__b == __e) 1084227825Stheraven __err |= ios_base::eofbit; 1085227825Stheraven return __b; 1086227825Stheraven} 1087227825Stheraven 1088227825Stheraventemplate <class _CharT, class _InputIterator> 1089227825Stheraven_InputIterator 1090227825Stheravennum_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, 1091227825Stheraven ios_base& __iob, 1092227825Stheraven ios_base::iostate& __err, 1093227825Stheraven unsigned long& __v) const 1094227825Stheraven{ 1095227825Stheraven // Stage 1 1096227825Stheraven int __base = this->__get_base(__iob); 1097227825Stheraven // Stage 2 1098227825Stheraven char_type __atoms[26]; 1099227825Stheraven char_type __thousands_sep; 1100227825Stheraven string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); 1101227825Stheraven char __a[__num_get_base::__num_get_buf_sz] = {0}; 1102227825Stheraven char* __a_end = __a; 1103227825Stheraven unsigned __g[__num_get_base::__num_get_buf_sz]; 1104227825Stheraven unsigned* __g_end = __g; 1105227825Stheraven unsigned __dc = 0; 1106227825Stheraven for (; __b != __e; ++__b) 1107227825Stheraven if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, 1108227825Stheraven __thousands_sep, __grouping, __g, __g_end, 1109227825Stheraven __atoms)) 1110227825Stheraven break; 1111227825Stheraven if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) 1112227825Stheraven *__g_end++ = __dc; 1113227825Stheraven // Stage 3 1114227825Stheraven __v = __num_get_unsigned_integral<unsigned long>(__a, __a_end, __err, __base); 1115227825Stheraven // Digit grouping checked 1116227825Stheraven __check_grouping(__grouping, __g, __g_end, __err); 1117227825Stheraven // EOF checked 1118227825Stheraven if (__b == __e) 1119227825Stheraven __err |= ios_base::eofbit; 1120227825Stheraven return __b; 1121227825Stheraven} 1122227825Stheraven 1123227825Stheraventemplate <class _CharT, class _InputIterator> 1124227825Stheraven_InputIterator 1125227825Stheravennum_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, 1126227825Stheraven ios_base& __iob, 1127227825Stheraven ios_base::iostate& __err, 1128227825Stheraven unsigned long long& __v) const 1129227825Stheraven{ 1130227825Stheraven // Stage 1 1131227825Stheraven int __base = this->__get_base(__iob); 1132227825Stheraven // Stage 2 1133227825Stheraven char_type __atoms[26]; 1134227825Stheraven char_type __thousands_sep; 1135227825Stheraven string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); 1136227825Stheraven char __a[__num_get_base::__num_get_buf_sz] = {0}; 1137227825Stheraven char* __a_end = __a; 1138227825Stheraven unsigned __g[__num_get_base::__num_get_buf_sz]; 1139227825Stheraven unsigned* __g_end = __g; 1140227825Stheraven unsigned __dc = 0; 1141227825Stheraven for (; __b != __e; ++__b) 1142227825Stheraven if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, 1143227825Stheraven __thousands_sep, __grouping, __g, __g_end, 1144227825Stheraven __atoms)) 1145227825Stheraven break; 1146227825Stheraven if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) 1147227825Stheraven *__g_end++ = __dc; 1148227825Stheraven // Stage 3 1149227825Stheraven __v = __num_get_unsigned_integral<unsigned long long>(__a, __a_end, __err, __base); 1150227825Stheraven // Digit grouping checked 1151227825Stheraven __check_grouping(__grouping, __g, __g_end, __err); 1152227825Stheraven // EOF checked 1153227825Stheraven if (__b == __e) 1154227825Stheraven __err |= ios_base::eofbit; 1155227825Stheraven return __b; 1156227825Stheraven} 1157227825Stheraven 1158227825Stheraventemplate <class _CharT, class _InputIterator> 1159227825Stheraven_InputIterator 1160227825Stheravennum_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, 1161227825Stheraven ios_base& __iob, 1162227825Stheraven ios_base::iostate& __err, 1163227825Stheraven float& __v) const 1164227825Stheraven{ 1165227825Stheraven // Stage 1, nothing to do 1166227825Stheraven // Stage 2 1167227825Stheraven char_type __atoms[32]; 1168227825Stheraven char_type __decimal_point; 1169227825Stheraven char_type __thousands_sep; 1170227825Stheraven string __grouping = this->__stage2_float_prep(__iob, __atoms, 1171227825Stheraven __decimal_point, 1172227825Stheraven __thousands_sep); 1173227825Stheraven char __a[__num_get_base::__num_get_buf_sz] = {0}; 1174227825Stheraven char* __a_end = __a; 1175227825Stheraven unsigned __g[__num_get_base::__num_get_buf_sz]; 1176227825Stheraven unsigned* __g_end = __g; 1177227825Stheraven unsigned __dc = 0; 1178227825Stheraven bool __in_units = true; 1179227825Stheraven char __exp = 'E'; 1180227825Stheraven for (; __b != __e; ++__b) 1181227825Stheraven if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end, 1182227825Stheraven __decimal_point, __thousands_sep, 1183227825Stheraven __grouping, __g, __g_end, 1184227825Stheraven __dc, __atoms)) 1185227825Stheraven break; 1186227825Stheraven if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz) 1187227825Stheraven *__g_end++ = __dc; 1188227825Stheraven // Stage 3 1189227825Stheraven __v = __num_get_float<float>(__a, __a_end, __err); 1190227825Stheraven // Digit grouping checked 1191227825Stheraven __check_grouping(__grouping, __g, __g_end, __err); 1192227825Stheraven // EOF checked 1193227825Stheraven if (__b == __e) 1194227825Stheraven __err |= ios_base::eofbit; 1195227825Stheraven return __b; 1196227825Stheraven} 1197227825Stheraven 1198227825Stheraventemplate <class _CharT, class _InputIterator> 1199227825Stheraven_InputIterator 1200227825Stheravennum_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, 1201227825Stheraven ios_base& __iob, 1202227825Stheraven ios_base::iostate& __err, 1203227825Stheraven double& __v) const 1204227825Stheraven{ 1205227825Stheraven // Stage 1, nothing to do 1206227825Stheraven // Stage 2 1207227825Stheraven char_type __atoms[32]; 1208227825Stheraven char_type __decimal_point; 1209227825Stheraven char_type __thousands_sep; 1210227825Stheraven string __grouping = this->__stage2_float_prep(__iob, __atoms, 1211227825Stheraven __decimal_point, 1212227825Stheraven __thousands_sep); 1213227825Stheraven char __a[__num_get_base::__num_get_buf_sz] = {0}; 1214227825Stheraven char* __a_end = __a; 1215227825Stheraven unsigned __g[__num_get_base::__num_get_buf_sz]; 1216227825Stheraven unsigned* __g_end = __g; 1217227825Stheraven unsigned __dc = 0; 1218227825Stheraven bool __in_units = true; 1219227825Stheraven char __exp = 'E'; 1220227825Stheraven for (; __b != __e; ++__b) 1221227825Stheraven if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end, 1222227825Stheraven __decimal_point, __thousands_sep, 1223227825Stheraven __grouping, __g, __g_end, 1224227825Stheraven __dc, __atoms)) 1225227825Stheraven break; 1226227825Stheraven if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz) 1227227825Stheraven *__g_end++ = __dc; 1228227825Stheraven // Stage 3 1229227825Stheraven __v = __num_get_float<double>(__a, __a_end, __err); 1230227825Stheraven // Digit grouping checked 1231227825Stheraven __check_grouping(__grouping, __g, __g_end, __err); 1232227825Stheraven // EOF checked 1233227825Stheraven if (__b == __e) 1234227825Stheraven __err |= ios_base::eofbit; 1235227825Stheraven return __b; 1236227825Stheraven} 1237227825Stheraven 1238227825Stheraventemplate <class _CharT, class _InputIterator> 1239227825Stheraven_InputIterator 1240227825Stheravennum_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, 1241227825Stheraven ios_base& __iob, 1242227825Stheraven ios_base::iostate& __err, 1243227825Stheraven long double& __v) const 1244227825Stheraven{ 1245227825Stheraven // Stage 1, nothing to do 1246227825Stheraven // Stage 2 1247227825Stheraven char_type __atoms[32]; 1248227825Stheraven char_type __decimal_point; 1249227825Stheraven char_type __thousands_sep; 1250227825Stheraven string __grouping = this->__stage2_float_prep(__iob, __atoms, 1251227825Stheraven __decimal_point, 1252227825Stheraven __thousands_sep); 1253227825Stheraven char __a[__num_get_base::__num_get_buf_sz] = {0}; 1254227825Stheraven char* __a_end = __a; 1255227825Stheraven unsigned __g[__num_get_base::__num_get_buf_sz]; 1256227825Stheraven unsigned* __g_end = __g; 1257227825Stheraven unsigned __dc = 0; 1258227825Stheraven bool __in_units = true; 1259227825Stheraven char __exp = 'E'; 1260227825Stheraven for (; __b != __e; ++__b) 1261227825Stheraven if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end, 1262227825Stheraven __decimal_point, __thousands_sep, 1263227825Stheraven __grouping, __g, __g_end, 1264227825Stheraven __dc, __atoms)) 1265227825Stheraven break; 1266227825Stheraven if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz) 1267227825Stheraven *__g_end++ = __dc; 1268227825Stheraven // Stage 3 1269227825Stheraven __v = __num_get_float<long double>(__a, __a_end, __err); 1270227825Stheraven // Digit grouping checked 1271227825Stheraven __check_grouping(__grouping, __g, __g_end, __err); 1272227825Stheraven // EOF checked 1273227825Stheraven if (__b == __e) 1274227825Stheraven __err |= ios_base::eofbit; 1275227825Stheraven return __b; 1276227825Stheraven} 1277227825Stheraven 1278227825Stheraventemplate <class _CharT, class _InputIterator> 1279227825Stheraven_InputIterator 1280227825Stheravennum_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, 1281227825Stheraven ios_base& __iob, 1282227825Stheraven ios_base::iostate& __err, 1283227825Stheraven void*& __v) const 1284227825Stheraven{ 1285227825Stheraven // Stage 1 1286227825Stheraven int __base = 16; 1287227825Stheraven // Stage 2 1288227825Stheraven char_type __atoms[26]; 1289232950Stheraven char_type __thousands_sep = 0; 1290227825Stheraven string __grouping; 1291227825Stheraven use_facet<ctype<_CharT> >(__iob.getloc()).widen(__num_get_base::__src, 1292227825Stheraven __num_get_base::__src + 26, __atoms); 1293227825Stheraven char __a[__num_get_base::__num_get_buf_sz] = {0}; 1294227825Stheraven char* __a_end = __a; 1295227825Stheraven unsigned __g[__num_get_base::__num_get_buf_sz]; 1296227825Stheraven unsigned* __g_end = __g; 1297227825Stheraven unsigned __dc = 0; 1298227825Stheraven for (; __b != __e; ++__b) 1299227825Stheraven if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, 1300227825Stheraven __thousands_sep, __grouping, 1301227825Stheraven __g, __g_end, __atoms)) 1302227825Stheraven break; 1303227825Stheraven // Stage 3 1304227825Stheraven __a[sizeof(__a)-1] = 0; 1305227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 1306227825Stheraven if (sscanf_l(__a, _LIBCPP_GET_C_LOCALE, "%p", &__v) != 1) 1307227825Stheraven#else 1308227825Stheraven if (__sscanf_l(__a, __cloc(), "%p", &__v) != 1) 1309227825Stheraven#endif 1310227825Stheraven __err = ios_base::failbit; 1311227825Stheraven // EOF checked 1312227825Stheraven if (__b == __e) 1313227825Stheraven __err |= ios_base::eofbit; 1314227825Stheraven return __b; 1315227825Stheraven} 1316227825Stheraven 1317242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class num_get<char>) 1318242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class num_get<wchar_t>) 1319227825Stheraven 1320227825Stheravenstruct __num_put_base 1321227825Stheraven{ 1322227825Stheravenprotected: 1323227825Stheraven static void __format_int(char* __fmt, const char* __len, bool __signd, 1324227825Stheraven ios_base::fmtflags __flags); 1325227825Stheraven static bool __format_float(char* __fmt, const char* __len, 1326227825Stheraven ios_base::fmtflags __flags); 1327227825Stheraven static char* __identify_padding(char* __nb, char* __ne, 1328227825Stheraven const ios_base& __iob); 1329227825Stheraven}; 1330227825Stheraven 1331227825Stheraventemplate <class _CharT> 1332227825Stheravenstruct __num_put 1333227825Stheraven : protected __num_put_base 1334227825Stheraven{ 1335227825Stheraven static void __widen_and_group_int(char* __nb, char* __np, char* __ne, 1336227825Stheraven _CharT* __ob, _CharT*& __op, _CharT*& __oe, 1337227825Stheraven const locale& __loc); 1338227825Stheraven static void __widen_and_group_float(char* __nb, char* __np, char* __ne, 1339227825Stheraven _CharT* __ob, _CharT*& __op, _CharT*& __oe, 1340227825Stheraven const locale& __loc); 1341227825Stheraven}; 1342227825Stheraven 1343227825Stheraventemplate <class _CharT> 1344227825Stheravenvoid 1345227825Stheraven__num_put<_CharT>::__widen_and_group_int(char* __nb, char* __np, char* __ne, 1346227825Stheraven _CharT* __ob, _CharT*& __op, _CharT*& __oe, 1347227825Stheraven const locale& __loc) 1348227825Stheraven{ 1349227825Stheraven const ctype<_CharT>& __ct = use_facet<ctype<_CharT> > (__loc); 1350227825Stheraven const numpunct<_CharT>& __npt = use_facet<numpunct<_CharT> >(__loc); 1351227825Stheraven string __grouping = __npt.grouping(); 1352227825Stheraven if (__grouping.empty()) 1353227825Stheraven { 1354227825Stheraven __ct.widen(__nb, __ne, __ob); 1355227825Stheraven __oe = __ob + (__ne - __nb); 1356227825Stheraven } 1357227825Stheraven else 1358227825Stheraven { 1359227825Stheraven __oe = __ob; 1360227825Stheraven char* __nf = __nb; 1361227825Stheraven if (*__nf == '-' || *__nf == '+') 1362227825Stheraven *__oe++ = __ct.widen(*__nf++); 1363227825Stheraven if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' || 1364227825Stheraven __nf[1] == 'X')) 1365227825Stheraven { 1366227825Stheraven *__oe++ = __ct.widen(*__nf++); 1367227825Stheraven *__oe++ = __ct.widen(*__nf++); 1368227825Stheraven } 1369227825Stheraven reverse(__nf, __ne); 1370227825Stheraven _CharT __thousands_sep = __npt.thousands_sep(); 1371227825Stheraven unsigned __dc = 0; 1372227825Stheraven unsigned __dg = 0; 1373227825Stheraven for (char* __p = __nf; __p < __ne; ++__p) 1374227825Stheraven { 1375227825Stheraven if (static_cast<unsigned>(__grouping[__dg]) > 0 && 1376227825Stheraven __dc == static_cast<unsigned>(__grouping[__dg])) 1377227825Stheraven { 1378227825Stheraven *__oe++ = __thousands_sep; 1379227825Stheraven __dc = 0; 1380227825Stheraven if (__dg < __grouping.size()-1) 1381227825Stheraven ++__dg; 1382227825Stheraven } 1383227825Stheraven *__oe++ = __ct.widen(*__p); 1384227825Stheraven ++__dc; 1385227825Stheraven } 1386227825Stheraven reverse(__ob + (__nf - __nb), __oe); 1387227825Stheraven } 1388227825Stheraven if (__np == __ne) 1389227825Stheraven __op = __oe; 1390227825Stheraven else 1391227825Stheraven __op = __ob + (__np - __nb); 1392227825Stheraven} 1393227825Stheraven 1394227825Stheraventemplate <class _CharT> 1395227825Stheravenvoid 1396227825Stheraven__num_put<_CharT>::__widen_and_group_float(char* __nb, char* __np, char* __ne, 1397227825Stheraven _CharT* __ob, _CharT*& __op, _CharT*& __oe, 1398227825Stheraven const locale& __loc) 1399227825Stheraven{ 1400227825Stheraven const ctype<_CharT>& __ct = use_facet<ctype<_CharT> > (__loc); 1401227825Stheraven const numpunct<_CharT>& __npt = use_facet<numpunct<_CharT> >(__loc); 1402227825Stheraven string __grouping = __npt.grouping(); 1403227825Stheraven __oe = __ob; 1404227825Stheraven char* __nf = __nb; 1405227825Stheraven if (*__nf == '-' || *__nf == '+') 1406227825Stheraven *__oe++ = __ct.widen(*__nf++); 1407227825Stheraven char* __ns; 1408227825Stheraven if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' || 1409227825Stheraven __nf[1] == 'X')) 1410227825Stheraven { 1411227825Stheraven *__oe++ = __ct.widen(*__nf++); 1412227825Stheraven *__oe++ = __ct.widen(*__nf++); 1413227825Stheraven for (__ns = __nf; __ns < __ne; ++__ns) 1414227825Stheraven if (!isxdigit_l(*__ns, _LIBCPP_GET_C_LOCALE)) 1415227825Stheraven break; 1416227825Stheraven } 1417227825Stheraven else 1418227825Stheraven { 1419227825Stheraven for (__ns = __nf; __ns < __ne; ++__ns) 1420227825Stheraven if (!isdigit_l(*__ns, _LIBCPP_GET_C_LOCALE)) 1421227825Stheraven break; 1422227825Stheraven } 1423227825Stheraven if (__grouping.empty()) 1424227825Stheraven { 1425227825Stheraven __ct.widen(__nf, __ns, __oe); 1426227825Stheraven __oe += __ns - __nf; 1427227825Stheraven } 1428227825Stheraven else 1429227825Stheraven { 1430227825Stheraven reverse(__nf, __ns); 1431227825Stheraven _CharT __thousands_sep = __npt.thousands_sep(); 1432227825Stheraven unsigned __dc = 0; 1433227825Stheraven unsigned __dg = 0; 1434227825Stheraven for (char* __p = __nf; __p < __ns; ++__p) 1435227825Stheraven { 1436227825Stheraven if (__grouping[__dg] > 0 && __dc == static_cast<unsigned>(__grouping[__dg])) 1437227825Stheraven { 1438227825Stheraven *__oe++ = __thousands_sep; 1439227825Stheraven __dc = 0; 1440227825Stheraven if (__dg < __grouping.size()-1) 1441227825Stheraven ++__dg; 1442227825Stheraven } 1443227825Stheraven *__oe++ = __ct.widen(*__p); 1444227825Stheraven ++__dc; 1445227825Stheraven } 1446227825Stheraven reverse(__ob + (__nf - __nb), __oe); 1447227825Stheraven } 1448227825Stheraven for (__nf = __ns; __nf < __ne; ++__nf) 1449227825Stheraven { 1450227825Stheraven if (*__nf == '.') 1451227825Stheraven { 1452227825Stheraven *__oe++ = __npt.decimal_point(); 1453227825Stheraven ++__nf; 1454227825Stheraven break; 1455227825Stheraven } 1456227825Stheraven else 1457227825Stheraven *__oe++ = __ct.widen(*__nf); 1458227825Stheraven } 1459227825Stheraven __ct.widen(__nf, __ne, __oe); 1460227825Stheraven __oe += __ne - __nf; 1461227825Stheraven if (__np == __ne) 1462227825Stheraven __op = __oe; 1463227825Stheraven else 1464227825Stheraven __op = __ob + (__np - __nb); 1465227825Stheraven} 1466227825Stheraven 1467242945Stheraven_LIBCPP_EXTERN_TEMPLATE(struct __num_put<char>) 1468242945Stheraven_LIBCPP_EXTERN_TEMPLATE(struct __num_put<wchar_t>) 1469227825Stheraven 1470227825Stheraventemplate <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> > 1471227825Stheravenclass _LIBCPP_VISIBLE num_put 1472227825Stheraven : public locale::facet, 1473227825Stheraven private __num_put<_CharT> 1474227825Stheraven{ 1475227825Stheravenpublic: 1476227825Stheraven typedef _CharT char_type; 1477227825Stheraven typedef _OutputIterator iter_type; 1478227825Stheraven 1479227825Stheraven _LIBCPP_ALWAYS_INLINE 1480227825Stheraven explicit num_put(size_t __refs = 0) 1481227825Stheraven : locale::facet(__refs) {} 1482227825Stheraven 1483227825Stheraven _LIBCPP_ALWAYS_INLINE 1484227825Stheraven iter_type put(iter_type __s, ios_base& __iob, char_type __fl, 1485227825Stheraven bool __v) const 1486227825Stheraven { 1487227825Stheraven return do_put(__s, __iob, __fl, __v); 1488227825Stheraven } 1489227825Stheraven 1490227825Stheraven _LIBCPP_ALWAYS_INLINE 1491227825Stheraven iter_type put(iter_type __s, ios_base& __iob, char_type __fl, 1492227825Stheraven long __v) const 1493227825Stheraven { 1494227825Stheraven return do_put(__s, __iob, __fl, __v); 1495227825Stheraven } 1496227825Stheraven 1497227825Stheraven _LIBCPP_ALWAYS_INLINE 1498227825Stheraven iter_type put(iter_type __s, ios_base& __iob, char_type __fl, 1499227825Stheraven long long __v) const 1500227825Stheraven { 1501227825Stheraven return do_put(__s, __iob, __fl, __v); 1502227825Stheraven } 1503227825Stheraven 1504227825Stheraven _LIBCPP_ALWAYS_INLINE 1505227825Stheraven iter_type put(iter_type __s, ios_base& __iob, char_type __fl, 1506227825Stheraven unsigned long __v) const 1507227825Stheraven { 1508227825Stheraven return do_put(__s, __iob, __fl, __v); 1509227825Stheraven } 1510227825Stheraven 1511227825Stheraven _LIBCPP_ALWAYS_INLINE 1512227825Stheraven iter_type put(iter_type __s, ios_base& __iob, char_type __fl, 1513227825Stheraven unsigned long long __v) const 1514227825Stheraven { 1515227825Stheraven return do_put(__s, __iob, __fl, __v); 1516227825Stheraven } 1517227825Stheraven 1518227825Stheraven _LIBCPP_ALWAYS_INLINE 1519227825Stheraven iter_type put(iter_type __s, ios_base& __iob, char_type __fl, 1520227825Stheraven double __v) const 1521227825Stheraven { 1522227825Stheraven return do_put(__s, __iob, __fl, __v); 1523227825Stheraven } 1524227825Stheraven 1525227825Stheraven _LIBCPP_ALWAYS_INLINE 1526227825Stheraven iter_type put(iter_type __s, ios_base& __iob, char_type __fl, 1527227825Stheraven long double __v) const 1528227825Stheraven { 1529227825Stheraven return do_put(__s, __iob, __fl, __v); 1530227825Stheraven } 1531227825Stheraven 1532227825Stheraven _LIBCPP_ALWAYS_INLINE 1533227825Stheraven iter_type put(iter_type __s, ios_base& __iob, char_type __fl, 1534227825Stheraven const void* __v) const 1535227825Stheraven { 1536227825Stheraven return do_put(__s, __iob, __fl, __v); 1537227825Stheraven } 1538227825Stheraven 1539227825Stheraven static locale::id id; 1540227825Stheraven 1541227825Stheravenprotected: 1542227825Stheraven _LIBCPP_ALWAYS_INLINE 1543227825Stheraven ~num_put() {} 1544227825Stheraven 1545227825Stheraven virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, 1546227825Stheraven bool __v) const; 1547227825Stheraven virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, 1548227825Stheraven long __v) const; 1549227825Stheraven virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, 1550227825Stheraven long long __v) const; 1551227825Stheraven virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, 1552227825Stheraven unsigned long) const; 1553227825Stheraven virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, 1554227825Stheraven unsigned long long) const; 1555227825Stheraven virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, 1556227825Stheraven double __v) const; 1557227825Stheraven virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, 1558227825Stheraven long double __v) const; 1559227825Stheraven virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, 1560227825Stheraven const void* __v) const; 1561227825Stheraven}; 1562227825Stheraven 1563227825Stheraventemplate <class _CharT, class _OutputIterator> 1564227825Stheravenlocale::id 1565227825Stheravennum_put<_CharT, _OutputIterator>::id; 1566227825Stheraven 1567227825Stheraventemplate <class _CharT, class _OutputIterator> 1568227825Stheraven_LIBCPP_HIDDEN 1569227825Stheraven_OutputIterator 1570227825Stheraven__pad_and_output(_OutputIterator __s, 1571227825Stheraven const _CharT* __ob, const _CharT* __op, const _CharT* __oe, 1572227825Stheraven ios_base& __iob, _CharT __fl) 1573227825Stheraven{ 1574227825Stheraven streamsize __sz = __oe - __ob; 1575227825Stheraven streamsize __ns = __iob.width(); 1576227825Stheraven if (__ns > __sz) 1577227825Stheraven __ns -= __sz; 1578227825Stheraven else 1579227825Stheraven __ns = 0; 1580227825Stheraven for (;__ob < __op; ++__ob, ++__s) 1581227825Stheraven *__s = *__ob; 1582227825Stheraven for (; __ns; --__ns, ++__s) 1583227825Stheraven *__s = __fl; 1584227825Stheraven for (; __ob < __oe; ++__ob, ++__s) 1585227825Stheraven *__s = *__ob; 1586227825Stheraven __iob.width(0); 1587227825Stheraven return __s; 1588227825Stheraven} 1589227825Stheraven 1590241903Sdimtemplate <class _CharT, class _Traits> 1591241903Sdim_LIBCPP_HIDDEN 1592241903Sdimostreambuf_iterator<_CharT, _Traits> 1593241903Sdim__pad_and_output(ostreambuf_iterator<_CharT, _Traits> __s, 1594241903Sdim const _CharT* __ob, const _CharT* __op, const _CharT* __oe, 1595241903Sdim ios_base& __iob, _CharT __fl) 1596241903Sdim{ 1597241903Sdim if (__s.__sbuf_ == nullptr) 1598241903Sdim return __s; 1599241903Sdim streamsize __sz = __oe - __ob; 1600241903Sdim streamsize __ns = __iob.width(); 1601241903Sdim if (__ns > __sz) 1602241903Sdim __ns -= __sz; 1603241903Sdim else 1604241903Sdim __ns = 0; 1605241903Sdim streamsize __np = __op - __ob; 1606241903Sdim if (__np > 0) 1607241903Sdim { 1608241903Sdim if (__s.__sbuf_->sputn(__ob, __np) != __np) 1609241903Sdim { 1610241903Sdim __s.__sbuf_ = nullptr; 1611241903Sdim return __s; 1612241903Sdim } 1613241903Sdim } 1614241903Sdim if (__ns > 0) 1615241903Sdim { 1616241903Sdim basic_string<_CharT, _Traits> __sp(__ns, __fl); 1617241903Sdim if (__s.__sbuf_->sputn(__sp.data(), __ns) != __ns) 1618241903Sdim { 1619241903Sdim __s.__sbuf_ = nullptr; 1620241903Sdim return __s; 1621241903Sdim } 1622241903Sdim } 1623241903Sdim __np = __oe - __op; 1624241903Sdim if (__np > 0) 1625241903Sdim { 1626241903Sdim if (__s.__sbuf_->sputn(__op, __np) != __np) 1627241903Sdim { 1628241903Sdim __s.__sbuf_ = nullptr; 1629241903Sdim return __s; 1630241903Sdim } 1631241903Sdim } 1632241903Sdim __iob.width(0); 1633241903Sdim return __s; 1634241903Sdim} 1635241903Sdim 1636227825Stheraventemplate <class _CharT, class _OutputIterator> 1637227825Stheraven_OutputIterator 1638227825Stheravennum_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, 1639227825Stheraven char_type __fl, bool __v) const 1640227825Stheraven{ 1641227825Stheraven if ((__iob.flags() & ios_base::boolalpha) == 0) 1642227825Stheraven return do_put(__s, __iob, __fl, (unsigned long)__v); 1643227825Stheraven const numpunct<char_type>& __np = use_facet<numpunct<char_type> >(__iob.getloc()); 1644227825Stheraven typedef typename numpunct<char_type>::string_type string_type; 1645227825Stheraven string_type __nm = __v ? __np.truename() : __np.falsename(); 1646227825Stheraven for (typename string_type::iterator __i = __nm.begin(); __i != __nm.end(); ++__i, ++__s) 1647227825Stheraven *__s = *__i; 1648227825Stheraven return __s; 1649227825Stheraven} 1650227825Stheraven 1651227825Stheraventemplate <class _CharT, class _OutputIterator> 1652227825Stheraven_OutputIterator 1653227825Stheravennum_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, 1654227825Stheraven char_type __fl, long __v) const 1655227825Stheraven{ 1656227825Stheraven // Stage 1 - Get number in narrow char 1657227825Stheraven char __fmt[6] = {'%', 0}; 1658227825Stheraven const char* __len = "l"; 1659227825Stheraven this->__format_int(__fmt+1, __len, true, __iob.flags()); 1660227825Stheraven const unsigned __nbuf = (numeric_limits<long>::digits / 3) 1661227825Stheraven + ((numeric_limits<long>::digits % 3) != 0) 1662227825Stheraven + 1; 1663227825Stheraven char __nar[__nbuf]; 1664227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 1665227825Stheraven int __nc = sprintf_l(__nar, _LIBCPP_GET_C_LOCALE, __fmt, __v); 1666227825Stheraven#else 1667227825Stheraven int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v); 1668227825Stheraven#endif 1669227825Stheraven char* __ne = __nar + __nc; 1670227825Stheraven char* __np = this->__identify_padding(__nar, __ne, __iob); 1671227825Stheraven // Stage 2 - Widen __nar while adding thousands separators 1672227825Stheraven char_type __o[2*(__nbuf-1) - 1]; 1673227825Stheraven char_type* __op; // pad here 1674227825Stheraven char_type* __oe; // end of output 1675227825Stheraven this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc()); 1676227825Stheraven // [__o, __oe) contains thousands_sep'd wide number 1677227825Stheraven // Stage 3 & 4 1678227825Stheraven return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); 1679227825Stheraven} 1680227825Stheraven 1681227825Stheraventemplate <class _CharT, class _OutputIterator> 1682227825Stheraven_OutputIterator 1683227825Stheravennum_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, 1684227825Stheraven char_type __fl, long long __v) const 1685227825Stheraven{ 1686227825Stheraven // Stage 1 - Get number in narrow char 1687227825Stheraven char __fmt[8] = {'%', 0}; 1688227825Stheraven const char* __len = "ll"; 1689227825Stheraven this->__format_int(__fmt+1, __len, true, __iob.flags()); 1690227825Stheraven const unsigned __nbuf = (numeric_limits<long long>::digits / 3) 1691227825Stheraven + ((numeric_limits<long long>::digits % 3) != 0) 1692227825Stheraven + 1; 1693227825Stheraven char __nar[__nbuf]; 1694227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 1695227825Stheraven int __nc = sprintf_l(__nar, _LIBCPP_GET_C_LOCALE, __fmt, __v); 1696227825Stheraven#else 1697227825Stheraven int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v); 1698227825Stheraven#endif 1699227825Stheraven char* __ne = __nar + __nc; 1700227825Stheraven char* __np = this->__identify_padding(__nar, __ne, __iob); 1701227825Stheraven // Stage 2 - Widen __nar while adding thousands separators 1702227825Stheraven char_type __o[2*(__nbuf-1) - 1]; 1703227825Stheraven char_type* __op; // pad here 1704227825Stheraven char_type* __oe; // end of output 1705227825Stheraven this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc()); 1706227825Stheraven // [__o, __oe) contains thousands_sep'd wide number 1707227825Stheraven // Stage 3 & 4 1708227825Stheraven return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); 1709227825Stheraven} 1710227825Stheraven 1711227825Stheraventemplate <class _CharT, class _OutputIterator> 1712227825Stheraven_OutputIterator 1713227825Stheravennum_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, 1714227825Stheraven char_type __fl, unsigned long __v) const 1715227825Stheraven{ 1716227825Stheraven // Stage 1 - Get number in narrow char 1717227825Stheraven char __fmt[6] = {'%', 0}; 1718227825Stheraven const char* __len = "l"; 1719227825Stheraven this->__format_int(__fmt+1, __len, false, __iob.flags()); 1720227825Stheraven const unsigned __nbuf = (numeric_limits<unsigned long>::digits / 3) 1721227825Stheraven + ((numeric_limits<unsigned long>::digits % 3) != 0) 1722227825Stheraven + 1; 1723227825Stheraven char __nar[__nbuf]; 1724227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 1725227825Stheraven int __nc = sprintf_l(__nar, _LIBCPP_GET_C_LOCALE, __fmt, __v); 1726227825Stheraven#else 1727227825Stheraven int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v); 1728227825Stheraven#endif 1729227825Stheraven char* __ne = __nar + __nc; 1730227825Stheraven char* __np = this->__identify_padding(__nar, __ne, __iob); 1731227825Stheraven // Stage 2 - Widen __nar while adding thousands separators 1732227825Stheraven char_type __o[2*(__nbuf-1) - 1]; 1733227825Stheraven char_type* __op; // pad here 1734227825Stheraven char_type* __oe; // end of output 1735227825Stheraven this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc()); 1736227825Stheraven // [__o, __oe) contains thousands_sep'd wide number 1737227825Stheraven // Stage 3 & 4 1738227825Stheraven return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); 1739227825Stheraven} 1740227825Stheraven 1741227825Stheraventemplate <class _CharT, class _OutputIterator> 1742227825Stheraven_OutputIterator 1743227825Stheravennum_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, 1744227825Stheraven char_type __fl, unsigned long long __v) const 1745227825Stheraven{ 1746227825Stheraven // Stage 1 - Get number in narrow char 1747227825Stheraven char __fmt[8] = {'%', 0}; 1748227825Stheraven const char* __len = "ll"; 1749227825Stheraven this->__format_int(__fmt+1, __len, false, __iob.flags()); 1750227825Stheraven const unsigned __nbuf = (numeric_limits<unsigned long long>::digits / 3) 1751227825Stheraven + ((numeric_limits<unsigned long long>::digits % 3) != 0) 1752227825Stheraven + 1; 1753227825Stheraven char __nar[__nbuf]; 1754227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 1755227825Stheraven int __nc = sprintf_l(__nar, _LIBCPP_GET_C_LOCALE, __fmt, __v); 1756227825Stheraven#else 1757227825Stheraven int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v); 1758227825Stheraven#endif 1759227825Stheraven char* __ne = __nar + __nc; 1760227825Stheraven char* __np = this->__identify_padding(__nar, __ne, __iob); 1761227825Stheraven // Stage 2 - Widen __nar while adding thousands separators 1762227825Stheraven char_type __o[2*(__nbuf-1) - 1]; 1763227825Stheraven char_type* __op; // pad here 1764227825Stheraven char_type* __oe; // end of output 1765227825Stheraven this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc()); 1766227825Stheraven // [__o, __oe) contains thousands_sep'd wide number 1767227825Stheraven // Stage 3 & 4 1768227825Stheraven return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); 1769227825Stheraven} 1770227825Stheraven 1771227825Stheraventemplate <class _CharT, class _OutputIterator> 1772227825Stheraven_OutputIterator 1773227825Stheravennum_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, 1774227825Stheraven char_type __fl, double __v) const 1775227825Stheraven{ 1776227825Stheraven // Stage 1 - Get number in narrow char 1777227825Stheraven char __fmt[8] = {'%', 0}; 1778227825Stheraven const char* __len = ""; 1779227825Stheraven bool __specify_precision = this->__format_float(__fmt+1, __len, __iob.flags()); 1780227825Stheraven const unsigned __nbuf = 30; 1781227825Stheraven char __nar[__nbuf]; 1782227825Stheraven char* __nb = __nar; 1783227825Stheraven int __nc; 1784227825Stheraven if (__specify_precision) 1785227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 1786227825Stheraven __nc = snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, 1787227825Stheraven (int)__iob.precision(), __v); 1788227825Stheraven#else 1789227825Stheraven __nc = __snprintf_l(__nb, __nbuf, __cloc(), __fmt, 1790227825Stheraven (int)__iob.precision(), __v); 1791227825Stheraven#endif 1792227825Stheraven else 1793227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 1794227825Stheraven __nc = snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v); 1795227825Stheraven#else 1796227825Stheraven __nc = __snprintf_l(__nb, __nbuf, __cloc(), __fmt, __v); 1797227825Stheraven#endif 1798227825Stheraven unique_ptr<char, void(*)(void*)> __nbh(0, free); 1799227825Stheraven if (__nc > static_cast<int>(__nbuf-1)) 1800227825Stheraven { 1801227825Stheraven if (__specify_precision) 1802227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 1803227825Stheraven __nc = asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v); 1804227825Stheraven#else 1805227825Stheraven __nc = __asprintf_l(&__nb, __cloc(), __fmt, 1806227825Stheraven (int)__iob.precision(), __v); 1807227825Stheraven#endif 1808227825Stheraven else 1809227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 1810227825Stheraven __nc = asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v); 1811227825Stheraven#else 1812227825Stheraven __nc = __asprintf_l(&__nb, __cloc(), __fmt, (int)__iob.precision(), __v); 1813227825Stheraven#endif 1814227825Stheraven if (__nb == 0) 1815227825Stheraven __throw_bad_alloc(); 1816227825Stheraven __nbh.reset(__nb); 1817227825Stheraven } 1818227825Stheraven char* __ne = __nb + __nc; 1819227825Stheraven char* __np = this->__identify_padding(__nb, __ne, __iob); 1820227825Stheraven // Stage 2 - Widen __nar while adding thousands separators 1821227825Stheraven char_type __o[2*(__nbuf-1) - 1]; 1822227825Stheraven char_type* __ob = __o; 1823227825Stheraven unique_ptr<char_type, void(*)(void*)> __obh(0, free); 1824227825Stheraven if (__nb != __nar) 1825227825Stheraven { 1826232950Stheraven __ob = (char_type*)malloc(2*static_cast<size_t>(__nc)*sizeof(char_type)); 1827227825Stheraven if (__ob == 0) 1828227825Stheraven __throw_bad_alloc(); 1829227825Stheraven __obh.reset(__ob); 1830227825Stheraven } 1831227825Stheraven char_type* __op; // pad here 1832227825Stheraven char_type* __oe; // end of output 1833227825Stheraven this->__widen_and_group_float(__nb, __np, __ne, __ob, __op, __oe, __iob.getloc()); 1834227825Stheraven // [__o, __oe) contains thousands_sep'd wide number 1835227825Stheraven // Stage 3 & 4 1836227825Stheraven __s = __pad_and_output(__s, __ob, __op, __oe, __iob, __fl); 1837227825Stheraven return __s; 1838227825Stheraven} 1839227825Stheraven 1840227825Stheraventemplate <class _CharT, class _OutputIterator> 1841227825Stheraven_OutputIterator 1842227825Stheravennum_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, 1843227825Stheraven char_type __fl, long double __v) const 1844227825Stheraven{ 1845227825Stheraven // Stage 1 - Get number in narrow char 1846227825Stheraven char __fmt[8] = {'%', 0}; 1847227825Stheraven const char* __len = "L"; 1848227825Stheraven bool __specify_precision = this->__format_float(__fmt+1, __len, __iob.flags()); 1849227825Stheraven const unsigned __nbuf = 30; 1850227825Stheraven char __nar[__nbuf]; 1851227825Stheraven char* __nb = __nar; 1852227825Stheraven int __nc; 1853227825Stheraven if (__specify_precision) 1854227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 1855227825Stheraven __nc = snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, 1856227825Stheraven (int)__iob.precision(), __v); 1857227825Stheraven#else 1858227825Stheraven __nc = __snprintf_l(__nb, __nbuf, __cloc(), __fmt, 1859227825Stheraven (int)__iob.precision(), __v); 1860227825Stheraven#endif 1861227825Stheraven else 1862227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 1863227825Stheraven __nc = snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v); 1864227825Stheraven#else 1865227825Stheraven __nc = __snprintf_l(__nb, __nbuf, __cloc(), __fmt, __v); 1866227825Stheraven#endif 1867227825Stheraven unique_ptr<char, void(*)(void*)> __nbh(0, free); 1868227825Stheraven if (__nc > static_cast<int>(__nbuf-1)) 1869227825Stheraven { 1870227825Stheraven if (__specify_precision) 1871227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 1872227825Stheraven __nc = asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v); 1873227825Stheraven#else 1874227825Stheraven __nc = __asprintf_l(&__nb, __cloc(), __fmt, 1875227825Stheraven (int)__iob.precision(), __v); 1876227825Stheraven#endif 1877227825Stheraven else 1878227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 1879227825Stheraven __nc = asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v); 1880227825Stheraven#else 1881227825Stheraven __nc = __asprintf_l(&__nb, __cloc(), __fmt, __v); 1882227825Stheraven#endif 1883227825Stheraven if (__nb == 0) 1884227825Stheraven __throw_bad_alloc(); 1885227825Stheraven __nbh.reset(__nb); 1886227825Stheraven } 1887227825Stheraven char* __ne = __nb + __nc; 1888227825Stheraven char* __np = this->__identify_padding(__nb, __ne, __iob); 1889227825Stheraven // Stage 2 - Widen __nar while adding thousands separators 1890227825Stheraven char_type __o[2*(__nbuf-1) - 1]; 1891227825Stheraven char_type* __ob = __o; 1892227825Stheraven unique_ptr<char_type, void(*)(void*)> __obh(0, free); 1893227825Stheraven if (__nb != __nar) 1894227825Stheraven { 1895232950Stheraven __ob = (char_type*)malloc(2*static_cast<size_t>(__nc)*sizeof(char_type)); 1896227825Stheraven if (__ob == 0) 1897227825Stheraven __throw_bad_alloc(); 1898227825Stheraven __obh.reset(__ob); 1899227825Stheraven } 1900227825Stheraven char_type* __op; // pad here 1901227825Stheraven char_type* __oe; // end of output 1902227825Stheraven this->__widen_and_group_float(__nb, __np, __ne, __ob, __op, __oe, __iob.getloc()); 1903227825Stheraven // [__o, __oe) contains thousands_sep'd wide number 1904227825Stheraven // Stage 3 & 4 1905227825Stheraven __s = __pad_and_output(__s, __ob, __op, __oe, __iob, __fl); 1906227825Stheraven return __s; 1907227825Stheraven} 1908227825Stheraven 1909227825Stheraventemplate <class _CharT, class _OutputIterator> 1910227825Stheraven_OutputIterator 1911227825Stheravennum_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, 1912227825Stheraven char_type __fl, const void* __v) const 1913227825Stheraven{ 1914227825Stheraven // Stage 1 - Get pointer in narrow char 1915227825Stheraven char __fmt[6] = "%p"; 1916227825Stheraven const unsigned __nbuf = 20; 1917227825Stheraven char __nar[__nbuf]; 1918227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 1919227825Stheraven int __nc = sprintf_l(__nar, _LIBCPP_GET_C_LOCALE, __fmt, __v); 1920227825Stheraven#else 1921227825Stheraven int __nc = __sprintf_l(__nar, __cloc(), __fmt, __v); 1922227825Stheraven#endif 1923227825Stheraven char* __ne = __nar + __nc; 1924227825Stheraven char* __np = this->__identify_padding(__nar, __ne, __iob); 1925227825Stheraven // Stage 2 - Widen __nar 1926227825Stheraven char_type __o[2*(__nbuf-1) - 1]; 1927227825Stheraven char_type* __op; // pad here 1928227825Stheraven char_type* __oe; // end of output 1929227825Stheraven const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc()); 1930227825Stheraven __ct.widen(__nar, __ne, __o); 1931227825Stheraven __oe = __o + (__ne - __nar); 1932227825Stheraven if (__np == __ne) 1933227825Stheraven __op = __oe; 1934227825Stheraven else 1935227825Stheraven __op = __o + (__np - __nar); 1936227825Stheraven // [__o, __oe) contains wide number 1937227825Stheraven // Stage 3 & 4 1938227825Stheraven return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); 1939227825Stheraven} 1940227825Stheraven 1941242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class num_put<char>) 1942242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class num_put<wchar_t>) 1943227825Stheraven 1944227825Stheraventemplate <class _CharT, class _InputIterator> 1945227825Stheraven_LIBCPP_HIDDEN 1946227825Stheravenint 1947227825Stheraven__get_up_to_n_digits(_InputIterator& __b, _InputIterator __e, 1948227825Stheraven ios_base::iostate& __err, const ctype<_CharT>& __ct, int __n) 1949227825Stheraven{ 1950227825Stheraven // Precondition: __n >= 1 1951227825Stheraven if (__b == __e) 1952227825Stheraven { 1953227825Stheraven __err |= ios_base::eofbit | ios_base::failbit; 1954227825Stheraven return 0; 1955227825Stheraven } 1956227825Stheraven // get first digit 1957227825Stheraven _CharT __c = *__b; 1958227825Stheraven if (!__ct.is(ctype_base::digit, __c)) 1959227825Stheraven { 1960227825Stheraven __err |= ios_base::failbit; 1961227825Stheraven return 0; 1962227825Stheraven } 1963227825Stheraven int __r = __ct.narrow(__c, 0) - '0'; 1964227825Stheraven for (++__b, --__n; __b != __e && __n > 0; ++__b, --__n) 1965227825Stheraven { 1966227825Stheraven // get next digit 1967227825Stheraven __c = *__b; 1968227825Stheraven if (!__ct.is(ctype_base::digit, __c)) 1969227825Stheraven return __r; 1970227825Stheraven __r = __r * 10 + __ct.narrow(__c, 0) - '0'; 1971227825Stheraven } 1972227825Stheraven if (__b == __e) 1973227825Stheraven __err |= ios_base::eofbit; 1974227825Stheraven return __r; 1975227825Stheraven} 1976227825Stheraven 1977227825Stheravenclass _LIBCPP_VISIBLE time_base 1978227825Stheraven{ 1979227825Stheravenpublic: 1980227825Stheraven enum dateorder {no_order, dmy, mdy, ymd, ydm}; 1981227825Stheraven}; 1982227825Stheraven 1983227825Stheraventemplate <class _CharT> 1984227825Stheravenclass __time_get_c_storage // purposefully not decorated 1985227825Stheraven{ 1986227825Stheravenprotected: 1987227825Stheraven typedef basic_string<_CharT> string_type; 1988227825Stheraven 1989227825Stheraven virtual const string_type* __weeks() const; 1990227825Stheraven virtual const string_type* __months() const; 1991227825Stheraven virtual const string_type* __am_pm() const; 1992227825Stheraven virtual const string_type& __c() const; 1993227825Stheraven virtual const string_type& __r() const; 1994227825Stheraven virtual const string_type& __x() const; 1995227825Stheraven virtual const string_type& __X() const; 1996227825Stheraven}; 1997227825Stheraven 1998227825Stheraventemplate <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> > 1999227825Stheravenclass _LIBCPP_VISIBLE time_get 2000227825Stheraven : public locale::facet, 2001227825Stheraven public time_base, 2002227825Stheraven private __time_get_c_storage<_CharT> 2003227825Stheraven{ 2004227825Stheravenpublic: 2005227825Stheraven typedef _CharT char_type; 2006227825Stheraven typedef _InputIterator iter_type; 2007227825Stheraven typedef time_base::dateorder dateorder; 2008227825Stheraven typedef basic_string<char_type> string_type; 2009227825Stheraven 2010227825Stheraven _LIBCPP_ALWAYS_INLINE 2011227825Stheraven explicit time_get(size_t __refs = 0) 2012227825Stheraven : locale::facet(__refs) {} 2013227825Stheraven 2014227825Stheraven _LIBCPP_ALWAYS_INLINE 2015227825Stheraven dateorder date_order() const 2016227825Stheraven { 2017227825Stheraven return this->do_date_order(); 2018227825Stheraven } 2019227825Stheraven 2020227825Stheraven _LIBCPP_ALWAYS_INLINE 2021227825Stheraven iter_type get_time(iter_type __b, iter_type __e, ios_base& __iob, 2022227825Stheraven ios_base::iostate& __err, tm* __tm) const 2023227825Stheraven { 2024227825Stheraven return do_get_time(__b, __e, __iob, __err, __tm); 2025227825Stheraven } 2026227825Stheraven 2027227825Stheraven _LIBCPP_ALWAYS_INLINE 2028227825Stheraven iter_type get_date(iter_type __b, iter_type __e, ios_base& __iob, 2029227825Stheraven ios_base::iostate& __err, tm* __tm) const 2030227825Stheraven { 2031227825Stheraven return do_get_date(__b, __e, __iob, __err, __tm); 2032227825Stheraven } 2033227825Stheraven 2034227825Stheraven _LIBCPP_ALWAYS_INLINE 2035227825Stheraven iter_type get_weekday(iter_type __b, iter_type __e, ios_base& __iob, 2036227825Stheraven ios_base::iostate& __err, tm* __tm) const 2037227825Stheraven { 2038227825Stheraven return do_get_weekday(__b, __e, __iob, __err, __tm); 2039227825Stheraven } 2040227825Stheraven 2041227825Stheraven _LIBCPP_ALWAYS_INLINE 2042227825Stheraven iter_type get_monthname(iter_type __b, iter_type __e, ios_base& __iob, 2043227825Stheraven ios_base::iostate& __err, tm* __tm) const 2044227825Stheraven { 2045227825Stheraven return do_get_monthname(__b, __e, __iob, __err, __tm); 2046227825Stheraven } 2047227825Stheraven 2048227825Stheraven _LIBCPP_ALWAYS_INLINE 2049227825Stheraven iter_type get_year(iter_type __b, iter_type __e, ios_base& __iob, 2050227825Stheraven ios_base::iostate& __err, tm* __tm) const 2051227825Stheraven { 2052227825Stheraven return do_get_year(__b, __e, __iob, __err, __tm); 2053227825Stheraven } 2054227825Stheraven 2055227825Stheraven _LIBCPP_ALWAYS_INLINE 2056227825Stheraven iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 2057227825Stheraven ios_base::iostate& __err, tm *__tm, 2058227825Stheraven char __fmt, char __mod = 0) const 2059227825Stheraven { 2060227825Stheraven return do_get(__b, __e, __iob, __err, __tm, __fmt, __mod); 2061227825Stheraven } 2062227825Stheraven 2063227825Stheraven iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 2064227825Stheraven ios_base::iostate& __err, tm* __tm, 2065227825Stheraven const char_type* __fmtb, const char_type* __fmte) const; 2066227825Stheraven 2067227825Stheraven static locale::id id; 2068227825Stheraven 2069227825Stheravenprotected: 2070227825Stheraven _LIBCPP_ALWAYS_INLINE 2071227825Stheraven ~time_get() {} 2072227825Stheraven 2073227825Stheraven virtual dateorder do_date_order() const; 2074227825Stheraven virtual iter_type do_get_time(iter_type __b, iter_type __e, ios_base& __iob, 2075227825Stheraven ios_base::iostate& __err, tm* __tm) const; 2076227825Stheraven virtual iter_type do_get_date(iter_type __b, iter_type __e, ios_base& __iob, 2077227825Stheraven ios_base::iostate& __err, tm* __tm) const; 2078227825Stheraven virtual iter_type do_get_weekday(iter_type __b, iter_type __e, ios_base& __iob, 2079227825Stheraven ios_base::iostate& __err, tm* __tm) const; 2080227825Stheraven virtual iter_type do_get_monthname(iter_type __b, iter_type __e, ios_base& __iob, 2081227825Stheraven ios_base::iostate& __err, tm* __tm) const; 2082227825Stheraven virtual iter_type do_get_year(iter_type __b, iter_type __e, ios_base& __iob, 2083227825Stheraven ios_base::iostate& __err, tm* __tm) const; 2084227825Stheraven virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, 2085227825Stheraven ios_base::iostate& __err, tm* __tm, 2086227825Stheraven char __fmt, char __mod) const; 2087227825Stheravenprivate: 2088227825Stheraven void __get_white_space(iter_type& __b, iter_type __e, 2089227825Stheraven ios_base::iostate& __err, const ctype<char_type>& __ct) const; 2090227825Stheraven void __get_percent(iter_type& __b, iter_type __e, ios_base::iostate& __err, 2091227825Stheraven const ctype<char_type>& __ct) const; 2092227825Stheraven 2093227825Stheraven void __get_weekdayname(int& __m, 2094227825Stheraven iter_type& __b, iter_type __e, 2095227825Stheraven ios_base::iostate& __err, 2096227825Stheraven const ctype<char_type>& __ct) const; 2097227825Stheraven void __get_monthname(int& __m, 2098227825Stheraven iter_type& __b, iter_type __e, 2099227825Stheraven ios_base::iostate& __err, 2100227825Stheraven const ctype<char_type>& __ct) const; 2101227825Stheraven void __get_day(int& __d, 2102227825Stheraven iter_type& __b, iter_type __e, 2103227825Stheraven ios_base::iostate& __err, 2104227825Stheraven const ctype<char_type>& __ct) const; 2105227825Stheraven void __get_month(int& __m, 2106227825Stheraven iter_type& __b, iter_type __e, 2107227825Stheraven ios_base::iostate& __err, 2108227825Stheraven const ctype<char_type>& __ct) const; 2109227825Stheraven void __get_year(int& __y, 2110227825Stheraven iter_type& __b, iter_type __e, 2111227825Stheraven ios_base::iostate& __err, 2112227825Stheraven const ctype<char_type>& __ct) const; 2113227825Stheraven void __get_year4(int& __y, 2114227825Stheraven iter_type& __b, iter_type __e, 2115227825Stheraven ios_base::iostate& __err, 2116227825Stheraven const ctype<char_type>& __ct) const; 2117227825Stheraven void __get_hour(int& __d, 2118227825Stheraven iter_type& __b, iter_type __e, 2119227825Stheraven ios_base::iostate& __err, 2120227825Stheraven const ctype<char_type>& __ct) const; 2121227825Stheraven void __get_12_hour(int& __h, 2122227825Stheraven iter_type& __b, iter_type __e, 2123227825Stheraven ios_base::iostate& __err, 2124227825Stheraven const ctype<char_type>& __ct) const; 2125227825Stheraven void __get_am_pm(int& __h, 2126227825Stheraven iter_type& __b, iter_type __e, 2127227825Stheraven ios_base::iostate& __err, 2128227825Stheraven const ctype<char_type>& __ct) const; 2129227825Stheraven void __get_minute(int& __m, 2130227825Stheraven iter_type& __b, iter_type __e, 2131227825Stheraven ios_base::iostate& __err, 2132227825Stheraven const ctype<char_type>& __ct) const; 2133227825Stheraven void __get_second(int& __s, 2134227825Stheraven iter_type& __b, iter_type __e, 2135227825Stheraven ios_base::iostate& __err, 2136227825Stheraven const ctype<char_type>& __ct) const; 2137227825Stheraven void __get_weekday(int& __w, 2138227825Stheraven iter_type& __b, iter_type __e, 2139227825Stheraven ios_base::iostate& __err, 2140227825Stheraven const ctype<char_type>& __ct) const; 2141227825Stheraven void __get_day_year_num(int& __w, 2142227825Stheraven iter_type& __b, iter_type __e, 2143227825Stheraven ios_base::iostate& __err, 2144227825Stheraven const ctype<char_type>& __ct) const; 2145227825Stheraven}; 2146227825Stheraven 2147227825Stheraventemplate <class _CharT, class _InputIterator> 2148227825Stheravenlocale::id 2149227825Stheraventime_get<_CharT, _InputIterator>::id; 2150227825Stheraven 2151227825Stheraven// time_get primatives 2152227825Stheraven 2153227825Stheraventemplate <class _CharT, class _InputIterator> 2154227825Stheravenvoid 2155227825Stheraventime_get<_CharT, _InputIterator>::__get_weekdayname(int& __w, 2156227825Stheraven iter_type& __b, iter_type __e, 2157227825Stheraven ios_base::iostate& __err, 2158227825Stheraven const ctype<char_type>& __ct) const 2159227825Stheraven{ 2160227825Stheraven // Note: ignoring case comes from the POSIX strptime spec 2161227825Stheraven const string_type* __wk = this->__weeks(); 2162232950Stheraven ptrdiff_t __i = __scan_keyword(__b, __e, __wk, __wk+14, __ct, __err, false) - __wk; 2163227825Stheraven if (__i < 14) 2164227825Stheraven __w = __i % 7; 2165227825Stheraven} 2166227825Stheraven 2167227825Stheraventemplate <class _CharT, class _InputIterator> 2168227825Stheravenvoid 2169227825Stheraventime_get<_CharT, _InputIterator>::__get_monthname(int& __m, 2170227825Stheraven iter_type& __b, iter_type __e, 2171227825Stheraven ios_base::iostate& __err, 2172227825Stheraven const ctype<char_type>& __ct) const 2173227825Stheraven{ 2174227825Stheraven // Note: ignoring case comes from the POSIX strptime spec 2175227825Stheraven const string_type* __month = this->__months(); 2176232950Stheraven ptrdiff_t __i = __scan_keyword(__b, __e, __month, __month+24, __ct, __err, false) - __month; 2177227825Stheraven if (__i < 24) 2178227825Stheraven __m = __i % 12; 2179227825Stheraven} 2180227825Stheraven 2181227825Stheraventemplate <class _CharT, class _InputIterator> 2182227825Stheravenvoid 2183227825Stheraventime_get<_CharT, _InputIterator>::__get_day(int& __d, 2184227825Stheraven iter_type& __b, iter_type __e, 2185227825Stheraven ios_base::iostate& __err, 2186227825Stheraven const ctype<char_type>& __ct) const 2187227825Stheraven{ 2188227825Stheraven int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); 2189227825Stheraven if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 31) 2190227825Stheraven __d = __t; 2191227825Stheraven else 2192227825Stheraven __err |= ios_base::failbit; 2193227825Stheraven} 2194227825Stheraven 2195227825Stheraventemplate <class _CharT, class _InputIterator> 2196227825Stheravenvoid 2197227825Stheraventime_get<_CharT, _InputIterator>::__get_month(int& __m, 2198227825Stheraven iter_type& __b, iter_type __e, 2199227825Stheraven ios_base::iostate& __err, 2200227825Stheraven const ctype<char_type>& __ct) const 2201227825Stheraven{ 2202227825Stheraven int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2) - 1; 2203227825Stheraven if (!(__err & ios_base::failbit) && __t <= 11) 2204227825Stheraven __m = __t; 2205227825Stheraven else 2206227825Stheraven __err |= ios_base::failbit; 2207227825Stheraven} 2208227825Stheraven 2209227825Stheraventemplate <class _CharT, class _InputIterator> 2210227825Stheravenvoid 2211227825Stheraventime_get<_CharT, _InputIterator>::__get_year(int& __y, 2212227825Stheraven iter_type& __b, iter_type __e, 2213227825Stheraven ios_base::iostate& __err, 2214227825Stheraven const ctype<char_type>& __ct) const 2215227825Stheraven{ 2216227825Stheraven int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 4); 2217227825Stheraven if (!(__err & ios_base::failbit)) 2218227825Stheraven { 2219227825Stheraven if (__t < 69) 2220227825Stheraven __t += 2000; 2221227825Stheraven else if (69 <= __t && __t <= 99) 2222227825Stheraven __t += 1900; 2223227825Stheraven __y = __t - 1900; 2224227825Stheraven } 2225227825Stheraven} 2226227825Stheraven 2227227825Stheraventemplate <class _CharT, class _InputIterator> 2228227825Stheravenvoid 2229227825Stheraventime_get<_CharT, _InputIterator>::__get_year4(int& __y, 2230227825Stheraven iter_type& __b, iter_type __e, 2231227825Stheraven ios_base::iostate& __err, 2232227825Stheraven const ctype<char_type>& __ct) const 2233227825Stheraven{ 2234227825Stheraven int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 4); 2235227825Stheraven if (!(__err & ios_base::failbit)) 2236227825Stheraven __y = __t - 1900; 2237227825Stheraven} 2238227825Stheraven 2239227825Stheraventemplate <class _CharT, class _InputIterator> 2240227825Stheravenvoid 2241227825Stheraventime_get<_CharT, _InputIterator>::__get_hour(int& __h, 2242227825Stheraven iter_type& __b, iter_type __e, 2243227825Stheraven ios_base::iostate& __err, 2244227825Stheraven const ctype<char_type>& __ct) const 2245227825Stheraven{ 2246227825Stheraven int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); 2247227825Stheraven if (!(__err & ios_base::failbit) && __t <= 23) 2248227825Stheraven __h = __t; 2249227825Stheraven else 2250227825Stheraven __err |= ios_base::failbit; 2251227825Stheraven} 2252227825Stheraven 2253227825Stheraventemplate <class _CharT, class _InputIterator> 2254227825Stheravenvoid 2255227825Stheraventime_get<_CharT, _InputIterator>::__get_12_hour(int& __h, 2256227825Stheraven iter_type& __b, iter_type __e, 2257227825Stheraven ios_base::iostate& __err, 2258227825Stheraven const ctype<char_type>& __ct) const 2259227825Stheraven{ 2260227825Stheraven int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); 2261227825Stheraven if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 12) 2262227825Stheraven __h = __t; 2263227825Stheraven else 2264227825Stheraven __err |= ios_base::failbit; 2265227825Stheraven} 2266227825Stheraven 2267227825Stheraventemplate <class _CharT, class _InputIterator> 2268227825Stheravenvoid 2269227825Stheraventime_get<_CharT, _InputIterator>::__get_minute(int& __m, 2270227825Stheraven iter_type& __b, iter_type __e, 2271227825Stheraven ios_base::iostate& __err, 2272227825Stheraven const ctype<char_type>& __ct) const 2273227825Stheraven{ 2274227825Stheraven int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); 2275227825Stheraven if (!(__err & ios_base::failbit) && __t <= 59) 2276227825Stheraven __m = __t; 2277227825Stheraven else 2278227825Stheraven __err |= ios_base::failbit; 2279227825Stheraven} 2280227825Stheraven 2281227825Stheraventemplate <class _CharT, class _InputIterator> 2282227825Stheravenvoid 2283227825Stheraventime_get<_CharT, _InputIterator>::__get_second(int& __s, 2284227825Stheraven iter_type& __b, iter_type __e, 2285227825Stheraven ios_base::iostate& __err, 2286227825Stheraven const ctype<char_type>& __ct) const 2287227825Stheraven{ 2288227825Stheraven int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); 2289227825Stheraven if (!(__err & ios_base::failbit) && __t <= 60) 2290227825Stheraven __s = __t; 2291227825Stheraven else 2292227825Stheraven __err |= ios_base::failbit; 2293227825Stheraven} 2294227825Stheraven 2295227825Stheraventemplate <class _CharT, class _InputIterator> 2296227825Stheravenvoid 2297227825Stheraventime_get<_CharT, _InputIterator>::__get_weekday(int& __w, 2298227825Stheraven iter_type& __b, iter_type __e, 2299227825Stheraven ios_base::iostate& __err, 2300227825Stheraven const ctype<char_type>& __ct) const 2301227825Stheraven{ 2302227825Stheraven int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 1); 2303227825Stheraven if (!(__err & ios_base::failbit) && __t <= 6) 2304227825Stheraven __w = __t; 2305227825Stheraven else 2306227825Stheraven __err |= ios_base::failbit; 2307227825Stheraven} 2308227825Stheraven 2309227825Stheraventemplate <class _CharT, class _InputIterator> 2310227825Stheravenvoid 2311227825Stheraventime_get<_CharT, _InputIterator>::__get_day_year_num(int& __d, 2312227825Stheraven iter_type& __b, iter_type __e, 2313227825Stheraven ios_base::iostate& __err, 2314227825Stheraven const ctype<char_type>& __ct) const 2315227825Stheraven{ 2316227825Stheraven int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 3); 2317227825Stheraven if (!(__err & ios_base::failbit) && __t <= 365) 2318227825Stheraven __d = __t; 2319227825Stheraven else 2320227825Stheraven __err |= ios_base::failbit; 2321227825Stheraven} 2322227825Stheraven 2323227825Stheraventemplate <class _CharT, class _InputIterator> 2324227825Stheravenvoid 2325227825Stheraventime_get<_CharT, _InputIterator>::__get_white_space(iter_type& __b, iter_type __e, 2326227825Stheraven ios_base::iostate& __err, 2327227825Stheraven const ctype<char_type>& __ct) const 2328227825Stheraven{ 2329227825Stheraven for (; __b != __e && __ct.is(ctype_base::space, *__b); ++__b) 2330227825Stheraven ; 2331227825Stheraven if (__b == __e) 2332227825Stheraven __err |= ios_base::eofbit; 2333227825Stheraven} 2334227825Stheraven 2335227825Stheraventemplate <class _CharT, class _InputIterator> 2336227825Stheravenvoid 2337227825Stheraventime_get<_CharT, _InputIterator>::__get_am_pm(int& __h, 2338227825Stheraven iter_type& __b, iter_type __e, 2339227825Stheraven ios_base::iostate& __err, 2340227825Stheraven const ctype<char_type>& __ct) const 2341227825Stheraven{ 2342227825Stheraven const string_type* __ap = this->__am_pm(); 2343227825Stheraven if (__ap[0].size() + __ap[1].size() == 0) 2344227825Stheraven { 2345227825Stheraven __err |= ios_base::failbit; 2346227825Stheraven return; 2347227825Stheraven } 2348232950Stheraven ptrdiff_t __i = __scan_keyword(__b, __e, __ap, __ap+2, __ct, __err, false) - __ap; 2349227825Stheraven if (__i == 0 && __h == 12) 2350227825Stheraven __h = 0; 2351227825Stheraven else if (__i == 1 && __h < 12) 2352227825Stheraven __h += 12; 2353227825Stheraven} 2354227825Stheraven 2355227825Stheraventemplate <class _CharT, class _InputIterator> 2356227825Stheravenvoid 2357227825Stheraventime_get<_CharT, _InputIterator>::__get_percent(iter_type& __b, iter_type __e, 2358227825Stheraven ios_base::iostate& __err, 2359227825Stheraven const ctype<char_type>& __ct) const 2360227825Stheraven{ 2361227825Stheraven if (__b == __e) 2362227825Stheraven { 2363227825Stheraven __err |= ios_base::eofbit | ios_base::failbit; 2364227825Stheraven return; 2365227825Stheraven } 2366227825Stheraven if (__ct.narrow(*__b, 0) != '%') 2367227825Stheraven __err |= ios_base::failbit; 2368227825Stheraven else if(++__b == __e) 2369227825Stheraven __err |= ios_base::eofbit; 2370227825Stheraven} 2371227825Stheraven 2372227825Stheraven// time_get end primatives 2373227825Stheraven 2374227825Stheraventemplate <class _CharT, class _InputIterator> 2375227825Stheraven_InputIterator 2376227825Stheraventime_get<_CharT, _InputIterator>::get(iter_type __b, iter_type __e, 2377227825Stheraven ios_base& __iob, 2378227825Stheraven ios_base::iostate& __err, tm* __tm, 2379227825Stheraven const char_type* __fmtb, const char_type* __fmte) const 2380227825Stheraven{ 2381227825Stheraven const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc()); 2382227825Stheraven __err = ios_base::goodbit; 2383227825Stheraven while (__fmtb != __fmte && __err == ios_base::goodbit) 2384227825Stheraven { 2385227825Stheraven if (__b == __e) 2386227825Stheraven { 2387227825Stheraven __err = ios_base::failbit; 2388227825Stheraven break; 2389227825Stheraven } 2390227825Stheraven if (__ct.narrow(*__fmtb, 0) == '%') 2391227825Stheraven { 2392227825Stheraven if (++__fmtb == __fmte) 2393227825Stheraven { 2394227825Stheraven __err = ios_base::failbit; 2395227825Stheraven break; 2396227825Stheraven } 2397227825Stheraven char __cmd = __ct.narrow(*__fmtb, 0); 2398227825Stheraven char __opt = '\0'; 2399227825Stheraven if (__cmd == 'E' || __cmd == '0') 2400227825Stheraven { 2401227825Stheraven if (++__fmtb == __fmte) 2402227825Stheraven { 2403227825Stheraven __err = ios_base::failbit; 2404227825Stheraven break; 2405227825Stheraven } 2406227825Stheraven __opt = __cmd; 2407227825Stheraven __cmd = __ct.narrow(*__fmtb, 0); 2408227825Stheraven } 2409227825Stheraven __b = do_get(__b, __e, __iob, __err, __tm, __cmd, __opt); 2410227825Stheraven ++__fmtb; 2411227825Stheraven } 2412227825Stheraven else if (__ct.is(ctype_base::space, *__fmtb)) 2413227825Stheraven { 2414227825Stheraven for (++__fmtb; __fmtb != __fmte && __ct.is(ctype_base::space, *__fmtb); ++__fmtb) 2415227825Stheraven ; 2416227825Stheraven for ( ; __b != __e && __ct.is(ctype_base::space, *__b); ++__b) 2417227825Stheraven ; 2418227825Stheraven } 2419227825Stheraven else if (__ct.toupper(*__b) == __ct.toupper(*__fmtb)) 2420227825Stheraven { 2421227825Stheraven ++__b; 2422227825Stheraven ++__fmtb; 2423227825Stheraven } 2424227825Stheraven else 2425227825Stheraven __err = ios_base::failbit; 2426227825Stheraven } 2427227825Stheraven if (__b == __e) 2428227825Stheraven __err |= ios_base::eofbit; 2429227825Stheraven return __b; 2430227825Stheraven} 2431227825Stheraven 2432227825Stheraventemplate <class _CharT, class _InputIterator> 2433227825Stheraventypename time_get<_CharT, _InputIterator>::dateorder 2434227825Stheraventime_get<_CharT, _InputIterator>::do_date_order() const 2435227825Stheraven{ 2436227825Stheraven return mdy; 2437227825Stheraven} 2438227825Stheraven 2439227825Stheraventemplate <class _CharT, class _InputIterator> 2440227825Stheraven_InputIterator 2441227825Stheraventime_get<_CharT, _InputIterator>::do_get_time(iter_type __b, iter_type __e, 2442227825Stheraven ios_base& __iob, 2443227825Stheraven ios_base::iostate& __err, 2444227825Stheraven tm* __tm) const 2445227825Stheraven{ 2446227825Stheraven const char_type __fmt[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'}; 2447227825Stheraven return get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0])); 2448227825Stheraven} 2449227825Stheraven 2450227825Stheraventemplate <class _CharT, class _InputIterator> 2451227825Stheraven_InputIterator 2452227825Stheraventime_get<_CharT, _InputIterator>::do_get_date(iter_type __b, iter_type __e, 2453227825Stheraven ios_base& __iob, 2454227825Stheraven ios_base::iostate& __err, 2455227825Stheraven tm* __tm) const 2456227825Stheraven{ 2457227825Stheraven const string_type& __fmt = this->__x(); 2458227825Stheraven return get(__b, __e, __iob, __err, __tm, __fmt.data(), __fmt.data() + __fmt.size()); 2459227825Stheraven} 2460227825Stheraven 2461227825Stheraventemplate <class _CharT, class _InputIterator> 2462227825Stheraven_InputIterator 2463227825Stheraventime_get<_CharT, _InputIterator>::do_get_weekday(iter_type __b, iter_type __e, 2464227825Stheraven ios_base& __iob, 2465227825Stheraven ios_base::iostate& __err, 2466227825Stheraven tm* __tm) const 2467227825Stheraven{ 2468227825Stheraven const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc()); 2469227825Stheraven __get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct); 2470227825Stheraven return __b; 2471227825Stheraven} 2472227825Stheraven 2473227825Stheraventemplate <class _CharT, class _InputIterator> 2474227825Stheraven_InputIterator 2475227825Stheraventime_get<_CharT, _InputIterator>::do_get_monthname(iter_type __b, iter_type __e, 2476227825Stheraven ios_base& __iob, 2477227825Stheraven ios_base::iostate& __err, 2478227825Stheraven tm* __tm) const 2479227825Stheraven{ 2480227825Stheraven const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc()); 2481227825Stheraven __get_monthname(__tm->tm_mon, __b, __e, __err, __ct); 2482227825Stheraven return __b; 2483227825Stheraven} 2484227825Stheraven 2485227825Stheraventemplate <class _CharT, class _InputIterator> 2486227825Stheraven_InputIterator 2487227825Stheraventime_get<_CharT, _InputIterator>::do_get_year(iter_type __b, iter_type __e, 2488227825Stheraven ios_base& __iob, 2489227825Stheraven ios_base::iostate& __err, 2490227825Stheraven tm* __tm) const 2491227825Stheraven{ 2492227825Stheraven const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc()); 2493227825Stheraven __get_year(__tm->tm_year, __b, __e, __err, __ct); 2494227825Stheraven return __b; 2495227825Stheraven} 2496227825Stheraven 2497227825Stheraventemplate <class _CharT, class _InputIterator> 2498227825Stheraven_InputIterator 2499227825Stheraventime_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, 2500227825Stheraven ios_base& __iob, 2501227825Stheraven ios_base::iostate& __err, tm* __tm, 2502227825Stheraven char __fmt, char) const 2503227825Stheraven{ 2504227825Stheraven __err = ios_base::goodbit; 2505227825Stheraven const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc()); 2506227825Stheraven switch (__fmt) 2507227825Stheraven { 2508227825Stheraven case 'a': 2509227825Stheraven case 'A': 2510227825Stheraven __get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct); 2511227825Stheraven break; 2512227825Stheraven case 'b': 2513227825Stheraven case 'B': 2514227825Stheraven case 'h': 2515227825Stheraven __get_monthname(__tm->tm_mon, __b, __e, __err, __ct); 2516227825Stheraven break; 2517227825Stheraven case 'c': 2518227825Stheraven { 2519232950Stheraven const string_type& __fm = this->__c(); 2520232950Stheraven __b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size()); 2521227825Stheraven } 2522227825Stheraven break; 2523227825Stheraven case 'd': 2524227825Stheraven case 'e': 2525227825Stheraven __get_day(__tm->tm_mday, __b, __e, __err, __ct); 2526227825Stheraven break; 2527227825Stheraven case 'D': 2528227825Stheraven { 2529232950Stheraven const char_type __fm[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'}; 2530232950Stheraven __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0])); 2531227825Stheraven } 2532227825Stheraven break; 2533227825Stheraven case 'F': 2534227825Stheraven { 2535232950Stheraven const char_type __fm[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd'}; 2536232950Stheraven __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0])); 2537227825Stheraven } 2538227825Stheraven break; 2539227825Stheraven case 'H': 2540227825Stheraven __get_hour(__tm->tm_hour, __b, __e, __err, __ct); 2541227825Stheraven break; 2542227825Stheraven case 'I': 2543227825Stheraven __get_12_hour(__tm->tm_hour, __b, __e, __err, __ct); 2544227825Stheraven break; 2545227825Stheraven case 'j': 2546227825Stheraven __get_day_year_num(__tm->tm_yday, __b, __e, __err, __ct); 2547227825Stheraven break; 2548227825Stheraven case 'm': 2549227825Stheraven __get_month(__tm->tm_mon, __b, __e, __err, __ct); 2550227825Stheraven break; 2551227825Stheraven case 'M': 2552227825Stheraven __get_minute(__tm->tm_min, __b, __e, __err, __ct); 2553227825Stheraven break; 2554227825Stheraven case 'n': 2555227825Stheraven case 't': 2556227825Stheraven __get_white_space(__b, __e, __err, __ct); 2557227825Stheraven break; 2558227825Stheraven case 'p': 2559227825Stheraven __get_am_pm(__tm->tm_hour, __b, __e, __err, __ct); 2560227825Stheraven break; 2561227825Stheraven case 'r': 2562227825Stheraven { 2563232950Stheraven const char_type __fm[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'}; 2564232950Stheraven __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0])); 2565227825Stheraven } 2566227825Stheraven break; 2567227825Stheraven case 'R': 2568227825Stheraven { 2569232950Stheraven const char_type __fm[] = {'%', 'H', ':', '%', 'M'}; 2570232950Stheraven __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0])); 2571227825Stheraven } 2572227825Stheraven break; 2573227825Stheraven case 'S': 2574227825Stheraven __get_second(__tm->tm_sec, __b, __e, __err, __ct); 2575227825Stheraven break; 2576227825Stheraven case 'T': 2577227825Stheraven { 2578232950Stheraven const char_type __fm[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'}; 2579232950Stheraven __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0])); 2580227825Stheraven } 2581227825Stheraven break; 2582227825Stheraven case 'w': 2583227825Stheraven __get_weekday(__tm->tm_wday, __b, __e, __err, __ct); 2584227825Stheraven break; 2585227825Stheraven case 'x': 2586227825Stheraven return do_get_date(__b, __e, __iob, __err, __tm); 2587227825Stheraven case 'X': 2588227825Stheraven { 2589232950Stheraven const string_type& __fm = this->__X(); 2590232950Stheraven __b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size()); 2591227825Stheraven } 2592227825Stheraven break; 2593227825Stheraven case 'y': 2594227825Stheraven __get_year(__tm->tm_year, __b, __e, __err, __ct); 2595227825Stheraven break; 2596227825Stheraven case 'Y': 2597227825Stheraven __get_year4(__tm->tm_year, __b, __e, __err, __ct); 2598227825Stheraven break; 2599227825Stheraven case '%': 2600227825Stheraven __get_percent(__b, __e, __err, __ct); 2601227825Stheraven break; 2602227825Stheraven default: 2603227825Stheraven __err |= ios_base::failbit; 2604227825Stheraven } 2605227825Stheraven return __b; 2606227825Stheraven} 2607227825Stheraven 2608242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class time_get<char>) 2609242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class time_get<wchar_t>) 2610227825Stheraven 2611227825Stheravenclass __time_get 2612227825Stheraven{ 2613227825Stheravenprotected: 2614227825Stheraven locale_t __loc_; 2615227825Stheraven 2616227825Stheraven __time_get(const char* __nm); 2617227825Stheraven __time_get(const string& __nm); 2618227825Stheraven ~__time_get(); 2619227825Stheraven}; 2620227825Stheraven 2621227825Stheraventemplate <class _CharT> 2622227825Stheravenclass __time_get_storage 2623227825Stheraven : public __time_get 2624227825Stheraven{ 2625227825Stheravenprotected: 2626227825Stheraven typedef basic_string<_CharT> string_type; 2627227825Stheraven 2628227825Stheraven string_type __weeks_[14]; 2629227825Stheraven string_type __months_[24]; 2630227825Stheraven string_type __am_pm_[2]; 2631227825Stheraven string_type __c_; 2632227825Stheraven string_type __r_; 2633227825Stheraven string_type __x_; 2634227825Stheraven string_type __X_; 2635227825Stheraven 2636227825Stheraven explicit __time_get_storage(const char* __nm); 2637227825Stheraven explicit __time_get_storage(const string& __nm); 2638227825Stheraven 2639227825Stheraven _LIBCPP_ALWAYS_INLINE ~__time_get_storage() {} 2640227825Stheraven 2641227825Stheraven time_base::dateorder __do_date_order() const; 2642227825Stheraven 2643227825Stheravenprivate: 2644227825Stheraven void init(const ctype<_CharT>&); 2645227825Stheraven string_type __analyze(char __fmt, const ctype<_CharT>&); 2646227825Stheraven}; 2647227825Stheraven 2648227825Stheraventemplate <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> > 2649227825Stheravenclass _LIBCPP_VISIBLE time_get_byname 2650227825Stheraven : public time_get<_CharT, _InputIterator>, 2651227825Stheraven private __time_get_storage<_CharT> 2652227825Stheraven{ 2653227825Stheravenpublic: 2654227825Stheraven typedef time_base::dateorder dateorder; 2655227825Stheraven typedef _InputIterator iter_type; 2656227825Stheraven typedef _CharT char_type; 2657227825Stheraven typedef basic_string<char_type> string_type; 2658227825Stheraven 2659227825Stheraven _LIBCPP_INLINE_VISIBILITY 2660227825Stheraven explicit time_get_byname(const char* __nm, size_t __refs = 0) 2661227825Stheraven : time_get<_CharT, _InputIterator>(__refs), 2662227825Stheraven __time_get_storage<_CharT>(__nm) {} 2663227825Stheraven _LIBCPP_INLINE_VISIBILITY 2664227825Stheraven explicit time_get_byname(const string& __nm, size_t __refs = 0) 2665227825Stheraven : time_get<_CharT, _InputIterator>(__refs), 2666227825Stheraven __time_get_storage<_CharT>(__nm) {} 2667227825Stheraven 2668227825Stheravenprotected: 2669227825Stheraven _LIBCPP_INLINE_VISIBILITY 2670227825Stheraven ~time_get_byname() {} 2671227825Stheraven 2672227825Stheraven _LIBCPP_INLINE_VISIBILITY 2673227825Stheraven virtual dateorder do_date_order() const {return this->__do_date_order();} 2674227825Stheravenprivate: 2675227825Stheraven _LIBCPP_INLINE_VISIBILITY 2676227825Stheraven virtual const string_type* __weeks() const {return this->__weeks_;} 2677227825Stheraven _LIBCPP_INLINE_VISIBILITY 2678227825Stheraven virtual const string_type* __months() const {return this->__months_;} 2679227825Stheraven _LIBCPP_INLINE_VISIBILITY 2680227825Stheraven virtual const string_type* __am_pm() const {return this->__am_pm_;} 2681227825Stheraven _LIBCPP_INLINE_VISIBILITY 2682227825Stheraven virtual const string_type& __c() const {return this->__c_;} 2683227825Stheraven _LIBCPP_INLINE_VISIBILITY 2684227825Stheraven virtual const string_type& __r() const {return this->__r_;} 2685227825Stheraven _LIBCPP_INLINE_VISIBILITY 2686227825Stheraven virtual const string_type& __x() const {return this->__x_;} 2687227825Stheraven _LIBCPP_INLINE_VISIBILITY 2688227825Stheraven virtual const string_type& __X() const {return this->__X_;} 2689227825Stheraven}; 2690227825Stheraven 2691242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class time_get_byname<char>) 2692242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class time_get_byname<wchar_t>) 2693227825Stheraven 2694227825Stheravenclass __time_put 2695227825Stheraven{ 2696227825Stheraven locale_t __loc_; 2697227825Stheravenprotected: 2698227825Stheraven _LIBCPP_ALWAYS_INLINE __time_put() : __loc_(_LIBCPP_GET_C_LOCALE) {} 2699227825Stheraven __time_put(const char* __nm); 2700227825Stheraven __time_put(const string& __nm); 2701227825Stheraven ~__time_put(); 2702227825Stheraven void __do_put(char* __nb, char*& __ne, const tm* __tm, 2703227825Stheraven char __fmt, char __mod) const; 2704227825Stheraven void __do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm, 2705227825Stheraven char __fmt, char __mod) const; 2706227825Stheraven}; 2707227825Stheraven 2708227825Stheraventemplate <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> > 2709227825Stheravenclass _LIBCPP_VISIBLE time_put 2710227825Stheraven : public locale::facet, 2711227825Stheraven private __time_put 2712227825Stheraven{ 2713227825Stheravenpublic: 2714227825Stheraven typedef _CharT char_type; 2715227825Stheraven typedef _OutputIterator iter_type; 2716227825Stheraven 2717227825Stheraven _LIBCPP_ALWAYS_INLINE 2718227825Stheraven explicit time_put(size_t __refs = 0) 2719227825Stheraven : locale::facet(__refs) {} 2720227825Stheraven 2721227825Stheraven iter_type put(iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm, 2722227825Stheraven const char_type* __pb, const char_type* __pe) const; 2723227825Stheraven 2724227825Stheraven _LIBCPP_ALWAYS_INLINE 2725227825Stheraven iter_type put(iter_type __s, ios_base& __iob, char_type __fl, 2726227825Stheraven const tm* __tm, char __fmt, char __mod = 0) const 2727227825Stheraven { 2728227825Stheraven return do_put(__s, __iob, __fl, __tm, __fmt, __mod); 2729227825Stheraven } 2730227825Stheraven 2731227825Stheraven static locale::id id; 2732227825Stheraven 2733227825Stheravenprotected: 2734227825Stheraven _LIBCPP_ALWAYS_INLINE 2735227825Stheraven ~time_put() {} 2736227825Stheraven virtual iter_type do_put(iter_type __s, ios_base&, char_type, const tm* __tm, 2737227825Stheraven char __fmt, char __mod) const; 2738227825Stheraven 2739227825Stheraven _LIBCPP_ALWAYS_INLINE 2740227825Stheraven explicit time_put(const char* __nm, size_t __refs) 2741227825Stheraven : locale::facet(__refs), 2742227825Stheraven __time_put(__nm) {} 2743227825Stheraven _LIBCPP_ALWAYS_INLINE 2744227825Stheraven explicit time_put(const string& __nm, size_t __refs) 2745227825Stheraven : locale::facet(__refs), 2746227825Stheraven __time_put(__nm) {} 2747227825Stheraven}; 2748227825Stheraven 2749227825Stheraventemplate <class _CharT, class _OutputIterator> 2750227825Stheravenlocale::id 2751227825Stheraventime_put<_CharT, _OutputIterator>::id; 2752227825Stheraven 2753227825Stheraventemplate <class _CharT, class _OutputIterator> 2754227825Stheraven_OutputIterator 2755227825Stheraventime_put<_CharT, _OutputIterator>::put(iter_type __s, ios_base& __iob, 2756227825Stheraven char_type __fl, const tm* __tm, 2757227825Stheraven const char_type* __pb, 2758227825Stheraven const char_type* __pe) const 2759227825Stheraven{ 2760227825Stheraven const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc()); 2761227825Stheraven for (; __pb != __pe; ++__pb) 2762227825Stheraven { 2763227825Stheraven if (__ct.narrow(*__pb, 0) == '%') 2764227825Stheraven { 2765227825Stheraven if (++__pb == __pe) 2766227825Stheraven { 2767227825Stheraven *__s++ = __pb[-1]; 2768227825Stheraven break; 2769227825Stheraven } 2770227825Stheraven char __mod = 0; 2771227825Stheraven char __fmt = __ct.narrow(*__pb, 0); 2772227825Stheraven if (__fmt == 'E' || __fmt == 'O') 2773227825Stheraven { 2774227825Stheraven if (++__pb == __pe) 2775227825Stheraven { 2776227825Stheraven *__s++ = __pb[-2]; 2777227825Stheraven *__s++ = __pb[-1]; 2778227825Stheraven break; 2779227825Stheraven } 2780227825Stheraven __mod = __fmt; 2781227825Stheraven __fmt = __ct.narrow(*__pb, 0); 2782227825Stheraven } 2783227825Stheraven __s = do_put(__s, __iob, __fl, __tm, __fmt, __mod); 2784227825Stheraven } 2785227825Stheraven else 2786227825Stheraven *__s++ = *__pb; 2787227825Stheraven } 2788227825Stheraven return __s; 2789227825Stheraven} 2790227825Stheraven 2791227825Stheraventemplate <class _CharT, class _OutputIterator> 2792227825Stheraven_OutputIterator 2793232950Stheraventime_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base&, 2794227825Stheraven char_type, const tm* __tm, 2795227825Stheraven char __fmt, char __mod) const 2796227825Stheraven{ 2797227825Stheraven char_type __nar[100]; 2798227825Stheraven char_type* __nb = __nar; 2799227825Stheraven char_type* __ne = __nb + 100; 2800227825Stheraven __do_put(__nb, __ne, __tm, __fmt, __mod); 2801227825Stheraven return _VSTD::copy(__nb, __ne, __s); 2802227825Stheraven} 2803227825Stheraven 2804242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class time_put<char>) 2805242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class time_put<wchar_t>) 2806227825Stheraven 2807227825Stheraventemplate <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> > 2808227825Stheravenclass _LIBCPP_VISIBLE time_put_byname 2809227825Stheraven : public time_put<_CharT, _OutputIterator> 2810227825Stheraven{ 2811227825Stheravenpublic: 2812227825Stheraven _LIBCPP_ALWAYS_INLINE 2813227825Stheraven explicit time_put_byname(const char* __nm, size_t __refs = 0) 2814227825Stheraven : time_put<_CharT, _OutputIterator>(__nm, __refs) {} 2815227825Stheraven 2816227825Stheraven _LIBCPP_ALWAYS_INLINE 2817227825Stheraven explicit time_put_byname(const string& __nm, size_t __refs = 0) 2818227825Stheraven : time_put<_CharT, _OutputIterator>(__nm, __refs) {} 2819227825Stheraven 2820227825Stheravenprotected: 2821227825Stheraven _LIBCPP_ALWAYS_INLINE 2822227825Stheraven ~time_put_byname() {} 2823227825Stheraven}; 2824227825Stheraven 2825242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class time_put_byname<char>) 2826242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class time_put_byname<wchar_t>) 2827227825Stheraven 2828227825Stheraven// money_base 2829227825Stheraven 2830227825Stheravenclass _LIBCPP_VISIBLE money_base 2831227825Stheraven{ 2832227825Stheravenpublic: 2833227825Stheraven enum part {none, space, symbol, sign, value}; 2834227825Stheraven struct pattern {char field[4];}; 2835227825Stheraven 2836227825Stheraven _LIBCPP_ALWAYS_INLINE money_base() {} 2837227825Stheraven}; 2838227825Stheraven 2839227825Stheraven// moneypunct 2840227825Stheraven 2841227825Stheraventemplate <class _CharT, bool _International = false> 2842227825Stheravenclass _LIBCPP_VISIBLE moneypunct 2843227825Stheraven : public locale::facet, 2844227825Stheraven public money_base 2845227825Stheraven{ 2846227825Stheravenpublic: 2847227825Stheraven typedef _CharT char_type; 2848227825Stheraven typedef basic_string<char_type> string_type; 2849227825Stheraven 2850227825Stheraven _LIBCPP_ALWAYS_INLINE 2851227825Stheraven explicit moneypunct(size_t __refs = 0) 2852227825Stheraven : locale::facet(__refs) {} 2853227825Stheraven 2854227825Stheraven _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();} 2855227825Stheraven _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();} 2856227825Stheraven _LIBCPP_ALWAYS_INLINE string grouping() const {return do_grouping();} 2857227825Stheraven _LIBCPP_ALWAYS_INLINE string_type curr_symbol() const {return do_curr_symbol();} 2858227825Stheraven _LIBCPP_ALWAYS_INLINE string_type positive_sign() const {return do_positive_sign();} 2859227825Stheraven _LIBCPP_ALWAYS_INLINE string_type negative_sign() const {return do_negative_sign();} 2860227825Stheraven _LIBCPP_ALWAYS_INLINE int frac_digits() const {return do_frac_digits();} 2861227825Stheraven _LIBCPP_ALWAYS_INLINE pattern pos_format() const {return do_pos_format();} 2862227825Stheraven _LIBCPP_ALWAYS_INLINE pattern neg_format() const {return do_neg_format();} 2863227825Stheraven 2864227825Stheraven static locale::id id; 2865227825Stheraven static const bool intl = _International; 2866227825Stheraven 2867227825Stheravenprotected: 2868227825Stheraven _LIBCPP_ALWAYS_INLINE 2869227825Stheraven ~moneypunct() {} 2870227825Stheraven 2871227825Stheraven virtual char_type do_decimal_point() const {return numeric_limits<char_type>::max();} 2872227825Stheraven virtual char_type do_thousands_sep() const {return numeric_limits<char_type>::max();} 2873227825Stheraven virtual string do_grouping() const {return string();} 2874227825Stheraven virtual string_type do_curr_symbol() const {return string_type();} 2875227825Stheraven virtual string_type do_positive_sign() const {return string_type();} 2876227825Stheraven virtual string_type do_negative_sign() const {return string_type(1, '-');} 2877227825Stheraven virtual int do_frac_digits() const {return 0;} 2878227825Stheraven virtual pattern do_pos_format() const 2879241907Sdim {pattern __p = {{symbol, sign, none, value}}; return __p;} 2880227825Stheraven virtual pattern do_neg_format() const 2881241907Sdim {pattern __p = {{symbol, sign, none, value}}; return __p;} 2882227825Stheraven}; 2883227825Stheraven 2884227825Stheraventemplate <class _CharT, bool _International> 2885227825Stheravenlocale::id 2886227825Stheravenmoneypunct<_CharT, _International>::id; 2887227825Stheraven 2888242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class moneypunct<char, false>) 2889242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class moneypunct<char, true>) 2890242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class moneypunct<wchar_t, false>) 2891242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class moneypunct<wchar_t, true>) 2892227825Stheraven 2893227825Stheraven// moneypunct_byname 2894227825Stheraven 2895227825Stheraventemplate <class _CharT, bool _International = false> 2896227825Stheravenclass _LIBCPP_VISIBLE moneypunct_byname 2897227825Stheraven : public moneypunct<_CharT, _International> 2898227825Stheraven{ 2899227825Stheravenpublic: 2900227825Stheraven typedef money_base::pattern pattern; 2901227825Stheraven typedef _CharT char_type; 2902227825Stheraven typedef basic_string<char_type> string_type; 2903227825Stheraven 2904227825Stheraven _LIBCPP_ALWAYS_INLINE 2905227825Stheraven explicit moneypunct_byname(const char* __nm, size_t __refs = 0) 2906227825Stheraven : moneypunct<_CharT, _International>(__refs) {init(__nm);} 2907227825Stheraven 2908227825Stheraven _LIBCPP_ALWAYS_INLINE 2909227825Stheraven explicit moneypunct_byname(const string& __nm, size_t __refs = 0) 2910227825Stheraven : moneypunct<_CharT, _International>(__refs) {init(__nm.c_str());} 2911227825Stheraven 2912227825Stheravenprotected: 2913227825Stheraven _LIBCPP_ALWAYS_INLINE 2914227825Stheraven ~moneypunct_byname() {} 2915227825Stheraven 2916227825Stheraven virtual char_type do_decimal_point() const {return __decimal_point_;} 2917227825Stheraven virtual char_type do_thousands_sep() const {return __thousands_sep_;} 2918227825Stheraven virtual string do_grouping() const {return __grouping_;} 2919227825Stheraven virtual string_type do_curr_symbol() const {return __curr_symbol_;} 2920227825Stheraven virtual string_type do_positive_sign() const {return __positive_sign_;} 2921227825Stheraven virtual string_type do_negative_sign() const {return __negative_sign_;} 2922227825Stheraven virtual int do_frac_digits() const {return __frac_digits_;} 2923227825Stheraven virtual pattern do_pos_format() const {return __pos_format_;} 2924227825Stheraven virtual pattern do_neg_format() const {return __neg_format_;} 2925227825Stheraven 2926227825Stheravenprivate: 2927227825Stheraven char_type __decimal_point_; 2928227825Stheraven char_type __thousands_sep_; 2929227825Stheraven string __grouping_; 2930227825Stheraven string_type __curr_symbol_; 2931227825Stheraven string_type __positive_sign_; 2932227825Stheraven string_type __negative_sign_; 2933227825Stheraven int __frac_digits_; 2934227825Stheraven pattern __pos_format_; 2935227825Stheraven pattern __neg_format_; 2936227825Stheraven 2937227825Stheraven void init(const char*); 2938227825Stheraven}; 2939227825Stheraven 2940227825Stheraventemplate<> void moneypunct_byname<char, false>::init(const char*); 2941227825Stheraventemplate<> void moneypunct_byname<char, true>::init(const char*); 2942227825Stheraventemplate<> void moneypunct_byname<wchar_t, false>::init(const char*); 2943227825Stheraventemplate<> void moneypunct_byname<wchar_t, true>::init(const char*); 2944227825Stheraven 2945242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class moneypunct_byname<char, false>) 2946242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class moneypunct_byname<char, true>) 2947242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class moneypunct_byname<wchar_t, false>) 2948242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class moneypunct_byname<wchar_t, true>) 2949227825Stheraven 2950227825Stheraven// money_get 2951227825Stheraven 2952227825Stheraventemplate <class _CharT> 2953227825Stheravenclass __money_get 2954227825Stheraven{ 2955227825Stheravenprotected: 2956227825Stheraven typedef _CharT char_type; 2957227825Stheraven typedef basic_string<char_type> string_type; 2958227825Stheraven 2959227825Stheraven _LIBCPP_ALWAYS_INLINE __money_get() {} 2960227825Stheraven 2961227825Stheraven static void __gather_info(bool __intl, const locale& __loc, 2962227825Stheraven money_base::pattern& __pat, char_type& __dp, 2963227825Stheraven char_type& __ts, string& __grp, 2964227825Stheraven string_type& __sym, string_type& __psn, 2965227825Stheraven string_type& __nsn, int& __fd); 2966227825Stheraven}; 2967227825Stheraven 2968227825Stheraventemplate <class _CharT> 2969227825Stheravenvoid 2970227825Stheraven__money_get<_CharT>::__gather_info(bool __intl, const locale& __loc, 2971227825Stheraven money_base::pattern& __pat, char_type& __dp, 2972227825Stheraven char_type& __ts, string& __grp, 2973227825Stheraven string_type& __sym, string_type& __psn, 2974227825Stheraven string_type& __nsn, int& __fd) 2975227825Stheraven{ 2976227825Stheraven if (__intl) 2977227825Stheraven { 2978227825Stheraven const moneypunct<char_type, true>& __mp = 2979227825Stheraven use_facet<moneypunct<char_type, true> >(__loc); 2980227825Stheraven __pat = __mp.neg_format(); 2981227825Stheraven __nsn = __mp.negative_sign(); 2982227825Stheraven __psn = __mp.positive_sign(); 2983227825Stheraven __dp = __mp.decimal_point(); 2984227825Stheraven __ts = __mp.thousands_sep(); 2985227825Stheraven __grp = __mp.grouping(); 2986227825Stheraven __sym = __mp.curr_symbol(); 2987227825Stheraven __fd = __mp.frac_digits(); 2988227825Stheraven } 2989227825Stheraven else 2990227825Stheraven { 2991227825Stheraven const moneypunct<char_type, false>& __mp = 2992227825Stheraven use_facet<moneypunct<char_type, false> >(__loc); 2993227825Stheraven __pat = __mp.neg_format(); 2994227825Stheraven __nsn = __mp.negative_sign(); 2995227825Stheraven __psn = __mp.positive_sign(); 2996227825Stheraven __dp = __mp.decimal_point(); 2997227825Stheraven __ts = __mp.thousands_sep(); 2998227825Stheraven __grp = __mp.grouping(); 2999227825Stheraven __sym = __mp.curr_symbol(); 3000227825Stheraven __fd = __mp.frac_digits(); 3001227825Stheraven } 3002227825Stheraven} 3003227825Stheraven 3004242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class __money_get<char>) 3005242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class __money_get<wchar_t>) 3006227825Stheraven 3007227825Stheraventemplate <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> > 3008227825Stheravenclass _LIBCPP_VISIBLE money_get 3009227825Stheraven : public locale::facet, 3010227825Stheraven private __money_get<_CharT> 3011227825Stheraven{ 3012227825Stheravenpublic: 3013227825Stheraven typedef _CharT char_type; 3014227825Stheraven typedef _InputIterator iter_type; 3015227825Stheraven typedef basic_string<char_type> string_type; 3016227825Stheraven 3017227825Stheraven _LIBCPP_ALWAYS_INLINE 3018227825Stheraven explicit money_get(size_t __refs = 0) 3019227825Stheraven : locale::facet(__refs) {} 3020227825Stheraven 3021227825Stheraven _LIBCPP_ALWAYS_INLINE 3022227825Stheraven iter_type get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, 3023227825Stheraven ios_base::iostate& __err, long double& __v) const 3024227825Stheraven { 3025227825Stheraven return do_get(__b, __e, __intl, __iob, __err, __v); 3026227825Stheraven } 3027227825Stheraven 3028227825Stheraven _LIBCPP_ALWAYS_INLINE 3029227825Stheraven iter_type get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, 3030227825Stheraven ios_base::iostate& __err, string_type& __v) const 3031227825Stheraven { 3032227825Stheraven return do_get(__b, __e, __intl, __iob, __err, __v); 3033227825Stheraven } 3034227825Stheraven 3035227825Stheraven static locale::id id; 3036227825Stheraven 3037227825Stheravenprotected: 3038227825Stheraven 3039227825Stheraven _LIBCPP_ALWAYS_INLINE 3040227825Stheraven ~money_get() {} 3041227825Stheraven 3042227825Stheraven virtual iter_type do_get(iter_type __b, iter_type __e, bool __intl, 3043227825Stheraven ios_base& __iob, ios_base::iostate& __err, 3044227825Stheraven long double& __v) const; 3045227825Stheraven virtual iter_type do_get(iter_type __b, iter_type __e, bool __intl, 3046227825Stheraven ios_base& __iob, ios_base::iostate& __err, 3047227825Stheraven string_type& __v) const; 3048227825Stheraven 3049227825Stheravenprivate: 3050227825Stheraven static bool __do_get(iter_type& __b, iter_type __e, 3051227825Stheraven bool __intl, const locale& __loc, 3052227825Stheraven ios_base::fmtflags __flags, ios_base::iostate& __err, 3053227825Stheraven bool& __neg, const ctype<char_type>& __ct, 3054227825Stheraven unique_ptr<char_type, void(*)(void*)>& __wb, 3055227825Stheraven char_type*& __wn, char_type* __we); 3056227825Stheraven}; 3057227825Stheraven 3058227825Stheraventemplate <class _CharT, class _InputIterator> 3059227825Stheravenlocale::id 3060227825Stheravenmoney_get<_CharT, _InputIterator>::id; 3061227825Stheraven 3062227825Stheravenvoid __do_nothing(void*); 3063227825Stheraven 3064227825Stheraventemplate <class _Tp> 3065227825Stheraven_LIBCPP_HIDDEN 3066227825Stheravenvoid 3067227825Stheraven__double_or_nothing(unique_ptr<_Tp, void(*)(void*)>& __b, _Tp*& __n, _Tp*& __e) 3068227825Stheraven{ 3069227825Stheraven bool __owns = __b.get_deleter() != __do_nothing; 3070232950Stheraven size_t __cur_cap = static_cast<size_t>(__e-__b.get()) * sizeof(_Tp); 3071227825Stheraven size_t __new_cap = __cur_cap < numeric_limits<size_t>::max() / 2 ? 3072227825Stheraven 2 * __cur_cap : numeric_limits<size_t>::max(); 3073232950Stheraven size_t __n_off = static_cast<size_t>(__n - __b.get()); 3074227825Stheraven _Tp* __t = (_Tp*)realloc(__owns ? __b.get() : 0, __new_cap); 3075227825Stheraven if (__t == 0) 3076227825Stheraven __throw_bad_alloc(); 3077227825Stheraven if (__owns) 3078227825Stheraven __b.release(); 3079227825Stheraven __b = unique_ptr<_Tp, void(*)(void*)>(__t, free); 3080227825Stheraven __new_cap /= sizeof(_Tp); 3081227825Stheraven __n = __b.get() + __n_off; 3082227825Stheraven __e = __b.get() + __new_cap; 3083227825Stheraven} 3084227825Stheraven 3085227825Stheraven// true == success 3086227825Stheraventemplate <class _CharT, class _InputIterator> 3087227825Stheravenbool 3088227825Stheravenmoney_get<_CharT, _InputIterator>::__do_get(iter_type& __b, iter_type __e, 3089227825Stheraven bool __intl, const locale& __loc, 3090227825Stheraven ios_base::fmtflags __flags, 3091227825Stheraven ios_base::iostate& __err, 3092227825Stheraven bool& __neg, 3093227825Stheraven const ctype<char_type>& __ct, 3094227825Stheraven unique_ptr<char_type, void(*)(void*)>& __wb, 3095227825Stheraven char_type*& __wn, char_type* __we) 3096227825Stheraven{ 3097227825Stheraven const unsigned __bz = 100; 3098227825Stheraven unsigned __gbuf[__bz]; 3099227825Stheraven unique_ptr<unsigned, void(*)(void*)> __gb(__gbuf, __do_nothing); 3100227825Stheraven unsigned* __gn = __gb.get(); 3101227825Stheraven unsigned* __ge = __gn + __bz; 3102227825Stheraven money_base::pattern __pat; 3103227825Stheraven char_type __dp; 3104227825Stheraven char_type __ts; 3105227825Stheraven string __grp; 3106227825Stheraven string_type __sym; 3107227825Stheraven string_type __psn; 3108227825Stheraven string_type __nsn; 3109232950Stheraven // Capture the spaces read into money_base::{space,none} so they 3110232950Stheraven // can be compared to initial spaces in __sym. 3111232950Stheraven string_type __spaces; 3112227825Stheraven int __fd; 3113227825Stheraven __money_get<_CharT>::__gather_info(__intl, __loc, __pat, __dp, __ts, __grp, 3114227825Stheraven __sym, __psn, __nsn, __fd); 3115227825Stheraven const string_type* __trailing_sign = 0; 3116227825Stheraven __wn = __wb.get(); 3117227825Stheraven for (unsigned __p = 0; __p < 4 && __b != __e; ++__p) 3118227825Stheraven { 3119227825Stheraven switch (__pat.field[__p]) 3120227825Stheraven { 3121227825Stheraven case money_base::space: 3122227825Stheraven if (__p != 3) 3123227825Stheraven { 3124227825Stheraven if (__ct.is(ctype_base::space, *__b)) 3125232950Stheraven __spaces.push_back(*__b++); 3126227825Stheraven else 3127227825Stheraven { 3128227825Stheraven __err |= ios_base::failbit; 3129227825Stheraven return false; 3130227825Stheraven } 3131227825Stheraven } 3132227825Stheraven // drop through 3133227825Stheraven case money_base::none: 3134227825Stheraven if (__p != 3) 3135227825Stheraven { 3136227825Stheraven while (__b != __e && __ct.is(ctype_base::space, *__b)) 3137232950Stheraven __spaces.push_back(*__b++); 3138227825Stheraven } 3139227825Stheraven break; 3140227825Stheraven case money_base::sign: 3141227825Stheraven if (__psn.size() + __nsn.size() > 0) 3142227825Stheraven { 3143227825Stheraven if (__psn.size() == 0 || __nsn.size() == 0) 3144227825Stheraven { // sign is optional 3145227825Stheraven if (__psn.size() > 0) 3146227825Stheraven { // __nsn.size() == 0 3147227825Stheraven if (*__b == __psn[0]) 3148227825Stheraven { 3149227825Stheraven ++__b; 3150227825Stheraven if (__psn.size() > 1) 3151227825Stheraven __trailing_sign = &__psn; 3152227825Stheraven } 3153227825Stheraven else 3154227825Stheraven __neg = true; 3155227825Stheraven } 3156227825Stheraven else if (*__b == __nsn[0]) // __nsn.size() > 0 && __psn.size() == 0 3157227825Stheraven { 3158227825Stheraven ++__b; 3159227825Stheraven __neg = true; 3160227825Stheraven if (__nsn.size() > 1) 3161227825Stheraven __trailing_sign = &__nsn; 3162227825Stheraven } 3163227825Stheraven } 3164227825Stheraven else // sign is required 3165227825Stheraven { 3166227825Stheraven if (*__b == __psn[0]) 3167227825Stheraven { 3168227825Stheraven ++__b; 3169227825Stheraven if (__psn.size() > 1) 3170227825Stheraven __trailing_sign = &__psn; 3171227825Stheraven } 3172227825Stheraven else if (*__b == __nsn[0]) 3173227825Stheraven { 3174227825Stheraven ++__b; 3175227825Stheraven __neg = true; 3176227825Stheraven if (__nsn.size() > 1) 3177227825Stheraven __trailing_sign = &__nsn; 3178227825Stheraven } 3179227825Stheraven else 3180227825Stheraven { 3181227825Stheraven __err |= ios_base::failbit; 3182227825Stheraven return false; 3183227825Stheraven } 3184227825Stheraven } 3185227825Stheraven } 3186227825Stheraven break; 3187227825Stheraven case money_base::symbol: 3188227825Stheraven { 3189227825Stheraven bool __more_needed = __trailing_sign || 3190227825Stheraven (__p < 2) || 3191227825Stheraven (__p == 2 && __pat.field[3] != static_cast<char>(money_base::none)); 3192227825Stheraven bool __sb = __flags & ios_base::showbase; 3193227825Stheraven if (__sb || __more_needed) 3194227825Stheraven { 3195232950Stheraven typename string_type::const_iterator __sym_space_end = __sym.begin(); 3196232950Stheraven if (__p > 0 && (__pat.field[__p - 1] == money_base::none || 3197232950Stheraven __pat.field[__p - 1] == money_base::space)) { 3198232950Stheraven // Match spaces we've already read against spaces at 3199232950Stheraven // the beginning of __sym. 3200232950Stheraven while (__sym_space_end != __sym.end() && 3201232950Stheraven __ct.is(ctype_base::space, *__sym_space_end)) 3202232950Stheraven ++__sym_space_end; 3203232950Stheraven const size_t __num_spaces = __sym_space_end - __sym.begin(); 3204232950Stheraven if (__num_spaces > __spaces.size() || 3205232950Stheraven !equal(__spaces.end() - __num_spaces, __spaces.end(), 3206232950Stheraven __sym.begin())) { 3207232950Stheraven // No match. Put __sym_space_end back at the 3208232950Stheraven // beginning of __sym, which will prevent a 3209232950Stheraven // match in the next loop. 3210232950Stheraven __sym_space_end = __sym.begin(); 3211232950Stheraven } 3212232950Stheraven } 3213232950Stheraven typename string_type::const_iterator __sym_curr_char = __sym_space_end; 3214232950Stheraven while (__sym_curr_char != __sym.end() && __b != __e && 3215232950Stheraven *__b == *__sym_curr_char) { 3216232950Stheraven ++__b; 3217232950Stheraven ++__sym_curr_char; 3218232950Stheraven } 3219232950Stheraven if (__sb && __sym_curr_char != __sym.end()) 3220227825Stheraven { 3221227825Stheraven __err |= ios_base::failbit; 3222227825Stheraven return false; 3223227825Stheraven } 3224227825Stheraven } 3225227825Stheraven } 3226227825Stheraven break; 3227227825Stheraven case money_base::value: 3228227825Stheraven { 3229227825Stheraven unsigned __ng = 0; 3230227825Stheraven for (; __b != __e; ++__b) 3231227825Stheraven { 3232227825Stheraven char_type __c = *__b; 3233227825Stheraven if (__ct.is(ctype_base::digit, __c)) 3234227825Stheraven { 3235227825Stheraven if (__wn == __we) 3236227825Stheraven __double_or_nothing(__wb, __wn, __we); 3237227825Stheraven *__wn++ = __c; 3238227825Stheraven ++__ng; 3239227825Stheraven } 3240227825Stheraven else if (__grp.size() > 0 && __ng > 0 && __c == __ts) 3241227825Stheraven { 3242227825Stheraven if (__gn == __ge) 3243227825Stheraven __double_or_nothing(__gb, __gn, __ge); 3244227825Stheraven *__gn++ = __ng; 3245227825Stheraven __ng = 0; 3246227825Stheraven } 3247227825Stheraven else 3248227825Stheraven break; 3249227825Stheraven } 3250227825Stheraven if (__gb.get() != __gn && __ng > 0) 3251227825Stheraven { 3252227825Stheraven if (__gn == __ge) 3253227825Stheraven __double_or_nothing(__gb, __gn, __ge); 3254227825Stheraven *__gn++ = __ng; 3255227825Stheraven } 3256227825Stheraven if (__fd > 0) 3257227825Stheraven { 3258227825Stheraven if (__b == __e || *__b != __dp) 3259227825Stheraven { 3260227825Stheraven __err |= ios_base::failbit; 3261227825Stheraven return false; 3262227825Stheraven } 3263227825Stheraven for (++__b; __fd > 0; --__fd, ++__b) 3264227825Stheraven { 3265227825Stheraven if (__b == __e || !__ct.is(ctype_base::digit, *__b)) 3266227825Stheraven { 3267227825Stheraven __err |= ios_base::failbit; 3268227825Stheraven return false; 3269227825Stheraven } 3270227825Stheraven if (__wn == __we) 3271227825Stheraven __double_or_nothing(__wb, __wn, __we); 3272227825Stheraven *__wn++ = *__b; 3273227825Stheraven } 3274227825Stheraven } 3275227825Stheraven if (__wn == __wb.get()) 3276227825Stheraven { 3277227825Stheraven __err |= ios_base::failbit; 3278227825Stheraven return false; 3279227825Stheraven } 3280227825Stheraven } 3281227825Stheraven break; 3282227825Stheraven } 3283227825Stheraven } 3284227825Stheraven if (__trailing_sign) 3285227825Stheraven { 3286227825Stheraven for (unsigned __i = 1; __i < __trailing_sign->size(); ++__i, ++__b) 3287227825Stheraven { 3288227825Stheraven if (__b == __e || *__b != (*__trailing_sign)[__i]) 3289227825Stheraven { 3290227825Stheraven __err |= ios_base::failbit; 3291227825Stheraven return false; 3292227825Stheraven } 3293227825Stheraven } 3294227825Stheraven } 3295227825Stheraven if (__gb.get() != __gn) 3296227825Stheraven { 3297227825Stheraven ios_base::iostate __et = ios_base::goodbit; 3298227825Stheraven __check_grouping(__grp, __gb.get(), __gn, __et); 3299227825Stheraven if (__et) 3300227825Stheraven { 3301227825Stheraven __err |= ios_base::failbit; 3302227825Stheraven return false; 3303227825Stheraven } 3304227825Stheraven } 3305227825Stheraven return true; 3306227825Stheraven} 3307227825Stheraven 3308227825Stheraventemplate <class _CharT, class _InputIterator> 3309227825Stheraven_InputIterator 3310227825Stheravenmoney_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, 3311227825Stheraven bool __intl, ios_base& __iob, 3312227825Stheraven ios_base::iostate& __err, 3313227825Stheraven long double& __v) const 3314227825Stheraven{ 3315232950Stheraven const int __bz = 100; 3316227825Stheraven char_type __wbuf[__bz]; 3317227825Stheraven unique_ptr<char_type, void(*)(void*)> __wb(__wbuf, __do_nothing); 3318227825Stheraven char_type* __wn; 3319227825Stheraven char_type* __we = __wbuf + __bz; 3320227825Stheraven locale __loc = __iob.getloc(); 3321227825Stheraven const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__loc); 3322227825Stheraven bool __neg = false; 3323227825Stheraven if (__do_get(__b, __e, __intl, __loc, __iob.flags(), __err, __neg, __ct, 3324227825Stheraven __wb, __wn, __we)) 3325227825Stheraven { 3326227825Stheraven const char __src[] = "0123456789"; 3327227825Stheraven char_type __atoms[sizeof(__src)-1]; 3328227825Stheraven __ct.widen(__src, __src + (sizeof(__src)-1), __atoms); 3329227825Stheraven char __nbuf[__bz]; 3330227825Stheraven char* __nc = __nbuf; 3331227825Stheraven unique_ptr<char, void(*)(void*)> __h(0, free); 3332227825Stheraven if (__wn - __wb.get() > __bz-2) 3333227825Stheraven { 3334232950Stheraven __h.reset((char*)malloc(static_cast<size_t>(__wn - __wb.get() + 2))); 3335227825Stheraven if (__h.get() == 0) 3336227825Stheraven __throw_bad_alloc(); 3337227825Stheraven __nc = __h.get(); 3338227825Stheraven } 3339227825Stheraven if (__neg) 3340227825Stheraven *__nc++ = '-'; 3341227825Stheraven for (const char_type* __w = __wb.get(); __w < __wn; ++__w, ++__nc) 3342227825Stheraven *__nc = __src[find(__atoms, __atoms+sizeof(__atoms), *__w) - __atoms]; 3343227825Stheraven *__nc = char(); 3344227825Stheraven if (sscanf(__nbuf, "%Lf", &__v) != 1) 3345227825Stheraven __throw_runtime_error("money_get error"); 3346227825Stheraven } 3347227825Stheraven if (__b == __e) 3348227825Stheraven __err |= ios_base::eofbit; 3349227825Stheraven return __b; 3350227825Stheraven} 3351227825Stheraven 3352227825Stheraventemplate <class _CharT, class _InputIterator> 3353227825Stheraven_InputIterator 3354227825Stheravenmoney_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, 3355227825Stheraven bool __intl, ios_base& __iob, 3356227825Stheraven ios_base::iostate& __err, 3357227825Stheraven string_type& __v) const 3358227825Stheraven{ 3359232950Stheraven const int __bz = 100; 3360227825Stheraven char_type __wbuf[__bz]; 3361227825Stheraven unique_ptr<char_type, void(*)(void*)> __wb(__wbuf, __do_nothing); 3362227825Stheraven char_type* __wn; 3363227825Stheraven char_type* __we = __wbuf + __bz; 3364227825Stheraven locale __loc = __iob.getloc(); 3365227825Stheraven const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__loc); 3366227825Stheraven bool __neg = false; 3367227825Stheraven if (__do_get(__b, __e, __intl, __loc, __iob.flags(), __err, __neg, __ct, 3368227825Stheraven __wb, __wn, __we)) 3369227825Stheraven { 3370227825Stheraven __v.clear(); 3371227825Stheraven if (__neg) 3372227825Stheraven __v.push_back(__ct.widen('-')); 3373227825Stheraven char_type __z = __ct.widen('0'); 3374227825Stheraven char_type* __w; 3375227825Stheraven for (__w = __wb.get(); __w < __wn-1; ++__w) 3376227825Stheraven if (*__w != __z) 3377227825Stheraven break; 3378227825Stheraven __v.append(__w, __wn); 3379227825Stheraven } 3380227825Stheraven if (__b == __e) 3381227825Stheraven __err |= ios_base::eofbit; 3382227825Stheraven return __b; 3383227825Stheraven} 3384227825Stheraven 3385242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class money_get<char>) 3386242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class money_get<wchar_t>) 3387227825Stheraven 3388227825Stheraven// money_put 3389227825Stheraven 3390227825Stheraventemplate <class _CharT> 3391227825Stheravenclass __money_put 3392227825Stheraven{ 3393227825Stheravenprotected: 3394227825Stheraven typedef _CharT char_type; 3395227825Stheraven typedef basic_string<char_type> string_type; 3396227825Stheraven 3397227825Stheraven _LIBCPP_ALWAYS_INLINE __money_put() {} 3398227825Stheraven 3399227825Stheraven static void __gather_info(bool __intl, bool __neg, const locale& __loc, 3400227825Stheraven money_base::pattern& __pat, char_type& __dp, 3401227825Stheraven char_type& __ts, string& __grp, 3402227825Stheraven string_type& __sym, string_type& __sn, 3403227825Stheraven int& __fd); 3404227825Stheraven static void __format(char_type* __mb, char_type*& __mi, char_type*& __me, 3405227825Stheraven ios_base::fmtflags __flags, 3406227825Stheraven const char_type* __db, const char_type* __de, 3407227825Stheraven const ctype<char_type>& __ct, bool __neg, 3408227825Stheraven const money_base::pattern& __pat, char_type __dp, 3409227825Stheraven char_type __ts, const string& __grp, 3410227825Stheraven const string_type& __sym, const string_type& __sn, 3411227825Stheraven int __fd); 3412227825Stheraven}; 3413227825Stheraven 3414227825Stheraventemplate <class _CharT> 3415227825Stheravenvoid 3416227825Stheraven__money_put<_CharT>::__gather_info(bool __intl, bool __neg, const locale& __loc, 3417227825Stheraven money_base::pattern& __pat, char_type& __dp, 3418227825Stheraven char_type& __ts, string& __grp, 3419227825Stheraven string_type& __sym, string_type& __sn, 3420227825Stheraven int& __fd) 3421227825Stheraven{ 3422227825Stheraven if (__intl) 3423227825Stheraven { 3424227825Stheraven const moneypunct<char_type, true>& __mp = 3425227825Stheraven use_facet<moneypunct<char_type, true> >(__loc); 3426227825Stheraven if (__neg) 3427227825Stheraven { 3428227825Stheraven __pat = __mp.neg_format(); 3429227825Stheraven __sn = __mp.negative_sign(); 3430227825Stheraven } 3431227825Stheraven else 3432227825Stheraven { 3433227825Stheraven __pat = __mp.pos_format(); 3434227825Stheraven __sn = __mp.positive_sign(); 3435227825Stheraven } 3436227825Stheraven __dp = __mp.decimal_point(); 3437227825Stheraven __ts = __mp.thousands_sep(); 3438227825Stheraven __grp = __mp.grouping(); 3439227825Stheraven __sym = __mp.curr_symbol(); 3440227825Stheraven __fd = __mp.frac_digits(); 3441227825Stheraven } 3442227825Stheraven else 3443227825Stheraven { 3444227825Stheraven const moneypunct<char_type, false>& __mp = 3445227825Stheraven use_facet<moneypunct<char_type, false> >(__loc); 3446227825Stheraven if (__neg) 3447227825Stheraven { 3448227825Stheraven __pat = __mp.neg_format(); 3449227825Stheraven __sn = __mp.negative_sign(); 3450227825Stheraven } 3451227825Stheraven else 3452227825Stheraven { 3453227825Stheraven __pat = __mp.pos_format(); 3454227825Stheraven __sn = __mp.positive_sign(); 3455227825Stheraven } 3456227825Stheraven __dp = __mp.decimal_point(); 3457227825Stheraven __ts = __mp.thousands_sep(); 3458227825Stheraven __grp = __mp.grouping(); 3459227825Stheraven __sym = __mp.curr_symbol(); 3460227825Stheraven __fd = __mp.frac_digits(); 3461227825Stheraven } 3462227825Stheraven} 3463227825Stheraven 3464227825Stheraventemplate <class _CharT> 3465227825Stheravenvoid 3466227825Stheraven__money_put<_CharT>::__format(char_type* __mb, char_type*& __mi, char_type*& __me, 3467227825Stheraven ios_base::fmtflags __flags, 3468227825Stheraven const char_type* __db, const char_type* __de, 3469227825Stheraven const ctype<char_type>& __ct, bool __neg, 3470227825Stheraven const money_base::pattern& __pat, char_type __dp, 3471227825Stheraven char_type __ts, const string& __grp, 3472227825Stheraven const string_type& __sym, const string_type& __sn, 3473227825Stheraven int __fd) 3474227825Stheraven{ 3475227825Stheraven __me = __mb; 3476227825Stheraven for (unsigned __p = 0; __p < 4; ++__p) 3477227825Stheraven { 3478227825Stheraven switch (__pat.field[__p]) 3479227825Stheraven { 3480227825Stheraven case money_base::none: 3481227825Stheraven __mi = __me; 3482227825Stheraven break; 3483227825Stheraven case money_base::space: 3484227825Stheraven __mi = __me; 3485227825Stheraven *__me++ = __ct.widen(' '); 3486227825Stheraven break; 3487227825Stheraven case money_base::sign: 3488227825Stheraven if (!__sn.empty()) 3489227825Stheraven *__me++ = __sn[0]; 3490227825Stheraven break; 3491227825Stheraven case money_base::symbol: 3492227825Stheraven if (!__sym.empty() && (__flags & ios_base::showbase)) 3493227825Stheraven __me = _VSTD::copy(__sym.begin(), __sym.end(), __me); 3494227825Stheraven break; 3495227825Stheraven case money_base::value: 3496227825Stheraven { 3497227825Stheraven // remember start of value so we can reverse it 3498227825Stheraven char_type* __t = __me; 3499227825Stheraven // find beginning of digits 3500227825Stheraven if (__neg) 3501227825Stheraven ++__db; 3502227825Stheraven // find end of digits 3503227825Stheraven const char_type* __d; 3504227825Stheraven for (__d = __db; __d < __de; ++__d) 3505227825Stheraven if (!__ct.is(ctype_base::digit, *__d)) 3506227825Stheraven break; 3507227825Stheraven // print fractional part 3508227825Stheraven if (__fd > 0) 3509227825Stheraven { 3510227825Stheraven int __f; 3511227825Stheraven for (__f = __fd; __d > __db && __f > 0; --__f) 3512227825Stheraven *__me++ = *--__d; 3513227825Stheraven char_type __z = __f > 0 ? __ct.widen('0') : char_type(); 3514227825Stheraven for (; __f > 0; --__f) 3515227825Stheraven *__me++ = __z; 3516227825Stheraven *__me++ = __dp; 3517227825Stheraven } 3518227825Stheraven // print units part 3519227825Stheraven if (__d == __db) 3520227825Stheraven { 3521227825Stheraven *__me++ = __ct.widen('0'); 3522227825Stheraven } 3523227825Stheraven else 3524227825Stheraven { 3525227825Stheraven unsigned __ng = 0; 3526227825Stheraven unsigned __ig = 0; 3527227825Stheraven unsigned __gl = __grp.empty() ? numeric_limits<unsigned>::max() 3528227825Stheraven : static_cast<unsigned>(__grp[__ig]); 3529227825Stheraven while (__d != __db) 3530227825Stheraven { 3531227825Stheraven if (__ng == __gl) 3532227825Stheraven { 3533227825Stheraven *__me++ = __ts; 3534227825Stheraven __ng = 0; 3535227825Stheraven if (++__ig < __grp.size()) 3536227825Stheraven __gl = __grp[__ig] == numeric_limits<char>::max() ? 3537227825Stheraven numeric_limits<unsigned>::max() : 3538227825Stheraven static_cast<unsigned>(__grp[__ig]); 3539227825Stheraven } 3540227825Stheraven *__me++ = *--__d; 3541227825Stheraven ++__ng; 3542227825Stheraven } 3543227825Stheraven } 3544227825Stheraven // reverse it 3545227825Stheraven reverse(__t, __me); 3546227825Stheraven } 3547227825Stheraven break; 3548227825Stheraven } 3549227825Stheraven } 3550227825Stheraven // print rest of sign, if any 3551227825Stheraven if (__sn.size() > 1) 3552227825Stheraven __me = _VSTD::copy(__sn.begin()+1, __sn.end(), __me); 3553227825Stheraven // set alignment 3554227825Stheraven if ((__flags & ios_base::adjustfield) == ios_base::left) 3555227825Stheraven __mi = __me; 3556227825Stheraven else if ((__flags & ios_base::adjustfield) != ios_base::internal) 3557227825Stheraven __mi = __mb; 3558227825Stheraven} 3559227825Stheraven 3560242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class __money_put<char>) 3561242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class __money_put<wchar_t>) 3562227825Stheraven 3563227825Stheraventemplate <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> > 3564227825Stheravenclass _LIBCPP_VISIBLE money_put 3565227825Stheraven : public locale::facet, 3566227825Stheraven private __money_put<_CharT> 3567227825Stheraven{ 3568227825Stheravenpublic: 3569227825Stheraven typedef _CharT char_type; 3570227825Stheraven typedef _OutputIterator iter_type; 3571227825Stheraven typedef basic_string<char_type> string_type; 3572227825Stheraven 3573227825Stheraven _LIBCPP_ALWAYS_INLINE 3574227825Stheraven explicit money_put(size_t __refs = 0) 3575227825Stheraven : locale::facet(__refs) {} 3576227825Stheraven 3577227825Stheraven _LIBCPP_ALWAYS_INLINE 3578227825Stheraven iter_type put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, 3579227825Stheraven long double __units) const 3580227825Stheraven { 3581227825Stheraven return do_put(__s, __intl, __iob, __fl, __units); 3582227825Stheraven } 3583227825Stheraven 3584227825Stheraven _LIBCPP_ALWAYS_INLINE 3585227825Stheraven iter_type put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, 3586227825Stheraven const string_type& __digits) const 3587227825Stheraven { 3588227825Stheraven return do_put(__s, __intl, __iob, __fl, __digits); 3589227825Stheraven } 3590227825Stheraven 3591227825Stheraven static locale::id id; 3592227825Stheraven 3593227825Stheravenprotected: 3594227825Stheraven _LIBCPP_ALWAYS_INLINE 3595227825Stheraven ~money_put() {} 3596227825Stheraven 3597227825Stheraven virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __iob, 3598227825Stheraven char_type __fl, long double __units) const; 3599227825Stheraven virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __iob, 3600227825Stheraven char_type __fl, const string_type& __digits) const; 3601227825Stheraven}; 3602227825Stheraven 3603227825Stheraventemplate <class _CharT, class _OutputIterator> 3604227825Stheravenlocale::id 3605227825Stheravenmoney_put<_CharT, _OutputIterator>::id; 3606227825Stheraven 3607227825Stheraventemplate <class _CharT, class _OutputIterator> 3608227825Stheraven_OutputIterator 3609227825Stheravenmoney_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl, 3610227825Stheraven ios_base& __iob, char_type __fl, 3611227825Stheraven long double __units) const 3612227825Stheraven{ 3613227825Stheraven // convert to char 3614227825Stheraven const size_t __bs = 100; 3615227825Stheraven char __buf[__bs]; 3616227825Stheraven char* __bb = __buf; 3617227825Stheraven char_type __digits[__bs]; 3618227825Stheraven char_type* __db = __digits; 3619232950Stheraven size_t __n = static_cast<size_t>(snprintf(__bb, __bs, "%.0Lf", __units)); 3620227825Stheraven unique_ptr<char, void(*)(void*)> __hn(0, free); 3621227825Stheraven unique_ptr<char_type, void(*)(void*)> __hd(0, free); 3622227825Stheraven // secure memory for digit storage 3623227825Stheraven if (__n > __bs-1) 3624227825Stheraven { 3625227825Stheraven#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 3626232950Stheraven __n = static_cast<size_t>(asprintf_l(&__bb, _LIBCPP_GET_C_LOCALE, "%.0Lf", __units)); 3627227825Stheraven#else 3628227825Stheraven __n = __asprintf_l(&__bb, __cloc(), "%.0Lf", __units); 3629227825Stheraven#endif 3630227825Stheraven if (__bb == 0) 3631227825Stheraven __throw_bad_alloc(); 3632227825Stheraven __hn.reset(__bb); 3633227825Stheraven __hd.reset((char_type*)malloc(__n * sizeof(char_type))); 3634232950Stheraven if (__hd == nullptr) 3635227825Stheraven __throw_bad_alloc(); 3636227825Stheraven __db = __hd.get(); 3637227825Stheraven } 3638227825Stheraven // gather info 3639227825Stheraven locale __loc = __iob.getloc(); 3640227825Stheraven const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__loc); 3641227825Stheraven __ct.widen(__bb, __bb + __n, __db); 3642227825Stheraven bool __neg = __n > 0 && __bb[0] == '-'; 3643227825Stheraven money_base::pattern __pat; 3644227825Stheraven char_type __dp; 3645227825Stheraven char_type __ts; 3646227825Stheraven string __grp; 3647227825Stheraven string_type __sym; 3648227825Stheraven string_type __sn; 3649227825Stheraven int __fd; 3650227825Stheraven this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd); 3651227825Stheraven // secure memory for formatting 3652227825Stheraven char_type __mbuf[__bs]; 3653227825Stheraven char_type* __mb = __mbuf; 3654227825Stheraven unique_ptr<char_type, void(*)(void*)> __hw(0, free); 3655227825Stheraven size_t __exn = static_cast<int>(__n) > __fd ? 3656232950Stheraven (__n - static_cast<size_t>(__fd)) * 2 + __sn.size() + 3657232950Stheraven __sym.size() + static_cast<size_t>(__fd) + 1 3658232950Stheraven : __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 2; 3659227825Stheraven if (__exn > __bs) 3660227825Stheraven { 3661227825Stheraven __hw.reset((char_type*)malloc(__exn * sizeof(char_type))); 3662227825Stheraven __mb = __hw.get(); 3663227825Stheraven if (__mb == 0) 3664227825Stheraven __throw_bad_alloc(); 3665227825Stheraven } 3666227825Stheraven // format 3667227825Stheraven char_type* __mi; 3668227825Stheraven char_type* __me; 3669227825Stheraven this->__format(__mb, __mi, __me, __iob.flags(), 3670227825Stheraven __db, __db + __n, __ct, 3671227825Stheraven __neg, __pat, __dp, __ts, __grp, __sym, __sn, __fd); 3672227825Stheraven return __pad_and_output(__s, __mb, __mi, __me, __iob, __fl); 3673227825Stheraven} 3674227825Stheraven 3675227825Stheraventemplate <class _CharT, class _OutputIterator> 3676227825Stheraven_OutputIterator 3677227825Stheravenmoney_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl, 3678227825Stheraven ios_base& __iob, char_type __fl, 3679227825Stheraven const string_type& __digits) const 3680227825Stheraven{ 3681227825Stheraven // gather info 3682227825Stheraven locale __loc = __iob.getloc(); 3683227825Stheraven const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__loc); 3684227825Stheraven bool __neg = __digits.size() > 0 && __digits[0] == __ct.widen('-'); 3685227825Stheraven money_base::pattern __pat; 3686227825Stheraven char_type __dp; 3687227825Stheraven char_type __ts; 3688227825Stheraven string __grp; 3689227825Stheraven string_type __sym; 3690227825Stheraven string_type __sn; 3691227825Stheraven int __fd; 3692227825Stheraven this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd); 3693227825Stheraven // secure memory for formatting 3694227825Stheraven char_type __mbuf[100]; 3695227825Stheraven char_type* __mb = __mbuf; 3696227825Stheraven unique_ptr<char_type, void(*)(void*)> __h(0, free); 3697232950Stheraven size_t __exn = static_cast<int>(__digits.size()) > __fd ? 3698232950Stheraven (__digits.size() - static_cast<size_t>(__fd)) * 2 + 3699232950Stheraven __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 1 3700232950Stheraven : __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 2; 3701227825Stheraven if (__exn > 100) 3702227825Stheraven { 3703227825Stheraven __h.reset((char_type*)malloc(__exn * sizeof(char_type))); 3704227825Stheraven __mb = __h.get(); 3705227825Stheraven if (__mb == 0) 3706227825Stheraven __throw_bad_alloc(); 3707227825Stheraven } 3708227825Stheraven // format 3709227825Stheraven char_type* __mi; 3710227825Stheraven char_type* __me; 3711227825Stheraven this->__format(__mb, __mi, __me, __iob.flags(), 3712227825Stheraven __digits.data(), __digits.data() + __digits.size(), __ct, 3713227825Stheraven __neg, __pat, __dp, __ts, __grp, __sym, __sn, __fd); 3714227825Stheraven return __pad_and_output(__s, __mb, __mi, __me, __iob, __fl); 3715227825Stheraven} 3716227825Stheraven 3717242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class money_put<char>) 3718242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class money_put<wchar_t>) 3719227825Stheraven 3720227825Stheraven// messages 3721227825Stheraven 3722227825Stheravenclass _LIBCPP_VISIBLE messages_base 3723227825Stheraven{ 3724227825Stheravenpublic: 3725227825Stheraven typedef ptrdiff_t catalog; 3726227825Stheraven 3727227825Stheraven _LIBCPP_ALWAYS_INLINE messages_base() {} 3728227825Stheraven}; 3729227825Stheraven 3730227825Stheraventemplate <class _CharT> 3731227825Stheravenclass _LIBCPP_VISIBLE messages 3732227825Stheraven : public locale::facet, 3733227825Stheraven public messages_base 3734227825Stheraven{ 3735227825Stheravenpublic: 3736227825Stheraven typedef _CharT char_type; 3737227825Stheraven typedef basic_string<_CharT> string_type; 3738227825Stheraven 3739227825Stheraven _LIBCPP_ALWAYS_INLINE 3740227825Stheraven explicit messages(size_t __refs = 0) 3741227825Stheraven : locale::facet(__refs) {} 3742227825Stheraven 3743227825Stheraven _LIBCPP_ALWAYS_INLINE 3744227825Stheraven catalog open(const basic_string<char>& __nm, const locale& __loc) const 3745227825Stheraven { 3746227825Stheraven return do_open(__nm, __loc); 3747227825Stheraven } 3748227825Stheraven 3749227825Stheraven _LIBCPP_ALWAYS_INLINE 3750227825Stheraven string_type get(catalog __c, int __set, int __msgid, 3751227825Stheraven const string_type& __dflt) const 3752227825Stheraven { 3753227825Stheraven return do_get(__c, __set, __msgid, __dflt); 3754227825Stheraven } 3755227825Stheraven 3756227825Stheraven _LIBCPP_ALWAYS_INLINE 3757227825Stheraven void close(catalog __c) const 3758227825Stheraven { 3759227825Stheraven do_close(__c); 3760227825Stheraven } 3761227825Stheraven 3762227825Stheraven static locale::id id; 3763227825Stheraven 3764227825Stheravenprotected: 3765227825Stheraven _LIBCPP_ALWAYS_INLINE 3766227825Stheraven ~messages() {} 3767227825Stheraven 3768227825Stheraven virtual catalog do_open(const basic_string<char>&, const locale&) const; 3769227825Stheraven virtual string_type do_get(catalog, int __set, int __msgid, 3770227825Stheraven const string_type& __dflt) const; 3771227825Stheraven virtual void do_close(catalog) const; 3772227825Stheraven}; 3773227825Stheraven 3774227825Stheraventemplate <class _CharT> 3775227825Stheravenlocale::id 3776227825Stheravenmessages<_CharT>::id; 3777227825Stheraven 3778227825Stheraventemplate <class _CharT> 3779227825Stheraventypename messages<_CharT>::catalog 3780227825Stheravenmessages<_CharT>::do_open(const basic_string<char>& __nm, const locale&) const 3781227825Stheraven{ 3782227825Stheraven#if _WIN32 3783227825Stheraven return -1; 3784227825Stheraven#else // _WIN32 3785227825Stheraven catalog __cat = (catalog)catopen(__nm.c_str(), NL_CAT_LOCALE); 3786227825Stheraven if (__cat != -1) 3787227825Stheraven __cat = static_cast<catalog>((static_cast<size_t>(__cat) >> 1)); 3788227825Stheraven return __cat; 3789227825Stheraven#endif // _WIN32 3790227825Stheraven} 3791227825Stheraven 3792227825Stheraventemplate <class _CharT> 3793227825Stheraventypename messages<_CharT>::string_type 3794227825Stheravenmessages<_CharT>::do_get(catalog __c, int __set, int __msgid, 3795227825Stheraven const string_type& __dflt) const 3796227825Stheraven{ 3797227825Stheraven#if _WIN32 3798227825Stheraven return __dflt; 3799227825Stheraven#else // _WIN32 3800227825Stheraven string __ndflt; 3801227825Stheraven __narrow_to_utf8<sizeof(char_type)*__CHAR_BIT__>()(back_inserter(__ndflt), 3802227825Stheraven __dflt.c_str(), 3803227825Stheraven __dflt.c_str() + __dflt.size()); 3804227825Stheraven if (__c != -1) 3805227825Stheraven __c <<= 1; 3806227825Stheraven nl_catd __cat = (nl_catd)__c; 3807227825Stheraven char* __n = catgets(__cat, __set, __msgid, __ndflt.c_str()); 3808227825Stheraven string_type __w; 3809227825Stheraven __widen_from_utf8<sizeof(char_type)*__CHAR_BIT__>()(back_inserter(__w), 3810227825Stheraven __n, __n + strlen(__n)); 3811227825Stheraven return __w; 3812227825Stheraven#endif // _WIN32 3813227825Stheraven} 3814227825Stheraven 3815227825Stheraventemplate <class _CharT> 3816227825Stheravenvoid 3817227825Stheravenmessages<_CharT>::do_close(catalog __c) const 3818227825Stheraven{ 3819227825Stheraven#if !_WIN32 3820227825Stheraven if (__c != -1) 3821227825Stheraven __c <<= 1; 3822227825Stheraven nl_catd __cat = (nl_catd)__c; 3823227825Stheraven catclose(__cat); 3824227825Stheraven#endif // !_WIN32 3825227825Stheraven} 3826227825Stheraven 3827242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class messages<char>) 3828242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class messages<wchar_t>) 3829227825Stheraven 3830227825Stheraventemplate <class _CharT> 3831227825Stheravenclass _LIBCPP_VISIBLE messages_byname 3832227825Stheraven : public messages<_CharT> 3833227825Stheraven{ 3834227825Stheravenpublic: 3835227825Stheraven typedef messages_base::catalog catalog; 3836227825Stheraven typedef basic_string<_CharT> string_type; 3837227825Stheraven 3838227825Stheraven _LIBCPP_ALWAYS_INLINE 3839227825Stheraven explicit messages_byname(const char*, size_t __refs = 0) 3840227825Stheraven : messages<_CharT>(__refs) {} 3841227825Stheraven 3842227825Stheraven _LIBCPP_ALWAYS_INLINE 3843227825Stheraven explicit messages_byname(const string&, size_t __refs = 0) 3844227825Stheraven : messages<_CharT>(__refs) {} 3845227825Stheraven 3846227825Stheravenprotected: 3847227825Stheraven _LIBCPP_ALWAYS_INLINE 3848227825Stheraven ~messages_byname() {} 3849227825Stheraven}; 3850227825Stheraven 3851242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class messages_byname<char>) 3852242945Stheraven_LIBCPP_EXTERN_TEMPLATE(class messages_byname<wchar_t>) 3853227825Stheraven 3854227825Stheraventemplate<class _Codecvt, class _Elem = wchar_t, 3855227825Stheraven class _Wide_alloc = allocator<_Elem>, 3856227825Stheraven class _Byte_alloc = allocator<char> > 3857227825Stheravenclass _LIBCPP_VISIBLE wstring_convert 3858227825Stheraven{ 3859227825Stheravenpublic: 3860227825Stheraven typedef basic_string<char, char_traits<char>, _Byte_alloc> byte_string; 3861227825Stheraven typedef basic_string<_Elem, char_traits<_Elem>, _Wide_alloc> wide_string; 3862227825Stheraven typedef typename _Codecvt::state_type state_type; 3863227825Stheraven typedef typename wide_string::traits_type::int_type int_type; 3864227825Stheraven 3865227825Stheravenprivate: 3866227825Stheraven byte_string __byte_err_string_; 3867227825Stheraven wide_string __wide_err_string_; 3868227825Stheraven _Codecvt* __cvtptr_; 3869227825Stheraven state_type __cvtstate_; 3870227825Stheraven size_t __cvtcount_; 3871227825Stheraven 3872227825Stheraven wstring_convert(const wstring_convert& __wc); 3873227825Stheraven wstring_convert& operator=(const wstring_convert& __wc); 3874227825Stheravenpublic: 3875227825Stheraven wstring_convert(_Codecvt* __pcvt = new _Codecvt); 3876227825Stheraven wstring_convert(_Codecvt* __pcvt, state_type __state); 3877227825Stheraven wstring_convert(const byte_string& __byte_err, 3878227825Stheraven const wide_string& __wide_err = wide_string()); 3879227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3880227825Stheraven wstring_convert(wstring_convert&& __wc); 3881227825Stheraven#endif 3882227825Stheraven ~wstring_convert(); 3883227825Stheraven 3884227825Stheraven _LIBCPP_ALWAYS_INLINE 3885227825Stheraven wide_string from_bytes(char __byte) 3886227825Stheraven {return from_bytes(&__byte, &__byte+1);} 3887227825Stheraven _LIBCPP_ALWAYS_INLINE 3888227825Stheraven wide_string from_bytes(const char* __ptr) 3889227825Stheraven {return from_bytes(__ptr, __ptr + char_traits<char>::length(__ptr));} 3890227825Stheraven _LIBCPP_ALWAYS_INLINE 3891227825Stheraven wide_string from_bytes(const byte_string& __str) 3892227825Stheraven {return from_bytes(__str.data(), __str.data() + __str.size());} 3893227825Stheraven wide_string from_bytes(const char* __first, const char* __last); 3894227825Stheraven 3895227825Stheraven _LIBCPP_ALWAYS_INLINE 3896227825Stheraven byte_string to_bytes(_Elem __wchar) 3897227825Stheraven {return to_bytes(&__wchar, &__wchar+1);} 3898227825Stheraven _LIBCPP_ALWAYS_INLINE 3899227825Stheraven byte_string to_bytes(const _Elem* __wptr) 3900227825Stheraven {return to_bytes(__wptr, __wptr + char_traits<_Elem>::length(__wptr));} 3901227825Stheraven _LIBCPP_ALWAYS_INLINE 3902227825Stheraven byte_string to_bytes(const wide_string& __wstr) 3903227825Stheraven {return to_bytes(__wstr.data(), __wstr.data() + __wstr.size());} 3904227825Stheraven byte_string to_bytes(const _Elem* __first, const _Elem* __last); 3905227825Stheraven 3906227825Stheraven _LIBCPP_ALWAYS_INLINE 3907227825Stheraven size_t converted() const {return __cvtcount_;} 3908227825Stheraven _LIBCPP_ALWAYS_INLINE 3909227825Stheraven state_type state() const {return __cvtstate_;} 3910227825Stheraven}; 3911227825Stheraven 3912227825Stheraventemplate<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> 3913227825Stheraveninline _LIBCPP_ALWAYS_INLINE 3914227825Stheravenwstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: 3915227825Stheraven wstring_convert(_Codecvt* __pcvt) 3916227825Stheraven : __cvtptr_(__pcvt), __cvtstate_(), __cvtcount_(0) 3917227825Stheraven{ 3918227825Stheraven} 3919227825Stheraven 3920227825Stheraventemplate<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> 3921227825Stheraveninline _LIBCPP_ALWAYS_INLINE 3922227825Stheravenwstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: 3923227825Stheraven wstring_convert(_Codecvt* __pcvt, state_type __state) 3924227825Stheraven : __cvtptr_(__pcvt), __cvtstate_(__state), __cvtcount_(0) 3925227825Stheraven{ 3926227825Stheraven} 3927227825Stheraven 3928227825Stheraventemplate<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> 3929227825Stheravenwstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: 3930227825Stheraven wstring_convert(const byte_string& __byte_err, const wide_string& __wide_err) 3931227825Stheraven : __byte_err_string_(__byte_err), __wide_err_string_(__wide_err), 3932227825Stheraven __cvtstate_(), __cvtcount_(0) 3933227825Stheraven{ 3934227825Stheraven __cvtptr_ = new _Codecvt; 3935227825Stheraven} 3936227825Stheraven 3937227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3938227825Stheraven 3939227825Stheraventemplate<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> 3940227825Stheraveninline _LIBCPP_ALWAYS_INLINE 3941227825Stheravenwstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: 3942227825Stheraven wstring_convert(wstring_convert&& __wc) 3943227825Stheraven : __byte_err_string_(_VSTD::move(__wc.__byte_err_string_)), 3944227825Stheraven __wide_err_string_(_VSTD::move(__wc.__wide_err_string_)), 3945227825Stheraven __cvtptr_(__wc.__cvtptr_), 3946227825Stheraven __cvtstate_(__wc.__cvtstate_), __cvtcount_(__wc.__cvtstate_) 3947227825Stheraven{ 3948227825Stheraven __wc.__cvtptr_ = nullptr; 3949227825Stheraven} 3950227825Stheraven 3951227825Stheraven#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 3952227825Stheraven 3953227825Stheraventemplate<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> 3954227825Stheravenwstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::~wstring_convert() 3955227825Stheraven{ 3956227825Stheraven delete __cvtptr_; 3957227825Stheraven} 3958227825Stheraven 3959227825Stheraventemplate<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> 3960227825Stheraventypename wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::wide_string 3961227825Stheravenwstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: 3962227825Stheraven from_bytes(const char* __frm, const char* __frm_end) 3963227825Stheraven{ 3964227825Stheraven __cvtcount_ = 0; 3965227825Stheraven if (__cvtptr_ != nullptr) 3966227825Stheraven { 3967227825Stheraven wide_string __ws(2*(__frm_end - __frm), _Elem()); 3968241903Sdim if (__frm != __frm_end) 3969241903Sdim __ws.resize(__ws.capacity()); 3970227825Stheraven codecvt_base::result __r = codecvt_base::ok; 3971227825Stheraven state_type __st = __cvtstate_; 3972227825Stheraven if (__frm != __frm_end) 3973227825Stheraven { 3974227825Stheraven _Elem* __to = &__ws[0]; 3975227825Stheraven _Elem* __to_end = __to + __ws.size(); 3976227825Stheraven const char* __frm_nxt; 3977227825Stheraven do 3978227825Stheraven { 3979227825Stheraven _Elem* __to_nxt; 3980227825Stheraven __r = __cvtptr_->in(__st, __frm, __frm_end, __frm_nxt, 3981227825Stheraven __to, __to_end, __to_nxt); 3982227825Stheraven __cvtcount_ += __frm_nxt - __frm; 3983227825Stheraven if (__frm_nxt == __frm) 3984227825Stheraven { 3985227825Stheraven __r = codecvt_base::error; 3986227825Stheraven } 3987227825Stheraven else if (__r == codecvt_base::noconv) 3988227825Stheraven { 3989227825Stheraven __ws.resize(__to - &__ws[0]); 3990227825Stheraven // This only gets executed if _Elem is char 3991227825Stheraven __ws.append((const _Elem*)__frm, (const _Elem*)__frm_end); 3992227825Stheraven __frm = __frm_nxt; 3993227825Stheraven __r = codecvt_base::ok; 3994227825Stheraven } 3995227825Stheraven else if (__r == codecvt_base::ok) 3996227825Stheraven { 3997227825Stheraven __ws.resize(__to_nxt - &__ws[0]); 3998227825Stheraven __frm = __frm_nxt; 3999227825Stheraven } 4000227825Stheraven else if (__r == codecvt_base::partial) 4001227825Stheraven { 4002227825Stheraven ptrdiff_t __s = __to_nxt - &__ws[0]; 4003227825Stheraven __ws.resize(2 * __s); 4004227825Stheraven __to = &__ws[0] + __s; 4005227825Stheraven __to_end = &__ws[0] + __ws.size(); 4006227825Stheraven __frm = __frm_nxt; 4007227825Stheraven } 4008227825Stheraven } while (__r == codecvt_base::partial && __frm_nxt < __frm_end); 4009227825Stheraven } 4010227825Stheraven if (__r == codecvt_base::ok) 4011227825Stheraven return __ws; 4012227825Stheraven } 4013227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 4014227825Stheraven if (__wide_err_string_.empty()) 4015227825Stheraven throw range_error("wstring_convert: from_bytes error"); 4016227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 4017227825Stheraven return __wide_err_string_; 4018227825Stheraven} 4019227825Stheraven 4020227825Stheraventemplate<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> 4021227825Stheraventypename wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::byte_string 4022227825Stheravenwstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: 4023227825Stheraven to_bytes(const _Elem* __frm, const _Elem* __frm_end) 4024227825Stheraven{ 4025227825Stheraven __cvtcount_ = 0; 4026227825Stheraven if (__cvtptr_ != nullptr) 4027227825Stheraven { 4028227825Stheraven byte_string __bs(2*(__frm_end - __frm), char()); 4029241903Sdim if (__frm != __frm_end) 4030241903Sdim __bs.resize(__bs.capacity()); 4031227825Stheraven codecvt_base::result __r = codecvt_base::ok; 4032227825Stheraven state_type __st = __cvtstate_; 4033227825Stheraven if (__frm != __frm_end) 4034227825Stheraven { 4035227825Stheraven char* __to = &__bs[0]; 4036227825Stheraven char* __to_end = __to + __bs.size(); 4037227825Stheraven const _Elem* __frm_nxt; 4038227825Stheraven do 4039227825Stheraven { 4040227825Stheraven char* __to_nxt; 4041227825Stheraven __r = __cvtptr_->out(__st, __frm, __frm_end, __frm_nxt, 4042227825Stheraven __to, __to_end, __to_nxt); 4043227825Stheraven __cvtcount_ += __frm_nxt - __frm; 4044227825Stheraven if (__frm_nxt == __frm) 4045227825Stheraven { 4046227825Stheraven __r = codecvt_base::error; 4047227825Stheraven } 4048227825Stheraven else if (__r == codecvt_base::noconv) 4049227825Stheraven { 4050227825Stheraven __bs.resize(__to - &__bs[0]); 4051227825Stheraven // This only gets executed if _Elem is char 4052227825Stheraven __bs.append((const char*)__frm, (const char*)__frm_end); 4053227825Stheraven __frm = __frm_nxt; 4054227825Stheraven __r = codecvt_base::ok; 4055227825Stheraven } 4056227825Stheraven else if (__r == codecvt_base::ok) 4057227825Stheraven { 4058227825Stheraven __bs.resize(__to_nxt - &__bs[0]); 4059227825Stheraven __frm = __frm_nxt; 4060227825Stheraven } 4061227825Stheraven else if (__r == codecvt_base::partial) 4062227825Stheraven { 4063227825Stheraven ptrdiff_t __s = __to_nxt - &__bs[0]; 4064227825Stheraven __bs.resize(2 * __s); 4065227825Stheraven __to = &__bs[0] + __s; 4066227825Stheraven __to_end = &__bs[0] + __bs.size(); 4067227825Stheraven __frm = __frm_nxt; 4068227825Stheraven } 4069227825Stheraven } while (__r == codecvt_base::partial && __frm_nxt < __frm_end); 4070227825Stheraven } 4071227825Stheraven if (__r == codecvt_base::ok) 4072227825Stheraven { 4073227825Stheraven size_t __s = __bs.size(); 4074227825Stheraven __bs.resize(__bs.capacity()); 4075227825Stheraven char* __to = &__bs[0] + __s; 4076227825Stheraven char* __to_end = __to + __bs.size(); 4077227825Stheraven do 4078227825Stheraven { 4079227825Stheraven char* __to_nxt; 4080227825Stheraven __r = __cvtptr_->unshift(__st, __to, __to_end, __to_nxt); 4081227825Stheraven if (__r == codecvt_base::noconv) 4082227825Stheraven { 4083227825Stheraven __bs.resize(__to - &__bs[0]); 4084227825Stheraven __r = codecvt_base::ok; 4085227825Stheraven } 4086227825Stheraven else if (__r == codecvt_base::ok) 4087227825Stheraven { 4088227825Stheraven __bs.resize(__to_nxt - &__bs[0]); 4089227825Stheraven } 4090227825Stheraven else if (__r == codecvt_base::partial) 4091227825Stheraven { 4092232950Stheraven ptrdiff_t __sp = __to_nxt - &__bs[0]; 4093232950Stheraven __bs.resize(2 * __sp); 4094232950Stheraven __to = &__bs[0] + __sp; 4095227825Stheraven __to_end = &__bs[0] + __bs.size(); 4096227825Stheraven } 4097227825Stheraven } while (__r == codecvt_base::partial); 4098227825Stheraven if (__r == codecvt_base::ok) 4099227825Stheraven return __bs; 4100227825Stheraven } 4101227825Stheraven } 4102227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 4103227825Stheraven if (__byte_err_string_.empty()) 4104227825Stheraven throw range_error("wstring_convert: to_bytes error"); 4105227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 4106227825Stheraven return __byte_err_string_; 4107227825Stheraven} 4108227825Stheraven 4109227825Stheraventemplate <class _Codecvt, class _Elem = wchar_t, class _Tr = char_traits<_Elem> > 4110227825Stheravenclass _LIBCPP_VISIBLE wbuffer_convert 4111227825Stheraven : public basic_streambuf<_Elem, _Tr> 4112227825Stheraven{ 4113227825Stheravenpublic: 4114227825Stheraven // types: 4115227825Stheraven typedef _Elem char_type; 4116227825Stheraven typedef _Tr traits_type; 4117227825Stheraven typedef typename traits_type::int_type int_type; 4118227825Stheraven typedef typename traits_type::pos_type pos_type; 4119227825Stheraven typedef typename traits_type::off_type off_type; 4120227825Stheraven typedef typename _Codecvt::state_type state_type; 4121227825Stheraven 4122227825Stheravenprivate: 4123227825Stheraven char* __extbuf_; 4124227825Stheraven const char* __extbufnext_; 4125227825Stheraven const char* __extbufend_; 4126227825Stheraven char __extbuf_min_[8]; 4127227825Stheraven size_t __ebs_; 4128227825Stheraven char_type* __intbuf_; 4129227825Stheraven size_t __ibs_; 4130227825Stheraven streambuf* __bufptr_; 4131227825Stheraven _Codecvt* __cv_; 4132227825Stheraven state_type __st_; 4133227825Stheraven ios_base::openmode __cm_; 4134227825Stheraven bool __owns_eb_; 4135227825Stheraven bool __owns_ib_; 4136227825Stheraven bool __always_noconv_; 4137227825Stheraven 4138227825Stheraven wbuffer_convert(const wbuffer_convert&); 4139227825Stheraven wbuffer_convert& operator=(const wbuffer_convert&); 4140227825Stheravenpublic: 4141227825Stheraven wbuffer_convert(streambuf* __bytebuf = 0, _Codecvt* __pcvt = new _Codecvt, 4142227825Stheraven state_type __state = state_type()); 4143227825Stheraven ~wbuffer_convert(); 4144227825Stheraven 4145227825Stheraven _LIBCPP_INLINE_VISIBILITY 4146227825Stheraven streambuf* rdbuf() const {return __bufptr_;} 4147227825Stheraven _LIBCPP_INLINE_VISIBILITY 4148227825Stheraven streambuf* rdbuf(streambuf* __bytebuf) 4149227825Stheraven { 4150227825Stheraven streambuf* __r = __bufptr_; 4151227825Stheraven __bufptr_ = __bytebuf; 4152227825Stheraven return __r; 4153227825Stheraven } 4154227825Stheraven 4155227825Stheraven _LIBCPP_INLINE_VISIBILITY 4156227825Stheraven state_type state() const {return __st_;} 4157227825Stheraven 4158227825Stheravenprotected: 4159227825Stheraven virtual int_type underflow(); 4160227825Stheraven virtual int_type pbackfail(int_type __c = traits_type::eof()); 4161227825Stheraven virtual int_type overflow (int_type __c = traits_type::eof()); 4162227825Stheraven virtual basic_streambuf<char_type, traits_type>* setbuf(char_type* __s, 4163227825Stheraven streamsize __n); 4164227825Stheraven virtual pos_type seekoff(off_type __off, ios_base::seekdir __way, 4165227825Stheraven ios_base::openmode __wch = ios_base::in | ios_base::out); 4166227825Stheraven virtual pos_type seekpos(pos_type __sp, 4167227825Stheraven ios_base::openmode __wch = ios_base::in | ios_base::out); 4168227825Stheraven virtual int sync(); 4169227825Stheraven 4170227825Stheravenprivate: 4171227825Stheraven bool __read_mode(); 4172227825Stheraven void __write_mode(); 4173227825Stheraven wbuffer_convert* __close(); 4174227825Stheraven}; 4175227825Stheraven 4176227825Stheraventemplate <class _Codecvt, class _Elem, class _Tr> 4177227825Stheravenwbuffer_convert<_Codecvt, _Elem, _Tr>:: 4178227825Stheraven wbuffer_convert(streambuf* __bytebuf, _Codecvt* __pcvt, state_type __state) 4179227825Stheraven : __extbuf_(0), 4180227825Stheraven __extbufnext_(0), 4181227825Stheraven __extbufend_(0), 4182227825Stheraven __ebs_(0), 4183227825Stheraven __intbuf_(0), 4184227825Stheraven __ibs_(0), 4185227825Stheraven __bufptr_(__bytebuf), 4186227825Stheraven __cv_(__pcvt), 4187227825Stheraven __st_(__state), 4188227825Stheraven __cm_(0), 4189227825Stheraven __owns_eb_(false), 4190227825Stheraven __owns_ib_(false), 4191227825Stheraven __always_noconv_(__cv_ ? __cv_->always_noconv() : false) 4192227825Stheraven{ 4193227825Stheraven setbuf(0, 4096); 4194227825Stheraven} 4195227825Stheraven 4196227825Stheraventemplate <class _Codecvt, class _Elem, class _Tr> 4197227825Stheravenwbuffer_convert<_Codecvt, _Elem, _Tr>::~wbuffer_convert() 4198227825Stheraven{ 4199227825Stheraven __close(); 4200227825Stheraven delete __cv_; 4201227825Stheraven if (__owns_eb_) 4202227825Stheraven delete [] __extbuf_; 4203227825Stheraven if (__owns_ib_) 4204227825Stheraven delete [] __intbuf_; 4205227825Stheraven} 4206227825Stheraven 4207227825Stheraventemplate <class _Codecvt, class _Elem, class _Tr> 4208227825Stheraventypename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type 4209227825Stheravenwbuffer_convert<_Codecvt, _Elem, _Tr>::underflow() 4210227825Stheraven{ 4211227825Stheraven if (__cv_ == 0 || __bufptr_ == 0) 4212227825Stheraven return traits_type::eof(); 4213227825Stheraven bool __initial = __read_mode(); 4214227825Stheraven char_type __1buf; 4215227825Stheraven if (this->gptr() == 0) 4216227825Stheraven this->setg(&__1buf, &__1buf+1, &__1buf+1); 4217227825Stheraven const size_t __unget_sz = __initial ? 0 : min<size_t>((this->egptr() - this->eback()) / 2, 4); 4218227825Stheraven int_type __c = traits_type::eof(); 4219227825Stheraven if (this->gptr() == this->egptr()) 4220227825Stheraven { 4221227825Stheraven memmove(this->eback(), this->egptr() - __unget_sz, __unget_sz * sizeof(char_type)); 4222227825Stheraven if (__always_noconv_) 4223227825Stheraven { 4224227825Stheraven streamsize __nmemb = static_cast<streamsize>(this->egptr() - this->eback() - __unget_sz); 4225227825Stheraven __nmemb = __bufptr_->sgetn((char*)this->eback() + __unget_sz, __nmemb); 4226227825Stheraven if (__nmemb != 0) 4227227825Stheraven { 4228227825Stheraven this->setg(this->eback(), 4229227825Stheraven this->eback() + __unget_sz, 4230227825Stheraven this->eback() + __unget_sz + __nmemb); 4231227825Stheraven __c = *this->gptr(); 4232227825Stheraven } 4233227825Stheraven } 4234227825Stheraven else 4235227825Stheraven { 4236227825Stheraven memmove(__extbuf_, __extbufnext_, __extbufend_ - __extbufnext_); 4237227825Stheraven __extbufnext_ = __extbuf_ + (__extbufend_ - __extbufnext_); 4238227825Stheraven __extbufend_ = __extbuf_ + (__extbuf_ == __extbuf_min_ ? sizeof(__extbuf_min_) : __ebs_); 4239227825Stheraven streamsize __nmemb = _VSTD::min(static_cast<streamsize>(this->egptr() - this->eback() - __unget_sz), 4240227825Stheraven static_cast<streamsize>(__extbufend_ - __extbufnext_)); 4241227825Stheraven codecvt_base::result __r; 4242227825Stheraven state_type __svs = __st_; 4243227825Stheraven streamsize __nr = __bufptr_->sgetn(const_cast<char*>(__extbufnext_), __nmemb); 4244227825Stheraven if (__nr != 0) 4245227825Stheraven { 4246227825Stheraven __extbufend_ = __extbufnext_ + __nr; 4247227825Stheraven char_type* __inext; 4248227825Stheraven __r = __cv_->in(__st_, __extbuf_, __extbufend_, __extbufnext_, 4249227825Stheraven this->eback() + __unget_sz, 4250227825Stheraven this->egptr(), __inext); 4251227825Stheraven if (__r == codecvt_base::noconv) 4252227825Stheraven { 4253227825Stheraven this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, (char_type*)__extbufend_); 4254227825Stheraven __c = *this->gptr(); 4255227825Stheraven } 4256227825Stheraven else if (__inext != this->eback() + __unget_sz) 4257227825Stheraven { 4258227825Stheraven this->setg(this->eback(), this->eback() + __unget_sz, __inext); 4259227825Stheraven __c = *this->gptr(); 4260227825Stheraven } 4261227825Stheraven } 4262227825Stheraven } 4263227825Stheraven } 4264227825Stheraven else 4265227825Stheraven __c = *this->gptr(); 4266227825Stheraven if (this->eback() == &__1buf) 4267227825Stheraven this->setg(0, 0, 0); 4268227825Stheraven return __c; 4269227825Stheraven} 4270227825Stheraven 4271227825Stheraventemplate <class _Codecvt, class _Elem, class _Tr> 4272227825Stheraventypename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type 4273227825Stheravenwbuffer_convert<_Codecvt, _Elem, _Tr>::pbackfail(int_type __c) 4274227825Stheraven{ 4275227825Stheraven if (__cv_ != 0 && __bufptr_ != 0 && this->eback() < this->gptr()) 4276227825Stheraven { 4277227825Stheraven if (traits_type::eq_int_type(__c, traits_type::eof())) 4278227825Stheraven { 4279227825Stheraven this->gbump(-1); 4280227825Stheraven return traits_type::not_eof(__c); 4281227825Stheraven } 4282227825Stheraven if (traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) 4283227825Stheraven { 4284227825Stheraven this->gbump(-1); 4285227825Stheraven *this->gptr() = traits_type::to_char_type(__c); 4286227825Stheraven return __c; 4287227825Stheraven } 4288227825Stheraven } 4289227825Stheraven return traits_type::eof(); 4290227825Stheraven} 4291227825Stheraven 4292227825Stheraventemplate <class _Codecvt, class _Elem, class _Tr> 4293227825Stheraventypename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type 4294227825Stheravenwbuffer_convert<_Codecvt, _Elem, _Tr>::overflow(int_type __c) 4295227825Stheraven{ 4296227825Stheraven if (__cv_ == 0 || __bufptr_ == 0) 4297227825Stheraven return traits_type::eof(); 4298227825Stheraven __write_mode(); 4299227825Stheraven char_type __1buf; 4300227825Stheraven char_type* __pb_save = this->pbase(); 4301227825Stheraven char_type* __epb_save = this->epptr(); 4302227825Stheraven if (!traits_type::eq_int_type(__c, traits_type::eof())) 4303227825Stheraven { 4304227825Stheraven if (this->pptr() == 0) 4305227825Stheraven this->setp(&__1buf, &__1buf+1); 4306227825Stheraven *this->pptr() = traits_type::to_char_type(__c); 4307227825Stheraven this->pbump(1); 4308227825Stheraven } 4309227825Stheraven if (this->pptr() != this->pbase()) 4310227825Stheraven { 4311227825Stheraven if (__always_noconv_) 4312227825Stheraven { 4313227825Stheraven streamsize __nmemb = static_cast<streamsize>(this->pptr() - this->pbase()); 4314227825Stheraven if (__bufptr_->sputn((const char*)this->pbase(), __nmemb) != __nmemb) 4315227825Stheraven return traits_type::eof(); 4316227825Stheraven } 4317227825Stheraven else 4318227825Stheraven { 4319227825Stheraven char* __extbe = __extbuf_; 4320227825Stheraven codecvt_base::result __r; 4321227825Stheraven do 4322227825Stheraven { 4323227825Stheraven const char_type* __e; 4324227825Stheraven __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e, 4325227825Stheraven __extbuf_, __extbuf_ + __ebs_, __extbe); 4326227825Stheraven if (__e == this->pbase()) 4327227825Stheraven return traits_type::eof(); 4328227825Stheraven if (__r == codecvt_base::noconv) 4329227825Stheraven { 4330227825Stheraven streamsize __nmemb = static_cast<size_t>(this->pptr() - this->pbase()); 4331227825Stheraven if (__bufptr_->sputn((const char*)this->pbase(), __nmemb) != __nmemb) 4332227825Stheraven return traits_type::eof(); 4333227825Stheraven } 4334227825Stheraven else if (__r == codecvt_base::ok || __r == codecvt_base::partial) 4335227825Stheraven { 4336227825Stheraven streamsize __nmemb = static_cast<size_t>(__extbe - __extbuf_); 4337227825Stheraven if (__bufptr_->sputn(__extbuf_, __nmemb) != __nmemb) 4338227825Stheraven return traits_type::eof(); 4339227825Stheraven if (__r == codecvt_base::partial) 4340227825Stheraven { 4341227825Stheraven this->setp((char_type*)__e, this->pptr()); 4342227825Stheraven this->pbump(this->epptr() - this->pbase()); 4343227825Stheraven } 4344227825Stheraven } 4345227825Stheraven else 4346227825Stheraven return traits_type::eof(); 4347227825Stheraven } while (__r == codecvt_base::partial); 4348227825Stheraven } 4349227825Stheraven this->setp(__pb_save, __epb_save); 4350227825Stheraven } 4351227825Stheraven return traits_type::not_eof(__c); 4352227825Stheraven} 4353227825Stheraven 4354227825Stheraventemplate <class _Codecvt, class _Elem, class _Tr> 4355227825Stheravenbasic_streambuf<_Elem, _Tr>* 4356227825Stheravenwbuffer_convert<_Codecvt, _Elem, _Tr>::setbuf(char_type* __s, streamsize __n) 4357227825Stheraven{ 4358227825Stheraven this->setg(0, 0, 0); 4359227825Stheraven this->setp(0, 0); 4360227825Stheraven if (__owns_eb_) 4361227825Stheraven delete [] __extbuf_; 4362227825Stheraven if (__owns_ib_) 4363227825Stheraven delete [] __intbuf_; 4364227825Stheraven __ebs_ = __n; 4365227825Stheraven if (__ebs_ > sizeof(__extbuf_min_)) 4366227825Stheraven { 4367227825Stheraven if (__always_noconv_ && __s) 4368227825Stheraven { 4369227825Stheraven __extbuf_ = (char*)__s; 4370227825Stheraven __owns_eb_ = false; 4371227825Stheraven } 4372227825Stheraven else 4373227825Stheraven { 4374227825Stheraven __extbuf_ = new char[__ebs_]; 4375227825Stheraven __owns_eb_ = true; 4376227825Stheraven } 4377227825Stheraven } 4378227825Stheraven else 4379227825Stheraven { 4380227825Stheraven __extbuf_ = __extbuf_min_; 4381227825Stheraven __ebs_ = sizeof(__extbuf_min_); 4382227825Stheraven __owns_eb_ = false; 4383227825Stheraven } 4384227825Stheraven if (!__always_noconv_) 4385227825Stheraven { 4386227825Stheraven __ibs_ = max<streamsize>(__n, sizeof(__extbuf_min_)); 4387227825Stheraven if (__s && __ibs_ >= sizeof(__extbuf_min_)) 4388227825Stheraven { 4389227825Stheraven __intbuf_ = __s; 4390227825Stheraven __owns_ib_ = false; 4391227825Stheraven } 4392227825Stheraven else 4393227825Stheraven { 4394227825Stheraven __intbuf_ = new char_type[__ibs_]; 4395227825Stheraven __owns_ib_ = true; 4396227825Stheraven } 4397227825Stheraven } 4398227825Stheraven else 4399227825Stheraven { 4400227825Stheraven __ibs_ = 0; 4401227825Stheraven __intbuf_ = 0; 4402227825Stheraven __owns_ib_ = false; 4403227825Stheraven } 4404227825Stheraven return this; 4405227825Stheraven} 4406227825Stheraven 4407227825Stheraventemplate <class _Codecvt, class _Elem, class _Tr> 4408227825Stheraventypename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type 4409227825Stheravenwbuffer_convert<_Codecvt, _Elem, _Tr>::seekoff(off_type __off, ios_base::seekdir __way, 4410227825Stheraven ios_base::openmode __om) 4411227825Stheraven{ 4412227825Stheraven int __width = __cv_->encoding(); 4413227825Stheraven if (__cv_ == 0 || __bufptr_ == 0 || (__width <= 0 && __off != 0) || sync()) 4414227825Stheraven return pos_type(off_type(-1)); 4415227825Stheraven // __width > 0 || __off == 0 4416227825Stheraven switch (__way) 4417227825Stheraven { 4418227825Stheraven case ios_base::beg: 4419227825Stheraven break; 4420227825Stheraven case ios_base::cur: 4421227825Stheraven break; 4422227825Stheraven case ios_base::end: 4423227825Stheraven break; 4424227825Stheraven default: 4425227825Stheraven return pos_type(off_type(-1)); 4426227825Stheraven } 4427227825Stheraven pos_type __r = __bufptr_->pubseekoff(__width * __off, __way, __om); 4428227825Stheraven __r.state(__st_); 4429227825Stheraven return __r; 4430227825Stheraven} 4431227825Stheraven 4432227825Stheraventemplate <class _Codecvt, class _Elem, class _Tr> 4433227825Stheraventypename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type 4434227825Stheravenwbuffer_convert<_Codecvt, _Elem, _Tr>::seekpos(pos_type __sp, ios_base::openmode __wch) 4435227825Stheraven{ 4436227825Stheraven if (__cv_ == 0 || __bufptr_ == 0 || sync()) 4437227825Stheraven return pos_type(off_type(-1)); 4438227825Stheraven if (__bufptr_->pubseekpos(__sp, __wch) == pos_type(off_type(-1))) 4439227825Stheraven return pos_type(off_type(-1)); 4440227825Stheraven return __sp; 4441227825Stheraven} 4442227825Stheraven 4443227825Stheraventemplate <class _Codecvt, class _Elem, class _Tr> 4444227825Stheravenint 4445227825Stheravenwbuffer_convert<_Codecvt, _Elem, _Tr>::sync() 4446227825Stheraven{ 4447227825Stheraven if (__cv_ == 0 || __bufptr_ == 0) 4448227825Stheraven return 0; 4449227825Stheraven if (__cm_ & ios_base::out) 4450227825Stheraven { 4451227825Stheraven if (this->pptr() != this->pbase()) 4452227825Stheraven if (overflow() == traits_type::eof()) 4453227825Stheraven return -1; 4454227825Stheraven codecvt_base::result __r; 4455227825Stheraven do 4456227825Stheraven { 4457227825Stheraven char* __extbe; 4458227825Stheraven __r = __cv_->unshift(__st_, __extbuf_, __extbuf_ + __ebs_, __extbe); 4459227825Stheraven streamsize __nmemb = static_cast<streamsize>(__extbe - __extbuf_); 4460227825Stheraven if (__bufptr_->sputn(__extbuf_, __nmemb) != __nmemb) 4461227825Stheraven return -1; 4462227825Stheraven } while (__r == codecvt_base::partial); 4463227825Stheraven if (__r == codecvt_base::error) 4464227825Stheraven return -1; 4465227825Stheraven if (__bufptr_->pubsync()) 4466227825Stheraven return -1; 4467227825Stheraven } 4468227825Stheraven else if (__cm_ & ios_base::in) 4469227825Stheraven { 4470227825Stheraven off_type __c; 4471227825Stheraven if (__always_noconv_) 4472227825Stheraven __c = this->egptr() - this->gptr(); 4473227825Stheraven else 4474227825Stheraven { 4475227825Stheraven int __width = __cv_->encoding(); 4476227825Stheraven __c = __extbufend_ - __extbufnext_; 4477227825Stheraven if (__width > 0) 4478227825Stheraven __c += __width * (this->egptr() - this->gptr()); 4479227825Stheraven else 4480227825Stheraven { 4481227825Stheraven if (this->gptr() != this->egptr()) 4482227825Stheraven { 4483227825Stheraven reverse(this->gptr(), this->egptr()); 4484227825Stheraven codecvt_base::result __r; 4485227825Stheraven const char_type* __e = this->gptr(); 4486227825Stheraven char* __extbe; 4487227825Stheraven do 4488227825Stheraven { 4489227825Stheraven __r = __cv_->out(__st_, __e, this->egptr(), __e, 4490227825Stheraven __extbuf_, __extbuf_ + __ebs_, __extbe); 4491227825Stheraven switch (__r) 4492227825Stheraven { 4493227825Stheraven case codecvt_base::noconv: 4494227825Stheraven __c += this->egptr() - this->gptr(); 4495227825Stheraven break; 4496227825Stheraven case codecvt_base::ok: 4497227825Stheraven case codecvt_base::partial: 4498227825Stheraven __c += __extbe - __extbuf_; 4499227825Stheraven break; 4500227825Stheraven default: 4501227825Stheraven return -1; 4502227825Stheraven } 4503227825Stheraven } while (__r == codecvt_base::partial); 4504227825Stheraven } 4505227825Stheraven } 4506227825Stheraven } 4507227825Stheraven if (__bufptr_->pubseekoff(-__c, ios_base::cur, __cm_) == pos_type(off_type(-1))) 4508227825Stheraven return -1; 4509227825Stheraven this->setg(0, 0, 0); 4510227825Stheraven __cm_ = 0; 4511227825Stheraven } 4512227825Stheraven return 0; 4513227825Stheraven} 4514227825Stheraven 4515227825Stheraventemplate <class _Codecvt, class _Elem, class _Tr> 4516227825Stheravenbool 4517227825Stheravenwbuffer_convert<_Codecvt, _Elem, _Tr>::__read_mode() 4518227825Stheraven{ 4519227825Stheraven if (!(__cm_ & ios_base::in)) 4520227825Stheraven { 4521227825Stheraven this->setp(0, 0); 4522227825Stheraven if (__always_noconv_) 4523227825Stheraven this->setg((char_type*)__extbuf_, 4524227825Stheraven (char_type*)__extbuf_ + __ebs_, 4525227825Stheraven (char_type*)__extbuf_ + __ebs_); 4526227825Stheraven else 4527227825Stheraven this->setg(__intbuf_, __intbuf_ + __ibs_, __intbuf_ + __ibs_); 4528227825Stheraven __cm_ = ios_base::in; 4529227825Stheraven return true; 4530227825Stheraven } 4531227825Stheraven return false; 4532227825Stheraven} 4533227825Stheraven 4534227825Stheraventemplate <class _Codecvt, class _Elem, class _Tr> 4535227825Stheravenvoid 4536227825Stheravenwbuffer_convert<_Codecvt, _Elem, _Tr>::__write_mode() 4537227825Stheraven{ 4538227825Stheraven if (!(__cm_ & ios_base::out)) 4539227825Stheraven { 4540227825Stheraven this->setg(0, 0, 0); 4541227825Stheraven if (__ebs_ > sizeof(__extbuf_min_)) 4542227825Stheraven { 4543227825Stheraven if (__always_noconv_) 4544227825Stheraven this->setp((char_type*)__extbuf_, 4545227825Stheraven (char_type*)__extbuf_ + (__ebs_ - 1)); 4546227825Stheraven else 4547227825Stheraven this->setp(__intbuf_, __intbuf_ + (__ibs_ - 1)); 4548227825Stheraven } 4549227825Stheraven else 4550227825Stheraven this->setp(0, 0); 4551227825Stheraven __cm_ = ios_base::out; 4552227825Stheraven } 4553227825Stheraven} 4554227825Stheraven 4555227825Stheraventemplate <class _Codecvt, class _Elem, class _Tr> 4556227825Stheravenwbuffer_convert<_Codecvt, _Elem, _Tr>* 4557227825Stheravenwbuffer_convert<_Codecvt, _Elem, _Tr>::__close() 4558227825Stheraven{ 4559227825Stheraven wbuffer_convert* __rt = 0; 4560227825Stheraven if (__cv_ != 0 && __bufptr_ != 0) 4561227825Stheraven { 4562227825Stheraven __rt = this; 4563227825Stheraven if ((__cm_ & ios_base::out) && sync()) 4564227825Stheraven __rt = 0; 4565227825Stheraven } 4566227825Stheraven return __rt; 4567227825Stheraven} 4568227825Stheraven 4569227825Stheraven_LIBCPP_END_NAMESPACE_STD 4570227825Stheraven 4571227825Stheraven#endif // _LIBCPP_LOCALE 4572