From 8ab45eafebfd510554920e09e5ee85e94701dea9 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 5 Jan 2016 10:17:30 -0800 Subject: Merge to XFA: Make FPDF_WIDESTRING work regardless of endianness. Original Review URL: https://codereview.chromium.org/1554363002 . (cherry picked from commit ed34cdf99d5a4b33e57f81f9244a311f6fb86db3) TBR=thestig@chromium.org Review URL: https://codereview.chromium.org/1559373002 . --- testing/embedder_test_timer_handling_delegate.h | 4 ++-- testing/test_support.cpp | 15 ++++++++++++++- testing/test_support.h | 6 +++++- 3 files changed, 21 insertions(+), 4 deletions(-) (limited to 'testing') diff --git a/testing/embedder_test_timer_handling_delegate.h b/testing/embedder_test_timer_handling_delegate.h index 74e346e830..a704bd49df 100644 --- a/testing/embedder_test_timer_handling_delegate.h +++ b/testing/embedder_test_timer_handling_delegate.h @@ -21,8 +21,8 @@ class EmbedderTestTimerHandlingDelegate : public EmbedderTest::Delegate { int type_in, int icon_in) : type(type_in), icon(icon_in) { - message = GetWideString(message_in); - title = GetWideString(title_in); + message = GetPlatformWString(message_in); + title = GetPlatformWString(title_in); } std::wstring message; diff --git a/testing/test_support.cpp b/testing/test_support.cpp index f71f6f8b4f..c7ab10ee3c 100644 --- a/testing/test_support.cpp +++ b/testing/test_support.cpp @@ -98,7 +98,7 @@ char* GetFileContents(const char* filename, size_t* retlen) { return buffer; } -std::wstring GetWideString(FPDF_WIDESTRING wstr) { +std::wstring GetPlatformWString(FPDF_WIDESTRING wstr) { if (!wstr) return nullptr; @@ -114,6 +114,19 @@ std::wstring GetWideString(FPDF_WIDESTRING wstr) { return platform_string; } +FPDF_WIDESTRING GetFPDFWideString(const std::wstring& wstr) { + size_t length = sizeof(uint16_t) * (wstr.length() + 1); + unsigned char* ptr = static_cast(malloc(length)); + size_t i = 0; + for (wchar_t w : wstr) { + ptr[i++] = w & 0xff; + ptr[i++] = (w >> 8) & 0xff; + } + ptr[i++] = 0; + ptr[i] = 0; + return reinterpret_cast(ptr); +} + #ifdef PDF_ENABLE_V8 #ifdef V8_USE_EXTERNAL_STARTUP_DATA bool InitializeV8ForPDFium(const std::string& exe_path, diff --git a/testing/test_support.h b/testing/test_support.h index a2241144a4..d48d5596f4 100644 --- a/testing/test_support.h +++ b/testing/test_support.h @@ -19,7 +19,11 @@ char* GetFileContents(const char* filename, size_t* retlen); // Converts a FPDF_WIDESTRING to a std::wstring. // Deals with differences between UTF16LE and wchar_t. -std::wstring GetWideString(FPDF_WIDESTRING wstr); +std::wstring GetPlatformWString(const FPDF_WIDESTRING wstr); + +// Returns a newly mallocated FPDF_WIDESTRING (caller must free()). +// Deals with differences between UTF16LE and wchar_t. +FPDF_WIDESTRING GetFPDFWideString(const std::wstring& wstr); #ifdef PDF_ENABLE_V8 #ifdef V8_USE_EXTERNAL_STARTUP_DATA -- cgit v1.2.3