}
if (s >= end) return false;
}
- if (( base == 0 || base == 16) && *s == '0' && (s+1 <= end ) &&
+ if (( base == 0 || base == 16) && *s == '0' && (s+1 < end ) &&
tolower(*(s+1)) == 'x') {
s += 2;
base = 16;
int any = 0, c;
int64_t acc = 0;
- for (c = *s++; s <= end; c = *s++) {
+ do {
+ c = *s;
if (xisdigit(c)) {
c -= '0';
} else if (xisalpha(c)) {
acc *= base;
acc += c;
}
- }
+ } while (++s < end);
if (any == 0) // nothing was parsed
return false;
acc = -acc;
result = acc;
- return success(s - range.rawContent() - 1);
+ return success(s - range.rawContent());
}
const int64_t benchmark = 1234;
CPPUNIT_ASSERT(t.int64(rv, 10));
CPPUNIT_ASSERT_EQUAL(benchmark,rv);
+ CPPUNIT_ASSERT(t.buf().isEmpty());
}
// successful parse, autodetect base
const int64_t benchmark = 1234;
CPPUNIT_ASSERT(t.int64(rv));
CPPUNIT_ASSERT_EQUAL(benchmark,rv);
+ CPPUNIT_ASSERT(t.buf().isEmpty());
}
// successful parse, autodetect base
const int64_t benchmark = 01234;
CPPUNIT_ASSERT(t.int64(rv));
CPPUNIT_ASSERT_EQUAL(benchmark,rv);
+ CPPUNIT_ASSERT(t.buf().isEmpty());
}
// successful parse, autodetect base
const int64_t benchmark = 0x12f4;
CPPUNIT_ASSERT(t.int64(rv));
CPPUNIT_ASSERT_EQUAL(benchmark,rv);
+ CPPUNIT_ASSERT(t.buf().isEmpty());
}
// API mismatch: don't eat leading space
int64_t rv;
Parser::Tokenizer t(SBuf(" 1234"));
CPPUNIT_ASSERT(!t.int64(rv));
+ CPPUNIT_ASSERT_EQUAL(SBuf(" 1234"), t.buf());
}
// API mismatch: don't eat multiple leading spaces
int64_t rv;
Parser::Tokenizer t(SBuf(" 1234"));
CPPUNIT_ASSERT(!t.int64(rv));
+ CPPUNIT_ASSERT_EQUAL(SBuf(" 1234"), t.buf());
}
// trailing spaces
int64_t rv;
Parser::Tokenizer t(SBuf("1029397752385698678762234"));
CPPUNIT_ASSERT(!t.int64(rv));
+ CPPUNIT_ASSERT_EQUAL(SBuf("1029397752385698678762234"), t.buf());
}
// buffered sub-string parsing
CPPUNIT_ASSERT_EQUAL(SBuf("22"),t.buf());
CPPUNIT_ASSERT(t.int64(rv));
CPPUNIT_ASSERT_EQUAL(benchmark,rv);
+ CPPUNIT_ASSERT(t.buf().isEmpty());
}
// base-16, prefix