Rename WideString::{UTF8,UTF16LE}_Encode() to To{UTF8,UTF16LE}().

Make consistent with ToDefANSI().

Change-Id: I576f5a8a2bb3f633c7dca67efd7712fa610acf4d
Reviewed-on: https://pdfium-review.googlesource.com/c/45791
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fxjs/cfxjse_engine.cpp b/fxjs/cfxjse_engine.cpp
index 70cacbb..d46c4bb 100644
--- a/fxjs/cfxjse_engine.cpp
+++ b/fxjs/cfxjse_engine.cpp
@@ -508,7 +508,7 @@
   if (!wsScript)
     return false;
 
-  ByteString btScript = wsScript->UTF8Encode();
+  ByteString btScript = wsScript->ToUTF8();
   auto hRetValue = pdfium::MakeUnique<CFXJSE_Value>(GetIsolate());
   CXFA_Node* pThisObject = pParent->GetParent();
   CFXJSE_Context* pVariablesContext =
diff --git a/fxjs/cfxjse_formcalc_context.cpp b/fxjs/cfxjse_formcalc_context.cpp
index 848c693..f577e32 100644
--- a/fxjs/cfxjse_formcalc_context.cpp
+++ b/fxjs/cfxjse_formcalc_context.cpp
@@ -504,7 +504,7 @@
                               : pLocale->GetTimePattern(category);
   if (!bStandard)
     AlternateDateTimeSymbols(&strRet, pLocale->GetDateTimeSymbols(), bIsDate);
-  return strRet.UTF8Encode();
+  return strRet.ToUTF8();
 }
 
 bool IsWhitespace(char c) {
@@ -2713,7 +2713,7 @@
   WideString wsRet;
   CXFA_LocaleValue(XFA_VT_DATE, WideString::FromUTF8(szDate), pMgr)
       .FormatPatterns(wsRet, wsFormat, pLocale, XFA_VALUEPICTURE_Display);
-  return wsRet.UTF8Encode();
+  return wsRet.ToUTF8();
 }
 
 // static
@@ -2737,7 +2737,7 @@
   WideString wsRet;
   widgetValue.FormatPatterns(wsRet, wsFormat, pLocale,
                              XFA_VALUEPICTURE_Display);
-  return wsRet.UTF8Encode();
+  return wsRet.ToUTF8();
 }
 
 // static
@@ -3971,7 +3971,7 @@
     return;
   }
 
-  args.GetReturnValue()->SetString(wsRet.UTF8Encode().AsStringView());
+  args.GetReturnValue()->SetString(wsRet.ToUTF8().AsStringView());
 }
 
 // static
@@ -4106,7 +4106,7 @@
       return;
     }
     args.GetReturnValue()->SetString(
-        localeValue.GetValue().UTF8Encode().AsStringView());
+        localeValue.GetValue().ToUTF8().AsStringView());
     return;
   }
 
@@ -4130,7 +4130,7 @@
         return;
       }
       args.GetReturnValue()->SetString(
-          localeValue.GetValue().UTF8Encode().AsStringView());
+          localeValue.GetValue().ToUTF8().AsStringView());
       return;
     }
     case XFA_VT_DATE: {
@@ -4142,7 +4142,7 @@
         return;
       }
       args.GetReturnValue()->SetString(
-          localeValue.GetValue().UTF8Encode().AsStringView());
+          localeValue.GetValue().ToUTF8().AsStringView());
       return;
     }
     case XFA_VT_TIME: {
@@ -4154,7 +4154,7 @@
         return;
       }
       args.GetReturnValue()->SetString(
-          localeValue.GetValue().UTF8Encode().AsStringView());
+          localeValue.GetValue().ToUTF8().AsStringView());
       return;
     }
     case XFA_VT_TEXT: {
@@ -4166,7 +4166,7 @@
         return;
       }
       args.GetReturnValue()->SetString(
-          localeValue.GetValue().UTF8Encode().AsStringView());
+          localeValue.GetValue().ToUTF8().AsStringView());
       return;
     }
     case XFA_VT_FLOAT: {
@@ -4197,7 +4197,7 @@
         return;
       }
       args.GetReturnValue()->SetString(
-          localeValue2.GetValue().UTF8Encode().AsStringView());
+          localeValue2.GetValue().ToUTF8().AsStringView());
       return;
     }
   }
