From fffdeebfd0ed9806d32eb5609e0fdd015c25c5ac Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Mon, 28 May 2018 17:51:28 +0000 Subject: 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 Commit-Queue: Ryan Harrison --- core/fpdfapi/parser/cpdf_dictionary.cpp | 37 +++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'core/fpdfapi/parser/cpdf_dictionary.cpp') 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_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; } -- cgit v1.2.3