~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

« back to all changes in this revision

Viewing changes to gmp3/cxx/isfuns.cc

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-06-24 15:13:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040624151346-xh0xaaktyyp7aorc
Tags: 2.7.0-26
C_GC_OFFSET is 2 on m68k-linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Auxiliary functions for C++-style input of GMP types.
 
2
 
 
3
Copyright 2001 Free Software Foundation, Inc.
 
4
 
 
5
This file is part of the GNU MP Library.
 
6
 
 
7
The GNU MP Library is free software; you can redistribute it and/or modify
 
8
it under the terms of the GNU Lesser General Public License as published by
 
9
the Free Software Foundation; either version 2.1 of the License, or (at your
 
10
option) any later version.
 
11
 
 
12
The GNU MP Library is distributed in the hope that it will be useful, but
 
13
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
14
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 
15
License for more details.
 
16
 
 
17
You should have received a copy of the GNU Lesser General Public License
 
18
along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
 
19
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 
20
MA 02111-1307, USA. */
 
21
 
 
22
#include <cctype>
 
23
#include <iostream>
 
24
#include <string>
 
25
#include "gmp.h"
 
26
#include "gmp-impl.h"
 
27
 
 
28
using namespace std;
 
29
 
 
30
 
 
31
int
 
32
__gmp_istream_set_base (istream &i, char &c, bool &zero, bool &showbase)
 
33
{
 
34
  int base;
 
35
 
 
36
  zero = showbase = false;
 
37
  switch (i.flags() & ios::basefield)
 
38
    {
 
39
    case ios::dec:
 
40
      base = 10;
 
41
      break;
 
42
    case ios::hex:
 
43
      base = 16;
 
44
      break;
 
45
    case ios::oct:
 
46
      base = 8;
 
47
      break;
 
48
    default:
 
49
      showbase = true; // look for initial "0" or "0x" or "0X"
 
50
      if (c == '0')
 
51
        {
 
52
          if (! i.get(c))
 
53
            c = 0; // reset or we might loop indefinitely
 
54
 
 
55
          if (c == 'x' || c == 'X')
 
56
            {
 
57
              base = 16;
 
58
              i.get(c);
 
59
            }
 
60
          else
 
61
            {
 
62
              base = 8;
 
63
              zero = true; // if no other digit is read, the "0" counts
 
64
            }
 
65
        }
 
66
      else
 
67
        base = 10;
 
68
      break;
 
69
    }
 
70
 
 
71
  return base;
 
72
}
 
73
 
 
74
void
 
75
__gmp_istream_set_digits (string &s, istream &i, char &c, bool &ok, int base)
 
76
{
 
77
  switch (base)
 
78
    {
 
79
    case 10:
 
80
      while (isdigit(c))
 
81
        {
 
82
          ok = true; // at least a valid digit was read
 
83
          s += c;
 
84
          if (! i.get(c))
 
85
            break;
 
86
        }
 
87
      break;
 
88
    case 8:
 
89
      while (isdigit(c) && c != '8' && c != '9')
 
90
        {
 
91
          ok = true; // at least a valid digit was read
 
92
          s += c;
 
93
          if (! i.get(c))
 
94
            break;
 
95
        }
 
96
      break;
 
97
    case 16:
 
98
      while (isxdigit(c))
 
99
        {
 
100
          ok = true; // at least a valid digit was read
 
101
          s += c;
 
102
          if (! i.get(c))
 
103
            break;
 
104
        }
 
105
      break;
 
106
    }
 
107
}