diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-11-30 20:50:20 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-11-30 20:50:20 +0000 |
commit | 0ae8e03cc2d310ba0ba19b878ea448f17a577cdb (patch) | |
tree | e52a04144fd4945e3c90aadaeb11f4892f52baa2 | |
parent | 9a2267d2531f4e75a6bcafb48abacfefe8a4a555 (diff) | |
download | pdfium-0ae8e03cc2d310ba0ba19b878ea448f17a577cdb.tar.xz |
Create CXFA_Node::NameToAttributeEnum
This CL removes XFA_GetAttributeEnumByName and moves the functionality
into CXFA_Node::NameToAttriuteEnum.
Change-Id: Id1484103c62bf7728d5406c22fb9d83fc0e032e1
Reviewed-on: https://pdfium-review.googlesource.com/19791
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
-rw-r--r-- | fxjs/cjx_node.cpp | 9 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_node.cpp | 15 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_node.h | 3 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_node_unittest.cpp | 10 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_validatedata.cpp | 7 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_utils.cpp | 14 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_utils.h | 2 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_utils_unittest.cpp | 11 |
8 files changed, 36 insertions, 35 deletions
diff --git a/fxjs/cjx_node.cpp b/fxjs/cjx_node.cpp index 6b717f2d9d..3442b35b9d 100644 --- a/fxjs/cjx_node.cpp +++ b/fxjs/cjx_node.cpp @@ -193,10 +193,11 @@ bool CJX_Node::SetAttribute(XFA_Attribute eAttr, XFA_AttributeType eType = GetXFANode()->GetAttributeType(eAttr); switch (eType) { case XFA_AttributeType::Enum: { - const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue); - return SetEnum( - eAttr, pEnum ? pEnum->eName : *(GetXFANode()->GetDefaultEnum(eAttr)), - bNotify); + pdfium::Optional<XFA_ATTRIBUTEENUM> item = + CXFA_Node::NameToAttributeEnum(wsValue); + return SetEnum(eAttr, + item ? *item : *(GetXFANode()->GetDefaultEnum(eAttr)), + bNotify); } case XFA_AttributeType::CData: return SetCData(eAttr, WideString(wsValue), bNotify, false); diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 99f0eea5a8..f24bddb990 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -141,6 +141,21 @@ WideString CXFA_Node::AttributeEnumToName(XFA_ATTRIBUTEENUM item) { return g_XFAEnumData[static_cast<int32_t>(item)].pName; } +// static +pdfium::Optional<XFA_ATTRIBUTEENUM> CXFA_Node::NameToAttributeEnum( + const WideStringView& name) { + if (name.IsEmpty()) + return {}; + + auto* it = std::lower_bound(g_XFAEnumData, g_XFAEnumData + g_iXFAEnumCount, + FX_HashCode_GetW(name, false), + [](const XFA_ATTRIBUTEENUMINFO& arg, + uint32_t hash) { return arg.uHash < hash; }); + if (it != g_XFAEnumData + g_iXFAEnumCount && name == it->pName) + return {it->eName}; + return {}; +} + CXFA_Node::CXFA_Node(CXFA_Document* pDoc, uint16_t ePacket, uint32_t validPackets, diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h index 3d0b3db673..3e05f36fab 100644 --- a/xfa/fxfa/parser/cxfa_node.h +++ b/xfa/fxfa/parser/cxfa_node.h @@ -14,6 +14,7 @@ #include "core/fxcrt/fx_string.h" #include "fxjs/cjx_node.h" +#include "third_party/base/optional.h" #include "xfa/fxfa/parser/cxfa_object.h" class CFX_XMLNode; @@ -62,6 +63,8 @@ class CXFA_Node : public CXFA_Object { #endif // NDEBUG static WideString AttributeEnumToName(XFA_ATTRIBUTEENUM item); + static pdfium::Optional<XFA_ATTRIBUTEENUM> NameToAttributeEnum( + const WideStringView& name); static XFA_Attribute NameToAttribute(const WideStringView& name); static WideString AttributeToName(XFA_Attribute attr); static XFA_Element NameToElement(const WideString& name); diff --git a/xfa/fxfa/parser/cxfa_node_unittest.cpp b/xfa/fxfa/parser/cxfa_node_unittest.cpp index 93df084391..55360a6c47 100644 --- a/xfa/fxfa/parser/cxfa_node_unittest.cpp +++ b/xfa/fxfa/parser/cxfa_node_unittest.cpp @@ -15,3 +15,13 @@ TEST(CXFA_NodeTest, NameToAttribute) { EXPECT_EQ(XFA_Attribute::DecipherOnly, CXFA_Node::NameToAttribute(L"decipherOnly")); } + +TEST(CXFA_NodeTest, GetAttributeEnumByName) { + EXPECT_FALSE(!!CXFA_Node::NameToAttributeEnum(L"")); + EXPECT_FALSE(!!CXFA_Node::NameToAttributeEnum(L"nonesuch")); + EXPECT_EQ(XFA_ATTRIBUTEENUM_Asterisk, *CXFA_Node::NameToAttributeEnum(L"*")); + EXPECT_EQ(XFA_ATTRIBUTEENUM_Visible, + *CXFA_Node::NameToAttributeEnum(L"visible")); + EXPECT_EQ(XFA_ATTRIBUTEENUM_Lowered, + *CXFA_Node::NameToAttributeEnum(L"lowered")); +} diff --git a/xfa/fxfa/parser/cxfa_validatedata.cpp b/xfa/fxfa/parser/cxfa_validatedata.cpp index 8b3f539d48..dd45b5295b 100644 --- a/xfa/fxfa/parser/cxfa_validatedata.cpp +++ b/xfa/fxfa/parser/cxfa_validatedata.cpp @@ -24,11 +24,10 @@ XFA_ATTRIBUTEENUM CXFA_ValidateData::GetFormatTest() const { } void CXFA_ValidateData::SetNullTest(const WideString& wsValue) { - const XFA_ATTRIBUTEENUMINFO* pInfo = - XFA_GetAttributeEnumByName(wsValue.AsStringView()); + pdfium::Optional<XFA_ATTRIBUTEENUM> item = + CXFA_Node::NameToAttributeEnum(wsValue.AsStringView()); m_pNode->JSNode()->SetEnum(XFA_Attribute::NullTest, - pInfo ? pInfo->eName : XFA_ATTRIBUTEENUM_Disabled, - false); + item ? *item : XFA_ATTRIBUTEENUM_Disabled, false); } XFA_ATTRIBUTEENUM CXFA_ValidateData::GetNullTest() const { diff --git a/xfa/fxfa/parser/xfa_utils.cpp b/xfa/fxfa/parser/xfa_utils.cpp index 9dc34407bd..e9315763b7 100644 --- a/xfa/fxfa/parser/xfa_utils.cpp +++ b/xfa/fxfa/parser/xfa_utils.cpp @@ -186,20 +186,6 @@ const XFA_SCRIPTATTRIBUTEINFO* XFA_GetScriptAttributeByName( return nullptr; } -const XFA_ATTRIBUTEENUMINFO* XFA_GetAttributeEnumByName( - const WideStringView& wsName) { - if (wsName.IsEmpty()) - return nullptr; - - auto* it = std::lower_bound(g_XFAEnumData, g_XFAEnumData + g_iXFAEnumCount, - FX_HashCode_GetW(wsName, false), - [](const XFA_ATTRIBUTEENUMINFO& arg, - uint32_t hash) { return arg.uHash < hash; }); - if (it != g_XFAEnumData + g_iXFAEnumCount && wsName == it->pName) - return it; - return nullptr; -} - const XFA_PACKETINFO* XFA_GetPacketByIndex(XFA_PacketType ePacket) { return g_XFAPacketData + static_cast<uint8_t>(ePacket); } diff --git a/xfa/fxfa/parser/xfa_utils.h b/xfa/fxfa/parser/xfa_utils.h index 40e7d7440b..889dcc0f0a 100644 --- a/xfa/fxfa/parser/xfa_utils.h +++ b/xfa/fxfa/parser/xfa_utils.h @@ -42,8 +42,6 @@ const XFA_SCRIPTATTRIBUTEINFO* XFA_GetScriptAttributeByName( XFA_Element eElement, const WideStringView& wsAttributeName); -const XFA_ATTRIBUTEENUMINFO* XFA_GetAttributeEnumByName( - const WideStringView& wsName); const XFA_PACKETINFO* XFA_GetPacketByIndex(XFA_PacketType ePacket); const XFA_PACKETINFO* XFA_GetPacketByID(uint32_t dwPacket); diff --git a/xfa/fxfa/parser/xfa_utils_unittest.cpp b/xfa/fxfa/parser/xfa_utils_unittest.cpp index b27cdaa36e..c9f662eb8d 100644 --- a/xfa/fxfa/parser/xfa_utils_unittest.cpp +++ b/xfa/fxfa/parser/xfa_utils_unittest.cpp @@ -22,14 +22,3 @@ TEST(XfaUtilsImpTest, XFA_MapRotation) { XFA_MapRotation(TestCases[i].input)); } } - -TEST(XFAUtilsTest, GetAttributeEnumByName) { - EXPECT_EQ(nullptr, XFA_GetAttributeEnumByName(L"")); - EXPECT_EQ(nullptr, XFA_GetAttributeEnumByName(L"nonesuch")); - EXPECT_EQ(XFA_ATTRIBUTEENUM_Asterisk, - XFA_GetAttributeEnumByName(L"*")->eName); - EXPECT_EQ(XFA_ATTRIBUTEENUM_Visible, - XFA_GetAttributeEnumByName(L"visible")->eName); - EXPECT_EQ(XFA_ATTRIBUTEENUM_Lowered, - XFA_GetAttributeEnumByName(L"lowered")->eName); -} |