1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <iomanip>
11
12 // template <class moneyT> T7 get_money(moneyT& mon, bool intl = false);
13
14 // REQUIRES: locale.en_US.UTF-8
15
16 #include <iomanip>
17 #include <istream>
18 #include <cassert>
19
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
testbuftestbuf32 testbuf() {}
testbuftestbuf33 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
main()42 int main()
43 {
44 {
45 testbuf<char> sb(" -$1,234,567.89");
46 std::istream is(&sb);
47 is.imbue(std::locale(LOCALE_en_US_UTF_8));
48 long double x = 0;
49 is >> std::get_money(x, false);
50 assert(x == -123456789);
51 }
52 {
53 testbuf<char> sb(" -USD 1,234,567.89");
54 std::istream is(&sb);
55 is.imbue(std::locale(LOCALE_en_US_UTF_8));
56 long double x = 0;
57 is >> std::get_money(x, true);
58 assert(x == -123456789);
59 }
60 {
61 testbuf<wchar_t> sb(L" -$1,234,567.89");
62 std::wistream is(&sb);
63 is.imbue(std::locale(LOCALE_en_US_UTF_8));
64 long double x = 0;
65 is >> std::get_money(x, false);
66 assert(x == -123456789);
67 }
68 {
69 testbuf<wchar_t> sb(L" -USD 1,234,567.89");
70 std::wistream is(&sb);
71 is.imbue(std::locale(LOCALE_en_US_UTF_8));
72 long double x = 0;
73 is >> std::get_money(x, true);
74 assert(x == -123456789);
75 }
76 }
77