1 #include "cvc4autoconfig.h"
2 #include "util/integer.h"
7 # error "This source should only ever be built if CVC4_CLN_IMP is on !"
8 #endif /* CVC4_CLN_IMP */
14 void Integer::parseInt(const std::string
& s
, unsigned base
) throw(std::invalid_argument
) {
15 cln::cl_read_flags flags
;
16 flags
.syntax
= cln::syntax_integer
;
17 flags
.lsyntax
= cln::lsyntax_standard
;
18 flags
.rational_base
= base
;
20 // infer base in a manner consistent with GMP
22 flags
.lsyntax
= cln::lsyntax_commonlisp
;
24 if(s
[1] == 'X' || s
[1] == 'x') {
25 st
.replace(0, 2, "#x");
26 } else if(s
[1] == 'B' || s
[1] == 'b') {
27 st
.replace(0, 2, "#b");
29 st
.replace(0, 1, "#o");
31 readInt(flags
, st
, base
);
34 flags
.rational_base
= 10;
37 readInt(flags
, s
, base
);
40 void Integer::readInt(const cln::cl_read_flags
& flags
, const std::string
& s
, unsigned base
) throw(std::invalid_argument
) {
42 // Removing leading zeroes, CLN has a bug for these inputs up to and
43 // including CLN v1.3.2.
44 // See http://www.ginac.de/CLN/cln.git/?a=commit;h=4a477b0cc3dd7fbfb23b25090ff8c8869c8fa21a for details.
45 size_t pos
= s
.find_first_not_of('0');
46 if(pos
== std::string::npos
) {
47 d_value
= read_integer(flags
, "0", NULL
, NULL
);
49 const char* cstr
= s
.c_str();
50 const char* start
= cstr
+ pos
;
51 const char* end
= cstr
+ s
.length();
52 d_value
= read_integer(flags
, start
, end
, NULL
);
56 ss
<< "Integer() failed to parse value \"" << s
<< "\" in base " << base
;
57 throw std::invalid_argument(ss
.str());