summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fxcrt/fx_extension.cpp28
-rw-r--r--core/fxcrt/fx_extension_unittest.cpp14
-rw-r--r--core/fxcrt/include/fx_ext.h8
3 files changed, 26 insertions, 24 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);