aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDFTokenizer.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2017-07-23 01:23:52 +0200
committerJay Berkenbilt <ejb@ql.org>2017-07-27 19:59:56 +0200
commitdd8dad74f47b6068281dd605a04bc2d0b6283423 (patch)
treedb7d72b522591b4f47bf44569713dc9752416b63 /libqpdf/QPDFTokenizer.cc
parent0a745021e7d6676ded2a344134b68b180fb3be60 (diff)
downloadqpdf-dd8dad74f47b6068281dd605a04bc2d0b6283423.tar.zst
Move lexer helper functions to QUtil
Diffstat (limited to 'libqpdf/QPDFTokenizer.cc')
-rw-r--r--libqpdf/QPDFTokenizer.cc65
1 files changed, 5 insertions, 60 deletions
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 <qpdf/QTC.hh>
#include <qpdf/QPDFExc.hh>
+#include <qpdf/QUtil.hh>
#include <stdexcept>
#include <string.h>
-// 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<InputSource> input,
}
else
{
- if (is_space(static_cast<unsigned char>(ch)) &&
+ if (QUtil::is_space(static_cast<unsigned char>(ch)) &&
(input->getLastOffset() == offset))
{
++offset;