aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <pcarlini@unitus.it>2002-09-28 01:08:22 +0200
committerPaolo Carlini <paolo@gcc.gnu.org>2002-09-27 23:08:22 +0000
commitb1af5a30a54316b085b979805a6bced0ff93a7b1 (patch)
tree8df33c36f6136919b5d4aba511e02d7ac7e56e3e
parent2a5de0f14b830705d871fd5ce966feefda294a18 (diff)
downloadgcc-b1af5a30a54316b085b979805a6bced0ff93a7b1.zip
gcc-b1af5a30a54316b085b979805a6bced0ff93a7b1.tar.gz
gcc-b1af5a30a54316b085b979805a6bced0ff93a7b1.tar.bz2
locale_facets.tcc (num_put::_M_widen_int): Deal correctly with grouped, showbased (oct or hex) zero.
2002-09-27 Paolo Carlini <pcarlini@unitus.it> * include/bits/locale_facets.tcc (num_put::_M_widen_int): Deal correctly with grouped, showbased (oct or hex) zero. * testsuite/22_locale/num_put_members_char.cc: Add test05. * testsuite/22_locale/num_put_members_wchar_t.cc: Ditto. From-SVN: r57598
-rw-r--r--libstdc++-v3/ChangeLog7
-rw-r--r--libstdc++-v3/include/bits/locale_facets.tcc4
-rw-r--r--libstdc++-v3/testsuite/22_locale/num_put_members_char.cc38
-rw-r--r--libstdc++-v3/testsuite/22_locale/num_put_members_wchar_t.cc38
4 files changed, 86 insertions, 1 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index aa1c2a5..5309c0a 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,10 @@
+2002-09-27 Paolo Carlini <pcarlini@unitus.it>
+
+ * include/bits/locale_facets.tcc (num_put::_M_widen_int):
+ Deal correctly with grouped, showbased (oct or hex) zero.
+ * testsuite/22_locale/num_put_members_char.cc: Add test05.
+ * testsuite/22_locale/num_put_members_wchar_t.cc: Ditto.
+
2002-09-27 Richard Henderson <rth@redhat.com>
* config/os/hpux/cpu_limits.h: Remove.
diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc
index 195d33a..f21054e 100644
--- a/libstdc++-v3/include/bits/locale_facets.tcc
+++ b/libstdc++-v3/include/bits/locale_facets.tcc
@@ -798,8 +798,10 @@ namespace std
// By itself __add_grouping cannot deal correctly with __ws when
// ios::showbase is set and ios_base::oct || ios_base::hex.
// Therefore we take care "by hand" of the initial 0, 0x or 0X.
+ // However, remember that the latter do not occur if the number
+ // printed is '0' (__len == 1).
streamsize __off = 0;
- if (__io.flags() & ios_base::showbase)
+ if ((__io.flags() & ios_base::showbase) && __len > 1)
if (__basefield == ios_base::oct)
{
__off = 1;
diff --git a/libstdc++-v3/testsuite/22_locale/num_put_members_char.cc b/libstdc++-v3/testsuite/22_locale/num_put_members_char.cc
index fcc1f79..e93900b 100644
--- a/libstdc++-v3/testsuite/22_locale/num_put_members_char.cc
+++ b/libstdc++-v3/testsuite/22_locale/num_put_members_char.cc
@@ -326,12 +326,50 @@ void test04()
}
}
+// Make sure that, in a locale that expects grouping, when showbase
+// is true, an hexadecimal or octal zero is correctly output (the case
+// of zero is special since there is no 0x, 0 respectively, prefix)
+void test05()
+{
+ using namespace std;
+ bool test = true;
+
+ // A locale that expects grouping.
+ locale loc_de("de_DE");
+
+ const string empty;
+ string result;
+
+ ostringstream oss;
+ oss.imbue(loc_de);
+ const num_put<char>& np = use_facet<num_put<char> >(oss.getloc());
+
+ long l = 0;
+
+ oss.str(empty);
+ oss.clear();
+ oss.setf(ios::showbase);
+ oss.setf(ios::hex, ios::basefield);
+ np.put(oss.rdbuf(), oss, '+', l);
+ result = oss.str();
+ VERIFY( result == "0" );
+
+ oss.str(empty);
+ oss.clear();
+ oss.setf(ios::showbase);
+ oss.setf(ios::oct, ios::basefield);
+ np.put(oss.rdbuf(), oss, '+', l);
+ result = oss.str();
+ VERIFY( result == "0" );
+}
+
int main()
{
test01();
test02();
test03();
test04();
+ test05();
return 0;
}
diff --git a/libstdc++-v3/testsuite/22_locale/num_put_members_wchar_t.cc b/libstdc++-v3/testsuite/22_locale/num_put_members_wchar_t.cc
index 4fbf25f..53fdd59 100644
--- a/libstdc++-v3/testsuite/22_locale/num_put_members_wchar_t.cc
+++ b/libstdc++-v3/testsuite/22_locale/num_put_members_wchar_t.cc
@@ -325,6 +325,43 @@ void test04()
VERIFY( preLANG == postLANG );
}
}
+
+// Make sure that, in a locale that expects grouping, when showbase
+// is true, an hexadecimal or octal zero is correctly output (the case
+// of zero is special since there is no 0x, 0 respectively, prefix)
+void test05()
+{
+ using namespace std;
+ bool test = true;
+
+ // A locale that expects grouping.
+ locale loc_de("de_DE");
+
+ const wstring empty;
+ wstring result;
+
+ wostringstream oss;
+ oss.imbue(loc_de);
+ const num_put<wchar_t>& np = use_facet<num_put<wchar_t> >(oss.getloc());
+
+ long l = 0;
+
+ oss.str(empty);
+ oss.clear();
+ oss.setf(ios::showbase);
+ oss.setf(ios::hex, ios::basefield);
+ np.put(oss.rdbuf(), oss, L'+', l);
+ result = oss.str();
+ VERIFY( result == L"0" );
+
+ oss.str(empty);
+ oss.clear();
+ oss.setf(ios::showbase);
+ oss.setf(ios::oct, ios::basefield);
+ np.put(oss.rdbuf(), oss, L'+', l);
+ result = oss.str();
+ VERIFY( result == L"0" );
+}
#endif
int main()
@@ -334,6 +371,7 @@ int main()
test02();
test03();
test04();
+ test05();
#endif
return 0;
}