summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Sander <oliver.sander@tu-dresden.de>2020-01-27 17:33:49 +0100
committerAlbert Astals Cid <tsdgeos@yahoo.es>2020-02-23 16:47:00 +0000
commit5804f51c7cf439432082b668ba8df3b0a6048caf (patch)
treeffc7956262ffa0f8f079d70cb112b208437629b8
parent06a658708d73b4e2d0bcb9f5572be9b2754368eb (diff)
Use a std::string value in LinkURI
-rw-r--r--glib/poppler-action.cc4
-rw-r--r--poppler/Link.cc40
-rw-r--r--poppler/Link.h10
-rw-r--r--qt5/src/poppler-page.cc2
-rw-r--r--qt5/src/poppler-private.cc2
-rw-r--r--utils/HtmlOutputDev.cc2
6 files changed, 23 insertions, 37 deletions
diff --git a/glib/poppler-action.cc b/glib/poppler-action.cc
index e6be5b9b..583efb53 100644
--- a/glib/poppler-action.cc
+++ b/glib/poppler-action.cc
@@ -405,9 +405,7 @@ static void
build_uri (PopplerAction *action,
const LinkURI *link)
{
- const gchar *uri;
-
- uri = link->getURI()->c_str ();
+ const gchar *uri = link->getURI().c_str ();
if (uri != nullptr)
action->uri.uri = g_strdup (uri);
}
diff --git a/poppler/Link.cc b/poppler/Link.cc
index cfce4d36..318c6b96 100644
--- a/poppler/Link.cc
+++ b/poppler/Link.cc
@@ -560,38 +560,33 @@ LinkLaunch::~LinkLaunch() {
//------------------------------------------------------------------------
LinkURI::LinkURI(const Object *uriObj, const GooString *baseURI) {
- const GooString *uri2;
- int n;
- char c;
-
- uri = nullptr;
+ hasURIFlag = false;
if (uriObj->isString()) {
- uri2 = uriObj->getString();
- n = (int)strcspn(uri2->c_str(), "/:");
- if (n < uri2->getLength() && uri2->getChar(n) == ':') {
+ const std::string& uri2 = uriObj->getString()->toStr();
+ size_t n = strcspn(uri2.c_str(), "/:");
+ if (n < uri2.size() && uri2[n] == ':') {
// "http:..." etc.
- uri = uri2->copy();
- } else if (!uri2->cmpN("www.", 4)) {
+ uri = uri2;
+ } else if (!uri2.compare(0,4,"www.")) {
// "www.[...]" without the leading "http://"
- uri = new GooString("http://");
- uri->append(uri2);
+ uri = "http://" + uri2;
} else {
// relative URI
if (baseURI) {
- uri = baseURI->copy();
- if (uri->getLength() > 0) {
- c = uri->getChar(uri->getLength() - 1);
+ uri = baseURI->toStr();
+ if (uri.size() > 0) {
+ char c = uri.back();
if (c != '/' && c != '?') {
- uri->append('/');
+ uri += '/';
}
}
- if (uri2->getChar(0) == '/') {
- uri->append(uri2->c_str() + 1, uri2->getLength() - 1);
+ if (uri2[0] == '/') {
+ uri.append(uri2.c_str() + 1, uri2.size() - 1);
} else {
- uri->append(uri2);
+ uri += uri2;
}
} else {
- uri = uri2->copy();
+ uri = uri2;
}
}
} else {
@@ -599,11 +594,6 @@ LinkURI::LinkURI(const Object *uriObj, const GooString *baseURI) {
}
}
-LinkURI::~LinkURI() {
- if (uri)
- delete uri;
-}
-
//------------------------------------------------------------------------
// LinkNamed
//------------------------------------------------------------------------
diff --git a/poppler/Link.h b/poppler/Link.h
index aaaf09c1..1871890f 100644
--- a/poppler/Link.h
+++ b/poppler/Link.h
@@ -253,19 +253,17 @@ public:
// Build a LinkURI given the URI (string) and base URI.
LinkURI(const Object *uriObj, const GooString *baseURI);
- // Destructor.
- ~LinkURI() override;
-
// Was the LinkURI created successfully?
- bool isOk() const override { return uri != nullptr; }
+ bool isOk() const override { return hasURIFlag; }
// Accessors.
LinkActionKind getKind() const override { return actionURI; }
- const GooString *getURI() const { return uri; }
+ const std::string& getURI() const { return uri; }
private:
- GooString *uri; // the URI
+ std::string uri; // the URI
+ bool hasURIFlag;
};
//------------------------------------------------------------------------
diff --git a/qt5/src/poppler-page.cc b/qt5/src/poppler-page.cc
index 25731146..e36f6fd3 100644
--- a/qt5/src/poppler-page.cc
+++ b/qt5/src/poppler-page.cc
@@ -275,7 +275,7 @@ Link* PageData::convertLinkActionToLink(::LinkAction * a, DocumentData *parentDo
case actionURI:
{
- popplerLink = new LinkBrowse( linkArea, ((LinkURI *)a)->getURI()->c_str() );
+ popplerLink = new LinkBrowse( linkArea, ((LinkURI *)a)->getURI().c_str() );
}
break;
diff --git a/qt5/src/poppler-private.cc b/qt5/src/poppler-private.cc
index cb5bf8f1..e630f565 100644
--- a/qt5/src/poppler-private.cc
+++ b/qt5/src/poppler-private.cc
@@ -228,7 +228,7 @@ namespace Debug {
case actionURI:
{
const LinkURI * u = static_cast< const LinkURI * >( a );
- e->setAttribute( QStringLiteral("DestinationURI"), u->getURI()->c_str() );
+ e->setAttribute( QStringLiteral("DestinationURI"), u->getURI().c_str() );
}
default: ;
}
diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc
index 75fb5bbb..0212626b 100644
--- a/utils/HtmlOutputDev.cc
+++ b/utils/HtmlOutputDev.cc
@@ -1628,7 +1628,7 @@ GooString* HtmlOutputDev::getLinkDest(AnnotLink *link){
case actionURI:
{
LinkURI *ha=(LinkURI *) link->getAction();
- GooString* file=new GooString(ha->getURI()->c_str());
+ GooString* file=new GooString(ha->getURI());
// printf("uri : %s\n",file->c_str());
return file;
}