diff options
author | Paolo Carlini <pcarlini@unitus.it> | 2002-02-28 22:16:45 +0100 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2002-02-28 21:16:45 +0000 |
commit | 694d519fb0a8b8c784895c780c2510a092624165 (patch) | |
tree | 84093a8ea6c178d4b3645af17dee99080214e396 | |
parent | abda4f1c2d763d7bbaff9ace16015938b73de107 (diff) | |
download | gcc-694d519fb0a8b8c784895c780c2510a092624165.zip gcc-694d519fb0a8b8c784895c780c2510a092624165.tar.gz gcc-694d519fb0a8b8c784895c780c2510a092624165.tar.bz2 |
locale_facets.tcc (num_get::_M_extract_int): Admit grouping for octals and hexadecimals too.
2002-02-28 Paolo Carlini <pcarlini@unitus.it>
* include/bits/locale_facets.tcc (num_get::_M_extract_int):
Admit grouping for octals and hexadecimals too.
* testsuite/22_locale/num_get_members_char.cc: Add test04.
(test01): Tweak "." -> "," in void* test.
* testsuite/22_locale/num_get_members_wchar_t.cc: Ditto.
* testsuite/27_io/ios_manip_basefield.cc: Remove static keyword.
* testsuite/27_io/ios_manip_fmtflags.cc: Remove two of them.
From-SVN: r50162
-rw-r--r-- | libstdc++-v3/ChangeLog | 11 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/locale_facets.tcc | 2 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/22_locale/num_get_members_char.cc | 67 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/22_locale/num_get_members_wchar_t.cc | 67 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/ios_manip_basefield.cc | 2 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/ios_manip_fmtflags.cc | 4 |
6 files changed, 147 insertions, 6 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index a65ae40..d1b2116 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,14 @@ +2002-02-28 Paolo Carlini <pcarlini@unitus.it> + + * include/bits/locale_facets.tcc (num_get::_M_extract_int): + Admit grouping for octals and hexadecimals too. + * testsuite/22_locale/num_get_members_char.cc: Add test04. + (test01): Tweak "." -> "," in void* test. + * testsuite/22_locale/num_get_members_wchar_t.cc: Ditto. + + * testsuite/27_io/ios_manip_basefield.cc: Remove static keyword. + * testsuite/27_io/ios_manip_fmtflags.cc: Remove two of them. + 2002-02-27 Paolo Carlini <pcarlini@unitus.it> * testsuite/27_io/ios_manip_basefield.cc (test01): diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index 4f4cb11..4f31bd6 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -310,7 +310,7 @@ namespace std __ctype.widen(_S_atoms, _S_atoms + __len, __watoms); string __found_grouping; const string __grouping = __np.grouping(); - bool __check_grouping = __grouping.size() && __base == 10; + bool __check_grouping = __grouping.size(); int __sep_pos = 0; const char_type __sep = __np.thousands_sep(); while (__beg != __end) diff --git a/libstdc++-v3/testsuite/22_locale/num_get_members_char.cc b/libstdc++-v3/testsuite/22_locale/num_get_members_char.cc index 1c9d8f0..8907d08 100644 --- a/libstdc++-v3/testsuite/22_locale/num_get_members_char.cc +++ b/libstdc++-v3/testsuite/22_locale/num_get_members_char.cc @@ -213,7 +213,7 @@ void test01() VERIFY( err == goodbit ); // const void - iss.str("0xbffff74c."); + iss.str("0xbffff74c,"); iss.clear(); err = goodbit; ng.get(iss.rdbuf(), 0, iss, err, v); @@ -332,11 +332,76 @@ void test03() #endif } +struct MyNP : std::numpunct<char> +{ + std::string do_grouping() const; + char do_thousands_sep() const; +}; + +std::string MyNP::do_grouping() const { std::string s("\3"); return s; } +char MyNP::do_thousands_sep() const { return ' '; } + +// Testing the correct parsing of grouped hexadecimals and octals. +void test04() +{ + using namespace std; + + bool test = true; + + unsigned long ul; + + istringstream iss; + iss.imbue(locale(locale(), new MyNP)); + + const num_get<char>& ng = use_facet<num_get<char> >(iss.getloc()); + const ios_base::iostate goodbit = ios_base::goodbit; + ios_base::iostate err = ios_base::goodbit; + + iss.setf(ios::hex, ios::basefield); + iss.str("0xbf fff 74c."); + err = goodbit; + ng.get(iss.rdbuf(), 0, iss, err, ul); + VERIFY( err == goodbit ); + VERIFY( ul == 0xbffff74c ); + + iss.str("0Xf fff."); + err = goodbit; + ng.get(iss.rdbuf(), 0, iss, err, ul); + VERIFY( err == goodbit ); + VERIFY( ul == 0xffff ); + + iss.str("f ffe."); + err = goodbit; + ng.get(iss.rdbuf(), 0, iss, err, ul); + VERIFY( err == goodbit ); + VERIFY( ul == 0xfffe ); + + iss.setf(ios::oct, ios::basefield); + iss.str("07 654 321."); + err = goodbit; + ng.get(iss.rdbuf(), 0, iss, err, ul); + VERIFY( err == goodbit ); + VERIFY( ul == 07654321 ); + + iss.str("07 777."); + err = goodbit; + ng.get(iss.rdbuf(), 0, iss, err, ul); + VERIFY( err == goodbit ); + VERIFY( ul == 07777 ); + + iss.str("7 776."); + err = goodbit; + ng.get(iss.rdbuf(), 0, iss, err, ul); + VERIFY( err == goodbit ); + VERIFY( ul == 07776 ); +} + int main() { test01(); test02(); test03(); + test04(); return 0; } diff --git a/libstdc++-v3/testsuite/22_locale/num_get_members_wchar_t.cc b/libstdc++-v3/testsuite/22_locale/num_get_members_wchar_t.cc index 53fb9c9..cbd39ae 100644 --- a/libstdc++-v3/testsuite/22_locale/num_get_members_wchar_t.cc +++ b/libstdc++-v3/testsuite/22_locale/num_get_members_wchar_t.cc @@ -214,7 +214,7 @@ void test01() VERIFY( err == goodbit ); // const void - iss.str(L"0xbffff74c."); + iss.str(L"0xbffff74c,"); iss.clear(); err = goodbit; ng.get(iss.rdbuf(), 0, iss, err, v); @@ -333,6 +333,70 @@ void test03() } #endif } + +struct MyNP : std::numpunct<wchar_t> +{ + std::string do_grouping() const; + wchar_t do_thousands_sep() const; +}; + +std::string MyNP::do_grouping() const { std::string s("\3"); return s; } +wchar_t MyNP::do_thousands_sep() const { return L' '; } + +// Testing the correct parsing of grouped hexadecimals and octals. +void test04() +{ + using namespace std; + + bool test = true; + + unsigned long ul; + + wistringstream iss; + iss.imbue(locale(locale(), new MyNP)); + + const num_get<wchar_t>& ng = use_facet<num_get<wchar_t> >(iss.getloc()); + const ios_base::iostate goodbit = ios_base::goodbit; + ios_base::iostate err = ios_base::goodbit; + + iss.setf(ios::hex, ios::basefield); + iss.str(L"0xbf fff 74c."); + err = goodbit; + ng.get(iss.rdbuf(), 0, iss, err, ul); + VERIFY( err == goodbit ); + VERIFY( ul == 0xbffff74c ); + + iss.str(L"0Xf fff."); + err = goodbit; + ng.get(iss.rdbuf(), 0, iss, err, ul); + VERIFY( err == goodbit ); + VERIFY( ul == 0xffff ); + + iss.str(L"f ffe."); + err = goodbit; + ng.get(iss.rdbuf(), 0, iss, err, ul); + VERIFY( err == goodbit ); + VERIFY( ul == 0xfffe ); + + iss.setf(ios::oct, ios::basefield); + iss.str(L"07 654 321."); + err = goodbit; + ng.get(iss.rdbuf(), 0, iss, err, ul); + VERIFY( err == goodbit ); + VERIFY( ul == 07654321 ); + + iss.str(L"07 777."); + err = goodbit; + ng.get(iss.rdbuf(), 0, iss, err, ul); + VERIFY( err == goodbit ); + VERIFY( ul == 07777 ); + + iss.str(L"7 776."); + err = goodbit; + ng.get(iss.rdbuf(), 0, iss, err, ul); + VERIFY( err == goodbit ); + VERIFY( ul == 07776 ); +} #endif int main() @@ -341,6 +405,7 @@ int main() test01(); test02(); test03(); + test04(); #endif return 0; } diff --git a/libstdc++-v3/testsuite/27_io/ios_manip_basefield.cc b/libstdc++-v3/testsuite/27_io/ios_manip_basefield.cc index 9a19699..1ce1d08 100644 --- a/libstdc++-v3/testsuite/27_io/ios_manip_basefield.cc +++ b/libstdc++-v3/testsuite/27_io/ios_manip_basefield.cc @@ -38,7 +38,7 @@ struct MyNP : std::numpunct<char> char do_thousands_sep() const; }; -std::string MyNP::do_grouping() const { static std::string s("\3"); return s; } +std::string MyNP::do_grouping() const { std::string s("\3"); return s; } char MyNP::do_thousands_sep() const { return ' '; } int diff --git a/libstdc++-v3/testsuite/27_io/ios_manip_fmtflags.cc b/libstdc++-v3/testsuite/27_io/ios_manip_fmtflags.cc index 64b1b85..3173dc3 100644 --- a/libstdc++-v3/testsuite/27_io/ios_manip_fmtflags.cc +++ b/libstdc++-v3/testsuite/27_io/ios_manip_fmtflags.cc @@ -41,13 +41,13 @@ struct MyNP : std::numpunct<char> std::string MyNP::do_truename() const { - static std::string s("yea"); + std::string s("yea"); return s; } std::string MyNP::do_falsename() const { - static std::string s("nay"); + std::string s("nay"); return s; } |