From e4d2cffd31a1f705f04d11223444455aa35923a6 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 7 Aug 2018 23:22:24 +0000 Subject: Remove unused codepage code from GetByteString(). It is only called ever called from one place with 0 (FX_CODEPAGE_DefANSI), with more complicated usage being funneled directly into FXSYS_ code. Next, fold it into ByteString::FromUnicode(). Change-Id: I85aa0dd3a4ca8cddcff22533e0a284ff3f5535ee Reviewed-on: https://pdfium-review.googlesource.com/39670 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- core/fxcrt/bytestring.cpp | 57 ++++++++++++++--------------------------------- 1 file changed, 17 insertions(+), 40 deletions(-) (limited to 'core') diff --git a/core/fxcrt/bytestring.cpp b/core/fxcrt/bytestring.cpp index 984acf9c69..4d55c98912 100644 --- a/core/fxcrt/bytestring.cpp +++ b/core/fxcrt/bytestring.cpp @@ -55,44 +55,6 @@ const char* FX_strstr(const char* haystack, return nullptr; } -#ifndef NDEBUG -bool IsValidCodePage(uint16_t codepage) { - switch (codepage) { - case FX_CODEPAGE_DefANSI: - case FX_CODEPAGE_ShiftJIS: - case FX_CODEPAGE_ChineseSimplified: - case FX_CODEPAGE_Hangul: - case FX_CODEPAGE_ChineseTraditional: - return true; - default: - return false; - } -} -#endif - -ByteString GetByteString(uint16_t codepage, const WideStringView& wstr) { -#ifndef NDEBUG - ASSERT(IsValidCodePage(codepage)); -#endif - - int src_len = wstr.GetLength(); - int dest_len = - FXSYS_WideCharToMultiByte(codepage, 0, wstr.unterminated_c_str(), src_len, - nullptr, 0, nullptr, nullptr); - if (!dest_len) - return ByteString(); - - ByteString bstr; - { - // Span's lifetime must end before ReleaseBuffer() below. - pdfium::span dest_buf = bstr.GetBuffer(dest_len); - FXSYS_WideCharToMultiByte(codepage, 0, wstr.unterminated_c_str(), src_len, - dest_buf.data(), dest_len, nullptr, nullptr); - } - bstr.ReleaseBuffer(dest_len); - return bstr; -} - } // namespace namespace fxcrt { @@ -715,8 +677,23 @@ WideString ByteString::UTF8Decode() const { } // static -ByteString ByteString::FromUnicode(const WideString& str) { - return GetByteString(0, str.AsStringView()); +ByteString ByteString::FromUnicode(const WideString& wstr) { + int src_len = wstr.GetLength(); + int dest_len = + FXSYS_WideCharToMultiByte(FX_CODEPAGE_DefANSI, 0, wstr.c_str(), src_len, + nullptr, 0, nullptr, nullptr); + if (!dest_len) + return ByteString(); + + ByteString bstr; + { + // Span's lifetime must end before ReleaseBuffer() below. + pdfium::span dest_buf = bstr.GetBuffer(dest_len); + FXSYS_WideCharToMultiByte(FX_CODEPAGE_DefANSI, 0, wstr.c_str(), src_len, + dest_buf.data(), dest_len, nullptr, nullptr); + } + bstr.ReleaseBuffer(dest_len); + return bstr; } int ByteString::Compare(const ByteStringView& str) const { -- cgit v1.2.3