From f351ba03ebf31103c0a6a0c00b1477d39c060139 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 27 Nov 2017 18:28:06 +0000 Subject: Add some helpers for attribute lookup This CL adds helpers to CXFA_Node to convert from strings to attributes and from attributes to their string names. A static_assert was added to make sure the list of attributes is the same size as the attribute data so the checks can be removed. Change-Id: Idebc65021d71f604bcf498e4cf42252af00d802b Reviewed-on: https://pdfium-review.googlesource.com/19270 Reviewed-by: Henrique Nakashima Commit-Queue: dsinclair --- xfa/fxfa/parser/cxfa_node.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'xfa/fxfa/parser/cxfa_node.cpp') diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index ccbf31048d..4402208900 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -138,6 +138,19 @@ const XFA_ATTRIBUTEENUMINFO* GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) { return g_XFAEnumData + eName; } +// static +WideString CXFA_Node::AttributeToName(XFA_Attribute attr) { + return XFA_GetAttributeByID(attr)->pName; +} + +// static +XFA_Attribute CXFA_Node::NameToAttribute(const WideStringView& name) { + const XFA_ATTRIBUTEINFO* attr = XFA_GetAttributeByName(name); + if (!attr) + return XFA_Attribute::Unknown; + return attr->eName; +} + CXFA_Node::CXFA_Node(CXFA_Document* pDoc, uint16_t ePacket, uint32_t validPackets, -- cgit v1.2.3