* or guesstimated; consumes the parsed characters.
*
* \param result output value. Not touched if parseing is unsuccessful
- * \param base specify base to do the parsing in. Admitted values are
- * 8, 10, 16 and 0, the latter specifying to use C syntax for guessing
- * the base
+ * \param base specify base to do the parsing in, with the same restrictions
+ * as strtoll. Defaults to 0 (meaning guess)
* \return true if the parsing was successful
*/
bool int64 (int64_t &result, int base = 0);
void
testTokenizer::testTokenizerInt64()
{
- int64_t rv;
-
// successful parse in base 10
{
+ int64_t rv;
Parser::Tokenizer t(SBuf("1234"));
const int64_t benchmark = 1234;
CPPUNIT_ASSERT(t.int64(rv, 10));
// successful parse, autodetect base
{
+ int64_t rv;
Parser::Tokenizer t(SBuf("1234"));
const int64_t benchmark = 1234;
CPPUNIT_ASSERT(t.int64(rv));
// successful parse, autodetect base
{
+ int64_t rv;
Parser::Tokenizer t(SBuf("01234"));
const int64_t benchmark = 01234;
CPPUNIT_ASSERT(t.int64(rv));
// successful parse, autodetect base
{
+ int64_t rv;
Parser::Tokenizer t(SBuf("0x12f4"));
const int64_t benchmark = 0x12f4;
CPPUNIT_ASSERT(t.int64(rv));
// API mismatch: don't eat leading space
{
+ int64_t rv;
Parser::Tokenizer t(SBuf(" 1234"));
CPPUNIT_ASSERT(!t.int64(rv));
}
// API mismatch: don't eat multiple leading spaces
{
+ int64_t rv;
Parser::Tokenizer t(SBuf(" 1234"));
CPPUNIT_ASSERT(!t.int64(rv));
}
// trailing spaces
{
+ int64_t rv;
Parser::Tokenizer t(SBuf("1234 foo"));
const int64_t benchmark = 1234;
CPPUNIT_ASSERT(t.int64(rv));
// trailing nonspaces
{
+ int64_t rv;
Parser::Tokenizer t(SBuf("1234foo"));
const int64_t benchmark = 1234;
CPPUNIT_ASSERT(t.int64(rv));
// trailing nonspaces
{
+ int64_t rv;
Parser::Tokenizer t(SBuf("0x1234foo"));
const int64_t benchmark = 0x1234f;
CPPUNIT_ASSERT(t.int64(rv));
CPPUNIT_ASSERT_EQUAL(benchmark,rv);
CPPUNIT_ASSERT_EQUAL(SBuf("oo"), t.buf());
}
+
+ // overflow
+ {
+ int64_t rv;
+ Parser::Tokenizer t(SBuf("1029397752385698678762234"));
+ CPPUNIT_ASSERT(!t.int64(rv));
+ }
}