From cfd5147d922ee4e29e10f116dfca79325398a6db Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Tue, 8 Feb 2022 11:07:37 -0500 Subject: Add QPDF::getVersionAsPDFVersion --- libqpdf/PDFVersion.cc | 36 ++++++++++++++++++------------------ libqpdf/QPDF.cc | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+), 18 deletions(-) (limited to 'libqpdf') diff --git a/libqpdf/PDFVersion.cc b/libqpdf/PDFVersion.cc index c2f28bf8..18c04716 100644 --- a/libqpdf/PDFVersion.cc +++ b/libqpdf/PDFVersion.cc @@ -7,30 +7,30 @@ PDFVersion::PDFVersion() : { } -PDFVersion::PDFVersion(int major, int minor, int extension) : - major(major), - minor(minor), - extension(extension) +PDFVersion::PDFVersion(int major_version, int minor_version, int extension_level) : + major_version(major_version), + minor_version(minor_version), + extension_level(extension_level) { } bool PDFVersion::operator<(PDFVersion const& rhs) const { - return ((this->major < rhs.major) ? true : - (this->major > rhs.major) ? false : - (this->minor < rhs.minor) ? true : - (this->minor > rhs.minor) ? false : - (this->extension < rhs.minor) ? true : + return ((this->major_version < rhs.major_version) ? true : + (this->major_version > rhs.major_version) ? false : + (this->minor_version < rhs.minor_version) ? true : + (this->minor_version > rhs.minor_version) ? false : + (this->extension_level < rhs.extension_level) ? true : false); } bool PDFVersion::operator==(PDFVersion const& rhs) const { - return ((this->major == rhs.major) && - (this->minor == rhs.minor) && - (this->extension == rhs.extension)); + return ((this->major_version == rhs.major_version) && + (this->minor_version == rhs.minor_version) && + (this->extension_level == rhs.extension_level)); } void @@ -45,25 +45,25 @@ PDFVersion::updateIfGreater(PDFVersion const& other) void PDFVersion::getVersion(std::string& version, int& extension_level) const { - extension_level = this->extension; - version = QUtil::int_to_string(this->major) + "." + - QUtil::int_to_string(this->minor); + extension_level = this->extension_level; + version = QUtil::int_to_string(this->major_version) + "." + + QUtil::int_to_string(this->minor_version); } int PDFVersion::getMajor() const { - return this->major; + return this->major_version; } int PDFVersion::getMinor() const { - return this->minor; + return this->minor_version; } int PDFVersion::getExtensionLevel() const { - return this->extension; + return this->extension_level; } diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 02a003a5..2337f43d 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -2742,6 +2743,24 @@ QPDF::getFilename() const return this->m->file->getName(); } +PDFVersion +QPDF::getVersionAsPDFVersion() +{ + int major = 1; + int minor = 3; + int extension_level = getExtensionLevel(); + + std::regex v("^[[:space:]]*([0-9]+)\\.([0-9]+)"); + std::smatch m; + if (std::regex_search(this->m->pdf_version, m, v)) + { + major = QUtil::string_to_int(m[1].str().c_str()); + minor = QUtil::string_to_int(m[2].str().c_str()); + } + + return PDFVersion(major, minor, extension_level); +} + std::string QPDF::getPDFVersion() const { -- cgit v1.2.3-54-g00ecf