From dd8dad74f47b6068281dd605a04bc2d0b6283423 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 22 Jul 2017 19:23:52 -0400 Subject: Move lexer helper functions to QUtil --- libqpdf/QPDFTokenizer.cc | 65 ++++-------------------------------------------- 1 file changed, 5 insertions(+), 60 deletions(-) (limited to 'libqpdf/QPDFTokenizer.cc') diff --git a/libqpdf/QPDFTokenizer.cc b/libqpdf/QPDFTokenizer.cc index 90961006..40f04f34 100644 --- a/libqpdf/QPDFTokenizer.cc +++ b/libqpdf/QPDFTokenizer.cc @@ -6,66 +6,11 @@ #include #include +#include #include #include -// See note above about ctype. -static bool is_hex_digit(char ch) -{ - return (strchr("0123456789abcdefABCDEF", ch) != 0); -} -static bool is_space(char ch) -{ - return (strchr(" \f\n\r\t\v", ch) != 0); -} -static bool is_digit(char ch) -{ - return ((ch >= '0') && (ch <= '9')); -} -static bool -is_number(std::string const& str) -{ - // ^[\+\-]?(\.\d+|\d+(\.\d+)?)$ - char const* p = str.c_str(); - if (! *p) - { - return false; - } - if ((*p == '-') || (*p == '+')) - { - ++p; - } - bool found_dot = false; - bool found_digit = false; - for (; *p; ++p) - { - if (*p == '.') - { - if (found_dot) - { - // only one dot - return false; - } - if (! *(p+1)) - { - // dot can't be last - return false; - } - found_dot = true; - } - else if (is_digit(*p)) - { - found_digit = true; - } - else - { - return false; - } - } - return found_digit; -} - QPDFTokenizer::QPDFTokenizer() : pound_special_in_name(true), allow_eof(false) @@ -117,7 +62,7 @@ QPDFTokenizer::resolveLiteral() if ((*p == '#') && this->pound_special_in_name) { if (p[1] && p[2] && - is_hex_digit(p[1]) && is_hex_digit(p[2])) + QUtil::is_hex_digit(p[1]) && QUtil::is_hex_digit(p[2])) { char num[3]; num[0] = p[1]; @@ -153,7 +98,7 @@ QPDFTokenizer::resolveLiteral() } val = nval; } - else if (is_number(val)) + else if (QUtil::is_number(val.c_str())) { if (val.find('.') != std::string::npos) { @@ -447,7 +392,7 @@ QPDFTokenizer::presentCharacter(char ch) } val = nval; } - else if (is_hex_digit(ch)) + else if (QUtil::is_hex_digit(ch)) { val += ch; } @@ -554,7 +499,7 @@ QPDFTokenizer::readToken(PointerHolder input, } else { - if (is_space(static_cast(ch)) && + if (QUtil::is_space(static_cast(ch)) && (input->getLastOffset() == offset)) { ++offset; -- cgit v1.2.3-54-g00ecf