diff options
author | Lei Zhang <thestig@chromium.org> | 2018-05-28 17:51:28 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-05-28 17:51:28 +0000 |
commit | fffdeebfd0ed9806d32eb5609e0fdd015c25c5ac (patch) | |
tree | 7461043e508179a7d33b850486f312c58048e4a8 /core/fpdfapi/parser/cpdf_dictionary.cpp | |
parent | 45a55241d315d25067582d29fcdc1ff8b818965f (diff) | |
download | pdfium-fffdeebfd0ed9806d32eb5609e0fdd015c25c5ac.tar.xz |
Add const/non-const versions of remaining CPDF_Dictionary methods.
GetObjectFor() and GetDirectObjectFor().
Change-Id: I588cd994dfccf0ffd4c8f91362a4806dc109251e
Reviewed-on: https://pdfium-review.googlesource.com/32991
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'core/fpdfapi/parser/cpdf_dictionary.cpp')
-rw-r--r-- | core/fpdfapi/parser/cpdf_dictionary.cpp | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/core/fpdfapi/parser/cpdf_dictionary.cpp b/core/fpdfapi/parser/cpdf_dictionary.cpp index 5257a20586..ae7239efdf 100644 --- a/core/fpdfapi/parser/cpdf_dictionary.cpp +++ b/core/fpdfapi/parser/cpdf_dictionary.cpp @@ -81,63 +81,74 @@ std::unique_ptr<CPDF_Object> CPDF_Dictionary::CloneNonCyclic( return std::move(pCopy); } -CPDF_Object* CPDF_Dictionary::GetObjectFor(const ByteString& key) const { +const CPDF_Object* CPDF_Dictionary::GetObjectFor(const ByteString& key) const { auto it = m_Map.find(key); return it != m_Map.end() ? it->second.get() : nullptr; } -CPDF_Object* CPDF_Dictionary::GetDirectObjectFor(const ByteString& key) const { +CPDF_Object* CPDF_Dictionary::GetObjectFor(const ByteString& key) { + auto it = m_Map.find(key); + return it != m_Map.end() ? it->second.get() : nullptr; +} + +const CPDF_Object* CPDF_Dictionary::GetDirectObjectFor( + const ByteString& key) const { + const CPDF_Object* p = GetObjectFor(key); + return p ? p->GetDirect() : nullptr; +} + +CPDF_Object* CPDF_Dictionary::GetDirectObjectFor(const ByteString& key) { CPDF_Object* p = GetObjectFor(key); return p ? p->GetDirect() : nullptr; } ByteString CPDF_Dictionary::GetStringFor(const ByteString& key) const { - CPDF_Object* p = GetObjectFor(key); + const CPDF_Object* p = GetObjectFor(key); return p ? p->GetString() : ByteString(); } WideString CPDF_Dictionary::GetUnicodeTextFor(const ByteString& key) const { - CPDF_Object* p = GetObjectFor(key); - if (CPDF_Reference* pRef = ToReference(p)) + const CPDF_Object* p = GetObjectFor(key); + if (const CPDF_Reference* pRef = ToReference(p)) p = pRef->GetDirect(); return p ? p->GetUnicodeText() : WideString(); } ByteString CPDF_Dictionary::GetStringFor(const ByteString& key, const ByteString& def) const { - CPDF_Object* p = GetObjectFor(key); + const CPDF_Object* p = GetObjectFor(key); return p ? p->GetString() : ByteString(def); } int CPDF_Dictionary::GetIntegerFor(const ByteString& key) const { - CPDF_Object* p = GetObjectFor(key); + const CPDF_Object* p = GetObjectFor(key); return p ? p->GetInteger() : 0; } int CPDF_Dictionary::GetIntegerFor(const ByteString& key, int def) const { - CPDF_Object* p = GetObjectFor(key); + const CPDF_Object* p = GetObjectFor(key); return p ? p->GetInteger() : def; } float CPDF_Dictionary::GetNumberFor(const ByteString& key) const { - CPDF_Object* p = GetObjectFor(key); + const CPDF_Object* p = GetObjectFor(key); return p ? p->GetNumber() : 0; } bool CPDF_Dictionary::GetBooleanFor(const ByteString& key, bool bDefault) const { - CPDF_Object* p = GetObjectFor(key); + const CPDF_Object* p = GetObjectFor(key); return ToBoolean(p) ? p->GetInteger() != 0 : bDefault; } const CPDF_Dictionary* CPDF_Dictionary::GetDictFor( const ByteString& key) const { - CPDF_Object* p = GetDirectObjectFor(key); + const CPDF_Object* p = GetDirectObjectFor(key); if (!p) return nullptr; - if (CPDF_Dictionary* pDict = p->AsDictionary()) + if (const CPDF_Dictionary* pDict = p->AsDictionary()) return pDict; - if (CPDF_Stream* pStream = p->AsStream()) + if (const CPDF_Stream* pStream = p->AsStream()) return pStream->GetDict(); return nullptr; } |