Prefer string comparisons to hash comparisons.

The code is easier to read, and it avoids all sorts of unrelated
strings being aliased to the hash.

-- add some constexprs
-- convert some g_Names to kNames
-- kill some blank lines

Change-Id: I49c3cc9d6e45d427be343dd76921289ab4edf569
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/83560
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/xfa/fgas/crt/cfgas_stringformatter.cpp b/xfa/fgas/crt/cfgas_stringformatter.cpp
index 2e4296a..3347909 100644
--- a/xfa/fgas/crt/cfgas_stringformatter.cpp
+++ b/xfa/fgas/crt/cfgas_stringformatter.cpp
@@ -44,7 +44,6 @@
 
 #undef SUBC
 #define SUBC(a, b, c) a, c
-
 constexpr LocaleDateTimeSubcategoryWithHash kLocaleDateTimeSubcategoryData[] = {
     {SUBC(0x14da2125, "default", LocaleIface::DateTimeSubcategory::kDefault)},
     {SUBC(0x9041d4b0, "short", LocaleIface::DateTimeSubcategory::kShort)},
@@ -59,7 +58,6 @@
     {SUBC(0x54034c2f, "decimal", LocaleIface::NumSubcategory::kDecimal)},
     {SUBC(0x7568e6ae, "integer", LocaleIface::NumSubcategory::kInteger)},
 };
-
 #undef SUBC
 
 struct FX_LOCALETIMEZONEINFO {
@@ -68,14 +66,22 @@
   int16_t iMinute;
 };
 
