From 42eebb9bade006ceb602805c474bc9df5ef630b9 Mon Sep 17 00:00:00 2001 From: Oliver Sander Date: Sat, 25 Jan 2020 20:44:56 +0100 Subject: Use a std::string value in LinkRendition --- poppler/Link.cc | 11 ++++------- poppler/Link.h | 4 ++-- utils/JSInfo.cc | 12 +++++------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/poppler/Link.cc b/poppler/Link.cc index 9433fd9f..0aca017a 100644 --- a/poppler/Link.cc +++ b/poppler/Link.cc @@ -714,7 +714,6 @@ LinkSound::LinkSound(const Object *soundObj) { LinkRendition::LinkRendition(const Object *obj) { operation = NoRendition; media = nullptr; - js = nullptr; int operationCode = -1; screenRef = Ref::INVALID(); @@ -723,11 +722,10 @@ LinkRendition::LinkRendition(const Object *obj) { Object tmp = obj->dictLookup("JS"); if (!tmp.isNull()) { if (tmp.isString()) { - js = new GooString(tmp.getString()); + js = tmp.getString()->toStr(); } else if (tmp.isStream()) { Stream *stream = tmp.getStream(); - js = new GooString(); - stream->fillGooString(js); + stream->fillString(js); } else { error(errSyntaxWarning, -1, "Invalid Rendition Action: JS not string or stream"); } @@ -736,7 +734,7 @@ LinkRendition::LinkRendition(const Object *obj) { tmp = obj->dictLookup("OP"); if (tmp.isInt()) { operationCode = tmp.getInt(); - if (!js && (operationCode < 0 || operationCode > 4)) { + if (js.empty() && (operationCode < 0 || operationCode > 4)) { error(errSyntaxWarning, -1, "Invalid Rendition Action: unrecognized operation valued: {0:d}", operationCode); } else { // retrieve rendition object @@ -773,14 +771,13 @@ LinkRendition::LinkRendition(const Object *obj) { operation = PlayRendition; break; } - } else if (!js) { + } else if (js=="") { error(errSyntaxWarning, -1, "Invalid Rendition action: no OP or JS field defined"); } } } LinkRendition::~LinkRendition() { - delete js; delete media; } diff --git a/poppler/Link.h b/poppler/Link.h index 053cbb85..f3b2d787 100644 --- a/poppler/Link.h +++ b/poppler/Link.h @@ -365,7 +365,7 @@ public: const MediaRendition* getMedia() const { return media; } - const GooString *getScript() const { return js; } + const std::string& getScript() const { return js; } private: @@ -375,7 +375,7 @@ private: MediaRendition* media; - GooString *js; + std::string js; }; //------------------------------------------------------------------------ diff --git a/utils/JSInfo.cc b/utils/JSInfo.cc index ba082904..aa9402d5 100644 --- a/utils/JSInfo.cc +++ b/utils/JSInfo.cc @@ -71,15 +71,13 @@ void JSInfo::scanLinkAction(LinkAction *link, const char *action, bool deleteLin if (link->getKind() == actionRendition) { LinkRendition *linkr = static_cast(link); - if (linkr->getScript()) { + if (!linkr->getScript().empty()) { hasJS = true; if (print) { - const GooString *s = linkr->getScript(); - if (s && s->c_str()) { - fprintf(file, "%s (Rendition):\n", action); - printJS(s); - fputs("\n\n", file); - } + fprintf(file, "%s (Rendition):\n", action); + const GooString s(linkr->getScript()); + printJS(&s); + fputs("\n\n", file); } } } -- cgit v1.2.3