[poppler] poppler/Catalog.cc poppler/Catalog.h poppler/Link.cc poppler/Link.h

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Mar 30 14:02:15 UTC 2022


 poppler/Catalog.cc |    6 +-----
 poppler/Catalog.h  |    7 ++++---
 poppler/Link.cc    |    8 ++++----
 poppler/Link.h     |    7 ++++---
 4 files changed, 13 insertions(+), 15 deletions(-)

New commits:
commit dbbaa1651dc168f71054e3dd9ef91e33c960bfb7
Author: Albert Astals Cid <aacid at kde.org>
Date:   Wed Mar 30 15:55:53 2022 +0200

    Move Catalog baseURI to optional string

diff --git a/poppler/Catalog.cc b/poppler/Catalog.cc
index 7c2eff84..986577a7 100644
--- a/poppler/Catalog.cc
+++ b/poppler/Catalog.cc
@@ -79,7 +79,6 @@ Catalog::Catalog(PDFDoc *docA)
     doc = docA;
     xref = doc->getXRef();
     numPages = -1;
-    baseURI = nullptr;
     pageLabelInfo = nullptr;
     form = nullptr;
     optContent = nullptr;
@@ -111,7 +110,7 @@ Catalog::Catalog(PDFDoc *docA)
     if (obj.isDict()) {
         Object obj2 = obj.getDict()->lookupEnsureEncryptedIfNeeded("Base");
         if (obj2.isString()) {
-            baseURI = obj2.getString()->copy();
+            baseURI = obj2.getString()->toStr();
         }
     }
 
@@ -156,9 +155,6 @@ Catalog::~Catalog()
     delete destNameTree;
     delete embeddedFileNameTree;
     delete jsNameTree;
-    if (baseURI) {
-        delete baseURI;
-    }
     delete pageLabelInfo;
     delete form;
     delete optContent;
diff --git a/poppler/Catalog.h b/poppler/Catalog.h
index ffeb481c..70ca99ca 100644
--- a/poppler/Catalog.h
+++ b/poppler/Catalog.h
@@ -46,8 +46,9 @@
 #include "Object.h"
 #include "Link.h"
 
-#include <vector>
 #include <memory>
+#include <optional>
+#include <vector>
 
 class PDFDoc;
 class XRef;
@@ -132,7 +133,7 @@ public:
     Ref *getPageRef(int i);
 
     // Return base URI, or NULL if none.
-    GooString *getBaseURI() { return baseURI; }
+    const std::optional<std::string> &getBaseURI() const { return baseURI; }
 
     // Return the contents of the metadata stream, or NULL if there is
     // no metadata.
@@ -285,7 +286,7 @@ private:
     NameTree *destNameTree; // named destination name-tree
     NameTree *embeddedFileNameTree; // embedded file name-tree
     NameTree *jsNameTree; // Java Script name-tree
-    GooString *baseURI; // base URI for URI-type links
+    std::optional<std::string> baseURI; // base URI for URI-type links
     Object metadata; // metadata stream
     StructTreeRoot *structTreeRoot; // structure tree root
     unsigned int markInfo; // Flags from MarkInfo dictionary
diff --git a/poppler/Link.cc b/poppler/Link.cc
index 52c59581..dd17cf33 100644
--- a/poppler/Link.cc
+++ b/poppler/Link.cc
@@ -63,13 +63,13 @@ std::unique_ptr<LinkAction> LinkAction::parseDest(const Object *obj)
     return action;
 }
 
-std::unique_ptr<LinkAction> LinkAction::parseAction(const Object *obj, const GooString *baseURI)
+std::unique_ptr<LinkAction> LinkAction::parseAction(const Object *obj, const std::optional<std::string> &baseURI)
 {
     std::set<int> seenNextActions;
     return parseAction(obj, baseURI, &seenNextActions);
 }
 
-std::unique_ptr<LinkAction> LinkAction::parseAction(const Object *obj, const GooString *baseURI, std::set<int> *seenNextActions)
+std::unique_ptr<LinkAction> LinkAction::parseAction(const Object *obj, const std::optional<std::string> &baseURI, std::set<int> *seenNextActions)
 {
 
     if (!obj->isDict()) {
@@ -513,7 +513,7 @@ LinkLaunch::~LinkLaunch() = default;
 // LinkURI
 //------------------------------------------------------------------------
 
-LinkURI::LinkURI(const Object *uriObj, const GooString *baseURI)
+LinkURI::LinkURI(const Object *uriObj, const std::optional<std::string> &baseURI)
 {
     hasURIFlag = false;
     if (uriObj->isString()) {
@@ -529,7 +529,7 @@ LinkURI::LinkURI(const Object *uriObj, const GooString *baseURI)
         } else {
             // relative URI
             if (baseURI) {
-                uri = baseURI->toStr();
+                uri = *baseURI;
                 if (uri.size() > 0) {
                     char c = uri.back();
                     if (c != '/' && c != '?') {
diff --git a/poppler/Link.h b/poppler/Link.h
index 3cd78e33..0c4677ca 100644
--- a/poppler/Link.h
+++ b/poppler/Link.h
@@ -35,6 +35,7 @@
 #include "Object.h"
 #include "poppler_private_export.h"
 #include <memory>
+#include <optional>
 #include <set>
 
 class GooString;
@@ -86,13 +87,13 @@ public:
     static std::unique_ptr<LinkAction> parseDest(const Object *obj);
 
     // Parse an action dictionary.
-    static std::unique_ptr<LinkAction> parseAction(const Object *obj, const GooString *baseURI = nullptr);
+    static std::unique_ptr<LinkAction> parseAction(const Object *obj, const std::optional<std::string> &baseURI = {});
 
     // A List of the next actions to execute in order.
     const std::vector<std::unique_ptr<LinkAction>> &nextActions() const;
 
 private:
-    static std::unique_ptr<LinkAction> parseAction(const Object *obj, const GooString *baseURI, std::set<int> *seenNextActions);
+    static std::unique_ptr<LinkAction> parseAction(const Object *obj, const std::optional<std::string> &baseURI, std::set<int> *seenNextActions);
 
     std::vector<std::unique_ptr<LinkAction>> nextActionList;
 };
@@ -242,7 +243,7 @@ class POPPLER_PRIVATE_EXPORT LinkURI : public LinkAction
 {
 public:
     // Build a LinkURI given the URI (string) and base URI.
-    LinkURI(const Object *uriObj, const GooString *baseURI);
+    LinkURI(const Object *uriObj, const std::optional<std::string> &baseURI);
 
     ~LinkURI() override;
 


More information about the poppler mailing list