aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDFTokenizer.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2017-07-23 01:10:19 +0200
committerJay Berkenbilt <ejb@ql.org>2017-07-27 19:59:56 +0200
commit0a745021e7d6676ded2a344134b68b180fb3be60 (patch)
tree9dacc49261dbda00537d6497d7b360c20409a4ff /libqpdf/QPDFTokenizer.cc
parent8740b380fe31a51b0472d1e4b902cfc9bce21c3a (diff)
downloadqpdf-0a745021e7d6676ded2a344134b68b180fb3be60.tar.zst
Remove PCRE from QPDFTokenizer
Diffstat (limited to 'libqpdf/QPDFTokenizer.cc')
-rw-r--r--libqpdf/QPDFTokenizer.cc51
1 files changed, 47 insertions, 4 deletions
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 <qpdf/PCRE.hh>
#include <qpdf/QTC.hh>
#include <qpdf/QPDFExc.hh>
@@ -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)
{