summaryrefslogtreecommitdiff
path: root/cxx/isfuns.cc
diff options
context:
space:
mode:
authorKevin Ryde <user42@zip.com.au>2001-10-09 03:22:19 +0200
committerKevin Ryde <user42@zip.com.au>2001-10-09 03:22:19 +0200
commitddc1b47f3e826d602fd9ddf4f1500412b33593ee (patch)
treed625d5fa3d909781afcf1466c904d2568952c9e8 /cxx/isfuns.cc
parent1b4c4adb01a1ffd62375a5dc4192f524e3f71c02 (diff)
downloadgmp-ddc1b47f3e826d602fd9ddf4f1500412b33593ee.tar.gz
2001-10-09 Gerardo Ballabio <ballabio@sissa.it>
* cxx/isfuns.cc: New file.
Diffstat (limited to 'cxx/isfuns.cc')
-rw-r--r--cxx/isfuns.cc104
1 files changed, 104 insertions, 0 deletions
diff --git a/cxx/isfuns.cc b/cxx/isfuns.cc
new file mode 100644
index 000000000..c29ed7f03
--- /dev/null
+++ b/cxx/isfuns.cc
@@ -0,0 +1,104 @@
+/* Auxiliary functions for C++-style input of GMP types.
+
+Copyright 2001 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or (at your
+option) any later version.
+
+The GNU MP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the GNU MP Library; see the file COPYING.LIB. If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+#include <cctype>
+#include <iostream>
+#include <string>
+#include "gmp.h"
+#include "gmp-impl.h"
+
+int
+__gmp_istream_set_base (istream &i, char &c, bool &zero, bool &showbase)
+{
+ int base;
+
+ zero = showbase = false;
+ switch (i.flags() & ios::basefield)
+ {
+ case ios::dec:
+ base = 10;
+ break;
+ case ios::hex:
+ base = 16;
+ break;
+ case ios::oct:
+ base = 8;
+ break;
+ default:
+ showbase = true; // look for initial "0" or "0x" or "0X"
+ if (c == '0')
+ {
+ if (! i.get(c))
+ c = 0; // reset or we might loop indefinitely
+
+ if (c == 'x' || c == 'X')
+ {
+ base = 16;
+ i.get(c);
+ }
+ else
+ {
+ base = 8;
+ zero = true; // if no other digit is read, the "0" counts
+ }
+ }
+ else
+ base = 10;
+ break;
+ }
+
+ return base;
+}
+
+void
+__gmp_istream_set_digits (string &s, istream &i, char &c, bool &ok, int base)
+{
+ switch (base)
+ {
+ case 10:
+ while (isdigit(c))
+ {
+ ok = true; // at least a valid digit was read
+ s += c;
+ if (! i.get(c))
+ break;
+ }
+ break;
+ case 8:
+ while (isdigit(c) && c != '8' && c != '9')
+ {
+ ok = true; // at least a valid digit was read
+ s += c;
+ if (! i.get(c))
+ break;
+ }
+ break;
+ case 16:
+ while (isxdigit(c))
+ {
+ ok = true; // at least a valid digit was read
+ s += c;
+ if (! i.get(c))
+ break;
+ }
+ break;
+ }
+}