Move FX_ParseStringString() into an anonymous namespace.
Rename it to ParseStringString(), and fix some nits near its call sites.
Change-Id: Ief0aad014ba0783cdb8ebc16a5d9a64205d8f5e0
Reviewed-on: https://pdfium-review.googlesource.com/c/51190
Reviewed-by: Nicolás Peña Moreno <npm@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fxjs/fx_date_helpers.cpp b/fxjs/fx_date_helpers.cpp
index 451f4a9..9feda50 100644
--- a/fxjs/fx_date_helpers.cpp
+++ b/fxjs/fx_date_helpers.cpp
@@ -164,6 +164,18 @@
}
}
+// TODO(thestig): Consider returning a WideStringView to make this even faster.
+WideString ParseStringString(const WideString& str,
+ size_t nStart,
+ size_t* pSkip) {
+ size_t i = nStart;
+ while (i < str.GetLength() && std::iswalnum(str[i]))
+ ++i;
+
+ *pSkip = i - nStart;
+ return str.Mid(nStart, *pSkip);
+}
+
} // namespace
const wchar_t* const kMonths[12] = {L"Jan", L"Feb", L"Mar", L"Apr",
@@ -288,18 +300,6 @@
return nRet;
}
-// TODO(thestig): Consider returning a WideStringView to make this even faster.
-WideString FX_ParseStringString(const WideString& str,
- size_t nStart,
- size_t* pSkip) {
- size_t i = nStart;
- while (i < str.GetLength() && std::iswalnum(str[i]))
- ++i;
-
- *pSkip = i - nStart;
- return str.Mid(nStart, *pSkip);
-}
-
ConversionStatus FX_ParseDateUsingFormat(const WideString& value,
const WideString& format,
double* result) {
@@ -438,9 +438,9 @@
} else if (remaining == 2 || format[i + 3] != c) {
switch (c) {
case 'm': {
- WideString sMonth = FX_ParseStringString(value, j, &nSkip);
+ WideString sMonth = ParseStringString(value, j, &nSkip);
bool bFind = false;
- for (int m = 0; m < 12; m++) {
+ for (size_t m = 0; m < FX_ArraySize(kMonths); ++m) {
if (sMonth.CompareNoCase(kMonths[m]) == 0) {
nMonth = m + 1;
i += 3;
@@ -473,13 +473,11 @@
case 'm': {
bool bFind = false;
- WideString sMonth = FX_ParseStringString(value, j, &nSkip);
+ WideString sMonth = ParseStringString(value, j, &nSkip);
sMonth.MakeLower();
-
- for (int m = 0; m < 12; m++) {
+ for (size_t m = 0; m < FX_ArraySize(kFullMonths); ++m) {
WideString sFullMonths = WideString(kFullMonths[m]);
sFullMonths.MakeLower();
-
if (sFullMonths.Contains(sMonth.c_str())) {
nMonth = m + 1;
i += 4;
diff --git a/fxjs/fx_date_helpers.h b/fxjs/fx_date_helpers.h
index f92caba..9f23a67 100644
--- a/fxjs/fx_date_helpers.h
+++ b/fxjs/fx_date_helpers.h
@@ -40,10 +40,6 @@
size_t* pSkip,
size_t nMaxStep);
-WideString FX_ParseStringString(const WideString& str,
- size_t nStart,
- size_t* pSkip);
-
ConversionStatus FX_ParseDateUsingFormat(const WideString& value,
const WideString& format,
double* result);
@@ -67,7 +63,6 @@
using fxjs::FX_MakeTime;
using fxjs::FX_MakeDate;
using fxjs::FX_ParseStringInteger;
-using fxjs::FX_ParseStringString;
using fxjs::FX_ParseDateUsingFormat;
#endif // FXJS_FX_DATE_HELPERS_H_