Commit 0a745021e7d6676ded2a344134b68b180fb3be60
1 parent
8740b380
Remove PCRE from QPDFTokenizer
Showing
1 changed file
with
47 additions
and
4 deletions
libqpdf/QPDFTokenizer.cc
| @@ -4,7 +4,6 @@ | @@ -4,7 +4,6 @@ | ||
| 4 | // it's not worth the risk of including it in case it may accidentally | 4 | // it's not worth the risk of including it in case it may accidentally |
| 5 | // be used. | 5 | // be used. |
| 6 | 6 | ||
| 7 | -#include <qpdf/PCRE.hh> | ||
| 8 | #include <qpdf/QTC.hh> | 7 | #include <qpdf/QTC.hh> |
| 9 | #include <qpdf/QPDFExc.hh> | 8 | #include <qpdf/QPDFExc.hh> |
| 10 | 9 | ||
| @@ -20,6 +19,52 @@ static bool is_space(char ch) | @@ -20,6 +19,52 @@ static bool is_space(char ch) | ||
| 20 | { | 19 | { |
| 21 | return (strchr(" \f\n\r\t\v", ch) != 0); | 20 | return (strchr(" \f\n\r\t\v", ch) != 0); |
| 22 | } | 21 | } |
| 22 | +static bool is_digit(char ch) | ||
| 23 | +{ | ||
| 24 | + return ((ch >= '0') && (ch <= '9')); | ||
| 25 | +} | ||
| 26 | +static bool | ||
| 27 | +is_number(std::string const& str) | ||
| 28 | +{ | ||
| 29 | + // ^[\+\-]?(\.\d+|\d+(\.\d+)?)$ | ||
| 30 | + char const* p = str.c_str(); | ||
| 31 | + if (! *p) | ||
| 32 | + { | ||
| 33 | + return false; | ||
| 34 | + } | ||
| 35 | + if ((*p == '-') || (*p == '+')) | ||
| 36 | + { | ||
| 37 | + ++p; | ||
| 38 | + } | ||
| 39 | + bool found_dot = false; | ||
| 40 | + bool found_digit = false; | ||
| 41 | + for (; *p; ++p) | ||
| 42 | + { | ||
| 43 | + if (*p == '.') | ||
| 44 | + { | ||
| 45 | + if (found_dot) | ||
| 46 | + { | ||
| 47 | + // only one dot | ||
| 48 | + return false; | ||
| 49 | + } | ||
| 50 | + if (! *(p+1)) | ||
| 51 | + { | ||
| 52 | + // dot can't be last | ||
| 53 | + return false; | ||
| 54 | + } | ||
| 55 | + found_dot = true; | ||
| 56 | + } | ||
| 57 | + else if (is_digit(*p)) | ||
| 58 | + { | ||
| 59 | + found_digit = true; | ||
| 60 | + } | ||
| 61 | + else | ||
| 62 | + { | ||
| 63 | + return false; | ||
| 64 | + } | ||
| 65 | + } | ||
| 66 | + return found_digit; | ||
| 67 | +} | ||
| 23 | 68 | ||
| 24 | QPDFTokenizer::QPDFTokenizer() : | 69 | QPDFTokenizer::QPDFTokenizer() : |
| 25 | pound_special_in_name(true), | 70 | pound_special_in_name(true), |
| @@ -59,8 +104,6 @@ QPDFTokenizer::reset() | @@ -59,8 +104,6 @@ QPDFTokenizer::reset() | ||
| 59 | void | 104 | void |
| 60 | QPDFTokenizer::resolveLiteral() | 105 | QPDFTokenizer::resolveLiteral() |
| 61 | { | 106 | { |
| 62 | - PCRE num_re("^[\\+\\-]?(?:\\.\\d+|\\d+(?:\\.\\d+)?)$"); | ||
| 63 | - | ||
| 64 | if ((val.length() > 0) && (val.at(0) == '/')) | 107 | if ((val.length() > 0) && (val.at(0) == '/')) |
| 65 | { | 108 | { |
| 66 | type = tt_name; | 109 | type = tt_name; |
| @@ -110,7 +153,7 @@ QPDFTokenizer::resolveLiteral() | @@ -110,7 +153,7 @@ QPDFTokenizer::resolveLiteral() | ||
| 110 | } | 153 | } |
| 111 | val = nval; | 154 | val = nval; |
| 112 | } | 155 | } |
| 113 | - else if (num_re.match(val.c_str())) | 156 | + else if (is_number(val)) |
| 114 | { | 157 | { |
| 115 | if (val.find('.') != std::string::npos) | 158 | if (val.find('.') != std::string::npos) |
| 116 | { | 159 | { |