int main(int, char**) { std::ios ios(0); std::string loc_name(LOCALE_ru_RU_UTF_8); ios.imbue(std::locale(ios.getloc(), new std::moneypunct_byname<char, false>(loc_name))); ios.imbue(std::locale(ios.getloc(), new std::moneypunct_byname<char, true>(loc_name))); ios.imbue(std::locale(ios.getloc(), new std::moneypunct_byname<wchar_t, false>(loc_name))); ios.imbue(std::locale(ios.getloc(), new std::moneypunct_byname<wchar_t, true>(loc_name))); { const my_facet f(1); // char, national { // zero long double v = 0; char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), false, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "0,00 "); } { // negative one long double v = -1; char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), false, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "-0,01 "); } { // positive long double v = 123456789; char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), false, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "1 234 567,89 "); } { // negative long double v = -123456789; char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), false, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "-1 234 567,89 "); } { // zero, showbase long double v = 0; showbase(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), false, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "0,00 \xD1\x80\xD1\x83\xD0\xB1""."); } { // negative one, showbase long double v = -1; showbase(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), false, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "-0,01 \xD1\x80\xD1\x83\xD0\xB1""."); } { // positive, showbase long double v = 123456789; showbase(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), false, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "1 234 567,89 \xD1\x80\xD1\x83\xD0\xB1""."); } { // negative, showbase long double v = -123456789; showbase(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), false, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "-1 234 567,89 \xD1\x80\xD1\x83\xD0\xB1""."); } { // negative, showbase, left long double v = -123456789; showbase(ios); ios.width(20); left(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), false, ios, ' ', v); std::string ex(str, iter.base()); assert(ex == "-1 234 567,89 \xD1\x80\xD1\x83\xD0\xB1""."); assert(ios.width() == 0); } { // negative, showbase, internal long double v = -123456789; showbase(ios); ios.width(20); internal(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), false, ios, ' ', v); std::string ex(str, iter.base()); assert(ex == "-1 234 567,89 \xD1\x80\xD1\x83\xD0\xB1""."); assert(ios.width() == 0); } { // negative, showbase, right long double v = -123456789; showbase(ios); ios.width(20); right(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), false, ios, ' ', v); std::string ex(str, iter.base()); assert(ex == "-1 234 567,89 \xD1\x80\xD1\x83\xD0\xB1""."); assert(ios.width() == 0); } // char, international noshowbase(ios); ios.unsetf(std::ios_base::adjustfield); { // zero long double v = 0; char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), true, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "0,00 "); } { // negative one long double v = -1; char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), true, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "-0,01 "); } { // positive long double v = 123456789; char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), true, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "1 234 567,89 "); } { // negative long double v = -123456789; char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), true, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "-1 234 567,89 "); } { // zero, showbase long double v = 0; showbase(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), true, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "0,00 RUB "); } { // negative one, showbase long double v = -1; showbase(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), true, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "-0,01 RUB "); } { // positive, showbase long double v = 123456789; showbase(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), true, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "1 234 567,89 RUB "); } { // negative, showbase long double v = -123456789; showbase(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), true, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "-1 234 567,89 RUB "); } { // negative, showbase, left long double v = -123456789; showbase(ios); ios.width(20); left(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), true, ios, ' ', v); std::string ex(str, iter.base()); assert(ex == "-1 234 567,89 RUB "); assert(ios.width() == 0); } { // negative, showbase, internal long double v = -123456789; showbase(ios); ios.width(20); internal(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), true, ios, ' ', v); std::string ex(str, iter.base()); assert(ex == "-1 234 567,89 RUB "); assert(ios.width() == 0); } { // negative, showbase, right long double v = -123456789; showbase(ios); ios.width(20); right(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), true, ios, ' ', v); std::string ex(str, iter.base()); assert(ex == " -1 234 567,89 RUB "); assert(ios.width() == 0); } } { const my_facetw f(1); // wchar_t, national noshowbase(ios); ios.unsetf(std::ios_base::adjustfield); { // zero long double v = 0; wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), false, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"0,00 "); } { // negative one long double v = -1; wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), false, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"-0,01 "); } { // positive long double v = 123456789; wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), false, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"1 234 567,89 "); } { // negative long double v = -123456789; wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), false, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"-1 234 567,89 "); } { // zero, showbase long double v = 0; showbase(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), false, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"0,00 \x440\x443\x431""."); } { // negative one, showbase long double v = -1; showbase(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), false, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"-0,01 \x440\x443\x431""."); } { // positive, showbase long double v = 123456789; showbase(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), false, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"1 234 567,89 \x440\x443\x431""."); } { // negative, showbase long double v = -123456789; showbase(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), false, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"-1 234 567,89 \x440\x443\x431""."); } { // negative, showbase, left long double v = -123456789; showbase(ios); ios.width(20); left(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), false, ios, ' ', v); std::wstring ex(str, iter.base()); assert(ex == L"-1 234 567,89 \x440\x443\x431"". "); assert(ios.width() == 0); } { // negative, showbase, internal long double v = -123456789; showbase(ios); ios.width(20); internal(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), false, ios, ' ', v); std::wstring ex(str, iter.base()); assert(ex == L"-1 234 567,89 \x440\x443\x431""."); assert(ios.width() == 0); } { // negative, showbase, right long double v = -123456789; showbase(ios); ios.width(20); right(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), false, ios, ' ', v); std::wstring ex(str, iter.base()); assert(ex == L" -1 234 567,89 \x440\x443\x431""."); assert(ios.width() == 0); } // wchar_t, international noshowbase(ios); ios.unsetf(std::ios_base::adjustfield); { // zero long double v = 0; wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), true, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"0,00 "); } { // negative one long double v = -1; wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), true, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"-0,01 "); } { // positive long double v = 123456789; wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), true, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"1 234 567,89 "); } { // negative long double v = -123456789; wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), true, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"-1 234 567,89 "); } { // zero, showbase long double v = 0; showbase(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), true, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"0,00 RUB "); } { // negative one, showbase long double v = -1; showbase(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), true, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"-0,01 RUB "); } { // positive, showbase long double v = 123456789; showbase(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), true, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"1 234 567,89 RUB "); } { // negative, showbase long double v = -123456789; showbase(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), true, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"-1 234 567,89 RUB "); } { // negative, showbase, left long double v = -123456789; showbase(ios); ios.width(20); left(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), true, ios, ' ', v); std::wstring ex(str, iter.base()); assert(ex == L"-1 234 567,89 RUB "); assert(ios.width() == 0); } { // negative, showbase, internal long double v = -123456789; showbase(ios); ios.width(20); internal(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), true, ios, ' ', v); std::wstring ex(str, iter.base()); assert(ex == L"-1 234 567,89 RUB "); assert(ios.width() == 0); } { // negative, showbase, right long double v = -123456789; showbase(ios); ios.width(20); right(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), true, ios, ' ', v); std::wstring ex(str, iter.base()); assert(ex == L" -1 234 567,89 RUB "); assert(ios.width() == 0); } } return 0; }
int main() { std::ios ios(0); std::string loc_name("en_US"); ios.imbue(std::locale(ios.getloc(), new std::moneypunct_byname<char, false>(loc_name))); ios.imbue(std::locale(ios.getloc(), new std::moneypunct_byname<char, true>(loc_name))); ios.imbue(std::locale(ios.getloc(), new std::moneypunct_byname<wchar_t, false>(loc_name))); ios.imbue(std::locale(ios.getloc(), new std::moneypunct_byname<wchar_t, true>(loc_name))); { const my_facet f(1); // char, national { // zero long double v = 0; char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), false, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "0.00"); } { // negative one long double v = -1; char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), false, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "-0.01"); } { // positive long double v = 123456789; char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), false, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "1,234,567.89"); } { // negative long double v = -123456789; char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), false, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "-1,234,567.89"); } { // zero, showbase long double v = 0; showbase(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), false, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "$0.00"); } { // negative one, showbase long double v = -1; showbase(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), false, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "-$0.01"); } { // positive, showbase long double v = 123456789; showbase(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), false, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "$1,234,567.89"); } { // negative, showbase long double v = -123456789; showbase(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), false, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "-$1,234,567.89"); } { // negative, showbase, left long double v = -123456789; showbase(ios); ios.width(20); left(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), false, ios, ' ', v); std::string ex(str, iter.base()); assert(ex == "-$1,234,567.89 "); assert(ios.width() == 0); } { // negative, showbase, internal long double v = -123456789; showbase(ios); ios.width(20); internal(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), false, ios, ' ', v); std::string ex(str, iter.base()); assert(ex == "-$ 1,234,567.89"); assert(ios.width() == 0); } { // negative, showbase, right long double v = -123456789; showbase(ios); ios.width(20); right(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), false, ios, ' ', v); std::string ex(str, iter.base()); assert(ex == " -$1,234,567.89"); assert(ios.width() == 0); } // char, international noshowbase(ios); ios.unsetf(std::ios_base::adjustfield); { // zero long double v = 0; char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), true, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "0.00"); } { // negative one long double v = -1; char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), true, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "-0.01"); } { // positive long double v = 123456789; char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), true, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "1,234,567.89"); } { // negative long double v = -123456789; char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), true, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "-1,234,567.89"); } { // zero, showbase long double v = 0; showbase(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), true, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "USD 0.00"); } { // negative one, showbase long double v = -1; showbase(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), true, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "-USD 0.01"); } { // positive, showbase long double v = 123456789; showbase(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), true, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "USD 1,234,567.89"); } { // negative, showbase long double v = -123456789; showbase(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), true, ios, '*', v); std::string ex(str, iter.base()); assert(ex == "-USD 1,234,567.89"); } { // negative, showbase, left long double v = -123456789; showbase(ios); ios.width(20); left(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), true, ios, ' ', v); std::string ex(str, iter.base()); assert(ex == "-USD 1,234,567.89 "); assert(ios.width() == 0); } { // negative, showbase, internal long double v = -123456789; showbase(ios); ios.width(20); internal(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), true, ios, ' ', v); std::string ex(str, iter.base()); assert(ex == "-USD 1,234,567.89"); assert(ios.width() == 0); } { // negative, showbase, right long double v = -123456789; showbase(ios); ios.width(20); right(ios); char str[100]; output_iterator<char*> iter = f.put(output_iterator<char*>(str), true, ios, ' ', v); std::string ex(str, iter.base()); assert(ex == " -USD 1,234,567.89"); assert(ios.width() == 0); } } { const my_facetw f(1); // wchar_t, national noshowbase(ios); ios.unsetf(std::ios_base::adjustfield); { // zero long double v = 0; wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), false, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"0.00"); } { // negative one long double v = -1; wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), false, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"-0.01"); } { // positive long double v = 123456789; wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), false, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"1,234,567.89"); } { // negative long double v = -123456789; wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), false, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"-1,234,567.89"); } { // zero, showbase long double v = 0; showbase(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), false, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"$0.00"); } { // negative one, showbase long double v = -1; showbase(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), false, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"-$0.01"); } { // positive, showbase long double v = 123456789; showbase(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), false, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"$1,234,567.89"); } { // negative, showbase long double v = -123456789; showbase(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), false, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"-$1,234,567.89"); } { // negative, showbase, left long double v = -123456789; showbase(ios); ios.width(20); left(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), false, ios, ' ', v); std::wstring ex(str, iter.base()); assert(ex == L"-$1,234,567.89 "); assert(ios.width() == 0); } { // negative, showbase, internal long double v = -123456789; showbase(ios); ios.width(20); internal(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), false, ios, ' ', v); std::wstring ex(str, iter.base()); assert(ex == L"-$ 1,234,567.89"); assert(ios.width() == 0); } { // negative, showbase, right long double v = -123456789; showbase(ios); ios.width(20); right(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), false, ios, ' ', v); std::wstring ex(str, iter.base()); assert(ex == L" -$1,234,567.89"); assert(ios.width() == 0); } // wchar_t, international noshowbase(ios); ios.unsetf(std::ios_base::adjustfield); { // zero long double v = 0; wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), true, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"0.00"); } { // negative one long double v = -1; wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), true, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"-0.01"); } { // positive long double v = 123456789; wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), true, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"1,234,567.89"); } { // negative long double v = -123456789; wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), true, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"-1,234,567.89"); } { // zero, showbase long double v = 0; showbase(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), true, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"USD 0.00"); } { // negative one, showbase long double v = -1; showbase(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), true, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"-USD 0.01"); } { // positive, showbase long double v = 123456789; showbase(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), true, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"USD 1,234,567.89"); } { // negative, showbase long double v = -123456789; showbase(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), true, ios, '*', v); std::wstring ex(str, iter.base()); assert(ex == L"-USD 1,234,567.89"); } { // negative, showbase, left long double v = -123456789; showbase(ios); ios.width(20); left(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), true, ios, ' ', v); std::wstring ex(str, iter.base()); assert(ex == L"-USD 1,234,567.89 "); assert(ios.width() == 0); } { // negative, showbase, internal long double v = -123456789; showbase(ios); ios.width(20); internal(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), true, ios, ' ', v); std::wstring ex(str, iter.base()); assert(ex == L"-USD 1,234,567.89"); assert(ios.width() == 0); } { // negative, showbase, right long double v = -123456789; showbase(ios); ios.width(20); right(ios); wchar_t str[100]; output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), true, ios, ' ', v); std::wstring ex(str, iter.base()); assert(ex == L" -USD 1,234,567.89"); assert(ios.width() == 0); } } }
int main() { std::ios ios(0); std::string loc_name(LOCALE_zh_CN_UTF_8); ios.imbue(std::locale(ios.getloc(), new std::moneypunct_byname<char, false>(loc_name))); ios.imbue(std::locale(ios.getloc(), new std::moneypunct_byname<char, true>(loc_name))); ios.imbue(std::locale(ios.getloc(), new std::moneypunct_byname<wchar_t, false>(loc_name))); ios.imbue(std::locale(ios.getloc(), new std::moneypunct_byname<wchar_t, true>(loc_name))); { const my_facet f(1); // char, national { // zero std::string v = "0.00"; typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == 0); } { // negative one std::string v = "-0.01"; typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == -1); } { // positive std::string v = "1,234,567.89"; typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == 123456789); } { // negative std::string v = "-1,234,567.89"; typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == -123456789); } { // negative std::string v = "-1234567.89"; typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == -123456789); } { // zero, showbase std::string v = "\xEF\xBF\xA5""0.00"; typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == 0); } { // zero, showbase std::string v = "\xEF\xBF\xA5""0.00"; showbase(ios); typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == 0); noshowbase(ios); } { // negative one, showbase std::string v = "\xEF\xBF\xA5""-0.01"; typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == -1); } { // negative one, showbase std::string v = "\xEF\xBF\xA5""-0.01"; showbase(ios); typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == -1); noshowbase(ios); } { // positive, showbase std::string v = "\xEF\xBF\xA5""1,234,567.89"; typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == 123456789); } { // positive, showbase std::string v = "\xEF\xBF\xA5""1,234,567.89"; showbase(ios); typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == 123456789); noshowbase(ios); } { // negative, showbase std::string v = "\xEF\xBF\xA5""-1,234,567.89"; showbase(ios); typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == -123456789); noshowbase(ios); } { // negative, showbase std::string v = "CNY -1,234,567.89"; showbase(ios); typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + 0); assert(err == std::ios_base::failbit); noshowbase(ios); } { // negative, showbase std::string v = "CNY -1,234,567.89"; typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + 0); assert(err == std::ios_base::failbit); } } { const my_facet f(1); // char, international { // zero std::string v = "0.00"; typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == 0); } { // negative one std::string v = "-0.01"; typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == -1); } { // positive std::string v = "1,234,567.89"; typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == 123456789); } { // negative std::string v = "-1,234,567.89"; typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == -123456789); } { // negative std::string v = "-1234567.89"; typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == -123456789); } { // zero, showbase std::string v = "CNY 0.00"; typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == 0); } { // zero, showbase std::string v = "CNY 0.00"; showbase(ios); typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == 0); noshowbase(ios); } { // negative one, showbase std::string v = "CNY -0.01"; typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == -1); } { // negative one, showbase std::string v = "CNY -0.01"; showbase(ios); typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == -1); noshowbase(ios); } { // positive, showbase std::string v = "CNY 1,234,567.89"; typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == 123456789); } { // positive, showbase std::string v = "CNY 1,234,567.89"; showbase(ios); typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == 123456789); noshowbase(ios); } { // negative, showbase std::string v = "CNY -1,234,567.89"; showbase(ios); typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == -123456789); noshowbase(ios); } { // negative, showbase std::string v = "\xEF\xBF\xA5""-1,234,567.89"; showbase(ios); typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + 0); assert(err == std::ios_base::failbit); noshowbase(ios); } { // negative, showbase std::string v = "\xEF\xBF\xA5""-1,234,567.89"; typedef input_iterator<const char*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + 0); assert(err == std::ios_base::failbit); } } { const my_facetw f(1); // wchar_t, national { // zero std::wstring v = L"0.00"; typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == 0); } { // negative one std::wstring v = L"-0.01"; typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == -1); } { // positive std::wstring v = L"1,234,567.89"; typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == 123456789); } { // negative std::wstring v = L"-1,234,567.89"; typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == -123456789); } { // negative std::wstring v = L"-1234567.89"; typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == -123456789); } { // zero, showbase std::wstring v = L"\xFFE5""0.00"; typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == 0); } { // zero, showbase std::wstring v = L"\xFFE5""0.00"; showbase(ios); typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == 0); noshowbase(ios); } { // negative one, showbase std::wstring v = L"\xFFE5""-0.01"; typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == -1); } { // negative one, showbase std::wstring v = L"\xFFE5""-0.01"; showbase(ios); typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == -1); noshowbase(ios); } { // positive, showbase std::wstring v = L"\xFFE5""1,234,567.89"; typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == 123456789); } { // positive, showbase std::wstring v = L"\xFFE5""1,234,567.89"; showbase(ios); typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == 123456789); noshowbase(ios); } { // negative, showbase std::wstring v = L"\xFFE5""-1,234,567.89"; showbase(ios); typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == -123456789); noshowbase(ios); } { // negative, showbase std::wstring v = L"CNY -1,234,567.89"; showbase(ios); typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + 0); assert(err == std::ios_base::failbit); noshowbase(ios); } { // negative, showbase std::wstring v = L"CNY -1,234,567.89"; typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), false, ios, err, ex); assert(iter.base() == v.data() + 0); assert(err == std::ios_base::failbit); } } { const my_facetw f(1); // wchar_t, international { // zero std::wstring v = L"0.00"; typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == 0); } { // negative one std::wstring v = L"-0.01"; typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == -1); } { // positive std::wstring v = L"1,234,567.89"; typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == 123456789); } { // negative std::wstring v = L"-1,234,567.89"; typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == -123456789); } { // negative std::wstring v = L"-1234567.89"; typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == -123456789); } { // zero, showbase std::wstring v = L"CNY 0.00"; typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == 0); } { // zero, showbase std::wstring v = L"CNY 0.00"; showbase(ios); typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == 0); noshowbase(ios); } { // negative one, showbase std::wstring v = L"CNY -0.01"; typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == -1); } { // negative one, showbase std::wstring v = L"CNY -0.01"; showbase(ios); typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == -1); noshowbase(ios); } { // positive, showbase std::wstring v = L"CNY 1,234,567.89"; typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == 123456789); } { // positive, showbase std::wstring v = L"CNY 1,234,567.89"; showbase(ios); typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == 123456789); noshowbase(ios); } { // negative, showbase std::wstring v = L"CNY -1,234,567.89"; showbase(ios); typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + v.size()); assert(err == std::ios_base::eofbit); assert(ex == -123456789); noshowbase(ios); } { // negative, showbase std::wstring v = L"\xFFE5""-1,234,567.89"; showbase(ios); typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + 0); assert(err == std::ios_base::failbit); noshowbase(ios); } { // negative, showbase std::wstring v = L"\xFFE5""-1,234,567.89"; typedef input_iterator<const wchar_t*> I; long double ex; std::ios_base::iostate err = std::ios_base::goodbit; I iter = f.get(I(v.data()), I(v.data() + v.size()), true, ios, err, ex); assert(iter.base() == v.data() + 0); assert(err == std::ios_base::failbit); } } }