summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Sander <oliver.sander@tu-dresden.de>2020-01-25 10:20:03 +0100
committerAlbert Astals Cid <tsdgeos@yahoo.es>2020-02-23 16:46:59 +0000
commit70ba56662286257a84d0d979c8f47eb3d3a5356b (patch)
treea58397b64b17f03c5bb676faf7e61678c27b62c6
parente9278387cbff75ce75a87a92bc297b53256bd3fc (diff)
Use a std::string value in LinkJavaScript
-rw-r--r--glib/poppler-action.cc9
-rw-r--r--poppler/Link.cc15
-rw-r--r--poppler/Link.h9
-rw-r--r--poppler/Stream.h11
-rw-r--r--qt5/src/poppler-page.cc2
-rw-r--r--utils/JSInfo.cc7
6 files changed, 29 insertions, 24 deletions
diff --git a/glib/poppler-action.cc b/glib/poppler-action.cc
index 193536c2..3851a390 100644
--- a/glib/poppler-action.cc
+++ b/glib/poppler-action.cc
@@ -523,11 +523,10 @@ static void
build_javascript (PopplerAction *action,
const LinkJavaScript *link)
{
- const GooString *script;
-
- script = link->getScript();
- if (script)
- action->javascript.script = _poppler_goo_string_to_utf8 (script);
+ if (link->isOk()) {
+ const GooString script(link->getScript());
+ action->javascript.script = _poppler_goo_string_to_utf8 (&script);
+ }
}
diff --git a/poppler/Link.cc b/poppler/Link.cc
index f9d4edf9..af8d44dd 100644
--- a/poppler/Link.cc
+++ b/poppler/Link.cc
@@ -794,21 +794,16 @@ LinkRendition::~LinkRendition() {
//------------------------------------------------------------------------
LinkJavaScript::LinkJavaScript(Object *jsObj) {
- js = nullptr;
+ isValid = false;
if (jsObj->isString()) {
- js = new GooString(jsObj->getString());
+ js = jsObj->getString()->toStr();
+ isValid = true;
}
else if (jsObj->isStream()) {
Stream *stream = jsObj->getStream();
- js = new GooString();
- stream->fillGooString(js);
- }
-}
-
-LinkJavaScript::~LinkJavaScript() {
- if (js) {
- delete js;
+ stream->fillString(js);
+ isValid = true;
}
}
diff --git a/poppler/Link.h b/poppler/Link.h
index 48a7a91e..184e43e7 100644
--- a/poppler/Link.h
+++ b/poppler/Link.h
@@ -418,18 +418,17 @@ public:
// Build a LinkJavaScript given the action name.
LinkJavaScript(Object *jsObj);
- ~LinkJavaScript() override;
-
- bool isOk() const override { return js != nullptr; }
+ bool isOk() const override { return isValid; }
LinkActionKind getKind() const override { return actionJavaScript; }
- const GooString *getScript() const { return js; }
+ const std::string& getScript() const { return js; }
static Object createObject(XRef *xref, const GooString &js);
private:
- GooString *js;
+ std::string js;
+ bool isValid;
};
//------------------------------------------------------------------------
diff --git a/poppler/Stream.h b/poppler/Stream.h
index 758433b3..e19790e5 100644
--- a/poppler/Stream.h
+++ b/poppler/Stream.h
@@ -28,6 +28,7 @@
// Copyright (C) 2013 Pino Toscano <pino@kde.org>
// Copyright (C) 2019 Volker Krause <vkrause@kde.org>
// Copyright (C) 2019 Alexander Volkov <a.volkov@rusbitech.ru>
+// Copyright (C) 2020 Oliver Sander <oliver.sander@tu-dresden.de>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
@@ -129,6 +130,16 @@ public:
}
}
+ inline void fillString(std::string& s)
+ {
+ unsigned char readBuf[4096];
+ int readChars;
+ reset();
+ while ((readChars = doGetChars(4096, readBuf)) != 0) {
+ s.append((const char *)readBuf, readChars);
+ }
+ }
+
inline void fillGooString(GooString *s)
{
unsigned char readBuf[4096];
diff --git a/qt5/src/poppler-page.cc b/qt5/src/poppler-page.cc
index 9e08134a..39753b7e 100644
--- a/qt5/src/poppler-page.cc
+++ b/qt5/src/poppler-page.cc
@@ -289,7 +289,7 @@ Link* PageData::convertLinkActionToLink(::LinkAction * a, DocumentData *parentDo
case actionJavaScript:
{
::LinkJavaScript *ljs = (::LinkJavaScript *)a;
- popplerLink = new LinkJavaScript( linkArea, UnicodeParsedString(ljs->getScript()) );
+ popplerLink = new LinkJavaScript( linkArea, UnicodeParsedString( ljs->getScript() ) );
}
break;
diff --git a/utils/JSInfo.cc b/utils/JSInfo.cc
index 1ebd8a4c..ba082904 100644
--- a/utils/JSInfo.cc
+++ b/utils/JSInfo.cc
@@ -59,10 +59,11 @@ void JSInfo::scanLinkAction(LinkAction *link, const char *action, bool deleteLin
hasJS = true;
if (print) {
LinkJavaScript *linkjs = static_cast<LinkJavaScript *>(link);
- const GooString *s = linkjs->getScript();
- if (s && s->c_str()) {
+ if (linkjs->isOk()) {
+ const std::string& s = linkjs->getScript();
fprintf(file, "%s:\n", action);
- printJS(s);
+ GooString gooS = GooString(s);
+ printJS(&gooS);
fputs("\n\n", file);
}
}