From 0a745021e7d6676ded2a344134b68b180fb3be60 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 22 Jul 2017 19:10:19 -0400 Subject: Remove PCRE from QPDFTokenizer --- libqpdf/QPDFTokenizer.cc | 51 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) (limited to 'libqpdf') diff --git a/libqpdf/QPDFTokenizer.cc b/libqpdf/QPDFTokenizer.cc index 91b16825..90961006 100644 --- a/libqpdf/QPDFTokenizer.cc +++ b/libqpdf/QPDFTokenizer.cc @@ -4,7 +4,6 @@ // it's not worth the risk of including it in case it may accidentally // be used. -#include #include #include @@ -20,6 +19,52 @@ 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), @@ -59,8 +104,6 @@ QPDFTokenizer::reset() void QPDFTokenizer::resolveLiteral() { - PCRE num_re("^[\\+\\-]?(?:\\.\\d+|\\d+(?:\\.\\d+)?)$"); - if ((val.length() > 0) && (val.at(0) == '/')) { type = tt_name; @@ -110,7 +153,7 @@ QPDFTokenizer::resolveLiteral() } val = nval; } - else if (num_re.match(val.c_str())) + else if (is_number(val)) { if (val.find('.') != std::string::npos) { -- cgit v1.2.3-54-g00ecf