summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-10-09 23:15:56 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-10-09 23:15:56 +0000
commit46ab5abf23910983663b3daeb6dc2f6a98ee24a8 (patch)
tree0f9a78a0e8357bfd00c8f3183824ddcbf10612d2
parentbf2d7b7588c744183d0ee845b173e52f0fbda220 (diff)
downloadpdfium-46ab5abf23910983663b3daeb6dc2f6a98ee24a8.tar.xz
Remove some string comparisons in CPDF_Action.
We have a string to enum tokenizer. Use it. Re-order .cpp to match .h in one place. Change-Id: I6835826d5c7be599265ff05f2369da4f2bcc789c Reviewed-on: https://pdfium-review.googlesource.com/c/43791 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
-rw-r--r--core/fpdfdoc/cpdf_action.cpp70
1 files changed, 33 insertions, 37 deletions
diff --git a/core/fpdfdoc/cpdf_action.cpp b/core/fpdfdoc/cpdf_action.cpp
index 6238b05299..6e9e9f7b68 100644
--- a/core/fpdfdoc/cpdf_action.cpp
+++ b/core/fpdfdoc/cpdf_action.cpp
@@ -27,14 +27,26 @@ CPDF_Action::CPDF_Action(const CPDF_Dictionary* pDict) : m_pDict(pDict) {}
CPDF_Action::CPDF_Action(const CPDF_Action& that) = default;
-CPDF_Action::~CPDF_Action() {}
+CPDF_Action::~CPDF_Action() = default;
-CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const {
+CPDF_Action::ActionType CPDF_Action::GetType() const {
if (!m_pDict)
- return CPDF_Dest();
+ return Unknown;
+
+ ByteString csType = m_pDict->GetStringFor("S");
+ if (csType.IsEmpty())
+ return Unknown;
- ByteString type = m_pDict->GetStringFor("S");
- if (type != "GoTo" && type != "GoToR")
+ for (int i = 0; g_sATypes[i]; ++i) {
+ if (csType == g_sATypes[i])
+ return static_cast<ActionType>(i);
+ }
+ return Unknown;
+}
+
+CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const {
+ ActionType type = GetType();
+ if (type != GoTo && type != GoToR)
return CPDF_Dest();
const CPDF_Object* pDest = m_pDict->GetDirectObjectFor("D");
@@ -50,25 +62,10 @@ CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const {
return CPDF_Dest();
}
-CPDF_Action::ActionType CPDF_Action::GetType() const {
- if (!m_pDict)
- return Unknown;
-
- ByteString csType = m_pDict->GetStringFor("S");
- if (csType.IsEmpty())
- return Unknown;
-
- for (int i = 0; g_sATypes[i]; ++i) {
- if (csType == g_sATypes[i])
- return static_cast<ActionType>(i);
- }
- return Unknown;
-}
-
WideString CPDF_Action::GetFilePath() const {
- ByteString type = m_pDict->GetStringFor("S");
- if (type != "GoToR" && type != "Launch" && type != "SubmitForm" &&
- type != "ImportData") {
+ ActionType type = GetType();
+ if (type != GoToR && type != Launch && type != SubmitForm &&
+ type != ImportData) {
return WideString();
}
@@ -76,24 +73,23 @@ WideString CPDF_Action::GetFilePath() const {
if (pFile)
return CPDF_FileSpec(pFile).GetFileName();
- if (type == "Launch") {
- const CPDF_Dictionary* pWinDict = m_pDict->GetDictFor("Win");
- if (pWinDict) {
- return WideString::FromLocal(
- pWinDict->GetStringFor(pdfium::stream::kF).AsStringView());
- }
- }
- return WideString();
+ if (type != Launch)
+ return WideString();
+
+ const CPDF_Dictionary* pWinDict = m_pDict->GetDictFor("Win");
+ if (!pWinDict)
+ return WideString();
+
+ return WideString::FromLocal(
+ pWinDict->GetStringFor(pdfium::stream::kF).AsStringView());
}
ByteString CPDF_Action::GetURI(const CPDF_Document* pDoc) const {
- ByteString csURI;
- if (!m_pDict)
- return csURI;
- if (m_pDict->GetStringFor("S") != "URI")
- return csURI;
+ ActionType type = GetType();
+ if (type != URI)
+ return ByteString();
- csURI = m_pDict->GetStringFor("URI");
+ ByteString csURI = m_pDict->GetStringFor("URI");
const CPDF_Dictionary* pRoot = pDoc->GetRoot();
const CPDF_Dictionary* pURI = pRoot->GetDictFor("URI");
if (pURI) {