Commit ed2fb6a8a31c8801d03e6a397bd15d814eaf73a8

Authored by m-holger
1 parent 85b96841

Refactor `QPDF::validatePDFVersion`: relocate from `QPDF` to `Objects`, update u…

…sages, and clean up `QPDF.hh`.
include/qpdf/QPDF.hh
... ... @@ -791,8 +791,6 @@ class QPDF
791 791 bool is_root_metadata,
792 792 std::unique_ptr<Pipeline>& heap);
793 793  
794   - static bool validatePDFVersion(char const*&, std::string& version);
795   -
796 794 // JSON import
797 795 void importJSON(std::shared_ptr<InputSource>, bool must_be_complete);
798 796  
... ...
libqpdf/QPDF.cc
... ... @@ -315,25 +315,6 @@ QPDF::numWarnings() const
315 315 return m->warnings.size();
316 316 }
317 317  
318   -bool
319   -QPDF::validatePDFVersion(char const*& p, std::string& version)
320   -{
321   - if (!util::is_digit(*p)) {
322   - return false;
323   - }
324   - while (util::is_digit(*p)) {
325   - version.append(1, *p++);
326   - }
327   - if (!(*p == '.' && util::is_digit(*(p + 1)))) {
328   - return false;
329   - }
330   - version.append(1, *p++);
331   - while (util::is_digit(*p)) {
332   - version.append(1, *p++);
333   - }
334   - return true;
335   -}
336   -
337 318 void
338 319 QPDF::warn(QPDFExc const& e)
339 320 {
... ...
libqpdf/QPDF_json.cc
... ... @@ -482,7 +482,7 @@ QPDF::JSONReactor::dictionaryItem(std::string const&amp; key, JSON const&amp; value)
482 482 if (value.getString(v)) {
483 483 std::string version;
484 484 char const* p = v.c_str();
485   - if (QPDF::validatePDFVersion(p, version) && (*p == '\0')) {
  485 + if (objects.validatePDFVersion(p, version) && *p == '\0') {
486 486 pdf.m->pdf_version = version;
487 487 return true;
488 488 }
... ...
libqpdf/QPDF_objects.cc
... ... @@ -123,6 +123,25 @@ class Objects::PatternFinder final: public InputSource::Finder
123 123 };
124 124  
125 125 bool
  126 +Objects::validatePDFVersion(char const*& p, std::string& version)
  127 +{
  128 + if (!util::is_digit(*p)) {
  129 + return false;
  130 + }
  131 + while (util::is_digit(*p)) {
  132 + version.append(1, *p++);
  133 + }
  134 + if (!(*p == '.' && util::is_digit(*(p + 1)))) {
  135 + return false;
  136 + }
  137 + version.append(1, *p++);
  138 + while (util::is_digit(*p)) {
  139 + version.append(1, *p++);
  140 + }
  141 + return true;
  142 +}
  143 +
  144 +bool
126 145 Objects::findHeader()
127 146 {
128 147 qpdf_offset_t global_offset = m->file->tell();
... ...
libqpdf/qpdf/QPDF_private.hh
... ... @@ -1000,6 +1000,8 @@ class QPDF::Doc::Objects: Common
1000 1000 std::shared_ptr<QPDFObject> getObjectForJSON(int id, int gen);
1001 1001 size_t table_size();
1002 1002  
  1003 + static bool validatePDFVersion(char const*&, std::string& version);
  1004 +
1003 1005 // For QPDFWriter:
1004 1006  
1005 1007 std::map<QPDFObjGen, QPDFXRefEntry> const& xref_table();
... ...