Convert CXFA_Node::GetLocaleName out param to return

Change-Id: Ia135db144c7037795fc1a1964b4f3eee57250caa
Reviewed-on: https://pdfium-review.googlesource.com/22350
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
diff --git a/fxjs/xfa/cjx_subform.cpp b/fxjs/xfa/cjx_subform.cpp
index a388505..947d66d 100644
--- a/fxjs/xfa/cjx_subform.cpp
+++ b/fxjs/xfa/cjx_subform.cpp
@@ -86,8 +86,7 @@
     return;
   }
 
-  WideString wsLocaleName;
-  GetXFANode()->GetLocaleName(wsLocaleName);
+  WideString wsLocaleName = GetXFANode()->GetLocaleName().value_or(L"");
   pValue->SetString(wsLocaleName.UTF8Encode().AsStringView());
 }
 
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index 08af200..141c9f1 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -620,15 +620,15 @@
 }
 
 IFX_Locale* CXFA_Node::GetLocale() {
-  WideString wsLocaleName;
-  if (!GetLocaleName(wsLocaleName))
+  Optional<WideString> localeName = GetLocaleName();
+  if (!localeName)
     return nullptr;
-  if (wsLocaleName == L"ambient")
+  if (localeName.value() == L"ambient")
     return GetDocument()->GetLocalMgr()->GetDefLocale();
-  return GetDocument()->GetLocalMgr()->GetLocaleByName(wsLocaleName);
+  return GetDocument()->GetLocalMgr()->GetLocaleByName(localeName.value());
 }
 
-bool CXFA_Node::GetLocaleName(WideString& wsLocaleName) {
+Optional<WideString> CXFA_Node::GetLocaleName() {
   CXFA_Node* pForm = GetDocument()->GetXFAObject(XFA_HASHCODE_Form)->AsNode();
   CXFA_Subform* pTopSubform =
       pForm->GetFirstChildByClass<CXFA_Subform>(XFA_Element::Subform);
@@ -636,35 +636,32 @@
 
   CXFA_Node* pLocaleNode = this;
   do {
-    Optional<WideString> ret =
+    Optional<WideString> localeName =
         pLocaleNode->JSObject()->TryCData(XFA_Attribute::Locale, false);
-    if (ret) {
-      wsLocaleName = *ret;
-      return true;
-    }
+    if (localeName)
+      return localeName;
+
     pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent);
   } while (pLocaleNode && pLocaleNode != pTopSubform);
 
   CXFA_Node* pConfig = ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Config));
-  wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig);
-  if (!wsLocaleName.IsEmpty())
-    return true;
+  Optional<WideString> localeName = {
+      WideString(GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig))};
+  if (localeName && !localeName->IsEmpty())
+    return localeName;
 
   if (pTopSubform) {
-    Optional<WideString> ret =
+    localeName =
         pTopSubform->JSObject()->TryCData(XFA_Attribute::Locale, false);
-    if (ret) {
-      wsLocaleName = *ret;
-      return true;
-    }
+    if (localeName)
+      return localeName;
   }
 
   IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale();
   if (!pLocale)
-    return false;
+    return {};
 
-  wsLocaleName = pLocale->GetName();
-  return true;
+  return {pLocale->GetName()};
 }
 
 XFA_AttributeEnum CXFA_Node::GetIntact() {
diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h
index dea53e4..c8adbfe 100644
--- a/xfa/fxfa/parser/cxfa_node.h
+++ b/xfa/fxfa/parser/cxfa_node.h
@@ -185,7 +185,7 @@
   CXFA_WidgetAcc* GetWidgetAcc();
   CXFA_WidgetAcc* GetContainerWidgetAcc();
   IFX_Locale* GetLocale();
-  bool GetLocaleName(WideString& wsLocaleName);
+  Optional<WideString> GetLocaleName();
   XFA_AttributeEnum GetIntact();
 
   CXFA_Node* GetFirstChildByName(const WideStringView& wsNodeName) const;