summaryrefslogtreecommitdiff
path: root/core/fxcrt
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcrt')
-rw-r--r--core/fxcrt/bytestring.cpp139
-rw-r--r--core/fxcrt/bytestring.h65
-rw-r--r--core/fxcrt/bytestring_unittest.cpp8
-rw-r--r--core/fxcrt/cfx_binarybuf.cpp22
-rw-r--r--core/fxcrt/cfx_binarybuf.h22
-rw-r--r--core/fxcrt/cfx_seekablestreamproxy.cpp45
-rw-r--r--core/fxcrt/cfx_seekablestreamproxy.h10
-rw-r--r--core/fxcrt/cfx_widetextbuf.cpp10
-rw-r--r--core/fxcrt/cfx_widetextbuf.h2
-rw-r--r--core/fxcrt/fx_safe_types.h2
-rw-r--r--core/fxcrt/fx_string.cpp10
-rw-r--r--core/fxcrt/fx_string.h2
-rw-r--r--core/fxcrt/fx_system.h16
-rw-r--r--core/fxcrt/string_data_template.h26
-rw-r--r--core/fxcrt/string_view_template.h36
-rw-r--r--core/fxcrt/widestring.cpp152
-rw-r--r--core/fxcrt/widestring.h66
-rw-r--r--core/fxcrt/widestring_unittest.cpp4
-rw-r--r--core/fxcrt/xml/cfx_xmlsyntaxparser.cpp2
-rw-r--r--core/fxcrt/xml/cfx_xmlsyntaxparser.h4
20 files changed, 313 insertions, 330 deletions
diff --git a/core/fxcrt/bytestring.cpp b/core/fxcrt/bytestring.cpp
index aa1fb57775..bd195dda1d 100644
--- a/core/fxcrt/bytestring.cpp
+++ b/core/fxcrt/bytestring.cpp
@@ -91,12 +91,12 @@ namespace fxcrt {
static_assert(sizeof(ByteString) <= sizeof(char*),
"Strings must not require more space than pointers");
-ByteString::ByteString(const char* pStr, FX_STRSIZE nLen) {
+ByteString::ByteString(const char* pStr, size_t nLen) {
if (nLen)
m_pData.Reset(StringData::Create(pStr, nLen));
}
-ByteString::ByteString(const uint8_t* pStr, FX_STRSIZE nLen) {
+ByteString::ByteString(const uint8_t* pStr, size_t nLen) {
if (nLen)
m_pData.Reset(
StringData::Create(reinterpret_cast<const char*>(pStr), nLen));
@@ -128,7 +128,7 @@ ByteString::ByteString(const ByteStringView& str1, const ByteStringView& str2) {
FX_SAFE_STRSIZE nSafeLen = str1.GetLength();
nSafeLen += str2.GetLength();
- FX_STRSIZE nNewLen = nSafeLen.ValueOrDie();
+ size_t nNewLen = nSafeLen.ValueOrDie();
if (nNewLen == 0)
return;
@@ -143,13 +143,13 @@ ByteString::ByteString(const std::initializer_list<ByteStringView>& list) {
for (const auto& item : list)
nSafeLen += item.GetLength();
- FX_STRSIZE nNewLen = nSafeLen.ValueOrDie();
+ size_t nNewLen = nSafeLen.ValueOrDie();
if (nNewLen == 0)
return;
m_pData.Reset(StringData::Create(nNewLen));
- FX_STRSIZE nOffset = 0;
+ size_t nOffset = 0;
for (const auto& item : list) {
m_pData->CopyContentsAt(nOffset, item.unterminated_c_str(),
item.GetLength());
@@ -264,13 +264,13 @@ bool ByteString::EqualNoCase(const ByteStringView& str) const {
if (!m_pData)
return str.IsEmpty();
- FX_STRSIZE len = str.GetLength();
+ size_t len = str.GetLength();
if (m_pData->m_nDataLength != len)
return false;
const uint8_t* pThis = (const uint8_t*)m_pData->m_String;
const uint8_t* pThat = str.raw_str();
- for (FX_STRSIZE i = 0; i < len; i++) {
+ for (size_t i = 0; i < len; i++) {
if ((*pThis) != (*pThat)) {
uint8_t bThis = FXSYS_tolower(*pThis);
uint8_t bThat = FXSYS_tolower(*pThat);
@@ -283,13 +283,13 @@ bool ByteString::EqualNoCase(const ByteStringView& str) const {
return true;
}
-void ByteString::AssignCopy(const char* pSrcData, FX_STRSIZE nSrcLen) {
+void ByteString::AssignCopy(const char* pSrcData, size_t nSrcLen) {
AllocBeforeWrite(nSrcLen);
m_pData->CopyContents(pSrcData, nSrcLen);
m_pData->m_nDataLength = nSrcLen;
}
-void ByteString::ReallocBeforeWrite(FX_STRSIZE nNewLength) {
+void ByteString::ReallocBeforeWrite(size_t nNewLength) {
if (m_pData && m_pData->CanOperateInPlace(nNewLength))
return;
@@ -300,7 +300,7 @@ void ByteString::ReallocBeforeWrite(FX_STRSIZE nNewLength) {
RetainPtr<StringData> pNewData(StringData::Create(nNewLength));
if (m_pData) {
- FX_STRSIZE nCopyLength = std::min(m_pData->m_nDataLength, nNewLength);
+ size_t nCopyLength = std::min(m_pData->m_nDataLength, nNewLength);
pNewData->CopyContents(m_pData->m_String, nCopyLength);
pNewData->m_nDataLength = nCopyLength;
} else {
@@ -310,7 +310,7 @@ void ByteString::ReallocBeforeWrite(FX_STRSIZE nNewLength) {
m_pData.Swap(pNewData);
}
-void ByteString::AllocBeforeWrite(FX_STRSIZE nNewLength) {
+void ByteString::AllocBeforeWrite(size_t nNewLength) {
if (m_pData && m_pData->CanOperateInPlace(nNewLength))
return;
@@ -322,7 +322,7 @@ void ByteString::AllocBeforeWrite(FX_STRSIZE nNewLength) {
m_pData.Reset(StringData::Create(nNewLength));
}
-void ByteString::ReleaseBuffer(FX_STRSIZE nNewLength) {
+void ByteString::ReleaseBuffer(size_t nNewLength) {
if (!m_pData)
return;
@@ -343,11 +343,11 @@ void ByteString::ReleaseBuffer(FX_STRSIZE nNewLength) {
}
}
-void ByteString::Reserve(FX_STRSIZE len) {
+void ByteString::Reserve(size_t len) {
GetBuffer(len);
}
-char* ByteString::GetBuffer(FX_STRSIZE nMinBufLength) {
+char* ByteString::GetBuffer(size_t nMinBufLength) {
if (!m_pData) {
if (nMinBufLength == 0)
return nullptr;
@@ -372,28 +372,28 @@ char* ByteString::GetBuffer(FX_STRSIZE nMinBufLength) {
return m_pData->m_String;
}
-FX_STRSIZE ByteString::Delete(FX_STRSIZE index, FX_STRSIZE count) {
+size_t ByteString::Delete(size_t index, size_t count) {
if (!m_pData)
return 0;
- FX_STRSIZE old_length = m_pData->m_nDataLength;
+ size_t old_length = m_pData->m_nDataLength;
if (count == 0 ||
- index != pdfium::clamp(index, static_cast<FX_STRSIZE>(0), old_length))
+ index != pdfium::clamp(index, static_cast<size_t>(0), old_length))
return old_length;
- FX_STRSIZE removal_length = index + count;
+ size_t removal_length = index + count;
if (removal_length > old_length)
return old_length;
ReallocBeforeWrite(old_length);
- FX_STRSIZE chars_to_copy = old_length - removal_length + 1;
+ size_t chars_to_copy = old_length - removal_length + 1;
memmove(m_pData->m_String + index, m_pData->m_String + removal_length,
chars_to_copy);
m_pData->m_nDataLength = old_length - count;
return m_pData->m_nDataLength;
}
-void ByteString::Concat(const char* pSrcData, FX_STRSIZE nSrcLen) {
+void ByteString::Concat(const char* pSrcData, size_t nSrcLen) {
if (!pSrcData || nSrcLen == 0)
return;
@@ -415,7 +415,7 @@ void ByteString::Concat(const char* pSrcData, FX_STRSIZE nSrcLen) {
m_pData.Swap(pNewData);
}
-ByteString ByteString::Mid(FX_STRSIZE first, FX_STRSIZE count) const {
+ByteString ByteString::Mid(size_t first, size_t count) const {
if (!m_pData)
return ByteString();
@@ -436,21 +436,21 @@ ByteString ByteString::Mid(FX_STRSIZE first, FX_STRSIZE count) const {
return dest;
}
-ByteString ByteString::Left(FX_STRSIZE count) const {
+ByteString ByteString::Left(size_t count) const {
if (count == 0 || !IsValidLength(count))
return ByteString();
return Mid(0, count);
}
-ByteString ByteString::Right(FX_STRSIZE count) const {
+ByteString ByteString::Right(size_t count) const {
if (count == 0 || !IsValidLength(count))
return ByteString();
return Mid(GetLength() - count, count);
}
void ByteString::AllocCopy(ByteString& dest,
- FX_STRSIZE nCopyLen,
- FX_STRSIZE nCopyIndex) const {
+ size_t nCopyLen,
+ size_t nCopyIndex) const {
if (nCopyLen == 0)
return;
@@ -472,7 +472,7 @@ ByteString ByteString::FormatInteger(int i) {
void ByteString::FormatV(const char* pFormat, va_list argList) {
va_list argListCopy;
va_copy(argListCopy, argList);
- FX_STRSIZE nMaxLen = vsnprintf(nullptr, 0, pFormat, argListCopy);
+ int nMaxLen = vsnprintf(nullptr, 0, pFormat, argListCopy);
va_end(argListCopy);
if (nMaxLen > 0) {
GetBuffer(nMaxLen);
@@ -495,18 +495,18 @@ void ByteString::Format(const char* pFormat, ...) {
va_end(argList);
}
-void ByteString::SetAt(FX_STRSIZE index, char c) {
+void ByteString::SetAt(size_t index, char c) {
ASSERT(IsValidIndex(index));
ReallocBeforeWrite(m_pData->m_nDataLength);
m_pData->m_String[index] = c;
}
-FX_STRSIZE ByteString::Insert(FX_STRSIZE location, char ch) {
- const FX_STRSIZE cur_length = m_pData ? m_pData->m_nDataLength : 0;
+size_t ByteString::Insert(size_t location, char ch) {
+ const size_t cur_length = m_pData ? m_pData->m_nDataLength : 0;
if (!IsValidLength(location))
return cur_length;
- const FX_STRSIZE new_length = cur_length + 1;
+ const size_t new_length = cur_length + 1;
ReallocBeforeWrite(new_length);
memmove(m_pData->m_String + location + 1, m_pData->m_String + location,
new_length - location);
@@ -515,46 +515,46 @@ FX_STRSIZE ByteString::Insert(FX_STRSIZE location, char ch) {
return new_length;
}
-pdfium::Optional<FX_STRSIZE> ByteString::Find(char ch, FX_STRSIZE start) const {
+pdfium::Optional<size_t> ByteString::Find(char ch, size_t start) const {
if (!m_pData)
- return pdfium::Optional<FX_STRSIZE>();
+ return pdfium::Optional<size_t>();
if (!IsValidIndex(start))
- return pdfium::Optional<FX_STRSIZE>();
+ return pdfium::Optional<size_t>();
const char* pStr = static_cast<const char*>(
memchr(m_pData->m_String + start, ch, m_pData->m_nDataLength - start));
- return pStr ? pdfium::Optional<FX_STRSIZE>(
- static_cast<FX_STRSIZE>(pStr - m_pData->m_String))
- : pdfium::Optional<FX_STRSIZE>();
+ return pStr ? pdfium::Optional<size_t>(
+ static_cast<size_t>(pStr - m_pData->m_String))
+ : pdfium::Optional<size_t>();
}
-pdfium::Optional<FX_STRSIZE> ByteString::Find(const ByteStringView& subStr,
- FX_STRSIZE start) const {
+pdfium::Optional<size_t> ByteString::Find(const ByteStringView& subStr,
+ size_t start) const {
if (!m_pData)
- return pdfium::Optional<FX_STRSIZE>();
+ return pdfium::Optional<size_t>();
if (!IsValidIndex(start))
- return pdfium::Optional<FX_STRSIZE>();
+ return pdfium::Optional<size_t>();
const char* pStr =
FX_strstr(m_pData->m_String + start, m_pData->m_nDataLength - start,
subStr.unterminated_c_str(), subStr.GetLength());
- return pStr ? pdfium::Optional<FX_STRSIZE>(
- static_cast<FX_STRSIZE>(pStr - m_pData->m_String))
- : pdfium::Optional<FX_STRSIZE>();
+ return pStr ? pdfium::Optional<size_t>(
+ static_cast<size_t>(pStr - m_pData->m_String))
+ : pdfium::Optional<size_t>();
}
-pdfium::Optional<FX_STRSIZE> ByteString::ReverseFind(char ch) const {
+pdfium::Optional<size_t> ByteString::ReverseFind(char ch) const {
if (!m_pData)
- return pdfium::Optional<FX_STRSIZE>();
+ return pdfium::Optional<size_t>();
- FX_STRSIZE nLength = m_pData->m_nDataLength;
+ size_t nLength = m_pData->m_nDataLength;
while (nLength--) {
if (m_pData->m_String[nLength] == ch)
- return pdfium::Optional<FX_STRSIZE>(nLength);
+ return pdfium::Optional<size_t>(nLength);
}
- return pdfium::Optional<FX_STRSIZE>();
+ return pdfium::Optional<size_t>();
}
void ByteString::MakeLower() {
@@ -573,7 +573,7 @@ void ByteString::MakeUpper() {
FXSYS_strupr(m_pData->m_String);
}
-FX_STRSIZE ByteString::Remove(char chRemove) {
+size_t ByteString::Remove(char chRemove) {
if (!m_pData || m_pData->m_nDataLength < 1)
return 0;
@@ -602,19 +602,19 @@ FX_STRSIZE ByteString::Remove(char chRemove) {
}
*pstrDest = 0;
- FX_STRSIZE nCount = static_cast<FX_STRSIZE>(pstrSource - pstrDest);
+ size_t nCount = static_cast<size_t>(pstrSource - pstrDest);
m_pData->m_nDataLength -= nCount;
return nCount;
}
-FX_STRSIZE ByteString::Replace(const ByteStringView& pOld,
- const ByteStringView& pNew) {
+size_t ByteString::Replace(const ByteStringView& pOld,
+ const ByteStringView& pNew) {
if (!m_pData || pOld.IsEmpty())
return 0;
- FX_STRSIZE nSourceLen = pOld.GetLength();
- FX_STRSIZE nReplacementLen = pNew.GetLength();
- FX_STRSIZE nCount = 0;
+ size_t nSourceLen = pOld.GetLength();
+ size_t nReplacementLen = pNew.GetLength();
+ size_t nCount = 0;
const char* pStart = m_pData->m_String;
char* pEnd = m_pData->m_String + m_pData->m_nDataLength;
while (1) {
@@ -629,7 +629,7 @@ FX_STRSIZE ByteString::Replace(const ByteStringView& pOld,
if (nCount == 0)
return 0;
- FX_STRSIZE nNewLength =
+ size_t nNewLength =
m_pData->m_nDataLength + (nReplacementLen - nSourceLen) * nCount;
if (nNewLength == 0) {
@@ -640,7 +640,7 @@ FX_STRSIZE ByteString::Replace(const ByteStringView& pOld,
RetainPtr<StringData> pNewData(StringData::Create(nNewLength));
pStart = m_pData->m_String;
char* pDest = pNewData->m_String;
- for (FX_STRSIZE i = 0; i < nCount; i++) {
+ for (size_t i = 0; i < nCount; i++) {
const char* pTarget = FX_strstr(pStart, static_cast<int>(pEnd - pStart),
pOld.unterminated_c_str(), nSourceLen);
memcpy(pDest, pStart, pTarget - pStart);
@@ -656,7 +656,7 @@ FX_STRSIZE ByteString::Replace(const ByteStringView& pOld,
WideString ByteString::UTF8Decode() const {
CFX_UTF8Decoder decoder;
- for (FX_STRSIZE i = 0; i < GetLength(); i++) {
+ for (size_t i = 0; i < GetLength(); i++) {
decoder.Input(static_cast<uint8_t>(m_pData->m_String[i]));
}
return WideString(decoder.GetResult());
@@ -671,10 +671,10 @@ int ByteString::Compare(const ByteStringView& str) const {
if (!m_pData) {
return str.IsEmpty() ? 0 : -1;
}
- FX_STRSIZE this_len = m_pData->m_nDataLength;
- FX_STRSIZE that_len = str.GetLength();
- FX_STRSIZE min_len = std::min(this_len, that_len);
- for (FX_STRSIZE i = 0; i < min_len; i++) {
+ size_t this_len = m_pData->m_nDataLength;
+ size_t that_len = str.GetLength();
+ size_t min_len = std::min(this_len, that_len);
+ for (size_t i = 0; i < min_len; i++) {
if (static_cast<uint8_t>(m_pData->m_String[i]) < str[i]) {
return -1;
}
@@ -695,12 +695,12 @@ void ByteString::TrimRight(const ByteStringView& pTargets) {
if (!m_pData || pTargets.IsEmpty())
return;
- FX_STRSIZE pos = GetLength();
+ size_t pos = GetLength();
if (pos == 0)
return;
while (pos) {
- FX_STRSIZE i = 0;
+ size_t i = 0;
while (i < pTargets.GetLength() &&
pTargets[i] != m_pData->m_String[pos - 1]) {
i++;
@@ -729,13 +729,13 @@ void ByteString::TrimLeft(const ByteStringView& pTargets) {
if (!m_pData || pTargets.IsEmpty())
return;
- FX_STRSIZE len = GetLength();
+ size_t len = GetLength();
if (len == 0)
return;
- FX_STRSIZE pos = 0;
+ size_t pos = 0;
while (pos < len) {
- FX_STRSIZE i = 0;
+ size_t i = 0;
while (i < pTargets.GetLength() && pTargets[i] != m_pData->m_String[pos]) {
i++;
}
@@ -746,7 +746,7 @@ void ByteString::TrimLeft(const ByteStringView& pTargets) {
}
if (pos) {
ReallocBeforeWrite(len);
- FX_STRSIZE nDataLength = len - pos;
+ size_t nDataLength = len - pos;
memmove(m_pData->m_String, m_pData->m_String + pos,
(nDataLength + 1) * sizeof(char));
m_pData->m_nDataLength = nDataLength;
@@ -763,8 +763,7 @@ void ByteString::TrimLeft() {
ByteString ByteString::FormatFloat(float d, int precision) {
char buf[32];
- FX_STRSIZE len = FX_ftoa(d, buf);
- return ByteString(buf, len);
+ return ByteString(buf, FX_ftoa(d, buf));
}
std::ostream& operator<<(std::ostream& os, const ByteString& str) {
diff --git a/core/fxcrt/bytestring.h b/core/fxcrt/bytestring.h
index eba9744402..2b01bc19aa 100644
--- a/core/fxcrt/bytestring.h
+++ b/core/fxcrt/bytestring.h
@@ -46,8 +46,8 @@ class ByteString {
// NOLINTNEXTLINE(runtime/explicit)
ByteString(wchar_t) = delete;
- ByteString(const char* ptr, FX_STRSIZE len);
- ByteString(const uint8_t* ptr, FX_STRSIZE len);
+ ByteString(const char* ptr, size_t len);
+ ByteString(const uint8_t* ptr, size_t len);
explicit ByteString(const ByteStringView& bstrc);
ByteString(const ByteStringView& bstrc1, const ByteStringView& bstrc2);
@@ -91,13 +91,13 @@ class ByteString {
return const_reverse_iterator(begin());
}
- FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; }
- FX_STRSIZE GetStringLength() const {
+ size_t GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; }
+ size_t GetStringLength() const {
return m_pData ? FXSYS_strlen(m_pData->m_String) : 0;
}
bool IsEmpty() const { return !GetLength(); }
- bool IsValidIndex(FX_STRSIZE index) const { return index < GetLength(); }
- bool IsValidLength(FX_STRSIZE length) const { return length <= GetLength(); }
+ bool IsValidIndex(size_t index) const { return index < GetLength(); }
+ bool IsValidLength(size_t length) const { return length <= GetLength(); }
int Compare(const ByteStringView& str) const;
bool EqualNoCase(const ByteStringView& str) const;
@@ -121,7 +121,7 @@ class ByteString {
const ByteString& operator+=(const ByteString& str);
const ByteString& operator+=(const ByteStringView& bstrc);
- CharType operator[](const FX_STRSIZE index) const {
+ CharType operator[](const size_t index) const {
ASSERT(IsValidIndex(index));
return m_pData ? m_pData->m_String[index] : 0;
}
@@ -129,34 +129,34 @@ class ByteString {
CharType First() const { return GetLength() ? (*this)[0] : 0; }
CharType Last() const { return GetLength() ? (*this)[GetLength() - 1] : 0; }
- void SetAt(FX_STRSIZE index, char c);
+ void SetAt(size_t index, char c);
- FX_STRSIZE Insert(FX_STRSIZE index, char ch);
- FX_STRSIZE InsertAtFront(char ch) { return Insert(0, ch); }
- FX_STRSIZE InsertAtBack(char ch) { return Insert(GetLength(), ch); }
- FX_STRSIZE Delete(FX_STRSIZE index, FX_STRSIZE count = 1);
+ size_t Insert(size_t index, char ch);
+ size_t InsertAtFront(char ch) { return Insert(0, ch); }
+ size_t InsertAtBack(char ch) { return Insert(GetLength(), ch); }
+ size_t Delete(size_t index, size_t count = 1);
void Format(const char* lpszFormat, ...);
void FormatV(const char* lpszFormat, va_list argList);
- void Reserve(FX_STRSIZE len);
- char* GetBuffer(FX_STRSIZE len);
- void ReleaseBuffer(FX_STRSIZE len);
+ void Reserve(size_t len);
+ char* GetBuffer(size_t len);
+ void ReleaseBuffer(size_t len);
- ByteString Mid(FX_STRSIZE first, FX_STRSIZE count) const;
- ByteString Left(FX_STRSIZE count) const;
- ByteString Right(FX_STRSIZE count) const;
+ ByteString Mid(size_t first, size_t count) const;
+ ByteString Left(size_t count) const;
+ ByteString Right(size_t count) const;
- pdfium::Optional<FX_STRSIZE> Find(const ByteStringView& lpszSub,
- FX_STRSIZE start = 0) const;
- pdfium::Optional<FX_STRSIZE> Find(char ch, FX_STRSIZE start = 0) const;
- pdfium::Optional<FX_STRSIZE> ReverseFind(char ch) const;
+ pdfium::Optional<size_t> Find(const ByteStringView& lpszSub,
+ size_t start = 0) const;
+ pdfium::Optional<size_t> Find(char ch, size_t start = 0) const;
+ pdfium::Optional<size_t> ReverseFind(char ch) const;
- bool Contains(const ByteStringView& lpszSub, FX_STRSIZE start = 0) const {
+ bool Contains(const ByteStringView& lpszSub, size_t start = 0) const {
return Find(lpszSub, start).has_value();
}
- bool Contains(char ch, FX_STRSIZE start = 0) const {
+ bool Contains(char ch, size_t start = 0) const {
return Find(ch, start).has_value();
}
@@ -171,10 +171,9 @@ class ByteString {
void TrimLeft(char chTarget);
void TrimLeft(const ByteStringView& lpszTargets);
- FX_STRSIZE Replace(const ByteStringView& lpszOld,
- const ByteStringView& lpszNew);
+ size_t Replace(const ByteStringView& lpszOld, const ByteStringView& lpszNew);
- FX_STRSIZE Remove(char ch);
+ size_t Remove(char ch);
WideString UTF8Decode() const;
@@ -186,13 +185,11 @@ class ByteString {
protected:
using StringData = StringDataTemplate<char>;
- void ReallocBeforeWrite(FX_STRSIZE nNewLen);
- void AllocBeforeWrite(FX_STRSIZE nNewLen);
- void AllocCopy(ByteString& dest,
- FX_STRSIZE nCopyLen,
- FX_STRSIZE nCopyIndex) const;
- void AssignCopy(const char* pSrcData, FX_STRSIZE nSrcLen);
- void Concat(const char* lpszSrcData, FX_STRSIZE nSrcLen);
+ void ReallocBeforeWrite(size_t nNewLen);
+ void AllocBeforeWrite(size_t nNewLen);
+ void AllocCopy(ByteString& dest, size_t nCopyLen, size_t nCopyIndex) const;
+ void AssignCopy(const char* pSrcData, size_t nSrcLen);
+ void Concat(const char* lpszSrcData, size_t nSrcLen);
RetainPtr<StringData> m_pData;
diff --git a/core/fxcrt/bytestring_unittest.cpp b/core/fxcrt/bytestring_unittest.cpp
index e1c832e114..d3597ad421 100644
--- a/core/fxcrt/bytestring_unittest.cpp
+++ b/core/fxcrt/bytestring_unittest.cpp
@@ -550,7 +550,7 @@ TEST(ByteString, Find) {
EXPECT_FALSE(empty_string.Find('a').has_value());
EXPECT_FALSE(empty_string.Find('\0').has_value());
- pdfium::Optional<FX_STRSIZE> result;
+ pdfium::Optional<size_t> result;
ByteString single_string("a");
result = single_string.Find('a');
ASSERT_TRUE(result.has_value());
@@ -599,7 +599,7 @@ TEST(ByteString, ReverseFind) {
EXPECT_FALSE(empty_string.ReverseFind('a').has_value());
EXPECT_FALSE(empty_string.ReverseFind('\0').has_value());
- pdfium::Optional<FX_STRSIZE> result;
+ pdfium::Optional<size_t> result;
ByteString single_string("a");
result = single_string.ReverseFind('a');
ASSERT_TRUE(result.has_value());
@@ -978,7 +978,7 @@ TEST(ByteStringView, FromVector) {
std::vector<uint8_t> lower_a_vec(10, static_cast<uint8_t>('a'));
ByteStringView lower_a_string(lower_a_vec);
- EXPECT_EQ(static_cast<FX_STRSIZE>(10), lower_a_string.GetLength());
+ EXPECT_EQ(static_cast<size_t>(10), lower_a_string.GetLength());
EXPECT_EQ("aaaaaaaaaa", lower_a_string);
std::vector<uint8_t> cleared_vec;
@@ -1012,7 +1012,7 @@ TEST(ByteStringView, Find) {
EXPECT_FALSE(empty_string.Find('a').has_value());
EXPECT_FALSE(empty_string.Find('\0').has_value());
- pdfium::Optional<FX_STRSIZE> result;
+ pdfium::Optional<size_t> result;
ByteStringView single_string("a");
result = single_string.Find('a');
ASSERT_TRUE(result.has_value());
diff --git a/core/fxcrt/cfx_binarybuf.cpp b/core/fxcrt/cfx_binarybuf.cpp
index b826fdd5b5..d1bd05385d 100644
--- a/core/fxcrt/cfx_binarybuf.cpp
+++ b/core/fxcrt/cfx_binarybuf.cpp
@@ -12,14 +12,14 @@
CFX_BinaryBuf::CFX_BinaryBuf()
: m_AllocStep(0), m_AllocSize(0), m_DataSize(0) {}
-CFX_BinaryBuf::CFX_BinaryBuf(FX_STRSIZE size)
+CFX_BinaryBuf::CFX_BinaryBuf(size_t size)
: m_AllocStep(0), m_AllocSize(size), m_DataSize(size) {
m_pBuffer.reset(FX_Alloc(uint8_t, size));
}
CFX_BinaryBuf::~CFX_BinaryBuf() {}
-void CFX_BinaryBuf::Delete(FX_STRSIZE start_index, FX_STRSIZE count) {
+void CFX_BinaryBuf::Delete(size_t start_index, size_t count) {
if (!m_pBuffer || count > m_DataSize || start_index > m_DataSize - count)
return;
@@ -28,7 +28,7 @@ void CFX_BinaryBuf::Delete(FX_STRSIZE start_index, FX_STRSIZE count) {
m_DataSize -= count;
}
-FX_STRSIZE CFX_BinaryBuf::GetLength() const {
+size_t CFX_BinaryBuf::GetLength() const {
return m_DataSize;
}
@@ -42,20 +42,20 @@ std::unique_ptr<uint8_t, FxFreeDeleter> CFX_BinaryBuf::DetachBuffer() {
return std::move(m_pBuffer);
}
-void CFX_BinaryBuf::EstimateSize(FX_STRSIZE size, FX_STRSIZE step) {
+void CFX_BinaryBuf::EstimateSize(size_t size, size_t step) {
m_AllocStep = step;
if (m_AllocSize < size)
ExpandBuf(size - m_DataSize);
}
-void CFX_BinaryBuf::ExpandBuf(FX_STRSIZE add_size) {
+void CFX_BinaryBuf::ExpandBuf(size_t add_size) {
FX_SAFE_STRSIZE new_size = m_DataSize;
new_size += add_size;
if (m_AllocSize >= new_size.ValueOrDie())
return;
- FX_STRSIZE alloc_step = std::max(static_cast<FX_STRSIZE>(128),
- m_AllocStep ? m_AllocStep : m_AllocSize / 4);
+ size_t alloc_step = std::max(static_cast<size_t>(128),
+ m_AllocStep ? m_AllocStep : m_AllocSize / 4);
new_size += alloc_step - 1; // Quantize, don't combine these lines.
new_size /= alloc_step;
new_size *= alloc_step;
@@ -65,8 +65,8 @@ void CFX_BinaryBuf::ExpandBuf(FX_STRSIZE add_size) {
: FX_Alloc(uint8_t, m_AllocSize));
}
-void CFX_BinaryBuf::AppendBlock(const void* pBuf, FX_STRSIZE size) {
- if (size <= 0)
+void CFX_BinaryBuf::AppendBlock(const void* pBuf, size_t size) {
+ if (size == 0)
return;
ExpandBuf(size);
@@ -78,9 +78,7 @@ void CFX_BinaryBuf::AppendBlock(const void* pBuf, FX_STRSIZE size) {
m_DataSize += size;
}
-void CFX_BinaryBuf::InsertBlock(FX_STRSIZE pos,
- const void* pBuf,
- FX_STRSIZE size) {
+void CFX_BinaryBuf::InsertBlock(size_t pos, const void* pBuf, size_t size) {
if (size <= 0)
return;
diff --git a/core/fxcrt/cfx_binarybuf.h b/core/fxcrt/cfx_binarybuf.h
index 186d8d1b88..1a1c821bb9 100644
--- a/core/fxcrt/cfx_binarybuf.h
+++ b/core/fxcrt/cfx_binarybuf.h
@@ -16,17 +16,17 @@
class CFX_BinaryBuf {
public:
CFX_BinaryBuf();
- explicit CFX_BinaryBuf(FX_STRSIZE size);
+ explicit CFX_BinaryBuf(size_t size);
virtual ~CFX_BinaryBuf();
uint8_t* GetBuffer() const { return m_pBuffer.get(); }
- FX_STRSIZE GetSize() const { return m_DataSize; }
- virtual FX_STRSIZE GetLength() const;
+ size_t GetSize() const { return m_DataSize; }
+ virtual size_t GetLength() const;
bool IsEmpty() const { return GetLength() == 0; }
void Clear();
- void EstimateSize(FX_STRSIZE size, FX_STRSIZE alloc_step = 0);
- void AppendBlock(const void* pBuf, FX_STRSIZE size);
+ void EstimateSize(size_t size, size_t alloc_step = 0);
+ void AppendBlock(const void* pBuf, size_t size);
void AppendString(const ByteString& str) {
AppendBlock(str.c_str(), str.GetLength());
}
@@ -36,18 +36,18 @@ class CFX_BinaryBuf {
m_pBuffer.get()[m_DataSize++] = byte;
}
- void InsertBlock(FX_STRSIZE pos, const void* pBuf, FX_STRSIZE size);
- void Delete(FX_STRSIZE start_index, FX_STRSIZE count);
+ void InsertBlock(size_t pos, const void* pBuf, size_t size);
+ void Delete(size_t start_index, size_t count);
// Releases ownership of |m_pBuffer| and returns it.
std::unique_ptr<uint8_t, FxFreeDeleter> DetachBuffer();
protected:
- void ExpandBuf(FX_STRSIZE size);
+ void ExpandBuf(size_t size);
- FX_STRSIZE m_AllocStep;
- FX_STRSIZE m_AllocSize;
- FX_STRSIZE m_DataSize;
+ size_t m_AllocStep;
+ size_t m_AllocSize;
+ size_t m_DataSize;
std::unique_ptr<uint8_t, FxFreeDeleter> m_pBuffer;
};
diff --git a/core/fxcrt/cfx_seekablestreamproxy.cpp b/core/fxcrt/cfx_seekablestreamproxy.cpp
index 3c0b5d5aef..f2590ecfd6 100644
--- a/core/fxcrt/cfx_seekablestreamproxy.cpp
+++ b/core/fxcrt/cfx_seekablestreamproxy.cpp
@@ -25,10 +25,10 @@
namespace {
// Returns {src bytes consumed, dst bytes produced}.
-std::pair<FX_STRSIZE, FX_STRSIZE> UTF8Decode(const char* pSrc,
- FX_STRSIZE srcLen,
- wchar_t* pDst,
- FX_STRSIZE dstLen) {
+std::pair<size_t, size_t> UTF8Decode(const char* pSrc,
+ size_t srcLen,
+ wchar_t* pDst,
+ size_t dstLen) {
ASSERT(pDst && dstLen > 0);
if (srcLen < 1)
@@ -36,9 +36,9 @@ std::pair<FX_STRSIZE, FX_STRSIZE> UTF8Decode(const char* pSrc,
uint32_t dwCode = 0;
int32_t iPending = 0;
- FX_STRSIZE iSrcNum = 0;
- FX_STRSIZE iDstNum = 0;
- FX_STRSIZE iIndex = 0;
+ size_t iSrcNum = 0;
+ size_t iDstNum = 0;
+ size_t iIndex = 0;
int32_t k = 1;
while (iIndex < srcLen) {
uint8_t byte = static_cast<uint8_t>(*(pSrc + iIndex));
@@ -91,18 +91,18 @@ std::pair<FX_STRSIZE, FX_STRSIZE> UTF8Decode(const char* pSrc,
return {iSrcNum, iDstNum};
}
-void UTF16ToWChar(void* pBuffer, FX_STRSIZE iLength) {
+void UTF16ToWChar(void* pBuffer, size_t iLength) {
ASSERT(pBuffer);
ASSERT(iLength > 0);
ASSERT(sizeof(wchar_t) > 2);
uint16_t* pSrc = static_cast<uint16_t*>(pBuffer);
wchar_t* pDst = static_cast<wchar_t*>(pBuffer);
- for (FX_STRSIZE i = 0; i < iLength; i++)
+ for (size_t i = 0; i < iLength; i++)
pDst[i] = static_cast<wchar_t>(pSrc[i]);
}
-void SwapByteOrder(wchar_t* pStr, FX_STRSIZE iLength) {
+void SwapByteOrder(wchar_t* pStr, size_t iLength) {
ASSERT(pStr);
uint16_t wch;
@@ -174,7 +174,7 @@ CFX_SeekableStreamProxy::CFX_SeekableStreamProxy(
Seek(From::Begin, static_cast<FX_FILESIZE>(m_wBOMLength));
}
-CFX_SeekableStreamProxy::CFX_SeekableStreamProxy(uint8_t* data, FX_STRSIZE size)
+CFX_SeekableStreamProxy::CFX_SeekableStreamProxy(uint8_t* data, size_t size)
: CFX_SeekableStreamProxy(
pdfium::MakeRetain<CFX_MemoryStream>(data, size, false),
false) {}
@@ -203,15 +203,14 @@ void CFX_SeekableStreamProxy::SetCodePage(uint16_t wCodePage) {
m_wCodePage = wCodePage;
}
-FX_STRSIZE CFX_SeekableStreamProxy::ReadData(uint8_t* pBuffer,
- FX_STRSIZE iBufferSize) {
+size_t CFX_SeekableStreamProxy::ReadData(uint8_t* pBuffer, size_t iBufferSize) {
ASSERT(pBuffer && iBufferSize > 0);
if (m_IsWriteStream)
return 0;
iBufferSize =
- std::min(iBufferSize, static_cast<FX_STRSIZE>(GetLength() - m_iPosition));
+ std::min(iBufferSize, static_cast<size_t>(GetLength() - m_iPosition));
if (iBufferSize <= 0)
return 0;
@@ -224,9 +223,9 @@ FX_STRSIZE CFX_SeekableStreamProxy::ReadData(uint8_t* pBuffer,
return new_pos.IsValid() ? iBufferSize : 0;
}
-FX_STRSIZE CFX_SeekableStreamProxy::ReadString(wchar_t* pStr,
- FX_STRSIZE iMaxLength,
- bool* bEOS) {
+size_t CFX_SeekableStreamProxy::ReadString(wchar_t* pStr,
+ size_t iMaxLength,
+ bool* bEOS) {
if (!pStr || iMaxLength == 0)
return 0;
@@ -235,8 +234,8 @@ FX_STRSIZE CFX_SeekableStreamProxy::ReadString(wchar_t* pStr,
if (m_wCodePage == FX_CODEPAGE_UTF16LE ||
m_wCodePage == FX_CODEPAGE_UTF16BE) {
- FX_STRSIZE iBytes = iMaxLength * 2;
- FX_STRSIZE iLen = ReadData(reinterpret_cast<uint8_t*>(pStr), iBytes);
+ size_t iBytes = iMaxLength * 2;
+ size_t iLen = ReadData(reinterpret_cast<uint8_t*>(pStr), iBytes);
iMaxLength = iLen / 2;
if (sizeof(wchar_t) > 2 && iMaxLength > 0)
UTF16ToWChar(pStr, iMaxLength);
@@ -246,17 +245,17 @@ FX_STRSIZE CFX_SeekableStreamProxy::ReadString(wchar_t* pStr,
} else {
FX_FILESIZE pos = GetPosition();
- FX_STRSIZE iBytes =
- std::min(iMaxLength, static_cast<FX_STRSIZE>(GetLength() - pos));
+ size_t iBytes =
+ std::min(iMaxLength, static_cast<size_t>(GetLength() - pos));
if (iBytes > 0) {
std::vector<uint8_t> buf(iBytes);
- FX_STRSIZE iLen = ReadData(buf.data(), iBytes);
+ size_t iLen = ReadData(buf.data(), iBytes);
if (m_wCodePage != FX_CODEPAGE_UTF8)
return 0;
- FX_STRSIZE iSrc = 0;
+ size_t iSrc = 0;
std::tie(iSrc, iMaxLength) = UTF8Decode(
reinterpret_cast<const char*>(buf.data()), iLen, pStr, iMaxLength);
Seek(From::Current, iSrc - iLen);
diff --git a/core/fxcrt/cfx_seekablestreamproxy.h b/core/fxcrt/cfx_seekablestreamproxy.h
index cadc96816d..c25ab3c9b6 100644
--- a/core/fxcrt/cfx_seekablestreamproxy.h
+++ b/core/fxcrt/cfx_seekablestreamproxy.h
@@ -25,11 +25,11 @@ class CFX_SeekableStreamProxy : public Retainable {
FX_FILESIZE GetLength() const { return m_pStream->GetSize(); }
FX_FILESIZE GetPosition() { return m_iPosition; }
- FX_STRSIZE GetBOMLength() const { return m_wBOMLength; }
+ size_t GetBOMLength() const { return m_wBOMLength; }
bool IsEOF() const { return m_iPosition >= GetLength(); }
void Seek(From eSeek, FX_FILESIZE iOffset);
- FX_STRSIZE ReadString(wchar_t* pStr, FX_STRSIZE iMaxLength, bool* bEOS);
+ size_t ReadString(wchar_t* pStr, size_t iMaxLength, bool* bEOS);
void WriteString(const WideStringView& str);
@@ -39,14 +39,14 @@ class CFX_SeekableStreamProxy : public Retainable {
private:
CFX_SeekableStreamProxy(const RetainPtr<IFX_SeekableStream>& stream,
bool isWriteSteam);
- CFX_SeekableStreamProxy(uint8_t* data, FX_STRSIZE size);
+ CFX_SeekableStreamProxy(uint8_t* data, size_t size);
~CFX_SeekableStreamProxy() override;
- FX_STRSIZE ReadData(uint8_t* pBuffer, FX_STRSIZE iBufferSize);
+ size_t ReadData(uint8_t* pBuffer, size_t iBufferSize);
bool m_IsWriteStream;
uint16_t m_wCodePage;
- FX_STRSIZE m_wBOMLength;
+ size_t m_wBOMLength;
FX_FILESIZE m_iPosition;
RetainPtr<IFX_SeekableStream> m_pStream;
};
diff --git a/core/fxcrt/cfx_widetextbuf.cpp b/core/fxcrt/cfx_widetextbuf.cpp
index d51e5ea314..08e4921560 100644
--- a/core/fxcrt/cfx_widetextbuf.cpp
+++ b/core/fxcrt/cfx_widetextbuf.cpp
@@ -6,7 +6,7 @@
#include "core/fxcrt/cfx_widetextbuf.h"
-FX_STRSIZE CFX_WideTextBuf::GetLength() const {
+size_t CFX_WideTextBuf::GetLength() const {
return m_DataSize / sizeof(wchar_t);
}
@@ -29,10 +29,10 @@ CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const WideString& str) {
CFX_WideTextBuf& CFX_WideTextBuf::operator<<(int i) {
char buf[32];
FXSYS_itoa(i, buf, 10);
- FX_STRSIZE len = FXSYS_strlen(buf);
+ size_t len = FXSYS_strlen(buf);
ExpandBuf(len * sizeof(wchar_t));
wchar_t* str = (wchar_t*)(m_pBuffer.get() + m_DataSize);
- for (FX_STRSIZE j = 0; j < len; j++) {
+ for (size_t j = 0; j < len; j++) {
*str++ = buf[j];
}
m_DataSize += len * sizeof(wchar_t);
@@ -41,10 +41,10 @@ CFX_WideTextBuf& CFX_WideTextBuf::operator<<(int i) {
CFX_WideTextBuf& CFX_WideTextBuf::operator<<(double f) {
char buf[32];
- FX_STRSIZE len = FX_ftoa((float)f, buf);
+ size_t len = FX_ftoa((float)f, buf);
ExpandBuf(len * sizeof(wchar_t));
wchar_t* str = (wchar_t*)(m_pBuffer.get() + m_DataSize);
- for (FX_STRSIZE i = 0; i < len; i++) {
+ for (size_t i = 0; i < len; i++) {
*str++ = buf[i];
}
m_DataSize += len * sizeof(wchar_t);
diff --git a/core/fxcrt/cfx_widetextbuf.h b/core/fxcrt/cfx_widetextbuf.h
index 77fe4141f9..84553a3e59 100644
--- a/core/fxcrt/cfx_widetextbuf.h
+++ b/core/fxcrt/cfx_widetextbuf.h
@@ -14,7 +14,7 @@
class CFX_WideTextBuf : public CFX_BinaryBuf {
public:
void AppendChar(wchar_t wch);
- FX_STRSIZE GetLength() const override;
+ size_t GetLength() const override;
wchar_t* GetBuffer() const {
return reinterpret_cast<wchar_t*>(m_pBuffer.get());
}
diff --git a/core/fxcrt/fx_safe_types.h b/core/fxcrt/fx_safe_types.h
index c7362b82f3..aae608096f 100644
--- a/core/fxcrt/fx_safe_types.h
+++ b/core/fxcrt/fx_safe_types.h
@@ -14,6 +14,6 @@ typedef pdfium::base::CheckedNumeric<uint32_t> FX_SAFE_UINT32;
typedef pdfium::base::CheckedNumeric<int32_t> FX_SAFE_INT32;
typedef pdfium::base::CheckedNumeric<size_t> FX_SAFE_SIZE_T;
typedef pdfium::base::CheckedNumeric<FX_FILESIZE> FX_SAFE_FILESIZE;
-typedef pdfium::base::CheckedNumeric<FX_STRSIZE> FX_SAFE_STRSIZE;
+typedef pdfium::base::CheckedNumeric<size_t> FX_SAFE_STRSIZE;
#endif // CORE_FXCRT_FX_SAFE_TYPES_H_
diff --git a/core/fxcrt/fx_string.cpp b/core/fxcrt/fx_string.cpp
index ce4e187837..233c5e64b7 100644
--- a/core/fxcrt/fx_string.cpp
+++ b/core/fxcrt/fx_string.cpp
@@ -62,7 +62,7 @@ class CFX_UTF8Encoder {
} // namespace
ByteString FX_UTF8Encode(const WideStringView& wsStr) {
- FX_STRSIZE len = wsStr.GetLength();
+ size_t len = wsStr.GetLength();
const wchar_t* pStr = wsStr.unterminated_c_str();
CFX_UTF8Encoder encoder;
while (len-- > 0)
@@ -99,7 +99,7 @@ bool FX_atonum(const ByteStringView& strc, void* pData) {
pdfium::base::CheckedNumeric<uint32_t> integer = 0;
bool bNegative = false;
bool bSigned = false;
- FX_STRSIZE cc = 0;
+ size_t cc = 0;
if (strc[0] == '+') {
cc++;
bSigned = true;
@@ -184,7 +184,7 @@ float FX_atof(const WideStringView& wsStr) {
return FX_atof(FX_UTF8Encode(wsStr).c_str());
}
-FX_STRSIZE FX_ftoa(float d, char* buf) {
+size_t FX_ftoa(float d, char* buf) {
buf[0] = '0';
buf[1] = '\0';
if (d == 0.0f) {
@@ -208,13 +208,13 @@ FX_STRSIZE FX_ftoa(float d, char* buf) {
return 1;
}
char buf2[32];
- FX_STRSIZE buf_size = 0;
+ size_t buf_size = 0;
if (bNegative) {
buf[buf_size++] = '-';
}
int i = scaled / scale;
FXSYS_itoa(i, buf2, 10);
- FX_STRSIZE len = FXSYS_strlen(buf2);
+ size_t len = FXSYS_strlen(buf2);
memcpy(buf + buf_size, buf2, len);
buf_size += len;
int fraction = scaled % scale;
diff --git a/core/fxcrt/fx_string.h b/core/fxcrt/fx_string.h
index 0481a15d34..4c24181e37 100644
--- a/core/fxcrt/fx_string.h
+++ b/core/fxcrt/fx_string.h
@@ -18,6 +18,6 @@ ByteString FX_UTF8Encode(const WideStringView& wsStr);
float FX_atof(const ByteStringView& str);
float FX_atof(const WideStringView& wsStr);
bool FX_atonum(const ByteStringView& str, void* pData);
-FX_STRSIZE FX_ftoa(float f, char* buf);
+size_t FX_ftoa(float f, char* buf);
#endif // CORE_FXCRT_FX_STRING_H_
diff --git a/core/fxcrt/fx_system.h b/core/fxcrt/fx_system.h
index 426dc085fc..2c84b02238 100644
--- a/core/fxcrt/fx_system.h
+++ b/core/fxcrt/fx_system.h
@@ -76,10 +76,6 @@ extern "C" {
#define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
#define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb))
-// Unsigned value used to represent a location or range in a string.
-// TODO(rharrison): Remove and use size_t directly once int->size_t stabilizes.
-typedef size_t FX_STRSIZE;
-
// PDFium file sizes match the platform, but PDFium itself does not support
// files larger than 2GB even if the platform does. The value must be signed
// to support -1 error returns.
@@ -120,15 +116,15 @@ typedef size_t FX_STRSIZE;
#include "third_party/base/numerics/safe_conversions.h"
-#define FXSYS_strlen(ptr) pdfium::base::checked_cast<FX_STRSIZE>(strlen(ptr))
-#define FXSYS_wcslen(ptr) pdfium::base::checked_cast<FX_STRSIZE>(wcslen(ptr))
+#define FXSYS_strlen(ptr) (strlen(ptr))
+#define FXSYS_wcslen(ptr) (wcslen(ptr))
// Overloaded functions for C++ templates
-inline FX_STRSIZE FXSYS_len(const char* ptr) {
+inline size_t FXSYS_len(const char* ptr) {
return FXSYS_strlen(ptr);
}
-inline FX_STRSIZE FXSYS_len(const wchar_t* ptr) {
+inline size_t FXSYS_len(const wchar_t* ptr) {
return FXSYS_wcslen(ptr);
}
@@ -150,8 +146,8 @@ inline const wchar_t* FXSYS_chr(const wchar_t* ptr, wchar_t ch, size_t len) {
extern "C" {
#else
-#define FXSYS_strlen(ptr) ((FX_STRSIZE)strlen(ptr))
-#define FXSYS_wcslen(ptr) ((FX_STRSIZE)wcslen(ptr))
+#define FXSYS_strlen(ptr) (strlen(ptr))
+#define FXSYS_wcslen(ptr) (wcslen(ptr))
#endif // __cplusplus
#if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
diff --git a/core/fxcrt/string_data_template.h b/core/fxcrt/string_data_template.h
index afec50fe01..bc797c07e2 100644
--- a/core/fxcrt/string_data_template.h
+++ b/core/fxcrt/string_data_template.h
@@ -16,13 +16,13 @@ namespace fxcrt {
template <typename CharType>
class StringDataTemplate {
public:
- static StringDataTemplate* Create(FX_STRSIZE nLen) {
+ static StringDataTemplate* Create(size_t nLen) {
ASSERT(nLen > 0);
// Calculate space needed for the fixed portion of the struct plus the
// NUL char that is not included in |m_nAllocLength|.
int overhead = offsetof(StringDataTemplate, m_String) + sizeof(CharType);
- pdfium::base::CheckedNumeric<FX_STRSIZE> nSize = nLen;
+ pdfium::base::CheckedNumeric<size_t> nSize = nLen;
nSize *= sizeof(CharType);
nSize += overhead;
@@ -32,8 +32,8 @@ class StringDataTemplate {
// by using this otherwise wasted space.
nSize += 7;
nSize &= ~7;
- FX_STRSIZE totalSize = nSize.ValueOrDie();
- FX_STRSIZE usableLen = (totalSize - overhead) / sizeof(CharType);
+ size_t totalSize = nSize.ValueOrDie();
+ size_t usableLen = (totalSize - overhead) / sizeof(CharType);
ASSERT(usableLen >= nLen);
void* pData = pdfium::base::PartitionAllocGeneric(
@@ -47,7 +47,7 @@ class StringDataTemplate {
return result;
}
- static StringDataTemplate* Create(const CharType* pStr, FX_STRSIZE nLen) {
+ static StringDataTemplate* Create(const CharType* pStr, size_t nLen) {
StringDataTemplate* result = Create(nLen);
result->CopyContents(pStr, nLen);
return result;
@@ -60,7 +60,7 @@ class StringDataTemplate {
this);
}
- bool CanOperateInPlace(FX_STRSIZE nTotalLen) const {
+ bool CanOperateInPlace(size_t nTotalLen) const {
return m_nRefs <= 1 && nTotalLen <= m_nAllocLength;
}
@@ -70,15 +70,13 @@ class StringDataTemplate {
(other.m_nDataLength + 1) * sizeof(CharType));
}
- void CopyContents(const CharType* pStr, FX_STRSIZE nLen) {
+ void CopyContents(const CharType* pStr, size_t nLen) {
ASSERT(nLen >= 0 && nLen <= m_nAllocLength);
memcpy(m_String, pStr, nLen * sizeof(CharType));
m_String[nLen] = 0;
}
- void CopyContentsAt(FX_STRSIZE offset,
- const CharType* pStr,
- FX_STRSIZE nLen) {
+ void CopyContentsAt(size_t offset, const CharType* pStr, size_t nLen) {
ASSERT(offset >= 0 && nLen >= 0 && offset + nLen <= m_nAllocLength);
memcpy(m_String + offset, pStr, nLen * sizeof(CharType));
m_String[offset + nLen] = 0;
@@ -91,19 +89,17 @@ class StringDataTemplate {
// the address space itself is a good upper bound on it.
intptr_t m_nRefs;
- // |FX_STRSIZE| is currently typedef'd as |int|.
- // TODO(palmer): It should be a |size_t|, or at least unsigned.
// These lengths are in terms of number of characters, not bytes, and do not
// include the terminating NUL character, but the underlying buffer is sized
// to be capable of holding it.
- FX_STRSIZE m_nDataLength;
- FX_STRSIZE m_nAllocLength;
+ size_t m_nDataLength;
+ size_t m_nAllocLength;
// Not really 1, variable size.
CharType m_String[1];
private:
- StringDataTemplate(FX_STRSIZE dataLen, FX_STRSIZE allocLen)
+ StringDataTemplate(size_t dataLen, size_t allocLen)
: m_nRefs(0), m_nDataLength(dataLen), m_nAllocLength(allocLen) {
ASSERT(dataLen >= 0);
ASSERT(dataLen <= allocLen);
diff --git a/core/fxcrt/string_view_template.h b/core/fxcrt/string_view_template.h
index 31c2c1e2af..346e5a469d 100644
--- a/core/fxcrt/string_view_template.h
+++ b/core/fxcrt/string_view_template.h
@@ -39,13 +39,13 @@ class StringViewTemplate {
: m_Ptr(reinterpret_cast<const UnsignedType*>(ptr)),
m_Length(ptr ? FXSYS_len(ptr) : 0) {}
- StringViewTemplate(const CharType* ptr, FX_STRSIZE len)
+ StringViewTemplate(const CharType* ptr, size_t len)
: m_Ptr(reinterpret_cast<const UnsignedType*>(ptr)), m_Length(len) {}
template <typename U = UnsignedType>
StringViewTemplate(
const UnsignedType* ptr,
- FX_STRSIZE size,
+ size_t size,
typename std::enable_if<!std::is_same<U, CharType>::value>::type* = 0)
: m_Ptr(ptr), m_Length(size) {}
@@ -64,7 +64,7 @@ class StringViewTemplate {
// Any changes to |vec| invalidate the string.
explicit StringViewTemplate(const std::vector<UnsignedType>& vec) {
- m_Length = pdfium::CollectionSize<FX_STRSIZE>(vec);
+ m_Length = pdfium::CollectionSize<size_t>(vec);
m_Ptr = m_Length ? vec.data() : nullptr;
}
@@ -116,8 +116,8 @@ class StringViewTemplate {
return 0;
uint32_t strid = 0;
- FX_STRSIZE size = std::min(static_cast<FX_STRSIZE>(4), m_Length);
- for (FX_STRSIZE i = 0; i < size; i++)
+ size_t size = std::min(static_cast<size_t>(4), m_Length);
+ for (size_t i = 0; i < size; i++)
strid = strid * 256 + m_Ptr.Get()[i];
return strid << ((4 - size) * 8);
@@ -128,12 +128,12 @@ class StringViewTemplate {
return reinterpret_cast<const CharType*>(m_Ptr.Get());
}
- FX_STRSIZE GetLength() const { return m_Length; }
+ size_t GetLength() const { return m_Length; }
bool IsEmpty() const { return m_Length == 0; }
- bool IsValidIndex(FX_STRSIZE index) const { return index < GetLength(); }
- bool IsValidLength(FX_STRSIZE length) const { return length <= GetLength(); }
+ bool IsValidIndex(size_t index) const { return index < GetLength(); }
+ bool IsValidLength(size_t length) const { return length <= GetLength(); }
- const UnsignedType& operator[](const FX_STRSIZE index) const {
+ const UnsignedType& operator[](const size_t index) const {
ASSERT(IsValidIndex(index));
return m_Ptr.Get()[index];
}
@@ -144,22 +144,22 @@ class StringViewTemplate {
return GetLength() ? (*this)[GetLength() - 1] : 0;
}
- const CharType CharAt(const FX_STRSIZE index) const {
+ const CharType CharAt(const size_t index) const {
ASSERT(IsValidIndex(index));
return static_cast<CharType>(m_Ptr.Get()[index]);
}
- pdfium::Optional<FX_STRSIZE> Find(CharType ch) const {
+ pdfium::Optional<size_t> Find(CharType ch) const {
const UnsignedType* found = reinterpret_cast<const UnsignedType*>(FXSYS_chr(
reinterpret_cast<const CharType*>(m_Ptr.Get()), ch, m_Length));
- return found ? pdfium::Optional<FX_STRSIZE>(found - m_Ptr.Get())
- : pdfium::Optional<FX_STRSIZE>();
+ return found ? pdfium::Optional<size_t>(found - m_Ptr.Get())
+ : pdfium::Optional<size_t>();
}
bool Contains(CharType ch) const { return Find(ch).has_value(); }
- StringViewTemplate Mid(FX_STRSIZE first, FX_STRSIZE count) const {
+ StringViewTemplate Mid(size_t first, size_t count) const {
if (!m_Ptr.Get())
return StringViewTemplate();
@@ -175,13 +175,13 @@ class StringViewTemplate {
return StringViewTemplate(m_Ptr.Get() + first, count);
}
- StringViewTemplate Left(FX_STRSIZE count) const {
+ StringViewTemplate Left(size_t count) const {
if (count == 0 || !IsValidLength(count))
return StringViewTemplate();
return Mid(0, count);
}
- StringViewTemplate Right(FX_STRSIZE count) const {
+ StringViewTemplate Right(size_t count) const {
if (count == 0 || !IsValidLength(count))
return StringViewTemplate();
return Mid(GetLength() - count, count);
@@ -191,7 +191,7 @@ class StringViewTemplate {
if (IsEmpty())
return StringViewTemplate();
- FX_STRSIZE pos = GetLength();
+ size_t pos = GetLength();
while (pos && CharAt(pos - 1) == ch)
pos--;
@@ -217,7 +217,7 @@ class StringViewTemplate {
protected:
UnownedPtr<const UnsignedType> m_Ptr;
- FX_STRSIZE m_Length;
+ size_t m_Length;
private:
void* operator new(size_t) throw() { return nullptr; }
diff --git a/core/fxcrt/widestring.cpp b/core/fxcrt/widestring.cpp
index 5fe7ee4777..a4632ee9db 100644
--- a/core/fxcrt/widestring.cpp
+++ b/core/fxcrt/widestring.cpp
@@ -55,9 +55,9 @@ const wchar_t* FX_wcsstr(const wchar_t* haystack,
return nullptr;
}
-pdfium::Optional<FX_STRSIZE> GuessSizeForVSWPrintf(const wchar_t* pFormat,
- va_list argList) {
- FX_STRSIZE nMaxLen = 0;
+pdfium::Optional<size_t> GuessSizeForVSWPrintf(const wchar_t* pFormat,
+ va_list argList) {
+ size_t nMaxLen = 0;
for (const wchar_t* pStr = pFormat; *pStr != 0; pStr++) {
if (*pStr != '%' || *(pStr = pStr + 1) == '%') {
++nMaxLen;
@@ -80,7 +80,7 @@ pdfium::Optional<FX_STRSIZE> GuessSizeForVSWPrintf(const wchar_t* pFormat,
++pStr;
}
if (nWidth < 0 || nWidth > 128 * 1024)
- return pdfium::Optional<FX_STRSIZE>();
+ return pdfium::Optional<size_t>();
int nPrecision = 0;
if (*pStr == '.') {
pStr++;
@@ -94,7 +94,7 @@ pdfium::Optional<FX_STRSIZE> GuessSizeForVSWPrintf(const wchar_t* pFormat,
}
}
if (nPrecision < 0 || nPrecision > 128 * 1024)
- return pdfium::Optional<FX_STRSIZE>();
+ return pdfium::Optional<size_t>();
int nModifier = 0;
if (*pStr == L'I' && *(pStr + 1) == L'6' && *(pStr + 2) == L'4') {
pStr += 3;
@@ -243,7 +243,7 @@ pdfium::Optional<FX_STRSIZE> GuessSizeForVSWPrintf(const wchar_t* pFormat,
nMaxLen += nItemLen;
}
nMaxLen += 32; // Fudge factor.
- return pdfium::Optional<FX_STRSIZE>(nMaxLen);
+ return pdfium::Optional<size_t>(nMaxLen);
}
#ifndef NDEBUG
@@ -293,7 +293,7 @@ WideString::WideString(WideString&& other) noexcept {
m_pData.Swap(other.m_pData);
}
-WideString::WideString(const wchar_t* pStr, FX_STRSIZE nLen) {
+WideString::WideString(const wchar_t* pStr, size_t nLen) {
if (nLen)
m_pData.Reset(StringData::Create(pStr, nLen));
}
@@ -317,7 +317,7 @@ WideString::WideString(const WideStringView& str1, const WideStringView& str2) {
FX_SAFE_STRSIZE nSafeLen = str1.GetLength();
nSafeLen += str2.GetLength();
- FX_STRSIZE nNewLen = nSafeLen.ValueOrDie();
+ size_t nNewLen = nSafeLen.ValueOrDie();
if (nNewLen == 0)
return;
@@ -332,13 +332,13 @@ WideString::WideString(const std::initializer_list<WideStringView>& list) {
for (const auto& item : list)
nSafeLen += item.GetLength();
- FX_STRSIZE nNewLen = nSafeLen.ValueOrDie();
+ size_t nNewLen = nSafeLen.ValueOrDie();
if (nNewLen == 0)
return;
m_pData.Reset(StringData::Create(nNewLen));
- FX_STRSIZE nOffset = 0;
+ size_t nOffset = 0;
for (const auto& item : list) {
m_pData->CopyContentsAt(nOffset, item.unterminated_c_str(),
item.GetLength());
@@ -443,13 +443,13 @@ bool WideString::operator<(const WideString& str) const {
return result < 0 || (result == 0 && GetLength() < str.GetLength());
}
-void WideString::AssignCopy(const wchar_t* pSrcData, FX_STRSIZE nSrcLen) {
+void WideString::AssignCopy(const wchar_t* pSrcData, size_t nSrcLen) {
AllocBeforeWrite(nSrcLen);
m_pData->CopyContents(pSrcData, nSrcLen);
m_pData->m_nDataLength = nSrcLen;
}
-void WideString::ReallocBeforeWrite(FX_STRSIZE nNewLength) {
+void WideString::ReallocBeforeWrite(size_t nNewLength) {
if (m_pData && m_pData->CanOperateInPlace(nNewLength))
return;
@@ -460,7 +460,7 @@ void WideString::ReallocBeforeWrite(FX_STRSIZE nNewLength) {
RetainPtr<StringData> pNewData(StringData::Create(nNewLength));
if (m_pData) {
- FX_STRSIZE nCopyLength = std::min(m_pData->m_nDataLength, nNewLength);
+ size_t nCopyLength = std::min(m_pData->m_nDataLength, nNewLength);
pNewData->CopyContents(m_pData->m_String, nCopyLength);
pNewData->m_nDataLength = nCopyLength;
} else {
@@ -470,7 +470,7 @@ void WideString::ReallocBeforeWrite(FX_STRSIZE nNewLength) {
m_pData.Swap(pNewData);
}
-void WideString::AllocBeforeWrite(FX_STRSIZE nNewLength) {
+void WideString::AllocBeforeWrite(size_t nNewLength) {
if (m_pData && m_pData->CanOperateInPlace(nNewLength))
return;
@@ -482,7 +482,7 @@ void WideString::AllocBeforeWrite(FX_STRSIZE nNewLength) {
m_pData.Reset(StringData::Create(nNewLength));
}
-void WideString::ReleaseBuffer(FX_STRSIZE nNewLength) {
+void WideString::ReleaseBuffer(size_t nNewLength) {
if (!m_pData)
return;
@@ -503,11 +503,11 @@ void WideString::ReleaseBuffer(FX_STRSIZE nNewLength) {
}
}
-void WideString::Reserve(FX_STRSIZE len) {
+void WideString::Reserve(size_t len) {
GetBuffer(len);
}
-wchar_t* WideString::GetBuffer(FX_STRSIZE nMinBufLength) {
+wchar_t* WideString::GetBuffer(size_t nMinBufLength) {
if (!m_pData) {
if (nMinBufLength == 0)
return nullptr;
@@ -532,28 +532,28 @@ wchar_t* WideString::GetBuffer(FX_STRSIZE nMinBufLength) {
return m_pData->m_String;
}
-FX_STRSIZE WideString::Delete(FX_STRSIZE index, FX_STRSIZE count) {
+size_t WideString::Delete(size_t index, size_t count) {
if (!m_pData)
return 0;
- FX_STRSIZE old_length = m_pData->m_nDataLength;
+ size_t old_length = m_pData->m_nDataLength;
if (count == 0 ||
- index != pdfium::clamp(index, static_cast<FX_STRSIZE>(0), old_length))
+ index != pdfium::clamp(index, static_cast<size_t>(0), old_length))
return old_length;
- FX_STRSIZE removal_length = index + count;
+ size_t removal_length = index + count;
if (removal_length > old_length)
return old_length;
ReallocBeforeWrite(old_length);
- FX_STRSIZE chars_to_copy = old_length - removal_length + 1;
+ size_t chars_to_copy = old_length - removal_length + 1;
wmemmove(m_pData->m_String + index, m_pData->m_String + removal_length,
chars_to_copy);
m_pData->m_nDataLength = old_length - count;
return m_pData->m_nDataLength;
}
-void WideString::Concat(const wchar_t* pSrcData, FX_STRSIZE nSrcLen) {
+void WideString::Concat(const wchar_t* pSrcData, size_t nSrcLen) {
if (!pSrcData || nSrcLen == 0)
return;
@@ -596,7 +596,7 @@ ByteString WideString::UTF16LE_Encode() const {
return result;
}
-WideString WideString::Mid(FX_STRSIZE first, FX_STRSIZE count) const {
+WideString WideString::Mid(size_t first, size_t count) const {
if (!m_pData)
return WideString();
@@ -617,21 +617,21 @@ WideString WideString::Mid(FX_STRSIZE first, FX_STRSIZE count) const {
return dest;
}
-WideString WideString::Left(FX_STRSIZE count) const {
+WideString WideString::Left(size_t count) const {
if (count == 0 || !IsValidLength(count))
return WideString();
return Mid(0, count);
}
-WideString WideString::Right(FX_STRSIZE count) const {
+WideString WideString::Right(size_t count) const {
if (count == 0 || !IsValidLength(count))
return WideString();
return Mid(GetLength() - count, count);
}
void WideString::AllocCopy(WideString& dest,
- FX_STRSIZE nCopyLen,
- FX_STRSIZE nCopyIndex) const {
+ size_t nCopyLen,
+ size_t nCopyIndex) const {
if (nCopyLen == 0)
return;
@@ -640,7 +640,7 @@ void WideString::AllocCopy(WideString& dest,
dest.m_pData.Swap(pNewData);
}
-bool WideString::TryVSWPrintf(FX_STRSIZE size,
+bool WideString::TryVSWPrintf(size_t size,
const wchar_t* pFormat,
va_list argList) {
GetBuffer(size);
@@ -676,7 +676,7 @@ void WideString::FormatV(const wchar_t* format, va_list argList) {
while (maxLen < 32 * 1024) {
va_copy(argListCopy, argList);
bool bSufficientBuffer =
- TryVSWPrintf(static_cast<FX_STRSIZE>(maxLen), format, argListCopy);
+ TryVSWPrintf(static_cast<size_t>(maxLen), format, argListCopy);
va_end(argListCopy);
if (bSufficientBuffer)
break;
@@ -691,12 +691,12 @@ void WideString::Format(const wchar_t* pFormat, ...) {
va_end(argList);
}
-FX_STRSIZE WideString::Insert(FX_STRSIZE location, wchar_t ch) {
- const FX_STRSIZE cur_length = m_pData ? m_pData->m_nDataLength : 0;
+size_t WideString::Insert(size_t location, wchar_t ch) {
+ const size_t cur_length = m_pData ? m_pData->m_nDataLength : 0;
if (!IsValidLength(location))
return cur_length;
- const FX_STRSIZE new_length = cur_length + 1;
+ const size_t new_length = cur_length + 1;
ReallocBeforeWrite(new_length);
wmemmove(m_pData->m_String + location + 1, m_pData->m_String + location,
new_length - location);
@@ -705,35 +705,34 @@ FX_STRSIZE WideString::Insert(FX_STRSIZE location, wchar_t ch) {
return new_length;
}
-pdfium::Optional<FX_STRSIZE> WideString::Find(wchar_t ch,
- FX_STRSIZE start) const {
+pdfium::Optional<size_t> WideString::Find(wchar_t ch, size_t start) const {
if (!m_pData)
- return pdfium::Optional<FX_STRSIZE>();
+ return pdfium::Optional<size_t>();
if (!IsValidIndex(start))
- return pdfium::Optional<FX_STRSIZE>();
+ return pdfium::Optional<size_t>();
const wchar_t* pStr =
wmemchr(m_pData->m_String + start, ch, m_pData->m_nDataLength - start);
- return pStr ? pdfium::Optional<FX_STRSIZE>(
- static_cast<FX_STRSIZE>(pStr - m_pData->m_String))
- : pdfium::Optional<FX_STRSIZE>();
+ return pStr ? pdfium::Optional<size_t>(
+ static_cast<size_t>(pStr - m_pData->m_String))
+ : pdfium::Optional<size_t>();
}
-pdfium::Optional<FX_STRSIZE> WideString::Find(const WideStringView& subStr,
- FX_STRSIZE start) const {
+pdfium::Optional<size_t> WideString::Find(const WideStringView& subStr,
+ size_t start) const {
if (!m_pData)
- return pdfium::Optional<FX_STRSIZE>();
+ return pdfium::Optional<size_t>();
if (!IsValidIndex(start))
- return pdfium::Optional<FX_STRSIZE>();
+ return pdfium::Optional<size_t>();
const wchar_t* pStr =
FX_wcsstr(m_pData->m_String + start, m_pData->m_nDataLength - start,
subStr.unterminated_c_str(), subStr.GetLength());
- return pStr ? pdfium::Optional<FX_STRSIZE>(
- static_cast<FX_STRSIZE>(pStr - m_pData->m_String))
- : pdfium::Optional<FX_STRSIZE>();
+ return pStr ? pdfium::Optional<size_t>(
+ static_cast<size_t>(pStr - m_pData->m_String))
+ : pdfium::Optional<size_t>();
}
void WideString::MakeLower() {
@@ -752,7 +751,7 @@ void WideString::MakeUpper() {
FXSYS_wcsupr(m_pData->m_String);
}
-FX_STRSIZE WideString::Remove(wchar_t chRemove) {
+size_t WideString::Remove(wchar_t chRemove) {
if (!m_pData || m_pData->m_nDataLength < 1)
return 0;
@@ -781,24 +780,25 @@ FX_STRSIZE WideString::Remove(wchar_t chRemove) {
}
*pstrDest = 0;
- FX_STRSIZE count = static_cast<FX_STRSIZE>(pstrSource - pstrDest);
+ size_t count = static_cast<size_t>(pstrSource - pstrDest);
m_pData->m_nDataLength -= count;
return count;
}
-FX_STRSIZE WideString::Replace(const WideStringView& pOld,
- const WideStringView& pNew) {
+size_t WideString::Replace(const WideStringView& pOld,
+ const WideStringView& pNew) {
if (!m_pData || pOld.IsEmpty())
return 0;
- FX_STRSIZE nSourceLen = pOld.GetLength();
- FX_STRSIZE nReplacementLen = pNew.GetLength();
- FX_STRSIZE count = 0;
+ size_t nSourceLen = pOld.GetLength();
+ size_t nReplacementLen = pNew.GetLength();
+ size_t count = 0;
const wchar_t* pStart = m_pData->m_String;
wchar_t* pEnd = m_pData->m_String + m_pData->m_nDataLength;
while (1) {
- const wchar_t* pTarget = FX_wcsstr(pStart, (FX_STRSIZE)(pEnd - pStart),
- pOld.unterminated_c_str(), nSourceLen);
+ const wchar_t* pTarget =
+ FX_wcsstr(pStart, static_cast<size_t>(pEnd - pStart),
+ pOld.unterminated_c_str(), nSourceLen);
if (!pTarget)
break;
@@ -808,7 +808,7 @@ FX_STRSIZE WideString::Replace(const WideStringView& pOld,
if (count == 0)
return 0;
- FX_STRSIZE nNewLength =
+ size_t nNewLength =
m_pData->m_nDataLength + (nReplacementLen - nSourceLen) * count;
if (nNewLength == 0) {
@@ -819,9 +819,10 @@ FX_STRSIZE WideString::Replace(const WideStringView& pOld,
RetainPtr<StringData> pNewData(StringData::Create(nNewLength));
pStart = m_pData->m_String;
wchar_t* pDest = pNewData->m_String;
- for (FX_STRSIZE i = 0; i < count; i++) {
- const wchar_t* pTarget = FX_wcsstr(pStart, (FX_STRSIZE)(pEnd - pStart),
- pOld.unterminated_c_str(), nSourceLen);
+ for (size_t i = 0; i < count; i++) {
+ const wchar_t* pTarget =
+ FX_wcsstr(pStart, static_cast<size_t>(pEnd - pStart),
+ pOld.unterminated_c_str(), nSourceLen);
wmemcpy(pDest, pStart, pTarget - pStart);
pDest += pTarget - pStart;
wmemcpy(pDest, pNew.unterminated_c_str(), pNew.GetLength());
@@ -850,29 +851,28 @@ WideString WideString::FromUTF8(const ByteStringView& str) {
return WideString();
CFX_UTF8Decoder decoder;
- for (FX_STRSIZE i = 0; i < str.GetLength(); i++)
+ for (size_t i = 0; i < str.GetLength(); i++)
decoder.Input(str[i]);
return WideString(decoder.GetResult());
}
// static
-WideString WideString::FromUTF16LE(const unsigned short* wstr,
- FX_STRSIZE wlen) {
+WideString WideString::FromUTF16LE(const unsigned short* wstr, size_t wlen) {
if (!wstr || wlen == 0) {
return WideString();
}
WideString result;
wchar_t* buf = result.GetBuffer(wlen);
- for (FX_STRSIZE i = 0; i < wlen; i++) {
+ for (size_t i = 0; i < wlen; i++) {
buf[i] = wstr[i];
}
result.ReleaseBuffer(wlen);
return result;
}
-void WideString::SetAt(FX_STRSIZE index, wchar_t c) {
+void WideString::SetAt(size_t index, wchar_t c) {
ASSERT(IsValidIndex(index));
ReallocBeforeWrite(m_pData->m_nDataLength);
m_pData->m_String[index] = c;
@@ -894,10 +894,10 @@ int WideString::Compare(const WideString& str) const {
if (!str.m_pData) {
return 1;
}
- FX_STRSIZE this_len = m_pData->m_nDataLength;
- FX_STRSIZE that_len = str.m_pData->m_nDataLength;
- FX_STRSIZE min_len = std::min(this_len, that_len);
- for (FX_STRSIZE i = 0; i < min_len; i++) {
+ size_t this_len = m_pData->m_nDataLength;
+ size_t that_len = str.m_pData->m_nDataLength;
+ size_t min_len = std::min(this_len, that_len);
+ for (size_t i = 0; i < min_len; i++) {
if (m_pData->m_String[i] < str.m_pData->m_String[i]) {
return -1;
}
@@ -921,8 +921,8 @@ int WideString::CompareNoCase(const wchar_t* lpsz) const {
return FXSYS_wcsicmp(m_pData->m_String, lpsz);
}
-FX_STRSIZE WideString::WStringLength(const unsigned short* str) {
- FX_STRSIZE len = 0;
+size_t WideString::WStringLength(const unsigned short* str) {
+ size_t len = 0;
if (str)
while (str[len])
len++;
@@ -933,7 +933,7 @@ void WideString::TrimRight(const WideStringView& pTargets) {
if (IsEmpty() || pTargets.IsEmpty())
return;
- FX_STRSIZE pos = GetLength();
+ size_t pos = GetLength();
while (pos && pTargets.Contains(m_pData->m_String[pos - 1]))
pos--;
@@ -957,13 +957,13 @@ void WideString::TrimLeft(const WideStringView& pTargets) {
if (!m_pData || pTargets.IsEmpty())
return;
- FX_STRSIZE len = GetLength();
+ size_t len = GetLength();
if (len == 0)
return;
- FX_STRSIZE pos = 0;
+ size_t pos = 0;
while (pos < len) {
- FX_STRSIZE i = 0;
+ size_t i = 0;
while (i < pTargets.GetLength() &&
pTargets.CharAt(i) != m_pData->m_String[pos]) {
i++;
@@ -977,7 +977,7 @@ void WideString::TrimLeft(const WideStringView& pTargets) {
return;
ReallocBeforeWrite(len);
- FX_STRSIZE nDataLength = len - pos;
+ size_t nDataLength = len - pos;
memmove(m_pData->m_String, m_pData->m_String + pos,
(nDataLength + 1) * sizeof(wchar_t));
m_pData->m_nDataLength = nDataLength;
diff --git a/core/fxcrt/widestring.h b/core/fxcrt/widestring.h
index f56703f1ab..73846e1be0 100644
--- a/core/fxcrt/widestring.h
+++ b/core/fxcrt/widestring.h
@@ -47,7 +47,7 @@ class WideString {
// NOLINTNEXTLINE(runtime/explicit)
WideString(char) = delete;
- WideString(const wchar_t* ptr, FX_STRSIZE len);
+ WideString(const wchar_t* ptr, size_t len);
explicit WideString(const WideStringView& str);
WideString(const WideStringView& str1, const WideStringView& str2);
@@ -59,9 +59,9 @@ class WideString {
static WideString FromCodePage(const ByteStringView& str, uint16_t codepage);
static WideString FromUTF8(const ByteStringView& str);
- static WideString FromUTF16LE(const unsigned short* str, FX_STRSIZE len);
+ static WideString FromUTF16LE(const unsigned short* str, size_t len);
- static FX_STRSIZE WStringLength(const unsigned short* str);
+ static size_t WStringLength(const unsigned short* str);
// Explicit conversion to C-style wide string.
// Note: Any subsequent modification of |this| will invalidate the result.
@@ -89,13 +89,13 @@ class WideString {
void clear() { m_pData.Reset(); }
- FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; }
- FX_STRSIZE GetStringLength() const {
+ size_t GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; }
+ size_t GetStringLength() const {
return m_pData ? FXSYS_wcslen(m_pData->m_String) : 0;
}
bool IsEmpty() const { return !GetLength(); }
- bool IsValidIndex(FX_STRSIZE index) const { return index < GetLength(); }
- bool IsValidLength(FX_STRSIZE length) const { return length <= GetLength(); }
+ bool IsValidIndex(size_t index) const { return index < GetLength(); }
+ bool IsValidLength(size_t length) const { return length <= GetLength(); }
const WideString& operator=(const wchar_t* str);
const WideString& operator=(const WideString& stringSrc);
@@ -116,7 +116,7 @@ class WideString {
bool operator<(const WideString& str) const;
- CharType operator[](const FX_STRSIZE index) const {
+ CharType operator[](const size_t index) const {
ASSERT(IsValidIndex(index));
return m_pData ? m_pData->m_String[index] : 0;
}
@@ -124,20 +124,20 @@ class WideString {
CharType First() const { return GetLength() ? (*this)[0] : 0; }
CharType Last() const { return GetLength() ? (*this)[GetLength() - 1] : 0; }
- void SetAt(FX_STRSIZE index, wchar_t c);
+ void SetAt(size_t index, wchar_t c);
int Compare(const wchar_t* str) const;
int Compare(const WideString& str) const;
int CompareNoCase(const wchar_t* str) const;
- WideString Mid(FX_STRSIZE first, FX_STRSIZE count) const;
- WideString Left(FX_STRSIZE count) const;
- WideString Right(FX_STRSIZE count) const;
+ WideString Mid(size_t first, size_t count) const;
+ WideString Left(size_t count) const;
+ WideString Right(size_t count) const;
- FX_STRSIZE Insert(FX_STRSIZE index, wchar_t ch);
- FX_STRSIZE InsertAtFront(wchar_t ch) { return Insert(0, ch); }
- FX_STRSIZE InsertAtBack(wchar_t ch) { return Insert(GetLength(), ch); }
- FX_STRSIZE Delete(FX_STRSIZE index, FX_STRSIZE count = 1);
+ size_t Insert(size_t index, wchar_t ch);
+ size_t InsertAtFront(wchar_t ch) { return Insert(0, ch); }
+ size_t InsertAtBack(wchar_t ch) { return Insert(GetLength(), ch); }
+ size_t Delete(size_t index, size_t count = 1);
void Format(const wchar_t* lpszFormat, ...);
void FormatV(const wchar_t* lpszFormat, va_list argList);
@@ -153,27 +153,27 @@ class WideString {
void TrimLeft(wchar_t chTarget);
void TrimLeft(const WideStringView& pTargets);
- void Reserve(FX_STRSIZE len);
- wchar_t* GetBuffer(FX_STRSIZE len);
- void ReleaseBuffer(FX_STRSIZE len);
+ void Reserve(size_t len);
+ wchar_t* GetBuffer(size_t len);
+ void ReleaseBuffer(size_t len);
int GetInteger() const;
float GetFloat() const;
- pdfium::Optional<FX_STRSIZE> Find(const WideStringView& pSub,
- FX_STRSIZE start = 0) const;
- pdfium::Optional<FX_STRSIZE> Find(wchar_t ch, FX_STRSIZE start = 0) const;
+ pdfium::Optional<size_t> Find(const WideStringView& pSub,
+ size_t start = 0) const;
+ pdfium::Optional<size_t> Find(wchar_t ch, size_t start = 0) const;
- bool Contains(const WideStringView& lpszSub, FX_STRSIZE start = 0) const {
+ bool Contains(const WideStringView& lpszSub, size_t start = 0) const {
return Find(lpszSub, start).has_value();
}
- bool Contains(char ch, FX_STRSIZE start = 0) const {
+ bool Contains(char ch, size_t start = 0) const {
return Find(ch, start).has_value();
}
- FX_STRSIZE Replace(const WideStringView& pOld, const WideStringView& pNew);
- FX_STRSIZE Remove(wchar_t ch);
+ size_t Replace(const WideStringView& pOld, const WideStringView& pNew);
+ size_t Remove(wchar_t ch);
ByteString UTF8Encode() const;
ByteString UTF16LE_Encode() const;
@@ -181,16 +181,14 @@ class WideString {
protected:
using StringData = StringDataTemplate<wchar_t>;
- void ReallocBeforeWrite(FX_STRSIZE nLen);
- void AllocBeforeWrite(FX_STRSIZE nLen);
- void AllocCopy(WideString& dest,
- FX_STRSIZE nCopyLen,
- FX_STRSIZE nCopyIndex) const;
- void AssignCopy(const wchar_t* pSrcData, FX_STRSIZE nSrcLen);
- void Concat(const wchar_t* lpszSrcData, FX_STRSIZE nSrcLen);
+ void ReallocBeforeWrite(size_t nLen);
+ void AllocBeforeWrite(size_t nLen);
+ void AllocCopy(WideString& dest, size_t nCopyLen, size_t nCopyIndex) const;
+ void AssignCopy(const wchar_t* pSrcData, size_t nSrcLen);
+ void Concat(const wchar_t* lpszSrcData, size_t nSrcLen);
// Returns true unless we ran out of space.
- bool TryVSWPrintf(FX_STRSIZE size, const wchar_t* format, va_list argList);
+ bool TryVSWPrintf(size_t size, const wchar_t* format, va_list argList);
RetainPtr<StringData> m_pData;
diff --git a/core/fxcrt/widestring_unittest.cpp b/core/fxcrt/widestring_unittest.cpp
index 5eba72eea7..1f7219616d 100644
--- a/core/fxcrt/widestring_unittest.cpp
+++ b/core/fxcrt/widestring_unittest.cpp
@@ -510,7 +510,7 @@ TEST(WideString, Find) {
EXPECT_FALSE(empty_string.Find(L'a').has_value());
EXPECT_FALSE(empty_string.Find(L'\0').has_value());
- pdfium::Optional<FX_STRSIZE> result;
+ pdfium::Optional<size_t> result;
WideString single_string(L"a");
result = single_string.Find(L'a');
ASSERT_TRUE(result.has_value());
@@ -1017,7 +1017,7 @@ TEST(WideStringView, Find) {
EXPECT_FALSE(empty_string.Find(L'a').has_value());
EXPECT_FALSE(empty_string.Find(L'\0').has_value());
- pdfium::Optional<FX_STRSIZE> result;
+ pdfium::Optional<size_t> result;
WideStringView single_string(L"a");
result = single_string.Find(L'a');
ASSERT_TRUE(result.has_value());
diff --git a/core/fxcrt/xml/cfx_xmlsyntaxparser.cpp b/core/fxcrt/xml/cfx_xmlsyntaxparser.cpp
index 5dcb867623..2d1d3d7a08 100644
--- a/core/fxcrt/xml/cfx_xmlsyntaxparser.cpp
+++ b/core/fxcrt/xml/cfx_xmlsyntaxparser.cpp
@@ -103,7 +103,7 @@ CFX_XMLSyntaxParser::CFX_XMLSyntaxParser(
m_iXMLPlaneSize =
std::min(m_iXMLPlaneSize,
- pdfium::base::checked_cast<FX_STRSIZE>(m_pStream->GetLength()));
+ pdfium::base::checked_cast<size_t>(m_pStream->GetLength()));
m_iCurrentPos = m_pStream->GetBOMLength();
FX_SAFE_STRSIZE alloc_size_safe = m_iXMLPlaneSize;
diff --git a/core/fxcrt/xml/cfx_xmlsyntaxparser.h b/core/fxcrt/xml/cfx_xmlsyntaxparser.h
index 8379aa445b..b93bbb6801 100644
--- a/core/fxcrt/xml/cfx_xmlsyntaxparser.h
+++ b/core/fxcrt/xml/cfx_xmlsyntaxparser.h
@@ -101,14 +101,14 @@ class CFX_XMLSyntaxParser {
void ParseTextChar(wchar_t ch);
RetainPtr<CFX_SeekableStreamProxy> m_pStream;
- FX_STRSIZE m_iXMLPlaneSize;
+ size_t m_iXMLPlaneSize;
FX_FILESIZE m_iCurrentPos;
int32_t m_iCurrentNodeNum;
int32_t m_iLastNodeNum;
int32_t m_iParsedBytes;
FX_FILESIZE m_ParsedChars;
std::vector<wchar_t> m_Buffer;
- FX_STRSIZE m_iBufferChars;
+ size_t m_iBufferChars;
bool m_bEOS;
FX_FILESIZE m_Start; // Start position in m_Buffer
FX_FILESIZE m_End; // End position in m_Buffer