@@ -4721,7 +4721,7 @@
     pContext->ThrowServerDeniedException();
     return;
   }
-  args.GetReturnValue()->SetString(decodedResponse.UTF8Encode().AsStringView());
+  args.GetReturnValue()->SetString(decodedResponse.ToUTF8().AsStringView());
 }
 
 // static
@@ -6235,5 +6235,5 @@
 
 void CFXJSE_FormCalcContext::ThrowException(const WideString& str) const {
   ASSERT(!str.IsEmpty());
-  FXJSE_ThrowMessage(str.UTF8Encode().AsStringView());
+  FXJSE_ThrowMessage(str.ToUTF8().AsStringView());
 }
diff --git a/fxjs/cjs_global.cpp b/fxjs/cjs_global.cpp
index 176872f..523d88e 100644
--- a/fxjs/cjs_global.cpp
+++ b/fxjs/cjs_global.cpp
@@ -413,7 +413,7 @@
                                CFX_GlobalArray* pArray) {
   std::vector<WideString> pKeyList = pRuntime->GetObjectPropertyNames(pObj);
   for (const auto& ws : pKeyList) {
-    ByteString sKey = ws.UTF8Encode();
+    ByteString sKey = ws.ToUTF8();
     v8::Local<v8::Value> v = pRuntime->GetObjectProperty(pObj, ws);
     if (v->IsNumber()) {
       auto pObjElement = pdfium::MakeUnique<CFX_KeyValue>();
diff --git a/fxjs/xfa/cjx_draw.cpp b/fxjs/xfa/cjx_draw.cpp
index 1754506..8408d85 100644
--- a/fxjs/xfa/cjx_draw.cpp
+++ b/fxjs/xfa/cjx_draw.cpp
@@ -111,7 +111,7 @@
     if (content.IsEmpty())
       pValue->SetNull();
     else
-      pValue->SetString(content.UTF8Encode().AsStringView());
+      pValue->SetString(content.ToUTF8().AsStringView());
 
     return;
   }
diff --git a/fxjs/xfa/cjx_eventpseudomodel.cpp b/fxjs/xfa/cjx_eventpseudomodel.cpp
index b80f8f3..494681a 100644
--- a/fxjs/xfa/cjx_eventpseudomodel.cpp
+++ b/fxjs/xfa/cjx_eventpseudomodel.cpp
@@ -24,7 +24,7 @@
     return;
   }
 
-  pReturn->SetString(wsValue->UTF8Encode().AsStringView());
+  pReturn->SetString(wsValue->ToUTF8().AsStringView());
 }
 
 void InterProperty(CFXJSE_Value* pReturn, int32_t* iValue, bool bSetting) {
@@ -112,7 +112,7 @@
   if (!pEventParam)
     return;
 
-  pValue->SetString(pEventParam->GetNewText().UTF8Encode().AsStringView());
+  pValue->SetString(pEventParam->GetNewText().ToUTF8().AsStringView());
 }
 
 void CJX_EventPseudoModel::prevContentType(CFXJSE_Value* pValue,
diff --git a/fxjs/xfa/cjx_exclgroup.cpp b/fxjs/xfa/cjx_exclgroup.cpp
index a5ddc94..a076e68 100644
--- a/fxjs/xfa/cjx_exclgroup.cpp
+++ b/fxjs/xfa/cjx_exclgroup.cpp
@@ -130,7 +130,7 @@
     pValue->SetNull();
     return;
   }
