diff options
33 files changed, 266 insertions, 332 deletions
diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp index f1fd980120..53fcf45ef5 100644 --- a/core/fxcrt/fx_extension.cpp +++ b/core/fxcrt/fx_extension.cpp @@ -217,14 +217,10 @@ int32_t FXSYS_strnicmp(const FX_CHAR* s1, const FX_CHAR* s2, size_t count) { } return ch1 - ch2; } -uint32_t FX_HashCode_String_GetA(const FX_CHAR* pStr, - int32_t iLength, - FX_BOOL bIgnoreCase) { - FXSYS_assert(pStr); - if (iLength < 0) { - iLength = (int32_t)FXSYS_strlen(pStr); - } - const FX_CHAR* pStrEnd = pStr + iLength; + +uint32_t FX_HashCode_GetA(const CFX_ByteStringC& str, bool bIgnoreCase) { + const FX_CHAR* pStr = str.c_str(); + const FX_CHAR* pStrEnd = pStr + str.GetLength(); uint32_t dwHashCode = 0; if (bIgnoreCase) { while (pStr < pStrEnd) { @@ -237,14 +233,10 @@ uint32_t FX_HashCode_String_GetA(const FX_CHAR* pStr, } return dwHashCode; } -uint32_t FX_HashCode_String_GetW(const FX_WCHAR* pStr, - int32_t iLength, - FX_BOOL bIgnoreCase) { - FXSYS_assert(pStr); - if (iLength < 0) { - iLength = (int32_t)FXSYS_wcslen(pStr); - } - const FX_WCHAR* pStrEnd = pStr + iLength; + +uint32_t FX_HashCode_GetW(const CFX_WideStringC& str, bool bIgnoreCase) { + const FX_WCHAR* pStr = str.c_str(); + const FX_WCHAR* pStrEnd = pStr + str.GetLength(); uint32_t dwHashCode = 0; if (bIgnoreCase) { while (pStr < pStrEnd) { @@ -327,9 +319,9 @@ void FX_Random_GenerateBase(uint32_t* pBuffer, int32_t iCount) { ::GetSystemTime(&st2); } while (FXSYS_memcmp(&st1, &st2, sizeof(SYSTEMTIME)) == 0); uint32_t dwHash1 = - FX_HashCode_String_GetA((const FX_CHAR*)&st1, sizeof(st1), TRUE); + FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)&st1, sizeof(st1)), true); uint32_t dwHash2 = - FX_HashCode_String_GetA((const FX_CHAR*)&st2, sizeof(st2), TRUE); + FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)&st2, sizeof(st2)), true); ::srand((dwHash1 << 16) | (uint32_t)dwHash2); #else time_t tmLast = time(NULL); diff --git a/core/fxcrt/fx_extension_unittest.cpp b/core/fxcrt/fx_extension_unittest.cpp index 7714999bbf..954e0956ed 100644 --- a/core/fxcrt/fx_extension_unittest.cpp +++ b/core/fxcrt/fx_extension_unittest.cpp @@ -26,3 +26,17 @@ TEST(fxcrt, FXSYS_isDecimalDigit) { EXPECT_FALSE(FXSYS_isDecimalDigit('a')); EXPECT_FALSE(FXSYS_isDecimalDigit(L'a')); } + +TEST(fxcrt, FX_HashCode_Ascii) { + EXPECT_EQ(0u, FX_HashCode_GetA("", false)); + EXPECT_EQ(65u, FX_HashCode_GetA("A", false)); + EXPECT_EQ(97u, FX_HashCode_GetA("A", true)); + EXPECT_EQ(31 * 65u + 66u, FX_HashCode_GetA("AB", false)); +} + +TEST(fxcrt, FX_HashCode_Wide) { + EXPECT_EQ(0u, FX_HashCode_GetW(L"", false)); + EXPECT_EQ(65u, FX_HashCode_GetW(L"A", false)); + EXPECT_EQ(97u, FX_HashCode_GetW(L"A", true)); + EXPECT_EQ(1313 * 65u + 66u, FX_HashCode_GetW(L"AB", false)); +} diff --git a/core/fxcrt/include/fx_ext.h b/core/fxcrt/include/fx_ext.h index 68ae2a3651..e956d3cb43 100644 --- a/core/fxcrt/include/fx_ext.h +++ b/core/fxcrt/include/fx_ext.h @@ -77,12 +77,8 @@ inline int FXSYS_toDecimalDigit(const FX_WCHAR c) { return std::iswdigit(c) ? c - L'0' : 0; } -uint32_t FX_HashCode_String_GetA(const FX_CHAR* pStr, - int32_t iLength, - FX_BOOL bIgnoreCase = FALSE); -uint32_t FX_HashCode_String_GetW(const FX_WCHAR* pStr, - int32_t iLength, - FX_BOOL bIgnoreCase = FALSE); +uint32_t FX_HashCode_GetA(const CFX_ByteStringC& str, bool bIgnoreCase); +uint32_t FX_HashCode_GetW(const CFX_WideStringC& Str, bool bIgnoreCase); void* FX_Random_MT_Start(uint32_t dwSeed); diff --git a/fpdfsdk/javascript/global.cpp b/fpdfsdk/javascript/global.cpp index 380713b425..043bd290ac 100644 --- a/fpdfsdk/javascript/global.cpp +++ b/fpdfsdk/javascript/global.cpp @@ -53,7 +53,7 @@ const unsigned int JSCONST_nUndefHash = CHash<'u', 'n', 'd', 'e', 'f', 'i', 'n', 'e', 'd'>::value; static unsigned JS_CalcHash(const wchar_t* main) { - return (unsigned)FX_HashCode_String_GetW(main, FXSYS_wcslen(main)); + return (unsigned)FX_HashCode_GetW(CFX_WideStringC(main), false); } #ifndef NDEBUG diff --git a/xfa/fde/css/fde_csscache.cpp b/xfa/fde/css/fde_csscache.cpp index e23b4c6377..9a259e1844 100644 --- a/xfa/fde/css/fde_csscache.cpp +++ b/xfa/fde/css/fde_csscache.cpp @@ -29,26 +29,19 @@ FDE_CSSTagCache::FDE_CSSTagCache(FDE_CSSTagCache* parent, dwTagHash(0), iClassIndex(0), dwClassHashs(1) { - static const uint32_t s_dwIDHash = FX_HashCode_String_GetW(L"id", 2, TRUE); - static const uint32_t s_dwClassHash = - FX_HashCode_String_GetW(L"class", 5, TRUE); - - CFX_WideString wsTag = pTag->GetTagName(); - dwTagHash = FX_HashCode_String_GetW(wsTag.c_str(), wsTag.GetLength(), TRUE); + static const uint32_t s_dwIDHash = FX_HashCode_GetW(L"id", true); + static const uint32_t s_dwClassHash = FX_HashCode_GetW(L"class", true); + dwTagHash = FX_HashCode_GetW(pTag->GetTagName().AsStringC(), true); for (auto it : *pTag) { CFX_WideString wsValue = it.first; CFX_WideString wsName = it.second; - - uint32_t dwNameHash = - FX_HashCode_String_GetW(wsName.c_str(), wsName.GetLength(), TRUE); - + uint32_t dwNameHash = FX_HashCode_GetW(wsName.AsStringC(), true); if (dwNameHash == s_dwClassHash) { - uint32_t dwHash = - FX_HashCode_String_GetW(wsValue.c_str(), wsValue.GetLength()); + uint32_t dwHash = FX_HashCode_GetW(wsValue.AsStringC(), false); dwClassHashs.Add(dwHash); } else if (dwNameHash == s_dwIDHash) { - dwIDHash = FX_HashCode_String_GetW(wsValue.c_str(), wsValue.GetLength()); + dwIDHash = FX_HashCode_GetW(wsValue.AsStringC(), false); } } } diff --git a/xfa/fde/css/fde_cssdatatable.cpp b/xfa/fde/css/fde_cssdatatable.cpp index 6abe5a7a26..f37f77b86c 100644 --- a/xfa/fde/css/fde_cssdatatable.cpp +++ b/xfa/fde/css/fde_cssdatatable.cpp @@ -557,10 +557,10 @@ FDE_LPCCSSPERSUDOTABLE FDE_GetCSSPersudoByEnum(FDE_CSSPERSUDO ePersudo) { return (ePersudo < FDE_CSSPERSUDO_NONE) ? (g_FDE_CSSPersudoType + ePersudo) : NULL; } -FDE_LPCCSSPROPERTYTABLE FDE_GetCSSPropertyByName(const FX_WCHAR* pszName, - int32_t iLength) { - FXSYS_assert(pszName != NULL && iLength > 0); - uint32_t dwHash = FX_HashCode_String_GetW(pszName, iLength, TRUE); +FDE_LPCCSSPROPERTYTABLE FDE_GetCSSPropertyByName( + const CFX_WideStringC& wsName) { + FXSYS_assert(!wsName.IsEmpty()); + uint32_t dwHash = FX_HashCode_GetW(wsName, true); int32_t iEnd = FDE_CSSPROPERTY_MAX - 1; int32_t iMid, iStart = 0; uint32_t dwMid; @@ -581,10 +581,9 @@ FDE_LPCCSSPROPERTYTABLE FDE_GetCSSPropertyByEnum(FDE_CSSPROPERTY eName) { return (eName < FDE_CSSPROPERTY_MAX) ? (g_FDE_CSSProperties + eName) : NULL; } FDE_LPCCSSPROPERTYVALUETABLE FDE_GetCSSPropertyValueByName( - const FX_WCHAR* pszName, - int32_t iLength) { - FXSYS_assert(pszName != NULL && iLength > 0); - uint32_t dwHash = FX_HashCode_String_GetW(pszName, iLength, TRUE); + const CFX_WideStringC& wsName) { + FXSYS_assert(!wsName.IsEmpty()); + uint32_t dwHash = FX_HashCode_GetW(wsName, true); int32_t iEnd = FDE_CSSPROPERTYVALUE_MAX - 1; int32_t iMid, iStart = 0; uint32_t dwMid; @@ -606,10 +605,10 @@ FDE_LPCCSSPROPERTYVALUETABLE FDE_GetCSSPropertyValueByEnum( return (eName < FDE_CSSPROPERTYVALUE_MAX) ? (g_FDE_CSSPropertyValues + eName) : NULL; } -FDE_LPCCSSMEDIATYPETABLE FDE_GetCSSMediaTypeByName(const FX_WCHAR* pszName, - int32_t iLength) { - FXSYS_assert(pszName != NULL && iLength > 0); - uint16_t wHash = (uint16_t)FX_HashCode_String_GetW(pszName, iLength, TRUE); +FDE_LPCCSSMEDIATYPETABLE FDE_GetCSSMediaTypeByName( + const CFX_WideStringC& wsName) { + FXSYS_assert(!wsName.IsEmpty()); + uint16_t wHash = FX_HashCode_GetW(wsName, true); int32_t iEnd = sizeof(g_FDE_CSSMediaTypes) / sizeof(FDE_CSSMEDIATYPETABLE) - 1; int32_t iMid, iStart = 0; @@ -627,10 +626,10 @@ FDE_LPCCSSMEDIATYPETABLE FDE_GetCSSMediaTypeByName(const FX_WCHAR* pszName, } while (iStart <= iEnd); return NULL; } -FDE_LPCCSSLENGTHUNITTABLE FDE_GetCSSLengthUnitByName(const FX_WCHAR* pszName, - int32_t iLength) { - FXSYS_assert(pszName != NULL && iLength > 0); - uint16_t wHash = (uint16_t)FX_HashCode_String_GetW(pszName, iLength, TRUE); +FDE_LPCCSSLENGTHUNITTABLE FDE_GetCSSLengthUnitByName( + const CFX_WideStringC& wsName) { + FXSYS_assert(!wsName.IsEmpty()); + uint16_t wHash = FX_HashCode_GetW(wsName, true); int32_t iEnd = sizeof(g_FDE_CSSLengthUnits) / sizeof(FDE_CSSLENGTHUNITTABLE) - 1; int32_t iMid, iStart = 0; @@ -648,10 +647,9 @@ FDE_LPCCSSLENGTHUNITTABLE FDE_GetCSSLengthUnitByName(const FX_WCHAR* pszName, } while (iStart <= iEnd); return NULL; } -FDE_LPCCSSCOLORTABLE FDE_GetCSSColorByName(const FX_WCHAR* pszName, - int32_t iLength) { - FXSYS_assert(pszName != NULL && iLength > 0); - uint32_t dwHash = FX_HashCode_String_GetW(pszName, iLength, TRUE); +FDE_LPCCSSCOLORTABLE FDE_GetCSSColorByName(const CFX_WideStringC& wsName) { + FXSYS_assert(!wsName.IsEmpty()); + uint32_t dwHash = FX_HashCode_GetW(wsName, true); int32_t iEnd = sizeof(g_FDE_CSSColors) / sizeof(FDE_CSSCOLORTABLE) - 1; int32_t iMid, iStart = 0; uint32_t dwMid; @@ -684,7 +682,8 @@ FX_BOOL FDE_ParseCSSNumber(const FX_WCHAR* pszValue, if (iValueLen >= 1 && *pszValue == '%') { eUnit = FDE_CSSPRIMITIVETYPE_Percent; } else if (iValueLen == 2) { - FDE_LPCCSSLENGTHUNITTABLE pUnit = FDE_GetCSSLengthUnitByName(pszValue, 2); + FDE_LPCCSSLENGTHUNITTABLE pUnit = + FDE_GetCSSLengthUnitByName(CFX_WideStringC(pszValue, 2)); if (pUnit != NULL) { eUnit = (FDE_CSSPRIMITIVETYPE)pUnit->wValue; } @@ -770,7 +769,8 @@ FX_BOOL FDE_ParseCSSColor(const FX_WCHAR* pszValue, dwColor = ArgbEncode(255, rgb[0], rgb[1], rgb[2]); return TRUE; } else { - FDE_LPCCSSCOLORTABLE pColor = FDE_GetCSSColorByName(pszValue, iValueLen); + FDE_LPCCSSCOLORTABLE pColor = + FDE_GetCSSColorByName(CFX_WideStringC(pszValue, iValueLen)); if (pColor != NULL) { dwColor = pColor->dwValue; return TRUE; diff --git a/xfa/fde/css/fde_cssdatatable.h b/xfa/fde/css/fde_cssdatatable.h index 8d17901d1d..a066c29f94 100644 --- a/xfa/fde/css/fde_cssdatatable.h +++ b/xfa/fde/css/fde_cssdatatable.h @@ -137,8 +137,7 @@ struct FDE_CSSPROPERTYTABLE { }; typedef FDE_CSSPROPERTYTABLE const* FDE_LPCCSSPROPERTYTABLE; -FDE_LPCCSSPROPERTYTABLE FDE_GetCSSPropertyByName(const FX_WCHAR* pszName, - int32_t iLength); +FDE_LPCCSSPROPERTYTABLE FDE_GetCSSPropertyByName(const CFX_WideStringC& wsName); FDE_LPCCSSPROPERTYTABLE FDE_GetCSSPropertyByEnum(FDE_CSSPROPERTY eName); struct FDE_CSSPROPERTYVALUETABLE { FDE_CSSPROPERTYVALUE eName; @@ -148,8 +147,7 @@ struct FDE_CSSPROPERTYVALUETABLE { typedef FDE_CSSPROPERTYVALUETABLE const* FDE_LPCCSSPROPERTYVALUETABLE; FDE_LPCCSSPROPERTYVALUETABLE FDE_GetCSSPropertyValueByName( - const FX_WCHAR* pszName, - int32_t iLength); + const CFX_WideStringC& wsName); FDE_LPCCSSPROPERTYVALUETABLE FDE_GetCSSPropertyValueByEnum( FDE_CSSPROPERTYVALUE eName); struct FDE_CSSMEDIATYPETABLE { @@ -157,22 +155,22 @@ struct FDE_CSSMEDIATYPETABLE { uint16_t wValue; }; typedef FDE_CSSMEDIATYPETABLE const* FDE_LPCCSSMEDIATYPETABLE; -FDE_LPCCSSMEDIATYPETABLE FDE_GetCSSMediaTypeByName(const FX_WCHAR* pszName, - int32_t iLength); +FDE_LPCCSSMEDIATYPETABLE FDE_GetCSSMediaTypeByName( + const CFX_WideStringC& wsName); struct FDE_CSSLENGTHUNITTABLE { uint16_t wHash; uint16_t wValue; }; typedef FDE_CSSLENGTHUNITTABLE const* FDE_LPCCSSLENGTHUNITTABLE; -FDE_LPCCSSLENGTHUNITTABLE FDE_GetCSSLengthUnitByName(const FX_WCHAR* pszName, - int32_t iLength); +FDE_LPCCSSLENGTHUNITTABLE FDE_GetCSSLengthUnitByName( + const CFX_WideStringC& wsName); struct FDE_CSSCOLORTABLE { uint32_t dwHash; FX_ARGB dwValue; }; typedef FDE_CSSCOLORTABLE const* FDE_LPCCSSCOLORTABLE; -FDE_LPCCSSCOLORTABLE FDE_GetCSSColorByName(const FX_WCHAR* pszName, - int32_t iLength); +FDE_LPCCSSCOLORTABLE FDE_GetCSSColorByName(const CFX_WideStringC& wsName); + struct FDE_CSSPERSUDOTABLE { FDE_CSSPERSUDO eName; const FX_WCHAR* pszName; diff --git a/xfa/fde/css/fde_cssdeclaration.cpp b/xfa/fde/css/fde_cssdeclaration.cpp index 5517d85cb2..e48372c2ed 100644 --- a/xfa/fde/css/fde_cssdeclaration.cpp +++ b/xfa/fde/css/fde_cssdeclaration.cpp @@ -57,8 +57,8 @@ const FX_WCHAR* CFDE_CSSDeclaration::CopyToLocal( void* pKey = NULL; if (pCache) { void* pszCached = NULL; - pKey = - (void*)(uintptr_t)FX_HashCode_String_GetW(pszValue, iValueLen, FALSE); + pKey = (void*)(uintptr_t)FX_HashCode_GetW( + CFX_WideStringC(pszValue, iValueLen), false); if (pCache->Lookup(pKey, pszCached)) { return (const FX_WCHAR*)pszCached; } @@ -298,7 +298,7 @@ IFDE_CSSValue* CFDE_CSSDeclaration::ParseEnum(const FDE_CSSPROPERTYARGS* pArgs, const FX_WCHAR* pszValue, int32_t iValueLen) { const FDE_CSSPROPERTYVALUETABLE* pValue = - FDE_GetCSSPropertyValueByName(pszValue, iValueLen); + FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); return pValue ? NewEnumValue(pArgs->pStaticStore, pValue->eName) : NULL; } IFDE_CSSValue* CFDE_CSSDeclaration::ParseColor(const FDE_CSSPROPERTYARGS* pArgs, @@ -371,7 +371,7 @@ IFDE_CSSValue* CFDE_CSSDeclaration::ParseFunction( switch (ePrimitiveType) { case FDE_CSSPRIMITIVETYPE_String: { const FDE_CSSPROPERTYVALUETABLE* pPropertyValue = - FDE_GetCSSPropertyValueByName(pszValue, iValueLen); + FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); if (pPropertyValue != NULL) { argumentArr.Add( NewEnumValue(pArgs->pStaticStore, pPropertyValue->eName)); @@ -429,7 +429,7 @@ FX_BOOL CFDE_CSSDeclaration::ParseContentProperty( return FALSE; case FDE_CSSPRIMITIVETYPE_String: { const FDE_CSSPROPERTYVALUETABLE* pValue = - FDE_GetCSSPropertyValueByName(pszValue, iValueLen); + FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); if (pValue != NULL) { switch (pValue->eName) { case FDE_CSSPROPERTYVALUE_Normal: @@ -563,7 +563,8 @@ FX_BOOL CFDE_CSSDeclaration::ParseValueListProperty( } if (dwType & FDE_CSSVALUETYPE_MaybeEnum) { const FDE_CSSPROPERTYVALUETABLE* pValue = - FDE_GetCSSPropertyValueByName(pszValue, iValueLen); + FDE_GetCSSPropertyValueByName( + CFX_WideStringC(pszValue, iValueLen)); if (pValue != NULL) { list.Add(NewEnumValue(pStaticStore, pValue->eName)); continue; @@ -695,7 +696,7 @@ FX_BOOL CFDE_CSSDeclaration::ParseBorderPropoerty( break; case FDE_CSSPRIMITIVETYPE_String: { const FDE_CSSCOLORTABLE* pColorItem = - FDE_GetCSSColorByName(pszValue, iValueLen); + FDE_GetCSSColorByName(CFX_WideStringC(pszValue, iValueLen)); if (pColorItem != NULL) { if (pColor == NULL) { pColor = FXTARGET_NewWith(pStaticStore) @@ -704,7 +705,7 @@ FX_BOOL CFDE_CSSDeclaration::ParseBorderPropoerty( continue; } const FDE_CSSPROPERTYVALUETABLE* pValue = - FDE_GetCSSPropertyValueByName(pszValue, iValueLen); + FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); if (pValue == NULL) { continue; } @@ -786,7 +787,7 @@ FX_BOOL CFDE_CSSDeclaration::ParseListStyleProperty( break; case FDE_CSSPRIMITIVETYPE_String: { const FDE_CSSPROPERTYVALUETABLE* pValue = - FDE_GetCSSPropertyValueByName(pszValue, iValueLen); + FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); if (pValue == NULL) { break; } @@ -878,7 +879,7 @@ FX_BOOL CFDE_CSSDeclaration::ParseBackgroundProperty( } break; case FDE_CSSPRIMITIVETYPE_String: { const FDE_CSSPROPERTYVALUETABLE* pValue = - FDE_GetCSSPropertyValueByName(pszValue, iValueLen); + FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); if (pValue != NULL) { switch (pValue->eName) { case FDE_CSSPROPERTYVALUE_None: @@ -931,7 +932,7 @@ FX_BOOL CFDE_CSSDeclaration::ParseBackgroundProperty( break; } const FDE_CSSCOLORTABLE* pColorItem = - FDE_GetCSSColorByName(pszValue, iValueLen); + FDE_GetCSSColorByName(CFX_WideStringC(pszValue, iValueLen)); if (pColorItem != NULL) { if (pColor == NULL) { pColor = FXTARGET_NewWith(pStaticStore) @@ -1001,7 +1002,7 @@ FX_BOOL CFDE_CSSDeclaration::ParseFontProperty(const FDE_CSSPROPERTYARGS* pArgs, switch (eType) { case FDE_CSSPRIMITIVETYPE_String: { const FDE_CSSPROPERTYVALUETABLE* pValue = - FDE_GetCSSPropertyValueByName(pszValue, iValueLen); + FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); if (pValue != NULL) { switch (pValue->eName) { case FDE_CSSPROPERTYVALUE_XxSmall: @@ -1139,7 +1140,7 @@ FX_BOOL CFDE_CSSDeclaration::ParseColumnRuleProperty( switch (eType) { case FDE_CSSPRIMITIVETYPE_String: { const FDE_CSSPROPERTYVALUETABLE* pValue = - FDE_GetCSSPropertyValueByName(pszValue, iValueLen); + FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); if (pValue != NULL) { switch (pValue->eName) { case FDE_CSSPROPERTYVALUE_None: @@ -1236,7 +1237,7 @@ FX_BOOL CFDE_CSSDeclaration::ParseTextEmphasisProperty( switch (eType) { case FDE_CSSPRIMITIVETYPE_String: { const FDE_CSSPROPERTYVALUETABLE* pValue = - FDE_GetCSSPropertyValueByName(pszValue, iValueLen); + FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); if (pValue != NULL) { arrEmphasisStyle.Add(NewEnumValue(pStaticStore, pValue->eName)); continue; @@ -1289,7 +1290,7 @@ FX_BOOL CFDE_CSSDeclaration::ParseColumnsProperty( switch (eType) { case FDE_CSSPRIMITIVETYPE_String: { const FDE_CSSPROPERTYVALUETABLE* pValue = - FDE_GetCSSPropertyValueByName(pszValue, iValueLen); + FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); if (pValue == NULL && pValue->eName == FDE_CSSPROPERTYVALUE_Auto) { pColumnWidth = NewEnumValue(pStaticStore, pValue->eName); } @@ -1341,7 +1342,7 @@ FX_BOOL CFDE_CSSDeclaration::ParseOverflowProperty( while (parser.NextValue(eType, pszValue, iValueLen)) { if (eType == FDE_CSSPRIMITIVETYPE_String) { const FDE_CSSPROPERTYVALUETABLE* pValue = - FDE_GetCSSPropertyValueByName(pszValue, iValueLen); + FDE_GetCSSPropertyValueByName(CFX_WideStringC(pszValue, iValueLen)); if (pValue != NULL) { switch (pValue->eName) { case FDE_CSSOVERFLOW_Visible: diff --git a/xfa/fde/css/fde_cssstyleselector.cpp b/xfa/fde/css/fde_cssstyleselector.cpp index 30502303f4..4f88c0d5d7 100644 --- a/xfa/fde/css/fde_cssstyleselector.cpp +++ b/xfa/fde/css/fde_cssstyleselector.cpp @@ -424,10 +424,8 @@ void CFDE_CSSStyleSelector::ComputeStyle( FXSYS_assert(iDeclCount >= 0); FXSYS_assert(pDestStyle); - static const uint32_t s_dwStyleHash = - FX_HashCode_String_GetW(L"style", 5, TRUE); - static const uint32_t s_dwAlignHash = - FX_HashCode_String_GetW(L"align", 5, TRUE); + static const uint32_t s_dwStyleHash = FX_HashCode_GetW(L"style", true); + static const uint32_t s_dwAlignHash = FX_HashCode_GetW(L"align", true); if (!pTag->empty()) { if (!m_pInlineStyleStore) @@ -437,9 +435,7 @@ void CFDE_CSSStyleSelector::ComputeStyle( for (auto it : *pTag) { CFX_WideString wsAttri = it.first; CFX_WideString wsValue = it.second; - - uint32_t dwAttriHash = - FX_HashCode_String_GetW(wsAttri.c_str(), wsAttri.GetLength(), TRUE); + uint32_t dwAttriHash = FX_HashCode_GetW(wsAttri.AsStringC(), true); if (dwAttriHash == s_dwStyleHash) { if (!pDecl) pDecl = FXTARGET_NewWith(m_pInlineStyleStore) CFDE_CSSDeclaration; @@ -565,7 +561,7 @@ void CFDE_CSSStyleSelector::AppendInlineStyle(CFDE_CSSDeclaration* pDecl, FDE_CSSSYNTAXSTATUS eStatus = pSyntax->DoSyntaxParse(); if (eStatus == FDE_CSSSYNTAXSTATUS_PropertyName) { psz = pSyntax->GetCurrentString(iLen); - args.pProperty = FDE_GetCSSPropertyByName(psz, iLen); + args.pProperty = FDE_GetCSSPropertyByName(CFX_WideStringC(psz, iLen)); if (args.pProperty == NULL) { wsName = CFX_WideStringC(psz, iLen); } diff --git a/xfa/fde/css/fde_cssstylesheet.cpp b/xfa/fde/css/fde_cssstylesheet.cpp index 4afb0cee63..15358c2942 100644 --- a/xfa/fde/css/fde_cssstylesheet.cpp +++ b/xfa/fde/css/fde_cssstylesheet.cpp @@ -196,7 +196,7 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadMediaRule( int32_t iLen; const FX_WCHAR* psz = pSyntax->GetCurrentString(iLen); FDE_LPCCSSMEDIATYPETABLE pMediaType = - FDE_GetCSSMediaTypeByName(psz, iLen); + FDE_GetCSSMediaTypeByName(CFX_WideStringC(psz, iLen)); if (pMediaType != NULL) { dwMediaList |= pMediaType->wValue; } @@ -249,7 +249,8 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadStyleRule( } break; case FDE_CSSSYNTAXSTATUS_PropertyName: pszValue = pSyntax->GetCurrentString(iValueLen); - propertyArgs.pProperty = FDE_GetCSSPropertyByName(pszValue, iValueLen); + propertyArgs.pProperty = + FDE_GetCSSPropertyByName(CFX_WideStringC(pszValue, iValueLen)); if (propertyArgs.pProperty == NULL) { wsName = CFX_WideStringC(pszValue, iValueLen); } @@ -305,7 +306,8 @@ FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadFontFaceRule( switch (pSyntax->DoSyntaxParse()) { case FDE_CSSSYNTAXSTATUS_PropertyName: pszValue = pSyntax->GetCurrentString(iValueLen); - propertyArgs.pProperty = FDE_GetCSSPropertyByName(pszValue, iValueLen); + propertyArgs.pProperty = + FDE_GetCSSPropertyByName(CFX_WideStringC(pszValue, iValueLen)); break; case FDE_CSSSYNTAXSTATUS_PropertyValue: if (propertyArgs.pProperty != NULL) { @@ -434,7 +436,7 @@ IFDE_CSSSelector* CFDE_CSSSelector::FromString(IFX_MEMAllocator* pStaticStore, if (wch == '.' || wch == '#') { if (psz == pStart || psz[-1] == ' ') { CFDE_CSSSelector* p = FXTARGET_NewWith(pStaticStore) - CFDE_CSSSelector(FDE_CSSSELECTORTYPE_Element, L"*", 1, TRUE); + CFDE_CSSSelector(FDE_CSSSELECTORTYPE_Element, L"*", 1, true); if (p == NULL) { return NULL; } @@ -452,7 +454,7 @@ IFDE_CSSSelector* CFDE_CSSSelector::FromString(IFX_MEMAllocator* pStaticStore, FDE_CSSSELECTORTYPE eType = wch == '.' ? FDE_CSSSELECTORTYPE_Class : FDE_CSSSELECTORTYPE_ID; CFDE_CSSSelector* p = FXTARGET_NewWith(pStaticStore) - CFDE_CSSSelector(eType, psz, iNameLen, FALSE); + CFDE_CSSSelector(eType, psz, iNameLen, false); if (p == NULL) { return NULL; } @@ -466,7 +468,7 @@ IFDE_CSSSelector* CFDE_CSSSelector::FromString(IFX_MEMAllocator* pStaticStore, return NULL; } CFDE_CSSSelector* p = FXTARGET_NewWith(pStaticStore) - CFDE_CSSSelector(FDE_CSSSELECTORTYPE_Element, psz, iNameLen, TRUE); + CFDE_CSSSelector(FDE_CSSSELECTORTYPE_Element, psz, iNameLen, true); if (p == NULL) { return NULL; } @@ -484,7 +486,7 @@ IFDE_CSSSelector* CFDE_CSSSelector::FromString(IFX_MEMAllocator* pStaticStore, return NULL; } CFDE_CSSSelector* p = FXTARGET_NewWith(pStaticStore) - CFDE_CSSSelector(FDE_CSSSELECTORTYPE_Persudo, psz, iNameLen, TRUE); + CFDE_CSSSelector(FDE_CSSSELECTORTYPE_Persudo, psz, iNameLen, true); if (p == NULL) { return NULL; } diff --git a/xfa/fde/css/fde_cssstylesheet.h b/xfa/fde/css/fde_cssstylesheet.h index 8ae8bd5393..21770bfe2b 100644 --- a/xfa/fde/css/fde_cssstylesheet.h +++ b/xfa/fde/css/fde_cssstylesheet.h @@ -15,10 +15,10 @@ class CFDE_CSSSelector : public IFDE_CSSSelector, public CFX_Target { CFDE_CSSSelector(FDE_CSSSELECTORTYPE eType, const FX_WCHAR* psz, int32_t iLen, - FX_BOOL bIgnoreCase) + bool bIgnoreCase) : m_eType(eType), - m_dwHash(FX_HashCode_String_GetW(psz, iLen, bIgnoreCase)), - m_pNext(NULL) {} + m_dwHash(FX_HashCode_GetW(CFX_WideStringC(psz, iLen), bIgnoreCase)), + m_pNext(nullptr) {} virtual FDE_CSSSELECTORTYPE GetType() const { return m_eType; } virtual uint32_t GetNameHash() const { return m_dwHash; } @@ -41,6 +41,7 @@ class CFDE_CSSSelector : public IFDE_CSSSelector, public CFX_Target { IFDE_CSSSelector* m_pNext; }; typedef CFX_ArrayTemplate<IFDE_CSSSelector*> CFDE_CSSSelectorArray; + class CFDE_CSSStyleRule : public IFDE_CSSStyleRule, public CFX_Target { public: CFDE_CSSStyleRule() : m_ppSelector(NULL), m_iSelectors(0) {} diff --git a/xfa/fgas/crt/fgas_codepage.cpp b/xfa/fgas/crt/fgas_codepage.cpp index 4734a0005e..36c40a6469 100644 --- a/xfa/fgas/crt/fgas_codepage.cpp +++ b/xfa/fgas/crt/fgas_codepage.cpp @@ -309,12 +309,12 @@ uint16_t FX_GetCodePageFromStringA(const FX_CHAR* pStr, int32_t iLength) { if (iLength == 0) { return 0xFFFF; } - uint32_t uHash = FX_HashCode_String_GetA(pStr, iLength, TRUE); - int32_t iStart = 0, iMid; + uint32_t uHash = FX_HashCode_GetA(CFX_ByteStringC(pStr, iLength), true); + int32_t iStart = 0; int32_t iEnd = sizeof(g_FXCPHashTable) / sizeof(FX_STR2CPHASH) - 1; FXSYS_assert(iEnd >= 0); do { - iMid = (iStart + iEnd) / 2; + int32_t iMid = (iStart + iEnd) / 2; const FX_STR2CPHASH& cp = g_FXCPHashTable[iMid]; if (uHash == cp.uHash) { return (uint16_t)cp.uCodePage; diff --git a/xfa/fgas/font/fgas_fontutils.cpp b/xfa/fgas/font/fgas_fontutils.cpp index 12271fbb64..21d5d0b5a5 100644 --- a/xfa/fgas/font/fgas_fontutils.cpp +++ b/xfa/fgas/font/fgas_fontutils.cpp @@ -42,7 +42,7 @@ uint32_t FGAS_GetFontFamilyHash(const FX_WCHAR* pszFontFamily, wsFont += L"Italic"; } wsFont += wCodePage; - return FX_HashCode_String_GetW(wsFont.c_str(), wsFont.GetLength()); + return FX_HashCode_GetW(wsFont.AsStringC(), false); } static const FGAS_FONTUSB g_FXGdiFontUSBTable[] = { {0x0000, 0x007F, 0, 1252}, {0x0080, 0x00FF, 1, 1252}, diff --git a/xfa/fgas/font/fgas_stdfontmgr.cpp b/xfa/fgas/font/fgas_stdfontmgr.cpp index 9e8c824118..4b2a1422d2 100644 --- a/xfa/fgas/font/fgas_stdfontmgr.cpp +++ b/xfa/fgas/font/fgas_stdfontmgr.cpp @@ -176,7 +176,7 @@ IFX_Font* CFX_StdFontMgrImp::LoadFont(const uint8_t* pBuffer, int32_t iLength) { } IFX_Font* CFX_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFileName) { FXSYS_assert(pszFileName != NULL); - uint32_t dwHash = FX_HashCode_String_GetW(pszFileName, -1); + uint32_t dwHash = FX_HashCode_GetW(pszFileName, false); IFX_Font* pFont = NULL; if (m_FileFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { if (pFont != NULL) { @@ -230,8 +230,8 @@ IFX_Font* CFX_StdFontMgrImp::LoadFont(IFX_Font* pSrcFont, } void* buffer[3] = {pSrcFont, (void*)(uintptr_t)dwFontStyles, (void*)(uintptr_t)wCodePage}; - uint32_t dwHash = - FX_HashCode_String_GetA((const FX_CHAR*)buffer, 3 * sizeof(void*)); + uint32_t dwHash = FX_HashCode_GetA( + CFX_ByteStringC((uint8_t*)buffer, sizeof(buffer)), false); IFX_Font* pFont = NULL; if (m_DeriveFonts.GetCount() > 0) { m_DeriveFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont); @@ -702,8 +702,7 @@ IFX_Font* CFX_FontMgrImp::GetFontByCodePage(uint16_t wCodePage, CFX_ByteString bsHash; bsHash.Format("%d, %d", wCodePage, dwFontStyles); bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); - uint32_t dwHash = FX_HashCode_String_GetA(bsHash.c_str(), bsHash.GetLength()); - + uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); CFX_ArrayTemplate<IFX_Font*>* pFonts = nullptr; if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { if (!pFonts) @@ -759,7 +758,7 @@ IFX_Font* CFX_FontMgrImp::GetFontByUnicode(FX_WCHAR wUnicode, else bsHash.Format("%d, %d", wCodePage, dwFontStyles); bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); - uint32_t dwHash = FX_HashCode_String_GetA(bsHash.c_str(), bsHash.GetLength()); + uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); CFX_ArrayTemplate<IFX_Font*>* pFonts = nullptr; if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { if (!pFonts) @@ -847,7 +846,7 @@ IFX_Font* CFX_FontMgrImp::LoadFont(const uint8_t* pBuffer, int32_t* pFaceCount) { void* Hash[2] = {(void*)(uintptr_t)pBuffer, (void*)(uintptr_t)iLength}; uint32_t dwHash = - FX_HashCode_String_GetA((const FX_CHAR*)Hash, 2 * sizeof(void*)); + FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)Hash, sizeof(Hash)), false); IFX_FileAccess* pFontAccess = nullptr; m_Hash2FileAccess.Lookup(dwHash, pFontAccess); return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE) @@ -860,7 +859,7 @@ IFX_Font* CFX_FontMgrImp::LoadFont(const FX_WCHAR* pszFileName, CFX_ByteString bsHash; bsHash += CFX_WideString(pszFileName).UTF8Encode(); - uint32_t dwHash = FX_HashCode_String_GetA(bsHash.c_str(), bsHash.GetLength()); + uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); IFX_FileAccess* pFontAccess = nullptr; if (!m_Hash2FileAccess.Lookup(dwHash, pFontAccess)) { pFontAccess = FX_CreateDefaultFileAccess(pszFileName); @@ -877,7 +876,7 @@ IFX_Font* CFX_FontMgrImp::LoadFont(IFX_Stream* pFontStream, FX_BOOL bSaveStream) { void* Hash[1] = {(void*)(uintptr_t)pFontStream}; uint32_t dwHash = - FX_HashCode_String_GetA((const FX_CHAR*)Hash, 1 * sizeof(void*)); + FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)Hash, sizeof(Hash)), false); IFX_FileAccess* pFontAccess = nullptr; m_Hash2FileAccess.Lookup(dwHash, pFontAccess); @@ -894,7 +893,7 @@ IFX_Font* CFX_FontMgrImp::LoadFont(IFX_FileAccess* pFontAccess, if (bWantCache) { CFX_ByteString bsHash; bsHash.Format("%d, %d", (uintptr_t)pFontAccess, iFaceIndex); - dwHash = FX_HashCode_String_GetA(bsHash.c_str(), bsHash.GetLength()); + dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); if (m_FileAccess2IFXFont.Lookup(dwHash, pFont)) { if (pFont) { if (pFaceCount) diff --git a/xfa/fgas/localization/fgas_locale.cpp b/xfa/fgas/localization/fgas_locale.cpp index 6e0add1fa5..9a8e05cbc7 100644 --- a/xfa/fgas/localization/fgas_locale.cpp +++ b/xfa/fgas/localization/fgas_locale.cpp @@ -595,8 +595,7 @@ FX_LOCALECATEGORY CFX_FormatString::GetCategory( wsCategory += pStr[ccf]; ccf++; } - uint32_t dwHash = - FX_HashCode_String_GetW(wsCategory.c_str(), wsCategory.GetLength()); + uint32_t dwHash = FX_HashCode_GetW(wsCategory.AsStringC(), false); if (dwHash == FX_LOCALECATEGORY_DateHash) { if (eCategory == FX_LOCALECATEGORY_Time) { return FX_LOCALECATEGORY_DateTime; @@ -755,8 +754,8 @@ IFX_Locale* CFX_FormatString::GetNumericFormat(const CFX_WideString& wsPattern, while (ccf < iLenf && pStr[ccf] != '(' && pStr[ccf] != '{') { wsSubCategory += pStr[ccf++]; } - uint32_t dwSubHash = FX_HashCode_String_GetW( - wsSubCategory.c_str(), wsSubCategory.GetLength()); + uint32_t dwSubHash = + FX_HashCode_GetW(wsSubCategory.AsStringC(), false); FX_LOCALENUMSUBCATEGORY eSubCategory = FX_LOCALENUMPATTERN_Decimal; for (int32_t i = 0; i < g_iFXLocaleNumSubCatCount; i++) { if (g_FXLocaleNumSubCatData[i].uHash == dwSubHash) { @@ -2209,8 +2208,8 @@ FX_DATETIMETYPE CFX_FormatString::GetDateTimeFormat( while (ccf < iLenf && pStr[ccf] != '(' && pStr[ccf] != '{') { wsSubCategory += pStr[ccf++]; } - uint32_t dwSubHash = FX_HashCode_String_GetW( - wsSubCategory.c_str(), wsSubCategory.GetLength()); + uint32_t dwSubHash = + FX_HashCode_GetW(wsSubCategory.AsStringC(), false); FX_LOCALEDATETIMESUBCATEGORY eSubCategory = FX_LOCALEDATETIMESUBCATEGORY_Medium; for (int32_t i = 0; i < g_iFXLocaleDateTimeSubCatCount; i++) { diff --git a/xfa/fxfa/app/xfa_ffbarcode.cpp b/xfa/fxfa/app/xfa_ffbarcode.cpp index 567882d546..b4608a349e 100644 --- a/xfa/fxfa/app/xfa_ffbarcode.cpp +++ b/xfa/fxfa/app/xfa_ffbarcode.cpp @@ -94,12 +94,12 @@ const int32_t g_iXFABarcodeTypeCount = XFA_LPCBARCODETYPEENUMINFO XFA_GetBarcodeTypeByName( const CFX_WideStringC& wsName) { - int32_t iLength = wsName.GetLength(); - if (iLength == 0) { - return NULL; - } - uint32_t uHash = FX_HashCode_String_GetW(wsName.c_str(), iLength, TRUE); - int32_t iStart = 0, iEnd = g_iXFABarcodeTypeCount - 1; + if (wsName.IsEmpty()) + return nullptr; + + uint32_t uHash = FX_HashCode_GetW(wsName, true); + int32_t iStart = 0; + int32_t iEnd = g_iXFABarcodeTypeCount - 1; do { int32_t iMid = (iStart + iEnd) / 2; XFA_LPCBARCODETYPEENUMINFO pInfo = g_XFABarCodeTypeEnumData + iMid; diff --git a/xfa/fxfa/app/xfa_ffdoc.cpp b/xfa/fxfa/app/xfa_ffdoc.cpp index 1fecee7547..4b0f67bb6a 100644 --- a/xfa/fxfa/app/xfa_ffdoc.cpp +++ b/xfa/fxfa/app/xfa_ffdoc.cpp @@ -326,8 +326,7 @@ CFX_DIBitmap* CXFA_FFDoc::GetPDFNamedImage(const CFX_WideStringC& wsName, if (!m_pPDFDoc) return nullptr; - uint32_t dwHash = - FX_HashCode_String_GetW(wsName.c_str(), wsName.GetLength(), FALSE); + uint32_t dwHash = FX_HashCode_GetW(wsName, false); FX_IMAGEDIB_AND_DPI* imageDIBDpi = nullptr; if (m_mapNamedImages.Lookup((void*)(uintptr_t)dwHash, (void*&)imageDIBDpi)) { iImageXDpi = imageDIBDpi->iImageXDpi; @@ -384,8 +383,7 @@ CFX_DIBitmap* CXFA_FFDoc::GetPDFNamedImage(const CFX_WideStringC& wsName, } CFDE_XMLElement* CXFA_FFDoc::GetPackageData(const CFX_WideStringC& wsPackage) { - uint32_t packetHash = - FX_HashCode_String_GetW(wsPackage.c_str(), wsPackage.GetLength()); + uint32_t packetHash = FX_HashCode_GetW(wsPackage, false); CXFA_Node* pNode = ToNode(m_pDocument->GetXFAObject(packetHash)); if (!pNode) { return NULL; @@ -399,8 +397,7 @@ FX_BOOL CXFA_FFDoc::SavePackage(const CFX_WideStringC& wsPackage, IFX_FileWrite* pFile, CXFA_ChecksumContext* pCSContext) { CXFA_DataExporter* pExport = new CXFA_DataExporter(m_pDocument); - uint32_t packetHash = - FX_HashCode_String_GetW(wsPackage.c_str(), wsPackage.GetLength()); + uint32_t packetHash = FX_HashCode_GetW(wsPackage, false); CXFA_Node* pNode = NULL; if (packetHash == XFA_HASHCODE_Xfa) { pNode = m_pDocument->GetRoot(); diff --git a/xfa/fxfa/app/xfa_ffdocview.cpp b/xfa/fxfa/app/xfa_ffdocview.cpp index 986e265a45..7a858748b7 100644 --- a/xfa/fxfa/app/xfa_ffdocview.cpp +++ b/xfa/fxfa/app/xfa_ffdocview.cpp @@ -779,9 +779,9 @@ void CXFA_FFDocView::RunBindItems() { wsLabelRef.IsEmpty() || wsLabelRef == FX_WSTRC(L"$"); const bool bValueUseContent = wsValueRef.IsEmpty() || wsValueRef == FX_WSTRC(L"$"); - CFX_WideString wsValue, wsLabel; - uint32_t uValueHash = - FX_HashCode_String_GetW(wsValueRef.c_str(), wsValueRef.GetLength()); + CFX_WideString wsValue; + CFX_WideString wsLabel; + uint32_t uValueHash = FX_HashCode_GetW(wsValueRef, false); for (int32_t i = 0; i < iCount; i++) { CXFA_Object* refObj = rs.nodes[i]; if (!refObj->IsNode()) { diff --git a/xfa/fxfa/app/xfa_fontmgr.cpp b/xfa/fxfa/app/xfa_fontmgr.cpp index 72952a7bd9..02b44be789 100644 --- a/xfa/fxfa/app/xfa_fontmgr.cpp +++ b/xfa/fxfa/app/xfa_fontmgr.cpp @@ -1694,12 +1694,7 @@ static const XFA_FONTINFO g_XFAFontsMap[] = { void XFA_LocalFontNameToEnglishName(const CFX_WideStringC& wsLocalName, CFX_WideString& wsEnglishName) { wsEnglishName = wsLocalName; -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ || \ - _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \ - _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \ - _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ - uint32_t dwLocalNameHash = FX_HashCode_String_GetW( - wsLocalName.c_str(), wsLocalName.GetLength(), TRUE); + uint32_t dwLocalNameHash = FX_HashCode_GetW(wsLocalName, true); int32_t iStart = 0; int32_t iEnd = sizeof(g_XFAFontsMap) / sizeof(XFA_FONTINFO) - 1; int32_t iMid = 0; @@ -1715,18 +1710,13 @@ void XFA_LocalFontNameToEnglishName(const CFX_WideStringC& wsLocalName, iEnd = iMid - 1; } } while (iEnd >= iStart); -#endif } const XFA_FONTINFO* XFA_GetFontINFOByFontName( const CFX_WideStringC& wsFontName) { -#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ || \ - _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \ - _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \ - _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ CFX_WideString wsFontNameTemp = wsFontName; wsFontNameTemp.Remove(L' '); - uint32_t dwCurFontNameHash = FX_HashCode_String_GetW( - wsFontNameTemp.c_str(), wsFontNameTemp.GetLength(), TRUE); + uint32_t dwCurFontNameHash = + FX_HashCode_GetW(wsFontNameTemp.AsStringC(), true); int32_t iStart = 0; int32_t iEnd = sizeof(g_XFAFontsMap) / sizeof(XFA_FONTINFO) - 1; int32_t iMid = 0; @@ -1744,9 +1734,6 @@ const XFA_FONTINFO* XFA_GetFontINFOByFontName( } } while (iEnd >= iStart); return pFontInfo; -#else - return NULL; -#endif } CXFA_DefFontMgr::~CXFA_DefFontMgr() { @@ -1891,8 +1878,7 @@ IFX_Font* CXFA_PDFFontMgr::GetFont(const CFX_WideStringC& wsFontFamily, uint32_t dwFontStyles, CPDF_Font** pPDFFont, FX_BOOL bStrictMatch) { - uint32_t dwHashCode = - FX_HashCode_String_GetW(wsFontFamily.c_str(), wsFontFamily.GetLength()); + uint32_t dwHashCode = FX_HashCode_GetW(wsFontFamily, false); CFX_ByteString strKey; strKey.Format("%u%u", dwHashCode, dwFontStyles); auto it = m_FontMap.find(strKey); @@ -2018,8 +2004,7 @@ IFX_Font* CXFA_FontMgr::GetFont(CXFA_FFDoc* hDoc, const CFX_WideStringC& wsFontFamily, uint32_t dwFontStyles, uint16_t wCodePage) { - uint32_t dwHash = FX_HashCode_String_GetW(wsFontFamily.c_str(), - wsFontFamily.GetLength(), FALSE); + uint32_t dwHash = FX_HashCode_GetW(wsFontFamily, false); CFX_ByteString bsKey; bsKey.Format("%u%u%u", dwHash, dwFontStyles, wCodePage); auto it = m_FontMap.find(bsKey); diff --git a/xfa/fxfa/app/xfa_textlayout.cpp b/xfa/fxfa/app/xfa_textlayout.cpp index b2030814bc..b259a7f357 100644 --- a/xfa/fxfa/app/xfa_textlayout.cpp +++ b/xfa/fxfa/app/xfa_textlayout.cpp @@ -112,22 +112,22 @@ IFDE_CSSComputedStyle* CXFA_TextParser::CreateRootStyle( FDE_CSSLENGTH indent; indent.Set(FDE_CSSLENGTHUNIT_Point, para.GetTextIndent()); pParaStyle->SetTextIndent(indent); - FDE_CSSTEXTALIGN hAlgin = FDE_CSSTEXTALIGN_Left; + FDE_CSSTEXTALIGN hAlign = FDE_CSSTEXTALIGN_Left; switch (para.GetHorizontalAlign()) { case XFA_ATTRIBUTEENUM_Center: - hAlgin = FDE_CSSTEXTALIGN_Center; + hAlign = FDE_CSSTEXTALIGN_Center; break; case XFA_ATTRIBUTEENUM_Right: - hAlgin = FDE_CSSTEXTALIGN_Right; + hAlign = FDE_CSSTEXTALIGN_Right; break; case XFA_ATTRIBUTEENUM_Justify: - hAlgin = FDE_CSSTEXTALIGN_Justify; + hAlign = FDE_CSSTEXTALIGN_Justify; break; case XFA_ATTRIBUTEENUM_JustifyAll: - hAlgin = FDE_CSSTEXTALIGN_JustifyAll; + hAlign = FDE_CSSTEXTALIGN_JustifyAll; break; } - pParaStyle->SetTextAlign(hAlgin); + pParaStyle->SetTextAlign(hAlign); FDE_CSSRECT rtMarginWidth; rtMarginWidth.left.Set(FDE_CSSLENGTHUNIT_Point, para.GetMarginLeft()); rtMarginWidth.top.Set(FDE_CSSLENGTHUNIT_Point, para.GetSpaceAbove()); @@ -275,8 +275,7 @@ void CXFA_TextParser::ParseTagInfo(CFDE_XMLNode* pXMLNode, CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); pXMLElement->GetLocalTagName(wsName); tagProvider.SetTagNameObj(wsName); - uint32_t dwHashCode = - FX_HashCode_String_GetW(wsName.c_str(), wsName.GetLength(), TRUE); + 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 = @@ -292,7 +291,7 @@ void CXFA_TextParser::ParseTagInfo(CFDE_XMLNode* pXMLNode, } } -int32_t CXFA_TextParser::GetVAlgin(CXFA_TextProvider* pTextProvider) const { +int32_t CXFA_TextParser::GetVAlign(CXFA_TextProvider* pTextProvider) const { CXFA_Para para = pTextProvider->GetParaNode(); return para ? para.GetVerticalAlign() : XFA_ATTRIBUTEENUM_Top; } @@ -613,8 +612,7 @@ FX_BOOL CXFA_TextParser::GetTabstops( break; case XFA_TABSTOPSSTATUS_Location: if (ch == ' ') { - uint32_t dwHashCode = FX_HashCode_String_GetW( - wsAlign.c_str(), wsAlign.GetLength(), TRUE); + uint32_t dwHashCode = FX_HashCode_GetW(wsAlign.AsStringC(), true); CXFA_Measurement ms(CFX_WideStringC(pTabStops + iLast, iCur - iLast)); FX_FLOAT fPos = ms.ToUnit(XFA_UNIT_Pt); pTabstopContext->Append(dwHashCode, fPos); @@ -628,8 +626,7 @@ FX_BOOL CXFA_TextParser::GetTabstops( } } if (!wsAlign.IsEmpty()) { - uint32_t dwHashCode = - FX_HashCode_String_GetW(wsAlign.c_str(), wsAlign.GetLength(), TRUE); + uint32_t dwHashCode = FX_HashCode_GetW(wsAlign.AsStringC(), true); CXFA_Measurement ms(CFX_WideStringC(pTabStops + iLast, iCur - iLast)); FX_FLOAT fPos = ms.ToUnit(XFA_UNIT_Pt); pTabstopContext->Append(dwHashCode, fPos); @@ -934,7 +931,7 @@ FX_BOOL CXFA_TextLayout::DoLayout(int32_t iBlockIndex, if (iBlockCount == 0 && fHeight > 0) { fHeight = fTextHeight - GetLayoutHeight(); if (fHeight > 0) { - int32_t iAlign = m_textParser.GetVAlgin(m_pTextProvider); + int32_t iAlign = m_textParser.GetVAlign(m_pTextProvider); if (iAlign == XFA_ATTRIBUTEENUM_Middle) { fHeight /= 2.0f; } else if (iAlign != XFA_ATTRIBUTEENUM_Bottom) { @@ -1253,7 +1250,7 @@ void CXFA_TextLayout::UpdateAlign(FX_FLOAT fHeight, FX_FLOAT fBottom) { if (fHeight < 0.1f) { return; } - switch (m_textParser.GetVAlgin(m_pTextProvider)) { + switch (m_textParser.GetVAlign(m_pTextProvider)) { case XFA_ATTRIBUTEENUM_Middle: fHeight /= 2.0f; break; @@ -1643,13 +1640,13 @@ void CXFA_TextLayout::DoTabstops(IFDE_CSSComputedStyle* pStyle, if (m_pTabstopContext->m_bTabstops) { XFA_TABSTOPS* pTabstops = m_pTabstopContext->m_tabstops.GetDataPtr(iTabstopsIndex); - uint32_t dwAlgin = pTabstops->dwAlign; - if (dwAlgin == FX_HashCode_String_GetW(L"center", 6)) { + uint32_t dwAlign = pTabstops->dwAlign; + if (dwAlign == FX_HashCode_GetW(L"center", false)) { fLeft = pPiece->rtPiece.width / 2.0f; - } else if (dwAlgin == FX_HashCode_String_GetW(L"right", 5) || - dwAlgin == FX_HashCode_String_GetW(L"before", 6)) { + } else if (dwAlign == FX_HashCode_GetW(L"right", false) || + dwAlign == FX_HashCode_GetW(L"before", false)) { fLeft = pPiece->rtPiece.width; - } else if (dwAlgin == FX_HashCode_String_GetW(L"decimal", 7)) { + } else if (dwAlign == FX_HashCode_GetW(L"decimal", false)) { int32_t iChars = pPiece->iChars; for (int32_t i = 0; i < iChars; i++) { if (pPiece->pszText[i] == L'.') { diff --git a/xfa/fxfa/app/xfa_textlayout.h b/xfa/fxfa/app/xfa_textlayout.h index 9cced6a65a..ccebff8ad9 100644 --- a/xfa/fxfa/app/xfa_textlayout.h +++ b/xfa/fxfa/app/xfa_textlayout.h @@ -87,7 +87,7 @@ class CXFA_TextParser { IFDE_CSSComputedStyle* pParentStyle); FX_BOOL IsParsed() const { return m_pAllocator != NULL; } - int32_t GetVAlgin(CXFA_TextProvider* pTextProvider) const; + int32_t GetVAlign(CXFA_TextProvider* pTextProvider) const; FX_FLOAT GetTabInterval(IFDE_CSSComputedStyle* pStyle) const; int32_t CountTabs(IFDE_CSSComputedStyle* pStyle) const; FX_BOOL IsSpaceRun(IFDE_CSSComputedStyle* pStyle) const; diff --git a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp index 351aedd669..9ab426d541 100644 --- a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp +++ b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp @@ -4238,19 +4238,17 @@ void CXFA_FM2JSContext::EncodeXML(const CFX_ByteStringC& szXMLString, } FX_BOOL CXFA_FM2JSContext::HTMLSTR2Code(const CFX_WideStringC& pData, uint32_t& iCode) { - int32_t iLength = pData.GetLength(); - uint32_t uHash = FX_HashCode_String_GetW(pData.c_str(), iLength); - XFA_FMHtmlHashedReserveCode htmlhashedreservecode; - int32_t iStart = 0, - iEnd = (sizeof(reservesForDecode) / sizeof(reservesForDecode[0])) - 1; - int32_t iMid = (iStart + iEnd) / 2; + uint32_t uHash = FX_HashCode_GetW(pData, false); + int32_t iStart = 0; + int32_t iEnd = FX_ArraySize(reservesForDecode) - 1; do { - iMid = (iStart + iEnd) / 2; - htmlhashedreservecode = reservesForDecode[iMid]; + int32_t iMid = (iStart + iEnd) / 2; + XFA_FMHtmlHashedReserveCode htmlhashedreservecode = reservesForDecode[iMid]; if (uHash == htmlhashedreservecode.m_uHash) { iCode = htmlhashedreservecode.m_uCode; return TRUE; - } else if (uHash < htmlhashedreservecode.m_uHash) { + } + if (uHash < htmlhashedreservecode.m_uHash) { iEnd = iMid - 1; } else { iStart = iMid + 1; diff --git a/xfa/fxfa/fm2js/xfa_lexer.cpp b/xfa/fxfa/fm2js/xfa_lexer.cpp index 4462bd5154..dd3b48ff54 100644 --- a/xfa/fxfa/fm2js/xfa_lexer.cpp +++ b/xfa/fxfa/fm2js/xfa_lexer.cpp @@ -516,21 +516,18 @@ void CXFA_FMLexer::Comment(const FX_WCHAR* p, const FX_WCHAR*& pEnd) { } XFA_FM_TOKEN CXFA_FMLexer::IsKeyword(const CFX_WideStringC& str) { - int32_t iLength = str.GetLength(); - uint32_t uHash = FX_HashCode_String_GetW(str.c_str(), iLength, TRUE); - int32_t iStart = KEYWORD_START, iEnd = KEYWORD_END; - int32_t iMid = (iStart + iEnd) / 2; - XFA_FMKeyword keyword; + uint32_t uHash = FX_HashCode_GetW(str, true); + int32_t iStart = KEYWORD_START; + int32_t iEnd = KEYWORD_END; do { - iMid = (iStart + iEnd) / 2; - keyword = keyWords[iMid]; - if (uHash == keyword.m_uHash) { + int32_t iMid = (iStart + iEnd) / 2; + XFA_FMKeyword keyword = keyWords[iMid]; + if (uHash == keyword.m_uHash) return keyword.m_type; - } else if (uHash < keyword.m_uHash) { + if (uHash < keyword.m_uHash) iEnd = iMid - 1; - } else { + else iStart = iMid + 1; - } } while (iStart <= iEnd); return TOKidentifier; } diff --git a/xfa/fxfa/fm2js/xfa_simpleexpression.cpp b/xfa/fxfa/fm2js/xfa_simpleexpression.cpp index f6c12ae64d..f652961b6e 100644 --- a/xfa/fxfa/fm2js/xfa_simpleexpression.cpp +++ b/xfa/fxfa/fm2js/xfa_simpleexpression.cpp @@ -483,8 +483,7 @@ CXFA_FMCallExpression::~CXFA_FMCallExpression() { } bool CXFA_FMCallExpression::IsBuildInFunc(CFX_WideTextBuf* funcName) { - uint32_t uHash = FX_HashCode_String_GetW(funcName->GetBuffer(), - funcName->GetLength(), TRUE); + uint32_t uHash = FX_HashCode_GetW(funcName->AsStringC(), true); const XFA_FMBuildInFunc* pEnd = g_BuildInFuncs + FX_ArraySize(g_BuildInFuncs); const XFA_FMBuildInFunc* pFunc = std::lower_bound(g_BuildInFuncs, pEnd, uHash, @@ -501,8 +500,7 @@ bool CXFA_FMCallExpression::IsBuildInFunc(CFX_WideTextBuf* funcName) { uint32_t CXFA_FMCallExpression::IsMethodWithObjParam( const CFX_WideStringC& methodName) { - int32_t iLength = methodName.GetLength(); - uint32_t uHash = FX_HashCode_String_GetW(methodName.c_str(), iLength); + uint32_t uHash = FX_HashCode_GetW(methodName, false); XFA_FMSOMMethod somMethodWithObjPara; uint32_t parameters = 0x00; int32_t iStart = 0, diff --git a/xfa/fxfa/parser/cxfa_widgetdata.cpp b/xfa/fxfa/parser/cxfa_widgetdata.cpp index a702527347..0c3d065a39 100644 --- a/xfa/fxfa/parser/cxfa_widgetdata.cpp +++ b/xfa/fxfa/parser/cxfa_widgetdata.cpp @@ -466,8 +466,7 @@ CXFA_Node* CXFA_WidgetData::GetSelectedMember() { CXFA_Node* CXFA_WidgetData::SetSelectedMember(const CFX_WideStringC& wsName, FX_BOOL bNotify) { CXFA_Node* pSelectedMember = NULL; - uint32_t nameHash = - FX_HashCode_String_GetW(wsName.c_str(), wsName.GetLength()); + uint32_t nameHash = FX_HashCode_GetW(wsName, false); for (CXFA_Node* pNode = ToNode(m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild)); pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { if (pNode->GetNameHash() == nameHash) { diff --git a/xfa/fxfa/parser/xfa_basic_imp.cpp b/xfa/fxfa/parser/xfa_basic_imp.cpp index 631b7c10ca..728ecfc319 100644 --- a/xfa/fxfa/parser/xfa_basic_imp.cpp +++ b/xfa/fxfa/parser/xfa_basic_imp.cpp @@ -21,12 +21,12 @@ #include "xfa/fxfa/parser/xfa_utils.h" const XFA_PACKETINFO* XFA_GetPacketByName(const CFX_WideStringC& wsName) { - int32_t iLength = wsName.GetLength(); - if (iLength == 0) { - return NULL; - } - uint32_t uHash = FX_HashCode_String_GetW(wsName.c_str(), iLength); - int32_t iStart = 0, iEnd = g_iXFAPacketCount - 1; + if (wsName.IsEmpty()) + return nullptr; + + uint32_t uHash = FX_HashCode_GetW(wsName, false); + int32_t iStart = 0; + int32_t iEnd = g_iXFAPacketCount - 1; do { int32_t iMid = (iStart + iEnd) / 2; const XFA_PACKETINFO* pInfo = g_XFAPacketData + iMid; @@ -63,12 +63,12 @@ const XFA_PACKETINFO* XFA_GetPacketByIndex(XFA_PACKET ePacket) { const XFA_ATTRIBUTEENUMINFO* XFA_GetAttributeEnumByName( const CFX_WideStringC& wsName) { - int32_t iLength = wsName.GetLength(); - if (iLength == 0) { - return NULL; - } - uint32_t uHash = FX_HashCode_String_GetW(wsName.c_str(), iLength); - int32_t iStart = 0, iEnd = g_iXFAEnumCount - 1; + 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; @@ -87,12 +87,12 @@ const XFA_ATTRIBUTEENUMINFO* XFA_GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) { } const XFA_ATTRIBUTEINFO* XFA_GetAttributeByName(const CFX_WideStringC& wsName) { - int32_t iLength = wsName.GetLength(); - if (iLength == 0) { - return NULL; - } - uint32_t uHash = FX_HashCode_String_GetW(wsName.c_str(), iLength); - int32_t iStart = 0, iEnd = g_iXFAAttributeCount - 1; + if (wsName.IsEmpty()) + return nullptr; + + uint32_t uHash = FX_HashCode_GetW(wsName, false); + int32_t iStart = 0; + int32_t iEnd = g_iXFAAttributeCount - 1; do { int32_t iMid = (iStart + iEnd) / 2; const XFA_ATTRIBUTEINFO* pInfo = g_XFAAttributeData + iMid; @@ -104,7 +104,7 @@ const XFA_ATTRIBUTEINFO* XFA_GetAttributeByName(const CFX_WideStringC& wsName) { iStart = iMid + 1; } } while (iStart <= iEnd); - return NULL; + return nullptr; } const XFA_ATTRIBUTEINFO* XFA_GetAttributeByID(XFA_ATTRIBUTE eName) { return (eName < g_iXFAAttributeCount) ? (g_XFAAttributeData + eName) : NULL; @@ -177,12 +177,12 @@ CXFA_Measurement XFA_GetAttributeDefaultValue_Measure(XFA_ELEMENT eElement, } const XFA_ELEMENTINFO* XFA_GetElementByName(const CFX_WideStringC& wsName) { - int32_t iLength = wsName.GetLength(); - if (iLength == 0) { - return NULL; - } - uint32_t uHash = FX_HashCode_String_GetW(wsName.c_str(), iLength); - int32_t iStart = 0, iEnd = g_iXFAElementCount - 1; + if (wsName.IsEmpty()) + return nullptr; + + uint32_t uHash = FX_HashCode_GetW(wsName, false); + int32_t iStart = 0; + int32_t iEnd = g_iXFAElementCount - 1; do { int32_t iMid = (iStart + iEnd) / 2; const XFA_ELEMENTINFO* pInfo = g_XFAElementData + iMid; @@ -334,10 +334,9 @@ const XFA_NOTSUREATTRIBUTE* XFA_GetNotsureAttribute(XFA_ELEMENT eElement, const XFA_METHODINFO* XFA_GetMethodByName(XFA_ELEMENT eElement, const CFX_WideStringC& wsMethodName) { - int32_t iLength = wsMethodName.GetLength(); - if (iLength == 0) { - return NULL; - } + if (wsMethodName.IsEmpty()) + return nullptr; + int32_t iElementIndex = eElement; while (iElementIndex != -1) { const XFA_SCRIPTHIERARCHY* scriptIndex = g_XFAScriptIndex + iElementIndex; @@ -346,8 +345,9 @@ const XFA_METHODINFO* XFA_GetMethodByName(XFA_ELEMENT eElement, iElementIndex = scriptIndex->wParentIndex; continue; } - uint32_t uHash = FX_HashCode_String_GetW(wsMethodName.c_str(), iLength); - int32_t iStart = scriptIndex->wMethodStart, iEnd = iStart + icount - 1; + uint32_t uHash = FX_HashCode_GetW(wsMethodName, false); + int32_t iStart = scriptIndex->wMethodStart; + int32_t iEnd = iStart + icount - 1; do { int32_t iMid = (iStart + iEnd) / 2; const XFA_METHODINFO* pInfo = g_SomMethodData + iMid; @@ -366,10 +366,9 @@ const XFA_METHODINFO* XFA_GetMethodByName(XFA_ELEMENT eElement, const XFA_SCRIPTATTRIBUTEINFO* XFA_GetScriptAttributeByName( XFA_ELEMENT eElement, const CFX_WideStringC& wsAttributeName) { - int32_t iLength = wsAttributeName.GetLength(); - if (iLength == 0) { - return NULL; - } + if (wsAttributeName.IsEmpty()) + return nullptr; + int32_t iElementIndex = eElement; while (iElementIndex != -1) { const XFA_SCRIPTHIERARCHY* scriptIndex = g_XFAScriptIndex + iElementIndex; @@ -378,7 +377,7 @@ const XFA_SCRIPTATTRIBUTEINFO* XFA_GetScriptAttributeByName( iElementIndex = scriptIndex->wParentIndex; continue; } - uint32_t uHash = FX_HashCode_String_GetW(wsAttributeName.c_str(), iLength); + uint32_t uHash = FX_HashCode_GetW(wsAttributeName, false); int32_t iStart = scriptIndex->wAttributeStart, iEnd = iStart + icount - 1; do { int32_t iMid = (iStart + iEnd) / 2; diff --git a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp index 22d3c625c9..59e663eec1 100644 --- a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp +++ b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp @@ -397,52 +397,48 @@ static CXFA_Node* XFA_DataMerge_FindGlobalDataNode(CXFA_Document* pDocument, CFX_WideStringC wsName, CXFA_Node* pDataScope, XFA_ELEMENT eMatchNodeType) { - uint32_t dwNameHash = - wsName.IsEmpty() ? 0 : FX_HashCode_String_GetW(wsName.c_str(), - wsName.GetLength()); - if (dwNameHash != 0) { - CXFA_Node* pBounded = XFA_DataMerge_GetGlobalBinding(pDocument, dwNameHash); - if (!pBounded) { - pBounded = XFA_DataMerge_ScopeMatchGlobalBinding(pDataScope, dwNameHash, - eMatchNodeType); - if (pBounded) { - XFA_DataMerge_RegisterGlobalBinding(pDocument, dwNameHash, pBounded); - } + if (wsName.IsEmpty()) + return nullptr; + + uint32_t dwNameHash = FX_HashCode_GetW(wsName, false); + CXFA_Node* pBounded = XFA_DataMerge_GetGlobalBinding(pDocument, dwNameHash); + if (!pBounded) { + pBounded = XFA_DataMerge_ScopeMatchGlobalBinding(pDataScope, dwNameHash, + eMatchNodeType); + if (pBounded) { + XFA_DataMerge_RegisterGlobalBinding(pDocument, dwNameHash, pBounded); } - return pBounded; } - return NULL; + return pBounded; } + static CXFA_Node* XFA_DataMerge_FindOnceDataNode(CXFA_Document* pDocument, CFX_WideStringC wsName, CXFA_Node* pDataScope, XFA_ELEMENT eMatchNodeType) { - uint32_t dwNameHash = - wsName.IsEmpty() ? 0 : FX_HashCode_String_GetW(wsName.c_str(), - wsName.GetLength()); - if (dwNameHash != 0) { - for (CXFA_Node *pCurDataScope = pDataScope, *pLastDataScope = NULL; - pCurDataScope && - pCurDataScope->GetPacketID() == XFA_XDPPACKET_Datasets; - pLastDataScope = pCurDataScope, - pCurDataScope = - pCurDataScope->GetNodeItem(XFA_NODEITEM_Parent)) { - for (CXFA_Node* pDataChild = - pCurDataScope->GetFirstChildByName(dwNameHash); - pDataChild; - pDataChild = pDataChild->GetNextSameNameSibling(dwNameHash)) { - if (pDataChild == pLastDataScope || - (eMatchNodeType != XFA_ELEMENT_DataModel && - pDataChild->GetClassID() != eMatchNodeType) || - pDataChild->HasBindItem()) { - continue; - } - return pDataChild; + if (wsName.IsEmpty()) + return nullptr; + + uint32_t dwNameHash = FX_HashCode_GetW(wsName, false); + CXFA_Node* pLastDataScope = nullptr; + for (CXFA_Node* pCurDataScope = pDataScope; + pCurDataScope && pCurDataScope->GetPacketID() == XFA_XDPPACKET_Datasets; + pCurDataScope = pCurDataScope->GetNodeItem(XFA_NODEITEM_Parent)) { + for (CXFA_Node* pDataChild = pCurDataScope->GetFirstChildByName(dwNameHash); + pDataChild; + pDataChild = pDataChild->GetNextSameNameSibling(dwNameHash)) { + if (pDataChild == pLastDataScope || pDataChild->HasBindItem() || + (eMatchNodeType != XFA_ELEMENT_DataModel && + pDataChild->GetClassID() != eMatchNodeType)) { + continue; } + return pDataChild; } + pLastDataScope = pCurDataScope; } - return NULL; + return nullptr; } + static CXFA_Node* XFA_DataMerge_FindDataRefDataNode(CXFA_Document* pDocument, CFX_WideStringC wsRef, CXFA_Node* pDataScope, @@ -561,8 +557,8 @@ static CXFA_Node* XFA_NodeMerge_CloneOrMergeInstanceManager( CXFA_NodeArray& subforms) { CFX_WideStringC wsSubformName = pTemplateNode->GetCData(XFA_ATTRIBUTE_Name); CFX_WideString wsInstMgrNodeName = FX_WSTRC(L"_") + wsSubformName; - uint32_t dwInstNameHash = FX_HashCode_String_GetW( - wsInstMgrNodeName.c_str(), wsInstMgrNodeName.GetLength()); + uint32_t dwInstNameHash = + FX_HashCode_GetW(wsInstMgrNodeName.AsStringC(), false); CXFA_Node* pExistingNode = XFA_DataMerge_FindFormDOMInstance( pDocument, XFA_ELEMENT_InstanceManager, dwInstNameHash, pFormParent); if (pExistingNode) { diff --git a/xfa/fxfa/parser/xfa_document_imp.cpp b/xfa/fxfa/parser/xfa_document_imp.cpp index 39bdf2503c..ad3fd70e0d 100644 --- a/xfa/fxfa/parser/xfa_document_imp.cpp +++ b/xfa/fxfa/parser/xfa_document_imp.cpp @@ -94,8 +94,7 @@ CXFA_FFNotify* CXFA_Document::GetNotify() const { return m_pParser->GetNotify(); } CXFA_Object* CXFA_Document::GetXFAObject(const CFX_WideStringC& wsNodeName) { - return GetXFAObject( - FX_HashCode_String_GetW(wsNodeName.c_str(), wsNodeName.GetLength())); + return GetXFAObject(FX_HashCode_GetW(wsNodeName, false)); } CXFA_Object* CXFA_Document::GetXFAObject(uint32_t dwNodeNameHash) { switch (dwNodeNameHash) { @@ -367,8 +366,7 @@ void CXFA_Document::DoProtoMerge() { pNode = sIterator.MoveToNext()) { CFX_WideStringC wsIDVal; if (pNode->TryCData(XFA_ATTRIBUTE_Id, wsIDVal) && !wsIDVal.IsEmpty()) { - mIDMap[FX_HashCode_String_GetW(wsIDVal.c_str(), wsIDVal.GetLength())] = - pNode; + mIDMap[FX_HashCode_GetW(wsIDVal, false)] = pNode; } CFX_WideStringC wsUseVal; if (pNode->TryCData(XFA_ATTRIBUTE_Use, wsUseVal) && !wsUseVal.IsEmpty()) { @@ -426,9 +424,7 @@ void CXFA_Document::DoProtoMerge() { pProtoNode = resoveNodeRS.nodes[0]->AsNode(); } } else if (!wsID.IsEmpty()) { - if (!mIDMap.Lookup( - FX_HashCode_String_GetW(wsID.c_str(), wsID.GetLength()), - pProtoNode)) { + if (!mIDMap.Lookup(FX_HashCode_GetW(wsID, false), pProtoNode)) { continue; } } diff --git a/xfa/fxfa/parser/xfa_object_imp.cpp b/xfa/fxfa/parser/xfa_object_imp.cpp index 93b596ae99..fd54b1509b 100644 --- a/xfa/fxfa/parser/xfa_object_imp.cpp +++ b/xfa/fxfa/parser/xfa_object_imp.cpp @@ -1769,24 +1769,22 @@ static const XFA_ExecEventParaInfo gs_eventParaInfos[] = { }; const XFA_ExecEventParaInfo* GetEventParaInfoByName( const CFX_WideStringC& wsEventName) { - int32_t iLength = wsEventName.GetLength(); - uint32_t uHash = FX_HashCode_String_GetW(wsEventName.c_str(), iLength); - const XFA_ExecEventParaInfo* eventParaInfo = NULL; - int32_t iStart = 0, - iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1; - int32_t iMid = (iStart + iEnd) / 2; + uint32_t uHash = FX_HashCode_GetW(wsEventName, false); + int32_t iStart = 0; + int32_t iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1; do { - iMid = (iStart + iEnd) / 2; - eventParaInfo = &gs_eventParaInfos[iMid]; + int32_t iMid = (iStart + iEnd) / 2; + const XFA_ExecEventParaInfo* eventParaInfo = &gs_eventParaInfos[iMid]; if (uHash == eventParaInfo->m_uHash) { return eventParaInfo; - } else if (uHash < eventParaInfo->m_uHash) { + } + if (uHash < eventParaInfo->m_uHash) { iEnd = iMid - 1; } else { iStart = iMid + 1; } } while (iStart <= iEnd); - return NULL; + return nullptr; } void XFA_STRING_TO_RGB(CFX_WideString& strRGB, int32_t& r, @@ -3287,9 +3285,7 @@ int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) { ? wsInstManagerName : wsInstManagerName.Mid(1); uint32_t dInstanceNameHash = - wsInstanceName.IsEmpty() ? 0 : FX_HashCode_String_GetW( - wsInstanceName.c_str(), - wsInstanceName.GetLength()); + FX_HashCode_GetW(wsInstanceName.AsStringC(), false); CXFA_Node* pPrevSibling = (iDesired == 0) ? this : XFA_ScriptInstanceManager_GetItem(this, iDesired - 1); @@ -3726,7 +3722,7 @@ enum XFA_KEYTYPE { XFA_KEYTYPE_Element, }; void* XFA_GetMapKey_Custom(const CFX_WideStringC& wsKey) { - uint32_t dwKey = FX_HashCode_String_GetW(wsKey.c_str(), wsKey.GetLength()); + uint32_t dwKey = FX_HashCode_GetW(wsKey, false); return (void*)(uintptr_t)((dwKey << 1) | XFA_KEYTYPE_Custom); } void* XFA_GetMapKey_Element(XFA_ELEMENT eElement, XFA_ATTRIBUTE eAttribute) { @@ -4732,9 +4728,7 @@ FX_BOOL CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) { return TRUE; } CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const { - return GetFirstChildByName( - wsName.IsEmpty() ? 0 : FX_HashCode_String_GetW(wsName.c_str(), - wsName.GetLength())); + return GetFirstChildByName(FX_HashCode_GetW(wsName, false)); } CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const { for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode; @@ -4765,10 +4759,7 @@ CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const { } CXFA_Node* CXFA_Node::GetNextSameNameSibling( const CFX_WideStringC& wsNodeName) const { - return GetNextSameNameSibling( - wsNodeName.IsEmpty() ? 0 - : FX_HashCode_String_GetW(wsNodeName.c_str(), - wsNodeName.GetLength())); + return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false)); } CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_ELEMENT eElement) const { for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode; @@ -4951,17 +4942,13 @@ int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName, void CXFA_Node::UpdateNameHash() { const XFA_NOTSUREATTRIBUTE* pNotsure = XFA_GetNotsureAttribute(GetClassID(), XFA_ATTRIBUTE_Name); + CFX_WideStringC wsName; if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) { - CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name); - m_dwNameHash = - wsName.IsEmpty() ? 0 : FX_HashCode_String_GetW(wsName.c_str(), - wsName.GetLength()); + wsName = GetCData(XFA_ATTRIBUTE_Name); + m_dwNameHash = FX_HashCode_GetW(wsName, false); } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) { - CFX_WideStringC wsName = - XFA_GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName; - m_dwNameHash = - wsName.IsEmpty() ? 0 : FX_HashCode_String_GetW(wsName.c_str(), - wsName.GetLength()); + wsName = XFA_GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName; + m_dwNameHash = FX_HashCode_GetW(wsName, false); } } CFDE_XMLNode* CXFA_Node::CreateXMLMappingNode() { @@ -5233,14 +5220,12 @@ CXFA_NodeList::CXFA_NodeList(CXFA_Document* pDocument) m_pDocument->GetScriptContext()->CacheList(this); } CXFA_Node* CXFA_NodeList::NamedItem(const CFX_WideStringC& wsName) { + uint32_t dwHashCode = FX_HashCode_GetW(wsName, false); int32_t iCount = GetLength(); - uint32_t dwHashCode = - FX_HashCode_String_GetW(wsName.c_str(), wsName.GetLength()); for (int32_t i = 0; i < iCount; i++) { CXFA_Node* ret = Item(i); - if (dwHashCode == ret->GetNameHash()) { + if (dwHashCode == ret->GetNameHash()) return ret; - } } return NULL; } diff --git a/xfa/fxfa/parser/xfa_script_imp.cpp b/xfa/fxfa/parser/xfa_script_imp.cpp index ee95865dc6..0c8aa1a838 100644 --- a/xfa/fxfa/parser/xfa_script_imp.cpp +++ b/xfa/fxfa/parser/xfa_script_imp.cpp @@ -179,8 +179,7 @@ void CXFA_ScriptContext::GlobalPropertyGetter(FXJSE_HOBJECT hObject, XFA_FM2JS_GlobalPropertyGetter(lpScriptContext->m_hFM2JSContext, hValue); return; } - uint32_t uHashCode = - FX_HashCode_String_GetW(wsPropName.c_str(), wsPropName.GetLength()); + uint32_t uHashCode = FX_HashCode_GetW(wsPropName.AsStringC(), false); if (uHashCode != XFA_HASHCODE_Layout) { CXFA_Object* pObject = lpScriptContext->GetDocument()->GetXFAObject(uHashCode); diff --git a/xfa/fxfa/parser/xfa_script_nodehelper.cpp b/xfa/fxfa/parser/xfa_script_nodehelper.cpp index 96ae98aeaf..96ecc5a125 100644 --- a/xfa/fxfa/parser/xfa_script_nodehelper.cpp +++ b/xfa/fxfa/parser/xfa_script_nodehelper.cpp @@ -33,7 +33,7 @@ CXFA_Node* CXFA_NodeHelper::XFA_ResolveNodes_GetOneChild( return NULL; } CXFA_NodeArray siblings; - uint32_t uNameHash = FX_HashCode_String_GetW(pwsName, FXSYS_wcslen(pwsName)); + uint32_t uNameHash = FX_HashCode_GetW(CFX_WideStringC(pwsName), false); XFA_NodeAcc_TraverseAnySiblings(parent, uNameHash, &siblings, bIsClassName); if (siblings.GetSize() == 0) { return NULL; diff --git a/xfa/fxfa/parser/xfa_script_resolveprocessor.cpp b/xfa/fxfa/parser/xfa_script_resolveprocessor.cpp index ecf384b51c..fcd24bf949 100644 --- a/xfa/fxfa/parser/xfa_script_resolveprocessor.cpp +++ b/xfa/fxfa/parser/xfa_script_resolveprocessor.cpp @@ -122,8 +122,8 @@ int32_t CXFA_ResolveProcessor::XFA_ResolveNodes_Dollar( if (rnd.m_nLevel > 0) { return -1; } - uint32_t dwNameHash = - FX_HashCode_String_GetW(wsName.c_str() + 1, iNameLen - 1); + uint32_t dwNameHash = FX_HashCode_GetW( + CFX_WideStringC(wsName.c_str() + 1, iNameLen - 1), false); if (dwNameHash == XFA_HASHCODE_Xfa) { nodes.Add(rnd.m_pSC->GetDocument()->GetRoot()); } else { @@ -151,8 +151,7 @@ int32_t CXFA_ResolveProcessor::XFA_ResolveNodes_Excalmatory( rndFind.m_pSC = rnd.m_pSC; rndFind.m_CurNode = datasets; rndFind.m_wsName = rnd.m_wsName.Right(rnd.m_wsName.GetLength() - 1); - rndFind.m_uHashName = FX_HashCode_String_GetW(rndFind.m_wsName.c_str(), - rndFind.m_wsName.GetLength()); + rndFind.m_uHashName = FX_HashCode_GetW(rndFind.m_wsName.AsStringC(), false); rndFind.m_nLevel = rnd.m_nLevel + 1; rndFind.m_dwStyles = XFA_RESOLVENODE_Children; rndFind.m_wsCondition = rnd.m_wsCondition; @@ -178,8 +177,7 @@ int32_t CXFA_ResolveProcessor::XFA_ResolveNodes_NumberSign( rndFind.m_dwStyles |= XFA_RESOLVENODE_TagName; rndFind.m_dwStyles &= ~XFA_RESOLVENODE_Attributes; rndFind.m_wsName = wsName; - rndFind.m_uHashName = FX_HashCode_String_GetW(rndFind.m_wsName.c_str(), - rndFind.m_wsName.GetLength()); + rndFind.m_uHashName = FX_HashCode_GetW(rndFind.m_wsName.AsStringC(), false); rndFind.m_wsCondition = wsCondition; rndFind.m_CurNode = curNode; XFA_ResolveNodes_Normal(rndFind); @@ -617,7 +615,7 @@ int32_t CXFA_ResolveProcessor::XFA_ResolveNodes_GetFilter( wsCondition.ReleaseBuffer(nConditionCount); wsCondition.TrimLeft(); wsCondition.TrimRight(); - rnd.m_uHashName = FX_HashCode_String_GetW(wsName.c_str(), wsName.GetLength()); + rnd.m_uHashName = FX_HashCode_GetW(wsName.AsStringC(), false); return nStart; } void CXFA_ResolveProcessor::XFA_ResolveNode_ConditionArray( diff --git a/xfa/fxfa/parser/xfa_utils_imp.cpp b/xfa/fxfa/parser/xfa_utils_imp.cpp index 4fec7c071b..77cac00b89 100644 --- a/xfa/fxfa/parser/xfa_utils_imp.cpp +++ b/xfa/fxfa/parser/xfa_utils_imp.cpp @@ -196,8 +196,7 @@ void XFA_GetPlainTextFromRichText(CFDE_XMLNode* pXMLNode, CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); CFX_WideString wsTag; pXMLElement->GetLocalTagName(wsTag); - uint32_t uTag = - FX_HashCode_String_GetW(wsTag.c_str(), wsTag.GetLength(), TRUE); + uint32_t uTag = FX_HashCode_GetW(wsTag.AsStringC(), true); if (uTag == 0x0001f714) { wsPlainText += L"\n"; } else if (uTag == 0x00000070) { |