From 34dab07ed6e826666fd0589069f2c9b5bd2ba4dc Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 8 Aug 2018 17:49:02 +0000 Subject: 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 Commit-Queue: Tom Sepez --- fxjs/cjs_publicmethods.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'fxjs/cjs_publicmethods.cpp') diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp index a86ece3461..f2cd3ff7c1 100644 --- a/fxjs/cjs_publicmethods.cpp +++ b/fxjs/cjs_publicmethods.cpp @@ -327,7 +327,7 @@ v8::Local CJS_PublicMethods::AF_MakeArrayFromList( return pRuntime->ToArray(val); WideString wsStr = pRuntime->ToWideString(val); - ByteString t = ByteString::FromUnicode(wsStr); + ByteString t = wsStr.ToDefANSI(); const char* p = t.c_str(); int nIndex = 0; @@ -882,7 +882,7 @@ CJS_Return CJS_PublicMethods::AFNumber_Format( return CJS_Return(L"No event handler"); WideString& Value = pEvent->Value(); - ByteString strValue = StrTrim(ByteString::FromUnicode(Value)); + ByteString strValue = StrTrim(Value.ToDefANSI()); if (strValue.IsEmpty()) return CJS_Return(); @@ -1078,7 +1078,7 @@ CJS_Return CJS_PublicMethods::AFPercent_Format( return CJS_Return(JSMessage::kBadObjectError); WideString& Value = pEvent->Value(); - ByteString strValue = StrTrim(ByteString::FromUnicode(Value)); + ByteString strValue = StrTrim(Value.ToDefANSI()); if (strValue.IsEmpty()) return CJS_Return(); @@ -1683,7 +1683,7 @@ CJS_Return CJS_PublicMethods::AFRange_Validate( if (pEvent->Value().IsEmpty()) return CJS_Return(); - double dEentValue = atof(ByteString::FromUnicode(pEvent->Value()).c_str()); + double dEentValue = atof(pEvent->Value().ToDefANSI().c_str()); bool bGreaterThan = pRuntime->ToBoolean(params[0]); double dGreaterThan = pRuntime->ToDouble(params[1]); bool bLessThan = pRuntime->ToBoolean(params[2]); -- cgit v1.2.3