summaryrefslogtreecommitdiff
path: root/xfa/fxfa
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fxfa')
-rw-r--r--xfa/fxfa/parser/xfa_utils.cpp19
-rw-r--r--xfa/fxfa/parser/xfa_utils_unittest.cpp13
2 files changed, 18 insertions, 14 deletions
diff --git a/xfa/fxfa/parser/xfa_utils.cpp b/xfa/fxfa/parser/xfa_utils.cpp
index 75d017b070..2ffba9b2e6 100644
--- a/xfa/fxfa/parser/xfa_utils.cpp
+++ b/xfa/fxfa/parser/xfa_utils.cpp
@@ -455,19 +455,12 @@ const XFA_ATTRIBUTEENUMINFO* XFA_GetAttributeEnumByName(
if (wsName.IsEmpty())
return nullptr;
- uint32_t uHash = FX_HashCode_GetW(wsName, false);
- int32_t iStart = 0;
- int32_t iEnd = g_iXFAEnumCount - 1;
- do {
- int32_t iMid = (iStart + iEnd) / 2;
- const XFA_ATTRIBUTEENUMINFO* pInfo = g_XFAEnumData + iMid;
- if (uHash == pInfo->uHash)
- return pInfo;
- if (uHash < pInfo->uHash)
- iEnd = iMid - 1;
- else
- iStart = iMid + 1;
- } while (iStart <= iEnd);
+ 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;
}
diff --git a/xfa/fxfa/parser/xfa_utils_unittest.cpp b/xfa/fxfa/parser/xfa_utils_unittest.cpp
index 1898a797ec..6a1de85624 100644
--- a/xfa/fxfa/parser/xfa_utils_unittest.cpp
+++ b/xfa/fxfa/parser/xfa_utils_unittest.cpp
@@ -276,9 +276,20 @@ TEST_F(XFANodeIteratorTest, ChildAsRootNext) {
TEST(XFAUtilsTest, GetAttributeByName) {
EXPECT_EQ(nullptr, XFA_GetAttributeByName(L""));
- EXPECT_EQ(nullptr, XFA_GetAttributeByName(L"clams"));
+ EXPECT_EQ(nullptr, XFA_GetAttributeByName(L"nonesuch"));
EXPECT_EQ(XFA_ATTRIBUTE_H, XFA_GetAttributeByName(L"h")->eName);
EXPECT_EQ(XFA_ATTRIBUTE_Short, XFA_GetAttributeByName(L"short")->eName);
EXPECT_EQ(XFA_ATTRIBUTE_DecipherOnly,
XFA_GetAttributeByName(L"decipherOnly")->eName);
}
+
+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);
+}