From ed2fb6a8a31c8801d03e6a397bd15d814eaf73a8 Mon Sep 17 00:00:00 2001 From: m-holger Date: Fri, 31 Oct 2025 16:52:34 +0000 Subject: [PATCH] Refactor `QPDF::validatePDFVersion`: relocate from `QPDF` to `Objects`, update usages, and clean up `QPDF.hh`. --- include/qpdf/QPDF.hh | 2 -- libqpdf/QPDF.cc | 19 ------------------- libqpdf/QPDF_json.cc | 2 +- libqpdf/QPDF_objects.cc | 19 +++++++++++++++++++ libqpdf/qpdf/QPDF_private.hh | 2 ++ 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index b9ae8f4..14cdbde 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -791,8 +791,6 @@ class QPDF bool is_root_metadata, std::unique_ptr& heap); - static bool validatePDFVersion(char const*&, std::string& version); - // JSON import void importJSON(std::shared_ptr, bool must_be_complete); diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index f60e714..5c7338b 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -315,25 +315,6 @@ QPDF::numWarnings() const return m->warnings.size(); } -bool -QPDF::validatePDFVersion(char const*& p, std::string& version) -{ - if (!util::is_digit(*p)) { - return false; - } - while (util::is_digit(*p)) { - version.append(1, *p++); - } - if (!(*p == '.' && util::is_digit(*(p + 1)))) { - return false; - } - version.append(1, *p++); - while (util::is_digit(*p)) { - version.append(1, *p++); - } - return true; -} - void QPDF::warn(QPDFExc const& e) { diff --git a/libqpdf/QPDF_json.cc b/libqpdf/QPDF_json.cc index 663599a..ba3b137 100644 --- a/libqpdf/QPDF_json.cc +++ b/libqpdf/QPDF_json.cc @@ -482,7 +482,7 @@ QPDF::JSONReactor::dictionaryItem(std::string const& key, JSON const& value) if (value.getString(v)) { std::string version; char const* p = v.c_str(); - if (QPDF::validatePDFVersion(p, version) && (*p == '\0')) { + if (objects.validatePDFVersion(p, version) && *p == '\0') { pdf.m->pdf_version = version; return true; } diff --git a/libqpdf/QPDF_objects.cc b/libqpdf/QPDF_objects.cc index 2240862..fbe4f19 100644 --- a/libqpdf/QPDF_objects.cc +++ b/libqpdf/QPDF_objects.cc @@ -123,6 +123,25 @@ class Objects::PatternFinder final: public InputSource::Finder }; bool +Objects::validatePDFVersion(char const*& p, std::string& version) +{ + if (!util::is_digit(*p)) { + return false; + } + while (util::is_digit(*p)) { + version.append(1, *p++); + } + if (!(*p == '.' && util::is_digit(*(p + 1)))) { + return false; + } + version.append(1, *p++); + while (util::is_digit(*p)) { + version.append(1, *p++); + } + return true; +} + +bool Objects::findHeader() { qpdf_offset_t global_offset = m->file->tell(); diff --git a/libqpdf/qpdf/QPDF_private.hh b/libqpdf/qpdf/QPDF_private.hh index 52414ea..a5738eb 100644 --- a/libqpdf/qpdf/QPDF_private.hh +++ b/libqpdf/qpdf/QPDF_private.hh @@ -1000,6 +1000,8 @@ class QPDF::Doc::Objects: Common std::shared_ptr getObjectForJSON(int id, int gen); size_t table_size(); + static bool validatePDFVersion(char const*&, std::string& version); + // For QPDFWriter: std::map const& xref_table(); -- libgit2 0.21.4