summaryrefslogtreecommitdiff
path: root/core/fxcrt
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-08-07 23:22:24 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-07 23:22:24 +0000
commite4d2cffd31a1f705f04d11223444455aa35923a6 (patch)
treec894e92f58b2b3c1a71ca18d7c120013e344d65d /core/fxcrt
parent3bee9c60f013b8b7e99c39ee35699d132b330334 (diff)
downloadpdfium-e4d2cffd31a1f705f04d11223444455aa35923a6.tar.xz
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 <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxcrt')
-rw-r--r--core/fxcrt/bytestring.cpp57
1 files changed, 17 insertions, 40 deletions
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<char> 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<char> 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 {