Commit 45a6100cbb014f5d4b89b7af1d03e8a846c474d9

Authored by m-holger
1 parent c08bb0ec

Inline QUtil functions used by QPDFTokenizer

include/qpdf/QUtil.hh
@@ -25,6 +25,7 @@ @@ -25,6 +25,7 @@
25 #include <qpdf/DLL.h> 25 #include <qpdf/DLL.h>
26 #include <qpdf/PointerHolder.hh> 26 #include <qpdf/PointerHolder.hh>
27 #include <qpdf/Types.h> 27 #include <qpdf/Types.h>
  28 +#include <cstring>
28 #include <functional> 29 #include <functional>
29 #include <list> 30 #include <list>
30 #include <memory> 31 #include <memory>
@@ -489,16 +490,16 @@ namespace QUtil @@ -489,16 +490,16 @@ namespace QUtil
489 // classes without using ctype, which we avoid because of locale 490 // classes without using ctype, which we avoid because of locale
490 // considerations. 491 // considerations.
491 QPDF_DLL 492 QPDF_DLL
492 - bool is_hex_digit(char); 493 + inline bool is_hex_digit(char);
493 494
494 QPDF_DLL 495 QPDF_DLL
495 - bool is_space(char); 496 + inline bool is_space(char);
496 497
497 QPDF_DLL 498 QPDF_DLL
498 - bool is_digit(char); 499 + inline bool is_digit(char);
499 500
500 QPDF_DLL 501 QPDF_DLL
501 - bool is_number(char const*); 502 + inline bool is_number(char const*);
502 503
503 // This method parses the numeric range syntax used by the qpdf 504 // This method parses the numeric range syntax used by the qpdf
504 // command-line tool. May throw std::runtime_error. 505 // command-line tool. May throw std::runtime_error.
@@ -526,4 +527,50 @@ namespace QUtil @@ -526,4 +527,50 @@ namespace QUtil
526 #endif // QPDF_NO_WCHAR_T 527 #endif // QPDF_NO_WCHAR_T
527 }; // namespace QUtil 528 }; // namespace QUtil
528 529
  530 +inline bool
  531 +QUtil::is_hex_digit(char ch)
  532 +{
  533 + return (ch && (strchr("0123456789abcdefABCDEF", ch) != nullptr));
  534 +}
  535 +
  536 +inline bool
  537 +QUtil::is_space(char ch)
  538 +{
  539 + return (ch && (strchr(" \f\n\r\t\v", ch) != nullptr));
  540 +}
  541 +
  542 +inline bool
  543 +QUtil::is_digit(char ch)
  544 +{
  545 + return ((ch >= '0') && (ch <= '9'));
  546 +}
  547 +
  548 +inline bool
  549 +QUtil::is_number(char const* p)
  550 +{
  551 + // ^[\+\-]?(\.\d*|\d+(\.\d*)?)$
  552 + if (!*p) {
  553 + return false;
  554 + }
  555 + if ((*p == '-') || (*p == '+')) {
  556 + ++p;
  557 + }
  558 + bool found_dot = false;
  559 + bool found_digit = false;
  560 + for (; *p; ++p) {
  561 + if (*p == '.') {
  562 + if (found_dot) {
  563 + // only one dot
  564 + return false;
  565 + }
  566 + found_dot = true;
  567 + } else if (QUtil::is_digit(*p)) {
  568 + found_digit = true;
  569 + } else {
  570 + return false;
  571 + }
  572 + }
  573 + return found_digit;
  574 +}
  575 +
529 #endif // QUTIL_HH 576 #endif // QUTIL_HH
libqpdf/QUtil.cc
@@ -1207,52 +1207,6 @@ QUtil::random() @@ -1207,52 +1207,6 @@ QUtil::random()
1207 return result; 1207 return result;
1208 } 1208 }
1209 1209
1210 -bool  
1211 -QUtil::is_hex_digit(char ch)  
1212 -{  
1213 - return (ch && (strchr("0123456789abcdefABCDEF", ch) != nullptr));  
1214 -}  
1215 -  
1216 -bool  
1217 -QUtil::is_space(char ch)  
1218 -{  
1219 - return (ch && (strchr(" \f\n\r\t\v", ch) != nullptr));  
1220 -}  
1221 -  
1222 -bool  
1223 -QUtil::is_digit(char ch)  
1224 -{  
1225 - return ((ch >= '0') && (ch <= '9'));  
1226 -}  
1227 -  
1228 -bool  
1229 -QUtil::is_number(char const* p)  
1230 -{  
1231 - // ^[\+\-]?(\.\d*|\d+(\.\d*)?)$  
1232 - if (!*p) {  
1233 - return false;  
1234 - }  
1235 - if ((*p == '-') || (*p == '+')) {  
1236 - ++p;  
1237 - }  
1238 - bool found_dot = false;  
1239 - bool found_digit = false;  
1240 - for (; *p; ++p) {  
1241 - if (*p == '.') {  
1242 - if (found_dot) {  
1243 - // only one dot  
1244 - return false;  
1245 - }  
1246 - found_dot = true;  
1247 - } else if (QUtil::is_digit(*p)) {  
1248 - found_digit = true;  
1249 - } else {  
1250 - return false;  
1251 - }  
1252 - }  
1253 - return found_digit;  
1254 -}  
1255 -  
1256 void 1210 void
1257 QUtil::read_file_into_memory( 1211 QUtil::read_file_into_memory(
1258 char const* filename, std::shared_ptr<char>& file_buf, size_t& size) 1212 char const* filename, std::shared_ptr<char>& file_buf, size_t& size)