-  pValue->SetString(wsValue.UTF8Encode().AsStringView());
+  pValue->SetString(wsValue.ToUTF8().AsStringView());
 }
 
 void CJX_ExclGroup::rawValue(CFXJSE_Value* pValue,
diff --git a/fxjs/xfa/cjx_field.cpp b/fxjs/xfa/cjx_field.cpp
index 453bac0..d22cf4e 100644
--- a/fxjs/xfa/cjx_field.cpp
+++ b/fxjs/xfa/cjx_field.cpp
@@ -110,7 +110,7 @@
     return CJS_Result::Success(runtime->NewNull());
 
   return CJS_Result::Success(
-      runtime->NewString(value->UTF8Encode().AsStringView()));
+      runtime->NewString(value->ToUTF8().AsStringView()));
 }
 
 CJS_Result CJX_Field::boundItem(
@@ -126,7 +126,7 @@
   WideString value = runtime->ToWideString(params[0]);
   WideString boundValue = node->GetItemValue(value.AsStringView());
   return CJS_Result::Success(
-      runtime->NewString(boundValue.UTF8Encode().AsStringView()));
+      runtime->NewString(boundValue.ToUTF8().AsStringView()));
 }
 
 CJS_Result CJX_Field::getItemState(
@@ -176,7 +176,7 @@
     return CJS_Result::Success(runtime->NewNull());
 
   return CJS_Result::Success(
-      runtime->NewString(value->UTF8Encode().AsStringView()));
+      runtime->NewString(value->ToUTF8().AsStringView()));
 }
 
 CJS_Result CJX_Field::setItemState(
@@ -276,7 +276,7 @@
     if (xfaNode->GetUIChildNode()->GetElementType() ==
             XFA_Element::NumericEdit &&
         (pNode->JSObject()->GetInteger(XFA_Attribute::FracDigits) == -1)) {
-      pValue->SetString(content.UTF8Encode().AsStringView());
+      pValue->SetString(content.ToUTF8().AsStringView());
     } else {
       CFX_Decimal decimal(content.AsStringView());
       pValue->SetFloat((float)(double)decimal);
@@ -289,7 +289,7 @@
     CFX_Decimal decimal(content.AsStringView());
     pValue->SetFloat((float)(double)decimal);
   } else {
-    pValue->SetString(content.UTF8Encode().AsStringView());
+    pValue->SetString(content.ToUTF8().AsStringView());
   }
 }
 
