summaryrefslogtreecommitdiff
path: root/core/fxcrt/widestring.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-08-08 22:20:29 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-08 22:20:29 +0000
commitf765805983d157e9a21d7202ba49148f24d226f3 (patch)
treeafae705a3a6c1fe55028cdebc5772ac244c7e762 /core/fxcrt/widestring.cpp
parent4b17aea63fede24925cd7579c27f55298e5e9937 (diff)
downloadpdfium-f765805983d157e9a21d7202ba49148f24d226f3.tar.xz
Remove unused codepage from WideString::GetWideString().
Consolidate code into sole caller, which always retrieves a string from the "default ANSI code page". Add unit test for this code path. Fix sign extension bug giving bogus 0xffffff80 codepoint uncovered by unit test on non-windows. Note windows result is different because the system conversion routine does actually work. Change-Id: I1c1246b203ee66e9ff0b6fccf97594788bcd0fca Reviewed-on: https://pdfium-review.googlesource.com/39730 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxcrt/widestring.cpp')
-rw-r--r--core/fxcrt/widestring.cpp59
1 files changed, 15 insertions, 44 deletions
diff --git a/core/fxcrt/widestring.cpp b/core/fxcrt/widestring.cpp
index 7dd1c30eb0..97073f170d 100644
--- a/core/fxcrt/widestring.cpp
+++ b/core/fxcrt/widestring.cpp
@@ -277,43 +277,6 @@ Optional<WideString> TryVSWPrintf(size_t size,
return {str};
}
-#ifndef NDEBUG
-bool IsValidWideCodePage(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
-
-WideString GetWideString(uint16_t codepage, const ByteStringView& bstr) {
-#ifndef NDEBUG
- ASSERT(IsValidWideCodePage(codepage));
-#endif
-
- int src_len = bstr.GetLength();
- int dest_len = FXSYS_MultiByteToWideChar(
- codepage, 0, bstr.unterminated_c_str(), src_len, nullptr, 0);
- if (!dest_len)
- return WideString();
-
- WideString wstr;
- {
- // Span's lifetime must end before ReleaseBuffer() below.
- pdfium::span<wchar_t> dest_buf = wstr.GetBuffer(dest_len);
- FXSYS_MultiByteToWideChar(codepage, 0, bstr.unterminated_c_str(), src_len,
- dest_buf.data(), dest_len);
- }
- wstr.ReleaseBuffer(dest_len);
- return wstr;
-}
-
} // namespace
namespace fxcrt {
@@ -902,14 +865,22 @@ size_t WideString::Replace(const WideStringView& pOld,
}
// static
-WideString WideString::FromLocal(const ByteStringView& str) {
- return FromCodePage(str, 0);
-}
+WideString WideString::FromLocal(const ByteStringView& bstr) {
+ int src_len = bstr.GetLength();
+ int dest_len = FXSYS_MultiByteToWideChar(
+ FX_CODEPAGE_DefANSI, 0, bstr.unterminated_c_str(), src_len, nullptr, 0);
+ if (!dest_len)
+ return WideString();
-// static
-WideString WideString::FromCodePage(const ByteStringView& str,
- uint16_t codepage) {
- return GetWideString(codepage, str);
+ WideString wstr;
+ {
+ // Span's lifetime must end before ReleaseBuffer() below.
+ pdfium::span<wchar_t> dest_buf = wstr.GetBuffer(dest_len);
+ FXSYS_MultiByteToWideChar(FX_CODEPAGE_DefANSI, 0, bstr.unterminated_c_str(),
+ src_len, dest_buf.data(), dest_len);
+ }
+ wstr.ReleaseBuffer(dest_len);
+ return wstr;
}
// static