Replace str[str.GetLength() - 1] with str.Last().
Simplify some related code along the way.
Change-Id: Ia65a8c6b8cb7feee310cef37af8a128646533e82
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/65571
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/font/cpdf_font.cpp b/core/fpdfapi/font/cpdf_font.cpp
index 089d61c..813e4b5 100644
--- a/core/fpdfapi/font/cpdf_font.cpp
+++ b/core/fpdfapi/font/cpdf_font.cpp
@@ -345,8 +345,7 @@
return 0;
size_t& offset = *pOffset;
- return offset < pString.GetLength() ? pString[offset++]
- : pString[pString.GetLength() - 1];
+ return offset < pString.GetLength() ? pString[offset++] : pString.Last();
}
bool CPDF_Font::IsStandardFont() const {
diff --git a/core/fpdftext/cpdf_linkextract.cpp b/core/fpdftext/cpdf_linkextract.cpp
index 81519a1..6ac5f98 100644
--- a/core/fpdftext/cpdf_linkextract.cpp
+++ b/core/fpdftext/cpdf_linkextract.cpp
@@ -152,7 +152,7 @@
if (strBeCheck.GetLength() > 5) {
while (strBeCheck.GetLength() > 0) {
- wchar_t ch = strBeCheck[strBeCheck.GetLength() - 1];
+ wchar_t ch = strBeCheck.Last();
if (ch != L')' && ch != L',' && ch != L'>' && ch != L'.')
break;
diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp
index f128475..677b5d2 100644
--- a/core/fpdftext/cpdf_textpage.cpp
+++ b/core/fpdftext/cpdf_textpage.cpp
@@ -962,8 +962,7 @@
return;
}
while (m_TempTextBuf.GetSize() > 0 &&
- m_TempTextBuf.AsStringView()[m_TempTextBuf.GetLength() - 1] ==
- 0x20) {
+ m_TempTextBuf.AsStringView().Last() == 0x20) {
m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1);
m_TempCharList.pop_back();
}
@@ -1005,7 +1004,7 @@
WideString str = m_TempTextBuf.MakeString();
if (str.IsEmpty())
str = m_TextBuf.AsStringView();
- if (str.IsEmpty() || str[str.GetLength() - 1] == L' ')
+ if (str.IsEmpty() || str.Last() == L' ')
continue;
float fontsize_h = pTextObj->m_TextState.GetFontSizeH();
@@ -1119,7 +1118,7 @@
}
} else if (i == 0) {
WideString str = m_TempTextBuf.MakeString();
- if (!str.IsEmpty() && str[str.GetLength() - 1] == L' ') {
+ if (!str.IsEmpty() && str.Last() == L' ') {
m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1);
m_TempCharList.pop_back();
}
diff --git a/core/fpdftext/cpdf_textpagefind.cpp b/core/fpdftext/cpdf_textpagefind.cpp
index 04f4130..6fd179b 100644
--- a/core/fpdftext/cpdf_textpagefind.cpp
+++ b/core/fpdftext/cpdf_textpagefind.cpp
@@ -248,7 +248,7 @@
size_t PreResEndPos = nStartPos;
int curChar = csWord[0];
WideString lastWord = m_csFindWhatArray[iWord - 1];
- int lastChar = lastWord[lastWord.GetLength() - 1];
+ int lastChar = lastWord.Last();
if (nStartPos == nResultPos.value() &&
!(IsIgnoreSpaceCharacter(lastChar) ||
IsIgnoreSpaceCharacter(curChar))) {
diff --git a/xfa/fxfa/cxfa_textlayout.cpp b/xfa/fxfa/cxfa_textlayout.cpp
index 7f6b328..cb28541 100644
--- a/xfa/fxfa/cxfa_textlayout.cpp
+++ b/xfa/fxfa/cxfa_textlayout.cpp
@@ -798,8 +798,7 @@
} else if (CFX_CSSDisplay::Inline == eDisplay &&
m_pLoader->bFilterSpace) {
m_pLoader->bFilterSpace = false;
- } else if (wsText.GetLength() > 0 &&
- (0x20 == wsText[wsText.GetLength() - 1])) {
+ } else if (wsText.GetLength() > 0 && wsText.Last() == 0x20) {
m_pLoader->bFilterSpace = true;
} else if (wsText.GetLength() != 0) {
m_pLoader->bFilterSpace = false;
@@ -816,14 +815,13 @@
if (AppendChar(wsText, pLinePos, 0, bSavePieces)) {
if (m_pLoader)
m_pLoader->bFilterSpace = false;
- if (IsEnd(bSavePieces)) {
- if (m_pLoader && m_pLoader->iTotalLines > -1) {
- m_pLoader->pXMLNode = pXMLNode;
- m_pLoader->pParentStyle = pParentStyle;
- }
- return false;
+ if (!IsEnd(bSavePieces))
+ return true;
+ if (m_pLoader && m_pLoader->iTotalLines > -1) {
+ m_pLoader->pXMLNode = pXMLNode;
+ m_pLoader->pParentStyle = pParentStyle;
}
- return true;
+ return false;
}
}
}
diff --git a/xfa/fxfa/parser/cxfa_document_parser.cpp b/xfa/fxfa/parser/cxfa_document_parser.cpp
index b141f7d..edae8b7 100644
--- a/xfa/fxfa/parser/cxfa_document_parser.cpp
+++ b/xfa/fxfa/parser/cxfa_document_parser.cpp
@@ -195,8 +195,7 @@
wsPlainText += L"\n";
}
} else if (uTag == 0xa48ac63) {
- if (!wsPlainText.IsEmpty() &&
- wsPlainText[wsPlainText.GetLength() - 1] != '\n') {
+ if (!wsPlainText.IsEmpty() && wsPlainText.Last() != '\n') {
wsPlainText += L"\n";
}
}
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index eb55163..9c1a2ff 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -3256,10 +3256,8 @@
return;
}
- wchar_t wcEnter = '\n';
- wchar_t wsLast = wsText[wsText.GetLength() - 1];
- if (wsLast == wcEnter)
- wsText = wsText + wcEnter;
+ if (wsText.Last() == L'\n')
+ wsText += L'\n';
CXFA_FieldLayoutData* layoutData = m_pLayoutData->AsFieldLayoutData();
if (!layoutData->m_pTextOut) {