summaryrefslogtreecommitdiff
path: root/core/fpdfdoc
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-05-13 17:51:27 -0700
committerCommit bot <commit-bot@chromium.org>2016-05-13 17:51:27 -0700
commit71a452f8ce12e31cc4e0d8c7878567b0c7fc63c2 (patch)
treea0ee545eb67b14f9398df98196d88e5150893ce8 /core/fpdfdoc
parentafe94306e3c542f0d499e7f7706ee5dec4028d8a (diff)
downloadpdfium-71a452f8ce12e31cc4e0d8c7878567b0c7fc63c2.tar.xz
Make CFX_ByteString(const CFX_ByteStringC&) explicit.
Add missing helper function to CFX_ByteTextBuf to avoid the anti-pattern CFX_ByteString(sBuf.AsStringC()), using the name "Make" to indicate there's an allocation going on in this case. Change some method arguments to take pre-existing ByteStrings where possible. Review-Url: https://codereview.chromium.org/1977093002
Diffstat (limited to 'core/fpdfdoc')
-rw-r--r--core/fpdfdoc/cpvt_generateap.cpp16
-rw-r--r--core/fpdfdoc/doc_action.cpp3
-rw-r--r--core/fpdfdoc/doc_basic.cpp25
-rw-r--r--core/fpdfdoc/doc_bookmark.cpp3
-rw-r--r--core/fpdfdoc/doc_formfield.cpp2
-rw-r--r--core/fpdfdoc/doc_link.cpp3
-rw-r--r--core/fpdfdoc/doc_ocg.cpp36
-rw-r--r--core/fpdfdoc/doc_tagged.cpp8
-rw-r--r--core/fpdfdoc/include/fpdf_doc.h2
9 files changed, 45 insertions, 53 deletions
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index 2fc0644bcc..adaee6363e 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -38,7 +38,7 @@ FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc,
CPDF_SimpleParser syntax(DA.AsStringC());
syntax.FindTagParamFromStart("Tf", 2);
- CFX_ByteString sFontName = syntax.GetWord();
+ CFX_ByteString sFontName(syntax.GetWord());
sFontName = PDF_NameDecode(sFontName);
if (sFontName.IsEmpty())
return FALSE;
@@ -519,7 +519,7 @@ CFX_ByteString CPVT_GenerateAP::GenerateEditAP(
if (bContinuous) {
if (place.LineCmp(oldplace) != 0) {
if (sWords.GetSize() > 0) {
- sLineStream << GetWordRenderString(sWords.AsStringC());
+ sLineStream << GetWordRenderString(sWords.MakeString());
sEditStream << sLineStream;
sLineStream.Clear();
sWords.Clear();
@@ -544,7 +544,7 @@ CFX_ByteString CPVT_GenerateAP::GenerateEditAP(
if (pIterator->GetWord(word)) {
if (word.nFontIndex != nCurFontIndex) {
if (sWords.GetSize() > 0) {
- sLineStream << GetWordRenderString(sWords.AsStringC());
+ sLineStream << GetWordRenderString(sWords.MakeString());
sWords.Clear();
}
sLineStream << GetFontSetString(pFontMap, word.nFontIndex,
@@ -575,11 +575,11 @@ CFX_ByteString CPVT_GenerateAP::GenerateEditAP(
}
}
if (sWords.GetSize() > 0) {
- sLineStream << GetWordRenderString(sWords.AsStringC());
+ sLineStream << GetWordRenderString(sWords.MakeString());
sEditStream << sLineStream;
sWords.Clear();
}
- return sEditStream.AsStringC();
+ return sEditStream.MakeString();
}
// Static.
@@ -687,7 +687,7 @@ CFX_ByteString CPVT_GenerateAP::GenerateBorderAP(
break;
}
}
- return sAppStream.AsStringC();
+ return sAppStream.MakeString();
}
// Static.
@@ -712,7 +712,7 @@ CFX_ByteString CPVT_GenerateAP::GenerateColorAP(const CPVT_Color& color,
case CPVT_Color::kTransparent:
break;
}
- return sColorStream.AsStringC();
+ return sColorStream.MakeString();
}
// Static.
@@ -760,5 +760,5 @@ CFX_ByteString CPVT_GenerateAP::GetFontSetString(IPVT_FontMap* pFontMap,
if (sFontAlias.GetLength() > 0 && fFontSize > 0)
sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n";
}
- return sRet.AsStringC();
+ return sRet.MakeString();
}
diff --git a/core/fpdfdoc/doc_action.cpp b/core/fpdfdoc/doc_action.cpp
index c478bbe1f4..6f3e2945fa 100644
--- a/core/fpdfdoc/doc_action.cpp
+++ b/core/fpdfdoc/doc_action.cpp
@@ -38,8 +38,7 @@ CPDF_Dest CPDF_Action::GetDest(CPDF_Document* pDoc) const {
}
if (pDest->IsString() || pDest->IsName()) {
CPDF_NameTree name_tree(pDoc, "Dests");
- return CPDF_Dest(
- name_tree.LookupNamedDest(pDoc, pDest->GetString().AsStringC()));
+ return CPDF_Dest(name_tree.LookupNamedDest(pDoc, pDest->GetString()));
}
if (CPDF_Array* pArray = pDest->AsArray())
return CPDF_Dest(pArray);
diff --git a/core/fpdfdoc/doc_basic.cpp b/core/fpdfdoc/doc_basic.cpp
index 76639efac6..ab99cff772 100644
--- a/core/fpdfdoc/doc_basic.cpp
+++ b/core/fpdfdoc/doc_basic.cpp
@@ -500,30 +500,25 @@ CFX_WideString CPDF_PageLabel::GetLabel(int nPage) const {
wsLabel.Format(L"%d", nPage + 1);
return wsLabel;
}
+
int32_t CPDF_PageLabel::GetPageByLabel(const CFX_ByteStringC& bsLabel) const {
- if (!m_pDocument) {
+ if (!m_pDocument)
return -1;
- }
+
CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot();
- if (!pPDFRoot) {
+ if (!pPDFRoot)
return -1;
- }
+
int nPages = m_pDocument->GetPageCount();
- CFX_ByteString bsLbl;
- CFX_ByteString bsOrig = bsLabel;
for (int i = 0; i < nPages; i++) {
- bsLbl = PDF_EncodeText(GetLabel(i));
- if (!bsLbl.Compare(bsOrig.AsStringC())) {
+ if (PDF_EncodeText(GetLabel(i)).Compare(bsLabel))
return i;
- }
- }
- bsLbl = bsOrig;
- int nPage = FXSYS_atoi(bsLbl.c_str());
- if (nPage > 0 && nPage <= nPages) {
- return nPage;
}
- return -1;
+
+ int nPage = FXSYS_atoi(CFX_ByteString(bsLabel).c_str()); // NUL terminate.
+ return nPage > 0 && nPage <= nPages ? nPage : -1;
}
+
int32_t CPDF_PageLabel::GetPageByLabel(const CFX_WideStringC& wsLabel) const {
return GetPageByLabel(PDF_EncodeText(wsLabel.c_str()).AsStringC());
}
diff --git a/core/fpdfdoc/doc_bookmark.cpp b/core/fpdfdoc/doc_bookmark.cpp
index aee9fb7b14..05ebc07a90 100644
--- a/core/fpdfdoc/doc_bookmark.cpp
+++ b/core/fpdfdoc/doc_bookmark.cpp
@@ -80,8 +80,7 @@ CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const {
return CPDF_Dest();
if (pDest->IsString() || pDest->IsName()) {
CPDF_NameTree name_tree(pDocument, "Dests");
- return CPDF_Dest(
- name_tree.LookupNamedDest(pDocument, pDest->GetString().AsStringC()));
+ return CPDF_Dest(name_tree.LookupNamedDest(pDocument, pDest->GetString()));
}
if (CPDF_Array* pArray = pDest->AsArray())
return CPDF_Dest(pArray);
diff --git a/core/fpdfdoc/doc_formfield.cpp b/core/fpdfdoc/doc_formfield.cpp
index d9333eef90..84d9a52dac 100644
--- a/core/fpdfdoc/doc_formfield.cpp
+++ b/core/fpdfdoc/doc_formfield.cpp
@@ -1062,7 +1062,7 @@ void CPDF_FormField::LoadDA() {
}
CPDF_SimpleParser syntax(DA.AsStringC());
syntax.FindTagParamFromStart("Tf", 2);
- CFX_ByteString font_name = syntax.GetWord();
+ CFX_ByteString font_name(syntax.GetWord());
CPDF_Dictionary* pFontDict = NULL;
if (m_pForm->m_pFormDict && m_pForm->m_pFormDict->GetDictBy("DR") &&
m_pForm->m_pFormDict->GetDictBy("DR")->GetDictBy("Font")) {
diff --git a/core/fpdfdoc/doc_link.cpp b/core/fpdfdoc/doc_link.cpp
index 995290b9fb..5d21e1d9aa 100644
--- a/core/fpdfdoc/doc_link.cpp
+++ b/core/fpdfdoc/doc_link.cpp
@@ -81,8 +81,7 @@ CPDF_Dest CPDF_Link::GetDest(CPDF_Document* pDoc) {
if (pDest->IsString() || pDest->IsName()) {
CPDF_NameTree name_tree(pDoc, "Dests");
- return CPDF_Dest(
- name_tree.LookupNamedDest(pDoc, pDest->GetString().AsStringC()));
+ return CPDF_Dest(name_tree.LookupNamedDest(pDoc, pDest->GetString()));
}
if (CPDF_Array* pArray = pDest->AsArray())
return CPDF_Dest(pArray);
diff --git a/core/fpdfdoc/doc_ocg.cpp b/core/fpdfdoc/doc_ocg.cpp
index 2249574b7f..51e018aea5 100644
--- a/core/fpdfdoc/doc_ocg.cpp
+++ b/core/fpdfdoc/doc_ocg.cpp
@@ -43,21 +43,21 @@ static FX_BOOL FPDFDOC_OCG_HasIntent(const CPDF_Dictionary* pDict,
bsIntent = pIntent->GetString();
return bsIntent == "All" || bsIntent == csElement;
}
+
static CPDF_Dictionary* FPDFDOC_OCG_GetConfig(CPDF_Document* pDoc,
- const CPDF_Dictionary* pOCGDict,
- const CFX_ByteStringC& bsState) {
- ASSERT(pDoc && pOCGDict);
+ const CPDF_Dictionary* pOCGDict) {
+ ASSERT(pOCGDict);
CPDF_Dictionary* pOCProperties = pDoc->GetRoot()->GetDictBy("OCProperties");
- if (!pOCProperties) {
- return NULL;
- }
+ if (!pOCProperties)
+ return nullptr;
+
CPDF_Array* pOCGs = pOCProperties->GetArrayBy("OCGs");
- if (!pOCGs) {
- return NULL;
- }
- if (FPDFDOC_OCG_FindGroup(pOCGs, pOCGDict) < 0) {
- return NULL;
- }
+ if (!pOCGs)
+ return nullptr;
+
+ if (FPDFDOC_OCG_FindGroup(pOCGs, pOCGDict) < 0)
+ return nullptr;
+
CPDF_Dictionary* pConfig = pOCProperties->GetDictBy("D");
CPDF_Array* pConfigs = pOCProperties->GetArrayBy("Configs");
if (pConfigs) {
@@ -96,14 +96,14 @@ CPDF_OCContext::CPDF_OCContext(CPDF_Document* pDoc, UsageType eUsageType) {
CPDF_OCContext::~CPDF_OCContext() {
m_OCGStates.clear();
}
-FX_BOOL CPDF_OCContext::LoadOCGStateFromConfig(const CFX_ByteStringC& csConfig,
+
+FX_BOOL CPDF_OCContext::LoadOCGStateFromConfig(const CFX_ByteString& csConfig,
const CPDF_Dictionary* pOCGDict,
FX_BOOL& bValidConfig) const {
- CPDF_Dictionary* pConfig =
- FPDFDOC_OCG_GetConfig(m_pDocument, pOCGDict, csConfig);
- if (!pConfig) {
+ CPDF_Dictionary* pConfig = FPDFDOC_OCG_GetConfig(m_pDocument, pOCGDict);
+ if (!pConfig)
return TRUE;
- }
+
bValidConfig = TRUE;
FX_BOOL bState = pConfig->GetStringBy("BaseState", "ON") != "OFF";
CPDF_Array* pArray = pConfig->GetArrayBy("ON");
@@ -167,7 +167,7 @@ FX_BOOL CPDF_OCContext::LoadOCGState(const CPDF_Dictionary* pOCGDict) const {
}
}
FX_BOOL bDefValid = FALSE;
- return LoadOCGStateFromConfig(csState.AsStringC(), pOCGDict, bDefValid);
+ return LoadOCGStateFromConfig(csState, pOCGDict, bDefValid);
}
FX_BOOL CPDF_OCContext::GetOCGVisible(const CPDF_Dictionary* pOCGDict) {
diff --git a/core/fpdfdoc/doc_tagged.cpp b/core/fpdfdoc/doc_tagged.cpp
index f559c0ac2b..2eca698614 100644
--- a/core/fpdfdoc/doc_tagged.cpp
+++ b/core/fpdfdoc/doc_tagged.cpp
@@ -356,7 +356,7 @@ CPDF_Object* CPDF_StructElementImpl::GetAttr(const CFX_ByteStringC& owner,
if (pA) {
CPDF_Dictionary* pAttrDict = FindAttrDict(pA, owner);
if (pAttrDict) {
- CPDF_Object* pAttr = pAttrDict->GetDirectObjectBy(name);
+ CPDF_Object* pAttr = pAttrDict->GetDirectObjectBy(CFX_ByteString(name));
if (pAttr) {
return pAttr;
}
@@ -375,14 +375,14 @@ CPDF_Object* CPDF_StructElementImpl::GetAttr(const CFX_ByteStringC& owner,
CFX_ByteString class_name = pArray->GetStringAt(i);
CPDF_Dictionary* pClassDict = pClassMap->GetDictBy(class_name);
if (pClassDict && pClassDict->GetStringBy("O") == owner)
- return pClassDict->GetDirectObjectBy(name);
+ return pClassDict->GetDirectObjectBy(CFX_ByteString(name));
}
return nullptr;
}
CFX_ByteString class_name = pC->GetString();
CPDF_Dictionary* pClassDict = pClassMap->GetDictBy(class_name);
if (pClassDict && pClassDict->GetStringBy("O") == owner)
- return pClassDict->GetDirectObjectBy(name);
+ return pClassDict->GetDirectObjectBy(CFX_ByteString(name));
return nullptr;
}
CPDF_Object* CPDF_StructElementImpl::GetAttr(const CFX_ByteStringC& owner,
@@ -407,7 +407,7 @@ CFX_ByteString CPDF_StructElementImpl::GetName(
CPDF_Object* pAttr = GetAttr(owner, name, bInheritable, subindex);
if (ToName(pAttr))
return pAttr->GetString();
- return default_value;
+ return CFX_ByteString(default_value);
}
FX_ARGB CPDF_StructElementImpl::GetColor(const CFX_ByteStringC& owner,
diff --git a/core/fpdfdoc/include/fpdf_doc.h b/core/fpdfdoc/include/fpdf_doc.h
index 306b131b88..d69887bd78 100644
--- a/core/fpdfdoc/include/fpdf_doc.h
+++ b/core/fpdfdoc/include/fpdf_doc.h
@@ -134,7 +134,7 @@ class CPDF_OCContext {
void ResetOCContext();
protected:
- FX_BOOL LoadOCGStateFromConfig(const CFX_ByteStringC& csConfig,
+ FX_BOOL LoadOCGStateFromConfig(const CFX_ByteString& csConfig,
const CPDF_Dictionary* pOCGDict,
FX_BOOL& bValidConfig) const;
FX_BOOL LoadOCGState(const CPDF_Dictionary* pOCGDict) const;