Add FXSYS_IsLowerASCII().

Add FXSYS_IsLowerASCII() to check whether a character is a lowercase
ASCII character.

This CL also adds callers for FXSYS_IsLowerASCII() to replace all
lowercase ASCII character checks across PDFium.

Change-Id: Id131f6c95c5221a69cd9225d421bd58f8e23d02b
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/67210
Commit-Queue: Hui Yingst <nigi@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/fx_extension.h b/core/fxcrt/fx_extension.h
index fba9544..69dedce 100644
--- a/core/fxcrt/fx_extension.h
+++ b/core/fxcrt/fx_extension.h
@@ -48,12 +48,16 @@
   return u_toupper(c);
 }
 
+inline bool FXSYS_IsLowerASCII(int32_t c) {
+  return c >= 'a' && c <= 'z';
+}
+
 inline bool FXSYS_IsUpperASCII(int32_t c) {
   return c >= 'A' && c <= 'Z';
 }
 
 inline char FXSYS_ToUpperASCII(char c) {
-  return (c >= 'a' && c <= 'z') ? (c + ('A' - 'a')) : c;
+  return FXSYS_IsLowerASCII(c) ? (c + ('A' - 'a')) : c;
 }
 
 inline bool FXSYS_iswalpha(wchar_t c) {
diff --git a/core/fxcrt/fx_extension_unittest.cpp b/core/fxcrt/fx_extension_unittest.cpp
index 125612b..2d265c7 100644
--- a/core/fxcrt/fx_extension_unittest.cpp
+++ b/core/fxcrt/fx_extension_unittest.cpp
@@ -8,6 +8,27 @@
 
 #include "testing/gtest/include/gtest/gtest.h"
 
+TEST(fxcrt, FXSYS_IsLowerASCII) {
+  EXPECT_TRUE(FXSYS_IsLowerASCII('a'));
+  EXPECT_TRUE(FXSYS_IsLowerASCII(L'a'));
+  EXPECT_TRUE(FXSYS_IsLowerASCII('b'));
+  EXPECT_TRUE(FXSYS_IsLowerASCII(L'b'));
+  EXPECT_TRUE(FXSYS_IsLowerASCII('y'));
+  EXPECT_TRUE(FXSYS_IsLowerASCII(L'y'));
+  EXPECT_TRUE(FXSYS_IsLowerASCII('z'));
+  EXPECT_TRUE(FXSYS_IsLowerASCII(L'z'));
+  EXPECT_FALSE(FXSYS_IsLowerASCII('`'));
+  EXPECT_FALSE(FXSYS_IsLowerASCII(L'`'));
+  EXPECT_FALSE(FXSYS_IsLowerASCII('{'));
+  EXPECT_FALSE(FXSYS_IsLowerASCII(L'{'));
+  EXPECT_FALSE(FXSYS_IsLowerASCII('Z'));
+  EXPECT_FALSE(FXSYS_IsLowerASCII(L'Z'));
+  EXPECT_FALSE(FXSYS_IsLowerASCII('7'));
+  EXPECT_FALSE(FXSYS_IsLowerASCII(L'7'));
+  EXPECT_FALSE(FXSYS_IsLowerASCII(static_cast<char>(-78)));
+  EXPECT_FALSE(FXSYS_IsLowerASCII(static_cast<wchar_t>(0xb2)));
+}
+
 TEST(fxcrt, FXSYS_IsUpperASCII) {
   EXPECT_TRUE(FXSYS_IsUpperASCII('A'));
   EXPECT_TRUE(FXSYS_IsUpperASCII(L'A'));
diff --git a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp
index b833ac0..9e389f8 100644
--- a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp
+++ b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp
@@ -95,7 +95,7 @@
 }
 
 bool IsNativeText(wchar_t ch) {
-  return (ch == ' ') || (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z');
+  return (ch == ' ') || (ch >= '0' && ch <= '9') || FXSYS_IsLowerASCII(ch);
 }
 
 bool IsX12TermSep(wchar_t ch) {
diff --git a/fxbarcode/datamatrix/BC_TextEncoder.cpp b/fxbarcode/datamatrix/BC_TextEncoder.cpp
index 10ee1d0..5ed444a 100644
--- a/fxbarcode/datamatrix/BC_TextEncoder.cpp
+++ b/fxbarcode/datamatrix/BC_TextEncoder.cpp
@@ -47,7 +47,7 @@
     *sb += (wchar_t)(c - 48 + 4);
     return 1;
   }
-  if (c >= 'a' && c <= 'z') {
+  if (FXSYS_IsLowerASCII(c)) {
     *sb += (wchar_t)(c - 97 + 14);
     return 1;
   }
diff --git a/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp b/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp
index 29e559a..0570338 100644
--- a/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp
+++ b/fxbarcode/pdf417/BC_PDF417HighLevelEncoder.cpp
@@ -56,7 +56,7 @@
 }
 
 bool IsAlphaLowerOrSpace(wchar_t ch) {
-  return ch == ' ' || (ch >= 'a' && ch <= 'z');
+  return ch == ' ' || FXSYS_IsLowerASCII(ch);
 }
 
 bool IsMixed(wchar_t ch) {