#include "core/fpdfdoc/cpdf_nametree.h"
#include <set>
#include <utility>
#include <vector>
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_dictionary.h"
#include "core/fpdfapi/parser/cpdf_document.h"
#include "core/fpdfapi/parser/cpdf_reference.h"
#include "core/fpdfapi/parser/cpdf_string.h"
#include "core/fpdfapi/parser/fpdf_parser_decode.h"
#include "core/fxcrt/check.h"
#include "core/fxcrt/ptr_util.h"
#include "core/fxcrt/stl_util.h"
namespace {
constexpr int kNameTreeMaxRecursion = …;
std::pair<WideString, WideString> GetNodeLimitsAndSanitize(
CPDF_Array* pLimits) { … }
bool GetNodeAncestorsLimitsInternal(const RetainPtr<CPDF_Dictionary>& pNode,
const CPDF_Array* pFind,
int nLevel,
std::vector<CPDF_Array*>* pLimits) { … }
std::vector<CPDF_Array*> GetNodeAncestorsLimits(
const RetainPtr<CPDF_Dictionary>& pNode,
const CPDF_Array* pFind) { … }
bool UpdateNodesAndLimitsUponDeletion(CPDF_Dictionary* pNode,
const CPDF_Array* pFind,
const WideString& csName,
int nLevel) { … }
bool IsTraversedObject(const CPDF_Object* obj,
std::set<uint32_t>* seen_obj_nums) { … }
bool IsArrayWithTraversedObject(const CPDF_Array* array,
std::set<uint32_t>* seen_obj_nums) { … }
RetainPtr<const CPDF_Object> SearchNameNodeByNameInternal(
const RetainPtr<CPDF_Dictionary>& pNode,
const WideString& csName,
int nLevel,
size_t* nIndex,
RetainPtr<CPDF_Array>* ppFind,
int* pFindIndex,
std::set<uint32_t>* seen_obj_nums) { … }
RetainPtr<const CPDF_Object> SearchNameNodeByName(
const RetainPtr<CPDF_Dictionary>& pNode,
const WideString& csName,
RetainPtr<CPDF_Array>* ppFind,
int* pFindIndex) { … }
struct IndexSearchResult { … };
std::optional<IndexSearchResult> SearchNameNodeByIndexInternal(
CPDF_Dictionary* pNode,
size_t nTargetPairIndex,
int nLevel,
size_t* nCurPairIndex) { … }
std::optional<IndexSearchResult> SearchNameNodeByIndex(
CPDF_Dictionary* pNode,
size_t nTargetPairIndex) { … }
size_t CountNamesInternal(const CPDF_Dictionary* pNode,
int nLevel,
std::set<const CPDF_Dictionary*>& seen) { … }
RetainPtr<const CPDF_Array> GetNamedDestFromObject(
RetainPtr<const CPDF_Object> obj) { … }
RetainPtr<const CPDF_Array> LookupOldStyleNamedDest(CPDF_Document* pDoc,
const ByteString& name) { … }
}
CPDF_NameTree::CPDF_NameTree(RetainPtr<CPDF_Dictionary> pRoot)
: … { … }
CPDF_NameTree::~CPDF_NameTree() = default;
std::unique_ptr<CPDF_NameTree> CPDF_NameTree::Create(
CPDF_Document* pDoc,
const ByteString& category) { … }
std::unique_ptr<CPDF_NameTree> CPDF_NameTree::CreateWithRootNameArray(
CPDF_Document* pDoc,
const ByteString& category) { … }
std::unique_ptr<CPDF_NameTree> CPDF_NameTree::CreateForTesting(
CPDF_Dictionary* pRoot) { … }
RetainPtr<const CPDF_Array> CPDF_NameTree::LookupNamedDest(
CPDF_Document* pDoc,
const ByteString& name) { … }
size_t CPDF_NameTree::GetCount() const { … }
bool CPDF_NameTree::AddValueAndName(RetainPtr<CPDF_Object> pObj,
const WideString& name) { … }
bool CPDF_NameTree::DeleteValueAndName(size_t nIndex) { … }
RetainPtr<CPDF_Object> CPDF_NameTree::LookupValueAndName(
size_t nIndex,
WideString* csName) const { … }
RetainPtr<const CPDF_Object> CPDF_NameTree::LookupValue(
const WideString& csName) const { … }
RetainPtr<const CPDF_Array> CPDF_NameTree::LookupNewStyleNamedDest(
const ByteString& sName) { … }