2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-06-05 11:50:53 +00:00

Inline QUtil functions used by QPDFTokenizer

This commit is contained in:
m-holger 2022-08-18 15:23:35 +01:00
parent c08bb0ec02
commit 45a6100cbb
2 changed files with 51 additions and 50 deletions

View File

@ -25,6 +25,7 @@
#include <qpdf/DLL.h>
#include <qpdf/PointerHolder.hh>
#include <qpdf/Types.h>
#include <cstring>
#include <functional>
#include <list>
#include <memory>
@ -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

View File

@ -1207,52 +1207,6 @@ QUtil::random()
return result;
}
bool
QUtil::is_hex_digit(char ch)
{
return (ch && (strchr("0123456789abcdefABCDEF", ch) != nullptr));
}
bool
QUtil::is_space(char ch)
{
return (ch && (strchr(" \f\n\r\t\v", ch) != nullptr));
}
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;
}
found_dot = true;
} else if (QUtil::is_digit(*p)) {
found_digit = true;
} else {
return false;
}
}
return found_digit;
}
void
QUtil::read_file_into_memory(
char const* filename, std::shared_ptr<char>& file_buf, size_t& size)