summaryrefslogtreecommitdiff
path: root/core/fxcrt/bytestring.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-08-08 17:49:02 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-08 17:49:02 +0000
commit34dab07ed6e826666fd0589069f2c9b5bd2ba4dc (patch)
tree0eb30bd1c76f54890a6d365258a7157ae9972748 /core/fxcrt/bytestring.cpp
parent6d9897b103aef10b369eb999a40c22011a8ae4f5 (diff)
downloadpdfium-34dab07ed6e826666fd0589069f2c9b5bd2ba4dc.tar.xz
Move ByteString::FromUnicode() to WideString::ToDefANSI()
Turns out that "FromUnicode" is misleading in that, on linux, it simply removes any characters beyond 0xFF and passes the rest unchanged, so no unicode decoding actually takes place. On Windows, it passes it into the system function specifying FX_CODEPAGE_DefANSI, converting it into the so-called "default ANSI code plane", passing some characters, converting others to '?' and still others to 'A'. Either way, nothing resembling UTF8 comes out of this, so pick a better name. These now immediately look suspicious, so a follow-up CL will see which ones should really be WideString::UTF8Encode() instead. Making this a normal method on a widestring rather than a static method on a bytestring feels more natural; this is parallel to the UTF8Encode and UTF16LE_Encode functions. Add a test that shows these conversions. Change-Id: Ia7551b47199eba61b5c328a97bfe9176ac8e583c Reviewed-on: https://pdfium-review.googlesource.com/39690 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxcrt/bytestring.cpp')
-rw-r--r--core/fxcrt/bytestring.cpp20
1 files changed, 0 insertions, 20 deletions
diff --git a/core/fxcrt/bytestring.cpp b/core/fxcrt/bytestring.cpp
index 4d55c98912..b6c1ce7bbd 100644
--- a/core/fxcrt/bytestring.cpp
+++ b/core/fxcrt/bytestring.cpp
@@ -676,26 +676,6 @@ WideString ByteString::UTF8Decode() const {
return WideString(decoder.GetResult());
}
-// static
-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 {
if (!m_pData)
return str.IsEmpty() ? 0 : -1;