Commit 5804f51c authored by Oliver Sander's avatar Oliver Sander Committed by Albert Astals Cid

Use a std::string value in LinkURI

parent 06a65870
......@@ -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);
}
......
......@@ -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
//------------------------------------------------------------------------
......
......@@ -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;
};
//------------------------------------------------------------------------
......
......@@ -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;
......
......@@ -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: ;
}
......
......@@ -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;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment