diff options
-rw-r--r-- | fxjs/cfxjse_formcalc_context.cpp | 68 |
1 files changed, 35 insertions, 33 deletions
diff --git a/fxjs/cfxjse_formcalc_context.cpp b/fxjs/cfxjse_formcalc_context.cpp index d8f7aff09f..5a2d581441 100644 --- a/fxjs/cfxjse_formcalc_context.cpp +++ b/fxjs/cfxjse_formcalc_context.cpp @@ -330,21 +330,22 @@ const uint8_t kAltTableTime[] = { static_assert(FX_ArraySize(kAltTableTime) == L'a' - L'A' + 1, "Invalid kAltTableTime size."); -void AlternateDateTimeSymbols(WideString& wsPattern, +void AlternateDateTimeSymbols(WideString* pPattern, const WideString& wsAltSymbols, - const uint8_t* pAltTable) { - int32_t nLength = wsPattern.GetLength(); + bool bIsDate) { + const uint8_t* pAltTable = bIsDate ? kAltTableDate : kAltTableTime; + int32_t nLength = pPattern->GetLength(); bool bInConstRange = false; bool bEscape = false; int32_t i = 0; while (i < nLength) { - wchar_t wc = wsPattern[i]; + wchar_t wc = (*pPattern)[i]; if (wc == L'\'') { bInConstRange = !bInConstRange; if (bEscape) { i++; } else { - wsPattern.Delete(i); + pPattern->Delete(i); nLength--; } bEscape = !bEscape; @@ -353,7 +354,7 @@ void AlternateDateTimeSymbols(WideString& wsPattern, if (!bInConstRange && wc >= L'A' && wc <= L'a') { uint8_t nAlt = pAltTable[wc - L'A']; if (nAlt != 255) - wsPattern.SetAt(i, wsAltSymbols[nAlt]); + pPattern->SetAt(i, wsAltSymbols[nAlt]); } i++; bEscape = false; @@ -456,11 +457,6 @@ CFXJSE_FormCalcContext* ToFormCalcContext(CFXJSE_Value* pValue) { return pHostObj ? pHostObj->AsFormCalcContext() : nullptr; } -bool IsWhitespace(char c) { - return c == 0x20 || c == 0x09 || c == 0x0B || c == 0x0C || c == 0x0A || - c == 0x0D; -} - LocaleIface* LocaleFromString(CXFA_Document* pDoc, CXFA_LocaleMgr* pMgr, const ByteStringView& szLocale) { @@ -495,6 +491,30 @@ FX_LOCALEDATETIMESUBCATEGORY SubCategoryFromInt(int32_t iStyle) { } } +ByteString GetLocalDateTimeFormat( + CXFA_Document* pDoc, + int32_t iStyle, + const ByteStringView& szLocale, + bool bStandard, + bool bIsDate) { + CXFA_LocaleMgr* pMgr = pDoc->GetLocaleMgr(); + LocaleIface* pLocale = LocaleFromString(pDoc, pMgr, szLocale); + if (!pLocale) + return ByteString(); + + FX_LOCALEDATETIMESUBCATEGORY category = SubCategoryFromInt(iStyle); + WideString strRet = bIsDate ? pLocale->GetDatePattern(category) + : pLocale->GetTimePattern(category); + if (!bStandard) + AlternateDateTimeSymbols(&strRet, pLocale->GetDateTimeSymbols(), bIsDate); + return strRet.UTF8Encode(); +} + +bool IsWhitespace(char c) { + return c == 0x20 || c == 0x09 || c == 0x0B || c == 0x0C || c == 0x0A || + c == 0x0D; +} + bool IsPartOfNumber(char ch) { return std::isdigit(ch) || ch == '-' || ch == '.'; } @@ -2127,17 +2147,8 @@ ByteString CFXJSE_FormCalcContext::GetLocalDateFormat( if (!pDoc) return ByteString(); - CXFA_LocaleMgr* pMgr = pDoc->GetLocaleMgr(); - LocaleIface* pLocale = LocaleFromString(pDoc, pMgr, szLocale); - if (!pLocale) - return ByteString(); - - WideString strRet = pLocale->GetDatePattern(SubCategoryFromInt(iStyle)); - if (!bStandard) { - AlternateDateTimeSymbols(strRet, pLocale->GetDateTimeSymbols(), - kAltTableDate); - } - return strRet.UTF8Encode(); + return GetLocalDateTimeFormat(pDoc, iStyle, szLocale, bStandard, + /*bIsDate=*/true); } // static @@ -2150,17 +2161,8 @@ ByteString CFXJSE_FormCalcContext::GetLocalTimeFormat( if (!pDoc) return ByteString(); - CXFA_LocaleMgr* pMgr = pDoc->GetLocaleMgr(); - LocaleIface* pLocale = LocaleFromString(pDoc, pMgr, szLocale); - if (!pLocale) - return ByteString(); - - WideString strRet = pLocale->GetTimePattern(SubCategoryFromInt(iStyle)); - if (!bStandard) { - AlternateDateTimeSymbols(strRet, pLocale->GetDateTimeSymbols(), - kAltTableTime); - } - return strRet.UTF8Encode(); + return GetLocalDateTimeFormat(pDoc, iStyle, szLocale, bStandard, + /*bIsDate=*/false); } // static |