summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fxcrt/bytestring.cpp87
-rw-r--r--core/fxcrt/bytestring.h14
-rw-r--r--core/fxcrt/bytestring_unittest.cpp118
-rw-r--r--core/fxcrt/widestring.cpp72
-rw-r--r--core/fxcrt/widestring.h14
-rw-r--r--core/fxcrt/widestring_unittest.cpp120
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp12
-rw-r--r--fxjs/cfxjse_formcalc_context.cpp3
-rw-r--r--fxjs/cfxjse_resolveprocessor.cpp9
-rw-r--r--fxjs/cjs_document.cpp6
-rw-r--r--fxjs/cjs_globaldata.cpp3
-rw-r--r--fxjs/cjs_publicmethods.cpp3
-rw-r--r--fxjs/cjx_hostpseudomodel.cpp3
-rw-r--r--xfa/fxfa/cxfa_textlayout.cpp2
-rw-r--r--xfa/fxfa/parser/cxfa_layoutpagemgr.cpp6
15 files changed, 283 insertions, 189 deletions
diff --git a/core/fxcrt/bytestring.cpp b/core/fxcrt/bytestring.cpp
index e868678c9f..324a2801e4 100644
--- a/core/fxcrt/bytestring.cpp
+++ b/core/fxcrt/bytestring.cpp
@@ -27,6 +27,8 @@ template struct std::hash<ByteString>;
namespace {
+constexpr char kTrimChars[] = "\x09\x0a\x0b\x0c\x0d\x20";
+
const char* FX_strstr(const char* haystack,
int haystack_len,
const char* needle,
@@ -98,7 +100,7 @@ static_assert(sizeof(ByteString) <= sizeof(char*),
// static
ByteString ByteString::FormatInteger(int i) {
char buf[32];
- FXSYS_snprintf(buf, 32, "%d", i);
+ FXSYS_snprintf(buf, sizeof(buf), "%d", i);
return ByteString(buf);
}
@@ -728,42 +730,32 @@ int ByteString::Compare(const ByteStringView& str) const {
return 0;
}
-void ByteString::TrimRight(const ByteStringView& pTargets) {
- if (!m_pData || pTargets.IsEmpty())
- return;
+void ByteString::Trim() {
+ TrimRight(kTrimChars);
+ TrimLeft(kTrimChars);
+}
- size_t pos = GetLength();
- if (pos == 0)
- return;
+void ByteString::Trim(char target) {
+ ByteStringView targets(target);
+ TrimRight(targets);
+ TrimLeft(targets);
+}
- while (pos) {
- size_t i = 0;
- while (i < pTargets.GetLength() &&
- pTargets[i] != m_pData->m_String[pos - 1]) {
- i++;
- }
- if (i == pTargets.GetLength()) {
- break;
- }
- pos--;
- }
- if (pos < m_pData->m_nDataLength) {
- ReallocBeforeWrite(m_pData->m_nDataLength);
- m_pData->m_String[pos] = 0;
- m_pData->m_nDataLength = pos;
- }
+void ByteString::Trim(const ByteStringView& targets) {
+ TrimRight(targets);
+ TrimLeft(targets);
}
-void ByteString::TrimRight(char chTarget) {
- TrimRight(ByteStringView(chTarget));
+void ByteString::TrimLeft() {
+ TrimLeft(kTrimChars);
}
-void ByteString::TrimRight() {
- TrimRight("\x09\x0a\x0b\x0c\x0d\x20");
+void ByteString::TrimLeft(char target) {
+ TrimLeft(ByteStringView(target));
}
-void ByteString::TrimLeft(const ByteStringView& pTargets) {
- if (!m_pData || pTargets.IsEmpty())
+void ByteString::TrimLeft(const ByteStringView& targets) {
+ if (!m_pData || targets.IsEmpty())
return;
size_t len = GetLength();
@@ -773,12 +765,10 @@ void ByteString::TrimLeft(const ByteStringView& pTargets) {
size_t pos = 0;
while (pos < len) {
size_t i = 0;
- while (i < pTargets.GetLength() && pTargets[i] != m_pData->m_String[pos]) {
+ while (i < targets.GetLength() && targets[i] != m_pData->m_String[pos])
i++;
- }
- if (i == pTargets.GetLength()) {
+ if (i == targets.GetLength())
break;
- }
pos++;
}
if (pos) {
@@ -790,12 +780,35 @@ void ByteString::TrimLeft(const ByteStringView& pTargets) {
}
}
-void ByteString::TrimLeft(char chTarget) {
- TrimLeft(ByteStringView(chTarget));
+void ByteString::TrimRight() {
+ TrimRight(kTrimChars);
}
-void ByteString::TrimLeft() {
- TrimLeft("\x09\x0a\x0b\x0c\x0d\x20");
+void ByteString::TrimRight(char target) {
+ TrimRight(ByteStringView(target));
+}
+
+void ByteString::TrimRight(const ByteStringView& targets) {
+ if (!m_pData || targets.IsEmpty())
+ return;
+
+ size_t pos = GetLength();
+ if (pos == 0)
+ return;
+
+ while (pos) {
+ size_t i = 0;
+ while (i < targets.GetLength() && targets[i] != m_pData->m_String[pos - 1])
+ i++;
+ if (i == targets.GetLength())
+ break;
+ pos--;
+ }
+ if (pos < m_pData->m_nDataLength) {
+ ReallocBeforeWrite(m_pData->m_nDataLength);
+ m_pData->m_String[pos] = 0;
+ m_pData->m_nDataLength = pos;
+ }
}
std::ostream& operator<<(std::ostream& os, const ByteString& str) {
diff --git a/core/fxcrt/bytestring.h b/core/fxcrt/bytestring.h
index 1acece3aee..bd414fc76f 100644
--- a/core/fxcrt/bytestring.h
+++ b/core/fxcrt/bytestring.h
@@ -167,13 +167,17 @@ class ByteString {
void MakeLower();
void MakeUpper();
- void TrimRight();
- void TrimRight(char chTarget);
- void TrimRight(const ByteStringView& lpszTargets);
+ void Trim();
+ void Trim(char target);
+ void Trim(const ByteStringView& targets);
void TrimLeft();
- void TrimLeft(char chTarget);
- void TrimLeft(const ByteStringView& lpszTargets);
+ void TrimLeft(char target);
+ void TrimLeft(const ByteStringView& targets);
+
+ void TrimRight();
+ void TrimRight(char target);
+ void TrimRight(const ByteStringView& targets);
size_t Replace(const ByteStringView& lpszOld, const ByteStringView& lpszNew);
diff --git a/core/fxcrt/bytestring_unittest.cpp b/core/fxcrt/bytestring_unittest.cpp
index 08c0e9211c..b45ee0fd5e 100644
--- a/core/fxcrt/bytestring_unittest.cpp
+++ b/core/fxcrt/bytestring_unittest.cpp
@@ -703,41 +703,75 @@ TEST(ByteString, UpperLower) {
EXPECT_EQ("", empty);
}
-TEST(ByteString, TrimRight) {
+TEST(ByteString, Trim) {
ByteString fred(" FRED ");
- fred.TrimRight();
- EXPECT_EQ(" FRED", fred);
- fred.TrimRight('E');
- EXPECT_EQ(" FRED", fred);
- fred.TrimRight('D');
- EXPECT_EQ(" FRE", fred);
- fred.TrimRight("ERP");
- EXPECT_EQ(" F", fred);
+ fred.Trim();
+ EXPECT_EQ("FRED", fred);
+ fred.Trim('E');
+ EXPECT_EQ("FRED", fred);
+ fred.Trim('F');
+ EXPECT_EQ("RED", fred);
+ fred.Trim("ERP");
+ EXPECT_EQ("D", fred);
ByteString blank(" ");
- blank.TrimRight("ERP");
+ blank.Trim("ERP");
EXPECT_EQ(" ", blank);
- blank.TrimRight('E');
+ blank.Trim('E');
EXPECT_EQ(" ", blank);
- blank.TrimRight();
+ blank.Trim();
EXPECT_EQ("", blank);
ByteString empty;
- empty.TrimRight("ERP");
+ empty.Trim("ERP");
EXPECT_EQ("", empty);
- empty.TrimRight('E');
+ empty.Trim('E');
EXPECT_EQ("", empty);
- empty.TrimRight();
+ empty.Trim();
EXPECT_EQ("", empty);
+
+ ByteString abc(" ABCCBA ");
+ abc.Trim("A");
+ EXPECT_EQ(" ABCCBA ", abc);
+ abc.Trim(" A");
+ EXPECT_EQ("BCCB", abc);
}
-TEST(ByteString, TrimRightCopies) {
+TEST(ByteString, TrimLeft) {
+ ByteString fred(" FRED ");
+ fred.TrimLeft();
+ EXPECT_EQ("FRED ", fred);
+ fred.TrimLeft('E');
+ EXPECT_EQ("FRED ", fred);
+ fred.TrimLeft('F');
+ EXPECT_EQ("RED ", fred);
+ fred.TrimLeft("ERP");
+ EXPECT_EQ("D ", fred);
+
+ ByteString blank(" ");
+ blank.TrimLeft("ERP");
+ EXPECT_EQ(" ", blank);
+ blank.TrimLeft('E');
+ EXPECT_EQ(" ", blank);
+ blank.TrimLeft();
+ EXPECT_EQ("", blank);
+
+ ByteString empty;
+ empty.TrimLeft("ERP");
+ EXPECT_EQ("", empty);
+ empty.TrimLeft('E');
+ EXPECT_EQ("", empty);
+ empty.TrimLeft();
+ EXPECT_EQ("", empty);
+}
+
+TEST(ByteString, TrimLeftCopies) {
{
// With a single reference, no copy takes place.
ByteString fred(" FRED ");
const char* old_buffer = fred.c_str();
- fred.TrimRight();
- EXPECT_EQ(" FRED", fred);
+ fred.TrimLeft();
+ EXPECT_EQ("FRED ", fred);
EXPECT_EQ(old_buffer, fred.c_str());
}
{
@@ -745,8 +779,8 @@ TEST(ByteString, TrimRightCopies) {
ByteString fred(" FRED ");
ByteString other_fred = fred;
const char* old_buffer = fred.c_str();
- fred.TrimRight();
- EXPECT_EQ(" FRED", fred);
+ fred.TrimLeft();
+ EXPECT_EQ("FRED ", fred);
EXPECT_EQ(" FRED ", other_fred);
EXPECT_NE(old_buffer, fred.c_str());
}
@@ -755,48 +789,48 @@ TEST(ByteString, TrimRightCopies) {
ByteString fred("FRED");
ByteString other_fred = fred;
const char* old_buffer = fred.c_str();
- fred.TrimRight();
+ fred.TrimLeft();
EXPECT_EQ("FRED", fred);
EXPECT_EQ("FRED", other_fred);
EXPECT_EQ(old_buffer, fred.c_str());
}
}
-TEST(ByteString, TrimLeft) {
+TEST(ByteString, TrimRight) {
ByteString fred(" FRED ");
- fred.TrimLeft();
- EXPECT_EQ("FRED ", fred);
- fred.TrimLeft('E');
- EXPECT_EQ("FRED ", fred);
- fred.TrimLeft('F');
- EXPECT_EQ("RED ", fred);
- fred.TrimLeft("ERP");
- EXPECT_EQ("D ", fred);
+ fred.TrimRight();
+ EXPECT_EQ(" FRED", fred);
+ fred.TrimRight('E');
+ EXPECT_EQ(" FRED", fred);
+ fred.TrimRight('D');
+ EXPECT_EQ(" FRE", fred);
+ fred.TrimRight("ERP");
+ EXPECT_EQ(" F", fred);
ByteString blank(" ");
- blank.TrimLeft("ERP");
+ blank.TrimRight("ERP");
EXPECT_EQ(" ", blank);
- blank.TrimLeft('E');
+ blank.TrimRight('E');
EXPECT_EQ(" ", blank);
- blank.TrimLeft();
+ blank.TrimRight();
EXPECT_EQ("", blank);
ByteString empty;
- empty.TrimLeft("ERP");
+ empty.TrimRight("ERP");
EXPECT_EQ("", empty);
- empty.TrimLeft('E');
+ empty.TrimRight('E');
EXPECT_EQ("", empty);
- empty.TrimLeft();
+ empty.TrimRight();
EXPECT_EQ("", empty);
}
-TEST(ByteString, TrimLeftCopies) {
+TEST(ByteString, TrimRightCopies) {
{
// With a single reference, no copy takes place.
ByteString fred(" FRED ");
const char* old_buffer = fred.c_str();
- fred.TrimLeft();
- EXPECT_EQ("FRED ", fred);
+ fred.TrimRight();
+ EXPECT_EQ(" FRED", fred);
EXPECT_EQ(old_buffer, fred.c_str());
}
{
@@ -804,8 +838,8 @@ TEST(ByteString, TrimLeftCopies) {
ByteString fred(" FRED ");
ByteString other_fred = fred;
const char* old_buffer = fred.c_str();
- fred.TrimLeft();
- EXPECT_EQ("FRED ", fred);
+ fred.TrimRight();
+ EXPECT_EQ(" FRED", fred);
EXPECT_EQ(" FRED ", other_fred);
EXPECT_NE(old_buffer, fred.c_str());
}
@@ -814,7 +848,7 @@ TEST(ByteString, TrimLeftCopies) {
ByteString fred("FRED");
ByteString other_fred = fred;
const char* old_buffer = fred.c_str();
- fred.TrimLeft();
+ fred.TrimRight();
EXPECT_EQ("FRED", fred);
EXPECT_EQ("FRED", other_fred);
EXPECT_EQ(old_buffer, fred.c_str());
diff --git a/core/fxcrt/widestring.cpp b/core/fxcrt/widestring.cpp
index d33ed1ad6c..2caa3b4213 100644
--- a/core/fxcrt/widestring.cpp
+++ b/core/fxcrt/widestring.cpp
@@ -31,6 +31,8 @@ template struct std::hash<WideString>;
namespace {
+constexpr wchar_t kTrimChars[] = L"\x09\x0a\x0b\x0c\x0d\x20";
+
const wchar_t* FX_wcsstr(const wchar_t* haystack,
int haystack_len,
const wchar_t* needle,
@@ -958,32 +960,33 @@ size_t WideString::WStringLength(const unsigned short* str) {
return len;
}
-void WideString::TrimRight(const WideStringView& pTargets) {
- if (IsEmpty() || pTargets.IsEmpty())
- return;
+void WideString::Trim() {
+ TrimRight(kTrimChars);
+ TrimLeft(kTrimChars);
+}
- size_t pos = GetLength();
- while (pos && pTargets.Contains(m_pData->m_String[pos - 1]))
- pos--;
+void WideString::Trim(wchar_t target) {
+ wchar_t str[2] = {target, 0};
+ TrimRight(str);
+ TrimLeft(str);
+}
- if (pos < m_pData->m_nDataLength) {
- ReallocBeforeWrite(m_pData->m_nDataLength);
- m_pData->m_String[pos] = 0;
- m_pData->m_nDataLength = pos;
- }
+void WideString::Trim(const WideStringView& targets) {
+ TrimRight(targets);
+ TrimLeft(targets);
}
-void WideString::TrimRight(wchar_t chTarget) {
- wchar_t str[2] = {chTarget, 0};
- TrimRight(str);
+void WideString::TrimLeft() {
+ TrimLeft(kTrimChars);
}
-void WideString::TrimRight() {
- TrimRight(L"\x09\x0a\x0b\x0c\x0d\x20");
+void WideString::TrimLeft(wchar_t target) {
+ wchar_t str[2] = {target, 0};
+ TrimLeft(str);
}
-void WideString::TrimLeft(const WideStringView& pTargets) {
- if (!m_pData || pTargets.IsEmpty())
+void WideString::TrimLeft(const WideStringView& targets) {
+ if (!m_pData || targets.IsEmpty())
return;
size_t len = GetLength();
@@ -993,13 +996,12 @@ void WideString::TrimLeft(const WideStringView& pTargets) {
size_t pos = 0;
while (pos < len) {
size_t i = 0;
- while (i < pTargets.GetLength() &&
- pTargets.CharAt(i) != m_pData->m_String[pos]) {
+ while (i < targets.GetLength() &&
+ targets.CharAt(i) != m_pData->m_String[pos]) {
i++;
}
- if (i == pTargets.GetLength()) {
+ if (i == targets.GetLength())
break;
- }
pos++;
}
if (!pos)
@@ -1012,14 +1014,30 @@ void WideString::TrimLeft(const WideStringView& pTargets) {
m_pData->m_nDataLength = nDataLength;
}
-void WideString::TrimLeft(wchar_t chTarget) {
- wchar_t str[2] = {chTarget, 0};
- TrimLeft(str);
+void WideString::TrimRight() {
+ TrimRight(kTrimChars);
}
-void WideString::TrimLeft() {
- TrimLeft(L"\x09\x0a\x0b\x0c\x0d\x20");
+void WideString::TrimRight(wchar_t target) {
+ wchar_t str[2] = {target, 0};
+ TrimRight(str);
}
+
+void WideString::TrimRight(const WideStringView& targets) {
+ if (IsEmpty() || targets.IsEmpty())
+ return;
+
+ size_t pos = GetLength();
+ while (pos && targets.Contains(m_pData->m_String[pos - 1]))
+ pos--;
+
+ if (pos < m_pData->m_nDataLength) {
+ ReallocBeforeWrite(m_pData->m_nDataLength);
+ m_pData->m_String[pos] = 0;
+ m_pData->m_nDataLength = pos;
+ }
+}
+
float FX_wtof(const wchar_t* str, int len) {
if (len == 0) {
return 0.0;
diff --git a/core/fxcrt/widestring.h b/core/fxcrt/widestring.h
index 9d856c72c9..f48c32379a 100644
--- a/core/fxcrt/widestring.h
+++ b/core/fxcrt/widestring.h
@@ -147,13 +147,17 @@ class WideString {
void MakeLower();
void MakeUpper();
- void TrimRight();
- void TrimRight(wchar_t chTarget);
- void TrimRight(const WideStringView& pTargets);
+ void Trim();
+ void Trim(wchar_t target);
+ void Trim(const WideStringView& targets);
void TrimLeft();
- void TrimLeft(wchar_t chTarget);
- void TrimLeft(const WideStringView& pTargets);
+ void TrimLeft(wchar_t target);
+ void TrimLeft(const WideStringView& targets);
+
+ void TrimRight();
+ void TrimRight(wchar_t target);
+ void TrimRight(const WideStringView& targets);
void Reserve(size_t len);
wchar_t* GetBuffer(size_t len);
diff --git a/core/fxcrt/widestring_unittest.cpp b/core/fxcrt/widestring_unittest.cpp
index aaa6d9cae7..39337aa7a7 100644
--- a/core/fxcrt/widestring_unittest.cpp
+++ b/core/fxcrt/widestring_unittest.cpp
@@ -628,41 +628,75 @@ TEST(WideString, UpperLower) {
EXPECT_EQ(L"", empty);
}
-TEST(WideString, TrimRight) {
+TEST(WideString, Trim) {
WideString fred(L" FRED ");
- fred.TrimRight();
- EXPECT_EQ(L" FRED", fred);
- fred.TrimRight(L'E');
- EXPECT_EQ(L" FRED", fred);
- fred.TrimRight(L'D');
- EXPECT_EQ(L" FRE", fred);
- fred.TrimRight(L"ERP");
- EXPECT_EQ(L" F", fred);
+ fred.Trim();
+ EXPECT_EQ(L"FRED", fred);
+ fred.Trim(L'E');
+ EXPECT_EQ(L"FRED", fred);
+ fred.Trim(L'F');
+ EXPECT_EQ(L"RED", fred);
+ fred.Trim(L"ERP");
+ EXPECT_EQ(L"D", fred);
WideString blank(L" ");
- blank.TrimRight(L"ERP");
+ blank.Trim(L"ERP");
EXPECT_EQ(L" ", blank);
- blank.TrimRight(L'E');
+ blank.Trim(L'E');
EXPECT_EQ(L" ", blank);
- blank.TrimRight();
+ blank.Trim();
EXPECT_EQ(L"", blank);
WideString empty;
- empty.TrimRight(L"ERP");
+ empty.Trim(L"ERP");
EXPECT_EQ(L"", empty);
- empty.TrimRight(L'E');
+ empty.Trim(L'E');
EXPECT_EQ(L"", empty);
- empty.TrimRight();
+ empty.Trim();
EXPECT_EQ(L"", empty);
+
+ WideString abc(L" ABCCBA ");
+ abc.Trim(L"A");
+ EXPECT_EQ(L" ABCCBA ", abc);
+ abc.Trim(L" A");
+ EXPECT_EQ(L"BCCB", abc);
}
-TEST(WideString, TrimRightCopies) {
+TEST(WideString, TrimLeft) {
+ WideString fred(L" FRED ");
+ fred.TrimLeft();
+ EXPECT_EQ(L"FRED ", fred);
+ fred.TrimLeft(L'E');
+ EXPECT_EQ(L"FRED ", fred);
+ fred.TrimLeft(L'F');
+ EXPECT_EQ(L"RED ", fred);
+ fred.TrimLeft(L"ERP");
+ EXPECT_EQ(L"D ", fred);
+
+ WideString blank(L" ");
+ blank.TrimLeft(L"ERP");
+ EXPECT_EQ(L" ", blank);
+ blank.TrimLeft(L'E');
+ EXPECT_EQ(L" ", blank);
+ blank.TrimLeft();
+ EXPECT_EQ(L"", blank);
+
+ WideString empty;
+ empty.TrimLeft(L"ERP");
+ EXPECT_EQ(L"", empty);
+ empty.TrimLeft(L'E');
+ EXPECT_EQ(L"", empty);
+ empty.TrimLeft();
+ EXPECT_EQ(L"", empty);
+}
+
+TEST(WideString, TrimLeftCopies) {
{
// With a single reference, no copy takes place.
WideString fred(L" FRED ");
const wchar_t* old_buffer = fred.c_str();
- fred.TrimRight();
- EXPECT_EQ(L" FRED", fred);
+ fred.TrimLeft();
+ EXPECT_EQ(L"FRED ", fred);
EXPECT_EQ(old_buffer, fred.c_str());
}
{
@@ -670,8 +704,8 @@ TEST(WideString, TrimRightCopies) {
WideString fred(L" FRED ");
WideString other_fred = fred;
const wchar_t* old_buffer = fred.c_str();
- fred.TrimRight();
- EXPECT_EQ(L" FRED", fred);
+ fred.TrimLeft();
+ EXPECT_EQ(L"FRED ", fred);
EXPECT_EQ(L" FRED ", other_fred);
EXPECT_NE(old_buffer, fred.c_str());
}
@@ -680,48 +714,48 @@ TEST(WideString, TrimRightCopies) {
WideString fred(L"FRED");
WideString other_fred = fred;
const wchar_t* old_buffer = fred.c_str();
- fred.TrimRight();
+ fred.TrimLeft();
EXPECT_EQ(L"FRED", fred);
EXPECT_EQ(L"FRED", other_fred);
EXPECT_EQ(old_buffer, fred.c_str());
}
}
-TEST(WideString, TrimLeft) {
+TEST(WideString, TrimRight) {
WideString fred(L" FRED ");
- fred.TrimLeft();
- EXPECT_EQ(L"FRED ", fred);
- fred.TrimLeft(L'E');
- EXPECT_EQ(L"FRED ", fred);
- fred.TrimLeft(L'F');
- EXPECT_EQ(L"RED ", fred);
- fred.TrimLeft(L"ERP");
- EXPECT_EQ(L"D ", fred);
+ fred.TrimRight();
+ EXPECT_EQ(L" FRED", fred);
+ fred.TrimRight(L'E');
+ EXPECT_EQ(L" FRED", fred);
+ fred.TrimRight(L'D');
+ EXPECT_EQ(L" FRE", fred);
+ fred.TrimRight(L"ERP");
+ EXPECT_EQ(L" F", fred);
WideString blank(L" ");
- blank.TrimLeft(L"ERP");
+ blank.TrimRight(L"ERP");
EXPECT_EQ(L" ", blank);
- blank.TrimLeft(L'E');
+ blank.TrimRight(L'E');
EXPECT_EQ(L" ", blank);
- blank.TrimLeft();
+ blank.TrimRight();
EXPECT_EQ(L"", blank);
WideString empty;
- empty.TrimLeft(L"ERP");
+ empty.TrimRight(L"ERP");
EXPECT_EQ(L"", empty);
- empty.TrimLeft(L'E');
+ empty.TrimRight(L'E');
EXPECT_EQ(L"", empty);
- empty.TrimLeft();
+ empty.TrimRight();
EXPECT_EQ(L"", empty);
}
-TEST(WideString, TrimLeftCopies) {
+TEST(WideString, TrimRightCopies) {
{
// With a single reference, no copy takes place.
WideString fred(L" FRED ");
const wchar_t* old_buffer = fred.c_str();
- fred.TrimLeft();
- EXPECT_EQ(L"FRED ", fred);
+ fred.TrimRight();
+ EXPECT_EQ(L" FRED", fred);
EXPECT_EQ(old_buffer, fred.c_str());
}
{
@@ -729,8 +763,8 @@ TEST(WideString, TrimLeftCopies) {
WideString fred(L" FRED ");
WideString other_fred = fred;
const wchar_t* old_buffer = fred.c_str();
- fred.TrimLeft();
- EXPECT_EQ(L"FRED ", fred);
+ fred.TrimRight();
+ EXPECT_EQ(L" FRED", fred);
EXPECT_EQ(L" FRED ", other_fred);
EXPECT_NE(old_buffer, fred.c_str());
}
@@ -739,7 +773,7 @@ TEST(WideString, TrimLeftCopies) {
WideString fred(L"FRED");
WideString other_fred = fred;
const wchar_t* old_buffer = fred.c_str();
- fred.TrimLeft();
+ fred.TrimRight();
EXPECT_EQ(L"FRED", fred);
EXPECT_EQ(L"FRED", other_fred);
EXPECT_EQ(old_buffer, fred.c_str());
@@ -894,7 +928,7 @@ TEST(WideString, UTF16LE_Encode) {
struct UTF16LEEncodeCase {
WideString ws;
ByteString bs;
- } utf16le_encode_cases[] = {
+ } const utf16le_encode_cases[] = {
{L"", ByteString("\0\0", 2)},
{L"abc", ByteString("a\0b\0c\0\0\0", 8)},
{L"abcdef", ByteString("a\0b\0c\0d\0e\0f\0\0\0", 14)},
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
index bc6c7dbe13..2c13b92d4e 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -853,20 +853,17 @@ bool CPDFXFA_DocEnvironment::MailToInfo(WideString& csURL,
tmp = srcURL.Left(pos.value());
tmp = tmp.Right(tmp.GetLength() - 7);
}
- tmp.TrimLeft();
- tmp.TrimRight();
+ tmp.Trim();
csToAddress = tmp;
srcURL = srcURL.Right(srcURL.GetLength() - (pos.value() + 1));
while (!srcURL.IsEmpty()) {
- srcURL.TrimLeft();
- srcURL.TrimRight();
+ srcURL.Trim();
pos = srcURL.Find(L'&');
tmp = (!pos.has_value()) ? srcURL : srcURL.Left(pos.value());
- tmp.TrimLeft();
- tmp.TrimRight();
+ tmp.Trim();
if (tmp.GetLength() >= 3 && tmp.Left(3).CompareNoCase(L"cc=") == 0) {
tmp = tmp.Right(tmp.GetLength() - 3);
if (!csCCAddress.IsEmpty())
@@ -922,8 +919,7 @@ bool CPDFXFA_DocEnvironment::SubmitDataInternal(CXFA_FFDoc* hDoc,
case XFA_ATTRIBUTEENUM_Xdp: {
WideString csContent;
submitData.GetSubmitXDPContent(csContent);
- csContent.TrimLeft();
- csContent.TrimRight();
+ csContent.Trim();
WideString space;
space.FromLocal(" ");
csContent = space + csContent + space;
diff --git a/fxjs/cfxjse_formcalc_context.cpp b/fxjs/cfxjse_formcalc_context.cpp
index f3c4ebe462..d34493a7b2 100644
--- a/fxjs/cfxjse_formcalc_context.cpp
+++ b/fxjs/cfxjse_formcalc_context.cpp
@@ -534,8 +534,7 @@ ByteString GUIDString(bool bSeparator) {
double ByteStringToDouble(const ByteStringView& szStringVal) {
WideString wsValue = WideString::FromUTF8(szStringVal);
- wsValue.TrimLeft();
- wsValue.TrimRight();
+ wsValue.Trim();
int32_t cc = 0;
bool bNegative = false;
diff --git a/fxjs/cfxjse_resolveprocessor.cpp b/fxjs/cfxjse_resolveprocessor.cpp
index 7802957c7c..ef7ddc10fb 100644
--- a/fxjs/cfxjse_resolveprocessor.cpp
+++ b/fxjs/cfxjse_resolveprocessor.cpp
@@ -582,11 +582,9 @@ int32_t CFXJSE_ResolveProcessor::GetFilter(const WideStringView& wsExpression,
return -1;
wsName.ReleaseBuffer(nNameCount);
- wsName.TrimLeft();
- wsName.TrimRight();
+ wsName.Trim();
wsCondition.ReleaseBuffer(nConditionCount);
- wsCondition.TrimLeft();
- wsCondition.TrimRight();
+ wsCondition.Trim();
rnd.m_uHashName =
static_cast<XFA_HashCode>(FX_HashCode_GetW(wsName.AsStringView(), false));
return nStart;
@@ -700,8 +698,7 @@ void CFXJSE_ResolveProcessor::FilterCondition(CFXJSE_ResolveNodeData& rnd,
}
}
int32_t iFoundCount = pdfium::CollectionSize<int32_t>(rnd.m_Objects);
- wsCondition.TrimLeft();
- wsCondition.TrimRight();
+ wsCondition.Trim();
int32_t iLen = wsCondition.GetLength();
if (!iLen) {
if (rnd.m_dwStyles & XFA_RESOLVENODE_ALL) {
diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp
index 862055a7ff..4885d68e1b 100644
--- a/fxjs/cjs_document.cpp
+++ b/fxjs/cjs_document.cpp
@@ -1264,10 +1264,8 @@ CJS_Return Document::getPageNthWord(
}
}
- if (bStrip) {
- swRet.TrimLeft();
- swRet.TrimRight();
- }
+ if (bStrip)
+ swRet.Trim();
return CJS_Return(pRuntime->NewString(swRet.c_str()));
}
diff --git a/fxjs/cjs_globaldata.cpp b/fxjs/cjs_globaldata.cpp
index 3f962734db..a78bce55c3 100644
--- a/fxjs/cjs_globaldata.cpp
+++ b/fxjs/cjs_globaldata.cpp
@@ -33,8 +33,7 @@ const uint8_t JS_RC4KEY[] = {
// Returns true if non-empty, setting sPropName
bool TrimPropName(ByteString* sPropName) {
- sPropName->TrimLeft();
- sPropName->TrimRight();
+ sPropName->Trim();
return sPropName->GetLength() != 0;
}
diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp
index 7220693813..eaa16c9fe1 100644
--- a/fxjs/cjs_publicmethods.cpp
+++ b/fxjs/cjs_publicmethods.cpp
@@ -73,8 +73,7 @@ const wchar_t* const kFullMonths[] = {L"January", L"February", L"March",
template <typename T>
T StrTrim(const T& str) {
T result = str;
- result.TrimLeft(' ');
- result.TrimRight(' ');
+ result.Trim(' ');
return result;
}
diff --git a/fxjs/cjx_hostpseudomodel.cpp b/fxjs/cjx_hostpseudomodel.cpp
index 090f23f7cd..35ab2f88c9 100644
--- a/fxjs/cjx_hostpseudomodel.cpp
+++ b/fxjs/cjx_hostpseudomodel.cpp
@@ -43,8 +43,7 @@ int32_t FilterName(const WideStringView& wsExpression,
pBuf[nCount++] = wCur;
}
wsFilter.ReleaseBuffer(nCount);
- wsFilter.TrimLeft();
- wsFilter.TrimRight();
+ wsFilter.Trim();
return nStart;
}
diff --git a/xfa/fxfa/cxfa_textlayout.cpp b/xfa/fxfa/cxfa_textlayout.cpp
index 93c1beebf7..7ff86bafeb 100644
--- a/xfa/fxfa/cxfa_textlayout.cpp
+++ b/xfa/fxfa/cxfa_textlayout.cpp
@@ -775,7 +775,7 @@ bool CXFA_TextLayout::LoadRichText(
if (m_pLoader) {
if (wsText.GetLength() > 0 &&
(m_pLoader->m_dwFlags & XFA_LOADERCNTXTFLG_FILTERSPACE)) {
- wsText.TrimLeft(0x20);
+ wsText.TrimLeft(L" ");
}
if (CFX_CSSDisplay::Block == eDisplay) {
m_pLoader->m_dwFlags |= XFA_LOADERCNTXTFLG_FILTERSPACE;
diff --git a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
index 2752b35718..c717aff259 100644
--- a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
+++ b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
@@ -142,8 +142,7 @@ CXFA_Node* ResolveBreakTarget(CXFA_Node* pPageSetRoot,
if (wsTargetAll.IsEmpty())
return nullptr;
- wsTargetAll.TrimLeft();
- wsTargetAll.TrimRight();
+ wsTargetAll.Trim();
int32_t iSplitIndex = 0;
bool bTargetAllFind = true;
while (iSplitIndex != -1) {
@@ -383,7 +382,8 @@ bool CXFA_LayoutPageMgr::PrepareFirstPage(CXFA_Node* pRootSubform) {
pRootSubform->GetNextSameClassSibling(XFA_Element::Subform);
}
}
- CXFA_Node *pLeader, *pTrailer;
+ CXFA_Node* pLeader;
+ CXFA_Node* pTrailer;
if (pBreakBeforeNode &&
ExecuteBreakBeforeOrAfter(pBreakBeforeNode, true, pLeader, pTrailer)) {
m_CurrentContainerRecordIter = m_ProposedContainerRecords.begin();