Move CJS_PublicMethods::ParseString{String,Interger} to fx_date_helpers.cpp

Change-Id: Iee697ca22557b4eb71533930f0b5c5797e73a041
Reviewed-on: https://pdfium-review.googlesource.com/c/45031
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp
index b7790be..e26af63 100644
--- a/fxjs/cjs_publicmethods.cpp
+++ b/fxjs/cjs_publicmethods.cpp
@@ -372,46 +372,6 @@
   return StrArray;
 }
 
-int CJS_PublicMethods::ParseStringInteger(const WideString& str,
-                                          size_t nStart,
-                                          size_t* pSkip,
-                                          size_t nMaxStep) {
-  int nRet = 0;
-  size_t nSkip = 0;
-  for (size_t i = nStart; i < str.GetLength(); ++i) {
-    if (i - nStart > 10)
-      break;
-
-    wchar_t c = str[i];
-    if (!std::iswdigit(c))
-      break;
-
-    nRet = nRet * 10 + FXSYS_DecimalCharToInt(c);
-    ++nSkip;
-    if (nSkip >= nMaxStep)
-      break;
-  }
-
-  *pSkip = nSkip;
-  return nRet;
-}
-
-WideString CJS_PublicMethods::ParseStringString(const WideString& str,
-                                                size_t nStart,
-                                                size_t* pSkip) {
-  WideString swRet;
-  swRet.Reserve(str.GetLength());
-  for (size_t i = nStart; i < str.GetLength(); ++i) {
-    wchar_t c = str[i];
-    if (!std::iswalnum(c))
-      break;
-
-    swRet += c;
-  }
-
-  *pSkip = swRet.GetLength();
-  return swRet;
-}
 
 double CJS_PublicMethods::ParseDate(const WideString& value,
                                     bool* bWrongFormat) {
@@ -435,7 +395,7 @@
 
     wchar_t c = value[i];
     if (std::iswdigit(c)) {
-      number[nIndex++] = ParseStringInteger(value, i, &nSkip, 4);
+      number[nIndex++] = FX_ParseStringInteger(value, i, &nSkip, 4);
       i += nSkip;
     } else {
       i++;
@@ -548,32 +508,32 @@
               j++;
               break;
             case 'm':
-              nMonth = ParseStringInteger(value, j, &nSkip, 2);
+              nMonth = FX_ParseStringInteger(value, j, &nSkip, 2);
               i++;
               j += nSkip;
               break;
             case 'd':
-              nDay = ParseStringInteger(value, j, &nSkip, 2);
+              nDay = FX_ParseStringInteger(value, j, &nSkip, 2);
               i++;
               j += nSkip;
               break;
             case 'H':
-              nHour = ParseStringInteger(value, j, &nSkip, 2);
+              nHour = FX_ParseStringInteger(value, j, &nSkip, 2);
               i++;
               j += nSkip;
               break;
             case 'h':
-              nHour = ParseStringInteger(value, j, &nSkip, 2);
+              nHour = FX_ParseStringInteger(value, j, &nSkip, 2);
               i++;
               j += nSkip;
               break;
             case 'M':
-              nMin = ParseStringInteger(value, j, &nSkip, 2);
+              nMin = FX_ParseStringInteger(value, j, &nSkip, 2);
               i++;
               j += nSkip;
               break;
             case 's':
-              nSec = ParseStringInteger(value, j, &nSkip, 2);
+              nSec = FX_ParseStringInteger(value, j, &nSkip, 2);
               i++;
               j += nSkip;
               break;
@@ -586,37 +546,37 @@
         } else if (remaining == 1 || format[i + 2] != c) {
           switch (c) {
             case 'y':
-              nYear = ParseStringInteger(value, j, &nSkip, 2);
+              nYear = FX_ParseStringInteger(value, j, &nSkip, 2);
               i += 2;
               j += nSkip;
               break;
             case 'm':
-              nMonth = ParseStringInteger(value, j, &nSkip, 2);
+              nMonth = FX_ParseStringInteger(value, j, &nSkip, 2);
               i += 2;
               j += nSkip;
               break;
             case 'd':
-              nDay = ParseStringInteger(value, j, &nSkip, 2);
+              nDay = FX_ParseStringInteger(value, j, &nSkip, 2);
               i += 2;
               j += nSkip;
               break;
             case 'H':
-              nHour = ParseStringInteger(value, j, &nSkip, 2);
+              nHour = FX_ParseStringInteger(value, j, &nSkip, 2);
               i += 2;
               j += nSkip;
               break;
             case 'h':
-              nHour = ParseStringInteger(value, j, &nSkip, 2);
+              nHour = FX_ParseStringInteger(value, j, &nSkip, 2);
               i += 2;
               j += nSkip;
               break;
             case 'M':
-              nMin = ParseStringInteger(value, j, &nSkip, 2);
+              nMin = FX_ParseStringInteger(value, j, &nSkip, 2);
               i += 2;
               j += nSkip;
               break;
             case 's':
-              nSec = ParseStringInteger(value, j, &nSkip, 2);
+              nSec = FX_ParseStringInteger(value, j, &nSkip, 2);
               i += 2;
               j += nSkip;
               break;
@@ -630,7 +590,7 @@
         } else if (remaining == 2 || format[i + 3] != c) {
           switch (c) {
             case 'm': {
-              WideString sMonth = ParseStringString(value, j, &nSkip);
+              WideString sMonth = FX_ParseStringString(value, j, &nSkip);
               bool bFind = false;
               for (int m = 0; m < 12; m++) {
                 if (sMonth.CompareNoCase(kMonths[m]) == 0) {
@@ -643,7 +603,7 @@
               }
 
               if (!bFind) {
-                nMonth = ParseStringInteger(value, j, &nSkip, 3);
+                nMonth = FX_ParseStringInteger(value, j, &nSkip, 3);
                 i += 3;
                 j += nSkip;
               }
@@ -658,14 +618,14 @@
         } else if (remaining == 3 || format[i + 4] != c) {
           switch (c) {
             case 'y':
-              nYear = ParseStringInteger(value, j, &nSkip, 4);
+              nYear = FX_ParseStringInteger(value, j, &nSkip, 4);
               j += nSkip;
               i += 4;
               break;
             case 'm': {
               bool bFind = false;
 
-              WideString sMonth = ParseStringString(value, j, &nSkip);
+              WideString sMonth = FX_ParseStringString(value, j, &nSkip);
               sMonth.MakeLower();
 
               for (int m = 0; m < 12; m++) {
@@ -682,7 +642,7 @@
               }
 
               if (!bFind) {
-                nMonth = ParseStringInteger(value, j, &nSkip, 4);
+                nMonth = FX_ParseStringInteger(value, j, &nSkip, 4);
                 i += 4;
                 j += nSkip;
               }
diff --git a/fxjs/cjs_publicmethods.h b/fxjs/cjs_publicmethods.h
index 99720ad..9398de2 100644
--- a/fxjs/cjs_publicmethods.h
+++ b/fxjs/cjs_publicmethods.h
@@ -140,13 +140,6 @@
   static void AFExtractNums_static(
       const v8::FunctionCallbackInfo<v8::Value>& info);
 
-  static int ParseStringInteger(const WideString& str,
-                                size_t nStart,
-                                size_t* pSkip,
-                                size_t nMaxStep);
-  static WideString ParseStringString(const WideString& str,
-                                      size_t nStart,
-                                      size_t* pSkip);
   static bool MaskSatisfied(wchar_t c_Change, wchar_t c_Mask);
   static bool IsReservedMaskChar(wchar_t ch);
   static double AF_Simple(const wchar_t* sFuction,
diff --git a/fxjs/fx_date_helpers.cpp b/fxjs/fx_date_helpers.cpp
index dbcdcf7..403a731 100644
--- a/fxjs/fx_date_helpers.cpp
+++ b/fxjs/fx_date_helpers.cpp
@@ -231,4 +231,45 @@
   return day * 86400000 + time;
 }
 
+int FX_ParseStringInteger(const WideString& str,
+                          size_t nStart,
+                          size_t* pSkip,
+                          size_t nMaxStep) {
+  int nRet = 0;
+  size_t nSkip = 0;
+  for (size_t i = nStart; i < str.GetLength(); ++i) {
+    if (i - nStart > 10)
+      break;
+
+    wchar_t c = str[i];
+    if (!std::iswdigit(c))
+      break;
+
+    nRet = nRet * 10 + FXSYS_DecimalCharToInt(c);
+    ++nSkip;
+    if (nSkip >= nMaxStep)
+      break;
+  }
+
+  *pSkip = nSkip;
+  return nRet;
+}
+
+WideString FX_ParseStringString(const WideString& str,
+                                size_t nStart,
+                                size_t* pSkip) {
+  WideString swRet;
+  swRet.Reserve(str.GetLength());
+  for (size_t i = nStart; i < str.GetLength(); ++i) {
+    wchar_t c = str[i];
+    if (!std::iswalnum(c))
+      break;
+
+    swRet += c;
+  }
+
+  *pSkip = swRet.GetLength();
+  return swRet;
+}
+
 }  // namespace fxjs
diff --git a/fxjs/fx_date_helpers.h b/fxjs/fx_date_helpers.h
index dbcc94a..8c21df0 100644
--- a/fxjs/fx_date_helpers.h
+++ b/fxjs/fx_date_helpers.h
@@ -7,6 +7,10 @@
 #ifndef FXJS_FX_DATE_HELPERS_H_
 #define FXJS_FX_DATE_HELPERS_H_
 
+#include <stddef.h>
+
+#include "core/fxcrt/fx_string.h"
+
 namespace fxjs {
 
 double FX_GetDateTime();
@@ -21,6 +25,15 @@
 double FX_MakeTime(int nHour, int nMin, int nSec, int nMs);
 double FX_MakeDate(double day, double time);
 
+int FX_ParseStringInteger(const WideString& str,
+                          size_t nStart,
+                          size_t* pSkip,
+                          size_t nMaxStep);
+
+WideString FX_ParseStringString(const WideString& str,
+                                size_t nStart,
+                                size_t* pSkip);
+
 }  // namespace fxjs
 
 using fxjs::FX_GetDateTime;
@@ -34,5 +47,7 @@
 using fxjs::FX_MakeDay;
 using fxjs::FX_MakeTime;
 using fxjs::FX_MakeDate;
+using fxjs::FX_ParseStringInteger;
+using fxjs::FX_ParseStringString;
 
 #endif  // FXJS_FX_DATE_HELPERS_H_