summaryrefslogtreecommitdiff
path: root/core/fpdfapi
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/fpdfapi
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/fpdfapi')
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_doc.cpp7
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_parser.cpp8
-rw-r--r--core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp6
-rw-r--r--core/fpdfapi/fpdf_page/pageint.h4
-rw-r--r--core/fpdfapi/fpdf_parser/cpdf_document.cpp2
-rw-r--r--core/fpdfapi/fpdf_parser/cpdf_security_handler.cpp36
-rw-r--r--core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp8
-rw-r--r--core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp4
-rw-r--r--core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp4
-rw-r--r--core/fpdfapi/fpdf_parser/fpdf_parser_utility.h2
-rw-r--r--core/fpdfapi/fpdf_render/fpdf_render_text.cpp2
11 files changed, 41 insertions, 42 deletions
diff --git a/core/fpdfapi/fpdf_page/fpdf_page_doc.cpp b/core/fpdfapi/fpdf_page/fpdf_page_doc.cpp
index 8287ea562d..f872906674 100644
--- a/core/fpdfapi/fpdf_page/fpdf_page_doc.cpp
+++ b/core/fpdfapi/fpdf_page/fpdf_page_doc.cpp
@@ -159,7 +159,7 @@ CPDF_Font* CPDF_DocPageData::GetFont(CPDF_Dictionary* pFontDict,
return fontData->AddRef();
}
-CPDF_Font* CPDF_DocPageData::GetStandardFont(const CFX_ByteStringC& fontName,
+CPDF_Font* CPDF_DocPageData::GetStandardFont(const CFX_ByteString& fontName,
CPDF_FontEncoding* pEncoding) {
if (fontName.IsEmpty())
return nullptr;
@@ -425,7 +425,8 @@ CPDF_IccProfile* CPDF_DocPageData::GetIccProfile(
stream.LoadAllData(pIccProfileStream, FALSE);
uint8_t digest[20];
CRYPT_SHA1Generate(stream.GetData(), stream.GetSize(), digest);
- auto hash_it = m_HashProfileMap.find(CFX_ByteStringC(digest, 20));
+ CFX_ByteString bsDigest(digest, 20);
+ auto hash_it = m_HashProfileMap.find(bsDigest);
if (hash_it != m_HashProfileMap.end()) {
auto it_copied_stream = m_IccProfileMap.find(hash_it->second);
return it_copied_stream->second->AddRef();
@@ -434,7 +435,7 @@ CPDF_IccProfile* CPDF_DocPageData::GetIccProfile(
new CPDF_IccProfile(stream.GetData(), stream.GetSize());
CPDF_CountedIccProfile* ipData = new CPDF_CountedIccProfile(pProfile);
m_IccProfileMap[pIccProfileStream] = ipData;
- m_HashProfileMap[CFX_ByteStringC(digest, 20)] = pIccProfileStream;
+ m_HashProfileMap[bsDigest] = pIccProfileStream;
return ipData->AddRef();
}
diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp
index da1355724f..8c16d8c41f 100644
--- a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp
+++ b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp
@@ -1143,7 +1143,7 @@ void CPDF_StreamContentParser::Handle_SetFont() {
}
CPDF_Object* CPDF_StreamContentParser::FindResourceObj(
- const CFX_ByteStringC& type,
+ const CFX_ByteString& type,
const CFX_ByteString& name) {
if (!m_pResources) {
return NULL;
@@ -1683,9 +1683,9 @@ void PDF_ReplaceAbbr(CPDF_Object* pObj) {
}
for (const auto& op : replacements) {
if (op.is_replace_key)
- pDict->ReplaceKey(op.key, op.replacement);
+ pDict->ReplaceKey(op.key, CFX_ByteString(op.replacement));
else
- pDict->SetAtName(op.key, op.replacement);
+ pDict->SetAtName(op.key, CFX_ByteString(op.replacement));
}
break;
}
@@ -1699,7 +1699,7 @@ void PDF_ReplaceAbbr(CPDF_Object* pObj) {
PDF_InlineValueAbbr, FX_ArraySize(PDF_InlineValueAbbr),
name.AsStringC());
if (!fullname.IsEmpty()) {
- pArray->SetAt(i, new CPDF_Name(fullname));
+ pArray->SetAt(i, new CPDF_Name(CFX_ByteString(fullname)));
}
} else {
PDF_ReplaceAbbr(pElement);
diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
index 58ecb6c4d6..5bac23e137 100644
--- a/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
+++ b/core/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp
@@ -502,7 +502,7 @@ CFX_ByteString CPDF_StreamParser::ReadString() {
if (buf.GetLength() > kMaxStringLength) {
return CFX_ByteString(buf.GetBuffer(), kMaxStringLength);
}
- return buf.AsStringC();
+ return buf.MakeString();
}
parlevel--;
buf.AppendChar(')');
@@ -581,7 +581,7 @@ CFX_ByteString CPDF_StreamParser::ReadString() {
if (buf.GetLength() > kMaxStringLength) {
return CFX_ByteString(buf.GetBuffer(), kMaxStringLength);
}
- return buf.AsStringC();
+ return buf.MakeString();
}
CFX_ByteString CPDF_StreamParser::ReadHexString() {
@@ -615,7 +615,7 @@ CFX_ByteString CPDF_StreamParser::ReadHexString() {
if (buf.GetLength() > kMaxStringLength)
return CFX_ByteString(buf.GetBuffer(), kMaxStringLength);
- return buf.AsStringC();
+ return buf.MakeString();
}
bool CPDF_StreamParser::PositionIsInBounds() const {
diff --git a/core/fpdfapi/fpdf_page/pageint.h b/core/fpdfapi/fpdf_page/pageint.h
index e904234e9f..6534186dc8 100644
--- a/core/fpdfapi/fpdf_page/pageint.h
+++ b/core/fpdfapi/fpdf_page/pageint.h
@@ -155,7 +155,7 @@ class CPDF_StreamContentParser {
CPDF_Font* FindFont(const CFX_ByteString& name);
CPDF_ColorSpace* FindColorSpace(const CFX_ByteString& name);
CPDF_Pattern* FindPattern(const CFX_ByteString& name, bool bShading);
- CPDF_Object* FindResourceObj(const CFX_ByteStringC& type,
+ CPDF_Object* FindResourceObj(const CFX_ByteString& type,
const CFX_ByteString& name);
protected:
@@ -318,7 +318,7 @@ class CPDF_DocPageData {
void Clear(FX_BOOL bRelease = FALSE);
CPDF_Font* GetFont(CPDF_Dictionary* pFontDict, FX_BOOL findOnly);
- CPDF_Font* GetStandardFont(const CFX_ByteStringC& fontName,
+ CPDF_Font* GetStandardFont(const CFX_ByteString& fontName,
CPDF_FontEncoding* pEncoding);
void ReleaseFont(CPDF_Dictionary* pFontDict);
CPDF_ColorSpace* GetColorSpace(CPDF_Object* pCSObj,
diff --git a/core/fpdfapi/fpdf_parser/cpdf_document.cpp b/core/fpdfapi/fpdf_parser/cpdf_document.cpp
index 39694c1c1a..52899eedb3 100644
--- a/core/fpdfapi/fpdf_parser/cpdf_document.cpp
+++ b/core/fpdfapi/fpdf_parser/cpdf_document.cpp
@@ -839,7 +839,7 @@ CPDF_Font* CPDF_Document::AddStandardFont(const FX_CHAR* font,
CFX_ByteString name(font);
if (PDF_GetStandardFontName(&name) < 0)
return nullptr;
- return GetPageData()->GetStandardFont(name.AsStringC(), pEncoding);
+ return GetPageData()->GetStandardFont(name, pEncoding);
}
CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert) {
diff --git a/core/fpdfapi/fpdf_parser/cpdf_security_handler.cpp b/core/fpdfapi/fpdf_parser/cpdf_security_handler.cpp
index 38099e0328..d6416fb055 100644
--- a/core/fpdfapi/fpdf_parser/cpdf_security_handler.cpp
+++ b/core/fpdfapi/fpdf_parser/cpdf_security_handler.cpp
@@ -112,10 +112,11 @@ FX_BOOL CPDF_SecurityHandler::CheckSecurity(int32_t key_len) {
uint32_t CPDF_SecurityHandler::GetPermissions() {
return m_Permissions;
}
-static FX_BOOL _LoadCryptInfo(CPDF_Dictionary* pEncryptDict,
- const CFX_ByteStringC& name,
- int& cipher,
- int& keylen) {
+
+static FX_BOOL LoadCryptInfo(CPDF_Dictionary* pEncryptDict,
+ const CFX_ByteString& name,
+ int& cipher,
+ int& keylen) {
int Version = pEncryptDict->GetIntegerBy("V");
cipher = FXCIPHER_RC4;
keylen = 0;
@@ -163,19 +164,15 @@ FX_BOOL CPDF_SecurityHandler::LoadDict(CPDF_Dictionary* pEncryptDict) {
m_Version = pEncryptDict->GetIntegerBy("V");
m_Revision = pEncryptDict->GetIntegerBy("R");
m_Permissions = pEncryptDict->GetIntegerBy("P", -1);
- if (m_Version < 4) {
- return _LoadCryptInfo(pEncryptDict, CFX_ByteStringC(), m_Cipher, m_KeyLen);
- }
+ if (m_Version < 4)
+ return LoadCryptInfo(pEncryptDict, CFX_ByteString(), m_Cipher, m_KeyLen);
+
CFX_ByteString stmf_name = pEncryptDict->GetStringBy("StmF");
CFX_ByteString strf_name = pEncryptDict->GetStringBy("StrF");
- if (stmf_name != strf_name) {
+ if (stmf_name != strf_name)
return FALSE;
- }
- if (!_LoadCryptInfo(pEncryptDict, strf_name.AsStringC(), m_Cipher,
- m_KeyLen)) {
- return FALSE;
- }
- return TRUE;
+
+ return LoadCryptInfo(pEncryptDict, strf_name, m_Cipher, m_KeyLen);
}
FX_BOOL CPDF_SecurityHandler::LoadDict(CPDF_Dictionary* pEncryptDict,
@@ -186,17 +183,18 @@ FX_BOOL CPDF_SecurityHandler::LoadDict(CPDF_Dictionary* pEncryptDict,
m_Version = pEncryptDict->GetIntegerBy("V");
m_Revision = pEncryptDict->GetIntegerBy("R");
m_Permissions = pEncryptDict->GetIntegerBy("P", -1);
- CFX_ByteString strf_name, stmf_name;
+
+ CFX_ByteString strf_name;
+ CFX_ByteString stmf_name;
if (m_Version >= 4) {
stmf_name = pEncryptDict->GetStringBy("StmF");
strf_name = pEncryptDict->GetStringBy("StrF");
- if (stmf_name != strf_name) {
+ if (stmf_name != strf_name)
return FALSE;
- }
}
- if (!_LoadCryptInfo(pEncryptDict, strf_name.AsStringC(), cipher, key_len)) {
+ if (!LoadCryptInfo(pEncryptDict, strf_name, cipher, key_len))
return FALSE;
- }
+
m_Cipher = cipher;
m_KeyLen = key_len;
return TRUE;
diff --git a/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp b/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp
index ae066f94c1..13a9972425 100644
--- a/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp
+++ b/core/fpdfapi/fpdf_parser/cpdf_syntax_parser.cpp
@@ -217,7 +217,7 @@ CFX_ByteString CPDF_SyntaxParser::ReadString() {
case 0:
if (ch == ')') {
if (parlevel == 0) {
- return buf.AsStringC();
+ return buf.MakeString();
}
parlevel--;
buf.AppendChar(')');
@@ -290,7 +290,7 @@ CFX_ByteString CPDF_SyntaxParser::ReadString() {
}
GetNextChar(ch);
- return buf.AsStringC();
+ return buf.MakeString();
}
CFX_ByteString CPDF_SyntaxParser::ReadHexString() {
@@ -322,7 +322,7 @@ CFX_ByteString CPDF_SyntaxParser::ReadHexString() {
if (!bFirst)
buf.AppendByte(code);
- return buf.AsStringC();
+ return buf.MakeString();
}
void CPDF_SyntaxParser::ToNextLine() {
@@ -470,7 +470,7 @@ CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjectHolder* pObjList,
if (!pObj)
continue;
- CFX_ByteStringC keyNoSlash(key.raw_str() + 1, key.GetLength() - 1);
+ CFX_ByteString keyNoSlash(key.raw_str() + 1, key.GetLength() - 1);
pDict->SetAt(keyNoSlash, pObj);
}
diff --git a/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
index 3893d9bd41..e9f5a6d468 100644
--- a/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
+++ b/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
@@ -528,7 +528,7 @@ CFX_ByteString PDF_EncodeString(const CFX_ByteString& src, FX_BOOL bHex) {
result.AppendChar("0123456789ABCDEF"[src[i] % 16]);
}
result.AppendChar('>');
- return result.AsStringC();
+ return result.MakeString();
}
result.AppendChar('(');
for (int i = 0; i < srclen; i++) {
@@ -545,7 +545,7 @@ CFX_ByteString PDF_EncodeString(const CFX_ByteString& src, FX_BOOL bHex) {
result.AppendChar(ch);
}
result.AppendChar(')');
- return result.AsStringC();
+ return result.MakeString();
}
void FlateEncode(const uint8_t* src_buf,
diff --git a/core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp b/core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
index 1e9252fa82..a738356e43 100644
--- a/core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
+++ b/core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
@@ -81,14 +81,14 @@ int32_t GetHeaderOffset(IFX_FileRead* pFile) {
return -1;
}
-int32_t GetDirectInteger(CPDF_Dictionary* pDict, const CFX_ByteStringC& key) {
+int32_t GetDirectInteger(CPDF_Dictionary* pDict, const CFX_ByteString& key) {
CPDF_Number* pObj = ToNumber(pDict->GetObjectBy(key));
return pObj ? pObj->GetInteger() : 0;
}
CFX_ByteString PDF_NameDecode(const CFX_ByteStringC& bstr) {
if (bstr.Find('#') == -1)
- return bstr;
+ return CFX_ByteString(bstr);
int size = bstr.GetLength();
CFX_ByteString result;
diff --git a/core/fpdfapi/fpdf_parser/fpdf_parser_utility.h b/core/fpdfapi/fpdf_parser/fpdf_parser_utility.h
index d072fbc191..0b27a1fe9a 100644
--- a/core/fpdfapi/fpdf_parser/fpdf_parser_utility.h
+++ b/core/fpdfapi/fpdf_parser/fpdf_parser_utility.h
@@ -34,6 +34,6 @@ inline bool PDFCharIsLineEnding(uint8_t c) {
}
int32_t GetHeaderOffset(IFX_FileRead* pFile);
-int32_t GetDirectInteger(CPDF_Dictionary* pDict, const CFX_ByteStringC& key);
+int32_t GetDirectInteger(CPDF_Dictionary* pDict, const CFX_ByteString& key);
#endif // CORE_FPDFAPI_FPDF_PARSER_FPDF_PARSER_UTILITY_H_
diff --git a/core/fpdfapi/fpdf_render/fpdf_render_text.cpp b/core/fpdfapi/fpdf_render/fpdf_render_text.cpp
index 33ad21351e..225b6726e2 100644
--- a/core/fpdfapi/fpdf_render/fpdf_render_text.cpp
+++ b/core/fpdfapi/fpdf_render/fpdf_render_text.cpp
@@ -57,7 +57,7 @@ CFX_GlyphBitmap* CPDF_Type3Cache::LoadGlyph(uint32_t charcode,
keygen.Generate(
4, FXSYS_round(pMatrix->a * 10000), FXSYS_round(pMatrix->b * 10000),
FXSYS_round(pMatrix->c * 10000), FXSYS_round(pMatrix->d * 10000));
- CFX_ByteStringC FaceGlyphsKey(keygen.m_Key, keygen.m_KeyLen);
+ CFX_ByteString FaceGlyphsKey(keygen.m_Key, keygen.m_KeyLen);
CPDF_Type3Glyphs* pSizeCache;
auto it = m_SizeMap.find(FaceGlyphsKey);
if (it == m_SizeMap.end()) {