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