summaryrefslogtreecommitdiff
path: root/core/fpdftext/cpdf_textpagefind.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_textpagefind.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_textpagefind.cpp')
-rw-r--r--core/fpdftext/cpdf_textpagefind.cpp26
1 files changed, 13 insertions, 13 deletions
diff --git a/core/fpdftext/cpdf_textpagefind.cpp b/core/fpdftext/cpdf_textpagefind.cpp
index 3c8e532a7f..55f940cad7 100644
--- a/core/fpdftext/cpdf_textpagefind.cpp
+++ b/core/fpdftext/cpdf_textpagefind.cpp
@@ -110,7 +110,7 @@ bool CPDF_TextPageFind::FindFirst(const CFX_WideString& findwhat,
m_csFindWhatArray.clear();
int i = 0;
while (i < len) {
- if (findwhatStr.GetAt(i) != ' ')
+ if (findwhatStr[i] != ' ')
break;
i++;
}
@@ -150,7 +150,7 @@ bool CPDF_TextPageFind::FindNext() {
CFX_WideString csWord = m_csFindWhatArray[iWord];
if (csWord.IsEmpty()) {
if (iWord == nCount - 1) {
- wchar_t strInsert = m_strText.GetAt(nStartPos);
+ wchar_t strInsert = m_strText[nStartPos];
if (strInsert == TEXT_LINEFEED_CHAR || strInsert == TEXT_SPACE_CHAR ||
strInsert == TEXT_RETURN_CHAR || strInsert == 160) {
nResultPos = nStartPos + 1;
@@ -174,16 +174,16 @@ bool CPDF_TextPageFind::FindNext() {
bool bMatch = true;
if (iWord != 0 && !bSpaceStart) {
int PreResEndPos = nStartPos;
- int curChar = csWord.GetAt(0);
+ int curChar = csWord[0];
CFX_WideString lastWord = m_csFindWhatArray[iWord - 1];
- int lastChar = lastWord.GetAt(lastWord.GetLength() - 1);
+ int lastChar = lastWord[lastWord.GetLength() - 1];
if (nStartPos == nResultPos &&
!(IsIgnoreSpaceCharacter(lastChar) ||
IsIgnoreSpaceCharacter(curChar))) {
bMatch = false;
}
for (int d = PreResEndPos; d < nResultPos; d++) {
- wchar_t strInsert = m_strText.GetAt(d);
+ wchar_t strInsert = m_strText[d];
if (strInsert != TEXT_LINEFEED_CHAR && strInsert != TEXT_SPACE_CHAR &&
strInsert != TEXT_RETURN_CHAR && strInsert != 160) {
bMatch = false;
@@ -192,7 +192,7 @@ bool CPDF_TextPageFind::FindNext() {
}
} else if (bSpaceStart) {
if (nResultPos > 0) {
- wchar_t strInsert = m_strText.GetAt(nResultPos - 1);
+ wchar_t strInsert = m_strText[nResultPos - 1];
if (strInsert != TEXT_LINEFEED_CHAR && strInsert != TEXT_SPACE_CHAR &&
strInsert != TEXT_RETURN_CHAR && strInsert != 160) {
bMatch = false;
@@ -293,7 +293,7 @@ void CPDF_TextPageFind::ExtractFindWhat(const CFX_WideString& findwhat) {
int pos = 0;
while (pos < csWord.GetLength()) {
CFX_WideString curStr = csWord.Mid(pos, 1);
- wchar_t curChar = csWord.GetAt(pos);
+ wchar_t curChar = csWord[pos];
if (IsIgnoreSpaceCharacter(curChar)) {
if (pos > 0 && curChar == 0x2019) {
pos++;
@@ -326,12 +326,12 @@ bool CPDF_TextPageFind::IsMatchWholeWord(const CFX_WideString& csPageText,
int char_count = endPos - startPos + 1;
if (char_count < 1)
return false;
- if (char_count == 1 && csPageText.GetAt(startPos) > 255)
+ if (char_count == 1 && csPageText[startPos] > 255)
return true;
if (startPos - 1 >= 0)
- char_left = csPageText.GetAt(startPos - 1);
+ char_left = csPageText[startPos - 1];
if (startPos + char_count < csPageText.GetLength())
- char_right = csPageText.GetAt(startPos + char_count);
+ char_right = csPageText[startPos + char_count];
if ((char_left > 'A' && char_left < 'a') ||
(char_left > 'a' && char_left < 'z') ||
(char_left > 0xfb00 && char_left < 0xfb06) || std::iswdigit(char_left) ||
@@ -348,9 +348,9 @@ bool CPDF_TextPageFind::IsMatchWholeWord(const CFX_WideString& csPageText,
return false;
}
if (char_count > 0) {
- if (std::iswdigit(char_left) && std::iswdigit(csPageText.GetAt(startPos)))
+ if (std::iswdigit(char_left) && std::iswdigit(csPageText[startPos]))
return false;
- if (std::iswdigit(char_right) && std::iswdigit(csPageText.GetAt(endPos)))
+ if (std::iswdigit(char_right) && std::iswdigit(csPageText[endPos]))
return false;
}
return true;
@@ -386,7 +386,7 @@ CFX_WideString CPDF_TextPageFind::MakeReverse(const CFX_WideString& str) {
str2.clear();
int nlen = str.GetLength();
for (int i = nlen - 1; i >= 0; i--)
- str2 += str.GetAt(i);
+ str2 += str[i];
return str2;
}