diff options
author | Ryan Harrison <rharrison@chromium.org> | 2017-09-27 10:53:11 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-09-27 16:11:38 +0000 |
commit | 875e98c581952478f3a3ccef9b2f2e3ed06c5346 (patch) | |
tree | 8e0d7e032056bf4c73d6da43c0f3ce4eadb74dfd /core/fxcrt/widestring.cpp | |
parent | cc3a3ee3ebcc1baabdfa7ffca5876dbbfa3980c1 (diff) | |
download | pdfium-875e98c581952478f3a3ccef9b2f2e3ed06c5346.tar.xz |
Remove FX_STRSIZE and replace with size_t
BUG=pdfium:828
Change-Id: I5c40237433ebabaeabdb43aec9cdf783e41dfe16
Reviewed-on: https://pdfium-review.googlesource.com/13230
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'core/fxcrt/widestring.cpp')
-rw-r--r-- | core/fxcrt/widestring.cpp | 152 |
1 files changed, 76 insertions, 76 deletions
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; |