Use str.IsEmpty() instead of str.GetLength() == 0.
Rewrite CFGAS_GEFont::GetFamilyName() along the way.
Change-Id: Iaeee9b90a0211a47cfbda79ce27f31c05ebdb897
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/65573
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/font/cpdf_cmapparser.cpp b/core/fpdfapi/font/cpdf_cmapparser.cpp
index 6b5e56f..af23f50 100644
--- a/core/fpdfapi/font/cpdf_cmapparser.cpp
+++ b/core/fpdfapi/font/cpdf_cmapparser.cpp
@@ -109,7 +109,7 @@
void CPDF_CMapParser::HandleCodeSpaceRange(ByteStringView word) {
if (word != "endcodespacerange") {
- if (word.GetLength() == 0 || word[0] != '<')
+ if (word.IsEmpty() || word[0] != '<')
return;
if (m_CodeSeq % 2) {
@@ -165,7 +165,7 @@
Optional<CPDF_CMap::CodeRange> CPDF_CMapParser::GetCodeRange(
ByteStringView first,
ByteStringView second) {
- if (first.GetLength() == 0 || first[0] != '<')
+ if (first.IsEmpty() || first[0] != '<')
return pdfium::nullopt;
size_t i;
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
index f21b5e5..0a55c27 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
@@ -430,7 +430,7 @@
FX_FILESIZE SavedObjPos = m_Pos;
bool bIsNumber;
ByteString word = GetNextWord(&bIsNumber);
- if (word.GetLength() == 0)
+ if (word.IsEmpty())
return nullptr;
if (bIsNumber) {
diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp
index 8c79208..7252f91 100644
--- a/core/fpdftext/cpdf_textpage.cpp
+++ b/core/fpdftext/cpdf_textpage.cpp
@@ -448,7 +448,7 @@
WideString CPDF_TextPage::GetPageText(int start, int count) const {
if (start < 0 || start >= CountChars() || count <= 0 || m_CharList.empty() ||
- m_TextBuf.GetLength() == 0) {
+ m_TextBuf.IsEmpty()) {
return WideString();
}
diff --git a/core/fxge/dib/fx_dib_main.cpp b/core/fxge/dib/fx_dib_main.cpp
index 031fe65..31e5919 100644
--- a/core/fxge/dib/fx_dib_main.cpp
+++ b/core/fxge/dib/fx_dib_main.cpp
@@ -106,7 +106,7 @@
FX_ARGB StringToFXARGB(WideStringView view) {
static constexpr FX_ARGB kDefaultValue = 0xff000000;
- if (view.GetLength() == 0)
+ if (view.IsEmpty())
return kDefaultValue;
int cc = 0;
diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp
index 0b3f472..9294f17 100644
--- a/fxjs/cjs_document.cpp
+++ b/fxjs/cjs_document.cpp
@@ -359,7 +359,7 @@
CPDFSDK_InteractiveForm* pInteractiveForm = GetSDKInteractiveForm();
ByteString sTextBuf = pInteractiveForm->ExportFormToFDFTextBuf();
- if (sTextBuf.GetLength() == 0)
+ if (sTextBuf.IsEmpty())
return CJS_Result::Failure(L"Bad FDF format.");
std::vector<v8::Local<v8::Value>> newParams = ExpandKeywordParams(
diff --git a/fxjs/cjs_runtime.cpp b/fxjs/cjs_runtime.cpp
index 81148de..919d47a 100644
--- a/fxjs/cjs_runtime.cpp
+++ b/fxjs/cjs_runtime.cpp
@@ -216,7 +216,7 @@
bool bAllowNaN = false;
if (value->IsString()) {
ByteString bstr = ToWideString(value).ToDefANSI();
- if (bstr.GetLength() == 0)
+ if (bstr.IsEmpty())
return value;
if (bstr == "NaN")
bAllowNaN = true;
diff --git a/fxjs/xfa/cfxjse_resolveprocessor.cpp b/fxjs/xfa/cfxjse_resolveprocessor.cpp
index 7aa265d..3dc80e7 100644
--- a/fxjs/xfa/cfxjse_resolveprocessor.cpp
+++ b/fxjs/xfa/cfxjse_resolveprocessor.cpp
@@ -220,7 +220,7 @@
if (rndFind.m_Objects.empty())
return false;
- if (wsCondition.GetLength() == 0 &&
+ if (wsCondition.IsEmpty() &&
pdfium::ContainsValue(rndFind.m_Objects, curNode)) {
rnd.m_Objects.emplace_back(curNode);
} else {
@@ -423,7 +423,7 @@
} else {
if (child->GetNameHash() == uNameHash) {
rnd.m_Objects.emplace_back(curNode);
- if (rnd.m_nLevel == 0 && wsCondition.GetLength() == 0) {
+ if (rnd.m_nLevel == 0 && wsCondition.IsEmpty()) {
rnd.m_Objects.clear();
rnd.m_Objects.emplace_back(curNode);
return true;
diff --git a/testing/fuzzers/pdf_css_fuzzer.cc b/testing/fuzzers/pdf_css_fuzzer.cc
index f820972..5f1471d 100644
--- a/testing/fuzzers/pdf_css_fuzzer.cc
+++ b/testing/fuzzers/pdf_css_fuzzer.cc
@@ -13,7 +13,7 @@
WideString::FromUTF8(ByteStringView(data, static_cast<size_t>(size)));
// If we convert the input into an empty string bail out.
- if (input.GetLength() == 0)
+ if (input.IsEmpty())
return 0;
CFX_CSSSyntaxParser parser(input.c_str(), input.GetLength());
diff --git a/xfa/fde/cfde_texteditengine.cpp b/xfa/fde/cfde_texteditengine.cpp
index 3b9c1ad..281f978 100644
--- a/xfa/fde/cfde_texteditengine.cpp
+++ b/xfa/fde/cfde_texteditengine.cpp
@@ -252,7 +252,7 @@
const WideString& request_text,
RecordOperation add_operation) {
WideString text = request_text;
- if (text.GetLength() == 0)
+ if (text.IsEmpty())
return;
idx = std::min(idx, text_length_);
diff --git a/xfa/fgas/font/cfgas_gefont.cpp b/xfa/fgas/font/cfgas_gefont.cpp
index 69aa702..5a7c625 100644
--- a/xfa/fgas/font/cfgas_gefont.cpp
+++ b/xfa/fgas/font/cfgas_gefont.cpp
@@ -130,12 +130,11 @@
}
WideString CFGAS_GEFont::GetFamilyName() const {
- if (!m_pFont->GetSubstFont() ||
- m_pFont->GetSubstFont()->m_Family.GetLength() == 0) {
- return WideString::FromDefANSI(m_pFont->GetFamilyName().AsStringView());
- }
- return WideString::FromDefANSI(
- m_pFont->GetSubstFont()->m_Family.AsStringView());
+ CFX_SubstFont* subst_font = m_pFont->GetSubstFont();
+ ByteString family_name = subst_font && !subst_font->m_Family.IsEmpty()
+ ? subst_font->m_Family
+ : m_pFont->GetFamilyName();
+ return WideString::FromDefANSI(family_name.AsStringView());
}
uint32_t CFGAS_GEFont::GetFontStyles() const {