| 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 |
// Bionic has minimal locale support, investigate this later. |
| 14 |
// XFAIL: LIBCXX-ANDROID-FIXME |
| 15 |
|
| 16 |
// REQUIRES: locale.en_US.UTF-8 |
| 17 |
|
| 18 |
#include <iomanip> |
| 19 |
#include <istream> |
| 20 |
#include <cassert> |
| 21 |
|
| 22 |
#include "test_macros.h" |
| 23 |
#include "platform_support.h" // locale name macros |
| 24 |
|
| 25 |
template <class CharT> |
| 26 |
struct testbuf |
| 27 |
: public std::basic_streambuf<CharT> |
| 28 |
{ |
| 29 |
typedef std::basic_string<CharT> string_type; |
| 30 |
typedef std::basic_streambuf<CharT> base; |
| 31 |
private: |
| 32 |
string_type str_; |
| 33 |
public: |
| 34 |
|
| 35 |
testbuf() {} |
| 36 |
testbuf(const string_type& str) |
| 37 |
: str_(str) |
| 38 |
{ |
| 39 |
base::setg(const_cast<CharT*>(str_.data()), |
| 40 |
const_cast<CharT*>(str_.data()), |
| 41 |
const_cast<CharT*>(str_.data()) + str_.size()); |
| 42 |
} |
| 43 |
}; |
| 44 |
|
| 45 |
int main(int, char**) |
| 46 |
{ |
| 47 |
{ |
| 48 |
#if defined(_WIN32) |
| 49 |
testbuf<char> sb(" ($1,234,567.89)"); |
| 50 |
#else |
| 51 |
testbuf<char> sb(" -$1,234,567.89"); |
| 52 |
#endif |
| 53 |
std::istream is(&sb); |
| 54 |
is.imbue(std::locale(LOCALE_en_US_UTF_8)); |
| 55 |
long double x = 0; |
| 56 |
is >> std::get_money(x, false); |
| 57 |
assert(x == -123456789); |
| 58 |
} |
| 59 |
{ |
| 60 |
#if defined(_WIN32) |
| 61 |
testbuf<char> sb(" (USD 1,234,567.89)"); |
| 62 |
#else |
| 63 |
testbuf<char> sb(" -USD 1,234,567.89"); |
| 64 |
#endif |
| 65 |
std::istream is(&sb); |
| 66 |
is.imbue(std::locale(LOCALE_en_US_UTF_8)); |
| 67 |
long double x = 0; |
| 68 |
is >> std::get_money(x, true); |
| 69 |
assert(x == -123456789); |
| 70 |
} |
| 71 |
#ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 72 |
{ |
| 73 |
#if defined(_WIN32) |
| 74 |
testbuf<wchar_t> sb(L" ($1,234,567.89)"); |
| 75 |
#else |
| 76 |
testbuf<wchar_t> sb(L" -$1,234,567.89"); |
| 77 |
#endif |
| 78 |
std::wistream is(&sb); |
| 79 |
is.imbue(std::locale(LOCALE_en_US_UTF_8)); |
| 80 |
long double x = 0; |
| 81 |
is >> std::get_money(x, false); |
| 82 |
assert(x == -123456789); |
| 83 |
} |
| 84 |
{ |
| 85 |
#if defined(_WIN32) |
| 86 |
testbuf<wchar_t> sb(L" (USD 1,234,567.89)"); |
| 87 |
#else |
| 88 |
testbuf<wchar_t> sb(L" -USD 1,234,567.89"); |
| 89 |
#endif |
| 90 |
std::wistream is(&sb); |
| 91 |
is.imbue(std::locale(LOCALE_en_US_UTF_8)); |
| 92 |
long double x = 0; |
| 93 |
is >> std::get_money(x, true); |
| 94 |
assert(x == -123456789); |
| 95 |
} |
| 96 |
#endif |
| 97 |
|
| 98 |
return 0; |
| 99 |
} |