diff options
author | Jay Berkenbilt <ejb@ql.org> | 2017-07-23 01:23:52 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2017-07-27 19:59:56 +0200 |
commit | dd8dad74f47b6068281dd605a04bc2d0b6283423 (patch) | |
tree | db7d72b522591b4f47bf44569713dc9752416b63 /libqpdf/QUtil.cc | |
parent | 0a745021e7d6676ded2a344134b68b180fb3be60 (diff) | |
download | qpdf-dd8dad74f47b6068281dd605a04bc2d0b6283423.tar.zst |
Move lexer helper functions to QUtil
Diffstat (limited to 'libqpdf/QUtil.cc')
-rw-r--r-- | libqpdf/QUtil.cc | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc index 37cfda9e..86de07f2 100644 --- a/libqpdf/QUtil.cc +++ b/libqpdf/QUtil.cc @@ -456,3 +456,63 @@ QUtil::srandom(unsigned int seed) srand(seed); #endif } + +bool +QUtil::is_hex_digit(char ch) +{ + return (strchr("0123456789abcdefABCDEF", ch) != 0); +} + +bool +QUtil::is_space(char ch) +{ + return (strchr(" \f\n\r\t\v", ch) != 0); +} + +bool +QUtil::is_digit(char ch) +{ + return ((ch >= '0') && (ch <= '9')); +} + +bool +QUtil::is_number(char const* p) +{ + // ^[\+\-]?(\.\d+|\d+(\.\d+)?)$ + 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 (QUtil::is_digit(*p)) + { + found_digit = true; + } + else + { + return false; + } + } + return found_digit; +} |