De-duplicate some code between cxfa_node.cpp and cxfa_util.cpp Introduce XFA_GetLocaleValueType() helper function. Change-Id: Idd7104753eeed8d0ab1019aaf7dd5c43ccee003c Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/80831 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 16335e0..b8ff3fb 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -4897,36 +4897,8 @@ if (!pValueChild) return wsValue; - CXFA_LocaleValue::ValueType iVTType; - switch (pValueChild->GetElementType()) { - case XFA_Element::Decimal: - iVTType = CXFA_LocaleValue::ValueType::kDecimal; - break; - case XFA_Element::Float: - iVTType = CXFA_LocaleValue::ValueType::kFloat; - break; - case XFA_Element::Date: - iVTType = CXFA_LocaleValue::ValueType::kDate; - break; - case XFA_Element::Time: - iVTType = CXFA_LocaleValue::ValueType::kTime; - break; - case XFA_Element::DateTime: - iVTType = CXFA_LocaleValue::ValueType::kDateTime; - break; - case XFA_Element::Boolean: - iVTType = CXFA_LocaleValue::ValueType::kBoolean; - break; - case XFA_Element::Integer: - iVTType = CXFA_LocaleValue::ValueType::kInteger; - break; - case XFA_Element::Text: - iVTType = CXFA_LocaleValue::ValueType::kText; - break; - default: - iVTType = CXFA_LocaleValue::ValueType::kNull; - break; - } + CXFA_LocaleValue::ValueType iVTType = + XFA_GetLocaleValueType(pValueChild->GetElementType()); CXFA_LocaleMgr* pLocaleMgr = GetDocument()->GetLocaleMgr(); CXFA_LocaleValue widgetValue(iVTType, wsValue, pLocaleMgr); switch (widgetValue.GetType()) {
diff --git a/xfa/fxfa/parser/xfa_utils.cpp b/xfa/fxfa/parser/xfa_utils.cpp index 451060a..b4c05ca 100644 --- a/xfa/fxfa/parser/xfa_utils.cpp +++ b/xfa/fxfa/parser/xfa_utils.cpp
@@ -22,7 +22,6 @@ #include "third_party/base/stl_util.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_localemgr.h" -#include "xfa/fxfa/parser/cxfa_localevalue.h" #include "xfa/fxfa/parser/cxfa_measurement.h" #include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_ui.h" @@ -386,40 +385,34 @@ if (!pValueChild) return CXFA_LocaleValue(); - CXFA_LocaleValue::ValueType iVTType; - switch (pValueChild->GetElementType()) { - case XFA_Element::Decimal: - iVTType = CXFA_LocaleValue::ValueType::kDecimal; - break; - case XFA_Element::Float: - iVTType = CXFA_LocaleValue::ValueType::kFloat; - break; - case XFA_Element::Date: - iVTType = CXFA_LocaleValue::ValueType::kDate; - break; - case XFA_Element::Time: - iVTType = CXFA_LocaleValue::ValueType::kTime; - break; - case XFA_Element::DateTime: - iVTType = CXFA_LocaleValue::ValueType::kDateTime; - break; - case XFA_Element::Boolean: - iVTType = CXFA_LocaleValue::ValueType::kBoolean; - break; - case XFA_Element::Integer: - iVTType = CXFA_LocaleValue::ValueType::kInteger; - break; - case XFA_Element::Text: - iVTType = CXFA_LocaleValue::ValueType::kText; - break; - default: - iVTType = CXFA_LocaleValue::ValueType::kNull; - break; - } - return CXFA_LocaleValue(iVTType, pNode->GetRawValue(), + return CXFA_LocaleValue(XFA_GetLocaleValueType(pValueChild->GetElementType()), + pNode->GetRawValue(), pNode->GetDocument()->GetLocaleMgr()); } +CXFA_LocaleValue::ValueType XFA_GetLocaleValueType(XFA_Element element) { + switch (element) { + case XFA_Element::Decimal: + return CXFA_LocaleValue::ValueType::kDecimal; + case XFA_Element::Float: + return CXFA_LocaleValue::ValueType::kFloat; + case XFA_Element::Date: + return CXFA_LocaleValue::ValueType::kDate; + case XFA_Element::Time: + return CXFA_LocaleValue::ValueType::kTime; + case XFA_Element::DateTime: + return CXFA_LocaleValue::ValueType::kDateTime; + case XFA_Element::Boolean: + return CXFA_LocaleValue::ValueType::kBoolean; + case XFA_Element::Integer: + return CXFA_LocaleValue::ValueType::kInteger; + case XFA_Element::Text: + return CXFA_LocaleValue::ValueType::kText; + default: + return CXFA_LocaleValue::ValueType::kNull; + } +} + bool XFA_FDEExtension_ResolveNamespaceQualifier(CFX_XMLElement* pNode, const WideString& wsQualifier, WideString* wsNamespaceURI) {
diff --git a/xfa/fxfa/parser/xfa_utils.h b/xfa/fxfa/parser/xfa_utils.h index 2a43b43..704aec1 100644 --- a/xfa/fxfa/parser/xfa_utils.h +++ b/xfa/fxfa/parser/xfa_utils.h
@@ -11,9 +11,9 @@ #include "core/fxcrt/retain_ptr.h" #include "xfa/fxfa/fxfa.h" #include "xfa/fxfa/fxfa_basic.h" +#include "xfa/fxfa/parser/cxfa_localevalue.h" class CFX_XMLElement; -class CXFA_LocaleValue; class CXFA_Node; bool XFA_FDEExtension_ResolveNamespaceQualifier(CFX_XMLElement* pNode, @@ -21,6 +21,7 @@ WideString* wsNamespaceURI); CXFA_LocaleValue XFA_GetLocaleValue(CXFA_Node* pNode); +CXFA_LocaleValue::ValueType XFA_GetLocaleValueType(XFA_Element element); int32_t XFA_MapRotation(int32_t nRotation); bool XFA_RecognizeRichText(CFX_XMLElement* pRichTextXMLNode);