1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // <iomanip> 10 11 // template <class moneyT> T7 get_money(moneyT& mon, bool intl = false); 12 13 // REQUIRES: locale.en_US.UTF-8 14 15 #include <iomanip> 16 #include <istream> 17 #include <cassert> 18 19 #include "test_macros.h" 20 #include "platform_support.h" // locale name macros 21 22 template <class CharT> 23 struct testbuf 24 : public std::basic_streambuf<CharT> 25 { 26 typedef std::basic_string<CharT> string_type; 27 typedef std::basic_streambuf<CharT> base; 28 private: 29 string_type str_; 30 public: 31 32 testbuf() {} 33 testbuf(const string_type& str) 34 : str_(str) 35 { 36 base::setg(const_cast<CharT*>(str_.data()), 37 const_cast<CharT*>(str_.data()), 38 const_cast<CharT*>(str_.data()) + str_.size()); 39 } 40 }; 41 42 int main(int, char**) 43 { 44 { 45 #if defined(_WIN32) 46 testbuf<char> sb(" ($1,234,567.89)"); 47 #else 48 testbuf<char> sb(" -$1,234,567.89"); 49 #endif 50 std::istream is(&sb); 51 is.imbue(std::locale(LOCALE_en_US_UTF_8)); 52 long double x = 0; 53 is >> std::get_money(x, false); 54 assert(x == -123456789); 55 } 56 { 57 #if defined(_WIN32) 58 testbuf<char> sb(" (USD 1,234,567.89)"); 59 #else 60 testbuf<char> sb(" -USD 1,234,567.89"); 61 #endif 62 std::istream is(&sb); 63 is.imbue(std::locale(LOCALE_en_US_UTF_8)); 64 long double x = 0; 65 is >> std::get_money(x, true); 66 assert(x == -123456789); 67 } 68 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 69 { 70 #if defined(_WIN32) 71 testbuf<wchar_t> sb(L" ($1,234,567.89)"); 72 #else 73 testbuf<wchar_t> sb(L" -$1,234,567.89"); 74 #endif 75 std::wistream is(&sb); 76 is.imbue(std::locale(LOCALE_en_US_UTF_8)); 77 long double x = 0; 78 is >> std::get_money(x, false); 79 assert(x == -123456789); 80 } 81 { 82 #if defined(_WIN32) 83 testbuf<wchar_t> sb(L" (USD 1,234,567.89)"); 84 #else 85 testbuf<wchar_t> sb(L" -USD 1,234,567.89"); 86 #endif 87 std::wistream is(&sb); 88 is.imbue(std::locale(LOCALE_en_US_UTF_8)); 89 long double x = 0; 90 is >> std::get_money(x, true); 91 assert(x == -123456789); 92 } 93 #endif 94 95 return 0; 96 } 97