Fix nits in CXFA_Node.

- Make methods const or move them into the anonymous namespace.
- Make GetItemLabel() return the value.

Change-Id: Ic6938d14e7efa09f1851950c28d3c855690d9aaf
Reviewed-on: https://pdfium-review.googlesource.com/40650
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index a60e665..6b30f79 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -368,6 +368,42 @@
   return fThickness;
 }
 
+WideString FormatNumStr(const WideString& wsValue, LocaleIface* pLocale) {
+  if (wsValue.IsEmpty())
+    return L"";
+
+  WideString wsSrcNum = wsValue;
+  WideString wsGroupSymbol = pLocale->GetGroupingSymbol();
+  bool bNeg = false;
+  if (wsSrcNum[0] == '-') {
+    bNeg = true;
+    wsSrcNum.Delete(0, 1);
+  }
+
+  auto dot_index = wsSrcNum.Find('.');
+  dot_index = !dot_index.has_value() ? wsSrcNum.GetLength() : dot_index;
+
+  if (dot_index.value() < 1)
+    return L"";
+
+  size_t nPos = dot_index.value() % 3;
+  WideString wsOutput;
+  for (size_t i = 0; i < dot_index.value(); i++) {
+    if (i % 3 == nPos && i != 0)
+      wsOutput += wsGroupSymbol;
+
+    wsOutput += wsSrcNum[i];
+  }
+  if (dot_index.value() < wsSrcNum.GetLength()) {
+    wsOutput += pLocale->GetDecimalSymbol();
+    wsOutput += wsSrcNum.Right(wsSrcNum.GetLength() - dot_index.value() - 1);
+  }
+  if (bNeg)
+    return pLocale->GetMinusSymbol() + wsOutput;
+
+  return wsOutput;
+}
+
 }  // namespace
 
 class CXFA_WidgetLayoutData {
@@ -3050,7 +3086,7 @@
   return fWidthCalc;
 }
 
