summaryrefslogtreecommitdiff
path: root/core/fpdftext/cpdf_textpage.cpp
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2017-08-15 10:37:59 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-08-15 15:03:10 +0000
commit8a1758bf11c2d741e0cddc761b1dd2cdf564db93 (patch)
tree82cbafc46f574a05ae0c1d1d3d7f9ebde6cb932d /core/fpdftext/cpdf_textpage.cpp
parent171cb27a720036c48ae3a6176084e880742af0a9 (diff)
downloadpdfium-8a1758bf11c2d741e0cddc761b1dd2cdf564db93.tar.xz
Remove GetAt from string classes
This method duplicates the behaviour of the const [] operator and doesn't offer any additional safety. Folding them into one implementation. SetAt is retained, since implementing the non-const [] operator to replace SetAt has potential performance concerns. Specifically many non-obvious cases of reading an element using [] will cause a realloc & copy. BUG=pdfium:860 Change-Id: I3ef5e5e5a15376f040256b646eb0d90636e24b67 Reviewed-on: https://pdfium-review.googlesource.com/10870 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fpdftext/cpdf_textpage.cpp')
-rw-r--r--core/fpdftext/cpdf_textpage.cpp30
1 files changed, 14 insertions, 16 deletions
diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp
index 1470ad700d..a4c8b8fba0 100644
--- a/core/fpdftext/cpdf_textpage.cpp
+++ b/core/fpdftext/cpdf_textpage.cpp
@@ -701,7 +701,7 @@ void CPDF_TextPage::CloseTempLine() {
CFX_WideString str = m_TempTextBuf.MakeString();
bool bPrevSpace = false;
for (int i = 0; i < str.GetLength(); i++) {
- if (str.GetAt(i) != ' ') {
+ if (str[i] != ' ') {
bPrevSpace = false;
continue;
}
@@ -841,8 +841,7 @@ FPDFText_MarkedContent CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) {
CPDF_Font* pFont = pTextObj->GetFont();
bExist = false;
for (FX_STRSIZE i = 0; i < nItems; i++) {
- if (pFont->CharCodeFromUnicode(actText.GetAt(i)) !=
- CPDF_Font::kInvalidCharCode) {
+ if (pFont->CharCodeFromUnicode(actText[i]) != CPDF_Font::kInvalidCharCode) {
bExist = true;
break;
}
@@ -852,7 +851,7 @@ FPDFText_MarkedContent CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) {
bExist = false;
for (FX_STRSIZE i = 0; i < nItems; i++) {
- wchar_t wChar = actText.GetAt(i);
+ wchar_t wChar = actText[i];
if ((wChar > 0x80 && wChar < 0xFFFD) || (wChar <= 0x80 && isprint(wChar))) {
bExist = true;
break;
@@ -889,7 +888,7 @@ void CPDF_TextPage::ProcessMarkedContent(PDFTEXT_Obj Obj) {
matrix.Concat(Obj.m_formMatrix);
for (FX_STRSIZE k = 0; k < nItems; k++) {
- wchar_t wChar = actText.GetAt(k);
+ wchar_t wChar = actText[k];
if (wChar <= 0x80 && !isprint(wChar))
wChar = 0x20;
if (wChar >= 0xFFFD)
@@ -1005,12 +1004,12 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) {
pTextObj->GetFont()->UnicodeFromCharCode(item.m_CharCode);
if (wstrItem.IsEmpty())
wstrItem += (wchar_t)item.m_CharCode;
- wchar_t curChar = wstrItem.GetAt(0);
+ wchar_t curChar = wstrItem[0];
if (curChar == 0x2D || curChar == 0xAD)
return;
}
while (m_TempTextBuf.GetSize() > 0 &&
- m_TempTextBuf.AsStringC().GetAt(m_TempTextBuf.GetLength() - 1) ==
+ m_TempTextBuf.AsStringC()[m_TempTextBuf.GetLength() - 1] ==
0x20) {
m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1);
m_TempCharList.pop_back();
@@ -1053,7 +1052,7 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) {
CFX_WideString str = m_TempTextBuf.MakeString();
if (str.IsEmpty())
str = m_TextBuf.AsStringC();
- if (str.IsEmpty() || str.GetAt(str.GetLength() - 1) == TEXT_SPACE_CHAR)
+ if (str.IsEmpty() || str[str.GetLength() - 1] == TEXT_SPACE_CHAR)
continue;
float fontsize_h = pTextObj->m_TextState.GetFontSizeH();
@@ -1164,7 +1163,7 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) {
}
if (!bDel) {
for (int nIndex = 0; nIndex < nTotal; nIndex++) {
- charinfo.m_Unicode = wstrItem.GetAt(nIndex);
+ charinfo.m_Unicode = wstrItem[nIndex];
if (charinfo.m_Unicode) {
charinfo.m_Index = m_TextBuf.GetLength();
m_TempTextBuf.AppendChar(charinfo.m_Unicode);
@@ -1175,8 +1174,7 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) {
}
} else if (i == 0) {
CFX_WideString str = m_TempTextBuf.MakeString();
- if (!str.IsEmpty() &&
- str.GetAt(str.GetLength() - 1) == TEXT_SPACE_CHAR) {
+ if (!str.IsEmpty() && str[str.GetLength() - 1] == TEXT_SPACE_CHAR) {
m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1);
m_TempCharList.pop_back();
}
@@ -1225,12 +1223,12 @@ bool CPDF_TextPage::IsHyphen(wchar_t curChar) {
if (nCount < 1)
return false;
int nIndex = nCount - 1;
- wchar_t wcTmp = strCurText.GetAt(nIndex);
+ wchar_t wcTmp = strCurText[nIndex];
while (wcTmp == 0x20 && nIndex > 0 && nIndex <= nCount - 1)
- wcTmp = strCurText.GetAt(--nIndex);
+ wcTmp = strCurText[--nIndex];
if (0x2D == wcTmp || 0xAD == wcTmp) {
if (--nIndex > 0) {
- wchar_t preChar = strCurText.GetAt((nIndex));
+ wchar_t preChar = strCurText[nIndex];
if (FXSYS_iswalpha(preChar) && FXSYS_iswalpha(curChar))
return true;
}
@@ -1268,7 +1266,7 @@ CPDF_TextPage::GenerateCharacter CPDF_TextPage::ProcessInsertObject(
pObj->GetFont()->UnicodeFromCharCode(item.m_CharCode);
if (wstrItem.IsEmpty())
wstrItem += static_cast<wchar_t>(item.m_CharCode);
- wchar_t curChar = wstrItem.GetAt(0);
+ wchar_t curChar = wstrItem[0];
if (WritingMode == TextOrientation::Horizontal) {
if (this_rect.Height() > 4.5 && prev_rect.Height() > 4.5) {
float top = this_rect.top < prev_rect.top ? this_rect.top : prev_rect.top;
@@ -1357,7 +1355,7 @@ CPDF_TextPage::GenerateCharacter CPDF_TextPage::ProcessInsertObject(
m_pPreTextObj->GetFont()->UnicodeFromCharCode(PrevItem.m_CharCode);
if (PrevStr.IsEmpty())
return GenerateCharacter::None;
- wchar_t preChar = PrevStr.GetAt(PrevStr.GetLength() - 1);
+ wchar_t preChar = PrevStr[PrevStr.GetLength() - 1];
CFX_Matrix matrix = pObj->GetTextMatrix();
matrix.Concat(formMatrix);