summaryrefslogtreecommitdiff
path: root/cxx
diff options
context:
space:
mode:
authorKevin Ryde <user42@zip.com.au>2003-10-18 00:29:31 +0200
committerKevin Ryde <user42@zip.com.au>2003-10-18 00:29:31 +0200
commitdf1d289549040b194ad1f0803c4b82775a406e66 (patch)
tree756978486458523307de5680f422693381d06e1a /cxx
parent7cf96ca114e41fa6166ab4c3436e4f7703af41ab (diff)
downloadgmp-df1d289549040b194ad1f0803c4b82775a406e66.tar.gz
* cxx/ismpz.cc, cxx/ismpq.cc, cxx/ismpf.cc: Use istream std::locale
ctype facet for isspace when available. Only accept space at the start of the input, same as g++ libstdc++. Use ASSERT_NOCARRY to check result of mpz_set_str etc.
Diffstat (limited to 'cxx')
-rw-r--r--cxx/ismpz.cc23
1 files changed, 16 insertions, 7 deletions
diff --git a/cxx/ismpz.cc b/cxx/ismpz.cc
index 07b385410..0cc3e7980 100644
--- a/cxx/ismpz.cc
+++ b/cxx/ismpz.cc
@@ -1,6 +1,6 @@
/* operator>> -- C++-style input of mpz_t.
-Copyright 2001 Free Software Foundation, Inc.
+Copyright 2001, 2003 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -28,6 +28,9 @@ MA 02111-1307, USA. */
using namespace std;
+// For g++ libstdc++ parsing see num_get<chartype,initer>::_M_extract_int in
+// include/bits/locale_facets.tcc.
+
istream &
operator>> (istream &i, mpz_ptr z)
{
@@ -39,8 +42,17 @@ operator>> (istream &i, mpz_ptr z)
i.get(c); // start reading
if (i.flags() & ios::skipws) // skip initial whitespace
- while (isspace(c) && i.get(c))
- ;
+ {
+#if HAVE_STD__LOCALE
+ const ctype<char>& ct = use_facet< ctype<char> >(i.getloc());
+#define cxx_isspace(c) (ct.is(ctype_base::space,(c)))
+#else
+#define cxx_isspace(c) isspace(c)
+#endif
+
+ while (cxx_isspace(c) && i.get(c))
+ ;
+ }
if (c == '-' || c == '+') // sign
{
@@ -49,9 +61,6 @@ operator>> (istream &i, mpz_ptr z)
i.get(c);
}
- while (isspace(c) && i.get(c)) // skip whitespace
- ;
-
base = __gmp_istream_set_base(i, c, zero, showbase); // select the base
__gmp_istream_set_digits(s, i, c, ok, base); // read the number
@@ -61,7 +70,7 @@ operator>> (istream &i, mpz_ptr z)
i.clear();
if (ok)
- mpz_set_str(z, s.c_str(), base); // extract the number
+ ASSERT_NOCARRY (mpz_set_str (z, s.c_str(), base)); // extract the number
else if (zero)
mpz_set_ui(z, 0);
else