@@ -305,7 +305,7 @@
     return;
   }
   pValue->SetString(
-      node->GetValue(XFA_VALUEPICTURE_Edit).UTF8Encode().AsStringView());
+      node->GetValue(XFA_VALUEPICTURE_Edit).ToUTF8().AsStringView());
 }
 
 void CJX_Field::formatMessage(CFXJSE_Value* pValue,
@@ -326,7 +326,7 @@
     return;
   }
   pValue->SetString(
-      node->GetValue(XFA_VALUEPICTURE_Display).UTF8Encode().AsStringView());
+      node->GetValue(XFA_VALUEPICTURE_Display).ToUTF8().AsStringView());
 }
 
 void CJX_Field::parentSubform(CFXJSE_Value* pValue,
diff --git a/fxjs/xfa/cjx_hostpseudomodel.cpp b/fxjs/xfa/cjx_hostpseudomodel.cpp
index 748641a..d6899cf 100644
--- a/fxjs/xfa/cjx_hostpseudomodel.cpp
+++ b/fxjs/xfa/cjx_hostpseudomodel.cpp
@@ -130,7 +130,7 @@
     return;
   }
   pValue->SetString(
-      pNotify->GetAppProvider()->GetLanguage().UTF8Encode().AsStringView());
+      pNotify->GetAppProvider()->GetLanguage().ToUTF8().AsStringView());
 }
 
 void CJX_HostPseudoModel::numPages(CFXJSE_Value* pValue,
@@ -160,7 +160,7 @@
     return;
   }
   pValue->SetString(
-      pNotify->GetAppProvider()->GetPlatform().UTF8Encode().AsStringView());
+      pNotify->GetAppProvider()->GetPlatform().ToUTF8().AsStringView());
 }
 
 void CJX_HostPseudoModel::title(CFXJSE_Value* pValue,
@@ -181,7 +181,7 @@
 
   WideString wsTitle;
   hDoc->GetDocEnvironment()->GetTitle(hDoc, wsTitle);
-  pValue->SetString(wsTitle.UTF8Encode().AsStringView());
+  pValue->SetString(wsTitle.ToUTF8().AsStringView());
 }
 
 void CJX_HostPseudoModel::validationsEnabled(CFXJSE_Value* pValue,
@@ -236,7 +236,7 @@
     return;
   }
   pValue->SetString(
-      pNotify->GetAppProvider()->GetAppName().UTF8Encode().AsStringView());
+      pNotify->GetAppProvider()->GetAppName().ToUTF8().AsStringView());
 }
 
 CJS_Result CJX_HostPseudoModel::gotoURL(
@@ -340,7 +340,7 @@
   WideString answer =
       pNotify->GetAppProvider()->Response(question, title, defaultAnswer, mark);
   return CJS_Result::Success(
-      runtime->NewString(answer.UTF8Encode().AsStringView()));
+      runtime->NewString(answer.ToUTF8().AsStringView()));
 }
 
 CJS_Result CJX_HostPseudoModel::documentInBatch(
diff --git a/fxjs/xfa/cjx_node.cpp b/fxjs/xfa/cjx_node.cpp
index c78ddcc..d26b9b1 100644
--- a/fxjs/xfa/cjx_node.cpp
+++ b/fxjs/xfa/cjx_node.cpp
@@ -152,7 +152,7 @@
 
   WideString expression = runtime->ToWideString(params[0]);
   return CJS_Result::Success(runtime->NewString(
-      GetAttribute(expression.AsStringView()).UTF8Encode().AsStringView()));
+      GetAttribute(expression.AsStringView()).ToUTF8().AsStringView()));
 }
 
 CJS_Result CJX_Node::getElement(
@@ -406,7 +406,7 @@
     return;
   }
   pValue->SetString(
-      TryNamespace().value_or(WideString()).UTF8Encode().AsStringView());
+      TryNamespace().value_or(WideString()).ToUTF8().AsStringView());
 }
 
 void CJX_Node::model(CFXJSE_Value* pValue,
diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp
index 44ebcc9..c4520bf 100644
--- a/fxjs/xfa/cjx_object.cpp
+++ b/fxjs/xfa/cjx_object.cpp
@@ -165,13 +165,13 @@
 }
 
 bool CJX_Object::HasMethod(const WideString& func) const {
-  return pdfium::ContainsKey(method_specs_, func.UTF8Encode());
+  return pdfium::ContainsKey(method_specs_, func.ToUTF8());
 }
 
 CJS_Result CJX_Object::RunMethod(
     const WideString& func,
     const std::vector<v8::Local<v8::Value>>& params) {
-  auto it = method_specs_.find(func.UTF8Encode());
+  auto it = method_specs_.find(func.ToUTF8());
   if (it == method_specs_.end())
     return CJS_Result::Failure(JSMessage::kUnknownMethod);
 
@@ -204,7 +204,7 @@
 
 void CJX_Object::ThrowException(const WideString& str) const {
   ASSERT(!str.IsEmpty());
-  FXJSE_ThrowMessage(str.UTF8Encode().AsStringView());
+  FXJSE_ThrowMessage(str.ToUTF8().AsStringView());
 }
 
 bool CJX_Object::HasAttribute(XFA_Attribute eAttr) {
@@ -1145,7 +1145,7 @@
                                          bool bSetting,
                                          XFA_Attribute eAttribute) {
   if (!bSetting) {
-    pValue->SetString(GetAttribute(eAttribute).UTF8Encode().AsStringView());
+    pValue->SetString(GetAttribute(eAttribute).ToUTF8().AsStringView());
     return;
   }
 
@@ -1278,7 +1278,7 @@
   int32_t b;
   std::tie(a, r, g, b) = ArgbDecode(color);
   pValue->SetString(
-      WideString::Format(L"%d,%d,%d", r, g, b).UTF8Encode().AsStringView());
+      WideString::Format(L"%d,%d,%d", r, g, b).ToUTF8().AsStringView());
 }
 
 void CJX_Object::Script_Som_BorderColor(CFXJSE_Value* pValue,
@@ -1309,7 +1309,7 @@
   int32_t b;
   std::tie(a, r, g, b) = ArgbDecode(color);
   pValue->SetString(
-      WideString::Format(L"%d,%d,%d", r, g, b).UTF8Encode().AsStringView());
+      WideString::Format(L"%d,%d,%d", r, g, b).ToUTF8().AsStringView());
 }
 
 void CJX_Object::Script_Som_BorderWidth(CFXJSE_Value* pValue,
@@ -1320,7 +1320,7 @@
     CXFA_Edge* edge = border->GetEdgeIfExists(0);
     CXFA_Measurement thickness =
         edge ? edge->GetMSThickness() : CXFA_Measurement(0.5, XFA_Unit::Pt);
-    pValue->SetString(thickness.ToString().UTF8Encode().AsStringView());
+    pValue->SetString(thickness.ToString().ToUTF8().AsStringView());
     return;
   }
 
@@ -1389,7 +1389,7 @@
     default:
       break;
   }
