Use size_t in CFX_CSSStyleSheet.
Change-Id: I6db54699323d5dba18afac09733962f3bb70fd50
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/66373
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/css/cfx_cssrulecollection.cpp b/core/fxcrt/css/cfx_cssrulecollection.cpp
index f525821..4b63914 100644
--- a/core/fxcrt/css/cfx_cssrulecollection.cpp
+++ b/core/fxcrt/css/cfx_cssrulecollection.cpp
@@ -34,9 +34,8 @@
}
void CFX_CSSRuleCollection::AddRulesFrom(const CFX_CSSStyleSheet* sheet) {
- int32_t iRules = sheet->CountRules();
- for (int32_t j = 0; j < iRules; j++)
- AddRulesFrom(sheet, sheet->GetRule(j));
+ for (size_t i = 0; i < sheet->CountRules(); ++i)
+ AddRulesFrom(sheet, sheet->GetRule(i));
}
void CFX_CSSRuleCollection::AddRulesFrom(const CFX_CSSStyleSheet* pStyleSheet,
diff --git a/core/fxcrt/css/cfx_cssstylesheet.cpp b/core/fxcrt/css/cfx_cssstylesheet.cpp
index df44530..c079097 100644
--- a/core/fxcrt/css/cfx_cssstylesheet.cpp
+++ b/core/fxcrt/css/cfx_cssstylesheet.cpp
@@ -13,7 +13,6 @@
#include "core/fxcrt/css/cfx_cssstylerule.h"
#include "core/fxcrt/fx_codepage.h"
#include "third_party/base/ptr_util.h"
-#include "third_party/base/stl_util.h"
CFX_CSSStyleSheet::CFX_CSSStyleSheet() {}
@@ -26,11 +25,11 @@
m_StringCache.clear();
}
-int32_t CFX_CSSStyleSheet::CountRules() const {
- return pdfium::CollectionSize<int32_t>(m_RuleArray);
+size_t CFX_CSSStyleSheet::CountRules() const {
+ return m_RuleArray.size();
}
-CFX_CSSStyleRule* CFX_CSSStyleSheet::GetRule(int32_t index) const {
+CFX_CSSStyleRule* CFX_CSSStyleSheet::GetRule(size_t index) const {
return m_RuleArray[index].get();
}
diff --git a/core/fxcrt/css/cfx_cssstylesheet.h b/core/fxcrt/css/cfx_cssstylesheet.h
index 3f3a94a..ed89106 100644
--- a/core/fxcrt/css/cfx_cssstylesheet.h
+++ b/core/fxcrt/css/cfx_cssstylesheet.h
@@ -23,8 +23,8 @@
bool LoadBuffer(const wchar_t* pBuffer, int32_t iBufSize);
- int32_t CountRules() const;
- CFX_CSSStyleRule* GetRule(int32_t index) const;
+ size_t CountRules() const;
+ CFX_CSSStyleRule* GetRule(size_t index) const;
private:
void Reset();
diff --git a/core/fxcrt/css/cfx_cssstylesheet_unittest.cpp b/core/fxcrt/css/cfx_cssstylesheet_unittest.cpp
index 5207ea2..a69c68f 100644
--- a/core/fxcrt/css/cfx_cssstylesheet_unittest.cpp
+++ b/core/fxcrt/css/cfx_cssstylesheet_unittest.cpp
@@ -27,7 +27,7 @@
void TearDown() override { decl_ = nullptr; }
- void LoadAndVerifyRuleCount(const wchar_t* buf, int rule_count) {
+ void LoadAndVerifyRuleCount(const wchar_t* buf, size_t rule_count) {
ASSERT(sheet_);
EXPECT_TRUE(sheet_->LoadBuffer(buf, wcslen(buf)));
EXPECT_EQ(sheet_->CountRules(), rule_count);
@@ -100,10 +100,10 @@
const wchar_t* buf =
L"a { border: 10px; }\nb { text-decoration: underline; }";
EXPECT_TRUE(sheet_->LoadBuffer(buf, wcslen(buf)));
- EXPECT_EQ(2, sheet_->CountRules());
+ EXPECT_EQ(2u, sheet_->CountRules());
CFX_CSSStyleRule* style = sheet_->GetRule(0);
- EXPECT_EQ(1UL, style->CountSelectorLists());
+ EXPECT_EQ(1u, style->CountSelectorLists());
bool found_selector = false;
uint32_t hash = FX_HashCode_GetW(L"a", true);
@@ -116,7 +116,7 @@
EXPECT_TRUE(found_selector);
decl_ = style->GetDeclaration();
- EXPECT_EQ(4UL, decl_->PropertyCountForTesting());
+ EXPECT_EQ(4u, decl_->PropertyCountForTesting());
VerifyFloat(CFX_CSSProperty::BorderLeftWidth, 10.0,
CFX_CSSNumberType::Pixels);
@@ -127,7 +127,7 @@
CFX_CSSNumberType::Pixels);
style = sheet_->GetRule(1);
- EXPECT_EQ(1UL, style->CountSelectorLists());
+ EXPECT_EQ(1u, style->CountSelectorLists());
found_selector = false;
hash = FX_HashCode_GetW(L"b", true);
@@ -140,7 +140,7 @@
EXPECT_TRUE(found_selector);
decl_ = style->GetDeclaration();
- EXPECT_EQ(1UL, decl_->PropertyCountForTesting());
+ EXPECT_EQ(1u, decl_->PropertyCountForTesting());
VerifyList(CFX_CSSProperty::TextDecoration,
{CFX_CSSPropertyValue::Underline});
}
@@ -148,28 +148,28 @@
TEST_F(CFX_CSSStyleSheetTest, ParseChildSelectors) {
const wchar_t* buf = L"a b c { border: 10px; }";
EXPECT_TRUE(sheet_->LoadBuffer(buf, wcslen(buf)));
- EXPECT_EQ(1, sheet_->CountRules());
+ EXPECT_EQ(1u, sheet_->CountRules());
CFX_CSSStyleRule* style = sheet_->GetRule(0);
- EXPECT_EQ(1UL, style->CountSelectorLists());
+ EXPECT_EQ(1u, style->CountSelectorLists());
auto* sel = style->GetSelectorList(0);
- EXPECT_TRUE(sel != nullptr);
+ ASSERT_TRUE(sel);
EXPECT_EQ(FX_HashCode_GetW(L"c", true), sel->GetNameHash());
sel = sel->GetNextSelector();
- EXPECT_TRUE(sel != nullptr);
+ ASSERT_TRUE(sel);
EXPECT_EQ(FX_HashCode_GetW(L"b", true), sel->GetNameHash());
sel = sel->GetNextSelector();
- EXPECT_TRUE(sel != nullptr);
+ ASSERT_TRUE(sel);
EXPECT_EQ(FX_HashCode_GetW(L"a", true), sel->GetNameHash());
sel = sel->GetNextSelector();
- EXPECT_TRUE(sel == nullptr);
+ EXPECT_FALSE(sel);
decl_ = style->GetDeclaration();
- EXPECT_EQ(4UL, decl_->PropertyCountForTesting());
+ EXPECT_EQ(4u, decl_->PropertyCountForTesting());
VerifyFloat(CFX_CSSProperty::BorderLeftWidth, 10.0,
CFX_CSSNumberType::Pixels);
@@ -183,19 +183,19 @@
TEST_F(CFX_CSSStyleSheetTest, ParseUnhandledSelectors) {
const wchar_t* buf = L"a > b { padding: 0; }";
EXPECT_TRUE(sheet_->LoadBuffer(buf, wcslen(buf)));
- EXPECT_EQ(0, sheet_->CountRules());
+ EXPECT_EQ(0u, sheet_->CountRules());
buf = L"a[first] { padding: 0; }";
EXPECT_TRUE(sheet_->LoadBuffer(buf, wcslen(buf)));
- EXPECT_EQ(0, sheet_->CountRules());
+ EXPECT_EQ(0u, sheet_->CountRules());
buf = L"a+b { padding: 0; }";
EXPECT_TRUE(sheet_->LoadBuffer(buf, wcslen(buf)));
- EXPECT_EQ(0, sheet_->CountRules());
+ EXPECT_EQ(0u, sheet_->CountRules());
buf = L"a ^ b { padding: 0; }";
EXPECT_TRUE(sheet_->LoadBuffer(buf, wcslen(buf)));
- EXPECT_EQ(0, sheet_->CountRules());
+ EXPECT_EQ(0u, sheet_->CountRules());
}
TEST_F(CFX_CSSStyleSheetTest, ParseMultipleSelectorsCombined) {