#include "test_iterators.h"
#include "platform_support.h" // locale name macros
+#include "test_macros.h"
typedef std::money_get<char, input_iterator<const char*> > Fn;
: Fw(refs) {}
};
+
+// GLIBC 2.27 and newer use U2027 (narrow non-breaking space) as a thousands sep.
+// this function converts the spaces in string inputs to that character if need
+// be.
+static std::wstring convert_thousands_sep(std::wstring const& in) {
+#if !defined(TEST_HAS_GLIBC) || !TEST_GLIBC_PREREQ(2,27)
+ return in;
+#else
+ std::wstring out;
+ unsigned I = 0;
+ bool seen_decimal = false;
+ for (; I < in.size(); ++I) {
+ if (seen_decimal || in[I] != L' ') {
+ seen_decimal |= in[I] == L',';
+ out.push_back(in[I]);
+ continue;
+ }
+ assert(in[I] == L' ');
+ out.push_back(L'\u202F');
+ }
+ return out;
+#endif
+}
+
int main()
{
std::ios ios(0);
assert(ex == -1);
}
{ // positive
- std::wstring v = L"1 234 567,89 ";
+ std::wstring v = convert_thousands_sep(L"1 234 567,89 ");
typedef input_iterator<const wchar_t*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
assert(ex == 123456789);
}
{ // negative
- std::wstring v = L"-1 234 567,89";
+ std::wstring v = convert_thousands_sep(L"-1 234 567,89");
typedef input_iterator<const wchar_t*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
assert(ex == -1);
}
{ // positive, showbase
- std::wstring v = L"1 234 567,89 \u20ac"; // EURO SIGN
+ std::wstring v = convert_thousands_sep(L"1 234 567,89 \u20ac"); // EURO SIGN
typedef input_iterator<const wchar_t*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
assert(ex == 123456789);
}
{ // positive, showbase
- std::wstring v = L"1 234 567,89 \u20ac"; // EURO SIGN
+ std::wstring v = convert_thousands_sep(L"1 234 567,89 \u20ac"); // EURO SIGN
showbase(ios);
typedef input_iterator<const wchar_t*> I;
long double ex;
noshowbase(ios);
}
{ // negative, showbase
- std::wstring v = L"-1 234 567,89 \u20ac"; // EURO SIGN
+ std::wstring v = convert_thousands_sep(L"-1 234 567,89 \u20ac"); // EURO SIGN
showbase(ios);
typedef input_iterator<const wchar_t*> I;
long double ex;
noshowbase(ios);
}
{ // negative, showbase
- std::wstring v = L"1 234 567,89 EUR -";
+ std::wstring v = convert_thousands_sep(L"1 234 567,89 EUR -");
showbase(ios);
typedef input_iterator<const wchar_t*> I;
long double ex;
noshowbase(ios);
}
{ // negative, showbase
- std::wstring v = L"1 234 567,89 EUR -";
+ std::wstring v = convert_thousands_sep(L"1 234 567,89 EUR -");
typedef input_iterator<const wchar_t*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
assert(ex == -1);
}
{ // positive
- std::wstring v = L"1 234 567,89 ";
+ std::wstring v = convert_thousands_sep(L"1 234 567,89 ");
typedef input_iterator<const wchar_t*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
assert(ex == 123456789);
}
{ // negative
- std::wstring v = L"-1 234 567,89";
+ std::wstring v = convert_thousands_sep(L"-1 234 567,89");
typedef input_iterator<const wchar_t*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
assert(ex == -1);
}
{ // positive, showbase
- std::wstring v = L"1 234 567,89 EUR";
+ std::wstring v = convert_thousands_sep(L"1 234 567,89 EUR");
typedef input_iterator<const wchar_t*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
assert(ex == 123456789);
}
{ // positive, showbase
- std::wstring v = L"1 234 567,89 EUR";
+ std::wstring v = convert_thousands_sep(L"1 234 567,89 EUR");
showbase(ios);
typedef input_iterator<const wchar_t*> I;
long double ex;
noshowbase(ios);
}
{ // negative, showbase
- std::wstring v = L"-1 234 567,89 EUR";
+ std::wstring v = convert_thousands_sep(L"-1 234 567,89 EUR");
showbase(ios);
typedef input_iterator<const wchar_t*> I;
long double ex;
noshowbase(ios);
}
{ // negative, showbase
- std::wstring v = L"1 234 567,89 Eu-";
+ std::wstring v = convert_thousands_sep(L"1 234 567,89 Eu-");
showbase(ios);
typedef input_iterator<const wchar_t*> I;
long double ex;
noshowbase(ios);
}
{ // negative, showbase
- std::wstring v = L"1 234 567,89 Eu-";
+ std::wstring v = convert_thousands_sep(L"1 234 567,89 Eu-");
typedef input_iterator<const wchar_t*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
#include "test_iterators.h"
#include "platform_support.h" // locale name macros
+#include "test_macros.h"
typedef std::money_put<char, output_iterator<char*> > Fn;
: Fw(refs) {}
};
+
+// GLIBC 2.27 and newer use U2027 (narrow non-breaking space) as a thousands sep.
+// this function converts the spaces in string inputs to that character if need
+// be.
+static std::wstring convert_thousands_sep(std::wstring const& in) {
+#if !defined(TEST_HAS_GLIBC) || !TEST_GLIBC_PREREQ(2,27)
+ return in;
+#else
+ std::wstring out;
+ unsigned I = 0;
+ bool seen_num_start = false;
+ bool seen_decimal = false;
+ for (; I < in.size(); ++I) {
+ seen_decimal |= in[I] == L',';
+ seen_num_start |= in[I] == '-' || std::iswdigit(in[I]);
+ if (seen_decimal || !seen_num_start || in[I] != L' ') {
+ out.push_back(in[I]);
+ continue;
+ }
+ assert(in[I] == L' ');
+ out.push_back(L'\u202F');
+ }
+ return out;
+#endif
+}
+
int main()
{
std::ios ios(0);
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(ex == convert_thousands_sep(L"1 234 567,89"));
}
{ // negative
long double v = -123456789;
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(ex == convert_thousands_sep(L"-1 234 567,89"));
}
{ // zero, showbase
long double v = 0;
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 \u20ac");
+ assert(ex == convert_thousands_sep(L"1 234 567,89 \u20ac"));
}
{ // negative, showbase
long double v = -123456789;
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 \u20ac");
+ assert(ex == convert_thousands_sep(L"-1 234 567,89 \u20ac"));
}
{ // negative, showbase, left
long double v = -123456789;
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 \u20ac ");
+ assert(ex == convert_thousands_sep(L"-1 234 567,89 \u20ac "));
assert(ios.width() == 0);
}
{ // negative, showbase, internal
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 \u20ac");
+ assert(ex == convert_thousands_sep(L"-1 234 567,89 \u20ac"));
assert(ios.width() == 0);
}
{ // negative, showbase, right
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 \u20ac");
+ assert(ex == convert_thousands_sep(L" -1 234 567,89 \u20ac"));
assert(ios.width() == 0);
}
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");
+ assert(ex == convert_thousands_sep(L"1 234 567,89"));
}
{ // negative
long double v = -123456789;
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");
+ assert(ex == convert_thousands_sep(L"-1 234 567,89"));
}
{ // zero, showbase
long double v = 0;
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 EUR");
+ assert(ex == convert_thousands_sep(L"1 234 567,89 EUR"));
}
{ // negative, showbase
long double v = -123456789;
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 EUR");
+ assert(ex == convert_thousands_sep(L"-1 234 567,89 EUR"));
}
{ // negative, showbase, left
long double v = -123456789;
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 EUR ");
+ assert(ex == convert_thousands_sep(L"-1 234 567,89 EUR "));
assert(ios.width() == 0);
}
{ // negative, showbase, internal
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 EUR");
+ assert(ex == convert_thousands_sep(L"-1 234 567,89 EUR"));
assert(ios.width() == 0);
}
{ // negative, showbase, right
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 EUR");
+ assert(ex == convert_thousands_sep(L" -1 234 567,89 EUR"));
assert(ios.width() == 0);
}
}
Fwt f(LOCALE_en_US_UTF_8, 1);
assert(f.thousands_sep() == L',');
}
-
{
Fnf f(LOCALE_fr_FR_UTF_8, 1);
assert(f.thousands_sep() == ' ');
Fnt f(LOCALE_fr_FR_UTF_8, 1);
assert(f.thousands_sep() == ' ');
}
+// The below tests work around GLIBC's use of U202F as mon_thousands_sep.
+#if defined(TEST_HAS_GLIBC) && TEST_GLIBC_PREREQ(2, 27)
+ const wchar_t fr_sep = L'\u202F';
+#else
+ const wchar_t fr_sep = L' ';
+#endif
{
Fwf f(LOCALE_fr_FR_UTF_8, 1);
- assert(f.thousands_sep() == L' ');
+ assert(f.thousands_sep() == fr_sep);
}
{
Fwt f(LOCALE_fr_FR_UTF_8, 1);
- assert(f.thousands_sep() == L' ');
+ assert(f.thousands_sep() == fr_sep);
}
// The below tests work around GLIBC's use of U00A0 as mon_thousands_sep
// and U002E as mon_decimal_point.
#ifndef TEST_HAS_GLIBC
const char sep = ' ';
const wchar_t wsep = L' ';
+#elif TEST_GLIBC_PREREQ(2, 27)
+ // FIXME libc++ specifically works around \u00A0 by translating it into
+ // a regular space.
+ const char sep = ' ';
+ const wchar_t wsep = L'\u202F';
#else
// FIXME libc++ specifically works around \u00A0 by translating it into
// a regular space.