Add WideString::{From,To}Latin1().

Also fix a typo in WideString::FromASCII()'s unit test.

Change-Id: I0cbed4e490347242a4750bd1b35c94a49dae8f85
Reviewed-on: https://pdfium-review.googlesource.com/c/48211
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/widestring.cpp b/core/fxcrt/widestring.cpp
index 038b302..76d596c 100644
--- a/core/fxcrt/widestring.cpp
+++ b/core/fxcrt/widestring.cpp
@@ -644,6 +644,14 @@
   return result;
 }
 
+ByteString WideString::ToLatin1() const {
+  ByteString result;
+  result.Reserve(GetLength());
+  for (wchar_t wc : *this)
+    result.InsertAtBack(static_cast<char>(wc & 0xff));
+  return result;
+}
+
 ByteString WideString::ToDefANSI() const {
   int src_len = GetLength();
   int dest_len = FXSYS_WideCharToMultiByte(
@@ -879,6 +887,15 @@
 }
 
 // static
+WideString WideString::FromLatin1(ByteStringView bstr) {
+  WideString result;
+  result.Reserve(bstr.GetLength());
+  for (char c : bstr)
+    result.InsertAtBack(static_cast<wchar_t>(c & 0xff));
+  return result;
+}
+
+// static
 WideString WideString::FromDefANSI(ByteStringView bstr) {
   int src_len = bstr.GetLength();
   int dest_len = FXSYS_MultiByteToWideChar(