summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2018-01-31 17:40:52 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-01-31 17:40:52 +0000
commitba5f94d9c702592384eeb9d1735038ac4b189b7d (patch)
tree85d58707102a9764cf606eb944e197e457bda8f9 /core
parentab762d33d6c1605a24a6304f31179d5c5059cd34 (diff)
downloadpdfium-ba5f94d9c702592384eeb9d1735038ac4b189b7d.tar.xz
Remove handrolled search from GetCSSLengthUnitByName
BUG=pdfium:798 Change-Id: I97d0dc566f95736ef12eda90ee0bf336cba42098 Reviewed-on: https://pdfium-review.googlesource.com/24715 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'core')
-rw-r--r--core/fxcrt/css/cfx_cssdeclaration.cpp55
1 files changed, 22 insertions, 33 deletions
diff --git a/core/fxcrt/css/cfx_cssdeclaration.cpp b/core/fxcrt/css/cfx_cssdeclaration.cpp
index 278ffabdca..d901a954af 100644
--- a/core/fxcrt/css/cfx_cssdeclaration.cpp
+++ b/core/fxcrt/css/cfx_cssdeclaration.cpp
@@ -77,19 +77,15 @@ const CFX_CSSPropertyValueEntry propertyValueTable[] = {
{CFX_CSSPropertyValue::TextTop, L"text-top", 0xFCB58D45},
};
-struct CFX_CSSLengthUnitTable {
- uint16_t wHash;
- CFX_CSSNumberType wValue;
+struct CFX_CSSLengthUnitEntry {
+ const wchar_t* value;
+ CFX_CSSNumberType type;
};
-const CFX_CSSLengthUnitTable g_CFX_CSSLengthUnits[] = {
- {0x0672, CFX_CSSNumberType::EMS},
- {0x067D, CFX_CSSNumberType::EXS},
- {0x1AF7, CFX_CSSNumberType::Inches},
- {0x2F7A, CFX_CSSNumberType::MilliMeters},
- {0x3ED3, CFX_CSSNumberType::Picas},
- {0x3EE4, CFX_CSSNumberType::Points},
- {0x3EE8, CFX_CSSNumberType::Pixels},
- {0xFC30, CFX_CSSNumberType::CentiMeters},
+const CFX_CSSLengthUnitEntry lengthUnitTable[] = {
+ {L"cm", CFX_CSSNumberType::CentiMeters}, {L"em", CFX_CSSNumberType::EMS},
+ {L"ex", CFX_CSSNumberType::EXS}, {L"in", CFX_CSSNumberType::Inches},
+ {L"mm", CFX_CSSNumberType::MilliMeters}, {L"pc", CFX_CSSNumberType::Picas},
+ {L"pt", CFX_CSSNumberType::Points}, {L"px", CFX_CSSNumberType::Pixels},
};
struct CFX_CSSColorTable {
@@ -124,25 +120,18 @@ const CFX_CSSPropertyValueEntry* GetCSSPropertyValueByName(
return nullptr;
}
-const CFX_CSSLengthUnitTable* GetCSSLengthUnitByName(
- const WideStringView& wsName) {
- ASSERT(!wsName.IsEmpty());
- uint16_t wHash = FX_HashCode_GetW(wsName, true);
- int32_t iEnd =
- sizeof(g_CFX_CSSLengthUnits) / sizeof(CFX_CSSLengthUnitTable) - 1;
- int32_t iMid, iStart = 0;
- uint16_t wMid;
- do {
- iMid = (iStart + iEnd) / 2;
- wMid = g_CFX_CSSLengthUnits[iMid].wHash;
- if (wHash == wMid) {
- return g_CFX_CSSLengthUnits + iMid;
- } else if (wHash > wMid) {
- iStart = iMid + 1;
- } else {
- iEnd = iMid - 1;
- }
- } while (iStart <= iEnd);
+const CFX_CSSLengthUnitEntry* GetCSSLengthUnitByName(WideStringView wsName) {
+ if (wsName.IsEmpty() || wsName.GetLength() != 2)
+ return nullptr;
+
+ WideString lowerName = WideString(wsName);
+ lowerName.MakeLower();
+
+ for (auto* iter = std::begin(lengthUnitTable);
+ iter != std::end(lengthUnitTable); ++iter) {
+ if (lowerName.Compare(iter->value) == 0)
+ return iter;
+ }
return nullptr;
}
@@ -182,10 +171,10 @@ bool ParseCSSNumber(const wchar_t* pszValue,
if (iValueLen >= 1 && *pszValue == '%') {
eUnit = CFX_CSSNumberType::Percent;
} else if (iValueLen == 2) {
- const CFX_CSSLengthUnitTable* pUnit =
+ const CFX_CSSLengthUnitEntry* pUnit =
GetCSSLengthUnitByName(WideStringView(pszValue, 2));
if (pUnit)
- eUnit = pUnit->wValue;
+ eUnit = pUnit->type;
}
return true;
}