From b58bf90755050e1bb6c5d33c329cdaf6cdde36ae Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 30 Nov 2017 20:33:20 +0000 Subject: Rename GetAttributeEnumById to CXFA_Node::AttributeEnumToName This is more consistent with the attribute and element to name methods. Change-Id: I3a7f9246d6fbaffa27a0068d8f93e717f5801d2a Reviewed-on: https://pdfium-review.googlesource.com/19851 Reviewed-by: Henrique Nakashima Commit-Queue: dsinclair --- fxjs/cjx_node.cpp | 14 +++++--------- xfa/fxfa/parser/cxfa_node.cpp | 7 +++++-- xfa/fxfa/parser/cxfa_node.h | 3 +-- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/fxjs/cjx_node.cpp b/fxjs/cjx_node.cpp index fe1612d022..338a160e77 100644 --- a/fxjs/cjx_node.cpp +++ b/fxjs/cjx_node.cpp @@ -244,7 +244,7 @@ pdfium::Optional CJX_Node::TryAttribute(XFA_Attribute eAttr, if (!value) return {}; - return {GetAttributeEnumByID(*value)->pName}; + return {CXFA_Node::AttributeEnumToName(*value)}; } case XFA_AttributeType::CData: return TryCData(eAttr, bUseDefault); @@ -1756,13 +1756,8 @@ void CJX_Node::Script_Som_Mandatory(CFXJSE_Value* pValue, return; } - const XFA_ATTRIBUTEENUMINFO* pInfo = - GetAttributeEnumByID(validateData.GetNullTest()); - if (!pInfo) { - pValue->SetString(""); - return; - } - pValue->SetString(WideString(pInfo->pName).UTF8Encode().AsStringView()); + WideString str = CXFA_Node::AttributeEnumToName(validateData.GetNullTest()); + pValue->SetString(str.UTF8Encode().AsStringView()); } void CJX_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue, @@ -3202,7 +3197,8 @@ bool CJX_Node::SetValue(XFA_Attribute eAttr, case XFA_AttributeType::Enum: elem->SetString( CXFA_Node::AttributeToName(eAttr), - GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue)->pName); + CXFA_Node::AttributeEnumToName(static_cast( + reinterpret_cast(pValue)))); break; case XFA_AttributeType::Boolean: elem->SetString(CXFA_Node::AttributeToName(eAttr), pValue ? L"1" : L"0"); diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 4d9e9966cb..99f0eea5a8 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -134,8 +134,11 @@ void ReorderDataNodes(const std::set& sSet1, } // namespace -const XFA_ATTRIBUTEENUMINFO* GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) { - return g_XFAEnumData + eName; +// static +WideString CXFA_Node::AttributeEnumToName(XFA_ATTRIBUTEENUM item) { + if (item >= g_iXFAEnumCount) + return L""; + return g_XFAEnumData[static_cast(item)].pName; } CXFA_Node::CXFA_Node(CXFA_Document* pDoc, diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h index b5217ad832..3d0b3db673 100644 --- a/xfa/fxfa/parser/cxfa_node.h +++ b/xfa/fxfa/parser/cxfa_node.h @@ -43,8 +43,6 @@ enum XFA_NODEITEM { XFA_NODEITEM_PrevSibling, }; -const XFA_ATTRIBUTEENUMINFO* GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName); - class CXFA_Node : public CXFA_Object { public: struct PropertyData { @@ -63,6 +61,7 @@ class CXFA_Node : public CXFA_Object { static WideString ElementToName(XFA_Element elem); #endif // NDEBUG + static WideString AttributeEnumToName(XFA_ATTRIBUTEENUM item); static XFA_Attribute NameToAttribute(const WideStringView& name); static WideString AttributeToName(XFA_Attribute attr); static XFA_Element NameToElement(const WideString& name); -- cgit v1.2.3