diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-10-18 16:46:57 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-10-18 16:46:57 +0000 |
commit | 7281ed762c675717429fc78447055ccdb1171927 (patch) | |
tree | df4981f3a0232d2b62af12be60b07d9d5da61e8d /fxjs | |
parent | 86587e400a1a0e1dceba1bd4641dfb7ab5dd81f1 (diff) | |
download | pdfium-7281ed762c675717429fc78447055ccdb1171927.tar.xz |
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 <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fxjs')
-rw-r--r-- | fxjs/cjs_publicmethods.cpp | 94 |
1 files changed, 38 insertions, 56 deletions
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 <typename T> 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<v8::Local<v8::Value>> 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<v8::Local<v8::Value>> 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<v8::Local<v8::Value>> 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<v8::Local<v8::Value>> newParams; - newParams.push_back(pRuntime->NewString(cFormats[iIndex])); + newParams.push_back(pRuntime->NewString(kTimeFormats[iIndex])); return AFDate_KeystrokeEx(pRuntime, newParams); } |