summaryrefslogtreecommitdiff
path: root/xfa/fxfa/app/xfa_textlayout.cpp
diff options
context:
space:
mode:
authordsinclair <dsinclair@chromium.org>2016-05-19 14:12:30 -0700
committerCommit bot <commit-bot@chromium.org>2016-05-19 14:12:30 -0700
commitc7600f99490f83e544e37feb77d3b9e8428b0f68 (patch)
treef6686e79a31ddc575ecc3ccd3475122670ff0ca4 /xfa/fxfa/app/xfa_textlayout.cpp
parentf8d8ac4fca2774550f3fbd3a21bbc1e326028c18 (diff)
downloadpdfium-c7600f99490f83e544e37feb77d3b9e8428b0f68.tar.xz
Remove CFX_DSPATemplate usage in CXFA_TextParser
This CL changes the check to use std::binary_search instead of the custom lookup method. The tag validation has been split out to a separate method with unit tests added. Review-Url: https://codereview.chromium.org/1996623002
Diffstat (limited to 'xfa/fxfa/app/xfa_textlayout.cpp')
-rw-r--r--xfa/fxfa/app/xfa_textlayout.cpp45
1 files changed, 30 insertions, 15 deletions
diff --git a/xfa/fxfa/app/xfa_textlayout.cpp b/xfa/fxfa/app/xfa_textlayout.cpp
index b7dfa3f168..91dd814e8d 100644
--- a/xfa/fxfa/app/xfa_textlayout.cpp
+++ b/xfa/fxfa/app/xfa_textlayout.cpp
@@ -220,14 +220,14 @@ void CXFA_TextParser::DoParse(CFDE_XMLNode* pXMLContainer,
}
void CXFA_TextParser::ParseRichText(CFDE_XMLNode* pXMLNode,
IFDE_CSSComputedStyle* pParentStyle) {
- if (pXMLNode == NULL) {
+ if (!pXMLNode)
return;
- }
+
CXFA_CSSTagProvider tagProvider;
ParseTagInfo(pXMLNode, tagProvider);
- if (!tagProvider.m_bTagAviliable) {
+ if (!tagProvider.m_bTagAvailable)
return;
- }
+
IFDE_CSSComputedStyle* pNewStyle = NULL;
if ((tagProvider.GetTagName() != FX_WSTRC(L"body")) ||
(tagProvider.GetTagName() != FX_WSTRC(L"html"))) {
@@ -263,30 +263,45 @@ void CXFA_TextParser::ParseRichText(CFDE_XMLNode* pXMLNode,
if (pNewStyle)
pNewStyle->Release();
}
-void CXFA_TextParser::ParseTagInfo(CFDE_XMLNode* pXMLNode,
- CXFA_CSSTagProvider& tagProvider) {
+
+bool CXFA_TextParser::TagValidate(const CFX_WideString& wsName) const {
static const uint32_t s_XFATagName[] = {
- 0x61, 0x62, 0x69, 0x70, 0x0001f714,
- 0x00022a55, 0x000239bb, 0x00025881, 0x0bd37faa, 0x0bd37fb8,
- 0xa73e3af2, 0xb182eaae, 0xdb8ac455,
+ 0x61, // a
+ 0x62, // b
+ 0x69, // i
+ 0x70, // p
+ 0x0001f714, // br
+ 0x00022a55, // li
+ 0x000239bb, // ol
+ 0x00025881, // ul
+ 0x0bd37faa, // sub
+ 0x0bd37fb8, // sup
+ 0xa73e3af2, // span
+ 0xb182eaae, // body
+ 0xdb8ac455, // html
};
+ static const int32_t s_iCount = FX_ArraySize(s_XFATagName);
+
+ return std::binary_search(s_XFATagName, s_XFATagName + s_iCount,
+ FX_HashCode_GetW(wsName.AsStringC(), true));
+}
+
+void CXFA_TextParser::ParseTagInfo(CFDE_XMLNode* pXMLNode,
+ CXFA_CSSTagProvider& tagProvider) {
CFX_WideString wsName;
if (pXMLNode->GetType() == FDE_XMLNODE_Element) {
CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
pXMLElement->GetLocalTagName(wsName);
tagProvider.SetTagNameObj(wsName);
- uint32_t dwHashCode = FX_HashCode_GetW(wsName.AsStringC(), true);
- static const int32_t s_iCount = sizeof(s_XFATagName) / sizeof(uint32_t);
- CFX_DSPATemplate<uint32_t> lookup;
- tagProvider.m_bTagAviliable =
- lookup.Lookup(dwHashCode, s_XFATagName, s_iCount) > -1;
+ tagProvider.m_bTagAvailable = TagValidate(wsName);
+
CFX_WideString wsValue;
pXMLElement->GetString(L"style", wsValue);
if (!wsValue.IsEmpty()) {
tagProvider.SetAttribute(L"style", wsValue);
}
} else if (pXMLNode->GetType() == FDE_XMLNODE_Text) {
- tagProvider.m_bTagAviliable = TRUE;
+ tagProvider.m_bTagAvailable = TRUE;
tagProvider.m_bContent = TRUE;
}
}