summaryrefslogtreecommitdiff
path: root/core/fpdfapi/fpdf_parser
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/fpdf_parser
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/fpdf_parser')
-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
6 files changed, 27 insertions, 29 deletions
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_