From 7281ed762c675717429fc78447055ccdb1171927 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 18 Oct 2018 16:46:57 +0000 Subject: De-dup some static string tables in cjs_publicmethods.cpp Change-Id: I1002c4075381f8104630036fc7e54df238fe35f5 Reviewed-on: https://pdfium-review.googlesource.com/c/44110 Commit-Queue: Tom Sepez Reviewed-by: Lei Zhang --- fxjs/cjs_publicmethods.cpp | 94 +++++++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 56 deletions(-) (limited to 'fxjs') diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp index a96cf23b0d..5fbee0dbdf 100644 --- a/fxjs/cjs_publicmethods.cpp +++ b/fxjs/cjs_publicmethods.cpp @@ -65,14 +65,32 @@ namespace { constexpr double kDoubleCorrect = 0.000000000000001; #endif -const wchar_t* const kMonths[] = {L"Jan", L"Feb", L"Mar", L"Apr", - L"May", L"Jun", L"Jul", L"Aug", - L"Sep", L"Oct", L"Nov", L"Dec"}; - -const wchar_t* const kFullMonths[] = {L"January", L"February", L"March", - L"April", L"May", L"June", - L"July", L"August", L"September", - L"October", L"November", L"December"}; +constexpr const wchar_t* kMonths[] = {L"Jan", L"Feb", L"Mar", L"Apr", + L"May", L"Jun", L"Jul", L"Aug", + L"Sep", L"Oct", L"Nov", L"Dec"}; + +constexpr const wchar_t* kFullMonths[] = {L"January", L"February", L"March", + L"April", L"May", L"June", + L"July", L"August", L"September", + L"October", L"November", L"December"}; + +constexpr const wchar_t* kDateFormats[] = {L"m/d", + L"m/d/yy", + L"mm/dd/yy", + L"mm/yy", + L"d-mmm", + L"d-mmm-yy", + L"dd-mmm-yy", + L"yy-mm-dd", + L"mmm-yy", + L"mmmm-yy", + L"mmm d, yyyy", + L"mmmm d, yyyy", + L"m/d/yy h:MM tt", + L"m/d/yy HH:MM"}; + +constexpr const wchar_t* kTimeFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", + L"h:MM:ss tt"}; template T StrTrim(const T& str) { @@ -1266,25 +1284,10 @@ CJS_Result CJS_PublicMethods::AFDate_Format( if (params.size() != 1) return CJS_Result::Failure(JSMessage::kParamError); - static constexpr const wchar_t* cFormats[] = {L"m/d", - L"m/d/yy", - L"mm/dd/yy", - L"mm/yy", - L"d-mmm", - L"d-mmm-yy", - L"dd-mmm-yy", - L"yy-mm-dd", - L"mmm-yy", - L"mmmm-yy", - L"mmm d, yyyy", - L"mmmm d, yyyy", - L"m/d/yy h:MM tt", - L"m/d/yy HH:MM"}; - - int iIndex = - WithinBoundsOrZero(pRuntime->ToInt32(params[0]), FX_ArraySize(cFormats)); + int iIndex = WithinBoundsOrZero(pRuntime->ToInt32(params[0]), + FX_ArraySize(kDateFormats)); std::vector> newParams; - newParams.push_back(pRuntime->NewString(cFormats[iIndex])); + newParams.push_back(pRuntime->NewString(kDateFormats[iIndex])); return AFDate_FormatEx(pRuntime, newParams); } @@ -1295,25 +1298,10 @@ CJS_Result CJS_PublicMethods::AFDate_Keystroke( if (params.size() != 1) return CJS_Result::Failure(JSMessage::kParamError); - static constexpr const wchar_t* cFormats[] = {L"m/d", - L"m/d/yy", - L"mm/dd/yy", - L"mm/yy", - L"d-mmm", - L"d-mmm-yy", - L"dd-mmm-yy", - L"yy-mm-dd", - L"mmm-yy", - L"mmmm-yy", - L"mmm d, yyyy", - L"mmmm d, yyyy", - L"m/d/yy h:MM tt", - L"m/d/yy HH:MM"}; - - int iIndex = - WithinBoundsOrZero(pRuntime->ToInt32(params[0]), FX_ArraySize(cFormats)); + int iIndex = WithinBoundsOrZero(pRuntime->ToInt32(params[0]), + FX_ArraySize(kDateFormats)); std::vector> newParams; - newParams.push_back(pRuntime->NewString(cFormats[iIndex])); + newParams.push_back(pRuntime->NewString(kDateFormats[iIndex])); return AFDate_KeystrokeEx(pRuntime, newParams); } @@ -1324,13 +1312,10 @@ CJS_Result CJS_PublicMethods::AFTime_Format( if (params.size() != 1) return CJS_Result::Failure(JSMessage::kParamError); - static constexpr const wchar_t* cFormats[] = {L"HH:MM", L"h:MM tt", - L"HH:MM:ss", L"h:MM:ss tt"}; - - int iIndex = - WithinBoundsOrZero(pRuntime->ToInt32(params[0]), FX_ArraySize(cFormats)); + int iIndex = WithinBoundsOrZero(pRuntime->ToInt32(params[0]), + FX_ArraySize(kTimeFormats)); std::vector> newParams; - newParams.push_back(pRuntime->NewString(cFormats[iIndex])); + newParams.push_back(pRuntime->NewString(kTimeFormats[iIndex])); return AFDate_FormatEx(pRuntime, newParams); } @@ -1340,13 +1325,10 @@ CJS_Result CJS_PublicMethods::AFTime_Keystroke( if (params.size() != 1) return CJS_Result::Failure(JSMessage::kParamError); - static constexpr const wchar_t* cFormats[] = {L"HH:MM", L"h:MM tt", - L"HH:MM:ss", L"h:MM:ss tt"}; - - int iIndex = - WithinBoundsOrZero(pRuntime->ToInt32(params[0]), FX_ArraySize(cFormats)); + int iIndex = WithinBoundsOrZero(pRuntime->ToInt32(params[0]), + FX_ArraySize(kTimeFormats)); std::vector> newParams; - newParams.push_back(pRuntime->NewString(cFormats[iIndex])); + newParams.push_back(pRuntime->NewString(kTimeFormats[iIndex])); return AFDate_KeystrokeEx(pRuntime, newParams); } -- cgit v1.2.3