-const FX_LOCALETIMEZONEINFO g_FXLocaleTimeZoneData[] = {
+constexpr FX_LOCALETIMEZONEINFO kFXLocaleTimeZoneData[] = {
     {L"CDT", -5, 0}, {L"CST", -6, 0}, {L"EDT", -4, 0}, {L"EST", -5, 0},
     {L"MDT", -6, 0}, {L"MST", -7, 0}, {L"PDT", -7, 0}, {L"PST", -8, 0},
 };
 
-const wchar_t kTimeSymbols[] = L"hHkKMSFAzZ";
-const wchar_t kDateSymbols[] = L"DJMEeGgYwW";
-const wchar_t kConstChars[] = L",-:/. ";
+constexpr wchar_t kTimeSymbols[] = L"hHkKMSFAzZ";
+constexpr wchar_t kDateSymbols[] = L"DJMEeGgYwW";
+constexpr wchar_t kConstChars[] = L",-:/. ";
+
+constexpr wchar_t kDateStr[] = L"date";
+constexpr wchar_t kTimeStr[] = L"time";
+constexpr wchar_t kDateTimeStr[] = L"datetime";
+constexpr wchar_t kNumStr[] = L"num";
+constexpr wchar_t kTextStr[] = L"text";
+constexpr wchar_t kZeroStr[] = L"zero";
+constexpr wchar_t kNullStr[] = L"null";
 
 size_t ParseTimeZone(pdfium::span<const wchar_t> spStr, int* tz) {
   *tz = 0;
@@ -448,8 +454,8 @@
         ResolveZone(tz_diff_minutes, pLocale, &hour, &minute);
       } else {
         // Search the timezone list. There are only 8 of them, so linear scan.
-        for (size_t i = 0; i < pdfium::size(g_FXLocaleTimeZoneData); ++i) {
-          const FX_LOCALETIMEZONEINFO& info = g_FXLocaleTimeZoneData[i];
+        for (size_t i = 0; i < pdfium::size(kFXLocaleTimeZoneData); ++i) {
+          const FX_LOCALETIMEZONEINFO& info = kFXLocaleTimeZoneData[i];
           if (tz != info.name)
             continue;
 
@@ -899,22 +905,21 @@
         wsCategory += m_spPattern[ccf];
         ccf++;
       }
-      uint32_t dwHash = FX_HashCode_GetW(wsCategory.AsStringView());
-      if (dwHash == FX_LOCALECATEGORY_DateTimeHash)
+      if (wsCategory == kDateTimeStr)
         return Category::kDateTime;
-      if (dwHash == FX_LOCALECATEGORY_TextHash)
+      if (wsCategory == kTextStr)
         return Category::kText;
-      if (dwHash == FX_LOCALECATEGORY_NumHash)
+      if (wsCategory == kNumStr)
         return Category::kNum;
-      if (dwHash == FX_LOCALECATEGORY_ZeroHash)
+      if (wsCategory == kZeroStr)
         return Category::kZero;
-      if (dwHash == FX_LOCALECATEGORY_NullHash)
+      if (wsCategory == kNullStr)
         return Category::kNull;
-      if (dwHash == FX_LOCALECATEGORY_DateHash) {
+      if (wsCategory == kDateStr) {
         if (eCategory == Category::kTime)
           return Category::kDateTime;
         eCategory = Category::kDate;
-      } else if (dwHash == FX_LOCALECATEGORY_TimeHash) {
+      } else if (wsCategory == kTimeStr) {
         if (eCategory == Category::kDate)
           return Category::kDateTime;
         eCategory = Category::kTime;
diff --git a/xfa/fgas/crt/cfgas_stringformatter.h b/xfa/fgas/crt/cfgas_stringformatter.h
index afdd5ea..3d0f7cd 100644
--- a/xfa/fgas/crt/cfgas_stringformatter.h
+++ b/xfa/fgas/crt/cfgas_stringformatter.h
@@ -13,14 +13,6 @@
 #include "third_party/base/span.h"
 #include "xfa/fgas/crt/locale_iface.h"
 
-#define FX_LOCALECATEGORY_DateHash 0xbde9abde
-#define FX_LOCALECATEGORY_TimeHash 0x2d71b00f
-#define FX_LOCALECATEGORY_DateTimeHash 0x158c72ed
-#define FX_LOCALECATEGORY_NumHash 0x0b4ff870
-#define FX_LOCALECATEGORY_TextHash 0x2d08af85
-#define FX_LOCALECATEGORY_ZeroHash 0x568cb500
-#define FX_LOCALECATEGORY_NullHash 0x052931bb
-
 class CFX_DateTime;
 class LocaleMgrIface;
 
diff --git a/xfa/fgas/crt/cfgas_stringformatter_unittest.cpp b/xfa/fgas/crt/cfgas_stringformatter_unittest.cpp
index f82b77f..183d967 100644
--- a/xfa/fgas/crt/cfgas_stringformatter_unittest.cpp
+++ b/xfa/fgas/crt/cfgas_stringformatter_unittest.cpp
@@ -743,20 +743,3 @@
   EXPECT_EQ(CFGAS_StringFormatter::Category::kDate,
             CFGAS_StringFormatter(L"date.long{}").GetCategory());
 }
-
-TEST_F(CFGAS_StringFormatterTest, HashConstants) {
-  EXPECT_EQ(static_cast<uint32_t>(FX_LOCALECATEGORY_DateHash),
-            FX_HashCode_GetW(L"date"));
-  EXPECT_EQ(static_cast<uint32_t>(FX_LOCALECATEGORY_TimeHash),
-            FX_HashCode_GetW(L"time"));
-  EXPECT_EQ(static_cast<uint32_t>(FX_LOCALECATEGORY_DateTimeHash),
-            FX_HashCode_GetW(L"datetime"));
-  EXPECT_EQ(static_cast<uint32_t>(FX_LOCALECATEGORY_NumHash),
-            FX_HashCode_GetW(L"num"));
-  EXPECT_EQ(static_cast<uint32_t>(FX_LOCALECATEGORY_TextHash),
-            FX_HashCode_GetW(L"text"));
-  EXPECT_EQ(static_cast<uint32_t>(FX_LOCALECATEGORY_ZeroHash),
-            FX_HashCode_GetW(L"zero"));
-  EXPECT_EQ(static_cast<uint32_t>(FX_LOCALECATEGORY_NullHash),
-            FX_HashCode_GetW(L"null"));
-}