101 lines · cpp
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-exception6//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-FIXME15 16// REQUIRES: locale.en_US.UTF-817 18#include <cassert>19#include <iomanip>20#include <istream>21#include <streambuf>22 23#include "test_macros.h"24#include "platform_support.h" // locale name macros25 26template <class CharT>27struct testbuf28 : public std::basic_streambuf<CharT>29{30 typedef std::basic_string<CharT> string_type;31 typedef std::basic_streambuf<CharT> base;32private:33 string_type str_;34public:35 36 testbuf() {}37 testbuf(const string_type& str)38 : str_(str)39 {40 base::setg(const_cast<CharT*>(str_.data()),41 const_cast<CharT*>(str_.data()),42 const_cast<CharT*>(str_.data()) + str_.size());43 }44};45 46int main(int, char**)47{48 {49#if defined(_WIN32)50 testbuf<char> sb(" ($1,234,567.89)");51#else52 testbuf<char> sb(" -$1,234,567.89");53#endif54 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, false);58 assert(x == -123456789);59 }60 {61#if defined(_WIN32)62 testbuf<char> sb(" (USD 1,234,567.89)");63#else64 testbuf<char> sb(" -USD 1,234,567.89");65#endif66 std::istream is(&sb);67 is.imbue(std::locale(LOCALE_en_US_UTF_8));68 long double x = 0;69 is >> std::get_money(x, true);70 assert(x == -123456789);71 }72#ifndef TEST_HAS_NO_WIDE_CHARACTERS73 {74#if defined(_WIN32)75 testbuf<wchar_t> sb(L" ($1,234,567.89)");76#else77 testbuf<wchar_t> sb(L" -$1,234,567.89");78#endif79 std::wistream is(&sb);80 is.imbue(std::locale(LOCALE_en_US_UTF_8));81 long double x = 0;82 is >> std::get_money(x, false);83 assert(x == -123456789);84 }85 {86#if defined(_WIN32)87 testbuf<wchar_t> sb(L" (USD 1,234,567.89)");88#else89 testbuf<wchar_t> sb(L" -USD 1,234,567.89");90#endif91 std::wistream is(&sb);92 is.imbue(std::locale(LOCALE_en_US_UTF_8));93 long double x = 0;94 is >> std::get_money(x, true);95 assert(x == -123456789);96 }97#endif98 99 return 0;100}101