From 45a6100cbb014f5d4b89b7af1d03e8a846c474d9 Mon Sep 17 00:00:00 2001 From: m-holger Date: Thu, 18 Aug 2022 15:23:35 +0100 Subject: Inline QUtil functions used by QPDFTokenizer --- include/qpdf/QUtil.hh | 55 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/qpdf/QUtil.hh b/include/qpdf/QUtil.hh index 32aeae1f..41b89da4 100644 --- a/include/qpdf/QUtil.hh +++ b/include/qpdf/QUtil.hh @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -489,16 +490,16 @@ namespace QUtil // classes without using ctype, which we avoid because of locale // considerations. QPDF_DLL - bool is_hex_digit(char); + inline bool is_hex_digit(char); QPDF_DLL - bool is_space(char); + inline bool is_space(char); QPDF_DLL - bool is_digit(char); + inline bool is_digit(char); QPDF_DLL - bool is_number(char const*); + inline bool is_number(char const*); // This method parses the numeric range syntax used by the qpdf // command-line tool. May throw std::runtime_error. @@ -526,4 +527,50 @@ namespace QUtil #endif // QPDF_NO_WCHAR_T }; // namespace QUtil +inline bool +QUtil::is_hex_digit(char ch) +{ + return (ch && (strchr("0123456789abcdefABCDEF", ch) != nullptr)); +} + +inline bool +QUtil::is_space(char ch) +{ + return (ch && (strchr(" \f\n\r\t\v", ch) != nullptr)); +} + +inline bool +QUtil::is_digit(char ch) +{ + return ((ch >= '0') && (ch <= '9')); +} + +inline 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; + } + found_dot = true; + } else if (QUtil::is_digit(*p)) { + found_digit = true; + } else { + return false; + } + } + return found_digit; +} + #endif // QUTIL_HH -- cgit v1.2.3-54-g00ecf