summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2017-07-28 14:07:04 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-07-28 18:21:44 +0000
commite7a99de4f711302d57fe22682a9a8c3cfddb458c (patch)
tree7bb176d42e2a2181f014b41bd621d6b242ed20e7 /core
parent106eecd27f346a0bc7f11f29a058a8fd16a77682 (diff)
downloadpdfium-e7a99de4f711302d57fe22682a9a8c3cfddb458c.tar.xz
Convert calls to Mid() to Left() or Right() if possible
The various string/byte classes support Mid(), Left(), and Right() for extracting substrings. Mid() can handle all possible cases, but Left() and Right() are useful for common cases and more explicit about what is going on. Calls like Mid(offset, length - offset) can be converted to Right(length - offset). Calls like Mid(0, length) can be converted to Left(length). If the substring being extracted does not extend all the way to one of the edges of the string, then Mid() still needs to be used. BUG=pdfium:828 Change-Id: I2ec46ad3d71aac0f7b513e103c69cbe8c854cf62 Reviewed-on: https://pdfium-review.googlesource.com/9510 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/font/cpdf_simplefont.cpp2
-rw-r--r--core/fpdfapi/page/cpdf_streamcontentparser.cpp6
-rw-r--r--core/fpdfdoc/cpvt_generateap.cpp4
-rw-r--r--core/fpdftext/cpdf_linkextract.cpp2
-rw-r--r--core/fpdftext/cpdf_textpage.cpp4
-rw-r--r--core/fpdftext/cpdf_textpagefind.cpp2
-rw-r--r--core/fxcrt/xml/cxml_parser.cpp4
-rw-r--r--core/fxge/cfx_fontmapper.cpp6
8 files changed, 15 insertions, 15 deletions
diff --git a/core/fpdfapi/font/cpdf_simplefont.cpp b/core/fpdfapi/font/cpdf_simplefont.cpp
index 8c8520f0c4..56a4b13cb3 100644
--- a/core/fpdfapi/font/cpdf_simplefont.cpp
+++ b/core/fpdfapi/font/cpdf_simplefont.cpp
@@ -130,7 +130,7 @@ bool CPDF_SimpleFont::LoadCommon() {
}
if (m_pFontFile) {
if (m_BaseFont.GetLength() > 8 && m_BaseFont[7] == '+')
- m_BaseFont = m_BaseFont.Mid(8, m_BaseFont.GetLength() - 8);
+ m_BaseFont = m_BaseFont.Right(m_BaseFont.GetLength() - 8);
} else {
LoadSubstFont();
}
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
index 5f571aa8d6..288f9d57a8 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -620,7 +620,7 @@ void CPDF_StreamContentParser::Handle_BeginImage() {
break;
}
auto word = m_pSyntax->GetWord();
- CFX_ByteString key(word.Mid(1, word.GetLength() - 1));
+ CFX_ByteString key(word.Right(word.GetLength() - 1));
auto pObj = m_pSyntax->ReadNextObject(false, false, 0);
if (!key.IsEmpty()) {
uint32_t dwObjNum = pObj ? pObj->GetObjNum() : 0;
@@ -1186,7 +1186,7 @@ CPDF_ColorSpace* CPDF_StreamContentParser::FindColorSpace(
}
if (name == "DeviceGray" || name == "DeviceCMYK" || name == "DeviceRGB") {
CFX_ByteString defname = "Default";
- defname += name.Mid(7, name.GetLength() - 7);
+ defname += name.Right(name.GetLength() - 7);
CPDF_Object* pDefObj = FindResourceObj("ColorSpace", defname);
if (!pDefObj) {
if (name == "DeviceGray") {
@@ -1525,7 +1525,7 @@ uint32_t CPDF_StreamContentParser::Parse(const uint8_t* pData,
break;
case CPDF_StreamParser::Name: {
auto word = syntax.GetWord();
- AddNameParam(word.Mid(1, word.GetLength() - 1));
+ AddNameParam(word.Right(word.GetLength() - 1));
break;
}
default:
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index 83c1f65587..956f91289b 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -66,7 +66,7 @@ bool GenerateWidgetAP(CPDF_Document* pDoc,
return false;
CPDF_Dictionary* pFontDict =
- pDRFontDict->GetDictFor(sFontName.Mid(1, sFontName.GetLength() - 1));
+ pDRFontDict->GetDictFor(sFontName.Right(sFontName.GetLength() - 1));
if (!pFontDict) {
pFontDict = pDoc->NewIndirect<CPDF_Dictionary>();
pFontDict->SetNewFor<CPDF_Name>("Type", "Font");
@@ -74,7 +74,7 @@ bool GenerateWidgetAP(CPDF_Document* pDoc,
pFontDict->SetNewFor<CPDF_Name>("BaseFont", "Helvetica");
pFontDict->SetNewFor<CPDF_Name>("Encoding", "WinAnsiEncoding");
pDRFontDict->SetNewFor<CPDF_Reference>(
- sFontName.Mid(1, sFontName.GetLength() - 1), pDoc,
+ sFontName.Right(sFontName.GetLength() - 1), pDoc,
pFontDict->GetObjNum());
}
CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict);
diff --git a/core/fpdftext/cpdf_linkextract.cpp b/core/fpdftext/cpdf_linkextract.cpp
index 5179f732c9..e0bd4ae49f 100644
--- a/core/fpdftext/cpdf_linkextract.cpp
+++ b/core/fpdftext/cpdf_linkextract.cpp
@@ -154,7 +154,7 @@ void CPDF_LinkExtract::ParseLink() {
while (strBeCheck.GetLength() > 0) {
wchar_t ch = strBeCheck.GetAt(strBeCheck.GetLength() - 1);
if (ch == L')' || ch == L',' || ch == L'>' || ch == L'.') {
- strBeCheck = strBeCheck.Mid(0, strBeCheck.GetLength() - 1);
+ strBeCheck = strBeCheck.Left(strBeCheck.GetLength() - 1);
nCount--;
} else {
break;
diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp
index 1dc03db4ff..8f0e376dbc 100644
--- a/core/fpdftext/cpdf_textpage.cpp
+++ b/core/fpdftext/cpdf_textpage.cpp
@@ -441,8 +441,8 @@ CFX_WideString CPDF_TextPage::GetPageText(int start, int nCount) const {
if (nCount == -1) {
nCount = pdfium::CollectionSize<int>(m_CharList) - start;
- return CFX_WideString(
- m_TextBuf.AsStringC().Mid(start, m_TextBuf.AsStringC().GetLength()));
+ CFX_WideStringC wsTextBuf = m_TextBuf.AsStringC();
+ return CFX_WideString(wsTextBuf.Right(wsTextBuf.GetLength() - start));
}
if (nCount <= 0 || m_CharList.empty())
return L"";
diff --git a/core/fpdftext/cpdf_textpagefind.cpp b/core/fpdftext/cpdf_textpagefind.cpp
index 058c293ac1..fe610abcd4 100644
--- a/core/fpdftext/cpdf_textpagefind.cpp
+++ b/core/fpdftext/cpdf_textpagefind.cpp
@@ -300,7 +300,7 @@ void CPDF_TextPageFind::ExtractFindWhat(const CFX_WideString& findwhat) {
continue;
}
if (pos > 0)
- m_csFindWhatArray.push_back(csWord.Mid(0, pos));
+ m_csFindWhatArray.push_back(csWord.Left(pos));
m_csFindWhatArray.push_back(curStr);
if (pos == csWord.GetLength() - 1) {
csWord.clear();
diff --git a/core/fxcrt/xml/cxml_parser.cpp b/core/fxcrt/xml/cxml_parser.cpp
index 0166ea8490..5ac1f82206 100644
--- a/core/fxcrt/xml/cxml_parser.cpp
+++ b/core/fxcrt/xml/cxml_parser.cpp
@@ -86,8 +86,8 @@ void FX_XML_SplitQualifiedName(const CFX_ByteStringC& bsFullName,
if (iStart == -1) {
bsName = bsFullName;
} else {
- bsSpace = bsFullName.Mid(0, iStart);
- bsName = bsFullName.Mid(iStart + 1, bsFullName.GetLength() - (iStart + 1));
+ bsSpace = bsFullName.Left(iStart);
+ bsName = bsFullName.Right(bsFullName.GetLength() - (iStart + 1));
}
}
diff --git a/core/fxge/cfx_fontmapper.cpp b/core/fxge/cfx_fontmapper.cpp
index 5c7b602fed..4c0073ab73 100644
--- a/core/fxge/cfx_fontmapper.cpp
+++ b/core/fxge/cfx_fontmapper.cpp
@@ -432,7 +432,7 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name,
CFX_ByteString SubstName = name;
SubstName.Remove(' ');
if (bTrueType && name[0] == '@')
- SubstName = name.Mid(1, name.GetLength() - 1);
+ SubstName = name.Right(name.GetLength() - 1);
PDF_GetStandardFontName(&SubstName);
if (SubstName == "Symbol" && !bTrueType) {
pSubstFont->m_Family = "Chrome Symbol";
@@ -453,7 +453,7 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name,
if (find >= 0) {
family = SubstName.Left(find);
PDF_GetStandardFontName(&family);
- style = SubstName.Mid(find + 1, SubstName.GetLength() - (find + 1));
+ style = SubstName.Right(SubstName.GetLength() - (find + 1));
bHasComma = true;
} else {
family = SubstName;
@@ -480,7 +480,7 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name,
if (!bHasComma) {
find = family.ReverseFind('-');
if (find >= 0) {
- style = family.Mid(find + 1, family.GetLength() - (find + 1));
+ style = family.Right(family.GetLength() - (find + 1));
family = family.Left(find);
bHasHyphen = true;
}