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 charT, class moneyT> T8 put_money(const moneyT& mon, bool intl = false); 12 13 // REQUIRES: locale.en_US.UTF-8 14 15 // XFAIL: LIBCXX-WINDOWS-FIXME 16 17 #include <iomanip> 18 #include <ostream> 19 #include <cassert> 20 21 #include "test_macros.h" 22 #include "platform_support.h" // locale name macros 23 24 template <class CharT> 25 class testbuf 26 : public std::basic_streambuf<CharT> 27 { 28 typedef std::basic_streambuf<CharT> base; 29 std::basic_string<CharT> str_; 30 public: 31 testbuf() 32 { 33 } 34 35 std::basic_string<CharT> str() const 36 {return std::basic_string<CharT>(base::pbase(), base::pptr());} 37 38 protected: 39 40 virtual typename base::int_type 41 overflow(typename base::int_type ch = base::traits_type::eof()) 42 { 43 if (ch != base::traits_type::eof()) 44 { 45 int n = str_.size(); 46 str_.push_back(static_cast<CharT>(ch)); 47 str_.resize(str_.capacity()); 48 base::setp(const_cast<CharT*>(str_.data()), 49 const_cast<CharT*>(str_.data() + str_.size())); 50 base::pbump(n+1); 51 } 52 return ch; 53 } 54 }; 55 56 int main(int, char**) 57 { 58 { 59 testbuf<char> sb; 60 std::ostream os(&sb); 61 os.imbue(std::locale(LOCALE_en_US_UTF_8)); 62 showbase(os); 63 long double x = -123456789; 64 os << std::put_money(x, false); 65 assert(sb.str() == "-$1,234,567.89"); 66 } 67 { 68 testbuf<char> sb; 69 std::ostream os(&sb); 70 os.imbue(std::locale(LOCALE_en_US_UTF_8)); 71 showbase(os); 72 long double x = -123456789; 73 os << std::put_money(x, true); 74 assert(sb.str() == "-USD 1,234,567.89"); 75 } 76 { 77 testbuf<wchar_t> sb; 78 std::wostream os(&sb); 79 os.imbue(std::locale(LOCALE_en_US_UTF_8)); 80 showbase(os); 81 long double x = -123456789; 82 os << std::put_money(x, false); 83 assert(sb.str() == L"-$1,234,567.89"); 84 } 85 { 86 testbuf<wchar_t> sb; 87 std::wostream os(&sb); 88 os.imbue(std::locale(LOCALE_en_US_UTF_8)); 89 showbase(os); 90 long double x = -123456789; 91 os << std::put_money(x, true); 92 assert(sb.str() == L"-USD 1,234,567.89"); 93 } 94 95 return 0; 96 } 97