14684ddb6SLionel Sambuc// -*- C++ -*- 24684ddb6SLionel Sambuc//===-------------------------- locale ------------------------------------===// 34684ddb6SLionel Sambuc// 44684ddb6SLionel Sambuc// The LLVM Compiler Infrastructure 54684ddb6SLionel Sambuc// 64684ddb6SLionel Sambuc// This file is dual licensed under the MIT and the University of Illinois Open 74684ddb6SLionel Sambuc// Source Licenses. See LICENSE.TXT for details. 84684ddb6SLionel Sambuc// 94684ddb6SLionel Sambuc//===----------------------------------------------------------------------===// 104684ddb6SLionel Sambuc 114684ddb6SLionel Sambuc#ifndef _LIBCPP_LOCALE 124684ddb6SLionel Sambuc#define _LIBCPP_LOCALE 134684ddb6SLionel Sambuc 144684ddb6SLionel Sambuc/* 154684ddb6SLionel Sambuc locale synopsis 164684ddb6SLionel Sambuc 174684ddb6SLionel Sambucnamespace std 184684ddb6SLionel Sambuc{ 194684ddb6SLionel Sambuc 204684ddb6SLionel Sambucclass locale 214684ddb6SLionel Sambuc{ 224684ddb6SLionel Sambucpublic: 234684ddb6SLionel Sambuc // types: 244684ddb6SLionel Sambuc class facet; 254684ddb6SLionel Sambuc class id; 264684ddb6SLionel Sambuc 274684ddb6SLionel Sambuc typedef int category; 284684ddb6SLionel Sambuc static const category // values assigned here are for exposition only 294684ddb6SLionel Sambuc none = 0x000, 304684ddb6SLionel Sambuc collate = 0x010, 314684ddb6SLionel Sambuc ctype = 0x020, 324684ddb6SLionel Sambuc monetary = 0x040, 334684ddb6SLionel Sambuc numeric = 0x080, 344684ddb6SLionel Sambuc time = 0x100, 354684ddb6SLionel Sambuc messages = 0x200, 364684ddb6SLionel Sambuc all = collate | ctype | monetary | numeric | time | messages; 374684ddb6SLionel Sambuc 384684ddb6SLionel Sambuc // construct/copy/destroy: 394684ddb6SLionel Sambuc locale() noexcept; 404684ddb6SLionel Sambuc locale(const locale& other) noexcept; 414684ddb6SLionel Sambuc explicit locale(const char* std_name); 424684ddb6SLionel Sambuc explicit locale(const string& std_name); 434684ddb6SLionel Sambuc locale(const locale& other, const char* std_name, category); 444684ddb6SLionel Sambuc locale(const locale& other, const string& std_name, category); 454684ddb6SLionel Sambuc template <class Facet> locale(const locale& other, Facet* f); 464684ddb6SLionel Sambuc locale(const locale& other, const locale& one, category); 474684ddb6SLionel Sambuc 484684ddb6SLionel Sambuc ~locale(); // not virtual 494684ddb6SLionel Sambuc 504684ddb6SLionel Sambuc const locale& operator=(const locale& other) noexcept; 514684ddb6SLionel Sambuc 524684ddb6SLionel Sambuc template <class Facet> locale combine(const locale& other) const; 534684ddb6SLionel Sambuc 544684ddb6SLionel Sambuc // locale operations: 554684ddb6SLionel Sambuc basic_string<char> name() const; 564684ddb6SLionel Sambuc bool operator==(const locale& other) const; 574684ddb6SLionel Sambuc bool operator!=(const locale& other) const; 584684ddb6SLionel Sambuc template <class charT, class Traits, class Allocator> 594684ddb6SLionel Sambuc bool operator()(const basic_string<charT,Traits,Allocator>& s1, 604684ddb6SLionel Sambuc const basic_string<charT,Traits,Allocator>& s2) const; 614684ddb6SLionel Sambuc 624684ddb6SLionel Sambuc // global locale objects: 634684ddb6SLionel Sambuc static locale global(const locale&); 644684ddb6SLionel Sambuc static const locale& classic(); 654684ddb6SLionel Sambuc}; 664684ddb6SLionel Sambuc 674684ddb6SLionel Sambuctemplate <class Facet> const Facet& use_facet(const locale&); 684684ddb6SLionel Sambuctemplate <class Facet> bool has_facet(const locale&) noexcept; 694684ddb6SLionel Sambuc 704684ddb6SLionel Sambuc// 22.3.3, convenience interfaces: 714684ddb6SLionel Sambuctemplate <class charT> bool isspace (charT c, const locale& loc); 724684ddb6SLionel Sambuctemplate <class charT> bool isprint (charT c, const locale& loc); 734684ddb6SLionel Sambuctemplate <class charT> bool iscntrl (charT c, const locale& loc); 744684ddb6SLionel Sambuctemplate <class charT> bool isupper (charT c, const locale& loc); 754684ddb6SLionel Sambuctemplate <class charT> bool islower (charT c, const locale& loc); 764684ddb6SLionel Sambuctemplate <class charT> bool isalpha (charT c, const locale& loc); 774684ddb6SLionel Sambuctemplate <class charT> bool isdigit (charT c, const locale& loc); 784684ddb6SLionel Sambuctemplate <class charT> bool ispunct (charT c, const locale& loc); 794684ddb6SLionel Sambuctemplate <class charT> bool isxdigit(charT c, const locale& loc); 804684ddb6SLionel Sambuctemplate <class charT> bool isalnum (charT c, const locale& loc); 814684ddb6SLionel Sambuctemplate <class charT> bool isgraph (charT c, const locale& loc); 824684ddb6SLionel Sambuctemplate <class charT> charT toupper(charT c, const locale& loc); 834684ddb6SLionel Sambuctemplate <class charT> charT tolower(charT c, const locale& loc); 844684ddb6SLionel Sambuc 854684ddb6SLionel Sambuctemplate<class Codecvt, class Elem = wchar_t, 864684ddb6SLionel Sambuc class Wide_alloc = allocator<Elem>, 874684ddb6SLionel Sambuc class Byte_alloc = allocator<char>> 884684ddb6SLionel Sambucclass wstring_convert 894684ddb6SLionel Sambuc{ 904684ddb6SLionel Sambucpublic: 914684ddb6SLionel Sambuc typedef basic_string<char, char_traits<char>, Byte_alloc> byte_string; 924684ddb6SLionel Sambuc typedef basic_string<Elem, char_traits<Elem>, Wide_alloc> wide_string; 934684ddb6SLionel Sambuc typedef typename Codecvt::state_type state_type; 944684ddb6SLionel Sambuc typedef typename wide_string::traits_type::int_type int_type; 954684ddb6SLionel Sambuc 964684ddb6SLionel Sambuc explicit wstring_convert(Codecvt* pcvt = new Codecvt); // explicit in C++14 974684ddb6SLionel Sambuc wstring_convert(Codecvt* pcvt, state_type state); 984684ddb6SLionel Sambuc explicit wstring_convert(const byte_string& byte_err, // explicit in C++14 994684ddb6SLionel Sambuc const wide_string& wide_err = wide_string()); 1004684ddb6SLionel Sambuc wstring_convert(const wstring_convert&) = delete; // C++14 1014684ddb6SLionel Sambuc wstring_convert & operator=(const wstring_convert &) = delete; // C++14 1024684ddb6SLionel Sambuc ~wstring_convert(); 1034684ddb6SLionel Sambuc 1044684ddb6SLionel Sambuc wide_string from_bytes(char byte); 1054684ddb6SLionel Sambuc wide_string from_bytes(const char* ptr); 1064684ddb6SLionel Sambuc wide_string from_bytes(const byte_string& str); 1074684ddb6SLionel Sambuc wide_string from_bytes(const char* first, const char* last); 1084684ddb6SLionel Sambuc 1094684ddb6SLionel Sambuc byte_string to_bytes(Elem wchar); 1104684ddb6SLionel Sambuc byte_string to_bytes(const Elem* wptr); 1114684ddb6SLionel Sambuc byte_string to_bytes(const wide_string& wstr); 1124684ddb6SLionel Sambuc byte_string to_bytes(const Elem* first, const Elem* last); 1134684ddb6SLionel Sambuc 1144684ddb6SLionel Sambuc size_t converted() const; // noexcept in C++14 1154684ddb6SLionel Sambuc state_type state() const; 1164684ddb6SLionel Sambuc}; 1174684ddb6SLionel Sambuc 1184684ddb6SLionel Sambuctemplate <class Codecvt, class Elem = wchar_t, class Tr = char_traits<Elem>> 1194684ddb6SLionel Sambucclass wbuffer_convert 1204684ddb6SLionel Sambuc : public basic_streambuf<Elem, Tr> 1214684ddb6SLionel Sambuc{ 1224684ddb6SLionel Sambucpublic: 1234684ddb6SLionel Sambuc typedef typename Tr::state_type state_type; 1244684ddb6SLionel Sambuc 1254684ddb6SLionel Sambuc explicit wbuffer_convert(streambuf* bytebuf = 0, Codecvt* pcvt = new Codecvt, 1264684ddb6SLionel Sambuc state_type state = state_type()); // explicit in C++14 1274684ddb6SLionel Sambuc wbuffer_convert(const wbuffer_convert&) = delete; // C++14 1284684ddb6SLionel Sambuc wbuffer_convert & operator=(const wbuffer_convert &) = delete; // C++14 1294684ddb6SLionel Sambuc ~wbuffer_convert(); // C++14 1304684ddb6SLionel Sambuc 1314684ddb6SLionel Sambuc streambuf* rdbuf() const; 1324684ddb6SLionel Sambuc streambuf* rdbuf(streambuf* bytebuf); 1334684ddb6SLionel Sambuc 1344684ddb6SLionel Sambuc state_type state() const; 1354684ddb6SLionel Sambuc}; 1364684ddb6SLionel Sambuc 1374684ddb6SLionel Sambuc// 22.4.1 and 22.4.1.3, ctype: 1384684ddb6SLionel Sambucclass ctype_base; 1394684ddb6SLionel Sambuctemplate <class charT> class ctype; 1404684ddb6SLionel Sambuctemplate <> class ctype<char>; // specialization 1414684ddb6SLionel Sambuctemplate <class charT> class ctype_byname; 1424684ddb6SLionel Sambuctemplate <> class ctype_byname<char>; // specialization 1434684ddb6SLionel Sambuc 1444684ddb6SLionel Sambucclass codecvt_base; 1454684ddb6SLionel Sambuctemplate <class internT, class externT, class stateT> class codecvt; 1464684ddb6SLionel Sambuctemplate <class internT, class externT, class stateT> class codecvt_byname; 1474684ddb6SLionel Sambuc 1484684ddb6SLionel Sambuc// 22.4.2 and 22.4.3, numeric: 1494684ddb6SLionel Sambuctemplate <class charT, class InputIterator> class num_get; 1504684ddb6SLionel Sambuctemplate <class charT, class OutputIterator> class num_put; 1514684ddb6SLionel Sambuctemplate <class charT> class numpunct; 1524684ddb6SLionel Sambuctemplate <class charT> class numpunct_byname; 1534684ddb6SLionel Sambuc 1544684ddb6SLionel Sambuc// 22.4.4, col lation: 1554684ddb6SLionel Sambuctemplate <class charT> class collate; 1564684ddb6SLionel Sambuctemplate <class charT> class collate_byname; 1574684ddb6SLionel Sambuc 1584684ddb6SLionel Sambuc// 22.4.5, date and time: 1594684ddb6SLionel Sambucclass time_base; 1604684ddb6SLionel Sambuctemplate <class charT, class InputIterator> class time_get; 1614684ddb6SLionel Sambuctemplate <class charT, class InputIterator> class time_get_byname; 1624684ddb6SLionel Sambuctemplate <class charT, class OutputIterator> class time_put; 1634684ddb6SLionel Sambuctemplate <class charT, class OutputIterator> class time_put_byname; 1644684ddb6SLionel Sambuc 1654684ddb6SLionel Sambuc// 22.4.6, money: 1664684ddb6SLionel Sambucclass money_base; 1674684ddb6SLionel Sambuctemplate <class charT, class InputIterator> class money_get; 1684684ddb6SLionel Sambuctemplate <class charT, class OutputIterator> class money_put; 1694684ddb6SLionel Sambuctemplate <class charT, bool Intl> class moneypunct; 1704684ddb6SLionel Sambuctemplate <class charT, bool Intl> class moneypunct_byname; 1714684ddb6SLionel Sambuc 1724684ddb6SLionel Sambuc// 22.4.7, message retrieval: 1734684ddb6SLionel Sambucclass messages_base; 1744684ddb6SLionel Sambuctemplate <class charT> class messages; 1754684ddb6SLionel Sambuctemplate <class charT> class messages_byname; 1764684ddb6SLionel Sambuc 1774684ddb6SLionel Sambuc} // std 1784684ddb6SLionel Sambuc 1794684ddb6SLionel Sambuc*/ 1804684ddb6SLionel Sambuc 1814684ddb6SLionel Sambuc#include <__config> 1824684ddb6SLionel Sambuc#include <__locale> 1834684ddb6SLionel Sambuc#include <algorithm> 1844684ddb6SLionel Sambuc#include <memory> 1854684ddb6SLionel Sambuc#include <ios> 1864684ddb6SLionel Sambuc#include <streambuf> 1874684ddb6SLionel Sambuc#include <iterator> 1884684ddb6SLionel Sambuc#include <limits> 1894684ddb6SLionel Sambuc#ifndef __APPLE__ 1904684ddb6SLionel Sambuc#include <cstdarg> 1914684ddb6SLionel Sambuc#endif 1924684ddb6SLionel Sambuc#include <cstdlib> 1934684ddb6SLionel Sambuc#include <ctime> 1944684ddb6SLionel Sambuc#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) 1954684ddb6SLionel Sambuc#include <support/win32/locale_win32.h> 196*0a6a1f1dSLionel Sambuc#elif defined(_NEWLIB_VERSION) 197*0a6a1f1dSLionel Sambuc// FIXME: replace all the uses of _NEWLIB_VERSION with __NEWLIB__ preceded by an 198*0a6a1f1dSLionel Sambuc// include of <sys/cdefs.h> once https://sourceware.org/ml/newlib-cvs/2014-q3/msg00038.html 199*0a6a1f1dSLionel Sambuc// has had a chance to bake for a bit 200*0a6a1f1dSLionel Sambuc#include <support/newlib/xlocale.h> 201*0a6a1f1dSLionel Sambuc#endif 202*0a6a1f1dSLionel Sambuc#ifdef _LIBCPP_HAS_CATOPEN 2034684ddb6SLionel Sambuc#include <nl_types.h> 204*0a6a1f1dSLionel Sambuc#endif 2054684ddb6SLionel Sambuc 2064684ddb6SLionel Sambuc#ifdef __APPLE__ 2074684ddb6SLionel Sambuc#include <Availability.h> 2084684ddb6SLionel Sambuc#endif 2094684ddb6SLionel Sambuc 2104684ddb6SLionel Sambuc#include <__undef_min_max> 2114684ddb6SLionel Sambuc 2124684ddb6SLionel Sambuc#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 2134684ddb6SLionel Sambuc#pragma GCC system_header 2144684ddb6SLionel Sambuc#endif 2154684ddb6SLionel Sambuc 2164684ddb6SLionel Sambuc_LIBCPP_BEGIN_NAMESPACE_STD 2174684ddb6SLionel Sambuc 2184684ddb6SLionel Sambuc#if defined(__APPLE__) || defined(__FreeBSD__) 2194684ddb6SLionel Sambuc# define _LIBCPP_GET_C_LOCALE 0 220*0a6a1f1dSLionel Sambuc#elif defined(__CloudABI__) || defined(__NetBSD__) || defined(__minix) 2214684ddb6SLionel Sambuc# define _LIBCPP_GET_C_LOCALE LC_C_LOCALE 2224684ddb6SLionel Sambuc#else 2234684ddb6SLionel Sambuc# define _LIBCPP_GET_C_LOCALE __cloc() 2244684ddb6SLionel Sambuc // Get the C locale object 2254684ddb6SLionel Sambuc _LIBCPP_FUNC_VIS locale_t __cloc(); 2264684ddb6SLionel Sambuc#define __cloc_defined 2274684ddb6SLionel Sambuc#endif 2284684ddb6SLionel Sambuc 2294684ddb6SLionel Sambuctypedef _VSTD::remove_pointer<locale_t>::type __locale_struct; 2304684ddb6SLionel Sambuctypedef _VSTD::unique_ptr<__locale_struct, decltype(&freelocale)> __locale_unique_ptr; 2314684ddb6SLionel Sambuc#ifndef _LIBCPP_LOCALE__L_EXTENSIONS 2324684ddb6SLionel Sambuctypedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii; 2334684ddb6SLionel Sambuc#endif 2344684ddb6SLionel Sambuc 2354684ddb6SLionel Sambuc// OSX has nice foo_l() functions that let you turn off use of the global 2364684ddb6SLionel Sambuc// locale. Linux, not so much. The following functions avoid the locale when 2374684ddb6SLionel Sambuc// that's possible and otherwise do the wrong thing. FIXME. 238*0a6a1f1dSLionel Sambuc#if defined(__linux__) || defined(__EMSCRIPTEN__) || defined(_AIX) || \ 239*0a6a1f1dSLionel Sambuc defined(_NEWLIB_VERSION) || defined(__GLIBC__) 2404684ddb6SLionel Sambuc 2414684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 2424684ddb6SLionel Sambucdecltype(MB_CUR_MAX_L(_VSTD::declval<locale_t>())) 2434684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 2444684ddb6SLionel Sambuc__mb_cur_max_l(locale_t __l) 2454684ddb6SLionel Sambuc{ 2464684ddb6SLionel Sambuc return MB_CUR_MAX_L(__l); 2474684ddb6SLionel Sambuc} 2484684ddb6SLionel Sambuc#else // _LIBCPP_LOCALE__L_EXTENSIONS 2494684ddb6SLionel Sambucinline _LIBCPP_ALWAYS_INLINE 2504684ddb6SLionel Sambucdecltype(MB_CUR_MAX) __mb_cur_max_l(locale_t __l) 2514684ddb6SLionel Sambuc{ 2524684ddb6SLionel Sambuc __locale_raii __current(uselocale(__l), uselocale); 2534684ddb6SLionel Sambuc return MB_CUR_MAX; 2544684ddb6SLionel Sambuc} 2554684ddb6SLionel Sambuc#endif // _LIBCPP_LOCALE__L_EXTENSIONS 2564684ddb6SLionel Sambuc 2574684ddb6SLionel Sambucinline _LIBCPP_ALWAYS_INLINE 2584684ddb6SLionel Sambucwint_t __btowc_l(int __c, locale_t __l) 2594684ddb6SLionel Sambuc{ 2604684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 2614684ddb6SLionel Sambuc return btowc_l(__c, __l); 2624684ddb6SLionel Sambuc#else 2634684ddb6SLionel Sambuc __locale_raii __current(uselocale(__l), uselocale); 2644684ddb6SLionel Sambuc return btowc(__c); 2654684ddb6SLionel Sambuc#endif 2664684ddb6SLionel Sambuc} 2674684ddb6SLionel Sambuc 2684684ddb6SLionel Sambucinline _LIBCPP_ALWAYS_INLINE 2694684ddb6SLionel Sambucint __wctob_l(wint_t __c, locale_t __l) 2704684ddb6SLionel Sambuc{ 2714684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 2724684ddb6SLionel Sambuc return wctob_l(__c, __l); 2734684ddb6SLionel Sambuc#else 2744684ddb6SLionel Sambuc __locale_raii __current(uselocale(__l), uselocale); 2754684ddb6SLionel Sambuc return wctob(__c); 2764684ddb6SLionel Sambuc#endif 2774684ddb6SLionel Sambuc} 2784684ddb6SLionel Sambuc 2794684ddb6SLionel Sambucinline _LIBCPP_ALWAYS_INLINE 2804684ddb6SLionel Sambucsize_t __wcsnrtombs_l(char *__dest, const wchar_t **__src, size_t __nwc, 2814684ddb6SLionel Sambuc size_t __len, mbstate_t *__ps, locale_t __l) 2824684ddb6SLionel Sambuc{ 2834684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 2844684ddb6SLionel Sambuc return wcsnrtombs_l(__dest, __src, __nwc, __len, __ps, __l); 2854684ddb6SLionel Sambuc#else 2864684ddb6SLionel Sambuc __locale_raii __current(uselocale(__l), uselocale); 2874684ddb6SLionel Sambuc return wcsnrtombs(__dest, __src, __nwc, __len, __ps); 2884684ddb6SLionel Sambuc#endif 2894684ddb6SLionel Sambuc} 2904684ddb6SLionel Sambuc 2914684ddb6SLionel Sambucinline _LIBCPP_ALWAYS_INLINE 2924684ddb6SLionel Sambucsize_t __wcrtomb_l(char *__s, wchar_t __wc, mbstate_t *__ps, locale_t __l) 2934684ddb6SLionel Sambuc{ 2944684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 2954684ddb6SLionel Sambuc return wcrtomb_l(__s, __wc, __ps, __l); 2964684ddb6SLionel Sambuc#else 2974684ddb6SLionel Sambuc __locale_raii __current(uselocale(__l), uselocale); 2984684ddb6SLionel Sambuc return wcrtomb(__s, __wc, __ps); 2994684ddb6SLionel Sambuc#endif 3004684ddb6SLionel Sambuc} 3014684ddb6SLionel Sambuc 3024684ddb6SLionel Sambucinline _LIBCPP_ALWAYS_INLINE 3034684ddb6SLionel Sambucsize_t __mbsnrtowcs_l(wchar_t * __dest, const char **__src, size_t __nms, 3044684ddb6SLionel Sambuc size_t __len, mbstate_t *__ps, locale_t __l) 3054684ddb6SLionel Sambuc{ 3064684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 3074684ddb6SLionel Sambuc return mbsnrtowcs_l(__dest, __src, __nms, __len, __ps, __l); 3084684ddb6SLionel Sambuc#else 3094684ddb6SLionel Sambuc __locale_raii __current(uselocale(__l), uselocale); 3104684ddb6SLionel Sambuc return mbsnrtowcs(__dest, __src, __nms, __len, __ps); 3114684ddb6SLionel Sambuc#endif 3124684ddb6SLionel Sambuc} 3134684ddb6SLionel Sambuc 3144684ddb6SLionel Sambucinline _LIBCPP_ALWAYS_INLINE 3154684ddb6SLionel Sambucsize_t __mbrtowc_l(wchar_t *__pwc, const char *__s, size_t __n, 3164684ddb6SLionel Sambuc mbstate_t *__ps, locale_t __l) 3174684ddb6SLionel Sambuc{ 3184684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 3194684ddb6SLionel Sambuc return mbrtowc_l(__pwc, __s, __n, __ps, __l); 3204684ddb6SLionel Sambuc#else 3214684ddb6SLionel Sambuc __locale_raii __current(uselocale(__l), uselocale); 3224684ddb6SLionel Sambuc return mbrtowc(__pwc, __s, __n, __ps); 3234684ddb6SLionel Sambuc#endif 3244684ddb6SLionel Sambuc} 3254684ddb6SLionel Sambuc 3264684ddb6SLionel Sambucinline _LIBCPP_ALWAYS_INLINE 3274684ddb6SLionel Sambucint __mbtowc_l(wchar_t *__pwc, const char *__pmb, size_t __max, locale_t __l) 3284684ddb6SLionel Sambuc{ 3294684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 3304684ddb6SLionel Sambuc return mbtowc_l(__pwc, __pmb, __max, __l); 3314684ddb6SLionel Sambuc#else 3324684ddb6SLionel Sambuc __locale_raii __current(uselocale(__l), uselocale); 3334684ddb6SLionel Sambuc return mbtowc(__pwc, __pmb, __max); 3344684ddb6SLionel Sambuc#endif 3354684ddb6SLionel Sambuc} 3364684ddb6SLionel Sambuc 3374684ddb6SLionel Sambucinline _LIBCPP_ALWAYS_INLINE 3384684ddb6SLionel Sambucsize_t __mbrlen_l(const char *__s, size_t __n, mbstate_t *__ps, locale_t __l) 3394684ddb6SLionel Sambuc{ 3404684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 3414684ddb6SLionel Sambuc return mbrlen_l(__s, __n, __ps, __l); 3424684ddb6SLionel Sambuc#else 3434684ddb6SLionel Sambuc __locale_raii __current(uselocale(__l), uselocale); 3444684ddb6SLionel Sambuc return mbrlen(__s, __n, __ps); 3454684ddb6SLionel Sambuc#endif 3464684ddb6SLionel Sambuc} 3474684ddb6SLionel Sambuc 3484684ddb6SLionel Sambucinline _LIBCPP_ALWAYS_INLINE 3494684ddb6SLionel Sambuclconv *__localeconv_l(locale_t __l) 3504684ddb6SLionel Sambuc{ 3514684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 3524684ddb6SLionel Sambuc return localeconv_l(__l); 3534684ddb6SLionel Sambuc#else 3544684ddb6SLionel Sambuc __locale_raii __current(uselocale(__l), uselocale); 3554684ddb6SLionel Sambuc return localeconv(); 3564684ddb6SLionel Sambuc#endif 3574684ddb6SLionel Sambuc} 3584684ddb6SLionel Sambuc 3594684ddb6SLionel Sambucinline _LIBCPP_ALWAYS_INLINE 3604684ddb6SLionel Sambucsize_t __mbsrtowcs_l(wchar_t *__dest, const char **__src, size_t __len, 3614684ddb6SLionel Sambuc mbstate_t *__ps, locale_t __l) 3624684ddb6SLionel Sambuc{ 3634684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 3644684ddb6SLionel Sambuc return mbsrtowcs_l(__dest, __src, __len, __ps, __l); 3654684ddb6SLionel Sambuc#else 3664684ddb6SLionel Sambuc __locale_raii __current(uselocale(__l), uselocale); 3674684ddb6SLionel Sambuc return mbsrtowcs(__dest, __src, __len, __ps); 3684684ddb6SLionel Sambuc#endif 3694684ddb6SLionel Sambuc} 3704684ddb6SLionel Sambuc 3714684ddb6SLionel Sambucinline 3724684ddb6SLionel Sambucint __snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...) { 3734684ddb6SLionel Sambuc va_list __va; 3744684ddb6SLionel Sambuc va_start(__va, __format); 3754684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 3764684ddb6SLionel Sambuc int __res = vsnprintf_l(__s, __n, __l, __format, __va); 3774684ddb6SLionel Sambuc#else 3784684ddb6SLionel Sambuc __locale_raii __current(uselocale(__l), uselocale); 3794684ddb6SLionel Sambuc int __res = vsnprintf(__s, __n, __format, __va); 3804684ddb6SLionel Sambuc#endif 3814684ddb6SLionel Sambuc va_end(__va); 3824684ddb6SLionel Sambuc return __res; 3834684ddb6SLionel Sambuc} 3844684ddb6SLionel Sambuc 3854684ddb6SLionel Sambucinline 3864684ddb6SLionel Sambucint __asprintf_l(char **__s, locale_t __l, const char *__format, ...) { 3874684ddb6SLionel Sambuc va_list __va; 3884684ddb6SLionel Sambuc va_start(__va, __format); 3894684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 3904684ddb6SLionel Sambuc int __res = vasprintf_l(__s, __l, __format, __va); 3914684ddb6SLionel Sambuc#else 3924684ddb6SLionel Sambuc __locale_raii __current(uselocale(__l), uselocale); 3934684ddb6SLionel Sambuc int __res = vasprintf(__s, __format, __va); 3944684ddb6SLionel Sambuc#endif 3954684ddb6SLionel Sambuc va_end(__va); 3964684ddb6SLionel Sambuc return __res; 3974684ddb6SLionel Sambuc} 3984684ddb6SLionel Sambuc 3994684ddb6SLionel Sambucinline 4004684ddb6SLionel Sambucint __sscanf_l(const char *__s, locale_t __l, const char *__format, ...) { 4014684ddb6SLionel Sambuc va_list __va; 4024684ddb6SLionel Sambuc va_start(__va, __format); 4034684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 4044684ddb6SLionel Sambuc int __res = vsscanf_l(__s, __l, __format, __va); 4054684ddb6SLionel Sambuc#else 4064684ddb6SLionel Sambuc __locale_raii __current(uselocale(__l), uselocale); 4074684ddb6SLionel Sambuc int __res = vsscanf(__s, __format, __va); 4084684ddb6SLionel Sambuc#endif 4094684ddb6SLionel Sambuc va_end(__va); 4104684ddb6SLionel Sambuc return __res; 4114684ddb6SLionel Sambuc} 4124684ddb6SLionel Sambuc 4134684ddb6SLionel Sambuc#endif // __linux__ 4144684ddb6SLionel Sambuc 4154684ddb6SLionel Sambuc// __scan_keyword 4164684ddb6SLionel Sambuc// Scans [__b, __e) until a match is found in the basic_strings range 4174684ddb6SLionel Sambuc// [__kb, __ke) or until it can be shown that there is no match in [__kb, __ke). 4184684ddb6SLionel Sambuc// __b will be incremented (visibly), consuming CharT until a match is found 4194684ddb6SLionel Sambuc// or proved to not exist. A keyword may be "", in which will match anything. 4204684ddb6SLionel Sambuc// If one keyword is a prefix of another, and the next CharT in the input 4214684ddb6SLionel Sambuc// might match another keyword, the algorithm will attempt to find the longest 4224684ddb6SLionel Sambuc// matching keyword. If the longer matching keyword ends up not matching, then 4234684ddb6SLionel Sambuc// no keyword match is found. If no keyword match is found, __ke is returned 4244684ddb6SLionel Sambuc// and failbit is set in __err. 4254684ddb6SLionel Sambuc// Else an iterator pointing to the matching keyword is found. If more than 4264684ddb6SLionel Sambuc// one keyword matches, an iterator to the first matching keyword is returned. 427*0a6a1f1dSLionel Sambuc// If on exit __b == __e, eofbit is set in __err. If __case_sensitive is false, 4284684ddb6SLionel Sambuc// __ct is used to force to lower case before comparing characters. 4294684ddb6SLionel Sambuc// Examples: 4304684ddb6SLionel Sambuc// Keywords: "a", "abb" 4314684ddb6SLionel Sambuc// If the input is "a", the first keyword matches and eofbit is set. 4324684ddb6SLionel Sambuc// If the input is "abc", no match is found and "ab" are consumed. 4334684ddb6SLionel Sambuctemplate <class _InputIterator, class _ForwardIterator, class _Ctype> 4344684ddb6SLionel Sambuc_LIBCPP_HIDDEN 4354684ddb6SLionel Sambuc_ForwardIterator 4364684ddb6SLionel Sambuc__scan_keyword(_InputIterator& __b, _InputIterator __e, 4374684ddb6SLionel Sambuc _ForwardIterator __kb, _ForwardIterator __ke, 4384684ddb6SLionel Sambuc const _Ctype& __ct, ios_base::iostate& __err, 4394684ddb6SLionel Sambuc bool __case_sensitive = true) 4404684ddb6SLionel Sambuc{ 4414684ddb6SLionel Sambuc typedef typename iterator_traits<_InputIterator>::value_type _CharT; 4424684ddb6SLionel Sambuc size_t __nkw = static_cast<size_t>(_VSTD::distance(__kb, __ke)); 4434684ddb6SLionel Sambuc const unsigned char __doesnt_match = '\0'; 4444684ddb6SLionel Sambuc const unsigned char __might_match = '\1'; 4454684ddb6SLionel Sambuc const unsigned char __does_match = '\2'; 4464684ddb6SLionel Sambuc unsigned char __statbuf[100]; 4474684ddb6SLionel Sambuc unsigned char* __status = __statbuf; 4484684ddb6SLionel Sambuc unique_ptr<unsigned char, void(*)(void*)> __stat_hold(0, free); 4494684ddb6SLionel Sambuc if (__nkw > sizeof(__statbuf)) 4504684ddb6SLionel Sambuc { 4514684ddb6SLionel Sambuc __status = (unsigned char*)malloc(__nkw); 4524684ddb6SLionel Sambuc if (__status == 0) 4534684ddb6SLionel Sambuc __throw_bad_alloc(); 4544684ddb6SLionel Sambuc __stat_hold.reset(__status); 4554684ddb6SLionel Sambuc } 4564684ddb6SLionel Sambuc size_t __n_might_match = __nkw; // At this point, any keyword might match 4574684ddb6SLionel Sambuc size_t __n_does_match = 0; // but none of them definitely do 4584684ddb6SLionel Sambuc // Initialize all statuses to __might_match, except for "" keywords are __does_match 4594684ddb6SLionel Sambuc unsigned char* __st = __status; 460*0a6a1f1dSLionel Sambuc for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void) ++__st) 4614684ddb6SLionel Sambuc { 4624684ddb6SLionel Sambuc if (!__ky->empty()) 4634684ddb6SLionel Sambuc *__st = __might_match; 4644684ddb6SLionel Sambuc else 4654684ddb6SLionel Sambuc { 4664684ddb6SLionel Sambuc *__st = __does_match; 4674684ddb6SLionel Sambuc --__n_might_match; 4684684ddb6SLionel Sambuc ++__n_does_match; 4694684ddb6SLionel Sambuc } 4704684ddb6SLionel Sambuc } 4714684ddb6SLionel Sambuc // While there might be a match, test keywords against the next CharT 4724684ddb6SLionel Sambuc for (size_t __indx = 0; __b != __e && __n_might_match > 0; ++__indx) 4734684ddb6SLionel Sambuc { 4744684ddb6SLionel Sambuc // Peek at the next CharT but don't consume it 4754684ddb6SLionel Sambuc _CharT __c = *__b; 4764684ddb6SLionel Sambuc if (!__case_sensitive) 4774684ddb6SLionel Sambuc __c = __ct.toupper(__c); 4784684ddb6SLionel Sambuc bool __consume = false; 4794684ddb6SLionel Sambuc // For each keyword which might match, see if the __indx character is __c 4804684ddb6SLionel Sambuc // If a match if found, consume __c 4814684ddb6SLionel Sambuc // If a match is found, and that is the last character in the keyword, 4824684ddb6SLionel Sambuc // then that keyword matches. 4834684ddb6SLionel Sambuc // If the keyword doesn't match this character, then change the keyword 4844684ddb6SLionel Sambuc // to doesn't match 4854684ddb6SLionel Sambuc __st = __status; 486*0a6a1f1dSLionel Sambuc for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void) ++__st) 4874684ddb6SLionel Sambuc { 4884684ddb6SLionel Sambuc if (*__st == __might_match) 4894684ddb6SLionel Sambuc { 4904684ddb6SLionel Sambuc _CharT __kc = (*__ky)[__indx]; 4914684ddb6SLionel Sambuc if (!__case_sensitive) 4924684ddb6SLionel Sambuc __kc = __ct.toupper(__kc); 4934684ddb6SLionel Sambuc if (__c == __kc) 4944684ddb6SLionel Sambuc { 4954684ddb6SLionel Sambuc __consume = true; 4964684ddb6SLionel Sambuc if (__ky->size() == __indx+1) 4974684ddb6SLionel Sambuc { 4984684ddb6SLionel Sambuc *__st = __does_match; 4994684ddb6SLionel Sambuc --__n_might_match; 5004684ddb6SLionel Sambuc ++__n_does_match; 5014684ddb6SLionel Sambuc } 5024684ddb6SLionel Sambuc } 5034684ddb6SLionel Sambuc else 5044684ddb6SLionel Sambuc { 5054684ddb6SLionel Sambuc *__st = __doesnt_match; 5064684ddb6SLionel Sambuc --__n_might_match; 5074684ddb6SLionel Sambuc } 5084684ddb6SLionel Sambuc } 5094684ddb6SLionel Sambuc } 5104684ddb6SLionel Sambuc // consume if we matched a character 5114684ddb6SLionel Sambuc if (__consume) 5124684ddb6SLionel Sambuc { 5134684ddb6SLionel Sambuc ++__b; 5144684ddb6SLionel Sambuc // If we consumed a character and there might be a matched keyword that 5154684ddb6SLionel Sambuc // was marked matched on a previous iteration, then such keywords 5164684ddb6SLionel Sambuc // which are now marked as not matching. 5174684ddb6SLionel Sambuc if (__n_might_match + __n_does_match > 1) 5184684ddb6SLionel Sambuc { 5194684ddb6SLionel Sambuc __st = __status; 520*0a6a1f1dSLionel Sambuc for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void) ++__st) 5214684ddb6SLionel Sambuc { 5224684ddb6SLionel Sambuc if (*__st == __does_match && __ky->size() != __indx+1) 5234684ddb6SLionel Sambuc { 5244684ddb6SLionel Sambuc *__st = __doesnt_match; 5254684ddb6SLionel Sambuc --__n_does_match; 5264684ddb6SLionel Sambuc } 5274684ddb6SLionel Sambuc } 5284684ddb6SLionel Sambuc } 5294684ddb6SLionel Sambuc } 5304684ddb6SLionel Sambuc } 5314684ddb6SLionel Sambuc // We've exited the loop because we hit eof and/or we have no more "might matches". 5324684ddb6SLionel Sambuc if (__b == __e) 5334684ddb6SLionel Sambuc __err |= ios_base::eofbit; 5344684ddb6SLionel Sambuc // Return the first matching result 535*0a6a1f1dSLionel Sambuc for (__st = __status; __kb != __ke; ++__kb, (void) ++__st) 5364684ddb6SLionel Sambuc if (*__st == __does_match) 5374684ddb6SLionel Sambuc break; 5384684ddb6SLionel Sambuc if (__kb == __ke) 5394684ddb6SLionel Sambuc __err |= ios_base::failbit; 5404684ddb6SLionel Sambuc return __kb; 5414684ddb6SLionel Sambuc} 5424684ddb6SLionel Sambuc 5434684ddb6SLionel Sambucstruct _LIBCPP_TYPE_VIS __num_get_base 5444684ddb6SLionel Sambuc{ 5454684ddb6SLionel Sambuc static const int __num_get_buf_sz = 40; 5464684ddb6SLionel Sambuc 5474684ddb6SLionel Sambuc static int __get_base(ios_base&); 5484684ddb6SLionel Sambuc static const char __src[33]; 5494684ddb6SLionel Sambuc}; 5504684ddb6SLionel Sambuc 5514684ddb6SLionel Sambuc_LIBCPP_FUNC_VIS 5524684ddb6SLionel Sambucvoid __check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end, 5534684ddb6SLionel Sambuc ios_base::iostate& __err); 5544684ddb6SLionel Sambuc 5554684ddb6SLionel Sambuctemplate <class _CharT> 5564684ddb6SLionel Sambucstruct __num_get 5574684ddb6SLionel Sambuc : protected __num_get_base 5584684ddb6SLionel Sambuc{ 5594684ddb6SLionel Sambuc static string __stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep); 5604684ddb6SLionel Sambuc static string __stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point, 5614684ddb6SLionel Sambuc _CharT& __thousands_sep); 5624684ddb6SLionel Sambuc static int __stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end, 5634684ddb6SLionel Sambuc unsigned& __dc, _CharT __thousands_sep, const string& __grouping, 5644684ddb6SLionel Sambuc unsigned* __g, unsigned*& __g_end, _CharT* __atoms); 5654684ddb6SLionel Sambuc static int __stage2_float_loop(_CharT __ct, bool& __in_units, char& __exp, 5664684ddb6SLionel Sambuc char* __a, char*& __a_end, 5674684ddb6SLionel Sambuc _CharT __decimal_point, _CharT __thousands_sep, 5684684ddb6SLionel Sambuc const string& __grouping, unsigned* __g, 5694684ddb6SLionel Sambuc unsigned*& __g_end, unsigned& __dc, _CharT* __atoms); 5704684ddb6SLionel Sambuc}; 5714684ddb6SLionel Sambuc 5724684ddb6SLionel Sambuctemplate <class _CharT> 5734684ddb6SLionel Sambucstring 5744684ddb6SLionel Sambuc__num_get<_CharT>::__stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep) 5754684ddb6SLionel Sambuc{ 5764684ddb6SLionel Sambuc locale __loc = __iob.getloc(); 5774684ddb6SLionel Sambuc use_facet<ctype<_CharT> >(__loc).widen(__src, __src + 26, __atoms); 5784684ddb6SLionel Sambuc const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc); 5794684ddb6SLionel Sambuc __thousands_sep = __np.thousands_sep(); 5804684ddb6SLionel Sambuc return __np.grouping(); 5814684ddb6SLionel Sambuc} 5824684ddb6SLionel Sambuc 5834684ddb6SLionel Sambuctemplate <class _CharT> 5844684ddb6SLionel Sambucstring 5854684ddb6SLionel Sambuc__num_get<_CharT>::__stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point, 5864684ddb6SLionel Sambuc _CharT& __thousands_sep) 5874684ddb6SLionel Sambuc{ 5884684ddb6SLionel Sambuc locale __loc = __iob.getloc(); 5894684ddb6SLionel Sambuc use_facet<ctype<_CharT> >(__loc).widen(__src, __src + 32, __atoms); 5904684ddb6SLionel Sambuc const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc); 5914684ddb6SLionel Sambuc __decimal_point = __np.decimal_point(); 5924684ddb6SLionel Sambuc __thousands_sep = __np.thousands_sep(); 5934684ddb6SLionel Sambuc return __np.grouping(); 5944684ddb6SLionel Sambuc} 5954684ddb6SLionel Sambuc 5964684ddb6SLionel Sambuctemplate <class _CharT> 5974684ddb6SLionel Sambucint 5984684ddb6SLionel Sambuc__num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end, 5994684ddb6SLionel Sambuc unsigned& __dc, _CharT __thousands_sep, const string& __grouping, 6004684ddb6SLionel Sambuc unsigned* __g, unsigned*& __g_end, _CharT* __atoms) 6014684ddb6SLionel Sambuc{ 6024684ddb6SLionel Sambuc if (__a_end == __a && (__ct == __atoms[24] || __ct == __atoms[25])) 6034684ddb6SLionel Sambuc { 6044684ddb6SLionel Sambuc *__a_end++ = __ct == __atoms[24] ? '+' : '-'; 6054684ddb6SLionel Sambuc __dc = 0; 6064684ddb6SLionel Sambuc return 0; 6074684ddb6SLionel Sambuc } 6084684ddb6SLionel Sambuc if (__grouping.size() != 0 && __ct == __thousands_sep) 6094684ddb6SLionel Sambuc { 6104684ddb6SLionel Sambuc if (__g_end-__g < __num_get_buf_sz) 6114684ddb6SLionel Sambuc { 6124684ddb6SLionel Sambuc *__g_end++ = __dc; 6134684ddb6SLionel Sambuc __dc = 0; 6144684ddb6SLionel Sambuc } 6154684ddb6SLionel Sambuc return 0; 6164684ddb6SLionel Sambuc } 6174684ddb6SLionel Sambuc ptrdiff_t __f = find(__atoms, __atoms + 26, __ct) - __atoms; 6184684ddb6SLionel Sambuc if (__f >= 24) 6194684ddb6SLionel Sambuc return -1; 6204684ddb6SLionel Sambuc switch (__base) 6214684ddb6SLionel Sambuc { 6224684ddb6SLionel Sambuc case 8: 6234684ddb6SLionel Sambuc case 10: 6244684ddb6SLionel Sambuc if (__f >= __base) 6254684ddb6SLionel Sambuc return -1; 6264684ddb6SLionel Sambuc break; 6274684ddb6SLionel Sambuc case 16: 6284684ddb6SLionel Sambuc if (__f < 22) 6294684ddb6SLionel Sambuc break; 6304684ddb6SLionel Sambuc if (__a_end != __a && __a_end - __a <= 2 && __a_end[-1] == '0') 6314684ddb6SLionel Sambuc { 6324684ddb6SLionel Sambuc __dc = 0; 6334684ddb6SLionel Sambuc *__a_end++ = __src[__f]; 6344684ddb6SLionel Sambuc return 0; 6354684ddb6SLionel Sambuc } 6364684ddb6SLionel Sambuc return -1; 6374684ddb6SLionel Sambuc } 6384684ddb6SLionel Sambuc *__a_end++ = __src[__f]; 6394684ddb6SLionel Sambuc ++__dc; 6404684ddb6SLionel Sambuc return 0; 6414684ddb6SLionel Sambuc} 6424684ddb6SLionel Sambuc 6434684ddb6SLionel Sambuctemplate <class _CharT> 6444684ddb6SLionel Sambucint 6454684ddb6SLionel Sambuc__num_get<_CharT>::__stage2_float_loop(_CharT __ct, bool& __in_units, char& __exp, char* __a, char*& __a_end, 6464684ddb6SLionel Sambuc _CharT __decimal_point, _CharT __thousands_sep, const string& __grouping, 6474684ddb6SLionel Sambuc unsigned* __g, unsigned*& __g_end, unsigned& __dc, _CharT* __atoms) 6484684ddb6SLionel Sambuc{ 6494684ddb6SLionel Sambuc if (__ct == __decimal_point) 6504684ddb6SLionel Sambuc { 6514684ddb6SLionel Sambuc if (!__in_units) 6524684ddb6SLionel Sambuc return -1; 6534684ddb6SLionel Sambuc __in_units = false; 6544684ddb6SLionel Sambuc *__a_end++ = '.'; 6554684ddb6SLionel Sambuc if (__grouping.size() != 0 && __g_end-__g < __num_get_buf_sz) 6564684ddb6SLionel Sambuc *__g_end++ = __dc; 6574684ddb6SLionel Sambuc return 0; 6584684ddb6SLionel Sambuc } 6594684ddb6SLionel Sambuc if (__ct == __thousands_sep && __grouping.size() != 0) 6604684ddb6SLionel Sambuc { 6614684ddb6SLionel Sambuc if (!__in_units) 6624684ddb6SLionel Sambuc return -1; 6634684ddb6SLionel Sambuc if (__g_end-__g < __num_get_buf_sz) 6644684ddb6SLionel Sambuc { 6654684ddb6SLionel Sambuc *__g_end++ = __dc; 6664684ddb6SLionel Sambuc __dc = 0; 6674684ddb6SLionel Sambuc } 6684684ddb6SLionel Sambuc return 0; 6694684ddb6SLionel Sambuc } 6704684ddb6SLionel Sambuc ptrdiff_t __f = find(__atoms, __atoms + 32, __ct) - __atoms; 6714684ddb6SLionel Sambuc if (__f >= 32) 6724684ddb6SLionel Sambuc return -1; 6734684ddb6SLionel Sambuc char __x = __src[__f]; 6744684ddb6SLionel Sambuc if (__x == '-' || __x == '+') 6754684ddb6SLionel Sambuc { 6764684ddb6SLionel Sambuc if (__a_end == __a || (__a_end[-1] & 0x5F) == (__exp & 0x7F)) 6774684ddb6SLionel Sambuc { 6784684ddb6SLionel Sambuc *__a_end++ = __x; 6794684ddb6SLionel Sambuc return 0; 6804684ddb6SLionel Sambuc } 6814684ddb6SLionel Sambuc return -1; 6824684ddb6SLionel Sambuc } 6834684ddb6SLionel Sambuc if (__x == 'x' || __x == 'X') 6844684ddb6SLionel Sambuc __exp = 'P'; 6854684ddb6SLionel Sambuc else if ((__x & 0x5F) == __exp) 6864684ddb6SLionel Sambuc { 6874684ddb6SLionel Sambuc __exp |= 0x80; 6884684ddb6SLionel Sambuc if (__in_units) 6894684ddb6SLionel Sambuc { 6904684ddb6SLionel Sambuc __in_units = false; 6914684ddb6SLionel Sambuc if (__grouping.size() != 0 && __g_end-__g < __num_get_buf_sz) 6924684ddb6SLionel Sambuc *__g_end++ = __dc; 6934684ddb6SLionel Sambuc } 6944684ddb6SLionel Sambuc } 6954684ddb6SLionel Sambuc *__a_end++ = __x; 6964684ddb6SLionel Sambuc if (__f >= 22) 6974684ddb6SLionel Sambuc return 0; 6984684ddb6SLionel Sambuc ++__dc; 6994684ddb6SLionel Sambuc return 0; 7004684ddb6SLionel Sambuc} 7014684ddb6SLionel Sambuc 7024684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_TYPE_VIS __num_get<char>) 7034684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_TYPE_VIS __num_get<wchar_t>) 7044684ddb6SLionel Sambuc 7054684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> > 7064684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY num_get 7074684ddb6SLionel Sambuc : public locale::facet, 7084684ddb6SLionel Sambuc private __num_get<_CharT> 7094684ddb6SLionel Sambuc{ 7104684ddb6SLionel Sambucpublic: 7114684ddb6SLionel Sambuc typedef _CharT char_type; 7124684ddb6SLionel Sambuc typedef _InputIterator iter_type; 7134684ddb6SLionel Sambuc 7144684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 7154684ddb6SLionel Sambuc explicit num_get(size_t __refs = 0) 7164684ddb6SLionel Sambuc : locale::facet(__refs) {} 7174684ddb6SLionel Sambuc 7184684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 7194684ddb6SLionel Sambuc iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 7204684ddb6SLionel Sambuc ios_base::iostate& __err, bool& __v) const 7214684ddb6SLionel Sambuc { 7224684ddb6SLionel Sambuc return do_get(__b, __e, __iob, __err, __v); 7234684ddb6SLionel Sambuc } 7244684ddb6SLionel Sambuc 7254684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 7264684ddb6SLionel Sambuc iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 7274684ddb6SLionel Sambuc ios_base::iostate& __err, long& __v) const 7284684ddb6SLionel Sambuc { 7294684ddb6SLionel Sambuc return do_get(__b, __e, __iob, __err, __v); 7304684ddb6SLionel Sambuc } 7314684ddb6SLionel Sambuc 7324684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 7334684ddb6SLionel Sambuc iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 7344684ddb6SLionel Sambuc ios_base::iostate& __err, long long& __v) const 7354684ddb6SLionel Sambuc { 7364684ddb6SLionel Sambuc return do_get(__b, __e, __iob, __err, __v); 7374684ddb6SLionel Sambuc } 7384684ddb6SLionel Sambuc 7394684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 7404684ddb6SLionel Sambuc iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 7414684ddb6SLionel Sambuc ios_base::iostate& __err, unsigned short& __v) const 7424684ddb6SLionel Sambuc { 7434684ddb6SLionel Sambuc return do_get(__b, __e, __iob, __err, __v); 7444684ddb6SLionel Sambuc } 7454684ddb6SLionel Sambuc 7464684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 7474684ddb6SLionel Sambuc iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 7484684ddb6SLionel Sambuc ios_base::iostate& __err, unsigned int& __v) const 7494684ddb6SLionel Sambuc { 7504684ddb6SLionel Sambuc return do_get(__b, __e, __iob, __err, __v); 7514684ddb6SLionel Sambuc } 7524684ddb6SLionel Sambuc 7534684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 7544684ddb6SLionel Sambuc iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 7554684ddb6SLionel Sambuc ios_base::iostate& __err, unsigned long& __v) const 7564684ddb6SLionel Sambuc { 7574684ddb6SLionel Sambuc return do_get(__b, __e, __iob, __err, __v); 7584684ddb6SLionel Sambuc } 7594684ddb6SLionel Sambuc 7604684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 7614684ddb6SLionel Sambuc iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 7624684ddb6SLionel Sambuc ios_base::iostate& __err, unsigned long long& __v) const 7634684ddb6SLionel Sambuc { 7644684ddb6SLionel Sambuc return do_get(__b, __e, __iob, __err, __v); 7654684ddb6SLionel Sambuc } 7664684ddb6SLionel Sambuc 7674684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 7684684ddb6SLionel Sambuc iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 7694684ddb6SLionel Sambuc ios_base::iostate& __err, float& __v) const 7704684ddb6SLionel Sambuc { 7714684ddb6SLionel Sambuc return do_get(__b, __e, __iob, __err, __v); 7724684ddb6SLionel Sambuc } 7734684ddb6SLionel Sambuc 7744684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 7754684ddb6SLionel Sambuc iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 7764684ddb6SLionel Sambuc ios_base::iostate& __err, double& __v) const 7774684ddb6SLionel Sambuc { 7784684ddb6SLionel Sambuc return do_get(__b, __e, __iob, __err, __v); 7794684ddb6SLionel Sambuc } 7804684ddb6SLionel Sambuc 7814684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 7824684ddb6SLionel Sambuc iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 7834684ddb6SLionel Sambuc ios_base::iostate& __err, long double& __v) const 7844684ddb6SLionel Sambuc { 7854684ddb6SLionel Sambuc return do_get(__b, __e, __iob, __err, __v); 7864684ddb6SLionel Sambuc } 7874684ddb6SLionel Sambuc 7884684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 7894684ddb6SLionel Sambuc iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 7904684ddb6SLionel Sambuc ios_base::iostate& __err, void*& __v) const 7914684ddb6SLionel Sambuc { 7924684ddb6SLionel Sambuc return do_get(__b, __e, __iob, __err, __v); 7934684ddb6SLionel Sambuc } 7944684ddb6SLionel Sambuc 7954684ddb6SLionel Sambuc static locale::id id; 7964684ddb6SLionel Sambuc 7974684ddb6SLionel Sambucprotected: 7984684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 7994684ddb6SLionel Sambuc ~num_get() {} 8004684ddb6SLionel Sambuc 8014684ddb6SLionel Sambuc template <class _Fp> 8024684ddb6SLionel Sambuc iter_type __do_get_floating_point 8034684ddb6SLionel Sambuc (iter_type __b, iter_type __e, ios_base& __iob, 8044684ddb6SLionel Sambuc ios_base::iostate& __err, _Fp& __v) const; 8054684ddb6SLionel Sambuc 8064684ddb6SLionel Sambuc template <class _Signed> 8074684ddb6SLionel Sambuc iter_type __do_get_signed 8084684ddb6SLionel Sambuc (iter_type __b, iter_type __e, ios_base& __iob, 8094684ddb6SLionel Sambuc ios_base::iostate& __err, _Signed& __v) const; 8104684ddb6SLionel Sambuc 8114684ddb6SLionel Sambuc template <class _Unsigned> 8124684ddb6SLionel Sambuc iter_type __do_get_unsigned 8134684ddb6SLionel Sambuc (iter_type __b, iter_type __e, ios_base& __iob, 8144684ddb6SLionel Sambuc ios_base::iostate& __err, _Unsigned& __v) const; 8154684ddb6SLionel Sambuc 8164684ddb6SLionel Sambuc 8174684ddb6SLionel Sambuc virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, 8184684ddb6SLionel Sambuc ios_base::iostate& __err, bool& __v) const; 8194684ddb6SLionel Sambuc 8204684ddb6SLionel Sambuc virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, 8214684ddb6SLionel Sambuc ios_base::iostate& __err, long& __v) const 8224684ddb6SLionel Sambuc { return this->__do_get_signed ( __b, __e, __iob, __err, __v ); } 8234684ddb6SLionel Sambuc 8244684ddb6SLionel Sambuc virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, 8254684ddb6SLionel Sambuc ios_base::iostate& __err, long long& __v) const 8264684ddb6SLionel Sambuc { return this->__do_get_signed ( __b, __e, __iob, __err, __v ); } 8274684ddb6SLionel Sambuc 8284684ddb6SLionel Sambuc virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, 8294684ddb6SLionel Sambuc ios_base::iostate& __err, unsigned short& __v) const 8304684ddb6SLionel Sambuc { return this->__do_get_unsigned ( __b, __e, __iob, __err, __v ); } 8314684ddb6SLionel Sambuc 8324684ddb6SLionel Sambuc virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, 8334684ddb6SLionel Sambuc ios_base::iostate& __err, unsigned int& __v) const 8344684ddb6SLionel Sambuc { return this->__do_get_unsigned ( __b, __e, __iob, __err, __v ); } 8354684ddb6SLionel Sambuc 8364684ddb6SLionel Sambuc virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, 8374684ddb6SLionel Sambuc ios_base::iostate& __err, unsigned long& __v) const 8384684ddb6SLionel Sambuc { return this->__do_get_unsigned ( __b, __e, __iob, __err, __v ); } 8394684ddb6SLionel Sambuc 8404684ddb6SLionel Sambuc virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, 8414684ddb6SLionel Sambuc ios_base::iostate& __err, unsigned long long& __v) const 8424684ddb6SLionel Sambuc { return this->__do_get_unsigned ( __b, __e, __iob, __err, __v ); } 8434684ddb6SLionel Sambuc 8444684ddb6SLionel Sambuc virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, 8454684ddb6SLionel Sambuc ios_base::iostate& __err, float& __v) const 8464684ddb6SLionel Sambuc { return this->__do_get_floating_point ( __b, __e, __iob, __err, __v ); } 8474684ddb6SLionel Sambuc 8484684ddb6SLionel Sambuc virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, 8494684ddb6SLionel Sambuc ios_base::iostate& __err, double& __v) const 8504684ddb6SLionel Sambuc { return this->__do_get_floating_point ( __b, __e, __iob, __err, __v ); } 8514684ddb6SLionel Sambuc 8524684ddb6SLionel Sambuc virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, 8534684ddb6SLionel Sambuc ios_base::iostate& __err, long double& __v) const 8544684ddb6SLionel Sambuc { return this->__do_get_floating_point ( __b, __e, __iob, __err, __v ); } 8554684ddb6SLionel Sambuc 8564684ddb6SLionel Sambuc virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, 8574684ddb6SLionel Sambuc ios_base::iostate& __err, void*& __v) const; 8584684ddb6SLionel Sambuc}; 8594684ddb6SLionel Sambuc 8604684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 8614684ddb6SLionel Sambuclocale::id 8624684ddb6SLionel Sambucnum_get<_CharT, _InputIterator>::id; 8634684ddb6SLionel Sambuc 8644684ddb6SLionel Sambuctemplate <class _Tp> 8654684ddb6SLionel Sambuc_Tp 8664684ddb6SLionel Sambuc__num_get_signed_integral(const char* __a, const char* __a_end, 8674684ddb6SLionel Sambuc ios_base::iostate& __err, int __base) 8684684ddb6SLionel Sambuc{ 8694684ddb6SLionel Sambuc if (__a != __a_end) 8704684ddb6SLionel Sambuc { 8714684ddb6SLionel Sambuc typename remove_reference<decltype(errno)>::type __save_errno = errno; 8724684ddb6SLionel Sambuc errno = 0; 8734684ddb6SLionel Sambuc char *__p2; 8744684ddb6SLionel Sambuc long long __ll = strtoll_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE); 8754684ddb6SLionel Sambuc typename remove_reference<decltype(errno)>::type __current_errno = errno; 8764684ddb6SLionel Sambuc if (__current_errno == 0) 8774684ddb6SLionel Sambuc errno = __save_errno; 8784684ddb6SLionel Sambuc if (__p2 != __a_end) 8794684ddb6SLionel Sambuc { 8804684ddb6SLionel Sambuc __err = ios_base::failbit; 8814684ddb6SLionel Sambuc return 0; 8824684ddb6SLionel Sambuc } 8834684ddb6SLionel Sambuc else if (__current_errno == ERANGE || 8844684ddb6SLionel Sambuc __ll < numeric_limits<_Tp>::min() || 8854684ddb6SLionel Sambuc numeric_limits<_Tp>::max() < __ll) 8864684ddb6SLionel Sambuc { 8874684ddb6SLionel Sambuc __err = ios_base::failbit; 8884684ddb6SLionel Sambuc if (__ll > 0) 8894684ddb6SLionel Sambuc return numeric_limits<_Tp>::max(); 8904684ddb6SLionel Sambuc else 8914684ddb6SLionel Sambuc return numeric_limits<_Tp>::min(); 8924684ddb6SLionel Sambuc } 8934684ddb6SLionel Sambuc return static_cast<_Tp>(__ll); 8944684ddb6SLionel Sambuc } 8954684ddb6SLionel Sambuc __err = ios_base::failbit; 8964684ddb6SLionel Sambuc return 0; 8974684ddb6SLionel Sambuc} 8984684ddb6SLionel Sambuc 8994684ddb6SLionel Sambuctemplate <class _Tp> 9004684ddb6SLionel Sambuc_Tp 9014684ddb6SLionel Sambuc__num_get_unsigned_integral(const char* __a, const char* __a_end, 9024684ddb6SLionel Sambuc ios_base::iostate& __err, int __base) 9034684ddb6SLionel Sambuc{ 9044684ddb6SLionel Sambuc if (__a != __a_end) 9054684ddb6SLionel Sambuc { 9064684ddb6SLionel Sambuc if (*__a == '-') 9074684ddb6SLionel Sambuc { 9084684ddb6SLionel Sambuc __err = ios_base::failbit; 9094684ddb6SLionel Sambuc return 0; 9104684ddb6SLionel Sambuc } 9114684ddb6SLionel Sambuc typename remove_reference<decltype(errno)>::type __save_errno = errno; 9124684ddb6SLionel Sambuc errno = 0; 9134684ddb6SLionel Sambuc char *__p2; 9144684ddb6SLionel Sambuc unsigned long long __ll = strtoull_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE); 9154684ddb6SLionel Sambuc typename remove_reference<decltype(errno)>::type __current_errno = errno; 9164684ddb6SLionel Sambuc if (__current_errno == 0) 9174684ddb6SLionel Sambuc errno = __save_errno; 9184684ddb6SLionel Sambuc if (__p2 != __a_end) 9194684ddb6SLionel Sambuc { 9204684ddb6SLionel Sambuc __err = ios_base::failbit; 9214684ddb6SLionel Sambuc return 0; 9224684ddb6SLionel Sambuc } 9234684ddb6SLionel Sambuc else if (__current_errno == ERANGE || 9244684ddb6SLionel Sambuc numeric_limits<_Tp>::max() < __ll) 9254684ddb6SLionel Sambuc { 9264684ddb6SLionel Sambuc __err = ios_base::failbit; 9274684ddb6SLionel Sambuc return numeric_limits<_Tp>::max(); 9284684ddb6SLionel Sambuc } 9294684ddb6SLionel Sambuc return static_cast<_Tp>(__ll); 9304684ddb6SLionel Sambuc } 9314684ddb6SLionel Sambuc __err = ios_base::failbit; 9324684ddb6SLionel Sambuc return 0; 9334684ddb6SLionel Sambuc} 9344684ddb6SLionel Sambuc 9354684ddb6SLionel Sambuctemplate <class _Tp> 9364684ddb6SLionel Sambuc_Tp 9374684ddb6SLionel Sambuc__num_get_float(const char* __a, const char* __a_end, ios_base::iostate& __err) 9384684ddb6SLionel Sambuc{ 9394684ddb6SLionel Sambuc if (__a != __a_end) 9404684ddb6SLionel Sambuc { 9414684ddb6SLionel Sambuc typename remove_reference<decltype(errno)>::type __save_errno = errno; 9424684ddb6SLionel Sambuc errno = 0; 9434684ddb6SLionel Sambuc char *__p2; 9444684ddb6SLionel Sambuc long double __ld = strtold_l(__a, &__p2, _LIBCPP_GET_C_LOCALE); 9454684ddb6SLionel Sambuc typename remove_reference<decltype(errno)>::type __current_errno = errno; 9464684ddb6SLionel Sambuc if (__current_errno == 0) 9474684ddb6SLionel Sambuc errno = __save_errno; 9484684ddb6SLionel Sambuc if (__p2 != __a_end) 9494684ddb6SLionel Sambuc { 9504684ddb6SLionel Sambuc __err = ios_base::failbit; 9514684ddb6SLionel Sambuc return 0; 9524684ddb6SLionel Sambuc } 9534684ddb6SLionel Sambuc else if (__current_errno == ERANGE) 9544684ddb6SLionel Sambuc __err = ios_base::failbit; 9554684ddb6SLionel Sambuc return static_cast<_Tp>(__ld); 9564684ddb6SLionel Sambuc } 9574684ddb6SLionel Sambuc __err = ios_base::failbit; 9584684ddb6SLionel Sambuc return 0; 9594684ddb6SLionel Sambuc} 9604684ddb6SLionel Sambuc 9614684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 9624684ddb6SLionel Sambuc_InputIterator 9634684ddb6SLionel Sambucnum_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, 9644684ddb6SLionel Sambuc ios_base& __iob, 9654684ddb6SLionel Sambuc ios_base::iostate& __err, 9664684ddb6SLionel Sambuc bool& __v) const 9674684ddb6SLionel Sambuc{ 9684684ddb6SLionel Sambuc if ((__iob.flags() & ios_base::boolalpha) == 0) 9694684ddb6SLionel Sambuc { 9704684ddb6SLionel Sambuc long __lv = -1; 9714684ddb6SLionel Sambuc __b = do_get(__b, __e, __iob, __err, __lv); 9724684ddb6SLionel Sambuc switch (__lv) 9734684ddb6SLionel Sambuc { 9744684ddb6SLionel Sambuc case 0: 9754684ddb6SLionel Sambuc __v = false; 9764684ddb6SLionel Sambuc break; 9774684ddb6SLionel Sambuc case 1: 9784684ddb6SLionel Sambuc __v = true; 9794684ddb6SLionel Sambuc break; 9804684ddb6SLionel Sambuc default: 9814684ddb6SLionel Sambuc __v = true; 9824684ddb6SLionel Sambuc __err = ios_base::failbit; 9834684ddb6SLionel Sambuc break; 9844684ddb6SLionel Sambuc } 9854684ddb6SLionel Sambuc return __b; 9864684ddb6SLionel Sambuc } 9874684ddb6SLionel Sambuc const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__iob.getloc()); 9884684ddb6SLionel Sambuc const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__iob.getloc()); 9894684ddb6SLionel Sambuc typedef typename numpunct<_CharT>::string_type string_type; 9904684ddb6SLionel Sambuc const string_type __names[2] = {__np.truename(), __np.falsename()}; 9914684ddb6SLionel Sambuc const string_type* __i = __scan_keyword(__b, __e, __names, __names+2, 9924684ddb6SLionel Sambuc __ct, __err); 9934684ddb6SLionel Sambuc __v = __i == __names; 9944684ddb6SLionel Sambuc return __b; 9954684ddb6SLionel Sambuc} 9964684ddb6SLionel Sambuc 9974684ddb6SLionel Sambuc// signed 9984684ddb6SLionel Sambuc 9994684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 10004684ddb6SLionel Sambuctemplate <class _Signed> 10014684ddb6SLionel Sambuc_InputIterator 10024684ddb6SLionel Sambucnum_get<_CharT, _InputIterator>::__do_get_signed(iter_type __b, iter_type __e, 10034684ddb6SLionel Sambuc ios_base& __iob, 10044684ddb6SLionel Sambuc ios_base::iostate& __err, 10054684ddb6SLionel Sambuc _Signed& __v) const 10064684ddb6SLionel Sambuc{ 10074684ddb6SLionel Sambuc // Stage 1 10084684ddb6SLionel Sambuc int __base = this->__get_base(__iob); 10094684ddb6SLionel Sambuc // Stage 2 10104684ddb6SLionel Sambuc char_type __atoms[26]; 10114684ddb6SLionel Sambuc char_type __thousands_sep; 10124684ddb6SLionel Sambuc string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); 10134684ddb6SLionel Sambuc string __buf; 10144684ddb6SLionel Sambuc __buf.resize(__buf.capacity()); 10154684ddb6SLionel Sambuc char* __a = &__buf[0]; 10164684ddb6SLionel Sambuc char* __a_end = __a; 10174684ddb6SLionel Sambuc unsigned __g[__num_get_base::__num_get_buf_sz]; 10184684ddb6SLionel Sambuc unsigned* __g_end = __g; 10194684ddb6SLionel Sambuc unsigned __dc = 0; 10204684ddb6SLionel Sambuc for (; __b != __e; ++__b) 10214684ddb6SLionel Sambuc { 1022*0a6a1f1dSLionel Sambuc if (__a_end == __a + __buf.size()) 10234684ddb6SLionel Sambuc { 10244684ddb6SLionel Sambuc size_t __tmp = __buf.size(); 10254684ddb6SLionel Sambuc __buf.resize(2*__buf.size()); 10264684ddb6SLionel Sambuc __buf.resize(__buf.capacity()); 10274684ddb6SLionel Sambuc __a = &__buf[0]; 10284684ddb6SLionel Sambuc __a_end = __a + __tmp; 10294684ddb6SLionel Sambuc } 10304684ddb6SLionel Sambuc if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, 10314684ddb6SLionel Sambuc __thousands_sep, __grouping, __g, __g_end, 10324684ddb6SLionel Sambuc __atoms)) 10334684ddb6SLionel Sambuc break; 10344684ddb6SLionel Sambuc } 10354684ddb6SLionel Sambuc if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) 10364684ddb6SLionel Sambuc *__g_end++ = __dc; 10374684ddb6SLionel Sambuc // Stage 3 10384684ddb6SLionel Sambuc __v = __num_get_signed_integral<_Signed>(__a, __a_end, __err, __base); 10394684ddb6SLionel Sambuc // Digit grouping checked 10404684ddb6SLionel Sambuc __check_grouping(__grouping, __g, __g_end, __err); 10414684ddb6SLionel Sambuc // EOF checked 10424684ddb6SLionel Sambuc if (__b == __e) 10434684ddb6SLionel Sambuc __err |= ios_base::eofbit; 10444684ddb6SLionel Sambuc return __b; 10454684ddb6SLionel Sambuc} 10464684ddb6SLionel Sambuc 10474684ddb6SLionel Sambuc// unsigned 10484684ddb6SLionel Sambuc 10494684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 10504684ddb6SLionel Sambuctemplate <class _Unsigned> 10514684ddb6SLionel Sambuc_InputIterator 10524684ddb6SLionel Sambucnum_get<_CharT, _InputIterator>::__do_get_unsigned(iter_type __b, iter_type __e, 10534684ddb6SLionel Sambuc ios_base& __iob, 10544684ddb6SLionel Sambuc ios_base::iostate& __err, 10554684ddb6SLionel Sambuc _Unsigned& __v) const 10564684ddb6SLionel Sambuc{ 10574684ddb6SLionel Sambuc // Stage 1 10584684ddb6SLionel Sambuc int __base = this->__get_base(__iob); 10594684ddb6SLionel Sambuc // Stage 2 10604684ddb6SLionel Sambuc char_type __atoms[26]; 10614684ddb6SLionel Sambuc char_type __thousands_sep; 10624684ddb6SLionel Sambuc string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep); 10634684ddb6SLionel Sambuc string __buf; 10644684ddb6SLionel Sambuc __buf.resize(__buf.capacity()); 10654684ddb6SLionel Sambuc char* __a = &__buf[0]; 10664684ddb6SLionel Sambuc char* __a_end = __a; 10674684ddb6SLionel Sambuc unsigned __g[__num_get_base::__num_get_buf_sz]; 10684684ddb6SLionel Sambuc unsigned* __g_end = __g; 10694684ddb6SLionel Sambuc unsigned __dc = 0; 10704684ddb6SLionel Sambuc for (; __b != __e; ++__b) 10714684ddb6SLionel Sambuc { 1072*0a6a1f1dSLionel Sambuc if (__a_end == __a + __buf.size()) 10734684ddb6SLionel Sambuc { 10744684ddb6SLionel Sambuc size_t __tmp = __buf.size(); 10754684ddb6SLionel Sambuc __buf.resize(2*__buf.size()); 10764684ddb6SLionel Sambuc __buf.resize(__buf.capacity()); 10774684ddb6SLionel Sambuc __a = &__buf[0]; 10784684ddb6SLionel Sambuc __a_end = __a + __tmp; 10794684ddb6SLionel Sambuc } 10804684ddb6SLionel Sambuc if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, 10814684ddb6SLionel Sambuc __thousands_sep, __grouping, __g, __g_end, 10824684ddb6SLionel Sambuc __atoms)) 10834684ddb6SLionel Sambuc break; 10844684ddb6SLionel Sambuc } 10854684ddb6SLionel Sambuc if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz) 10864684ddb6SLionel Sambuc *__g_end++ = __dc; 10874684ddb6SLionel Sambuc // Stage 3 10884684ddb6SLionel Sambuc __v = __num_get_unsigned_integral<_Unsigned>(__a, __a_end, __err, __base); 10894684ddb6SLionel Sambuc // Digit grouping checked 10904684ddb6SLionel Sambuc __check_grouping(__grouping, __g, __g_end, __err); 10914684ddb6SLionel Sambuc // EOF checked 10924684ddb6SLionel Sambuc if (__b == __e) 10934684ddb6SLionel Sambuc __err |= ios_base::eofbit; 10944684ddb6SLionel Sambuc return __b; 10954684ddb6SLionel Sambuc} 10964684ddb6SLionel Sambuc 10974684ddb6SLionel Sambuc// floating point 10984684ddb6SLionel Sambuc 10994684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 11004684ddb6SLionel Sambuctemplate <class _Fp> 11014684ddb6SLionel Sambuc_InputIterator 11024684ddb6SLionel Sambucnum_get<_CharT, _InputIterator>::__do_get_floating_point(iter_type __b, iter_type __e, 11034684ddb6SLionel Sambuc ios_base& __iob, 11044684ddb6SLionel Sambuc ios_base::iostate& __err, 11054684ddb6SLionel Sambuc _Fp& __v) const 11064684ddb6SLionel Sambuc{ 11074684ddb6SLionel Sambuc // Stage 1, nothing to do 11084684ddb6SLionel Sambuc // Stage 2 11094684ddb6SLionel Sambuc char_type __atoms[32]; 11104684ddb6SLionel Sambuc char_type __decimal_point; 11114684ddb6SLionel Sambuc char_type __thousands_sep; 11124684ddb6SLionel Sambuc string __grouping = this->__stage2_float_prep(__iob, __atoms, 11134684ddb6SLionel Sambuc __decimal_point, 11144684ddb6SLionel Sambuc __thousands_sep); 11154684ddb6SLionel Sambuc string __buf; 11164684ddb6SLionel Sambuc __buf.resize(__buf.capacity()); 11174684ddb6SLionel Sambuc char* __a = &__buf[0]; 11184684ddb6SLionel Sambuc char* __a_end = __a; 11194684ddb6SLionel Sambuc unsigned __g[__num_get_base::__num_get_buf_sz]; 11204684ddb6SLionel Sambuc unsigned* __g_end = __g; 11214684ddb6SLionel Sambuc unsigned __dc = 0; 11224684ddb6SLionel Sambuc bool __in_units = true; 11234684ddb6SLionel Sambuc char __exp = 'E'; 11244684ddb6SLionel Sambuc for (; __b != __e; ++__b) 11254684ddb6SLionel Sambuc { 1126*0a6a1f1dSLionel Sambuc if (__a_end == __a + __buf.size()) 11274684ddb6SLionel Sambuc { 11284684ddb6SLionel Sambuc size_t __tmp = __buf.size(); 11294684ddb6SLionel Sambuc __buf.resize(2*__buf.size()); 11304684ddb6SLionel Sambuc __buf.resize(__buf.capacity()); 11314684ddb6SLionel Sambuc __a = &__buf[0]; 11324684ddb6SLionel Sambuc __a_end = __a + __tmp; 11334684ddb6SLionel Sambuc } 11344684ddb6SLionel Sambuc if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end, 11354684ddb6SLionel Sambuc __decimal_point, __thousands_sep, 11364684ddb6SLionel Sambuc __grouping, __g, __g_end, 11374684ddb6SLionel Sambuc __dc, __atoms)) 11384684ddb6SLionel Sambuc break; 11394684ddb6SLionel Sambuc } 11404684ddb6SLionel Sambuc if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz) 11414684ddb6SLionel Sambuc *__g_end++ = __dc; 11424684ddb6SLionel Sambuc // Stage 3 11434684ddb6SLionel Sambuc __v = __num_get_float<_Fp>(__a, __a_end, __err); 11444684ddb6SLionel Sambuc // Digit grouping checked 11454684ddb6SLionel Sambuc __check_grouping(__grouping, __g, __g_end, __err); 11464684ddb6SLionel Sambuc // EOF checked 11474684ddb6SLionel Sambuc if (__b == __e) 11484684ddb6SLionel Sambuc __err |= ios_base::eofbit; 11494684ddb6SLionel Sambuc return __b; 11504684ddb6SLionel Sambuc} 11514684ddb6SLionel Sambuc 11524684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 11534684ddb6SLionel Sambuc_InputIterator 11544684ddb6SLionel Sambucnum_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, 11554684ddb6SLionel Sambuc ios_base& __iob, 11564684ddb6SLionel Sambuc ios_base::iostate& __err, 11574684ddb6SLionel Sambuc void*& __v) const 11584684ddb6SLionel Sambuc{ 11594684ddb6SLionel Sambuc // Stage 1 11604684ddb6SLionel Sambuc int __base = 16; 11614684ddb6SLionel Sambuc // Stage 2 11624684ddb6SLionel Sambuc char_type __atoms[26]; 11634684ddb6SLionel Sambuc char_type __thousands_sep = 0; 11644684ddb6SLionel Sambuc string __grouping; 11654684ddb6SLionel Sambuc use_facet<ctype<_CharT> >(__iob.getloc()).widen(__num_get_base::__src, 11664684ddb6SLionel Sambuc __num_get_base::__src + 26, __atoms); 11674684ddb6SLionel Sambuc string __buf; 11684684ddb6SLionel Sambuc __buf.resize(__buf.capacity()); 11694684ddb6SLionel Sambuc char* __a = &__buf[0]; 11704684ddb6SLionel Sambuc char* __a_end = __a; 11714684ddb6SLionel Sambuc unsigned __g[__num_get_base::__num_get_buf_sz]; 11724684ddb6SLionel Sambuc unsigned* __g_end = __g; 11734684ddb6SLionel Sambuc unsigned __dc = 0; 11744684ddb6SLionel Sambuc for (; __b != __e; ++__b) 11754684ddb6SLionel Sambuc { 1176*0a6a1f1dSLionel Sambuc if (__a_end == __a + __buf.size()) 11774684ddb6SLionel Sambuc { 11784684ddb6SLionel Sambuc size_t __tmp = __buf.size(); 11794684ddb6SLionel Sambuc __buf.resize(2*__buf.size()); 11804684ddb6SLionel Sambuc __buf.resize(__buf.capacity()); 11814684ddb6SLionel Sambuc __a = &__buf[0]; 11824684ddb6SLionel Sambuc __a_end = __a + __tmp; 11834684ddb6SLionel Sambuc } 11844684ddb6SLionel Sambuc if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc, 11854684ddb6SLionel Sambuc __thousands_sep, __grouping, 11864684ddb6SLionel Sambuc __g, __g_end, __atoms)) 11874684ddb6SLionel Sambuc break; 11884684ddb6SLionel Sambuc } 11894684ddb6SLionel Sambuc // Stage 3 1190*0a6a1f1dSLionel Sambuc __buf.resize(__a_end - __a); 11914684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 1192*0a6a1f1dSLionel Sambuc if (sscanf_l(__buf.c_str(), _LIBCPP_GET_C_LOCALE, "%p", &__v) != 1) 11934684ddb6SLionel Sambuc#else 1194*0a6a1f1dSLionel Sambuc if (__sscanf_l(__buf.c_str(), _LIBCPP_GET_C_LOCALE, "%p", &__v) != 1) 11954684ddb6SLionel Sambuc#endif 11964684ddb6SLionel Sambuc __err = ios_base::failbit; 11974684ddb6SLionel Sambuc // EOF checked 11984684ddb6SLionel Sambuc if (__b == __e) 11994684ddb6SLionel Sambuc __err |= ios_base::eofbit; 12004684ddb6SLionel Sambuc return __b; 12014684ddb6SLionel Sambuc} 12024684ddb6SLionel Sambuc 12034684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS num_get<char>) 12044684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS num_get<wchar_t>) 12054684ddb6SLionel Sambuc 12064684ddb6SLionel Sambucstruct _LIBCPP_TYPE_VIS __num_put_base 12074684ddb6SLionel Sambuc{ 12084684ddb6SLionel Sambucprotected: 12094684ddb6SLionel Sambuc static void __format_int(char* __fmt, const char* __len, bool __signd, 12104684ddb6SLionel Sambuc ios_base::fmtflags __flags); 12114684ddb6SLionel Sambuc static bool __format_float(char* __fmt, const char* __len, 12124684ddb6SLionel Sambuc ios_base::fmtflags __flags); 12134684ddb6SLionel Sambuc static char* __identify_padding(char* __nb, char* __ne, 12144684ddb6SLionel Sambuc const ios_base& __iob); 12154684ddb6SLionel Sambuc}; 12164684ddb6SLionel Sambuc 12174684ddb6SLionel Sambuctemplate <class _CharT> 12184684ddb6SLionel Sambucstruct __num_put 12194684ddb6SLionel Sambuc : protected __num_put_base 12204684ddb6SLionel Sambuc{ 12214684ddb6SLionel Sambuc static void __widen_and_group_int(char* __nb, char* __np, char* __ne, 12224684ddb6SLionel Sambuc _CharT* __ob, _CharT*& __op, _CharT*& __oe, 12234684ddb6SLionel Sambuc const locale& __loc); 12244684ddb6SLionel Sambuc static void __widen_and_group_float(char* __nb, char* __np, char* __ne, 12254684ddb6SLionel Sambuc _CharT* __ob, _CharT*& __op, _CharT*& __oe, 12264684ddb6SLionel Sambuc const locale& __loc); 12274684ddb6SLionel Sambuc}; 12284684ddb6SLionel Sambuc 12294684ddb6SLionel Sambuctemplate <class _CharT> 12304684ddb6SLionel Sambucvoid 12314684ddb6SLionel Sambuc__num_put<_CharT>::__widen_and_group_int(char* __nb, char* __np, char* __ne, 12324684ddb6SLionel Sambuc _CharT* __ob, _CharT*& __op, _CharT*& __oe, 12334684ddb6SLionel Sambuc const locale& __loc) 12344684ddb6SLionel Sambuc{ 12354684ddb6SLionel Sambuc const ctype<_CharT>& __ct = use_facet<ctype<_CharT> > (__loc); 12364684ddb6SLionel Sambuc const numpunct<_CharT>& __npt = use_facet<numpunct<_CharT> >(__loc); 12374684ddb6SLionel Sambuc string __grouping = __npt.grouping(); 12384684ddb6SLionel Sambuc if (__grouping.empty()) 12394684ddb6SLionel Sambuc { 12404684ddb6SLionel Sambuc __ct.widen(__nb, __ne, __ob); 12414684ddb6SLionel Sambuc __oe = __ob + (__ne - __nb); 12424684ddb6SLionel Sambuc } 12434684ddb6SLionel Sambuc else 12444684ddb6SLionel Sambuc { 12454684ddb6SLionel Sambuc __oe = __ob; 12464684ddb6SLionel Sambuc char* __nf = __nb; 12474684ddb6SLionel Sambuc if (*__nf == '-' || *__nf == '+') 12484684ddb6SLionel Sambuc *__oe++ = __ct.widen(*__nf++); 12494684ddb6SLionel Sambuc if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' || 12504684ddb6SLionel Sambuc __nf[1] == 'X')) 12514684ddb6SLionel Sambuc { 12524684ddb6SLionel Sambuc *__oe++ = __ct.widen(*__nf++); 12534684ddb6SLionel Sambuc *__oe++ = __ct.widen(*__nf++); 12544684ddb6SLionel Sambuc } 12554684ddb6SLionel Sambuc reverse(__nf, __ne); 12564684ddb6SLionel Sambuc _CharT __thousands_sep = __npt.thousands_sep(); 12574684ddb6SLionel Sambuc unsigned __dc = 0; 12584684ddb6SLionel Sambuc unsigned __dg = 0; 12594684ddb6SLionel Sambuc for (char* __p = __nf; __p < __ne; ++__p) 12604684ddb6SLionel Sambuc { 12614684ddb6SLionel Sambuc if (static_cast<unsigned>(__grouping[__dg]) > 0 && 12624684ddb6SLionel Sambuc __dc == static_cast<unsigned>(__grouping[__dg])) 12634684ddb6SLionel Sambuc { 12644684ddb6SLionel Sambuc *__oe++ = __thousands_sep; 12654684ddb6SLionel Sambuc __dc = 0; 12664684ddb6SLionel Sambuc if (__dg < __grouping.size()-1) 12674684ddb6SLionel Sambuc ++__dg; 12684684ddb6SLionel Sambuc } 12694684ddb6SLionel Sambuc *__oe++ = __ct.widen(*__p); 12704684ddb6SLionel Sambuc ++__dc; 12714684ddb6SLionel Sambuc } 12724684ddb6SLionel Sambuc reverse(__ob + (__nf - __nb), __oe); 12734684ddb6SLionel Sambuc } 12744684ddb6SLionel Sambuc if (__np == __ne) 12754684ddb6SLionel Sambuc __op = __oe; 12764684ddb6SLionel Sambuc else 12774684ddb6SLionel Sambuc __op = __ob + (__np - __nb); 12784684ddb6SLionel Sambuc} 12794684ddb6SLionel Sambuc 12804684ddb6SLionel Sambuctemplate <class _CharT> 12814684ddb6SLionel Sambucvoid 12824684ddb6SLionel Sambuc__num_put<_CharT>::__widen_and_group_float(char* __nb, char* __np, char* __ne, 12834684ddb6SLionel Sambuc _CharT* __ob, _CharT*& __op, _CharT*& __oe, 12844684ddb6SLionel Sambuc const locale& __loc) 12854684ddb6SLionel Sambuc{ 12864684ddb6SLionel Sambuc const ctype<_CharT>& __ct = use_facet<ctype<_CharT> > (__loc); 12874684ddb6SLionel Sambuc const numpunct<_CharT>& __npt = use_facet<numpunct<_CharT> >(__loc); 12884684ddb6SLionel Sambuc string __grouping = __npt.grouping(); 12894684ddb6SLionel Sambuc __oe = __ob; 12904684ddb6SLionel Sambuc char* __nf = __nb; 12914684ddb6SLionel Sambuc if (*__nf == '-' || *__nf == '+') 12924684ddb6SLionel Sambuc *__oe++ = __ct.widen(*__nf++); 12934684ddb6SLionel Sambuc char* __ns; 12944684ddb6SLionel Sambuc if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' || 12954684ddb6SLionel Sambuc __nf[1] == 'X')) 12964684ddb6SLionel Sambuc { 12974684ddb6SLionel Sambuc *__oe++ = __ct.widen(*__nf++); 12984684ddb6SLionel Sambuc *__oe++ = __ct.widen(*__nf++); 12994684ddb6SLionel Sambuc for (__ns = __nf; __ns < __ne; ++__ns) 13004684ddb6SLionel Sambuc if (!isxdigit_l(*__ns, _LIBCPP_GET_C_LOCALE)) 13014684ddb6SLionel Sambuc break; 13024684ddb6SLionel Sambuc } 13034684ddb6SLionel Sambuc else 13044684ddb6SLionel Sambuc { 13054684ddb6SLionel Sambuc for (__ns = __nf; __ns < __ne; ++__ns) 13064684ddb6SLionel Sambuc if (!isdigit_l(*__ns, _LIBCPP_GET_C_LOCALE)) 13074684ddb6SLionel Sambuc break; 13084684ddb6SLionel Sambuc } 13094684ddb6SLionel Sambuc if (__grouping.empty()) 13104684ddb6SLionel Sambuc { 13114684ddb6SLionel Sambuc __ct.widen(__nf, __ns, __oe); 13124684ddb6SLionel Sambuc __oe += __ns - __nf; 13134684ddb6SLionel Sambuc } 13144684ddb6SLionel Sambuc else 13154684ddb6SLionel Sambuc { 13164684ddb6SLionel Sambuc reverse(__nf, __ns); 13174684ddb6SLionel Sambuc _CharT __thousands_sep = __npt.thousands_sep(); 13184684ddb6SLionel Sambuc unsigned __dc = 0; 13194684ddb6SLionel Sambuc unsigned __dg = 0; 13204684ddb6SLionel Sambuc for (char* __p = __nf; __p < __ns; ++__p) 13214684ddb6SLionel Sambuc { 13224684ddb6SLionel Sambuc if (__grouping[__dg] > 0 && __dc == static_cast<unsigned>(__grouping[__dg])) 13234684ddb6SLionel Sambuc { 13244684ddb6SLionel Sambuc *__oe++ = __thousands_sep; 13254684ddb6SLionel Sambuc __dc = 0; 13264684ddb6SLionel Sambuc if (__dg < __grouping.size()-1) 13274684ddb6SLionel Sambuc ++__dg; 13284684ddb6SLionel Sambuc } 13294684ddb6SLionel Sambuc *__oe++ = __ct.widen(*__p); 13304684ddb6SLionel Sambuc ++__dc; 13314684ddb6SLionel Sambuc } 13324684ddb6SLionel Sambuc reverse(__ob + (__nf - __nb), __oe); 13334684ddb6SLionel Sambuc } 13344684ddb6SLionel Sambuc for (__nf = __ns; __nf < __ne; ++__nf) 13354684ddb6SLionel Sambuc { 13364684ddb6SLionel Sambuc if (*__nf == '.') 13374684ddb6SLionel Sambuc { 13384684ddb6SLionel Sambuc *__oe++ = __npt.decimal_point(); 13394684ddb6SLionel Sambuc ++__nf; 13404684ddb6SLionel Sambuc break; 13414684ddb6SLionel Sambuc } 13424684ddb6SLionel Sambuc else 13434684ddb6SLionel Sambuc *__oe++ = __ct.widen(*__nf); 13444684ddb6SLionel Sambuc } 13454684ddb6SLionel Sambuc __ct.widen(__nf, __ne, __oe); 13464684ddb6SLionel Sambuc __oe += __ne - __nf; 13474684ddb6SLionel Sambuc if (__np == __ne) 13484684ddb6SLionel Sambuc __op = __oe; 13494684ddb6SLionel Sambuc else 13504684ddb6SLionel Sambuc __op = __ob + (__np - __nb); 13514684ddb6SLionel Sambuc} 13524684ddb6SLionel Sambuc 13534684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_TYPE_VIS __num_put<char>) 13544684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_TYPE_VIS __num_put<wchar_t>) 13554684ddb6SLionel Sambuc 13564684ddb6SLionel Sambuctemplate <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> > 13574684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY num_put 13584684ddb6SLionel Sambuc : public locale::facet, 13594684ddb6SLionel Sambuc private __num_put<_CharT> 13604684ddb6SLionel Sambuc{ 13614684ddb6SLionel Sambucpublic: 13624684ddb6SLionel Sambuc typedef _CharT char_type; 13634684ddb6SLionel Sambuc typedef _OutputIterator iter_type; 13644684ddb6SLionel Sambuc 13654684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 13664684ddb6SLionel Sambuc explicit num_put(size_t __refs = 0) 13674684ddb6SLionel Sambuc : locale::facet(__refs) {} 13684684ddb6SLionel Sambuc 13694684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 13704684ddb6SLionel Sambuc iter_type put(iter_type __s, ios_base& __iob, char_type __fl, 13714684ddb6SLionel Sambuc bool __v) const 13724684ddb6SLionel Sambuc { 13734684ddb6SLionel Sambuc return do_put(__s, __iob, __fl, __v); 13744684ddb6SLionel Sambuc } 13754684ddb6SLionel Sambuc 13764684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 13774684ddb6SLionel Sambuc iter_type put(iter_type __s, ios_base& __iob, char_type __fl, 13784684ddb6SLionel Sambuc long __v) const 13794684ddb6SLionel Sambuc { 13804684ddb6SLionel Sambuc return do_put(__s, __iob, __fl, __v); 13814684ddb6SLionel Sambuc } 13824684ddb6SLionel Sambuc 13834684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 13844684ddb6SLionel Sambuc iter_type put(iter_type __s, ios_base& __iob, char_type __fl, 13854684ddb6SLionel Sambuc long long __v) const 13864684ddb6SLionel Sambuc { 13874684ddb6SLionel Sambuc return do_put(__s, __iob, __fl, __v); 13884684ddb6SLionel Sambuc } 13894684ddb6SLionel Sambuc 13904684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 13914684ddb6SLionel Sambuc iter_type put(iter_type __s, ios_base& __iob, char_type __fl, 13924684ddb6SLionel Sambuc unsigned long __v) const 13934684ddb6SLionel Sambuc { 13944684ddb6SLionel Sambuc return do_put(__s, __iob, __fl, __v); 13954684ddb6SLionel Sambuc } 13964684ddb6SLionel Sambuc 13974684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 13984684ddb6SLionel Sambuc iter_type put(iter_type __s, ios_base& __iob, char_type __fl, 13994684ddb6SLionel Sambuc unsigned long long __v) const 14004684ddb6SLionel Sambuc { 14014684ddb6SLionel Sambuc return do_put(__s, __iob, __fl, __v); 14024684ddb6SLionel Sambuc } 14034684ddb6SLionel Sambuc 14044684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 14054684ddb6SLionel Sambuc iter_type put(iter_type __s, ios_base& __iob, char_type __fl, 14064684ddb6SLionel Sambuc double __v) const 14074684ddb6SLionel Sambuc { 14084684ddb6SLionel Sambuc return do_put(__s, __iob, __fl, __v); 14094684ddb6SLionel Sambuc } 14104684ddb6SLionel Sambuc 14114684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 14124684ddb6SLionel Sambuc iter_type put(iter_type __s, ios_base& __iob, char_type __fl, 14134684ddb6SLionel Sambuc long double __v) const 14144684ddb6SLionel Sambuc { 14154684ddb6SLionel Sambuc return do_put(__s, __iob, __fl, __v); 14164684ddb6SLionel Sambuc } 14174684ddb6SLionel Sambuc 14184684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 14194684ddb6SLionel Sambuc iter_type put(iter_type __s, ios_base& __iob, char_type __fl, 14204684ddb6SLionel Sambuc const void* __v) const 14214684ddb6SLionel Sambuc { 14224684ddb6SLionel Sambuc return do_put(__s, __iob, __fl, __v); 14234684ddb6SLionel Sambuc } 14244684ddb6SLionel Sambuc 14254684ddb6SLionel Sambuc static locale::id id; 14264684ddb6SLionel Sambuc 14274684ddb6SLionel Sambucprotected: 14284684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 14294684ddb6SLionel Sambuc ~num_put() {} 14304684ddb6SLionel Sambuc 14314684ddb6SLionel Sambuc virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, 14324684ddb6SLionel Sambuc bool __v) const; 14334684ddb6SLionel Sambuc virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, 14344684ddb6SLionel Sambuc long __v) const; 14354684ddb6SLionel Sambuc virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, 14364684ddb6SLionel Sambuc long long __v) const; 14374684ddb6SLionel Sambuc virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, 14384684ddb6SLionel Sambuc unsigned long) const; 14394684ddb6SLionel Sambuc virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, 14404684ddb6SLionel Sambuc unsigned long long) const; 14414684ddb6SLionel Sambuc virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, 14424684ddb6SLionel Sambuc double __v) const; 14434684ddb6SLionel Sambuc virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, 14444684ddb6SLionel Sambuc long double __v) const; 14454684ddb6SLionel Sambuc virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl, 14464684ddb6SLionel Sambuc const void* __v) const; 14474684ddb6SLionel Sambuc}; 14484684ddb6SLionel Sambuc 14494684ddb6SLionel Sambuctemplate <class _CharT, class _OutputIterator> 14504684ddb6SLionel Sambuclocale::id 14514684ddb6SLionel Sambucnum_put<_CharT, _OutputIterator>::id; 14524684ddb6SLionel Sambuc 14534684ddb6SLionel Sambuctemplate <class _CharT, class _OutputIterator> 14544684ddb6SLionel Sambuc_LIBCPP_HIDDEN 14554684ddb6SLionel Sambuc_OutputIterator 14564684ddb6SLionel Sambuc__pad_and_output(_OutputIterator __s, 14574684ddb6SLionel Sambuc const _CharT* __ob, const _CharT* __op, const _CharT* __oe, 14584684ddb6SLionel Sambuc ios_base& __iob, _CharT __fl) 14594684ddb6SLionel Sambuc{ 14604684ddb6SLionel Sambuc streamsize __sz = __oe - __ob; 14614684ddb6SLionel Sambuc streamsize __ns = __iob.width(); 14624684ddb6SLionel Sambuc if (__ns > __sz) 14634684ddb6SLionel Sambuc __ns -= __sz; 14644684ddb6SLionel Sambuc else 14654684ddb6SLionel Sambuc __ns = 0; 14664684ddb6SLionel Sambuc for (;__ob < __op; ++__ob, ++__s) 14674684ddb6SLionel Sambuc *__s = *__ob; 14684684ddb6SLionel Sambuc for (; __ns; --__ns, ++__s) 14694684ddb6SLionel Sambuc *__s = __fl; 14704684ddb6SLionel Sambuc for (; __ob < __oe; ++__ob, ++__s) 14714684ddb6SLionel Sambuc *__s = *__ob; 14724684ddb6SLionel Sambuc __iob.width(0); 14734684ddb6SLionel Sambuc return __s; 14744684ddb6SLionel Sambuc} 14754684ddb6SLionel Sambuc 14764684ddb6SLionel Sambuc#if !defined(__APPLE__) || \ 14774684ddb6SLionel Sambuc (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \ 14784684ddb6SLionel Sambuc (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0) 14794684ddb6SLionel Sambuc 14804684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 14814684ddb6SLionel Sambuc_LIBCPP_HIDDEN 14824684ddb6SLionel Sambucostreambuf_iterator<_CharT, _Traits> 14834684ddb6SLionel Sambuc__pad_and_output(ostreambuf_iterator<_CharT, _Traits> __s, 14844684ddb6SLionel Sambuc const _CharT* __ob, const _CharT* __op, const _CharT* __oe, 14854684ddb6SLionel Sambuc ios_base& __iob, _CharT __fl) 14864684ddb6SLionel Sambuc{ 14874684ddb6SLionel Sambuc if (__s.__sbuf_ == nullptr) 14884684ddb6SLionel Sambuc return __s; 14894684ddb6SLionel Sambuc streamsize __sz = __oe - __ob; 14904684ddb6SLionel Sambuc streamsize __ns = __iob.width(); 14914684ddb6SLionel Sambuc if (__ns > __sz) 14924684ddb6SLionel Sambuc __ns -= __sz; 14934684ddb6SLionel Sambuc else 14944684ddb6SLionel Sambuc __ns = 0; 14954684ddb6SLionel Sambuc streamsize __np = __op - __ob; 14964684ddb6SLionel Sambuc if (__np > 0) 14974684ddb6SLionel Sambuc { 14984684ddb6SLionel Sambuc if (__s.__sbuf_->sputn(__ob, __np) != __np) 14994684ddb6SLionel Sambuc { 15004684ddb6SLionel Sambuc __s.__sbuf_ = nullptr; 15014684ddb6SLionel Sambuc return __s; 15024684ddb6SLionel Sambuc } 15034684ddb6SLionel Sambuc } 15044684ddb6SLionel Sambuc if (__ns > 0) 15054684ddb6SLionel Sambuc { 15064684ddb6SLionel Sambuc basic_string<_CharT, _Traits> __sp(__ns, __fl); 15074684ddb6SLionel Sambuc if (__s.__sbuf_->sputn(__sp.data(), __ns) != __ns) 15084684ddb6SLionel Sambuc { 15094684ddb6SLionel Sambuc __s.__sbuf_ = nullptr; 15104684ddb6SLionel Sambuc return __s; 15114684ddb6SLionel Sambuc } 15124684ddb6SLionel Sambuc } 15134684ddb6SLionel Sambuc __np = __oe - __op; 15144684ddb6SLionel Sambuc if (__np > 0) 15154684ddb6SLionel Sambuc { 15164684ddb6SLionel Sambuc if (__s.__sbuf_->sputn(__op, __np) != __np) 15174684ddb6SLionel Sambuc { 15184684ddb6SLionel Sambuc __s.__sbuf_ = nullptr; 15194684ddb6SLionel Sambuc return __s; 15204684ddb6SLionel Sambuc } 15214684ddb6SLionel Sambuc } 15224684ddb6SLionel Sambuc __iob.width(0); 15234684ddb6SLionel Sambuc return __s; 15244684ddb6SLionel Sambuc} 15254684ddb6SLionel Sambuc 15264684ddb6SLionel Sambuc#endif 15274684ddb6SLionel Sambuc 15284684ddb6SLionel Sambuctemplate <class _CharT, class _OutputIterator> 15294684ddb6SLionel Sambuc_OutputIterator 15304684ddb6SLionel Sambucnum_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, 15314684ddb6SLionel Sambuc char_type __fl, bool __v) const 15324684ddb6SLionel Sambuc{ 15334684ddb6SLionel Sambuc if ((__iob.flags() & ios_base::boolalpha) == 0) 15344684ddb6SLionel Sambuc return do_put(__s, __iob, __fl, (unsigned long)__v); 15354684ddb6SLionel Sambuc const numpunct<char_type>& __np = use_facet<numpunct<char_type> >(__iob.getloc()); 15364684ddb6SLionel Sambuc typedef typename numpunct<char_type>::string_type string_type; 15374684ddb6SLionel Sambuc#if _LIBCPP_DEBUG_LEVEL >= 2 15384684ddb6SLionel Sambuc string_type __tmp(__v ? __np.truename() : __np.falsename()); 15394684ddb6SLionel Sambuc string_type __nm = _VSTD::move(__tmp); 15404684ddb6SLionel Sambuc#else 15414684ddb6SLionel Sambuc string_type __nm = __v ? __np.truename() : __np.falsename(); 15424684ddb6SLionel Sambuc#endif 15434684ddb6SLionel Sambuc for (typename string_type::iterator __i = __nm.begin(); __i != __nm.end(); ++__i, ++__s) 15444684ddb6SLionel Sambuc *__s = *__i; 15454684ddb6SLionel Sambuc return __s; 15464684ddb6SLionel Sambuc} 15474684ddb6SLionel Sambuc 15484684ddb6SLionel Sambuctemplate <class _CharT, class _OutputIterator> 15494684ddb6SLionel Sambuc_OutputIterator 15504684ddb6SLionel Sambucnum_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, 15514684ddb6SLionel Sambuc char_type __fl, long __v) const 15524684ddb6SLionel Sambuc{ 15534684ddb6SLionel Sambuc // Stage 1 - Get number in narrow char 15544684ddb6SLionel Sambuc char __fmt[6] = {'%', 0}; 15554684ddb6SLionel Sambuc const char* __len = "l"; 15564684ddb6SLionel Sambuc this->__format_int(__fmt+1, __len, true, __iob.flags()); 15574684ddb6SLionel Sambuc const unsigned __nbuf = (numeric_limits<long>::digits / 3) 15584684ddb6SLionel Sambuc + ((numeric_limits<long>::digits % 3) != 0) 15594684ddb6SLionel Sambuc + 1; 15604684ddb6SLionel Sambuc char __nar[__nbuf]; 15614684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 15624684ddb6SLionel Sambuc int __nc = snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); 15634684ddb6SLionel Sambuc#else 1564*0a6a1f1dSLionel Sambuc int __nc = __snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); 15654684ddb6SLionel Sambuc#endif 15664684ddb6SLionel Sambuc char* __ne = __nar + __nc; 15674684ddb6SLionel Sambuc char* __np = this->__identify_padding(__nar, __ne, __iob); 15684684ddb6SLionel Sambuc // Stage 2 - Widen __nar while adding thousands separators 15694684ddb6SLionel Sambuc char_type __o[2*(__nbuf-1) - 1]; 15704684ddb6SLionel Sambuc char_type* __op; // pad here 15714684ddb6SLionel Sambuc char_type* __oe; // end of output 15724684ddb6SLionel Sambuc this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc()); 15734684ddb6SLionel Sambuc // [__o, __oe) contains thousands_sep'd wide number 15744684ddb6SLionel Sambuc // Stage 3 & 4 15754684ddb6SLionel Sambuc return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); 15764684ddb6SLionel Sambuc} 15774684ddb6SLionel Sambuc 15784684ddb6SLionel Sambuctemplate <class _CharT, class _OutputIterator> 15794684ddb6SLionel Sambuc_OutputIterator 15804684ddb6SLionel Sambucnum_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, 15814684ddb6SLionel Sambuc char_type __fl, long long __v) const 15824684ddb6SLionel Sambuc{ 15834684ddb6SLionel Sambuc // Stage 1 - Get number in narrow char 15844684ddb6SLionel Sambuc char __fmt[8] = {'%', 0}; 15854684ddb6SLionel Sambuc const char* __len = "ll"; 15864684ddb6SLionel Sambuc this->__format_int(__fmt+1, __len, true, __iob.flags()); 15874684ddb6SLionel Sambuc const unsigned __nbuf = (numeric_limits<long long>::digits / 3) 15884684ddb6SLionel Sambuc + ((numeric_limits<long long>::digits % 3) != 0) 1589*0a6a1f1dSLionel Sambuc + 2; 15904684ddb6SLionel Sambuc char __nar[__nbuf]; 15914684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 15924684ddb6SLionel Sambuc int __nc = snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); 15934684ddb6SLionel Sambuc#else 1594*0a6a1f1dSLionel Sambuc int __nc = __snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); 15954684ddb6SLionel Sambuc#endif 15964684ddb6SLionel Sambuc char* __ne = __nar + __nc; 15974684ddb6SLionel Sambuc char* __np = this->__identify_padding(__nar, __ne, __iob); 15984684ddb6SLionel Sambuc // Stage 2 - Widen __nar while adding thousands separators 15994684ddb6SLionel Sambuc char_type __o[2*(__nbuf-1) - 1]; 16004684ddb6SLionel Sambuc char_type* __op; // pad here 16014684ddb6SLionel Sambuc char_type* __oe; // end of output 16024684ddb6SLionel Sambuc this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc()); 16034684ddb6SLionel Sambuc // [__o, __oe) contains thousands_sep'd wide number 16044684ddb6SLionel Sambuc // Stage 3 & 4 16054684ddb6SLionel Sambuc return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); 16064684ddb6SLionel Sambuc} 16074684ddb6SLionel Sambuc 16084684ddb6SLionel Sambuctemplate <class _CharT, class _OutputIterator> 16094684ddb6SLionel Sambuc_OutputIterator 16104684ddb6SLionel Sambucnum_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, 16114684ddb6SLionel Sambuc char_type __fl, unsigned long __v) const 16124684ddb6SLionel Sambuc{ 16134684ddb6SLionel Sambuc // Stage 1 - Get number in narrow char 16144684ddb6SLionel Sambuc char __fmt[6] = {'%', 0}; 16154684ddb6SLionel Sambuc const char* __len = "l"; 16164684ddb6SLionel Sambuc this->__format_int(__fmt+1, __len, false, __iob.flags()); 16174684ddb6SLionel Sambuc const unsigned __nbuf = (numeric_limits<unsigned long>::digits / 3) 16184684ddb6SLionel Sambuc + ((numeric_limits<unsigned long>::digits % 3) != 0) 16194684ddb6SLionel Sambuc + 1; 16204684ddb6SLionel Sambuc char __nar[__nbuf]; 16214684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 16224684ddb6SLionel Sambuc int __nc = snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); 16234684ddb6SLionel Sambuc#else 1624*0a6a1f1dSLionel Sambuc int __nc = __snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); 16254684ddb6SLionel Sambuc#endif 16264684ddb6SLionel Sambuc char* __ne = __nar + __nc; 16274684ddb6SLionel Sambuc char* __np = this->__identify_padding(__nar, __ne, __iob); 16284684ddb6SLionel Sambuc // Stage 2 - Widen __nar while adding thousands separators 16294684ddb6SLionel Sambuc char_type __o[2*(__nbuf-1) - 1]; 16304684ddb6SLionel Sambuc char_type* __op; // pad here 16314684ddb6SLionel Sambuc char_type* __oe; // end of output 16324684ddb6SLionel Sambuc this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc()); 16334684ddb6SLionel Sambuc // [__o, __oe) contains thousands_sep'd wide number 16344684ddb6SLionel Sambuc // Stage 3 & 4 16354684ddb6SLionel Sambuc return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); 16364684ddb6SLionel Sambuc} 16374684ddb6SLionel Sambuc 16384684ddb6SLionel Sambuctemplate <class _CharT, class _OutputIterator> 16394684ddb6SLionel Sambuc_OutputIterator 16404684ddb6SLionel Sambucnum_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, 16414684ddb6SLionel Sambuc char_type __fl, unsigned long long __v) const 16424684ddb6SLionel Sambuc{ 16434684ddb6SLionel Sambuc // Stage 1 - Get number in narrow char 16444684ddb6SLionel Sambuc char __fmt[8] = {'%', 0}; 16454684ddb6SLionel Sambuc const char* __len = "ll"; 16464684ddb6SLionel Sambuc this->__format_int(__fmt+1, __len, false, __iob.flags()); 16474684ddb6SLionel Sambuc const unsigned __nbuf = (numeric_limits<unsigned long long>::digits / 3) 16484684ddb6SLionel Sambuc + ((numeric_limits<unsigned long long>::digits % 3) != 0) 16494684ddb6SLionel Sambuc + 1; 16504684ddb6SLionel Sambuc char __nar[__nbuf]; 16514684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 16524684ddb6SLionel Sambuc int __nc = snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); 16534684ddb6SLionel Sambuc#else 1654*0a6a1f1dSLionel Sambuc int __nc = __snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); 16554684ddb6SLionel Sambuc#endif 16564684ddb6SLionel Sambuc char* __ne = __nar + __nc; 16574684ddb6SLionel Sambuc char* __np = this->__identify_padding(__nar, __ne, __iob); 16584684ddb6SLionel Sambuc // Stage 2 - Widen __nar while adding thousands separators 16594684ddb6SLionel Sambuc char_type __o[2*(__nbuf-1) - 1]; 16604684ddb6SLionel Sambuc char_type* __op; // pad here 16614684ddb6SLionel Sambuc char_type* __oe; // end of output 16624684ddb6SLionel Sambuc this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc()); 16634684ddb6SLionel Sambuc // [__o, __oe) contains thousands_sep'd wide number 16644684ddb6SLionel Sambuc // Stage 3 & 4 16654684ddb6SLionel Sambuc return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); 16664684ddb6SLionel Sambuc} 16674684ddb6SLionel Sambuc 16684684ddb6SLionel Sambuctemplate <class _CharT, class _OutputIterator> 16694684ddb6SLionel Sambuc_OutputIterator 16704684ddb6SLionel Sambucnum_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, 16714684ddb6SLionel Sambuc char_type __fl, double __v) const 16724684ddb6SLionel Sambuc{ 16734684ddb6SLionel Sambuc // Stage 1 - Get number in narrow char 16744684ddb6SLionel Sambuc char __fmt[8] = {'%', 0}; 16754684ddb6SLionel Sambuc const char* __len = ""; 16764684ddb6SLionel Sambuc bool __specify_precision = this->__format_float(__fmt+1, __len, __iob.flags()); 16774684ddb6SLionel Sambuc const unsigned __nbuf = 30; 16784684ddb6SLionel Sambuc char __nar[__nbuf]; 16794684ddb6SLionel Sambuc char* __nb = __nar; 16804684ddb6SLionel Sambuc int __nc; 16814684ddb6SLionel Sambuc if (__specify_precision) 16824684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 16834684ddb6SLionel Sambuc __nc = snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, 16844684ddb6SLionel Sambuc (int)__iob.precision(), __v); 16854684ddb6SLionel Sambuc#else 1686*0a6a1f1dSLionel Sambuc __nc = __snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, 16874684ddb6SLionel Sambuc (int)__iob.precision(), __v); 16884684ddb6SLionel Sambuc#endif 16894684ddb6SLionel Sambuc else 16904684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 16914684ddb6SLionel Sambuc __nc = snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v); 16924684ddb6SLionel Sambuc#else 1693*0a6a1f1dSLionel Sambuc __nc = __snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v); 16944684ddb6SLionel Sambuc#endif 16954684ddb6SLionel Sambuc unique_ptr<char, void(*)(void*)> __nbh(0, free); 16964684ddb6SLionel Sambuc if (__nc > static_cast<int>(__nbuf-1)) 16974684ddb6SLionel Sambuc { 16984684ddb6SLionel Sambuc if (__specify_precision) 16994684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 17004684ddb6SLionel Sambuc __nc = asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v); 17014684ddb6SLionel Sambuc#else 1702*0a6a1f1dSLionel Sambuc __nc = __asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v); 17034684ddb6SLionel Sambuc#endif 17044684ddb6SLionel Sambuc else 17054684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 17064684ddb6SLionel Sambuc __nc = asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v); 17074684ddb6SLionel Sambuc#else 1708*0a6a1f1dSLionel Sambuc __nc = __asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v); 17094684ddb6SLionel Sambuc#endif 17104684ddb6SLionel Sambuc if (__nb == 0) 17114684ddb6SLionel Sambuc __throw_bad_alloc(); 17124684ddb6SLionel Sambuc __nbh.reset(__nb); 17134684ddb6SLionel Sambuc } 17144684ddb6SLionel Sambuc char* __ne = __nb + __nc; 17154684ddb6SLionel Sambuc char* __np = this->__identify_padding(__nb, __ne, __iob); 17164684ddb6SLionel Sambuc // Stage 2 - Widen __nar while adding thousands separators 17174684ddb6SLionel Sambuc char_type __o[2*(__nbuf-1) - 1]; 17184684ddb6SLionel Sambuc char_type* __ob = __o; 17194684ddb6SLionel Sambuc unique_ptr<char_type, void(*)(void*)> __obh(0, free); 17204684ddb6SLionel Sambuc if (__nb != __nar) 17214684ddb6SLionel Sambuc { 17224684ddb6SLionel Sambuc __ob = (char_type*)malloc(2*static_cast<size_t>(__nc)*sizeof(char_type)); 17234684ddb6SLionel Sambuc if (__ob == 0) 17244684ddb6SLionel Sambuc __throw_bad_alloc(); 17254684ddb6SLionel Sambuc __obh.reset(__ob); 17264684ddb6SLionel Sambuc } 17274684ddb6SLionel Sambuc char_type* __op; // pad here 17284684ddb6SLionel Sambuc char_type* __oe; // end of output 17294684ddb6SLionel Sambuc this->__widen_and_group_float(__nb, __np, __ne, __ob, __op, __oe, __iob.getloc()); 17304684ddb6SLionel Sambuc // [__o, __oe) contains thousands_sep'd wide number 17314684ddb6SLionel Sambuc // Stage 3 & 4 17324684ddb6SLionel Sambuc __s = __pad_and_output(__s, __ob, __op, __oe, __iob, __fl); 17334684ddb6SLionel Sambuc return __s; 17344684ddb6SLionel Sambuc} 17354684ddb6SLionel Sambuc 17364684ddb6SLionel Sambuctemplate <class _CharT, class _OutputIterator> 17374684ddb6SLionel Sambuc_OutputIterator 17384684ddb6SLionel Sambucnum_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, 17394684ddb6SLionel Sambuc char_type __fl, long double __v) const 17404684ddb6SLionel Sambuc{ 17414684ddb6SLionel Sambuc // Stage 1 - Get number in narrow char 17424684ddb6SLionel Sambuc char __fmt[8] = {'%', 0}; 17434684ddb6SLionel Sambuc const char* __len = "L"; 17444684ddb6SLionel Sambuc bool __specify_precision = this->__format_float(__fmt+1, __len, __iob.flags()); 17454684ddb6SLionel Sambuc const unsigned __nbuf = 30; 17464684ddb6SLionel Sambuc char __nar[__nbuf]; 17474684ddb6SLionel Sambuc char* __nb = __nar; 17484684ddb6SLionel Sambuc int __nc; 17494684ddb6SLionel Sambuc if (__specify_precision) 17504684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 17514684ddb6SLionel Sambuc __nc = snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, 17524684ddb6SLionel Sambuc (int)__iob.precision(), __v); 17534684ddb6SLionel Sambuc#else 1754*0a6a1f1dSLionel Sambuc __nc = __snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, 17554684ddb6SLionel Sambuc (int)__iob.precision(), __v); 17564684ddb6SLionel Sambuc#endif 17574684ddb6SLionel Sambuc else 17584684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 17594684ddb6SLionel Sambuc __nc = snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v); 17604684ddb6SLionel Sambuc#else 1761*0a6a1f1dSLionel Sambuc __nc = __snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v); 17624684ddb6SLionel Sambuc#endif 17634684ddb6SLionel Sambuc unique_ptr<char, void(*)(void*)> __nbh(0, free); 17644684ddb6SLionel Sambuc if (__nc > static_cast<int>(__nbuf-1)) 17654684ddb6SLionel Sambuc { 17664684ddb6SLionel Sambuc if (__specify_precision) 17674684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 17684684ddb6SLionel Sambuc __nc = asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v); 17694684ddb6SLionel Sambuc#else 1770*0a6a1f1dSLionel Sambuc __nc = __asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v); 17714684ddb6SLionel Sambuc#endif 17724684ddb6SLionel Sambuc else 17734684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 17744684ddb6SLionel Sambuc __nc = asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v); 17754684ddb6SLionel Sambuc#else 1776*0a6a1f1dSLionel Sambuc __nc = __asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v); 17774684ddb6SLionel Sambuc#endif 17784684ddb6SLionel Sambuc if (__nb == 0) 17794684ddb6SLionel Sambuc __throw_bad_alloc(); 17804684ddb6SLionel Sambuc __nbh.reset(__nb); 17814684ddb6SLionel Sambuc } 17824684ddb6SLionel Sambuc char* __ne = __nb + __nc; 17834684ddb6SLionel Sambuc char* __np = this->__identify_padding(__nb, __ne, __iob); 17844684ddb6SLionel Sambuc // Stage 2 - Widen __nar while adding thousands separators 17854684ddb6SLionel Sambuc char_type __o[2*(__nbuf-1) - 1]; 17864684ddb6SLionel Sambuc char_type* __ob = __o; 17874684ddb6SLionel Sambuc unique_ptr<char_type, void(*)(void*)> __obh(0, free); 17884684ddb6SLionel Sambuc if (__nb != __nar) 17894684ddb6SLionel Sambuc { 17904684ddb6SLionel Sambuc __ob = (char_type*)malloc(2*static_cast<size_t>(__nc)*sizeof(char_type)); 17914684ddb6SLionel Sambuc if (__ob == 0) 17924684ddb6SLionel Sambuc __throw_bad_alloc(); 17934684ddb6SLionel Sambuc __obh.reset(__ob); 17944684ddb6SLionel Sambuc } 17954684ddb6SLionel Sambuc char_type* __op; // pad here 17964684ddb6SLionel Sambuc char_type* __oe; // end of output 17974684ddb6SLionel Sambuc this->__widen_and_group_float(__nb, __np, __ne, __ob, __op, __oe, __iob.getloc()); 17984684ddb6SLionel Sambuc // [__o, __oe) contains thousands_sep'd wide number 17994684ddb6SLionel Sambuc // Stage 3 & 4 18004684ddb6SLionel Sambuc __s = __pad_and_output(__s, __ob, __op, __oe, __iob, __fl); 18014684ddb6SLionel Sambuc return __s; 18024684ddb6SLionel Sambuc} 18034684ddb6SLionel Sambuc 18044684ddb6SLionel Sambuctemplate <class _CharT, class _OutputIterator> 18054684ddb6SLionel Sambuc_OutputIterator 18064684ddb6SLionel Sambucnum_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, 18074684ddb6SLionel Sambuc char_type __fl, const void* __v) const 18084684ddb6SLionel Sambuc{ 18094684ddb6SLionel Sambuc // Stage 1 - Get pointer in narrow char 18104684ddb6SLionel Sambuc char __fmt[6] = "%p"; 18114684ddb6SLionel Sambuc const unsigned __nbuf = 20; 18124684ddb6SLionel Sambuc char __nar[__nbuf]; 18134684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 18144684ddb6SLionel Sambuc int __nc = snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); 18154684ddb6SLionel Sambuc#else 1816*0a6a1f1dSLionel Sambuc int __nc = __snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v); 18174684ddb6SLionel Sambuc#endif 18184684ddb6SLionel Sambuc char* __ne = __nar + __nc; 18194684ddb6SLionel Sambuc char* __np = this->__identify_padding(__nar, __ne, __iob); 18204684ddb6SLionel Sambuc // Stage 2 - Widen __nar 18214684ddb6SLionel Sambuc char_type __o[2*(__nbuf-1) - 1]; 18224684ddb6SLionel Sambuc char_type* __op; // pad here 18234684ddb6SLionel Sambuc char_type* __oe; // end of output 18244684ddb6SLionel Sambuc const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc()); 18254684ddb6SLionel Sambuc __ct.widen(__nar, __ne, __o); 18264684ddb6SLionel Sambuc __oe = __o + (__ne - __nar); 18274684ddb6SLionel Sambuc if (__np == __ne) 18284684ddb6SLionel Sambuc __op = __oe; 18294684ddb6SLionel Sambuc else 18304684ddb6SLionel Sambuc __op = __o + (__np - __nar); 18314684ddb6SLionel Sambuc // [__o, __oe) contains wide number 18324684ddb6SLionel Sambuc // Stage 3 & 4 18334684ddb6SLionel Sambuc return __pad_and_output(__s, __o, __op, __oe, __iob, __fl); 18344684ddb6SLionel Sambuc} 18354684ddb6SLionel Sambuc 18364684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS num_put<char>) 18374684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS num_put<wchar_t>) 18384684ddb6SLionel Sambuc 18394684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 18404684ddb6SLionel Sambuc_LIBCPP_HIDDEN 18414684ddb6SLionel Sambucint 18424684ddb6SLionel Sambuc__get_up_to_n_digits(_InputIterator& __b, _InputIterator __e, 18434684ddb6SLionel Sambuc ios_base::iostate& __err, const ctype<_CharT>& __ct, int __n) 18444684ddb6SLionel Sambuc{ 18454684ddb6SLionel Sambuc // Precondition: __n >= 1 18464684ddb6SLionel Sambuc if (__b == __e) 18474684ddb6SLionel Sambuc { 18484684ddb6SLionel Sambuc __err |= ios_base::eofbit | ios_base::failbit; 18494684ddb6SLionel Sambuc return 0; 18504684ddb6SLionel Sambuc } 18514684ddb6SLionel Sambuc // get first digit 18524684ddb6SLionel Sambuc _CharT __c = *__b; 18534684ddb6SLionel Sambuc if (!__ct.is(ctype_base::digit, __c)) 18544684ddb6SLionel Sambuc { 18554684ddb6SLionel Sambuc __err |= ios_base::failbit; 18564684ddb6SLionel Sambuc return 0; 18574684ddb6SLionel Sambuc } 18584684ddb6SLionel Sambuc int __r = __ct.narrow(__c, 0) - '0'; 1859*0a6a1f1dSLionel Sambuc for (++__b, (void) --__n; __b != __e && __n > 0; ++__b, (void) --__n) 18604684ddb6SLionel Sambuc { 18614684ddb6SLionel Sambuc // get next digit 18624684ddb6SLionel Sambuc __c = *__b; 18634684ddb6SLionel Sambuc if (!__ct.is(ctype_base::digit, __c)) 18644684ddb6SLionel Sambuc return __r; 18654684ddb6SLionel Sambuc __r = __r * 10 + __ct.narrow(__c, 0) - '0'; 18664684ddb6SLionel Sambuc } 18674684ddb6SLionel Sambuc if (__b == __e) 18684684ddb6SLionel Sambuc __err |= ios_base::eofbit; 18694684ddb6SLionel Sambuc return __r; 18704684ddb6SLionel Sambuc} 18714684ddb6SLionel Sambuc 18724684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS time_base 18734684ddb6SLionel Sambuc{ 18744684ddb6SLionel Sambucpublic: 18754684ddb6SLionel Sambuc enum dateorder {no_order, dmy, mdy, ymd, ydm}; 18764684ddb6SLionel Sambuc}; 18774684ddb6SLionel Sambuc 18784684ddb6SLionel Sambuctemplate <class _CharT> 1879*0a6a1f1dSLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY __time_get_c_storage 18804684ddb6SLionel Sambuc{ 18814684ddb6SLionel Sambucprotected: 18824684ddb6SLionel Sambuc typedef basic_string<_CharT> string_type; 18834684ddb6SLionel Sambuc 18844684ddb6SLionel Sambuc virtual const string_type* __weeks() const; 18854684ddb6SLionel Sambuc virtual const string_type* __months() const; 18864684ddb6SLionel Sambuc virtual const string_type* __am_pm() const; 18874684ddb6SLionel Sambuc virtual const string_type& __c() const; 18884684ddb6SLionel Sambuc virtual const string_type& __r() const; 18894684ddb6SLionel Sambuc virtual const string_type& __x() const; 18904684ddb6SLionel Sambuc virtual const string_type& __X() const; 1891*0a6a1f1dSLionel Sambuc 1892*0a6a1f1dSLionel Sambuc _LIBCPP_ALWAYS_INLINE 1893*0a6a1f1dSLionel Sambuc ~__time_get_c_storage() {} 18944684ddb6SLionel Sambuc}; 18954684ddb6SLionel Sambuc 18964684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> > 18974684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY time_get 18984684ddb6SLionel Sambuc : public locale::facet, 18994684ddb6SLionel Sambuc public time_base, 19004684ddb6SLionel Sambuc private __time_get_c_storage<_CharT> 19014684ddb6SLionel Sambuc{ 19024684ddb6SLionel Sambucpublic: 19034684ddb6SLionel Sambuc typedef _CharT char_type; 19044684ddb6SLionel Sambuc typedef _InputIterator iter_type; 19054684ddb6SLionel Sambuc typedef time_base::dateorder dateorder; 19064684ddb6SLionel Sambuc typedef basic_string<char_type> string_type; 19074684ddb6SLionel Sambuc 19084684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 19094684ddb6SLionel Sambuc explicit time_get(size_t __refs = 0) 19104684ddb6SLionel Sambuc : locale::facet(__refs) {} 19114684ddb6SLionel Sambuc 19124684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 19134684ddb6SLionel Sambuc dateorder date_order() const 19144684ddb6SLionel Sambuc { 19154684ddb6SLionel Sambuc return this->do_date_order(); 19164684ddb6SLionel Sambuc } 19174684ddb6SLionel Sambuc 19184684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 19194684ddb6SLionel Sambuc iter_type get_time(iter_type __b, iter_type __e, ios_base& __iob, 19204684ddb6SLionel Sambuc ios_base::iostate& __err, tm* __tm) const 19214684ddb6SLionel Sambuc { 19224684ddb6SLionel Sambuc return do_get_time(__b, __e, __iob, __err, __tm); 19234684ddb6SLionel Sambuc } 19244684ddb6SLionel Sambuc 19254684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 19264684ddb6SLionel Sambuc iter_type get_date(iter_type __b, iter_type __e, ios_base& __iob, 19274684ddb6SLionel Sambuc ios_base::iostate& __err, tm* __tm) const 19284684ddb6SLionel Sambuc { 19294684ddb6SLionel Sambuc return do_get_date(__b, __e, __iob, __err, __tm); 19304684ddb6SLionel Sambuc } 19314684ddb6SLionel Sambuc 19324684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 19334684ddb6SLionel Sambuc iter_type get_weekday(iter_type __b, iter_type __e, ios_base& __iob, 19344684ddb6SLionel Sambuc ios_base::iostate& __err, tm* __tm) const 19354684ddb6SLionel Sambuc { 19364684ddb6SLionel Sambuc return do_get_weekday(__b, __e, __iob, __err, __tm); 19374684ddb6SLionel Sambuc } 19384684ddb6SLionel Sambuc 19394684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 19404684ddb6SLionel Sambuc iter_type get_monthname(iter_type __b, iter_type __e, ios_base& __iob, 19414684ddb6SLionel Sambuc ios_base::iostate& __err, tm* __tm) const 19424684ddb6SLionel Sambuc { 19434684ddb6SLionel Sambuc return do_get_monthname(__b, __e, __iob, __err, __tm); 19444684ddb6SLionel Sambuc } 19454684ddb6SLionel Sambuc 19464684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 19474684ddb6SLionel Sambuc iter_type get_year(iter_type __b, iter_type __e, ios_base& __iob, 19484684ddb6SLionel Sambuc ios_base::iostate& __err, tm* __tm) const 19494684ddb6SLionel Sambuc { 19504684ddb6SLionel Sambuc return do_get_year(__b, __e, __iob, __err, __tm); 19514684ddb6SLionel Sambuc } 19524684ddb6SLionel Sambuc 19534684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 19544684ddb6SLionel Sambuc iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 19554684ddb6SLionel Sambuc ios_base::iostate& __err, tm *__tm, 19564684ddb6SLionel Sambuc char __fmt, char __mod = 0) const 19574684ddb6SLionel Sambuc { 19584684ddb6SLionel Sambuc return do_get(__b, __e, __iob, __err, __tm, __fmt, __mod); 19594684ddb6SLionel Sambuc } 19604684ddb6SLionel Sambuc 19614684ddb6SLionel Sambuc iter_type get(iter_type __b, iter_type __e, ios_base& __iob, 19624684ddb6SLionel Sambuc ios_base::iostate& __err, tm* __tm, 19634684ddb6SLionel Sambuc const char_type* __fmtb, const char_type* __fmte) const; 19644684ddb6SLionel Sambuc 19654684ddb6SLionel Sambuc static locale::id id; 19664684ddb6SLionel Sambuc 19674684ddb6SLionel Sambucprotected: 19684684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 19694684ddb6SLionel Sambuc ~time_get() {} 19704684ddb6SLionel Sambuc 19714684ddb6SLionel Sambuc virtual dateorder do_date_order() const; 19724684ddb6SLionel Sambuc virtual iter_type do_get_time(iter_type __b, iter_type __e, ios_base& __iob, 19734684ddb6SLionel Sambuc ios_base::iostate& __err, tm* __tm) const; 19744684ddb6SLionel Sambuc virtual iter_type do_get_date(iter_type __b, iter_type __e, ios_base& __iob, 19754684ddb6SLionel Sambuc ios_base::iostate& __err, tm* __tm) const; 19764684ddb6SLionel Sambuc virtual iter_type do_get_weekday(iter_type __b, iter_type __e, ios_base& __iob, 19774684ddb6SLionel Sambuc ios_base::iostate& __err, tm* __tm) const; 19784684ddb6SLionel Sambuc virtual iter_type do_get_monthname(iter_type __b, iter_type __e, ios_base& __iob, 19794684ddb6SLionel Sambuc ios_base::iostate& __err, tm* __tm) const; 19804684ddb6SLionel Sambuc virtual iter_type do_get_year(iter_type __b, iter_type __e, ios_base& __iob, 19814684ddb6SLionel Sambuc ios_base::iostate& __err, tm* __tm) const; 19824684ddb6SLionel Sambuc virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob, 19834684ddb6SLionel Sambuc ios_base::iostate& __err, tm* __tm, 19844684ddb6SLionel Sambuc char __fmt, char __mod) const; 19854684ddb6SLionel Sambucprivate: 19864684ddb6SLionel Sambuc void __get_white_space(iter_type& __b, iter_type __e, 19874684ddb6SLionel Sambuc ios_base::iostate& __err, const ctype<char_type>& __ct) const; 19884684ddb6SLionel Sambuc void __get_percent(iter_type& __b, iter_type __e, ios_base::iostate& __err, 19894684ddb6SLionel Sambuc const ctype<char_type>& __ct) const; 19904684ddb6SLionel Sambuc 19914684ddb6SLionel Sambuc void __get_weekdayname(int& __m, 19924684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 19934684ddb6SLionel Sambuc ios_base::iostate& __err, 19944684ddb6SLionel Sambuc const ctype<char_type>& __ct) const; 19954684ddb6SLionel Sambuc void __get_monthname(int& __m, 19964684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 19974684ddb6SLionel Sambuc ios_base::iostate& __err, 19984684ddb6SLionel Sambuc const ctype<char_type>& __ct) const; 19994684ddb6SLionel Sambuc void __get_day(int& __d, 20004684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 20014684ddb6SLionel Sambuc ios_base::iostate& __err, 20024684ddb6SLionel Sambuc const ctype<char_type>& __ct) const; 20034684ddb6SLionel Sambuc void __get_month(int& __m, 20044684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 20054684ddb6SLionel Sambuc ios_base::iostate& __err, 20064684ddb6SLionel Sambuc const ctype<char_type>& __ct) const; 20074684ddb6SLionel Sambuc void __get_year(int& __y, 20084684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 20094684ddb6SLionel Sambuc ios_base::iostate& __err, 20104684ddb6SLionel Sambuc const ctype<char_type>& __ct) const; 20114684ddb6SLionel Sambuc void __get_year4(int& __y, 20124684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 20134684ddb6SLionel Sambuc ios_base::iostate& __err, 20144684ddb6SLionel Sambuc const ctype<char_type>& __ct) const; 20154684ddb6SLionel Sambuc void __get_hour(int& __d, 20164684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 20174684ddb6SLionel Sambuc ios_base::iostate& __err, 20184684ddb6SLionel Sambuc const ctype<char_type>& __ct) const; 20194684ddb6SLionel Sambuc void __get_12_hour(int& __h, 20204684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 20214684ddb6SLionel Sambuc ios_base::iostate& __err, 20224684ddb6SLionel Sambuc const ctype<char_type>& __ct) const; 20234684ddb6SLionel Sambuc void __get_am_pm(int& __h, 20244684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 20254684ddb6SLionel Sambuc ios_base::iostate& __err, 20264684ddb6SLionel Sambuc const ctype<char_type>& __ct) const; 20274684ddb6SLionel Sambuc void __get_minute(int& __m, 20284684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 20294684ddb6SLionel Sambuc ios_base::iostate& __err, 20304684ddb6SLionel Sambuc const ctype<char_type>& __ct) const; 20314684ddb6SLionel Sambuc void __get_second(int& __s, 20324684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 20334684ddb6SLionel Sambuc ios_base::iostate& __err, 20344684ddb6SLionel Sambuc const ctype<char_type>& __ct) const; 20354684ddb6SLionel Sambuc void __get_weekday(int& __w, 20364684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 20374684ddb6SLionel Sambuc ios_base::iostate& __err, 20384684ddb6SLionel Sambuc const ctype<char_type>& __ct) const; 20394684ddb6SLionel Sambuc void __get_day_year_num(int& __w, 20404684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 20414684ddb6SLionel Sambuc ios_base::iostate& __err, 20424684ddb6SLionel Sambuc const ctype<char_type>& __ct) const; 20434684ddb6SLionel Sambuc}; 20444684ddb6SLionel Sambuc 20454684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 20464684ddb6SLionel Sambuclocale::id 20474684ddb6SLionel Sambuctime_get<_CharT, _InputIterator>::id; 20484684ddb6SLionel Sambuc 2049*0a6a1f1dSLionel Sambuc// time_get primitives 20504684ddb6SLionel Sambuc 20514684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 20524684ddb6SLionel Sambucvoid 20534684ddb6SLionel Sambuctime_get<_CharT, _InputIterator>::__get_weekdayname(int& __w, 20544684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 20554684ddb6SLionel Sambuc ios_base::iostate& __err, 20564684ddb6SLionel Sambuc const ctype<char_type>& __ct) const 20574684ddb6SLionel Sambuc{ 20584684ddb6SLionel Sambuc // Note: ignoring case comes from the POSIX strptime spec 20594684ddb6SLionel Sambuc const string_type* __wk = this->__weeks(); 20604684ddb6SLionel Sambuc ptrdiff_t __i = __scan_keyword(__b, __e, __wk, __wk+14, __ct, __err, false) - __wk; 20614684ddb6SLionel Sambuc if (__i < 14) 20624684ddb6SLionel Sambuc __w = __i % 7; 20634684ddb6SLionel Sambuc} 20644684ddb6SLionel Sambuc 20654684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 20664684ddb6SLionel Sambucvoid 20674684ddb6SLionel Sambuctime_get<_CharT, _InputIterator>::__get_monthname(int& __m, 20684684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 20694684ddb6SLionel Sambuc ios_base::iostate& __err, 20704684ddb6SLionel Sambuc const ctype<char_type>& __ct) const 20714684ddb6SLionel Sambuc{ 20724684ddb6SLionel Sambuc // Note: ignoring case comes from the POSIX strptime spec 20734684ddb6SLionel Sambuc const string_type* __month = this->__months(); 20744684ddb6SLionel Sambuc ptrdiff_t __i = __scan_keyword(__b, __e, __month, __month+24, __ct, __err, false) - __month; 20754684ddb6SLionel Sambuc if (__i < 24) 20764684ddb6SLionel Sambuc __m = __i % 12; 20774684ddb6SLionel Sambuc} 20784684ddb6SLionel Sambuc 20794684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 20804684ddb6SLionel Sambucvoid 20814684ddb6SLionel Sambuctime_get<_CharT, _InputIterator>::__get_day(int& __d, 20824684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 20834684ddb6SLionel Sambuc ios_base::iostate& __err, 20844684ddb6SLionel Sambuc const ctype<char_type>& __ct) const 20854684ddb6SLionel Sambuc{ 20864684ddb6SLionel Sambuc int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); 20874684ddb6SLionel Sambuc if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 31) 20884684ddb6SLionel Sambuc __d = __t; 20894684ddb6SLionel Sambuc else 20904684ddb6SLionel Sambuc __err |= ios_base::failbit; 20914684ddb6SLionel Sambuc} 20924684ddb6SLionel Sambuc 20934684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 20944684ddb6SLionel Sambucvoid 20954684ddb6SLionel Sambuctime_get<_CharT, _InputIterator>::__get_month(int& __m, 20964684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 20974684ddb6SLionel Sambuc ios_base::iostate& __err, 20984684ddb6SLionel Sambuc const ctype<char_type>& __ct) const 20994684ddb6SLionel Sambuc{ 21004684ddb6SLionel Sambuc int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2) - 1; 21014684ddb6SLionel Sambuc if (!(__err & ios_base::failbit) && __t <= 11) 21024684ddb6SLionel Sambuc __m = __t; 21034684ddb6SLionel Sambuc else 21044684ddb6SLionel Sambuc __err |= ios_base::failbit; 21054684ddb6SLionel Sambuc} 21064684ddb6SLionel Sambuc 21074684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 21084684ddb6SLionel Sambucvoid 21094684ddb6SLionel Sambuctime_get<_CharT, _InputIterator>::__get_year(int& __y, 21104684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 21114684ddb6SLionel Sambuc ios_base::iostate& __err, 21124684ddb6SLionel Sambuc const ctype<char_type>& __ct) const 21134684ddb6SLionel Sambuc{ 21144684ddb6SLionel Sambuc int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 4); 21154684ddb6SLionel Sambuc if (!(__err & ios_base::failbit)) 21164684ddb6SLionel Sambuc { 21174684ddb6SLionel Sambuc if (__t < 69) 21184684ddb6SLionel Sambuc __t += 2000; 21194684ddb6SLionel Sambuc else if (69 <= __t && __t <= 99) 21204684ddb6SLionel Sambuc __t += 1900; 21214684ddb6SLionel Sambuc __y = __t - 1900; 21224684ddb6SLionel Sambuc } 21234684ddb6SLionel Sambuc} 21244684ddb6SLionel Sambuc 21254684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 21264684ddb6SLionel Sambucvoid 21274684ddb6SLionel Sambuctime_get<_CharT, _InputIterator>::__get_year4(int& __y, 21284684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 21294684ddb6SLionel Sambuc ios_base::iostate& __err, 21304684ddb6SLionel Sambuc const ctype<char_type>& __ct) const 21314684ddb6SLionel Sambuc{ 21324684ddb6SLionel Sambuc int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 4); 21334684ddb6SLionel Sambuc if (!(__err & ios_base::failbit)) 21344684ddb6SLionel Sambuc __y = __t - 1900; 21354684ddb6SLionel Sambuc} 21364684ddb6SLionel Sambuc 21374684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 21384684ddb6SLionel Sambucvoid 21394684ddb6SLionel Sambuctime_get<_CharT, _InputIterator>::__get_hour(int& __h, 21404684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 21414684ddb6SLionel Sambuc ios_base::iostate& __err, 21424684ddb6SLionel Sambuc const ctype<char_type>& __ct) const 21434684ddb6SLionel Sambuc{ 21444684ddb6SLionel Sambuc int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); 21454684ddb6SLionel Sambuc if (!(__err & ios_base::failbit) && __t <= 23) 21464684ddb6SLionel Sambuc __h = __t; 21474684ddb6SLionel Sambuc else 21484684ddb6SLionel Sambuc __err |= ios_base::failbit; 21494684ddb6SLionel Sambuc} 21504684ddb6SLionel Sambuc 21514684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 21524684ddb6SLionel Sambucvoid 21534684ddb6SLionel Sambuctime_get<_CharT, _InputIterator>::__get_12_hour(int& __h, 21544684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 21554684ddb6SLionel Sambuc ios_base::iostate& __err, 21564684ddb6SLionel Sambuc const ctype<char_type>& __ct) const 21574684ddb6SLionel Sambuc{ 21584684ddb6SLionel Sambuc int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); 21594684ddb6SLionel Sambuc if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 12) 21604684ddb6SLionel Sambuc __h = __t; 21614684ddb6SLionel Sambuc else 21624684ddb6SLionel Sambuc __err |= ios_base::failbit; 21634684ddb6SLionel Sambuc} 21644684ddb6SLionel Sambuc 21654684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 21664684ddb6SLionel Sambucvoid 21674684ddb6SLionel Sambuctime_get<_CharT, _InputIterator>::__get_minute(int& __m, 21684684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 21694684ddb6SLionel Sambuc ios_base::iostate& __err, 21704684ddb6SLionel Sambuc const ctype<char_type>& __ct) const 21714684ddb6SLionel Sambuc{ 21724684ddb6SLionel Sambuc int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); 21734684ddb6SLionel Sambuc if (!(__err & ios_base::failbit) && __t <= 59) 21744684ddb6SLionel Sambuc __m = __t; 21754684ddb6SLionel Sambuc else 21764684ddb6SLionel Sambuc __err |= ios_base::failbit; 21774684ddb6SLionel Sambuc} 21784684ddb6SLionel Sambuc 21794684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 21804684ddb6SLionel Sambucvoid 21814684ddb6SLionel Sambuctime_get<_CharT, _InputIterator>::__get_second(int& __s, 21824684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 21834684ddb6SLionel Sambuc ios_base::iostate& __err, 21844684ddb6SLionel Sambuc const ctype<char_type>& __ct) const 21854684ddb6SLionel Sambuc{ 21864684ddb6SLionel Sambuc int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2); 21874684ddb6SLionel Sambuc if (!(__err & ios_base::failbit) && __t <= 60) 21884684ddb6SLionel Sambuc __s = __t; 21894684ddb6SLionel Sambuc else 21904684ddb6SLionel Sambuc __err |= ios_base::failbit; 21914684ddb6SLionel Sambuc} 21924684ddb6SLionel Sambuc 21934684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 21944684ddb6SLionel Sambucvoid 21954684ddb6SLionel Sambuctime_get<_CharT, _InputIterator>::__get_weekday(int& __w, 21964684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 21974684ddb6SLionel Sambuc ios_base::iostate& __err, 21984684ddb6SLionel Sambuc const ctype<char_type>& __ct) const 21994684ddb6SLionel Sambuc{ 22004684ddb6SLionel Sambuc int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 1); 22014684ddb6SLionel Sambuc if (!(__err & ios_base::failbit) && __t <= 6) 22024684ddb6SLionel Sambuc __w = __t; 22034684ddb6SLionel Sambuc else 22044684ddb6SLionel Sambuc __err |= ios_base::failbit; 22054684ddb6SLionel Sambuc} 22064684ddb6SLionel Sambuc 22074684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 22084684ddb6SLionel Sambucvoid 22094684ddb6SLionel Sambuctime_get<_CharT, _InputIterator>::__get_day_year_num(int& __d, 22104684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 22114684ddb6SLionel Sambuc ios_base::iostate& __err, 22124684ddb6SLionel Sambuc const ctype<char_type>& __ct) const 22134684ddb6SLionel Sambuc{ 22144684ddb6SLionel Sambuc int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 3); 22154684ddb6SLionel Sambuc if (!(__err & ios_base::failbit) && __t <= 365) 22164684ddb6SLionel Sambuc __d = __t; 22174684ddb6SLionel Sambuc else 22184684ddb6SLionel Sambuc __err |= ios_base::failbit; 22194684ddb6SLionel Sambuc} 22204684ddb6SLionel Sambuc 22214684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 22224684ddb6SLionel Sambucvoid 22234684ddb6SLionel Sambuctime_get<_CharT, _InputIterator>::__get_white_space(iter_type& __b, iter_type __e, 22244684ddb6SLionel Sambuc ios_base::iostate& __err, 22254684ddb6SLionel Sambuc const ctype<char_type>& __ct) const 22264684ddb6SLionel Sambuc{ 22274684ddb6SLionel Sambuc for (; __b != __e && __ct.is(ctype_base::space, *__b); ++__b) 22284684ddb6SLionel Sambuc ; 22294684ddb6SLionel Sambuc if (__b == __e) 22304684ddb6SLionel Sambuc __err |= ios_base::eofbit; 22314684ddb6SLionel Sambuc} 22324684ddb6SLionel Sambuc 22334684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 22344684ddb6SLionel Sambucvoid 22354684ddb6SLionel Sambuctime_get<_CharT, _InputIterator>::__get_am_pm(int& __h, 22364684ddb6SLionel Sambuc iter_type& __b, iter_type __e, 22374684ddb6SLionel Sambuc ios_base::iostate& __err, 22384684ddb6SLionel Sambuc const ctype<char_type>& __ct) const 22394684ddb6SLionel Sambuc{ 22404684ddb6SLionel Sambuc const string_type* __ap = this->__am_pm(); 22414684ddb6SLionel Sambuc if (__ap[0].size() + __ap[1].size() == 0) 22424684ddb6SLionel Sambuc { 22434684ddb6SLionel Sambuc __err |= ios_base::failbit; 22444684ddb6SLionel Sambuc return; 22454684ddb6SLionel Sambuc } 22464684ddb6SLionel Sambuc ptrdiff_t __i = __scan_keyword(__b, __e, __ap, __ap+2, __ct, __err, false) - __ap; 22474684ddb6SLionel Sambuc if (__i == 0 && __h == 12) 22484684ddb6SLionel Sambuc __h = 0; 22494684ddb6SLionel Sambuc else if (__i == 1 && __h < 12) 22504684ddb6SLionel Sambuc __h += 12; 22514684ddb6SLionel Sambuc} 22524684ddb6SLionel Sambuc 22534684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 22544684ddb6SLionel Sambucvoid 22554684ddb6SLionel Sambuctime_get<_CharT, _InputIterator>::__get_percent(iter_type& __b, iter_type __e, 22564684ddb6SLionel Sambuc ios_base::iostate& __err, 22574684ddb6SLionel Sambuc const ctype<char_type>& __ct) const 22584684ddb6SLionel Sambuc{ 22594684ddb6SLionel Sambuc if (__b == __e) 22604684ddb6SLionel Sambuc { 22614684ddb6SLionel Sambuc __err |= ios_base::eofbit | ios_base::failbit; 22624684ddb6SLionel Sambuc return; 22634684ddb6SLionel Sambuc } 22644684ddb6SLionel Sambuc if (__ct.narrow(*__b, 0) != '%') 22654684ddb6SLionel Sambuc __err |= ios_base::failbit; 22664684ddb6SLionel Sambuc else if(++__b == __e) 22674684ddb6SLionel Sambuc __err |= ios_base::eofbit; 22684684ddb6SLionel Sambuc} 22694684ddb6SLionel Sambuc 2270*0a6a1f1dSLionel Sambuc// time_get end primitives 22714684ddb6SLionel Sambuc 22724684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 22734684ddb6SLionel Sambuc_InputIterator 22744684ddb6SLionel Sambuctime_get<_CharT, _InputIterator>::get(iter_type __b, iter_type __e, 22754684ddb6SLionel Sambuc ios_base& __iob, 22764684ddb6SLionel Sambuc ios_base::iostate& __err, tm* __tm, 22774684ddb6SLionel Sambuc const char_type* __fmtb, const char_type* __fmte) const 22784684ddb6SLionel Sambuc{ 22794684ddb6SLionel Sambuc const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc()); 22804684ddb6SLionel Sambuc __err = ios_base::goodbit; 22814684ddb6SLionel Sambuc while (__fmtb != __fmte && __err == ios_base::goodbit) 22824684ddb6SLionel Sambuc { 22834684ddb6SLionel Sambuc if (__b == __e) 22844684ddb6SLionel Sambuc { 22854684ddb6SLionel Sambuc __err = ios_base::failbit; 22864684ddb6SLionel Sambuc break; 22874684ddb6SLionel Sambuc } 22884684ddb6SLionel Sambuc if (__ct.narrow(*__fmtb, 0) == '%') 22894684ddb6SLionel Sambuc { 22904684ddb6SLionel Sambuc if (++__fmtb == __fmte) 22914684ddb6SLionel Sambuc { 22924684ddb6SLionel Sambuc __err = ios_base::failbit; 22934684ddb6SLionel Sambuc break; 22944684ddb6SLionel Sambuc } 22954684ddb6SLionel Sambuc char __cmd = __ct.narrow(*__fmtb, 0); 22964684ddb6SLionel Sambuc char __opt = '\0'; 22974684ddb6SLionel Sambuc if (__cmd == 'E' || __cmd == '0') 22984684ddb6SLionel Sambuc { 22994684ddb6SLionel Sambuc if (++__fmtb == __fmte) 23004684ddb6SLionel Sambuc { 23014684ddb6SLionel Sambuc __err = ios_base::failbit; 23024684ddb6SLionel Sambuc break; 23034684ddb6SLionel Sambuc } 23044684ddb6SLionel Sambuc __opt = __cmd; 23054684ddb6SLionel Sambuc __cmd = __ct.narrow(*__fmtb, 0); 23064684ddb6SLionel Sambuc } 23074684ddb6SLionel Sambuc __b = do_get(__b, __e, __iob, __err, __tm, __cmd, __opt); 23084684ddb6SLionel Sambuc ++__fmtb; 23094684ddb6SLionel Sambuc } 23104684ddb6SLionel Sambuc else if (__ct.is(ctype_base::space, *__fmtb)) 23114684ddb6SLionel Sambuc { 23124684ddb6SLionel Sambuc for (++__fmtb; __fmtb != __fmte && __ct.is(ctype_base::space, *__fmtb); ++__fmtb) 23134684ddb6SLionel Sambuc ; 23144684ddb6SLionel Sambuc for ( ; __b != __e && __ct.is(ctype_base::space, *__b); ++__b) 23154684ddb6SLionel Sambuc ; 23164684ddb6SLionel Sambuc } 23174684ddb6SLionel Sambuc else if (__ct.toupper(*__b) == __ct.toupper(*__fmtb)) 23184684ddb6SLionel Sambuc { 23194684ddb6SLionel Sambuc ++__b; 23204684ddb6SLionel Sambuc ++__fmtb; 23214684ddb6SLionel Sambuc } 23224684ddb6SLionel Sambuc else 23234684ddb6SLionel Sambuc __err = ios_base::failbit; 23244684ddb6SLionel Sambuc } 23254684ddb6SLionel Sambuc if (__b == __e) 23264684ddb6SLionel Sambuc __err |= ios_base::eofbit; 23274684ddb6SLionel Sambuc return __b; 23284684ddb6SLionel Sambuc} 23294684ddb6SLionel Sambuc 23304684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 23314684ddb6SLionel Sambuctypename time_get<_CharT, _InputIterator>::dateorder 23324684ddb6SLionel Sambuctime_get<_CharT, _InputIterator>::do_date_order() const 23334684ddb6SLionel Sambuc{ 23344684ddb6SLionel Sambuc return mdy; 23354684ddb6SLionel Sambuc} 23364684ddb6SLionel Sambuc 23374684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 23384684ddb6SLionel Sambuc_InputIterator 23394684ddb6SLionel Sambuctime_get<_CharT, _InputIterator>::do_get_time(iter_type __b, iter_type __e, 23404684ddb6SLionel Sambuc ios_base& __iob, 23414684ddb6SLionel Sambuc ios_base::iostate& __err, 23424684ddb6SLionel Sambuc tm* __tm) const 23434684ddb6SLionel Sambuc{ 23444684ddb6SLionel Sambuc const char_type __fmt[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'}; 23454684ddb6SLionel Sambuc return get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0])); 23464684ddb6SLionel Sambuc} 23474684ddb6SLionel Sambuc 23484684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 23494684ddb6SLionel Sambuc_InputIterator 23504684ddb6SLionel Sambuctime_get<_CharT, _InputIterator>::do_get_date(iter_type __b, iter_type __e, 23514684ddb6SLionel Sambuc ios_base& __iob, 23524684ddb6SLionel Sambuc ios_base::iostate& __err, 23534684ddb6SLionel Sambuc tm* __tm) const 23544684ddb6SLionel Sambuc{ 23554684ddb6SLionel Sambuc const string_type& __fmt = this->__x(); 23564684ddb6SLionel Sambuc return get(__b, __e, __iob, __err, __tm, __fmt.data(), __fmt.data() + __fmt.size()); 23574684ddb6SLionel Sambuc} 23584684ddb6SLionel Sambuc 23594684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 23604684ddb6SLionel Sambuc_InputIterator 23614684ddb6SLionel Sambuctime_get<_CharT, _InputIterator>::do_get_weekday(iter_type __b, iter_type __e, 23624684ddb6SLionel Sambuc ios_base& __iob, 23634684ddb6SLionel Sambuc ios_base::iostate& __err, 23644684ddb6SLionel Sambuc tm* __tm) const 23654684ddb6SLionel Sambuc{ 23664684ddb6SLionel Sambuc const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc()); 23674684ddb6SLionel Sambuc __get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct); 23684684ddb6SLionel Sambuc return __b; 23694684ddb6SLionel Sambuc} 23704684ddb6SLionel Sambuc 23714684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 23724684ddb6SLionel Sambuc_InputIterator 23734684ddb6SLionel Sambuctime_get<_CharT, _InputIterator>::do_get_monthname(iter_type __b, iter_type __e, 23744684ddb6SLionel Sambuc ios_base& __iob, 23754684ddb6SLionel Sambuc ios_base::iostate& __err, 23764684ddb6SLionel Sambuc tm* __tm) const 23774684ddb6SLionel Sambuc{ 23784684ddb6SLionel Sambuc const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc()); 23794684ddb6SLionel Sambuc __get_monthname(__tm->tm_mon, __b, __e, __err, __ct); 23804684ddb6SLionel Sambuc return __b; 23814684ddb6SLionel Sambuc} 23824684ddb6SLionel Sambuc 23834684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 23844684ddb6SLionel Sambuc_InputIterator 23854684ddb6SLionel Sambuctime_get<_CharT, _InputIterator>::do_get_year(iter_type __b, iter_type __e, 23864684ddb6SLionel Sambuc ios_base& __iob, 23874684ddb6SLionel Sambuc ios_base::iostate& __err, 23884684ddb6SLionel Sambuc tm* __tm) const 23894684ddb6SLionel Sambuc{ 23904684ddb6SLionel Sambuc const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc()); 23914684ddb6SLionel Sambuc __get_year(__tm->tm_year, __b, __e, __err, __ct); 23924684ddb6SLionel Sambuc return __b; 23934684ddb6SLionel Sambuc} 23944684ddb6SLionel Sambuc 23954684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 23964684ddb6SLionel Sambuc_InputIterator 23974684ddb6SLionel Sambuctime_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, 23984684ddb6SLionel Sambuc ios_base& __iob, 23994684ddb6SLionel Sambuc ios_base::iostate& __err, tm* __tm, 24004684ddb6SLionel Sambuc char __fmt, char) const 24014684ddb6SLionel Sambuc{ 24024684ddb6SLionel Sambuc __err = ios_base::goodbit; 24034684ddb6SLionel Sambuc const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc()); 24044684ddb6SLionel Sambuc switch (__fmt) 24054684ddb6SLionel Sambuc { 24064684ddb6SLionel Sambuc case 'a': 24074684ddb6SLionel Sambuc case 'A': 24084684ddb6SLionel Sambuc __get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct); 24094684ddb6SLionel Sambuc break; 24104684ddb6SLionel Sambuc case 'b': 24114684ddb6SLionel Sambuc case 'B': 24124684ddb6SLionel Sambuc case 'h': 24134684ddb6SLionel Sambuc __get_monthname(__tm->tm_mon, __b, __e, __err, __ct); 24144684ddb6SLionel Sambuc break; 24154684ddb6SLionel Sambuc case 'c': 24164684ddb6SLionel Sambuc { 24174684ddb6SLionel Sambuc const string_type& __fm = this->__c(); 24184684ddb6SLionel Sambuc __b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size()); 24194684ddb6SLionel Sambuc } 24204684ddb6SLionel Sambuc break; 24214684ddb6SLionel Sambuc case 'd': 24224684ddb6SLionel Sambuc case 'e': 24234684ddb6SLionel Sambuc __get_day(__tm->tm_mday, __b, __e, __err, __ct); 24244684ddb6SLionel Sambuc break; 24254684ddb6SLionel Sambuc case 'D': 24264684ddb6SLionel Sambuc { 24274684ddb6SLionel Sambuc const char_type __fm[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'}; 24284684ddb6SLionel Sambuc __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0])); 24294684ddb6SLionel Sambuc } 24304684ddb6SLionel Sambuc break; 24314684ddb6SLionel Sambuc case 'F': 24324684ddb6SLionel Sambuc { 24334684ddb6SLionel Sambuc const char_type __fm[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd'}; 24344684ddb6SLionel Sambuc __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0])); 24354684ddb6SLionel Sambuc } 24364684ddb6SLionel Sambuc break; 24374684ddb6SLionel Sambuc case 'H': 24384684ddb6SLionel Sambuc __get_hour(__tm->tm_hour, __b, __e, __err, __ct); 24394684ddb6SLionel Sambuc break; 24404684ddb6SLionel Sambuc case 'I': 24414684ddb6SLionel Sambuc __get_12_hour(__tm->tm_hour, __b, __e, __err, __ct); 24424684ddb6SLionel Sambuc break; 24434684ddb6SLionel Sambuc case 'j': 24444684ddb6SLionel Sambuc __get_day_year_num(__tm->tm_yday, __b, __e, __err, __ct); 24454684ddb6SLionel Sambuc break; 24464684ddb6SLionel Sambuc case 'm': 24474684ddb6SLionel Sambuc __get_month(__tm->tm_mon, __b, __e, __err, __ct); 24484684ddb6SLionel Sambuc break; 24494684ddb6SLionel Sambuc case 'M': 24504684ddb6SLionel Sambuc __get_minute(__tm->tm_min, __b, __e, __err, __ct); 24514684ddb6SLionel Sambuc break; 24524684ddb6SLionel Sambuc case 'n': 24534684ddb6SLionel Sambuc case 't': 24544684ddb6SLionel Sambuc __get_white_space(__b, __e, __err, __ct); 24554684ddb6SLionel Sambuc break; 24564684ddb6SLionel Sambuc case 'p': 24574684ddb6SLionel Sambuc __get_am_pm(__tm->tm_hour, __b, __e, __err, __ct); 24584684ddb6SLionel Sambuc break; 24594684ddb6SLionel Sambuc case 'r': 24604684ddb6SLionel Sambuc { 24614684ddb6SLionel Sambuc const char_type __fm[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'}; 24624684ddb6SLionel Sambuc __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0])); 24634684ddb6SLionel Sambuc } 24644684ddb6SLionel Sambuc break; 24654684ddb6SLionel Sambuc case 'R': 24664684ddb6SLionel Sambuc { 24674684ddb6SLionel Sambuc const char_type __fm[] = {'%', 'H', ':', '%', 'M'}; 24684684ddb6SLionel Sambuc __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0])); 24694684ddb6SLionel Sambuc } 24704684ddb6SLionel Sambuc break; 24714684ddb6SLionel Sambuc case 'S': 24724684ddb6SLionel Sambuc __get_second(__tm->tm_sec, __b, __e, __err, __ct); 24734684ddb6SLionel Sambuc break; 24744684ddb6SLionel Sambuc case 'T': 24754684ddb6SLionel Sambuc { 24764684ddb6SLionel Sambuc const char_type __fm[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'}; 24774684ddb6SLionel Sambuc __b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0])); 24784684ddb6SLionel Sambuc } 24794684ddb6SLionel Sambuc break; 24804684ddb6SLionel Sambuc case 'w': 24814684ddb6SLionel Sambuc __get_weekday(__tm->tm_wday, __b, __e, __err, __ct); 24824684ddb6SLionel Sambuc break; 24834684ddb6SLionel Sambuc case 'x': 24844684ddb6SLionel Sambuc return do_get_date(__b, __e, __iob, __err, __tm); 24854684ddb6SLionel Sambuc case 'X': 24864684ddb6SLionel Sambuc { 24874684ddb6SLionel Sambuc const string_type& __fm = this->__X(); 24884684ddb6SLionel Sambuc __b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size()); 24894684ddb6SLionel Sambuc } 24904684ddb6SLionel Sambuc break; 24914684ddb6SLionel Sambuc case 'y': 24924684ddb6SLionel Sambuc __get_year(__tm->tm_year, __b, __e, __err, __ct); 24934684ddb6SLionel Sambuc break; 24944684ddb6SLionel Sambuc case 'Y': 24954684ddb6SLionel Sambuc __get_year4(__tm->tm_year, __b, __e, __err, __ct); 24964684ddb6SLionel Sambuc break; 24974684ddb6SLionel Sambuc case '%': 24984684ddb6SLionel Sambuc __get_percent(__b, __e, __err, __ct); 24994684ddb6SLionel Sambuc break; 25004684ddb6SLionel Sambuc default: 25014684ddb6SLionel Sambuc __err |= ios_base::failbit; 25024684ddb6SLionel Sambuc } 25034684ddb6SLionel Sambuc return __b; 25044684ddb6SLionel Sambuc} 25054684ddb6SLionel Sambuc 25064684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS time_get<char>) 25074684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS time_get<wchar_t>) 25084684ddb6SLionel Sambuc 25094684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS __time_get 25104684ddb6SLionel Sambuc{ 25114684ddb6SLionel Sambucprotected: 25124684ddb6SLionel Sambuc locale_t __loc_; 25134684ddb6SLionel Sambuc 25144684ddb6SLionel Sambuc __time_get(const char* __nm); 25154684ddb6SLionel Sambuc __time_get(const string& __nm); 25164684ddb6SLionel Sambuc ~__time_get(); 25174684ddb6SLionel Sambuc}; 25184684ddb6SLionel Sambuc 25194684ddb6SLionel Sambuctemplate <class _CharT> 2520*0a6a1f1dSLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY __time_get_storage 25214684ddb6SLionel Sambuc : public __time_get 25224684ddb6SLionel Sambuc{ 25234684ddb6SLionel Sambucprotected: 25244684ddb6SLionel Sambuc typedef basic_string<_CharT> string_type; 25254684ddb6SLionel Sambuc 25264684ddb6SLionel Sambuc string_type __weeks_[14]; 25274684ddb6SLionel Sambuc string_type __months_[24]; 25284684ddb6SLionel Sambuc string_type __am_pm_[2]; 25294684ddb6SLionel Sambuc string_type __c_; 25304684ddb6SLionel Sambuc string_type __r_; 25314684ddb6SLionel Sambuc string_type __x_; 25324684ddb6SLionel Sambuc string_type __X_; 25334684ddb6SLionel Sambuc 25344684ddb6SLionel Sambuc explicit __time_get_storage(const char* __nm); 25354684ddb6SLionel Sambuc explicit __time_get_storage(const string& __nm); 25364684ddb6SLionel Sambuc 25374684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE ~__time_get_storage() {} 25384684ddb6SLionel Sambuc 25394684ddb6SLionel Sambuc time_base::dateorder __do_date_order() const; 25404684ddb6SLionel Sambuc 25414684ddb6SLionel Sambucprivate: 25424684ddb6SLionel Sambuc void init(const ctype<_CharT>&); 25434684ddb6SLionel Sambuc string_type __analyze(char __fmt, const ctype<_CharT>&); 25444684ddb6SLionel Sambuc}; 25454684ddb6SLionel Sambuc 25464684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> > 25474684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY time_get_byname 25484684ddb6SLionel Sambuc : public time_get<_CharT, _InputIterator>, 25494684ddb6SLionel Sambuc private __time_get_storage<_CharT> 25504684ddb6SLionel Sambuc{ 25514684ddb6SLionel Sambucpublic: 25524684ddb6SLionel Sambuc typedef time_base::dateorder dateorder; 25534684ddb6SLionel Sambuc typedef _InputIterator iter_type; 25544684ddb6SLionel Sambuc typedef _CharT char_type; 25554684ddb6SLionel Sambuc typedef basic_string<char_type> string_type; 25564684ddb6SLionel Sambuc 25574684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25584684ddb6SLionel Sambuc explicit time_get_byname(const char* __nm, size_t __refs = 0) 25594684ddb6SLionel Sambuc : time_get<_CharT, _InputIterator>(__refs), 25604684ddb6SLionel Sambuc __time_get_storage<_CharT>(__nm) {} 25614684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25624684ddb6SLionel Sambuc explicit time_get_byname(const string& __nm, size_t __refs = 0) 25634684ddb6SLionel Sambuc : time_get<_CharT, _InputIterator>(__refs), 25644684ddb6SLionel Sambuc __time_get_storage<_CharT>(__nm) {} 25654684ddb6SLionel Sambuc 25664684ddb6SLionel Sambucprotected: 25674684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25684684ddb6SLionel Sambuc ~time_get_byname() {} 25694684ddb6SLionel Sambuc 25704684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25714684ddb6SLionel Sambuc virtual dateorder do_date_order() const {return this->__do_date_order();} 25724684ddb6SLionel Sambucprivate: 25734684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25744684ddb6SLionel Sambuc virtual const string_type* __weeks() const {return this->__weeks_;} 25754684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25764684ddb6SLionel Sambuc virtual const string_type* __months() const {return this->__months_;} 25774684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25784684ddb6SLionel Sambuc virtual const string_type* __am_pm() const {return this->__am_pm_;} 25794684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25804684ddb6SLionel Sambuc virtual const string_type& __c() const {return this->__c_;} 25814684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25824684ddb6SLionel Sambuc virtual const string_type& __r() const {return this->__r_;} 25834684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25844684ddb6SLionel Sambuc virtual const string_type& __x() const {return this->__x_;} 25854684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 25864684ddb6SLionel Sambuc virtual const string_type& __X() const {return this->__X_;} 25874684ddb6SLionel Sambuc}; 25884684ddb6SLionel Sambuc 25894684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS time_get_byname<char>) 25904684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS time_get_byname<wchar_t>) 25914684ddb6SLionel Sambuc 25924684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS __time_put 25934684ddb6SLionel Sambuc{ 25944684ddb6SLionel Sambuc locale_t __loc_; 25954684ddb6SLionel Sambucprotected: 25964684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE __time_put() : __loc_(_LIBCPP_GET_C_LOCALE) {} 25974684ddb6SLionel Sambuc __time_put(const char* __nm); 25984684ddb6SLionel Sambuc __time_put(const string& __nm); 25994684ddb6SLionel Sambuc ~__time_put(); 26004684ddb6SLionel Sambuc void __do_put(char* __nb, char*& __ne, const tm* __tm, 26014684ddb6SLionel Sambuc char __fmt, char __mod) const; 26024684ddb6SLionel Sambuc void __do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm, 26034684ddb6SLionel Sambuc char __fmt, char __mod) const; 26044684ddb6SLionel Sambuc}; 26054684ddb6SLionel Sambuc 26064684ddb6SLionel Sambuctemplate <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> > 26074684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY time_put 26084684ddb6SLionel Sambuc : public locale::facet, 26094684ddb6SLionel Sambuc private __time_put 26104684ddb6SLionel Sambuc{ 26114684ddb6SLionel Sambucpublic: 26124684ddb6SLionel Sambuc typedef _CharT char_type; 26134684ddb6SLionel Sambuc typedef _OutputIterator iter_type; 26144684ddb6SLionel Sambuc 26154684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 26164684ddb6SLionel Sambuc explicit time_put(size_t __refs = 0) 26174684ddb6SLionel Sambuc : locale::facet(__refs) {} 26184684ddb6SLionel Sambuc 26194684ddb6SLionel Sambuc iter_type put(iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm, 26204684ddb6SLionel Sambuc const char_type* __pb, const char_type* __pe) const; 26214684ddb6SLionel Sambuc 26224684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 26234684ddb6SLionel Sambuc iter_type put(iter_type __s, ios_base& __iob, char_type __fl, 26244684ddb6SLionel Sambuc const tm* __tm, char __fmt, char __mod = 0) const 26254684ddb6SLionel Sambuc { 26264684ddb6SLionel Sambuc return do_put(__s, __iob, __fl, __tm, __fmt, __mod); 26274684ddb6SLionel Sambuc } 26284684ddb6SLionel Sambuc 26294684ddb6SLionel Sambuc static locale::id id; 26304684ddb6SLionel Sambuc 26314684ddb6SLionel Sambucprotected: 26324684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 26334684ddb6SLionel Sambuc ~time_put() {} 26344684ddb6SLionel Sambuc virtual iter_type do_put(iter_type __s, ios_base&, char_type, const tm* __tm, 26354684ddb6SLionel Sambuc char __fmt, char __mod) const; 26364684ddb6SLionel Sambuc 26374684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 26384684ddb6SLionel Sambuc explicit time_put(const char* __nm, size_t __refs) 26394684ddb6SLionel Sambuc : locale::facet(__refs), 26404684ddb6SLionel Sambuc __time_put(__nm) {} 26414684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 26424684ddb6SLionel Sambuc explicit time_put(const string& __nm, size_t __refs) 26434684ddb6SLionel Sambuc : locale::facet(__refs), 26444684ddb6SLionel Sambuc __time_put(__nm) {} 26454684ddb6SLionel Sambuc}; 26464684ddb6SLionel Sambuc 26474684ddb6SLionel Sambuctemplate <class _CharT, class _OutputIterator> 26484684ddb6SLionel Sambuclocale::id 26494684ddb6SLionel Sambuctime_put<_CharT, _OutputIterator>::id; 26504684ddb6SLionel Sambuc 26514684ddb6SLionel Sambuctemplate <class _CharT, class _OutputIterator> 26524684ddb6SLionel Sambuc_OutputIterator 26534684ddb6SLionel Sambuctime_put<_CharT, _OutputIterator>::put(iter_type __s, ios_base& __iob, 26544684ddb6SLionel Sambuc char_type __fl, const tm* __tm, 26554684ddb6SLionel Sambuc const char_type* __pb, 26564684ddb6SLionel Sambuc const char_type* __pe) const 26574684ddb6SLionel Sambuc{ 26584684ddb6SLionel Sambuc const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc()); 26594684ddb6SLionel Sambuc for (; __pb != __pe; ++__pb) 26604684ddb6SLionel Sambuc { 26614684ddb6SLionel Sambuc if (__ct.narrow(*__pb, 0) == '%') 26624684ddb6SLionel Sambuc { 26634684ddb6SLionel Sambuc if (++__pb == __pe) 26644684ddb6SLionel Sambuc { 26654684ddb6SLionel Sambuc *__s++ = __pb[-1]; 26664684ddb6SLionel Sambuc break; 26674684ddb6SLionel Sambuc } 26684684ddb6SLionel Sambuc char __mod = 0; 26694684ddb6SLionel Sambuc char __fmt = __ct.narrow(*__pb, 0); 26704684ddb6SLionel Sambuc if (__fmt == 'E' || __fmt == 'O') 26714684ddb6SLionel Sambuc { 26724684ddb6SLionel Sambuc if (++__pb == __pe) 26734684ddb6SLionel Sambuc { 26744684ddb6SLionel Sambuc *__s++ = __pb[-2]; 26754684ddb6SLionel Sambuc *__s++ = __pb[-1]; 26764684ddb6SLionel Sambuc break; 26774684ddb6SLionel Sambuc } 26784684ddb6SLionel Sambuc __mod = __fmt; 26794684ddb6SLionel Sambuc __fmt = __ct.narrow(*__pb, 0); 26804684ddb6SLionel Sambuc } 26814684ddb6SLionel Sambuc __s = do_put(__s, __iob, __fl, __tm, __fmt, __mod); 26824684ddb6SLionel Sambuc } 26834684ddb6SLionel Sambuc else 26844684ddb6SLionel Sambuc *__s++ = *__pb; 26854684ddb6SLionel Sambuc } 26864684ddb6SLionel Sambuc return __s; 26874684ddb6SLionel Sambuc} 26884684ddb6SLionel Sambuc 26894684ddb6SLionel Sambuctemplate <class _CharT, class _OutputIterator> 26904684ddb6SLionel Sambuc_OutputIterator 26914684ddb6SLionel Sambuctime_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base&, 26924684ddb6SLionel Sambuc char_type, const tm* __tm, 26934684ddb6SLionel Sambuc char __fmt, char __mod) const 26944684ddb6SLionel Sambuc{ 26954684ddb6SLionel Sambuc char_type __nar[100]; 26964684ddb6SLionel Sambuc char_type* __nb = __nar; 26974684ddb6SLionel Sambuc char_type* __ne = __nb + 100; 26984684ddb6SLionel Sambuc __do_put(__nb, __ne, __tm, __fmt, __mod); 26994684ddb6SLionel Sambuc return _VSTD::copy(__nb, __ne, __s); 27004684ddb6SLionel Sambuc} 27014684ddb6SLionel Sambuc 27024684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS time_put<char>) 27034684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS time_put<wchar_t>) 27044684ddb6SLionel Sambuc 27054684ddb6SLionel Sambuctemplate <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> > 27064684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY time_put_byname 27074684ddb6SLionel Sambuc : public time_put<_CharT, _OutputIterator> 27084684ddb6SLionel Sambuc{ 27094684ddb6SLionel Sambucpublic: 27104684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 27114684ddb6SLionel Sambuc explicit time_put_byname(const char* __nm, size_t __refs = 0) 27124684ddb6SLionel Sambuc : time_put<_CharT, _OutputIterator>(__nm, __refs) {} 27134684ddb6SLionel Sambuc 27144684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 27154684ddb6SLionel Sambuc explicit time_put_byname(const string& __nm, size_t __refs = 0) 27164684ddb6SLionel Sambuc : time_put<_CharT, _OutputIterator>(__nm, __refs) {} 27174684ddb6SLionel Sambuc 27184684ddb6SLionel Sambucprotected: 27194684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 27204684ddb6SLionel Sambuc ~time_put_byname() {} 27214684ddb6SLionel Sambuc}; 27224684ddb6SLionel Sambuc 27234684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS time_put_byname<char>) 27244684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS time_put_byname<wchar_t>) 27254684ddb6SLionel Sambuc 27264684ddb6SLionel Sambuc// money_base 27274684ddb6SLionel Sambuc 27284684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS money_base 27294684ddb6SLionel Sambuc{ 27304684ddb6SLionel Sambucpublic: 27314684ddb6SLionel Sambuc enum part {none, space, symbol, sign, value}; 27324684ddb6SLionel Sambuc struct pattern {char field[4];}; 27334684ddb6SLionel Sambuc 27344684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE money_base() {} 27354684ddb6SLionel Sambuc}; 27364684ddb6SLionel Sambuc 27374684ddb6SLionel Sambuc// moneypunct 27384684ddb6SLionel Sambuc 27394684ddb6SLionel Sambuctemplate <class _CharT, bool _International = false> 27404684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY moneypunct 27414684ddb6SLionel Sambuc : public locale::facet, 27424684ddb6SLionel Sambuc public money_base 27434684ddb6SLionel Sambuc{ 27444684ddb6SLionel Sambucpublic: 27454684ddb6SLionel Sambuc typedef _CharT char_type; 27464684ddb6SLionel Sambuc typedef basic_string<char_type> string_type; 27474684ddb6SLionel Sambuc 27484684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 27494684ddb6SLionel Sambuc explicit moneypunct(size_t __refs = 0) 27504684ddb6SLionel Sambuc : locale::facet(__refs) {} 27514684ddb6SLionel Sambuc 27524684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();} 27534684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();} 27544684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE string grouping() const {return do_grouping();} 27554684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE string_type curr_symbol() const {return do_curr_symbol();} 27564684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE string_type positive_sign() const {return do_positive_sign();} 27574684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE string_type negative_sign() const {return do_negative_sign();} 27584684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE int frac_digits() const {return do_frac_digits();} 27594684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE pattern pos_format() const {return do_pos_format();} 27604684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE pattern neg_format() const {return do_neg_format();} 27614684ddb6SLionel Sambuc 27624684ddb6SLionel Sambuc static locale::id id; 27634684ddb6SLionel Sambuc static const bool intl = _International; 27644684ddb6SLionel Sambuc 27654684ddb6SLionel Sambucprotected: 27664684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 27674684ddb6SLionel Sambuc ~moneypunct() {} 27684684ddb6SLionel Sambuc 27694684ddb6SLionel Sambuc virtual char_type do_decimal_point() const {return numeric_limits<char_type>::max();} 27704684ddb6SLionel Sambuc virtual char_type do_thousands_sep() const {return numeric_limits<char_type>::max();} 27714684ddb6SLionel Sambuc virtual string do_grouping() const {return string();} 27724684ddb6SLionel Sambuc virtual string_type do_curr_symbol() const {return string_type();} 27734684ddb6SLionel Sambuc virtual string_type do_positive_sign() const {return string_type();} 27744684ddb6SLionel Sambuc virtual string_type do_negative_sign() const {return string_type(1, '-');} 27754684ddb6SLionel Sambuc virtual int do_frac_digits() const {return 0;} 27764684ddb6SLionel Sambuc virtual pattern do_pos_format() const 27774684ddb6SLionel Sambuc {pattern __p = {{symbol, sign, none, value}}; return __p;} 27784684ddb6SLionel Sambuc virtual pattern do_neg_format() const 27794684ddb6SLionel Sambuc {pattern __p = {{symbol, sign, none, value}}; return __p;} 27804684ddb6SLionel Sambuc}; 27814684ddb6SLionel Sambuc 27824684ddb6SLionel Sambuctemplate <class _CharT, bool _International> 27834684ddb6SLionel Sambuclocale::id 27844684ddb6SLionel Sambucmoneypunct<_CharT, _International>::id; 27854684ddb6SLionel Sambuc 27864684ddb6SLionel Sambuctemplate <class _CharT, bool _International> 27874684ddb6SLionel Sambucconst bool 27884684ddb6SLionel Sambucmoneypunct<_CharT, _International>::intl; 27894684ddb6SLionel Sambuc 27904684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS moneypunct<char, false>) 27914684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS moneypunct<char, true>) 27924684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS moneypunct<wchar_t, false>) 27934684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS moneypunct<wchar_t, true>) 27944684ddb6SLionel Sambuc 27954684ddb6SLionel Sambuc// moneypunct_byname 27964684ddb6SLionel Sambuc 27974684ddb6SLionel Sambuctemplate <class _CharT, bool _International = false> 27984684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY moneypunct_byname 27994684ddb6SLionel Sambuc : public moneypunct<_CharT, _International> 28004684ddb6SLionel Sambuc{ 28014684ddb6SLionel Sambucpublic: 28024684ddb6SLionel Sambuc typedef money_base::pattern pattern; 28034684ddb6SLionel Sambuc typedef _CharT char_type; 28044684ddb6SLionel Sambuc typedef basic_string<char_type> string_type; 28054684ddb6SLionel Sambuc 28064684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 28074684ddb6SLionel Sambuc explicit moneypunct_byname(const char* __nm, size_t __refs = 0) 28084684ddb6SLionel Sambuc : moneypunct<_CharT, _International>(__refs) {init(__nm);} 28094684ddb6SLionel Sambuc 28104684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 28114684ddb6SLionel Sambuc explicit moneypunct_byname(const string& __nm, size_t __refs = 0) 28124684ddb6SLionel Sambuc : moneypunct<_CharT, _International>(__refs) {init(__nm.c_str());} 28134684ddb6SLionel Sambuc 28144684ddb6SLionel Sambucprotected: 28154684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 28164684ddb6SLionel Sambuc ~moneypunct_byname() {} 28174684ddb6SLionel Sambuc 28184684ddb6SLionel Sambuc virtual char_type do_decimal_point() const {return __decimal_point_;} 28194684ddb6SLionel Sambuc virtual char_type do_thousands_sep() const {return __thousands_sep_;} 28204684ddb6SLionel Sambuc virtual string do_grouping() const {return __grouping_;} 28214684ddb6SLionel Sambuc virtual string_type do_curr_symbol() const {return __curr_symbol_;} 28224684ddb6SLionel Sambuc virtual string_type do_positive_sign() const {return __positive_sign_;} 28234684ddb6SLionel Sambuc virtual string_type do_negative_sign() const {return __negative_sign_;} 28244684ddb6SLionel Sambuc virtual int do_frac_digits() const {return __frac_digits_;} 28254684ddb6SLionel Sambuc virtual pattern do_pos_format() const {return __pos_format_;} 28264684ddb6SLionel Sambuc virtual pattern do_neg_format() const {return __neg_format_;} 28274684ddb6SLionel Sambuc 28284684ddb6SLionel Sambucprivate: 28294684ddb6SLionel Sambuc char_type __decimal_point_; 28304684ddb6SLionel Sambuc char_type __thousands_sep_; 28314684ddb6SLionel Sambuc string __grouping_; 28324684ddb6SLionel Sambuc string_type __curr_symbol_; 28334684ddb6SLionel Sambuc string_type __positive_sign_; 28344684ddb6SLionel Sambuc string_type __negative_sign_; 28354684ddb6SLionel Sambuc int __frac_digits_; 28364684ddb6SLionel Sambuc pattern __pos_format_; 28374684ddb6SLionel Sambuc pattern __neg_format_; 28384684ddb6SLionel Sambuc 28394684ddb6SLionel Sambuc void init(const char*); 28404684ddb6SLionel Sambuc}; 28414684ddb6SLionel Sambuc 28424684ddb6SLionel Sambuctemplate<> void moneypunct_byname<char, false>::init(const char*); 28434684ddb6SLionel Sambuctemplate<> void moneypunct_byname<char, true>::init(const char*); 28444684ddb6SLionel Sambuctemplate<> void moneypunct_byname<wchar_t, false>::init(const char*); 28454684ddb6SLionel Sambuctemplate<> void moneypunct_byname<wchar_t, true>::init(const char*); 28464684ddb6SLionel Sambuc 28474684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS moneypunct_byname<char, false>) 28484684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS moneypunct_byname<char, true>) 28494684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS moneypunct_byname<wchar_t, false>) 28504684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS moneypunct_byname<wchar_t, true>) 28514684ddb6SLionel Sambuc 28524684ddb6SLionel Sambuc// money_get 28534684ddb6SLionel Sambuc 28544684ddb6SLionel Sambuctemplate <class _CharT> 28554684ddb6SLionel Sambucclass __money_get 28564684ddb6SLionel Sambuc{ 28574684ddb6SLionel Sambucprotected: 28584684ddb6SLionel Sambuc typedef _CharT char_type; 28594684ddb6SLionel Sambuc typedef basic_string<char_type> string_type; 28604684ddb6SLionel Sambuc 28614684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE __money_get() {} 28624684ddb6SLionel Sambuc 28634684ddb6SLionel Sambuc static void __gather_info(bool __intl, const locale& __loc, 28644684ddb6SLionel Sambuc money_base::pattern& __pat, char_type& __dp, 28654684ddb6SLionel Sambuc char_type& __ts, string& __grp, 28664684ddb6SLionel Sambuc string_type& __sym, string_type& __psn, 28674684ddb6SLionel Sambuc string_type& __nsn, int& __fd); 28684684ddb6SLionel Sambuc}; 28694684ddb6SLionel Sambuc 28704684ddb6SLionel Sambuctemplate <class _CharT> 28714684ddb6SLionel Sambucvoid 28724684ddb6SLionel Sambuc__money_get<_CharT>::__gather_info(bool __intl, const locale& __loc, 28734684ddb6SLionel Sambuc money_base::pattern& __pat, char_type& __dp, 28744684ddb6SLionel Sambuc char_type& __ts, string& __grp, 28754684ddb6SLionel Sambuc string_type& __sym, string_type& __psn, 28764684ddb6SLionel Sambuc string_type& __nsn, int& __fd) 28774684ddb6SLionel Sambuc{ 28784684ddb6SLionel Sambuc if (__intl) 28794684ddb6SLionel Sambuc { 28804684ddb6SLionel Sambuc const moneypunct<char_type, true>& __mp = 28814684ddb6SLionel Sambuc use_facet<moneypunct<char_type, true> >(__loc); 28824684ddb6SLionel Sambuc __pat = __mp.neg_format(); 28834684ddb6SLionel Sambuc __nsn = __mp.negative_sign(); 28844684ddb6SLionel Sambuc __psn = __mp.positive_sign(); 28854684ddb6SLionel Sambuc __dp = __mp.decimal_point(); 28864684ddb6SLionel Sambuc __ts = __mp.thousands_sep(); 28874684ddb6SLionel Sambuc __grp = __mp.grouping(); 28884684ddb6SLionel Sambuc __sym = __mp.curr_symbol(); 28894684ddb6SLionel Sambuc __fd = __mp.frac_digits(); 28904684ddb6SLionel Sambuc } 28914684ddb6SLionel Sambuc else 28924684ddb6SLionel Sambuc { 28934684ddb6SLionel Sambuc const moneypunct<char_type, false>& __mp = 28944684ddb6SLionel Sambuc use_facet<moneypunct<char_type, false> >(__loc); 28954684ddb6SLionel Sambuc __pat = __mp.neg_format(); 28964684ddb6SLionel Sambuc __nsn = __mp.negative_sign(); 28974684ddb6SLionel Sambuc __psn = __mp.positive_sign(); 28984684ddb6SLionel Sambuc __dp = __mp.decimal_point(); 28994684ddb6SLionel Sambuc __ts = __mp.thousands_sep(); 29004684ddb6SLionel Sambuc __grp = __mp.grouping(); 29014684ddb6SLionel Sambuc __sym = __mp.curr_symbol(); 29024684ddb6SLionel Sambuc __fd = __mp.frac_digits(); 29034684ddb6SLionel Sambuc } 29044684ddb6SLionel Sambuc} 29054684ddb6SLionel Sambuc 29064684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS __money_get<char>) 29074684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS __money_get<wchar_t>) 29084684ddb6SLionel Sambuc 29094684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> > 29104684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY money_get 29114684ddb6SLionel Sambuc : public locale::facet, 29124684ddb6SLionel Sambuc private __money_get<_CharT> 29134684ddb6SLionel Sambuc{ 29144684ddb6SLionel Sambucpublic: 29154684ddb6SLionel Sambuc typedef _CharT char_type; 29164684ddb6SLionel Sambuc typedef _InputIterator iter_type; 29174684ddb6SLionel Sambuc typedef basic_string<char_type> string_type; 29184684ddb6SLionel Sambuc 29194684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 29204684ddb6SLionel Sambuc explicit money_get(size_t __refs = 0) 29214684ddb6SLionel Sambuc : locale::facet(__refs) {} 29224684ddb6SLionel Sambuc 29234684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 29244684ddb6SLionel Sambuc iter_type get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, 29254684ddb6SLionel Sambuc ios_base::iostate& __err, long double& __v) const 29264684ddb6SLionel Sambuc { 29274684ddb6SLionel Sambuc return do_get(__b, __e, __intl, __iob, __err, __v); 29284684ddb6SLionel Sambuc } 29294684ddb6SLionel Sambuc 29304684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 29314684ddb6SLionel Sambuc iter_type get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob, 29324684ddb6SLionel Sambuc ios_base::iostate& __err, string_type& __v) const 29334684ddb6SLionel Sambuc { 29344684ddb6SLionel Sambuc return do_get(__b, __e, __intl, __iob, __err, __v); 29354684ddb6SLionel Sambuc } 29364684ddb6SLionel Sambuc 29374684ddb6SLionel Sambuc static locale::id id; 29384684ddb6SLionel Sambuc 29394684ddb6SLionel Sambucprotected: 29404684ddb6SLionel Sambuc 29414684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 29424684ddb6SLionel Sambuc ~money_get() {} 29434684ddb6SLionel Sambuc 29444684ddb6SLionel Sambuc virtual iter_type do_get(iter_type __b, iter_type __e, bool __intl, 29454684ddb6SLionel Sambuc ios_base& __iob, ios_base::iostate& __err, 29464684ddb6SLionel Sambuc long double& __v) const; 29474684ddb6SLionel Sambuc virtual iter_type do_get(iter_type __b, iter_type __e, bool __intl, 29484684ddb6SLionel Sambuc ios_base& __iob, ios_base::iostate& __err, 29494684ddb6SLionel Sambuc string_type& __v) const; 29504684ddb6SLionel Sambuc 29514684ddb6SLionel Sambucprivate: 29524684ddb6SLionel Sambuc static bool __do_get(iter_type& __b, iter_type __e, 29534684ddb6SLionel Sambuc bool __intl, const locale& __loc, 29544684ddb6SLionel Sambuc ios_base::fmtflags __flags, ios_base::iostate& __err, 29554684ddb6SLionel Sambuc bool& __neg, const ctype<char_type>& __ct, 29564684ddb6SLionel Sambuc unique_ptr<char_type, void(*)(void*)>& __wb, 29574684ddb6SLionel Sambuc char_type*& __wn, char_type* __we); 29584684ddb6SLionel Sambuc}; 29594684ddb6SLionel Sambuc 29604684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 29614684ddb6SLionel Sambuclocale::id 29624684ddb6SLionel Sambucmoney_get<_CharT, _InputIterator>::id; 29634684ddb6SLionel Sambuc 29644684ddb6SLionel Sambuc_LIBCPP_FUNC_VIS void __do_nothing(void*); 29654684ddb6SLionel Sambuc 29664684ddb6SLionel Sambuctemplate <class _Tp> 29674684ddb6SLionel Sambuc_LIBCPP_HIDDEN 29684684ddb6SLionel Sambucvoid 29694684ddb6SLionel Sambuc__double_or_nothing(unique_ptr<_Tp, void(*)(void*)>& __b, _Tp*& __n, _Tp*& __e) 29704684ddb6SLionel Sambuc{ 29714684ddb6SLionel Sambuc bool __owns = __b.get_deleter() != __do_nothing; 29724684ddb6SLionel Sambuc size_t __cur_cap = static_cast<size_t>(__e-__b.get()) * sizeof(_Tp); 29734684ddb6SLionel Sambuc size_t __new_cap = __cur_cap < numeric_limits<size_t>::max() / 2 ? 29744684ddb6SLionel Sambuc 2 * __cur_cap : numeric_limits<size_t>::max(); 2975*0a6a1f1dSLionel Sambuc if (__new_cap == 0) 2976*0a6a1f1dSLionel Sambuc __new_cap = sizeof(_Tp); 29774684ddb6SLionel Sambuc size_t __n_off = static_cast<size_t>(__n - __b.get()); 29784684ddb6SLionel Sambuc _Tp* __t = (_Tp*)realloc(__owns ? __b.get() : 0, __new_cap); 29794684ddb6SLionel Sambuc if (__t == 0) 29804684ddb6SLionel Sambuc __throw_bad_alloc(); 29814684ddb6SLionel Sambuc if (__owns) 29824684ddb6SLionel Sambuc __b.release(); 29834684ddb6SLionel Sambuc __b = unique_ptr<_Tp, void(*)(void*)>(__t, free); 29844684ddb6SLionel Sambuc __new_cap /= sizeof(_Tp); 29854684ddb6SLionel Sambuc __n = __b.get() + __n_off; 29864684ddb6SLionel Sambuc __e = __b.get() + __new_cap; 29874684ddb6SLionel Sambuc} 29884684ddb6SLionel Sambuc 29894684ddb6SLionel Sambuc// true == success 29904684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 29914684ddb6SLionel Sambucbool 29924684ddb6SLionel Sambucmoney_get<_CharT, _InputIterator>::__do_get(iter_type& __b, iter_type __e, 29934684ddb6SLionel Sambuc bool __intl, const locale& __loc, 29944684ddb6SLionel Sambuc ios_base::fmtflags __flags, 29954684ddb6SLionel Sambuc ios_base::iostate& __err, 29964684ddb6SLionel Sambuc bool& __neg, 29974684ddb6SLionel Sambuc const ctype<char_type>& __ct, 29984684ddb6SLionel Sambuc unique_ptr<char_type, void(*)(void*)>& __wb, 29994684ddb6SLionel Sambuc char_type*& __wn, char_type* __we) 30004684ddb6SLionel Sambuc{ 30014684ddb6SLionel Sambuc const unsigned __bz = 100; 30024684ddb6SLionel Sambuc unsigned __gbuf[__bz]; 30034684ddb6SLionel Sambuc unique_ptr<unsigned, void(*)(void*)> __gb(__gbuf, __do_nothing); 30044684ddb6SLionel Sambuc unsigned* __gn = __gb.get(); 30054684ddb6SLionel Sambuc unsigned* __ge = __gn + __bz; 30064684ddb6SLionel Sambuc money_base::pattern __pat; 30074684ddb6SLionel Sambuc char_type __dp; 30084684ddb6SLionel Sambuc char_type __ts; 30094684ddb6SLionel Sambuc string __grp; 30104684ddb6SLionel Sambuc string_type __sym; 30114684ddb6SLionel Sambuc string_type __psn; 30124684ddb6SLionel Sambuc string_type __nsn; 30134684ddb6SLionel Sambuc // Capture the spaces read into money_base::{space,none} so they 30144684ddb6SLionel Sambuc // can be compared to initial spaces in __sym. 30154684ddb6SLionel Sambuc string_type __spaces; 30164684ddb6SLionel Sambuc int __fd; 30174684ddb6SLionel Sambuc __money_get<_CharT>::__gather_info(__intl, __loc, __pat, __dp, __ts, __grp, 30184684ddb6SLionel Sambuc __sym, __psn, __nsn, __fd); 30194684ddb6SLionel Sambuc const string_type* __trailing_sign = 0; 30204684ddb6SLionel Sambuc __wn = __wb.get(); 30214684ddb6SLionel Sambuc for (unsigned __p = 0; __p < 4 && __b != __e; ++__p) 30224684ddb6SLionel Sambuc { 30234684ddb6SLionel Sambuc switch (__pat.field[__p]) 30244684ddb6SLionel Sambuc { 30254684ddb6SLionel Sambuc case money_base::space: 30264684ddb6SLionel Sambuc if (__p != 3) 30274684ddb6SLionel Sambuc { 30284684ddb6SLionel Sambuc if (__ct.is(ctype_base::space, *__b)) 30294684ddb6SLionel Sambuc __spaces.push_back(*__b++); 30304684ddb6SLionel Sambuc else 30314684ddb6SLionel Sambuc { 30324684ddb6SLionel Sambuc __err |= ios_base::failbit; 30334684ddb6SLionel Sambuc return false; 30344684ddb6SLionel Sambuc } 30354684ddb6SLionel Sambuc } 30364684ddb6SLionel Sambuc // drop through 30374684ddb6SLionel Sambuc case money_base::none: 30384684ddb6SLionel Sambuc if (__p != 3) 30394684ddb6SLionel Sambuc { 30404684ddb6SLionel Sambuc while (__b != __e && __ct.is(ctype_base::space, *__b)) 30414684ddb6SLionel Sambuc __spaces.push_back(*__b++); 30424684ddb6SLionel Sambuc } 30434684ddb6SLionel Sambuc break; 30444684ddb6SLionel Sambuc case money_base::sign: 30454684ddb6SLionel Sambuc if (__psn.size() + __nsn.size() > 0) 30464684ddb6SLionel Sambuc { 30474684ddb6SLionel Sambuc if (__psn.size() == 0 || __nsn.size() == 0) 30484684ddb6SLionel Sambuc { // sign is optional 30494684ddb6SLionel Sambuc if (__psn.size() > 0) 30504684ddb6SLionel Sambuc { // __nsn.size() == 0 30514684ddb6SLionel Sambuc if (*__b == __psn[0]) 30524684ddb6SLionel Sambuc { 30534684ddb6SLionel Sambuc ++__b; 30544684ddb6SLionel Sambuc if (__psn.size() > 1) 30554684ddb6SLionel Sambuc __trailing_sign = &__psn; 30564684ddb6SLionel Sambuc } 30574684ddb6SLionel Sambuc else 30584684ddb6SLionel Sambuc __neg = true; 30594684ddb6SLionel Sambuc } 30604684ddb6SLionel Sambuc else if (*__b == __nsn[0]) // __nsn.size() > 0 && __psn.size() == 0 30614684ddb6SLionel Sambuc { 30624684ddb6SLionel Sambuc ++__b; 30634684ddb6SLionel Sambuc __neg = true; 30644684ddb6SLionel Sambuc if (__nsn.size() > 1) 30654684ddb6SLionel Sambuc __trailing_sign = &__nsn; 30664684ddb6SLionel Sambuc } 30674684ddb6SLionel Sambuc } 30684684ddb6SLionel Sambuc else // sign is required 30694684ddb6SLionel Sambuc { 30704684ddb6SLionel Sambuc if (*__b == __psn[0]) 30714684ddb6SLionel Sambuc { 30724684ddb6SLionel Sambuc ++__b; 30734684ddb6SLionel Sambuc if (__psn.size() > 1) 30744684ddb6SLionel Sambuc __trailing_sign = &__psn; 30754684ddb6SLionel Sambuc } 30764684ddb6SLionel Sambuc else if (*__b == __nsn[0]) 30774684ddb6SLionel Sambuc { 30784684ddb6SLionel Sambuc ++__b; 30794684ddb6SLionel Sambuc __neg = true; 30804684ddb6SLionel Sambuc if (__nsn.size() > 1) 30814684ddb6SLionel Sambuc __trailing_sign = &__nsn; 30824684ddb6SLionel Sambuc } 30834684ddb6SLionel Sambuc else 30844684ddb6SLionel Sambuc { 30854684ddb6SLionel Sambuc __err |= ios_base::failbit; 30864684ddb6SLionel Sambuc return false; 30874684ddb6SLionel Sambuc } 30884684ddb6SLionel Sambuc } 30894684ddb6SLionel Sambuc } 30904684ddb6SLionel Sambuc break; 30914684ddb6SLionel Sambuc case money_base::symbol: 30924684ddb6SLionel Sambuc { 30934684ddb6SLionel Sambuc bool __more_needed = __trailing_sign || 30944684ddb6SLionel Sambuc (__p < 2) || 30954684ddb6SLionel Sambuc (__p == 2 && __pat.field[3] != static_cast<char>(money_base::none)); 30964684ddb6SLionel Sambuc bool __sb = (__flags & ios_base::showbase) != 0; 30974684ddb6SLionel Sambuc if (__sb || __more_needed) 30984684ddb6SLionel Sambuc { 30994684ddb6SLionel Sambuc typename string_type::const_iterator __sym_space_end = __sym.begin(); 31004684ddb6SLionel Sambuc if (__p > 0 && (__pat.field[__p - 1] == money_base::none || 31014684ddb6SLionel Sambuc __pat.field[__p - 1] == money_base::space)) { 31024684ddb6SLionel Sambuc // Match spaces we've already read against spaces at 31034684ddb6SLionel Sambuc // the beginning of __sym. 31044684ddb6SLionel Sambuc while (__sym_space_end != __sym.end() && 31054684ddb6SLionel Sambuc __ct.is(ctype_base::space, *__sym_space_end)) 31064684ddb6SLionel Sambuc ++__sym_space_end; 31074684ddb6SLionel Sambuc const size_t __num_spaces = __sym_space_end - __sym.begin(); 31084684ddb6SLionel Sambuc if (__num_spaces > __spaces.size() || 31094684ddb6SLionel Sambuc !equal(__spaces.end() - __num_spaces, __spaces.end(), 31104684ddb6SLionel Sambuc __sym.begin())) { 31114684ddb6SLionel Sambuc // No match. Put __sym_space_end back at the 31124684ddb6SLionel Sambuc // beginning of __sym, which will prevent a 31134684ddb6SLionel Sambuc // match in the next loop. 31144684ddb6SLionel Sambuc __sym_space_end = __sym.begin(); 31154684ddb6SLionel Sambuc } 31164684ddb6SLionel Sambuc } 31174684ddb6SLionel Sambuc typename string_type::const_iterator __sym_curr_char = __sym_space_end; 31184684ddb6SLionel Sambuc while (__sym_curr_char != __sym.end() && __b != __e && 31194684ddb6SLionel Sambuc *__b == *__sym_curr_char) { 31204684ddb6SLionel Sambuc ++__b; 31214684ddb6SLionel Sambuc ++__sym_curr_char; 31224684ddb6SLionel Sambuc } 31234684ddb6SLionel Sambuc if (__sb && __sym_curr_char != __sym.end()) 31244684ddb6SLionel Sambuc { 31254684ddb6SLionel Sambuc __err |= ios_base::failbit; 31264684ddb6SLionel Sambuc return false; 31274684ddb6SLionel Sambuc } 31284684ddb6SLionel Sambuc } 31294684ddb6SLionel Sambuc } 31304684ddb6SLionel Sambuc break; 31314684ddb6SLionel Sambuc case money_base::value: 31324684ddb6SLionel Sambuc { 31334684ddb6SLionel Sambuc unsigned __ng = 0; 31344684ddb6SLionel Sambuc for (; __b != __e; ++__b) 31354684ddb6SLionel Sambuc { 31364684ddb6SLionel Sambuc char_type __c = *__b; 31374684ddb6SLionel Sambuc if (__ct.is(ctype_base::digit, __c)) 31384684ddb6SLionel Sambuc { 31394684ddb6SLionel Sambuc if (__wn == __we) 31404684ddb6SLionel Sambuc __double_or_nothing(__wb, __wn, __we); 31414684ddb6SLionel Sambuc *__wn++ = __c; 31424684ddb6SLionel Sambuc ++__ng; 31434684ddb6SLionel Sambuc } 31444684ddb6SLionel Sambuc else if (__grp.size() > 0 && __ng > 0 && __c == __ts) 31454684ddb6SLionel Sambuc { 31464684ddb6SLionel Sambuc if (__gn == __ge) 31474684ddb6SLionel Sambuc __double_or_nothing(__gb, __gn, __ge); 31484684ddb6SLionel Sambuc *__gn++ = __ng; 31494684ddb6SLionel Sambuc __ng = 0; 31504684ddb6SLionel Sambuc } 31514684ddb6SLionel Sambuc else 31524684ddb6SLionel Sambuc break; 31534684ddb6SLionel Sambuc } 31544684ddb6SLionel Sambuc if (__gb.get() != __gn && __ng > 0) 31554684ddb6SLionel Sambuc { 31564684ddb6SLionel Sambuc if (__gn == __ge) 31574684ddb6SLionel Sambuc __double_or_nothing(__gb, __gn, __ge); 31584684ddb6SLionel Sambuc *__gn++ = __ng; 31594684ddb6SLionel Sambuc } 31604684ddb6SLionel Sambuc if (__fd > 0) 31614684ddb6SLionel Sambuc { 31624684ddb6SLionel Sambuc if (__b == __e || *__b != __dp) 31634684ddb6SLionel Sambuc { 31644684ddb6SLionel Sambuc __err |= ios_base::failbit; 31654684ddb6SLionel Sambuc return false; 31664684ddb6SLionel Sambuc } 31674684ddb6SLionel Sambuc for (++__b; __fd > 0; --__fd, ++__b) 31684684ddb6SLionel Sambuc { 31694684ddb6SLionel Sambuc if (__b == __e || !__ct.is(ctype_base::digit, *__b)) 31704684ddb6SLionel Sambuc { 31714684ddb6SLionel Sambuc __err |= ios_base::failbit; 31724684ddb6SLionel Sambuc return false; 31734684ddb6SLionel Sambuc } 31744684ddb6SLionel Sambuc if (__wn == __we) 31754684ddb6SLionel Sambuc __double_or_nothing(__wb, __wn, __we); 31764684ddb6SLionel Sambuc *__wn++ = *__b; 31774684ddb6SLionel Sambuc } 31784684ddb6SLionel Sambuc } 31794684ddb6SLionel Sambuc if (__wn == __wb.get()) 31804684ddb6SLionel Sambuc { 31814684ddb6SLionel Sambuc __err |= ios_base::failbit; 31824684ddb6SLionel Sambuc return false; 31834684ddb6SLionel Sambuc } 31844684ddb6SLionel Sambuc } 31854684ddb6SLionel Sambuc break; 31864684ddb6SLionel Sambuc } 31874684ddb6SLionel Sambuc } 31884684ddb6SLionel Sambuc if (__trailing_sign) 31894684ddb6SLionel Sambuc { 31904684ddb6SLionel Sambuc for (unsigned __i = 1; __i < __trailing_sign->size(); ++__i, ++__b) 31914684ddb6SLionel Sambuc { 31924684ddb6SLionel Sambuc if (__b == __e || *__b != (*__trailing_sign)[__i]) 31934684ddb6SLionel Sambuc { 31944684ddb6SLionel Sambuc __err |= ios_base::failbit; 31954684ddb6SLionel Sambuc return false; 31964684ddb6SLionel Sambuc } 31974684ddb6SLionel Sambuc } 31984684ddb6SLionel Sambuc } 31994684ddb6SLionel Sambuc if (__gb.get() != __gn) 32004684ddb6SLionel Sambuc { 32014684ddb6SLionel Sambuc ios_base::iostate __et = ios_base::goodbit; 32024684ddb6SLionel Sambuc __check_grouping(__grp, __gb.get(), __gn, __et); 32034684ddb6SLionel Sambuc if (__et) 32044684ddb6SLionel Sambuc { 32054684ddb6SLionel Sambuc __err |= ios_base::failbit; 32064684ddb6SLionel Sambuc return false; 32074684ddb6SLionel Sambuc } 32084684ddb6SLionel Sambuc } 32094684ddb6SLionel Sambuc return true; 32104684ddb6SLionel Sambuc} 32114684ddb6SLionel Sambuc 32124684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 32134684ddb6SLionel Sambuc_InputIterator 32144684ddb6SLionel Sambucmoney_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, 32154684ddb6SLionel Sambuc bool __intl, ios_base& __iob, 32164684ddb6SLionel Sambuc ios_base::iostate& __err, 32174684ddb6SLionel Sambuc long double& __v) const 32184684ddb6SLionel Sambuc{ 32194684ddb6SLionel Sambuc const int __bz = 100; 32204684ddb6SLionel Sambuc char_type __wbuf[__bz]; 32214684ddb6SLionel Sambuc unique_ptr<char_type, void(*)(void*)> __wb(__wbuf, __do_nothing); 32224684ddb6SLionel Sambuc char_type* __wn; 32234684ddb6SLionel Sambuc char_type* __we = __wbuf + __bz; 32244684ddb6SLionel Sambuc locale __loc = __iob.getloc(); 32254684ddb6SLionel Sambuc const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__loc); 32264684ddb6SLionel Sambuc bool __neg = false; 32274684ddb6SLionel Sambuc if (__do_get(__b, __e, __intl, __loc, __iob.flags(), __err, __neg, __ct, 32284684ddb6SLionel Sambuc __wb, __wn, __we)) 32294684ddb6SLionel Sambuc { 32304684ddb6SLionel Sambuc const char __src[] = "0123456789"; 32314684ddb6SLionel Sambuc char_type __atoms[sizeof(__src)-1]; 32324684ddb6SLionel Sambuc __ct.widen(__src, __src + (sizeof(__src)-1), __atoms); 32334684ddb6SLionel Sambuc char __nbuf[__bz]; 32344684ddb6SLionel Sambuc char* __nc = __nbuf; 32354684ddb6SLionel Sambuc unique_ptr<char, void(*)(void*)> __h(0, free); 32364684ddb6SLionel Sambuc if (__wn - __wb.get() > __bz-2) 32374684ddb6SLionel Sambuc { 32384684ddb6SLionel Sambuc __h.reset((char*)malloc(static_cast<size_t>(__wn - __wb.get() + 2))); 32394684ddb6SLionel Sambuc if (__h.get() == 0) 32404684ddb6SLionel Sambuc __throw_bad_alloc(); 32414684ddb6SLionel Sambuc __nc = __h.get(); 32424684ddb6SLionel Sambuc } 32434684ddb6SLionel Sambuc if (__neg) 32444684ddb6SLionel Sambuc *__nc++ = '-'; 32454684ddb6SLionel Sambuc for (const char_type* __w = __wb.get(); __w < __wn; ++__w, ++__nc) 32464684ddb6SLionel Sambuc *__nc = __src[find(__atoms, _VSTD::end(__atoms), *__w) - __atoms]; 32474684ddb6SLionel Sambuc *__nc = char(); 32484684ddb6SLionel Sambuc if (sscanf(__nbuf, "%Lf", &__v) != 1) 32494684ddb6SLionel Sambuc __throw_runtime_error("money_get error"); 32504684ddb6SLionel Sambuc } 32514684ddb6SLionel Sambuc if (__b == __e) 32524684ddb6SLionel Sambuc __err |= ios_base::eofbit; 32534684ddb6SLionel Sambuc return __b; 32544684ddb6SLionel Sambuc} 32554684ddb6SLionel Sambuc 32564684ddb6SLionel Sambuctemplate <class _CharT, class _InputIterator> 32574684ddb6SLionel Sambuc_InputIterator 32584684ddb6SLionel Sambucmoney_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e, 32594684ddb6SLionel Sambuc bool __intl, ios_base& __iob, 32604684ddb6SLionel Sambuc ios_base::iostate& __err, 32614684ddb6SLionel Sambuc string_type& __v) const 32624684ddb6SLionel Sambuc{ 32634684ddb6SLionel Sambuc const int __bz = 100; 32644684ddb6SLionel Sambuc char_type __wbuf[__bz]; 32654684ddb6SLionel Sambuc unique_ptr<char_type, void(*)(void*)> __wb(__wbuf, __do_nothing); 32664684ddb6SLionel Sambuc char_type* __wn; 32674684ddb6SLionel Sambuc char_type* __we = __wbuf + __bz; 32684684ddb6SLionel Sambuc locale __loc = __iob.getloc(); 32694684ddb6SLionel Sambuc const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__loc); 32704684ddb6SLionel Sambuc bool __neg = false; 32714684ddb6SLionel Sambuc if (__do_get(__b, __e, __intl, __loc, __iob.flags(), __err, __neg, __ct, 32724684ddb6SLionel Sambuc __wb, __wn, __we)) 32734684ddb6SLionel Sambuc { 32744684ddb6SLionel Sambuc __v.clear(); 32754684ddb6SLionel Sambuc if (__neg) 32764684ddb6SLionel Sambuc __v.push_back(__ct.widen('-')); 32774684ddb6SLionel Sambuc char_type __z = __ct.widen('0'); 32784684ddb6SLionel Sambuc char_type* __w; 32794684ddb6SLionel Sambuc for (__w = __wb.get(); __w < __wn-1; ++__w) 32804684ddb6SLionel Sambuc if (*__w != __z) 32814684ddb6SLionel Sambuc break; 32824684ddb6SLionel Sambuc __v.append(__w, __wn); 32834684ddb6SLionel Sambuc } 32844684ddb6SLionel Sambuc if (__b == __e) 32854684ddb6SLionel Sambuc __err |= ios_base::eofbit; 32864684ddb6SLionel Sambuc return __b; 32874684ddb6SLionel Sambuc} 32884684ddb6SLionel Sambuc 32894684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS money_get<char>) 32904684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS money_get<wchar_t>) 32914684ddb6SLionel Sambuc 32924684ddb6SLionel Sambuc// money_put 32934684ddb6SLionel Sambuc 32944684ddb6SLionel Sambuctemplate <class _CharT> 32954684ddb6SLionel Sambucclass __money_put 32964684ddb6SLionel Sambuc{ 32974684ddb6SLionel Sambucprotected: 32984684ddb6SLionel Sambuc typedef _CharT char_type; 32994684ddb6SLionel Sambuc typedef basic_string<char_type> string_type; 33004684ddb6SLionel Sambuc 33014684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE __money_put() {} 33024684ddb6SLionel Sambuc 33034684ddb6SLionel Sambuc static void __gather_info(bool __intl, bool __neg, const locale& __loc, 33044684ddb6SLionel Sambuc money_base::pattern& __pat, char_type& __dp, 33054684ddb6SLionel Sambuc char_type& __ts, string& __grp, 33064684ddb6SLionel Sambuc string_type& __sym, string_type& __sn, 33074684ddb6SLionel Sambuc int& __fd); 33084684ddb6SLionel Sambuc static void __format(char_type* __mb, char_type*& __mi, char_type*& __me, 33094684ddb6SLionel Sambuc ios_base::fmtflags __flags, 33104684ddb6SLionel Sambuc const char_type* __db, const char_type* __de, 33114684ddb6SLionel Sambuc const ctype<char_type>& __ct, bool __neg, 33124684ddb6SLionel Sambuc const money_base::pattern& __pat, char_type __dp, 33134684ddb6SLionel Sambuc char_type __ts, const string& __grp, 33144684ddb6SLionel Sambuc const string_type& __sym, const string_type& __sn, 33154684ddb6SLionel Sambuc int __fd); 33164684ddb6SLionel Sambuc}; 33174684ddb6SLionel Sambuc 33184684ddb6SLionel Sambuctemplate <class _CharT> 33194684ddb6SLionel Sambucvoid 33204684ddb6SLionel Sambuc__money_put<_CharT>::__gather_info(bool __intl, bool __neg, const locale& __loc, 33214684ddb6SLionel Sambuc money_base::pattern& __pat, char_type& __dp, 33224684ddb6SLionel Sambuc char_type& __ts, string& __grp, 33234684ddb6SLionel Sambuc string_type& __sym, string_type& __sn, 33244684ddb6SLionel Sambuc int& __fd) 33254684ddb6SLionel Sambuc{ 33264684ddb6SLionel Sambuc if (__intl) 33274684ddb6SLionel Sambuc { 33284684ddb6SLionel Sambuc const moneypunct<char_type, true>& __mp = 33294684ddb6SLionel Sambuc use_facet<moneypunct<char_type, true> >(__loc); 33304684ddb6SLionel Sambuc if (__neg) 33314684ddb6SLionel Sambuc { 33324684ddb6SLionel Sambuc __pat = __mp.neg_format(); 33334684ddb6SLionel Sambuc __sn = __mp.negative_sign(); 33344684ddb6SLionel Sambuc } 33354684ddb6SLionel Sambuc else 33364684ddb6SLionel Sambuc { 33374684ddb6SLionel Sambuc __pat = __mp.pos_format(); 33384684ddb6SLionel Sambuc __sn = __mp.positive_sign(); 33394684ddb6SLionel Sambuc } 33404684ddb6SLionel Sambuc __dp = __mp.decimal_point(); 33414684ddb6SLionel Sambuc __ts = __mp.thousands_sep(); 33424684ddb6SLionel Sambuc __grp = __mp.grouping(); 33434684ddb6SLionel Sambuc __sym = __mp.curr_symbol(); 33444684ddb6SLionel Sambuc __fd = __mp.frac_digits(); 33454684ddb6SLionel Sambuc } 33464684ddb6SLionel Sambuc else 33474684ddb6SLionel Sambuc { 33484684ddb6SLionel Sambuc const moneypunct<char_type, false>& __mp = 33494684ddb6SLionel Sambuc use_facet<moneypunct<char_type, false> >(__loc); 33504684ddb6SLionel Sambuc if (__neg) 33514684ddb6SLionel Sambuc { 33524684ddb6SLionel Sambuc __pat = __mp.neg_format(); 33534684ddb6SLionel Sambuc __sn = __mp.negative_sign(); 33544684ddb6SLionel Sambuc } 33554684ddb6SLionel Sambuc else 33564684ddb6SLionel Sambuc { 33574684ddb6SLionel Sambuc __pat = __mp.pos_format(); 33584684ddb6SLionel Sambuc __sn = __mp.positive_sign(); 33594684ddb6SLionel Sambuc } 33604684ddb6SLionel Sambuc __dp = __mp.decimal_point(); 33614684ddb6SLionel Sambuc __ts = __mp.thousands_sep(); 33624684ddb6SLionel Sambuc __grp = __mp.grouping(); 33634684ddb6SLionel Sambuc __sym = __mp.curr_symbol(); 33644684ddb6SLionel Sambuc __fd = __mp.frac_digits(); 33654684ddb6SLionel Sambuc } 33664684ddb6SLionel Sambuc} 33674684ddb6SLionel Sambuc 33684684ddb6SLionel Sambuctemplate <class _CharT> 33694684ddb6SLionel Sambucvoid 33704684ddb6SLionel Sambuc__money_put<_CharT>::__format(char_type* __mb, char_type*& __mi, char_type*& __me, 33714684ddb6SLionel Sambuc ios_base::fmtflags __flags, 33724684ddb6SLionel Sambuc const char_type* __db, const char_type* __de, 33734684ddb6SLionel Sambuc const ctype<char_type>& __ct, bool __neg, 33744684ddb6SLionel Sambuc const money_base::pattern& __pat, char_type __dp, 33754684ddb6SLionel Sambuc char_type __ts, const string& __grp, 33764684ddb6SLionel Sambuc const string_type& __sym, const string_type& __sn, 33774684ddb6SLionel Sambuc int __fd) 33784684ddb6SLionel Sambuc{ 33794684ddb6SLionel Sambuc __me = __mb; 33804684ddb6SLionel Sambuc for (unsigned __p = 0; __p < 4; ++__p) 33814684ddb6SLionel Sambuc { 33824684ddb6SLionel Sambuc switch (__pat.field[__p]) 33834684ddb6SLionel Sambuc { 33844684ddb6SLionel Sambuc case money_base::none: 33854684ddb6SLionel Sambuc __mi = __me; 33864684ddb6SLionel Sambuc break; 33874684ddb6SLionel Sambuc case money_base::space: 33884684ddb6SLionel Sambuc __mi = __me; 33894684ddb6SLionel Sambuc *__me++ = __ct.widen(' '); 33904684ddb6SLionel Sambuc break; 33914684ddb6SLionel Sambuc case money_base::sign: 33924684ddb6SLionel Sambuc if (!__sn.empty()) 33934684ddb6SLionel Sambuc *__me++ = __sn[0]; 33944684ddb6SLionel Sambuc break; 33954684ddb6SLionel Sambuc case money_base::symbol: 33964684ddb6SLionel Sambuc if (!__sym.empty() && (__flags & ios_base::showbase)) 33974684ddb6SLionel Sambuc __me = _VSTD::copy(__sym.begin(), __sym.end(), __me); 33984684ddb6SLionel Sambuc break; 33994684ddb6SLionel Sambuc case money_base::value: 34004684ddb6SLionel Sambuc { 34014684ddb6SLionel Sambuc // remember start of value so we can reverse it 34024684ddb6SLionel Sambuc char_type* __t = __me; 34034684ddb6SLionel Sambuc // find beginning of digits 34044684ddb6SLionel Sambuc if (__neg) 34054684ddb6SLionel Sambuc ++__db; 34064684ddb6SLionel Sambuc // find end of digits 34074684ddb6SLionel Sambuc const char_type* __d; 34084684ddb6SLionel Sambuc for (__d = __db; __d < __de; ++__d) 34094684ddb6SLionel Sambuc if (!__ct.is(ctype_base::digit, *__d)) 34104684ddb6SLionel Sambuc break; 34114684ddb6SLionel Sambuc // print fractional part 34124684ddb6SLionel Sambuc if (__fd > 0) 34134684ddb6SLionel Sambuc { 34144684ddb6SLionel Sambuc int __f; 34154684ddb6SLionel Sambuc for (__f = __fd; __d > __db && __f > 0; --__f) 34164684ddb6SLionel Sambuc *__me++ = *--__d; 34174684ddb6SLionel Sambuc char_type __z = __f > 0 ? __ct.widen('0') : char_type(); 34184684ddb6SLionel Sambuc for (; __f > 0; --__f) 34194684ddb6SLionel Sambuc *__me++ = __z; 34204684ddb6SLionel Sambuc *__me++ = __dp; 34214684ddb6SLionel Sambuc } 34224684ddb6SLionel Sambuc // print units part 34234684ddb6SLionel Sambuc if (__d == __db) 34244684ddb6SLionel Sambuc { 34254684ddb6SLionel Sambuc *__me++ = __ct.widen('0'); 34264684ddb6SLionel Sambuc } 34274684ddb6SLionel Sambuc else 34284684ddb6SLionel Sambuc { 34294684ddb6SLionel Sambuc unsigned __ng = 0; 34304684ddb6SLionel Sambuc unsigned __ig = 0; 34314684ddb6SLionel Sambuc unsigned __gl = __grp.empty() ? numeric_limits<unsigned>::max() 34324684ddb6SLionel Sambuc : static_cast<unsigned>(__grp[__ig]); 34334684ddb6SLionel Sambuc while (__d != __db) 34344684ddb6SLionel Sambuc { 34354684ddb6SLionel Sambuc if (__ng == __gl) 34364684ddb6SLionel Sambuc { 34374684ddb6SLionel Sambuc *__me++ = __ts; 34384684ddb6SLionel Sambuc __ng = 0; 34394684ddb6SLionel Sambuc if (++__ig < __grp.size()) 34404684ddb6SLionel Sambuc __gl = __grp[__ig] == numeric_limits<char>::max() ? 34414684ddb6SLionel Sambuc numeric_limits<unsigned>::max() : 34424684ddb6SLionel Sambuc static_cast<unsigned>(__grp[__ig]); 34434684ddb6SLionel Sambuc } 34444684ddb6SLionel Sambuc *__me++ = *--__d; 34454684ddb6SLionel Sambuc ++__ng; 34464684ddb6SLionel Sambuc } 34474684ddb6SLionel Sambuc } 34484684ddb6SLionel Sambuc // reverse it 34494684ddb6SLionel Sambuc reverse(__t, __me); 34504684ddb6SLionel Sambuc } 34514684ddb6SLionel Sambuc break; 34524684ddb6SLionel Sambuc } 34534684ddb6SLionel Sambuc } 34544684ddb6SLionel Sambuc // print rest of sign, if any 34554684ddb6SLionel Sambuc if (__sn.size() > 1) 34564684ddb6SLionel Sambuc __me = _VSTD::copy(__sn.begin()+1, __sn.end(), __me); 34574684ddb6SLionel Sambuc // set alignment 34584684ddb6SLionel Sambuc if ((__flags & ios_base::adjustfield) == ios_base::left) 34594684ddb6SLionel Sambuc __mi = __me; 34604684ddb6SLionel Sambuc else if ((__flags & ios_base::adjustfield) != ios_base::internal) 34614684ddb6SLionel Sambuc __mi = __mb; 34624684ddb6SLionel Sambuc} 34634684ddb6SLionel Sambuc 34644684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS __money_put<char>) 34654684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS __money_put<wchar_t>) 34664684ddb6SLionel Sambuc 34674684ddb6SLionel Sambuctemplate <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> > 34684684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY money_put 34694684ddb6SLionel Sambuc : public locale::facet, 34704684ddb6SLionel Sambuc private __money_put<_CharT> 34714684ddb6SLionel Sambuc{ 34724684ddb6SLionel Sambucpublic: 34734684ddb6SLionel Sambuc typedef _CharT char_type; 34744684ddb6SLionel Sambuc typedef _OutputIterator iter_type; 34754684ddb6SLionel Sambuc typedef basic_string<char_type> string_type; 34764684ddb6SLionel Sambuc 34774684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 34784684ddb6SLionel Sambuc explicit money_put(size_t __refs = 0) 34794684ddb6SLionel Sambuc : locale::facet(__refs) {} 34804684ddb6SLionel Sambuc 34814684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 34824684ddb6SLionel Sambuc iter_type put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, 34834684ddb6SLionel Sambuc long double __units) const 34844684ddb6SLionel Sambuc { 34854684ddb6SLionel Sambuc return do_put(__s, __intl, __iob, __fl, __units); 34864684ddb6SLionel Sambuc } 34874684ddb6SLionel Sambuc 34884684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 34894684ddb6SLionel Sambuc iter_type put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl, 34904684ddb6SLionel Sambuc const string_type& __digits) const 34914684ddb6SLionel Sambuc { 34924684ddb6SLionel Sambuc return do_put(__s, __intl, __iob, __fl, __digits); 34934684ddb6SLionel Sambuc } 34944684ddb6SLionel Sambuc 34954684ddb6SLionel Sambuc static locale::id id; 34964684ddb6SLionel Sambuc 34974684ddb6SLionel Sambucprotected: 34984684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 34994684ddb6SLionel Sambuc ~money_put() {} 35004684ddb6SLionel Sambuc 35014684ddb6SLionel Sambuc virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __iob, 35024684ddb6SLionel Sambuc char_type __fl, long double __units) const; 35034684ddb6SLionel Sambuc virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __iob, 35044684ddb6SLionel Sambuc char_type __fl, const string_type& __digits) const; 35054684ddb6SLionel Sambuc}; 35064684ddb6SLionel Sambuc 35074684ddb6SLionel Sambuctemplate <class _CharT, class _OutputIterator> 35084684ddb6SLionel Sambuclocale::id 35094684ddb6SLionel Sambucmoney_put<_CharT, _OutputIterator>::id; 35104684ddb6SLionel Sambuc 35114684ddb6SLionel Sambuctemplate <class _CharT, class _OutputIterator> 35124684ddb6SLionel Sambuc_OutputIterator 35134684ddb6SLionel Sambucmoney_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl, 35144684ddb6SLionel Sambuc ios_base& __iob, char_type __fl, 35154684ddb6SLionel Sambuc long double __units) const 35164684ddb6SLionel Sambuc{ 35174684ddb6SLionel Sambuc // convert to char 35184684ddb6SLionel Sambuc const size_t __bs = 100; 35194684ddb6SLionel Sambuc char __buf[__bs]; 35204684ddb6SLionel Sambuc char* __bb = __buf; 35214684ddb6SLionel Sambuc char_type __digits[__bs]; 35224684ddb6SLionel Sambuc char_type* __db = __digits; 35234684ddb6SLionel Sambuc size_t __n = static_cast<size_t>(snprintf(__bb, __bs, "%.0Lf", __units)); 35244684ddb6SLionel Sambuc unique_ptr<char, void(*)(void*)> __hn(0, free); 35254684ddb6SLionel Sambuc unique_ptr<char_type, void(*)(void*)> __hd(0, free); 35264684ddb6SLionel Sambuc // secure memory for digit storage 35274684ddb6SLionel Sambuc if (__n > __bs-1) 35284684ddb6SLionel Sambuc { 35294684ddb6SLionel Sambuc#ifdef _LIBCPP_LOCALE__L_EXTENSIONS 35304684ddb6SLionel Sambuc __n = static_cast<size_t>(asprintf_l(&__bb, _LIBCPP_GET_C_LOCALE, "%.0Lf", __units)); 35314684ddb6SLionel Sambuc#else 3532*0a6a1f1dSLionel Sambuc __n = __asprintf_l(&__bb, _LIBCPP_GET_C_LOCALE, "%.0Lf", __units); 35334684ddb6SLionel Sambuc#endif 35344684ddb6SLionel Sambuc if (__bb == 0) 35354684ddb6SLionel Sambuc __throw_bad_alloc(); 35364684ddb6SLionel Sambuc __hn.reset(__bb); 35374684ddb6SLionel Sambuc __hd.reset((char_type*)malloc(__n * sizeof(char_type))); 35384684ddb6SLionel Sambuc if (__hd == nullptr) 35394684ddb6SLionel Sambuc __throw_bad_alloc(); 35404684ddb6SLionel Sambuc __db = __hd.get(); 35414684ddb6SLionel Sambuc } 35424684ddb6SLionel Sambuc // gather info 35434684ddb6SLionel Sambuc locale __loc = __iob.getloc(); 35444684ddb6SLionel Sambuc const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__loc); 35454684ddb6SLionel Sambuc __ct.widen(__bb, __bb + __n, __db); 35464684ddb6SLionel Sambuc bool __neg = __n > 0 && __bb[0] == '-'; 35474684ddb6SLionel Sambuc money_base::pattern __pat; 35484684ddb6SLionel Sambuc char_type __dp; 35494684ddb6SLionel Sambuc char_type __ts; 35504684ddb6SLionel Sambuc string __grp; 35514684ddb6SLionel Sambuc string_type __sym; 35524684ddb6SLionel Sambuc string_type __sn; 35534684ddb6SLionel Sambuc int __fd; 35544684ddb6SLionel Sambuc this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd); 35554684ddb6SLionel Sambuc // secure memory for formatting 35564684ddb6SLionel Sambuc char_type __mbuf[__bs]; 35574684ddb6SLionel Sambuc char_type* __mb = __mbuf; 35584684ddb6SLionel Sambuc unique_ptr<char_type, void(*)(void*)> __hw(0, free); 35594684ddb6SLionel Sambuc size_t __exn = static_cast<int>(__n) > __fd ? 35604684ddb6SLionel Sambuc (__n - static_cast<size_t>(__fd)) * 2 + __sn.size() + 35614684ddb6SLionel Sambuc __sym.size() + static_cast<size_t>(__fd) + 1 35624684ddb6SLionel Sambuc : __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 2; 35634684ddb6SLionel Sambuc if (__exn > __bs) 35644684ddb6SLionel Sambuc { 35654684ddb6SLionel Sambuc __hw.reset((char_type*)malloc(__exn * sizeof(char_type))); 35664684ddb6SLionel Sambuc __mb = __hw.get(); 35674684ddb6SLionel Sambuc if (__mb == 0) 35684684ddb6SLionel Sambuc __throw_bad_alloc(); 35694684ddb6SLionel Sambuc } 35704684ddb6SLionel Sambuc // format 35714684ddb6SLionel Sambuc char_type* __mi; 35724684ddb6SLionel Sambuc char_type* __me; 35734684ddb6SLionel Sambuc this->__format(__mb, __mi, __me, __iob.flags(), 35744684ddb6SLionel Sambuc __db, __db + __n, __ct, 35754684ddb6SLionel Sambuc __neg, __pat, __dp, __ts, __grp, __sym, __sn, __fd); 35764684ddb6SLionel Sambuc return __pad_and_output(__s, __mb, __mi, __me, __iob, __fl); 35774684ddb6SLionel Sambuc} 35784684ddb6SLionel Sambuc 35794684ddb6SLionel Sambuctemplate <class _CharT, class _OutputIterator> 35804684ddb6SLionel Sambuc_OutputIterator 35814684ddb6SLionel Sambucmoney_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl, 35824684ddb6SLionel Sambuc ios_base& __iob, char_type __fl, 35834684ddb6SLionel Sambuc const string_type& __digits) const 35844684ddb6SLionel Sambuc{ 35854684ddb6SLionel Sambuc // gather info 35864684ddb6SLionel Sambuc locale __loc = __iob.getloc(); 35874684ddb6SLionel Sambuc const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__loc); 35884684ddb6SLionel Sambuc bool __neg = __digits.size() > 0 && __digits[0] == __ct.widen('-'); 35894684ddb6SLionel Sambuc money_base::pattern __pat; 35904684ddb6SLionel Sambuc char_type __dp; 35914684ddb6SLionel Sambuc char_type __ts; 35924684ddb6SLionel Sambuc string __grp; 35934684ddb6SLionel Sambuc string_type __sym; 35944684ddb6SLionel Sambuc string_type __sn; 35954684ddb6SLionel Sambuc int __fd; 35964684ddb6SLionel Sambuc this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd); 35974684ddb6SLionel Sambuc // secure memory for formatting 35984684ddb6SLionel Sambuc char_type __mbuf[100]; 35994684ddb6SLionel Sambuc char_type* __mb = __mbuf; 36004684ddb6SLionel Sambuc unique_ptr<char_type, void(*)(void*)> __h(0, free); 36014684ddb6SLionel Sambuc size_t __exn = static_cast<int>(__digits.size()) > __fd ? 36024684ddb6SLionel Sambuc (__digits.size() - static_cast<size_t>(__fd)) * 2 + 36034684ddb6SLionel Sambuc __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 1 36044684ddb6SLionel Sambuc : __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 2; 36054684ddb6SLionel Sambuc if (__exn > 100) 36064684ddb6SLionel Sambuc { 36074684ddb6SLionel Sambuc __h.reset((char_type*)malloc(__exn * sizeof(char_type))); 36084684ddb6SLionel Sambuc __mb = __h.get(); 36094684ddb6SLionel Sambuc if (__mb == 0) 36104684ddb6SLionel Sambuc __throw_bad_alloc(); 36114684ddb6SLionel Sambuc } 36124684ddb6SLionel Sambuc // format 36134684ddb6SLionel Sambuc char_type* __mi; 36144684ddb6SLionel Sambuc char_type* __me; 36154684ddb6SLionel Sambuc this->__format(__mb, __mi, __me, __iob.flags(), 36164684ddb6SLionel Sambuc __digits.data(), __digits.data() + __digits.size(), __ct, 36174684ddb6SLionel Sambuc __neg, __pat, __dp, __ts, __grp, __sym, __sn, __fd); 36184684ddb6SLionel Sambuc return __pad_and_output(__s, __mb, __mi, __me, __iob, __fl); 36194684ddb6SLionel Sambuc} 36204684ddb6SLionel Sambuc 36214684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS money_put<char>) 36224684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS money_put<wchar_t>) 36234684ddb6SLionel Sambuc 36244684ddb6SLionel Sambuc// messages 36254684ddb6SLionel Sambuc 36264684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS messages_base 36274684ddb6SLionel Sambuc{ 36284684ddb6SLionel Sambucpublic: 36294684ddb6SLionel Sambuc typedef ptrdiff_t catalog; 36304684ddb6SLionel Sambuc 36314684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE messages_base() {} 36324684ddb6SLionel Sambuc}; 36334684ddb6SLionel Sambuc 36344684ddb6SLionel Sambuctemplate <class _CharT> 36354684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY messages 36364684ddb6SLionel Sambuc : public locale::facet, 36374684ddb6SLionel Sambuc public messages_base 36384684ddb6SLionel Sambuc{ 36394684ddb6SLionel Sambucpublic: 36404684ddb6SLionel Sambuc typedef _CharT char_type; 36414684ddb6SLionel Sambuc typedef basic_string<_CharT> string_type; 36424684ddb6SLionel Sambuc 36434684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 36444684ddb6SLionel Sambuc explicit messages(size_t __refs = 0) 36454684ddb6SLionel Sambuc : locale::facet(__refs) {} 36464684ddb6SLionel Sambuc 36474684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 36484684ddb6SLionel Sambuc catalog open(const basic_string<char>& __nm, const locale& __loc) const 36494684ddb6SLionel Sambuc { 36504684ddb6SLionel Sambuc return do_open(__nm, __loc); 36514684ddb6SLionel Sambuc } 36524684ddb6SLionel Sambuc 36534684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 36544684ddb6SLionel Sambuc string_type get(catalog __c, int __set, int __msgid, 36554684ddb6SLionel Sambuc const string_type& __dflt) const 36564684ddb6SLionel Sambuc { 36574684ddb6SLionel Sambuc return do_get(__c, __set, __msgid, __dflt); 36584684ddb6SLionel Sambuc } 36594684ddb6SLionel Sambuc 36604684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 36614684ddb6SLionel Sambuc void close(catalog __c) const 36624684ddb6SLionel Sambuc { 36634684ddb6SLionel Sambuc do_close(__c); 36644684ddb6SLionel Sambuc } 36654684ddb6SLionel Sambuc 36664684ddb6SLionel Sambuc static locale::id id; 36674684ddb6SLionel Sambuc 36684684ddb6SLionel Sambucprotected: 36694684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 36704684ddb6SLionel Sambuc ~messages() {} 36714684ddb6SLionel Sambuc 36724684ddb6SLionel Sambuc virtual catalog do_open(const basic_string<char>&, const locale&) const; 36734684ddb6SLionel Sambuc virtual string_type do_get(catalog, int __set, int __msgid, 36744684ddb6SLionel Sambuc const string_type& __dflt) const; 36754684ddb6SLionel Sambuc virtual void do_close(catalog) const; 36764684ddb6SLionel Sambuc}; 36774684ddb6SLionel Sambuc 36784684ddb6SLionel Sambuctemplate <class _CharT> 36794684ddb6SLionel Sambuclocale::id 36804684ddb6SLionel Sambucmessages<_CharT>::id; 36814684ddb6SLionel Sambuc 36824684ddb6SLionel Sambuctemplate <class _CharT> 36834684ddb6SLionel Sambuctypename messages<_CharT>::catalog 36844684ddb6SLionel Sambucmessages<_CharT>::do_open(const basic_string<char>& __nm, const locale&) const 36854684ddb6SLionel Sambuc{ 3686*0a6a1f1dSLionel Sambuc#ifdef _LIBCPP_HAS_CATOPEN 36874684ddb6SLionel Sambuc catalog __cat = (catalog)catopen(__nm.c_str(), NL_CAT_LOCALE); 36884684ddb6SLionel Sambuc if (__cat != -1) 36894684ddb6SLionel Sambuc __cat = static_cast<catalog>((static_cast<size_t>(__cat) >> 1)); 36904684ddb6SLionel Sambuc return __cat; 3691*0a6a1f1dSLionel Sambuc#else // !_LIBCPP_HAS_CATOPEN 3692*0a6a1f1dSLionel Sambuc return -1; 3693*0a6a1f1dSLionel Sambuc#endif // _LIBCPP_HAS_CATOPEN 36944684ddb6SLionel Sambuc} 36954684ddb6SLionel Sambuc 36964684ddb6SLionel Sambuctemplate <class _CharT> 36974684ddb6SLionel Sambuctypename messages<_CharT>::string_type 36984684ddb6SLionel Sambucmessages<_CharT>::do_get(catalog __c, int __set, int __msgid, 36994684ddb6SLionel Sambuc const string_type& __dflt) const 37004684ddb6SLionel Sambuc{ 3701*0a6a1f1dSLionel Sambuc#ifdef _LIBCPP_HAS_CATOPEN 37024684ddb6SLionel Sambuc string __ndflt; 37034684ddb6SLionel Sambuc __narrow_to_utf8<sizeof(char_type)*__CHAR_BIT__>()(back_inserter(__ndflt), 37044684ddb6SLionel Sambuc __dflt.c_str(), 37054684ddb6SLionel Sambuc __dflt.c_str() + __dflt.size()); 37064684ddb6SLionel Sambuc if (__c != -1) 37074684ddb6SLionel Sambuc __c <<= 1; 37084684ddb6SLionel Sambuc nl_catd __cat = (nl_catd)__c; 37094684ddb6SLionel Sambuc char* __n = catgets(__cat, __set, __msgid, __ndflt.c_str()); 37104684ddb6SLionel Sambuc string_type __w; 37114684ddb6SLionel Sambuc __widen_from_utf8<sizeof(char_type)*__CHAR_BIT__>()(back_inserter(__w), 37124684ddb6SLionel Sambuc __n, __n + strlen(__n)); 37134684ddb6SLionel Sambuc return __w; 3714*0a6a1f1dSLionel Sambuc#else // !_LIBCPP_HAS_CATOPEN 3715*0a6a1f1dSLionel Sambuc return __dflt; 3716*0a6a1f1dSLionel Sambuc#endif // _LIBCPP_HAS_CATOPEN 37174684ddb6SLionel Sambuc} 37184684ddb6SLionel Sambuc 37194684ddb6SLionel Sambuctemplate <class _CharT> 37204684ddb6SLionel Sambucvoid 37214684ddb6SLionel Sambucmessages<_CharT>::do_close(catalog __c) const 37224684ddb6SLionel Sambuc{ 3723*0a6a1f1dSLionel Sambuc#ifdef _LIBCPP_HAS_CATOPEN 37244684ddb6SLionel Sambuc if (__c != -1) 37254684ddb6SLionel Sambuc __c <<= 1; 37264684ddb6SLionel Sambuc nl_catd __cat = (nl_catd)__c; 37274684ddb6SLionel Sambuc catclose(__cat); 3728*0a6a1f1dSLionel Sambuc#endif // _LIBCPP_HAS_CATOPEN 37294684ddb6SLionel Sambuc} 37304684ddb6SLionel Sambuc 37314684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS messages<char>) 37324684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS messages<wchar_t>) 37334684ddb6SLionel Sambuc 37344684ddb6SLionel Sambuctemplate <class _CharT> 37354684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY messages_byname 37364684ddb6SLionel Sambuc : public messages<_CharT> 37374684ddb6SLionel Sambuc{ 37384684ddb6SLionel Sambucpublic: 37394684ddb6SLionel Sambuc typedef messages_base::catalog catalog; 37404684ddb6SLionel Sambuc typedef basic_string<_CharT> string_type; 37414684ddb6SLionel Sambuc 37424684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 37434684ddb6SLionel Sambuc explicit messages_byname(const char*, size_t __refs = 0) 37444684ddb6SLionel Sambuc : messages<_CharT>(__refs) {} 37454684ddb6SLionel Sambuc 37464684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 37474684ddb6SLionel Sambuc explicit messages_byname(const string&, size_t __refs = 0) 37484684ddb6SLionel Sambuc : messages<_CharT>(__refs) {} 37494684ddb6SLionel Sambuc 37504684ddb6SLionel Sambucprotected: 37514684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 37524684ddb6SLionel Sambuc ~messages_byname() {} 37534684ddb6SLionel Sambuc}; 37544684ddb6SLionel Sambuc 37554684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS messages_byname<char>) 37564684ddb6SLionel Sambuc_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS messages_byname<wchar_t>) 37574684ddb6SLionel Sambuc 37584684ddb6SLionel Sambuctemplate<class _Codecvt, class _Elem = wchar_t, 37594684ddb6SLionel Sambuc class _Wide_alloc = allocator<_Elem>, 37604684ddb6SLionel Sambuc class _Byte_alloc = allocator<char> > 37614684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY wstring_convert 37624684ddb6SLionel Sambuc{ 37634684ddb6SLionel Sambucpublic: 37644684ddb6SLionel Sambuc typedef basic_string<char, char_traits<char>, _Byte_alloc> byte_string; 37654684ddb6SLionel Sambuc typedef basic_string<_Elem, char_traits<_Elem>, _Wide_alloc> wide_string; 37664684ddb6SLionel Sambuc typedef typename _Codecvt::state_type state_type; 37674684ddb6SLionel Sambuc typedef typename wide_string::traits_type::int_type int_type; 37684684ddb6SLionel Sambuc 37694684ddb6SLionel Sambucprivate: 37704684ddb6SLionel Sambuc byte_string __byte_err_string_; 37714684ddb6SLionel Sambuc wide_string __wide_err_string_; 37724684ddb6SLionel Sambuc _Codecvt* __cvtptr_; 37734684ddb6SLionel Sambuc state_type __cvtstate_; 37744684ddb6SLionel Sambuc size_t __cvtcount_; 37754684ddb6SLionel Sambuc 37764684ddb6SLionel Sambuc wstring_convert(const wstring_convert& __wc); 37774684ddb6SLionel Sambuc wstring_convert& operator=(const wstring_convert& __wc); 37784684ddb6SLionel Sambucpublic: 37794684ddb6SLionel Sambuc _LIBCPP_EXPLICIT_AFTER_CXX11 wstring_convert(_Codecvt* __pcvt = new _Codecvt); 37804684ddb6SLionel Sambuc wstring_convert(_Codecvt* __pcvt, state_type __state); 37814684ddb6SLionel Sambuc _LIBCPP_EXPLICIT_AFTER_CXX11 wstring_convert(const byte_string& __byte_err, 37824684ddb6SLionel Sambuc const wide_string& __wide_err = wide_string()); 37834684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 37844684ddb6SLionel Sambuc wstring_convert(wstring_convert&& __wc); 37854684ddb6SLionel Sambuc#endif 37864684ddb6SLionel Sambuc ~wstring_convert(); 37874684ddb6SLionel Sambuc 37884684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 37894684ddb6SLionel Sambuc wide_string from_bytes(char __byte) 37904684ddb6SLionel Sambuc {return from_bytes(&__byte, &__byte+1);} 37914684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 37924684ddb6SLionel Sambuc wide_string from_bytes(const char* __ptr) 37934684ddb6SLionel Sambuc {return from_bytes(__ptr, __ptr + char_traits<char>::length(__ptr));} 37944684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 37954684ddb6SLionel Sambuc wide_string from_bytes(const byte_string& __str) 37964684ddb6SLionel Sambuc {return from_bytes(__str.data(), __str.data() + __str.size());} 37974684ddb6SLionel Sambuc wide_string from_bytes(const char* __first, const char* __last); 37984684ddb6SLionel Sambuc 37994684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 38004684ddb6SLionel Sambuc byte_string to_bytes(_Elem __wchar) 38014684ddb6SLionel Sambuc {return to_bytes(&__wchar, &__wchar+1);} 38024684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 38034684ddb6SLionel Sambuc byte_string to_bytes(const _Elem* __wptr) 38044684ddb6SLionel Sambuc {return to_bytes(__wptr, __wptr + char_traits<_Elem>::length(__wptr));} 38054684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 38064684ddb6SLionel Sambuc byte_string to_bytes(const wide_string& __wstr) 38074684ddb6SLionel Sambuc {return to_bytes(__wstr.data(), __wstr.data() + __wstr.size());} 38084684ddb6SLionel Sambuc byte_string to_bytes(const _Elem* __first, const _Elem* __last); 38094684ddb6SLionel Sambuc 38104684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 38114684ddb6SLionel Sambuc size_t converted() const _NOEXCEPT {return __cvtcount_;} 38124684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 38134684ddb6SLionel Sambuc state_type state() const {return __cvtstate_;} 38144684ddb6SLionel Sambuc}; 38154684ddb6SLionel Sambuc 38164684ddb6SLionel Sambuctemplate<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> 38174684ddb6SLionel Sambucinline _LIBCPP_ALWAYS_INLINE 38184684ddb6SLionel Sambucwstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: 38194684ddb6SLionel Sambuc wstring_convert(_Codecvt* __pcvt) 38204684ddb6SLionel Sambuc : __cvtptr_(__pcvt), __cvtstate_(), __cvtcount_(0) 38214684ddb6SLionel Sambuc{ 38224684ddb6SLionel Sambuc} 38234684ddb6SLionel Sambuc 38244684ddb6SLionel Sambuctemplate<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> 38254684ddb6SLionel Sambucinline _LIBCPP_ALWAYS_INLINE 38264684ddb6SLionel Sambucwstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: 38274684ddb6SLionel Sambuc wstring_convert(_Codecvt* __pcvt, state_type __state) 38284684ddb6SLionel Sambuc : __cvtptr_(__pcvt), __cvtstate_(__state), __cvtcount_(0) 38294684ddb6SLionel Sambuc{ 38304684ddb6SLionel Sambuc} 38314684ddb6SLionel Sambuc 38324684ddb6SLionel Sambuctemplate<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> 38334684ddb6SLionel Sambucwstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: 38344684ddb6SLionel Sambuc wstring_convert(const byte_string& __byte_err, const wide_string& __wide_err) 38354684ddb6SLionel Sambuc : __byte_err_string_(__byte_err), __wide_err_string_(__wide_err), 38364684ddb6SLionel Sambuc __cvtstate_(), __cvtcount_(0) 38374684ddb6SLionel Sambuc{ 38384684ddb6SLionel Sambuc __cvtptr_ = new _Codecvt; 38394684ddb6SLionel Sambuc} 38404684ddb6SLionel Sambuc 38414684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 38424684ddb6SLionel Sambuc 38434684ddb6SLionel Sambuctemplate<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> 38444684ddb6SLionel Sambucinline _LIBCPP_ALWAYS_INLINE 38454684ddb6SLionel Sambucwstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: 38464684ddb6SLionel Sambuc wstring_convert(wstring_convert&& __wc) 38474684ddb6SLionel Sambuc : __byte_err_string_(_VSTD::move(__wc.__byte_err_string_)), 38484684ddb6SLionel Sambuc __wide_err_string_(_VSTD::move(__wc.__wide_err_string_)), 38494684ddb6SLionel Sambuc __cvtptr_(__wc.__cvtptr_), 38504684ddb6SLionel Sambuc __cvtstate_(__wc.__cvtstate_), __cvtcount_(__wc.__cvtstate_) 38514684ddb6SLionel Sambuc{ 38524684ddb6SLionel Sambuc __wc.__cvtptr_ = nullptr; 38534684ddb6SLionel Sambuc} 38544684ddb6SLionel Sambuc 38554684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 38564684ddb6SLionel Sambuc 38574684ddb6SLionel Sambuctemplate<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> 38584684ddb6SLionel Sambucwstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::~wstring_convert() 38594684ddb6SLionel Sambuc{ 38604684ddb6SLionel Sambuc delete __cvtptr_; 38614684ddb6SLionel Sambuc} 38624684ddb6SLionel Sambuc 38634684ddb6SLionel Sambuctemplate<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> 38644684ddb6SLionel Sambuctypename wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::wide_string 38654684ddb6SLionel Sambucwstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: 38664684ddb6SLionel Sambuc from_bytes(const char* __frm, const char* __frm_end) 38674684ddb6SLionel Sambuc{ 38684684ddb6SLionel Sambuc __cvtcount_ = 0; 38694684ddb6SLionel Sambuc if (__cvtptr_ != nullptr) 38704684ddb6SLionel Sambuc { 38714684ddb6SLionel Sambuc wide_string __ws(2*(__frm_end - __frm), _Elem()); 38724684ddb6SLionel Sambuc if (__frm != __frm_end) 38734684ddb6SLionel Sambuc __ws.resize(__ws.capacity()); 38744684ddb6SLionel Sambuc codecvt_base::result __r = codecvt_base::ok; 38754684ddb6SLionel Sambuc state_type __st = __cvtstate_; 38764684ddb6SLionel Sambuc if (__frm != __frm_end) 38774684ddb6SLionel Sambuc { 38784684ddb6SLionel Sambuc _Elem* __to = &__ws[0]; 38794684ddb6SLionel Sambuc _Elem* __to_end = __to + __ws.size(); 38804684ddb6SLionel Sambuc const char* __frm_nxt; 38814684ddb6SLionel Sambuc do 38824684ddb6SLionel Sambuc { 38834684ddb6SLionel Sambuc _Elem* __to_nxt; 38844684ddb6SLionel Sambuc __r = __cvtptr_->in(__st, __frm, __frm_end, __frm_nxt, 38854684ddb6SLionel Sambuc __to, __to_end, __to_nxt); 38864684ddb6SLionel Sambuc __cvtcount_ += __frm_nxt - __frm; 38874684ddb6SLionel Sambuc if (__frm_nxt == __frm) 38884684ddb6SLionel Sambuc { 38894684ddb6SLionel Sambuc __r = codecvt_base::error; 38904684ddb6SLionel Sambuc } 38914684ddb6SLionel Sambuc else if (__r == codecvt_base::noconv) 38924684ddb6SLionel Sambuc { 38934684ddb6SLionel Sambuc __ws.resize(__to - &__ws[0]); 38944684ddb6SLionel Sambuc // This only gets executed if _Elem is char 38954684ddb6SLionel Sambuc __ws.append((const _Elem*)__frm, (const _Elem*)__frm_end); 38964684ddb6SLionel Sambuc __frm = __frm_nxt; 38974684ddb6SLionel Sambuc __r = codecvt_base::ok; 38984684ddb6SLionel Sambuc } 38994684ddb6SLionel Sambuc else if (__r == codecvt_base::ok) 39004684ddb6SLionel Sambuc { 39014684ddb6SLionel Sambuc __ws.resize(__to_nxt - &__ws[0]); 39024684ddb6SLionel Sambuc __frm = __frm_nxt; 39034684ddb6SLionel Sambuc } 39044684ddb6SLionel Sambuc else if (__r == codecvt_base::partial) 39054684ddb6SLionel Sambuc { 39064684ddb6SLionel Sambuc ptrdiff_t __s = __to_nxt - &__ws[0]; 39074684ddb6SLionel Sambuc __ws.resize(2 * __s); 39084684ddb6SLionel Sambuc __to = &__ws[0] + __s; 39094684ddb6SLionel Sambuc __to_end = &__ws[0] + __ws.size(); 39104684ddb6SLionel Sambuc __frm = __frm_nxt; 39114684ddb6SLionel Sambuc } 39124684ddb6SLionel Sambuc } while (__r == codecvt_base::partial && __frm_nxt < __frm_end); 39134684ddb6SLionel Sambuc } 39144684ddb6SLionel Sambuc if (__r == codecvt_base::ok) 39154684ddb6SLionel Sambuc return __ws; 39164684ddb6SLionel Sambuc } 39174684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 39184684ddb6SLionel Sambuc if (__wide_err_string_.empty()) 39194684ddb6SLionel Sambuc throw range_error("wstring_convert: from_bytes error"); 39204684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 39214684ddb6SLionel Sambuc return __wide_err_string_; 39224684ddb6SLionel Sambuc} 39234684ddb6SLionel Sambuc 39244684ddb6SLionel Sambuctemplate<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> 39254684ddb6SLionel Sambuctypename wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::byte_string 39264684ddb6SLionel Sambucwstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>:: 39274684ddb6SLionel Sambuc to_bytes(const _Elem* __frm, const _Elem* __frm_end) 39284684ddb6SLionel Sambuc{ 39294684ddb6SLionel Sambuc __cvtcount_ = 0; 39304684ddb6SLionel Sambuc if (__cvtptr_ != nullptr) 39314684ddb6SLionel Sambuc { 39324684ddb6SLionel Sambuc byte_string __bs(2*(__frm_end - __frm), char()); 39334684ddb6SLionel Sambuc if (__frm != __frm_end) 39344684ddb6SLionel Sambuc __bs.resize(__bs.capacity()); 39354684ddb6SLionel Sambuc codecvt_base::result __r = codecvt_base::ok; 39364684ddb6SLionel Sambuc state_type __st = __cvtstate_; 39374684ddb6SLionel Sambuc if (__frm != __frm_end) 39384684ddb6SLionel Sambuc { 39394684ddb6SLionel Sambuc char* __to = &__bs[0]; 39404684ddb6SLionel Sambuc char* __to_end = __to + __bs.size(); 39414684ddb6SLionel Sambuc const _Elem* __frm_nxt; 39424684ddb6SLionel Sambuc do 39434684ddb6SLionel Sambuc { 39444684ddb6SLionel Sambuc char* __to_nxt; 39454684ddb6SLionel Sambuc __r = __cvtptr_->out(__st, __frm, __frm_end, __frm_nxt, 39464684ddb6SLionel Sambuc __to, __to_end, __to_nxt); 39474684ddb6SLionel Sambuc __cvtcount_ += __frm_nxt - __frm; 39484684ddb6SLionel Sambuc if (__frm_nxt == __frm) 39494684ddb6SLionel Sambuc { 39504684ddb6SLionel Sambuc __r = codecvt_base::error; 39514684ddb6SLionel Sambuc } 39524684ddb6SLionel Sambuc else if (__r == codecvt_base::noconv) 39534684ddb6SLionel Sambuc { 39544684ddb6SLionel Sambuc __bs.resize(__to - &__bs[0]); 39554684ddb6SLionel Sambuc // This only gets executed if _Elem is char 39564684ddb6SLionel Sambuc __bs.append((const char*)__frm, (const char*)__frm_end); 39574684ddb6SLionel Sambuc __frm = __frm_nxt; 39584684ddb6SLionel Sambuc __r = codecvt_base::ok; 39594684ddb6SLionel Sambuc } 39604684ddb6SLionel Sambuc else if (__r == codecvt_base::ok) 39614684ddb6SLionel Sambuc { 39624684ddb6SLionel Sambuc __bs.resize(__to_nxt - &__bs[0]); 39634684ddb6SLionel Sambuc __frm = __frm_nxt; 39644684ddb6SLionel Sambuc } 39654684ddb6SLionel Sambuc else if (__r == codecvt_base::partial) 39664684ddb6SLionel Sambuc { 39674684ddb6SLionel Sambuc ptrdiff_t __s = __to_nxt - &__bs[0]; 39684684ddb6SLionel Sambuc __bs.resize(2 * __s); 39694684ddb6SLionel Sambuc __to = &__bs[0] + __s; 39704684ddb6SLionel Sambuc __to_end = &__bs[0] + __bs.size(); 39714684ddb6SLionel Sambuc __frm = __frm_nxt; 39724684ddb6SLionel Sambuc } 39734684ddb6SLionel Sambuc } while (__r == codecvt_base::partial && __frm_nxt < __frm_end); 39744684ddb6SLionel Sambuc } 39754684ddb6SLionel Sambuc if (__r == codecvt_base::ok) 39764684ddb6SLionel Sambuc { 39774684ddb6SLionel Sambuc size_t __s = __bs.size(); 39784684ddb6SLionel Sambuc __bs.resize(__bs.capacity()); 39794684ddb6SLionel Sambuc char* __to = &__bs[0] + __s; 39804684ddb6SLionel Sambuc char* __to_end = __to + __bs.size(); 39814684ddb6SLionel Sambuc do 39824684ddb6SLionel Sambuc { 39834684ddb6SLionel Sambuc char* __to_nxt; 39844684ddb6SLionel Sambuc __r = __cvtptr_->unshift(__st, __to, __to_end, __to_nxt); 39854684ddb6SLionel Sambuc if (__r == codecvt_base::noconv) 39864684ddb6SLionel Sambuc { 39874684ddb6SLionel Sambuc __bs.resize(__to - &__bs[0]); 39884684ddb6SLionel Sambuc __r = codecvt_base::ok; 39894684ddb6SLionel Sambuc } 39904684ddb6SLionel Sambuc else if (__r == codecvt_base::ok) 39914684ddb6SLionel Sambuc { 39924684ddb6SLionel Sambuc __bs.resize(__to_nxt - &__bs[0]); 39934684ddb6SLionel Sambuc } 39944684ddb6SLionel Sambuc else if (__r == codecvt_base::partial) 39954684ddb6SLionel Sambuc { 39964684ddb6SLionel Sambuc ptrdiff_t __sp = __to_nxt - &__bs[0]; 39974684ddb6SLionel Sambuc __bs.resize(2 * __sp); 39984684ddb6SLionel Sambuc __to = &__bs[0] + __sp; 39994684ddb6SLionel Sambuc __to_end = &__bs[0] + __bs.size(); 40004684ddb6SLionel Sambuc } 40014684ddb6SLionel Sambuc } while (__r == codecvt_base::partial); 40024684ddb6SLionel Sambuc if (__r == codecvt_base::ok) 40034684ddb6SLionel Sambuc return __bs; 40044684ddb6SLionel Sambuc } 40054684ddb6SLionel Sambuc } 40064684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 40074684ddb6SLionel Sambuc if (__byte_err_string_.empty()) 40084684ddb6SLionel Sambuc throw range_error("wstring_convert: to_bytes error"); 40094684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 40104684ddb6SLionel Sambuc return __byte_err_string_; 40114684ddb6SLionel Sambuc} 40124684ddb6SLionel Sambuc 40134684ddb6SLionel Sambuctemplate <class _Codecvt, class _Elem = wchar_t, class _Tr = char_traits<_Elem> > 40144684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY wbuffer_convert 40154684ddb6SLionel Sambuc : public basic_streambuf<_Elem, _Tr> 40164684ddb6SLionel Sambuc{ 40174684ddb6SLionel Sambucpublic: 40184684ddb6SLionel Sambuc // types: 40194684ddb6SLionel Sambuc typedef _Elem char_type; 40204684ddb6SLionel Sambuc typedef _Tr traits_type; 40214684ddb6SLionel Sambuc typedef typename traits_type::int_type int_type; 40224684ddb6SLionel Sambuc typedef typename traits_type::pos_type pos_type; 40234684ddb6SLionel Sambuc typedef typename traits_type::off_type off_type; 40244684ddb6SLionel Sambuc typedef typename _Codecvt::state_type state_type; 40254684ddb6SLionel Sambuc 40264684ddb6SLionel Sambucprivate: 40274684ddb6SLionel Sambuc char* __extbuf_; 40284684ddb6SLionel Sambuc const char* __extbufnext_; 40294684ddb6SLionel Sambuc const char* __extbufend_; 40304684ddb6SLionel Sambuc char __extbuf_min_[8]; 40314684ddb6SLionel Sambuc size_t __ebs_; 40324684ddb6SLionel Sambuc char_type* __intbuf_; 40334684ddb6SLionel Sambuc size_t __ibs_; 40344684ddb6SLionel Sambuc streambuf* __bufptr_; 40354684ddb6SLionel Sambuc _Codecvt* __cv_; 40364684ddb6SLionel Sambuc state_type __st_; 40374684ddb6SLionel Sambuc ios_base::openmode __cm_; 40384684ddb6SLionel Sambuc bool __owns_eb_; 40394684ddb6SLionel Sambuc bool __owns_ib_; 40404684ddb6SLionel Sambuc bool __always_noconv_; 40414684ddb6SLionel Sambuc 40424684ddb6SLionel Sambuc wbuffer_convert(const wbuffer_convert&); 40434684ddb6SLionel Sambuc wbuffer_convert& operator=(const wbuffer_convert&); 40444684ddb6SLionel Sambucpublic: 40454684ddb6SLionel Sambuc _LIBCPP_EXPLICIT_AFTER_CXX11 wbuffer_convert(streambuf* __bytebuf = 0, 40464684ddb6SLionel Sambuc _Codecvt* __pcvt = new _Codecvt, state_type __state = state_type()); 40474684ddb6SLionel Sambuc ~wbuffer_convert(); 40484684ddb6SLionel Sambuc 40494684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 40504684ddb6SLionel Sambuc streambuf* rdbuf() const {return __bufptr_;} 40514684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 40524684ddb6SLionel Sambuc streambuf* rdbuf(streambuf* __bytebuf) 40534684ddb6SLionel Sambuc { 40544684ddb6SLionel Sambuc streambuf* __r = __bufptr_; 40554684ddb6SLionel Sambuc __bufptr_ = __bytebuf; 40564684ddb6SLionel Sambuc return __r; 40574684ddb6SLionel Sambuc } 40584684ddb6SLionel Sambuc 40594684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 40604684ddb6SLionel Sambuc state_type state() const {return __st_;} 40614684ddb6SLionel Sambuc 40624684ddb6SLionel Sambucprotected: 40634684ddb6SLionel Sambuc virtual int_type underflow(); 40644684ddb6SLionel Sambuc virtual int_type pbackfail(int_type __c = traits_type::eof()); 40654684ddb6SLionel Sambuc virtual int_type overflow (int_type __c = traits_type::eof()); 40664684ddb6SLionel Sambuc virtual basic_streambuf<char_type, traits_type>* setbuf(char_type* __s, 40674684ddb6SLionel Sambuc streamsize __n); 40684684ddb6SLionel Sambuc virtual pos_type seekoff(off_type __off, ios_base::seekdir __way, 40694684ddb6SLionel Sambuc ios_base::openmode __wch = ios_base::in | ios_base::out); 40704684ddb6SLionel Sambuc virtual pos_type seekpos(pos_type __sp, 40714684ddb6SLionel Sambuc ios_base::openmode __wch = ios_base::in | ios_base::out); 40724684ddb6SLionel Sambuc virtual int sync(); 40734684ddb6SLionel Sambuc 40744684ddb6SLionel Sambucprivate: 40754684ddb6SLionel Sambuc bool __read_mode(); 40764684ddb6SLionel Sambuc void __write_mode(); 40774684ddb6SLionel Sambuc wbuffer_convert* __close(); 40784684ddb6SLionel Sambuc}; 40794684ddb6SLionel Sambuc 40804684ddb6SLionel Sambuctemplate <class _Codecvt, class _Elem, class _Tr> 40814684ddb6SLionel Sambucwbuffer_convert<_Codecvt, _Elem, _Tr>:: 40824684ddb6SLionel Sambuc wbuffer_convert(streambuf* __bytebuf, _Codecvt* __pcvt, state_type __state) 40834684ddb6SLionel Sambuc : __extbuf_(0), 40844684ddb6SLionel Sambuc __extbufnext_(0), 40854684ddb6SLionel Sambuc __extbufend_(0), 40864684ddb6SLionel Sambuc __ebs_(0), 40874684ddb6SLionel Sambuc __intbuf_(0), 40884684ddb6SLionel Sambuc __ibs_(0), 40894684ddb6SLionel Sambuc __bufptr_(__bytebuf), 40904684ddb6SLionel Sambuc __cv_(__pcvt), 40914684ddb6SLionel Sambuc __st_(__state), 40924684ddb6SLionel Sambuc __cm_(0), 40934684ddb6SLionel Sambuc __owns_eb_(false), 40944684ddb6SLionel Sambuc __owns_ib_(false), 40954684ddb6SLionel Sambuc __always_noconv_(__cv_ ? __cv_->always_noconv() : false) 40964684ddb6SLionel Sambuc{ 40974684ddb6SLionel Sambuc setbuf(0, 4096); 40984684ddb6SLionel Sambuc} 40994684ddb6SLionel Sambuc 41004684ddb6SLionel Sambuctemplate <class _Codecvt, class _Elem, class _Tr> 41014684ddb6SLionel Sambucwbuffer_convert<_Codecvt, _Elem, _Tr>::~wbuffer_convert() 41024684ddb6SLionel Sambuc{ 41034684ddb6SLionel Sambuc __close(); 41044684ddb6SLionel Sambuc delete __cv_; 41054684ddb6SLionel Sambuc if (__owns_eb_) 41064684ddb6SLionel Sambuc delete [] __extbuf_; 41074684ddb6SLionel Sambuc if (__owns_ib_) 41084684ddb6SLionel Sambuc delete [] __intbuf_; 41094684ddb6SLionel Sambuc} 41104684ddb6SLionel Sambuc 41114684ddb6SLionel Sambuctemplate <class _Codecvt, class _Elem, class _Tr> 41124684ddb6SLionel Sambuctypename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type 41134684ddb6SLionel Sambucwbuffer_convert<_Codecvt, _Elem, _Tr>::underflow() 41144684ddb6SLionel Sambuc{ 41154684ddb6SLionel Sambuc if (__cv_ == 0 || __bufptr_ == 0) 41164684ddb6SLionel Sambuc return traits_type::eof(); 41174684ddb6SLionel Sambuc bool __initial = __read_mode(); 41184684ddb6SLionel Sambuc char_type __1buf; 41194684ddb6SLionel Sambuc if (this->gptr() == 0) 41204684ddb6SLionel Sambuc this->setg(&__1buf, &__1buf+1, &__1buf+1); 41214684ddb6SLionel Sambuc const size_t __unget_sz = __initial ? 0 : min<size_t>((this->egptr() - this->eback()) / 2, 4); 41224684ddb6SLionel Sambuc int_type __c = traits_type::eof(); 41234684ddb6SLionel Sambuc if (this->gptr() == this->egptr()) 41244684ddb6SLionel Sambuc { 41254684ddb6SLionel Sambuc memmove(this->eback(), this->egptr() - __unget_sz, __unget_sz * sizeof(char_type)); 41264684ddb6SLionel Sambuc if (__always_noconv_) 41274684ddb6SLionel Sambuc { 41284684ddb6SLionel Sambuc streamsize __nmemb = static_cast<streamsize>(this->egptr() - this->eback() - __unget_sz); 41294684ddb6SLionel Sambuc __nmemb = __bufptr_->sgetn((char*)this->eback() + __unget_sz, __nmemb); 41304684ddb6SLionel Sambuc if (__nmemb != 0) 41314684ddb6SLionel Sambuc { 41324684ddb6SLionel Sambuc this->setg(this->eback(), 41334684ddb6SLionel Sambuc this->eback() + __unget_sz, 41344684ddb6SLionel Sambuc this->eback() + __unget_sz + __nmemb); 41354684ddb6SLionel Sambuc __c = *this->gptr(); 41364684ddb6SLionel Sambuc } 41374684ddb6SLionel Sambuc } 41384684ddb6SLionel Sambuc else 41394684ddb6SLionel Sambuc { 41404684ddb6SLionel Sambuc memmove(__extbuf_, __extbufnext_, __extbufend_ - __extbufnext_); 41414684ddb6SLionel Sambuc __extbufnext_ = __extbuf_ + (__extbufend_ - __extbufnext_); 41424684ddb6SLionel Sambuc __extbufend_ = __extbuf_ + (__extbuf_ == __extbuf_min_ ? sizeof(__extbuf_min_) : __ebs_); 41434684ddb6SLionel Sambuc streamsize __nmemb = _VSTD::min(static_cast<streamsize>(this->egptr() - this->eback() - __unget_sz), 41444684ddb6SLionel Sambuc static_cast<streamsize>(__extbufend_ - __extbufnext_)); 41454684ddb6SLionel Sambuc codecvt_base::result __r; 41464684ddb6SLionel Sambuc state_type __svs = __st_; 41474684ddb6SLionel Sambuc streamsize __nr = __bufptr_->sgetn(const_cast<char*>(__extbufnext_), __nmemb); 41484684ddb6SLionel Sambuc if (__nr != 0) 41494684ddb6SLionel Sambuc { 41504684ddb6SLionel Sambuc __extbufend_ = __extbufnext_ + __nr; 41514684ddb6SLionel Sambuc char_type* __inext; 41524684ddb6SLionel Sambuc __r = __cv_->in(__st_, __extbuf_, __extbufend_, __extbufnext_, 41534684ddb6SLionel Sambuc this->eback() + __unget_sz, 41544684ddb6SLionel Sambuc this->egptr(), __inext); 41554684ddb6SLionel Sambuc if (__r == codecvt_base::noconv) 41564684ddb6SLionel Sambuc { 41574684ddb6SLionel Sambuc this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, (char_type*)__extbufend_); 41584684ddb6SLionel Sambuc __c = *this->gptr(); 41594684ddb6SLionel Sambuc } 41604684ddb6SLionel Sambuc else if (__inext != this->eback() + __unget_sz) 41614684ddb6SLionel Sambuc { 41624684ddb6SLionel Sambuc this->setg(this->eback(), this->eback() + __unget_sz, __inext); 41634684ddb6SLionel Sambuc __c = *this->gptr(); 41644684ddb6SLionel Sambuc } 41654684ddb6SLionel Sambuc } 41664684ddb6SLionel Sambuc } 41674684ddb6SLionel Sambuc } 41684684ddb6SLionel Sambuc else 41694684ddb6SLionel Sambuc __c = *this->gptr(); 41704684ddb6SLionel Sambuc if (this->eback() == &__1buf) 41714684ddb6SLionel Sambuc this->setg(0, 0, 0); 41724684ddb6SLionel Sambuc return __c; 41734684ddb6SLionel Sambuc} 41744684ddb6SLionel Sambuc 41754684ddb6SLionel Sambuctemplate <class _Codecvt, class _Elem, class _Tr> 41764684ddb6SLionel Sambuctypename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type 41774684ddb6SLionel Sambucwbuffer_convert<_Codecvt, _Elem, _Tr>::pbackfail(int_type __c) 41784684ddb6SLionel Sambuc{ 41794684ddb6SLionel Sambuc if (__cv_ != 0 && __bufptr_ != 0 && this->eback() < this->gptr()) 41804684ddb6SLionel Sambuc { 41814684ddb6SLionel Sambuc if (traits_type::eq_int_type(__c, traits_type::eof())) 41824684ddb6SLionel Sambuc { 41834684ddb6SLionel Sambuc this->gbump(-1); 41844684ddb6SLionel Sambuc return traits_type::not_eof(__c); 41854684ddb6SLionel Sambuc } 41864684ddb6SLionel Sambuc if (traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) 41874684ddb6SLionel Sambuc { 41884684ddb6SLionel Sambuc this->gbump(-1); 41894684ddb6SLionel Sambuc *this->gptr() = traits_type::to_char_type(__c); 41904684ddb6SLionel Sambuc return __c; 41914684ddb6SLionel Sambuc } 41924684ddb6SLionel Sambuc } 41934684ddb6SLionel Sambuc return traits_type::eof(); 41944684ddb6SLionel Sambuc} 41954684ddb6SLionel Sambuc 41964684ddb6SLionel Sambuctemplate <class _Codecvt, class _Elem, class _Tr> 41974684ddb6SLionel Sambuctypename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type 41984684ddb6SLionel Sambucwbuffer_convert<_Codecvt, _Elem, _Tr>::overflow(int_type __c) 41994684ddb6SLionel Sambuc{ 42004684ddb6SLionel Sambuc if (__cv_ == 0 || __bufptr_ == 0) 42014684ddb6SLionel Sambuc return traits_type::eof(); 42024684ddb6SLionel Sambuc __write_mode(); 42034684ddb6SLionel Sambuc char_type __1buf; 42044684ddb6SLionel Sambuc char_type* __pb_save = this->pbase(); 42054684ddb6SLionel Sambuc char_type* __epb_save = this->epptr(); 42064684ddb6SLionel Sambuc if (!traits_type::eq_int_type(__c, traits_type::eof())) 42074684ddb6SLionel Sambuc { 42084684ddb6SLionel Sambuc if (this->pptr() == 0) 42094684ddb6SLionel Sambuc this->setp(&__1buf, &__1buf+1); 42104684ddb6SLionel Sambuc *this->pptr() = traits_type::to_char_type(__c); 42114684ddb6SLionel Sambuc this->pbump(1); 42124684ddb6SLionel Sambuc } 42134684ddb6SLionel Sambuc if (this->pptr() != this->pbase()) 42144684ddb6SLionel Sambuc { 42154684ddb6SLionel Sambuc if (__always_noconv_) 42164684ddb6SLionel Sambuc { 42174684ddb6SLionel Sambuc streamsize __nmemb = static_cast<streamsize>(this->pptr() - this->pbase()); 42184684ddb6SLionel Sambuc if (__bufptr_->sputn((const char*)this->pbase(), __nmemb) != __nmemb) 42194684ddb6SLionel Sambuc return traits_type::eof(); 42204684ddb6SLionel Sambuc } 42214684ddb6SLionel Sambuc else 42224684ddb6SLionel Sambuc { 42234684ddb6SLionel Sambuc char* __extbe = __extbuf_; 42244684ddb6SLionel Sambuc codecvt_base::result __r; 42254684ddb6SLionel Sambuc do 42264684ddb6SLionel Sambuc { 42274684ddb6SLionel Sambuc const char_type* __e; 42284684ddb6SLionel Sambuc __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e, 42294684ddb6SLionel Sambuc __extbuf_, __extbuf_ + __ebs_, __extbe); 42304684ddb6SLionel Sambuc if (__e == this->pbase()) 42314684ddb6SLionel Sambuc return traits_type::eof(); 42324684ddb6SLionel Sambuc if (__r == codecvt_base::noconv) 42334684ddb6SLionel Sambuc { 42344684ddb6SLionel Sambuc streamsize __nmemb = static_cast<size_t>(this->pptr() - this->pbase()); 42354684ddb6SLionel Sambuc if (__bufptr_->sputn((const char*)this->pbase(), __nmemb) != __nmemb) 42364684ddb6SLionel Sambuc return traits_type::eof(); 42374684ddb6SLionel Sambuc } 42384684ddb6SLionel Sambuc else if (__r == codecvt_base::ok || __r == codecvt_base::partial) 42394684ddb6SLionel Sambuc { 42404684ddb6SLionel Sambuc streamsize __nmemb = static_cast<size_t>(__extbe - __extbuf_); 42414684ddb6SLionel Sambuc if (__bufptr_->sputn(__extbuf_, __nmemb) != __nmemb) 42424684ddb6SLionel Sambuc return traits_type::eof(); 42434684ddb6SLionel Sambuc if (__r == codecvt_base::partial) 42444684ddb6SLionel Sambuc { 42454684ddb6SLionel Sambuc this->setp((char_type*)__e, this->pptr()); 42464684ddb6SLionel Sambuc this->pbump(this->epptr() - this->pbase()); 42474684ddb6SLionel Sambuc } 42484684ddb6SLionel Sambuc } 42494684ddb6SLionel Sambuc else 42504684ddb6SLionel Sambuc return traits_type::eof(); 42514684ddb6SLionel Sambuc } while (__r == codecvt_base::partial); 42524684ddb6SLionel Sambuc } 42534684ddb6SLionel Sambuc this->setp(__pb_save, __epb_save); 42544684ddb6SLionel Sambuc } 42554684ddb6SLionel Sambuc return traits_type::not_eof(__c); 42564684ddb6SLionel Sambuc} 42574684ddb6SLionel Sambuc 42584684ddb6SLionel Sambuctemplate <class _Codecvt, class _Elem, class _Tr> 42594684ddb6SLionel Sambucbasic_streambuf<_Elem, _Tr>* 42604684ddb6SLionel Sambucwbuffer_convert<_Codecvt, _Elem, _Tr>::setbuf(char_type* __s, streamsize __n) 42614684ddb6SLionel Sambuc{ 42624684ddb6SLionel Sambuc this->setg(0, 0, 0); 42634684ddb6SLionel Sambuc this->setp(0, 0); 42644684ddb6SLionel Sambuc if (__owns_eb_) 42654684ddb6SLionel Sambuc delete [] __extbuf_; 42664684ddb6SLionel Sambuc if (__owns_ib_) 42674684ddb6SLionel Sambuc delete [] __intbuf_; 42684684ddb6SLionel Sambuc __ebs_ = __n; 42694684ddb6SLionel Sambuc if (__ebs_ > sizeof(__extbuf_min_)) 42704684ddb6SLionel Sambuc { 42714684ddb6SLionel Sambuc if (__always_noconv_ && __s) 42724684ddb6SLionel Sambuc { 42734684ddb6SLionel Sambuc __extbuf_ = (char*)__s; 42744684ddb6SLionel Sambuc __owns_eb_ = false; 42754684ddb6SLionel Sambuc } 42764684ddb6SLionel Sambuc else 42774684ddb6SLionel Sambuc { 42784684ddb6SLionel Sambuc __extbuf_ = new char[__ebs_]; 42794684ddb6SLionel Sambuc __owns_eb_ = true; 42804684ddb6SLionel Sambuc } 42814684ddb6SLionel Sambuc } 42824684ddb6SLionel Sambuc else 42834684ddb6SLionel Sambuc { 42844684ddb6SLionel Sambuc __extbuf_ = __extbuf_min_; 42854684ddb6SLionel Sambuc __ebs_ = sizeof(__extbuf_min_); 42864684ddb6SLionel Sambuc __owns_eb_ = false; 42874684ddb6SLionel Sambuc } 42884684ddb6SLionel Sambuc if (!__always_noconv_) 42894684ddb6SLionel Sambuc { 42904684ddb6SLionel Sambuc __ibs_ = max<streamsize>(__n, sizeof(__extbuf_min_)); 42914684ddb6SLionel Sambuc if (__s && __ibs_ >= sizeof(__extbuf_min_)) 42924684ddb6SLionel Sambuc { 42934684ddb6SLionel Sambuc __intbuf_ = __s; 42944684ddb6SLionel Sambuc __owns_ib_ = false; 42954684ddb6SLionel Sambuc } 42964684ddb6SLionel Sambuc else 42974684ddb6SLionel Sambuc { 42984684ddb6SLionel Sambuc __intbuf_ = new char_type[__ibs_]; 42994684ddb6SLionel Sambuc __owns_ib_ = true; 43004684ddb6SLionel Sambuc } 43014684ddb6SLionel Sambuc } 43024684ddb6SLionel Sambuc else 43034684ddb6SLionel Sambuc { 43044684ddb6SLionel Sambuc __ibs_ = 0; 43054684ddb6SLionel Sambuc __intbuf_ = 0; 43064684ddb6SLionel Sambuc __owns_ib_ = false; 43074684ddb6SLionel Sambuc } 43084684ddb6SLionel Sambuc return this; 43094684ddb6SLionel Sambuc} 43104684ddb6SLionel Sambuc 43114684ddb6SLionel Sambuctemplate <class _Codecvt, class _Elem, class _Tr> 43124684ddb6SLionel Sambuctypename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type 43134684ddb6SLionel Sambucwbuffer_convert<_Codecvt, _Elem, _Tr>::seekoff(off_type __off, ios_base::seekdir __way, 43144684ddb6SLionel Sambuc ios_base::openmode __om) 43154684ddb6SLionel Sambuc{ 43164684ddb6SLionel Sambuc int __width = __cv_->encoding(); 43174684ddb6SLionel Sambuc if (__cv_ == 0 || __bufptr_ == 0 || (__width <= 0 && __off != 0) || sync()) 43184684ddb6SLionel Sambuc return pos_type(off_type(-1)); 43194684ddb6SLionel Sambuc // __width > 0 || __off == 0 43204684ddb6SLionel Sambuc switch (__way) 43214684ddb6SLionel Sambuc { 43224684ddb6SLionel Sambuc case ios_base::beg: 43234684ddb6SLionel Sambuc break; 43244684ddb6SLionel Sambuc case ios_base::cur: 43254684ddb6SLionel Sambuc break; 43264684ddb6SLionel Sambuc case ios_base::end: 43274684ddb6SLionel Sambuc break; 43284684ddb6SLionel Sambuc default: 43294684ddb6SLionel Sambuc return pos_type(off_type(-1)); 43304684ddb6SLionel Sambuc } 43314684ddb6SLionel Sambuc pos_type __r = __bufptr_->pubseekoff(__width * __off, __way, __om); 43324684ddb6SLionel Sambuc __r.state(__st_); 43334684ddb6SLionel Sambuc return __r; 43344684ddb6SLionel Sambuc} 43354684ddb6SLionel Sambuc 43364684ddb6SLionel Sambuctemplate <class _Codecvt, class _Elem, class _Tr> 43374684ddb6SLionel Sambuctypename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type 43384684ddb6SLionel Sambucwbuffer_convert<_Codecvt, _Elem, _Tr>::seekpos(pos_type __sp, ios_base::openmode __wch) 43394684ddb6SLionel Sambuc{ 43404684ddb6SLionel Sambuc if (__cv_ == 0 || __bufptr_ == 0 || sync()) 43414684ddb6SLionel Sambuc return pos_type(off_type(-1)); 43424684ddb6SLionel Sambuc if (__bufptr_->pubseekpos(__sp, __wch) == pos_type(off_type(-1))) 43434684ddb6SLionel Sambuc return pos_type(off_type(-1)); 43444684ddb6SLionel Sambuc return __sp; 43454684ddb6SLionel Sambuc} 43464684ddb6SLionel Sambuc 43474684ddb6SLionel Sambuctemplate <class _Codecvt, class _Elem, class _Tr> 43484684ddb6SLionel Sambucint 43494684ddb6SLionel Sambucwbuffer_convert<_Codecvt, _Elem, _Tr>::sync() 43504684ddb6SLionel Sambuc{ 43514684ddb6SLionel Sambuc if (__cv_ == 0 || __bufptr_ == 0) 43524684ddb6SLionel Sambuc return 0; 43534684ddb6SLionel Sambuc if (__cm_ & ios_base::out) 43544684ddb6SLionel Sambuc { 43554684ddb6SLionel Sambuc if (this->pptr() != this->pbase()) 43564684ddb6SLionel Sambuc if (overflow() == traits_type::eof()) 43574684ddb6SLionel Sambuc return -1; 43584684ddb6SLionel Sambuc codecvt_base::result __r; 43594684ddb6SLionel Sambuc do 43604684ddb6SLionel Sambuc { 43614684ddb6SLionel Sambuc char* __extbe; 43624684ddb6SLionel Sambuc __r = __cv_->unshift(__st_, __extbuf_, __extbuf_ + __ebs_, __extbe); 43634684ddb6SLionel Sambuc streamsize __nmemb = static_cast<streamsize>(__extbe - __extbuf_); 43644684ddb6SLionel Sambuc if (__bufptr_->sputn(__extbuf_, __nmemb) != __nmemb) 43654684ddb6SLionel Sambuc return -1; 43664684ddb6SLionel Sambuc } while (__r == codecvt_base::partial); 43674684ddb6SLionel Sambuc if (__r == codecvt_base::error) 43684684ddb6SLionel Sambuc return -1; 43694684ddb6SLionel Sambuc if (__bufptr_->pubsync()) 43704684ddb6SLionel Sambuc return -1; 43714684ddb6SLionel Sambuc } 43724684ddb6SLionel Sambuc else if (__cm_ & ios_base::in) 43734684ddb6SLionel Sambuc { 43744684ddb6SLionel Sambuc off_type __c; 43754684ddb6SLionel Sambuc if (__always_noconv_) 43764684ddb6SLionel Sambuc __c = this->egptr() - this->gptr(); 43774684ddb6SLionel Sambuc else 43784684ddb6SLionel Sambuc { 43794684ddb6SLionel Sambuc int __width = __cv_->encoding(); 43804684ddb6SLionel Sambuc __c = __extbufend_ - __extbufnext_; 43814684ddb6SLionel Sambuc if (__width > 0) 43824684ddb6SLionel Sambuc __c += __width * (this->egptr() - this->gptr()); 43834684ddb6SLionel Sambuc else 43844684ddb6SLionel Sambuc { 43854684ddb6SLionel Sambuc if (this->gptr() != this->egptr()) 43864684ddb6SLionel Sambuc { 43874684ddb6SLionel Sambuc reverse(this->gptr(), this->egptr()); 43884684ddb6SLionel Sambuc codecvt_base::result __r; 43894684ddb6SLionel Sambuc const char_type* __e = this->gptr(); 43904684ddb6SLionel Sambuc char* __extbe; 43914684ddb6SLionel Sambuc do 43924684ddb6SLionel Sambuc { 43934684ddb6SLionel Sambuc __r = __cv_->out(__st_, __e, this->egptr(), __e, 43944684ddb6SLionel Sambuc __extbuf_, __extbuf_ + __ebs_, __extbe); 43954684ddb6SLionel Sambuc switch (__r) 43964684ddb6SLionel Sambuc { 43974684ddb6SLionel Sambuc case codecvt_base::noconv: 43984684ddb6SLionel Sambuc __c += this->egptr() - this->gptr(); 43994684ddb6SLionel Sambuc break; 44004684ddb6SLionel Sambuc case codecvt_base::ok: 44014684ddb6SLionel Sambuc case codecvt_base::partial: 44024684ddb6SLionel Sambuc __c += __extbe - __extbuf_; 44034684ddb6SLionel Sambuc break; 44044684ddb6SLionel Sambuc default: 44054684ddb6SLionel Sambuc return -1; 44064684ddb6SLionel Sambuc } 44074684ddb6SLionel Sambuc } while (__r == codecvt_base::partial); 44084684ddb6SLionel Sambuc } 44094684ddb6SLionel Sambuc } 44104684ddb6SLionel Sambuc } 44114684ddb6SLionel Sambuc if (__bufptr_->pubseekoff(-__c, ios_base::cur, __cm_) == pos_type(off_type(-1))) 44124684ddb6SLionel Sambuc return -1; 44134684ddb6SLionel Sambuc this->setg(0, 0, 0); 44144684ddb6SLionel Sambuc __cm_ = 0; 44154684ddb6SLionel Sambuc } 44164684ddb6SLionel Sambuc return 0; 44174684ddb6SLionel Sambuc} 44184684ddb6SLionel Sambuc 44194684ddb6SLionel Sambuctemplate <class _Codecvt, class _Elem, class _Tr> 44204684ddb6SLionel Sambucbool 44214684ddb6SLionel Sambucwbuffer_convert<_Codecvt, _Elem, _Tr>::__read_mode() 44224684ddb6SLionel Sambuc{ 44234684ddb6SLionel Sambuc if (!(__cm_ & ios_base::in)) 44244684ddb6SLionel Sambuc { 44254684ddb6SLionel Sambuc this->setp(0, 0); 44264684ddb6SLionel Sambuc if (__always_noconv_) 44274684ddb6SLionel Sambuc this->setg((char_type*)__extbuf_, 44284684ddb6SLionel Sambuc (char_type*)__extbuf_ + __ebs_, 44294684ddb6SLionel Sambuc (char_type*)__extbuf_ + __ebs_); 44304684ddb6SLionel Sambuc else 44314684ddb6SLionel Sambuc this->setg(__intbuf_, __intbuf_ + __ibs_, __intbuf_ + __ibs_); 44324684ddb6SLionel Sambuc __cm_ = ios_base::in; 44334684ddb6SLionel Sambuc return true; 44344684ddb6SLionel Sambuc } 44354684ddb6SLionel Sambuc return false; 44364684ddb6SLionel Sambuc} 44374684ddb6SLionel Sambuc 44384684ddb6SLionel Sambuctemplate <class _Codecvt, class _Elem, class _Tr> 44394684ddb6SLionel Sambucvoid 44404684ddb6SLionel Sambucwbuffer_convert<_Codecvt, _Elem, _Tr>::__write_mode() 44414684ddb6SLionel Sambuc{ 44424684ddb6SLionel Sambuc if (!(__cm_ & ios_base::out)) 44434684ddb6SLionel Sambuc { 44444684ddb6SLionel Sambuc this->setg(0, 0, 0); 44454684ddb6SLionel Sambuc if (__ebs_ > sizeof(__extbuf_min_)) 44464684ddb6SLionel Sambuc { 44474684ddb6SLionel Sambuc if (__always_noconv_) 44484684ddb6SLionel Sambuc this->setp((char_type*)__extbuf_, 44494684ddb6SLionel Sambuc (char_type*)__extbuf_ + (__ebs_ - 1)); 44504684ddb6SLionel Sambuc else 44514684ddb6SLionel Sambuc this->setp(__intbuf_, __intbuf_ + (__ibs_ - 1)); 44524684ddb6SLionel Sambuc } 44534684ddb6SLionel Sambuc else 44544684ddb6SLionel Sambuc this->setp(0, 0); 44554684ddb6SLionel Sambuc __cm_ = ios_base::out; 44564684ddb6SLionel Sambuc } 44574684ddb6SLionel Sambuc} 44584684ddb6SLionel Sambuc 44594684ddb6SLionel Sambuctemplate <class _Codecvt, class _Elem, class _Tr> 44604684ddb6SLionel Sambucwbuffer_convert<_Codecvt, _Elem, _Tr>* 44614684ddb6SLionel Sambucwbuffer_convert<_Codecvt, _Elem, _Tr>::__close() 44624684ddb6SLionel Sambuc{ 44634684ddb6SLionel Sambuc wbuffer_convert* __rt = 0; 44644684ddb6SLionel Sambuc if (__cv_ != 0 && __bufptr_ != 0) 44654684ddb6SLionel Sambuc { 44664684ddb6SLionel Sambuc __rt = this; 44674684ddb6SLionel Sambuc if ((__cm_ & ios_base::out) && sync()) 44684684ddb6SLionel Sambuc __rt = 0; 44694684ddb6SLionel Sambuc } 44704684ddb6SLionel Sambuc return __rt; 44714684ddb6SLionel Sambuc} 44724684ddb6SLionel Sambuc 44734684ddb6SLionel Sambuc_LIBCPP_END_NAMESPACE_STD 44744684ddb6SLionel Sambuc 44754684ddb6SLionel Sambuc#endif // _LIBCPP_LOCALE 4476