-float CXFA_Node::GetWidthWithoutMargin(float fWidthCalc) {
+float CXFA_Node::GetWidthWithoutMargin(float fWidthCalc) const {
   CXFA_Margin* margin = GetMarginIfExists();
   if (margin)
     fWidthCalc -= margin->GetLeftInset() + margin->GetRightInset();
@@ -3073,7 +3109,7 @@
   return fHeightCalc;
 }
 
-float CXFA_Node::GetHeightWithoutMargin(float fHeightCalc) {
+float CXFA_Node::GetHeightWithoutMargin(float fHeightCalc) const {
   CXFA_Margin* margin = GetMarginIfExists();
   if (margin)
     fHeightCalc -= margin->GetTopInset() + margin->GetBottomInset();
@@ -4079,22 +4115,17 @@
                                                     wsValue.c_str(), nIndex);
 }
 
-void CXFA_Node::GetItemLabel(const WideStringView& wsValue,
-                             WideString& wsLabel) {
-  int32_t iCount = 0;
+WideString CXFA_Node::GetItemLabel(const WideStringView& wsValue) const {
   std::vector<CXFA_Node*> listitems;
   CXFA_Node* pItems = GetFirstChild();
   for (; pItems; pItems = pItems->GetNextSibling()) {
     if (pItems->GetElementType() != XFA_Element::Items)
       continue;
-    iCount++;
     listitems.push_back(pItems);
   }
 
-  if (iCount <= 1) {
-    wsLabel = wsValue;
-    return;
-  }
+  if (listitems.size() <= 1)
+    return WideString(wsValue);
 
   CXFA_Node* pLabelItems = listitems[0];
   bool bSave = pLabelItems->JSObject()->GetBoolean(XFA_Attribute::Save);
@@ -4105,8 +4136,8 @@
   } else {
     pSaveItems = listitems[1];
   }
-  iCount = 0;
 
+  int32_t iCount = 0;
   int32_t iSearch = -1;
   for (CXFA_Node* pChildItem = pSaveItems->GetFirstChild(); pChildItem;
        pChildItem = pChildItem->GetNextSibling()) {
@@ -4117,12 +4148,11 @@
     iCount++;
   }
   if (iSearch < 0)
-    return;
+    return WideString();
 
   CXFA_Node* pText =
       pLabelItems->GetChild<CXFA_Node>(iSearch, XFA_Element::Unknown, false);
-  if (pText)
-    wsLabel = pText->JSObject()->GetContent(false);
+  return pText ? pText->JSObject()->GetContent(false) : WideString();
 }
 
 WideString CXFA_Node::GetItemValue(const WideStringView& wsLabel) {
@@ -4413,7 +4443,7 @@
   WideString wsValue = JSObject()->GetContent(false);
 
   if (eValueType == XFA_VALUEPICTURE_Display)
-    GetItemLabel(wsValue.AsStringView(), wsValue);
+    wsValue = GetItemLabel(wsValue.AsStringView());
 
   WideString wsPicture = GetPictureContent(eValueType);
   CXFA_Node* pNode = GetUIChildNode();
@@ -4592,43 +4622,6 @@
   return wsOutput;
 }
 
-WideString CXFA_Node::FormatNumStr(const WideString& wsValue,
-                                   LocaleIface* pLocale) {
-  if (wsValue.IsEmpty())
-    return L"";
-
-  WideString wsSrcNum = wsValue;
-  WideString wsGroupSymbol = pLocale->GetGroupingSymbol();
-  bool bNeg = false;
-  if (wsSrcNum[0] == '-') {
-    bNeg = true;
-    wsSrcNum.Delete(0, 1);
-  }
-
-  auto dot_index = wsSrcNum.Find('.');
-  dot_index = !dot_index.has_value() ? wsSrcNum.GetLength() : dot_index;
-
-  if (dot_index.value() < 1)
-    return L"";
-
-  size_t nPos = dot_index.value() % 3;
-  WideString wsOutput;
-  for (size_t i = 0; i < dot_index.value(); i++) {
-    if (i % 3 == nPos && i != 0)
-      wsOutput += wsGroupSymbol;
-
-    wsOutput += wsSrcNum[i];
-  }
-  if (dot_index.value() < wsSrcNum.GetLength()) {
-    wsOutput += pLocale->GetDecimalSymbol();
-    wsOutput += wsSrcNum.Right(wsSrcNum.GetLength() - dot_index.value() - 1);
-  }
-  if (bNeg)
-    return pLocale->GetMinusSymbol() + wsOutput;
-
-  return wsOutput;
-}
-
 void CXFA_Node::InsertListTextItem(CXFA_Node* pItems,
                                    const WideString& wsText,
                                    int32_t nIndex) {
diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h
index 99930c6..72e2a4e 100644
--- a/xfa/fxfa/parser/cxfa_node.h
+++ b/xfa/fxfa/parser/cxfa_node.h
@@ -450,8 +450,8 @@
   bool CalculateImageAutoSize(CXFA_FFDoc* doc, CFX_SizeF* pSize);
   float CalculateWidgetAutoHeight(float fHeightCalc);
   float CalculateWidgetAutoWidth(float fWidthCalc);
-  float GetWidthWithoutMargin(float fWidthCalc);
-  float GetHeightWithoutMargin(float fHeightCalc);
+  float GetWidthWithoutMargin(float fWidthCalc) const;
+  float GetHeightWithoutMargin(float fHeightCalc) const;
   void CalculateTextContentSize(CXFA_FFDoc* doc, CFX_SizeF* pSize);
   CFX_SizeF CalculateAccWidthAndHeight(CXFA_FFDoc* doc, float fWidth);
   void InitLayoutData();
@@ -460,8 +460,7 @@
   void InsertListTextItem(CXFA_Node* pItems,
                           const WideString& wsText,
                           int32_t nIndex);
-  WideString FormatNumStr(const WideString& wsValue, LocaleIface* pLocale);
-  void GetItemLabel(const WideStringView& wsValue, WideString& wsLabel);
+  WideString GetItemLabel(const WideStringView& wsValue) const;
 
   std::pair<XFA_FFWidgetType, CXFA_Ui*> CreateChildUIAndValueNodesIfNeeded();
   void CreateValueNodeIfNeeded(CXFA_Value* value, CXFA_Node* pUIChild);