-  pValue->SetString(wsMessage.UTF8Encode().AsStringView());
+  pValue->SetString(wsMessage.ToUTF8().AsStringView());
 }
 
 void CJX_Object::Script_Som_ValidationMessage(CFXJSE_Value* pValue,
@@ -1489,7 +1489,7 @@
     CFX_Decimal decimal(content.AsStringView());
     pValue->SetFloat((float)(double)decimal);
   } else {
-    pValue->SetString(content.UTF8Encode().AsStringView());
+    pValue->SetString(content.ToUTF8().AsStringView());
   }
 }
 
@@ -1506,7 +1506,7 @@
     pValue->SetNull();
     return;
   }
-  pValue->SetString(content.UTF8Encode().AsStringView());
+  pValue->SetString(content.ToUTF8().AsStringView());
 }
 
 void CJX_Object::Script_Som_DataNode(CFXJSE_Value* pValue,
@@ -1541,7 +1541,7 @@
   }
 
   WideString str = CXFA_Node::AttributeEnumToName(validate->GetNullTest());
-  pValue->SetString(str.UTF8Encode().AsStringView());
+  pValue->SetString(str.ToUTF8().AsStringView());
 }
 
 void CJX_Object::Script_Som_InstanceIndex(CFXJSE_Value* pValue,
@@ -1628,7 +1628,7 @@
   }
 
   Optional<WideString> checksum = TryAttribute(XFA_Attribute::Checksum, false);
-  pValue->SetString(checksum ? checksum->UTF8Encode().AsStringView() : "");
+  pValue->SetString(checksum ? checksum->ToUTF8().AsStringView() : "");
 }
 
 void CJX_Object::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue,
diff --git a/fxjs/xfa/cjx_packet.cpp b/fxjs/xfa/cjx_packet.cpp
index 2f5f307..87d67de 100644
--- a/fxjs/xfa/cjx_packet.cpp
+++ b/fxjs/xfa/cjx_packet.cpp
@@ -41,7 +41,7 @@
     attributeValue = element->GetAttribute(runtime->ToWideString(params[0]));
 
   return CJS_Result::Success(
-      runtime->NewString(attributeValue.UTF8Encode().AsStringView()));
+      runtime->NewString(attributeValue.ToUTF8().AsStringView()));
 }
 
 CJS_Result CJX_Packet::setAttribute(
@@ -94,5 +94,5 @@
   if (element)
     wsTextData = element->GetTextData();
 
-  pValue->SetString(wsTextData.UTF8Encode().AsStringView());
+  pValue->SetString(wsTextData.ToUTF8().AsStringView());
 }
diff --git a/fxjs/xfa/cjx_subform.cpp b/fxjs/xfa/cjx_subform.cpp
index 2fd0957..9487bc1 100644
--- a/fxjs/xfa/cjx_subform.cpp
+++ b/fxjs/xfa/cjx_subform.cpp
@@ -90,7 +90,7 @@
   }
 
   WideString wsLocaleName = GetXFANode()->GetLocaleName().value_or(L"");
-  pValue->SetString(wsLocaleName.UTF8Encode().AsStringView());
+  pValue->SetString(wsLocaleName.ToUTF8().AsStringView());
 }
 
 void CJX_Subform::instanceIndex(CFXJSE_Value* pValue,
diff --git a/fxjs/xfa/cjx_tree.cpp b/fxjs/xfa/cjx_tree.cpp
index 5921f8b..c42355f 100644
--- a/fxjs/xfa/cjx_tree.cpp
+++ b/fxjs/xfa/cjx_tree.cpp
@@ -145,7 +145,7 @@
 
   if (bSetting) {
     WideString wsMessage = L"Unable to set ";
-    FXJSE_ThrowMessage(wsMessage.UTF8Encode().AsStringView());
+    FXJSE_ThrowMessage(wsMessage.ToUTF8().AsStringView());
     return;
   }
 
@@ -213,7 +213,7 @@
   }
 
   WideString wsSOMExpression = GetXFAObject()->GetSOMExpression();
-  pValue->SetString(wsSOMExpression.UTF8Encode().AsStringView());
+  pValue->SetString(wsSOMExpression.ToUTF8().AsStringView());
 }
 
 void CJX_Tree::ResolveNodeList(CFXJSE_Value* pValue,