[poincare] Relative integer string parsing

This commit is contained in:
Romain Goyet
2015-09-21 14:52:59 +02:00
parent 9473d0d89e
commit 4fb2236ab5
2 changed files with 9 additions and 5 deletions

View File

@@ -48,6 +48,13 @@ Integer::Integer(const char * string) {
Integer base = Integer(10);
m_negative = false;
if (stringLength > 1 && string[0] == '-') {
m_negative = true;
string += 1;
stringLength -= 1;
}
if (stringLength > 2 && string[0] == '0') {
switch (string[1]) {
case 'x':
@@ -69,10 +76,6 @@ Integer::Integer(const char * string) {
v = v + Integer(digit_from_char(string[i])); // ASCII encoding
}
m_negative = 0;
#if 0
*this = v;
#else
// Pilfer v's ivars
m_numberOfDigits = v.m_numberOfDigits;
m_digits = v.m_digits;
@@ -80,7 +83,6 @@ Integer::Integer(const char * string) {
// Zero-out v
v.m_numberOfDigits = 0;
v.m_digits = NULL;
#endif
}
Integer::~Integer() {

View File

@@ -5,6 +5,8 @@
QUIZ_CASE(poincare_integer) {
assert(Integer(123) == Integer(123));
assert(Integer("123") == Integer(123));
assert(!(Integer("-123") == Integer(123)));
assert(Integer("-123") == Integer(-123));
//assert(Integer("0123") == Integer(123));
assert(Integer("0x2BABE") == Integer(178878));
assert(Integer("0b1011") == Integer(11));