summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorCaolán McNamara <caolan.mcnamara@collabora.com>2024-03-21 17:25:35 +0000
committerCaolán McNamara <caolan.mcnamara@collabora.com>2024-03-22 21:50:59 +0100
commitc6c6126aa3e8de256091b829b98b5943db6a8be6 (patch)
tree92f6d9235eaa8fb25e477fe2667396a56a285174 /include
parentc900850742efd4e1fb7c79c13c1b9a17fcd4981d (diff)
Related: tdf#160056 refactor SvNumberFormatter
to split it into two constituent parts SvNFFormatData which is the data store for number formats it generally operates on. SvNFLanguageData for data around the current language in use. and then a SvNFEngine which implements the interaction between those parts SvNFEngine has two policies, the typical RW mode and a new RO mode where the SvNFFormatData doesn't change, all formats needed in this mode must already exist. Change-Id: I56b070ccd2e556a0cb1fe609a2fae28e18277c8c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165146 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Diffstat (limited to 'include')
-rw-r--r--include/svl/nfengine.hxx432
-rw-r--r--include/svl/numformat.hxx151
-rw-r--r--include/svl/zformat.hxx81
3 files changed, 506 insertions, 158 deletions
diff --git a/include/svl/nfengine.hxx b/include/svl/nfengine.hxx
new file mode 100644
index 000000000000..aa57d731fbac
--- /dev/null
+++ b/include/svl/nfengine.hxx
@@ -0,0 +1,432 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#pragma once
+
+#include <svl/svldllapi.h>
+#include <com/sun/star/i18n/XNumberFormatCode.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
+#include <i18nlangtag/lang.h>
+#include <tools/link.hxx>
+#include <svl/nfkeytab.hxx>
+#include <svl/ondemand.hxx>
+#include <svl/zforlist.hxx>
+#include <unotools/charclass.hxx>
+
+#include <functional>
+#include <map>
+
+class Color;
+class ImpSvNumberformatScan;
+class ImpSvNumberInputScan;
+class SvNumberFormatterRegistry_Impl;
+class SvNumberFormatter;
+class NfCurrencyTable;
+
+class SVL_DLLPUBLIC SvNFLanguageData
+{
+public:
+ SvNFLanguageData(const css::uno::Reference<css::uno::XComponentContext>& rxContext,
+ LanguageType eLang, const SvNumberFormatter& rColorCallback);
+ SvNFLanguageData(const SvNFLanguageData& rOther);
+ ~SvNFLanguageData();
+
+ const css::uno::Reference<css::uno::XComponentContext>& GetComponentContext() const
+ {
+ return xContext;
+ }
+
+ // return the corresponding LocaleData wrapper
+ const LocaleDataWrapper* GetLocaleData() const;
+
+ // return the corresponding CharacterClassification wrapper
+ const CharClass* GetCharClass() const;
+
+ // return the corresponding Calendar wrapper
+ CalendarWrapper* GetCalendar() const;
+
+ // return corresponding Transliteration wrapper
+ const ::utl::TransliterationWrapper* GetTransliteration() const;
+
+ //! The following method is not to be used from outside but must be
+ //! public for the InputScanner.
+ // return the current FormatScanner
+ const ImpSvNumberformatScan* GetFormatScanner() const;
+
+ // return current (!) Locale
+ const LanguageTag& GetLanguageTag() const;
+
+ /// Get compatibility ("automatic" old style) currency from I18N locale data
+ void GetCompatibilityCurrency(OUString& rSymbol, OUString& rAbbrev) const;
+
+ // cached locale data items
+
+ // return the corresponding decimal separator
+ const OUString& GetNumDecimalSep() const;
+
+ // return the corresponding decimal separator alternative
+ const OUString& GetNumDecimalSepAlt() const;
+
+ // return the corresponding group (AKA thousand) separator
+ const OUString& GetNumThousandSep() const;
+
+ // return the corresponding date separator
+ const OUString& GetDateSep() const;
+
+ // checks for decimal separator and optional alternative
+ bool IsDecimalSep(std::u16string_view rStr) const;
+
+ /// Return the decimal separator matching the given locale / LanguageType.
+ OUString GetLangDecimalSep(LanguageType nLang) const;
+
+ /// Change language/country, also input and format scanner
+ void ChangeIntl(LanguageType eLnge);
+
+ /** Set evaluation type and order of input date strings
+ @see NfEvalDateFormat
+ */
+ void SetEvalDateFormat(NfEvalDateFormat eEDF) { eEvalDateFormat = eEDF; }
+ NfEvalDateFormat GetEvalDateFormat() const { return eEvalDateFormat; }
+
+ struct InputScannerPrivateAccess
+ {
+ friend class ImpSvNumberInputScan;
+
+ private:
+ InputScannerPrivateAccess() {}
+ };
+ /** Access for input scanner to temporarily (!) switch locales. */
+ OnDemandLocaleDataWrapper& GetOnDemandLocaleDataWrapper(const InputScannerPrivateAccess&)
+ {
+ return xLocaleData;
+ }
+
+ /** The language with which the formatter was initialized (system setting),
+ NOT the current language after a ChangeIntl() */
+ LanguageType GetIniLanguage() const { return IniLnge; }
+
+ LanguageType ImpResolveLanguage(LanguageType eLnge) const;
+
+ /// Return the reference date
+ const Date& GetNullDate() const;
+
+ sal_uInt16 GetCurrencyFormatStrings(NfWSStringsDtor&, const NfCurrencyEntry&, bool bBank) const;
+
+ void ChangeStandardPrec(short nPrec);
+
+ sal_uInt16 ExpandTwoDigitYear(sal_uInt16 nYear) const;
+
+private:
+ friend class SvNFEngine;
+ friend class SvNFFormatData;
+ friend class SvNumberFormatter;
+
+ css::uno::Reference<css::uno::XComponentContext> xContext;
+
+ const LanguageType IniLnge; // Initial language/country setting
+ LanguageType ActLnge; // Current language/country setting
+ LanguageTag aLanguageTag;
+ OnDemandCharClass xCharClass; // CharacterClassification
+ OnDemandLocaleDataWrapper xLocaleData; // LocaleData switched between SYSTEM, ENGLISH and other
+ OnDemandTransliterationWrapper xTransliteration; // Transliteration loaded on demand
+ OnDemandCalendarWrapper xCalendar; // Calendar loaded on demand
+ std::unique_ptr<ImpSvNumberInputScan> pStringScanner; // Input string scanner
+ std::unique_ptr<ImpSvNumberformatScan> pFormatScanner; // Format code string scanner
+
+ // cached locale data items needed almost every time
+ OUString aDecimalSep;
+ OUString aDecimalSepAlt;
+ OUString aThousandSep;
+ OUString aDateSep;
+
+ NfEvalDateFormat eEvalDateFormat; // DateFormat evaluation
+};
+
+class SVL_DLLPUBLIC SvNFFormatData
+{
+private:
+ typedef std::map<sal_uInt32, std::unique_ptr<SvNumberformat>> FormatEntryMap;
+ FormatEntryMap aFTable; // Table of format keys to format entries
+ typedef std::map<sal_uInt32, sal_uInt32> DefaultFormatKeysMap;
+ DefaultFormatKeysMap aDefaultFormatKeys; // Table of default standard to format keys
+ sal_uInt32 MaxCLOffset; // Max language/country offset used
+ sal_uInt32 nDefaultSystemCurrencyFormat; // NewCurrency matching SYSTEM locale
+ bool bNoZero; // Zero value suppression
+
+public:
+ SvNFFormatData();
+ ~SvNFFormatData();
+
+public:
+ const SvNumberformat* GetFormatEntry(sal_uInt32 nKey) const;
+
+ SvNumFormatType GetType(sal_uInt32 nFIndex) const;
+
+ /// Whether format index nFIndex is of type text or not
+ bool IsTextFormat(sal_uInt32 nFIndex) const;
+
+ OUString GetCalcCellReturn(sal_uInt32 nFormat) const;
+
+ /** Whether nFormat is of type css::util::NumberFormat::CURRENCY and the format code
+ contains a new SYMBOLTYPE_CURRENCY and if so which one [$xxx-nnn].
+ If ppEntry is not NULL and exactly one entry is found, a [$xxx-nnn] is
+ returned, even if the format code only contains [$xxx] !
+ */
+ bool GetNewCurrencySymbolString(sal_uInt32 nFormat, OUString& rSymbol,
+ const NfCurrencyEntry** ppEntry, bool* pBank = nullptr) const;
+
+private:
+ SvNFFormatData(const SvNFFormatData&) = delete;
+ SvNFFormatData& operator=(const SvNFFormatData&) = delete;
+
+ friend class SvNFEngine;
+ friend class SvNumberFormatter;
+
+ SVL_DLLPRIVATE sal_uInt32 GetStandardFormat(SvNFLanguageData& rCurrentLanguage,
+ const NativeNumberWrapper* pNatNum,
+ SvNumFormatType eType, LanguageType eLnge);
+
+ // Obtain the format entry for a given key index.
+ SVL_DLLPRIVATE SvNumberformat* GetFormatEntry(sal_uInt32 nKey);
+
+ SVL_DLLPRIVATE SvNumberformat* GetEntry(sal_uInt32 nKey) const;
+
+ /// Return whether zero suppression is switched on
+ SVL_DLLPRIVATE bool GetNoZero() const { return bNoZero; }
+ SVL_DLLPRIVATE void SetNoZero(bool bNZ) { bNoZero = bNZ; }
+
+ SVL_DLLPRIVATE sal_uInt32 ImpIsEntry(std::u16string_view rString, sal_uInt32 nCLOffset,
+ LanguageType eLnge) const;
+
+ // Return CLOffset or (MaxCLOffset + SV_COUNTRY_LANGUAGE_OFFSET) if new language/country
+ SVL_DLLPRIVATE sal_uInt32 ImpGetCLOffset(LanguageType eLnge) const;
+
+ // Generate builtin formats provided by i18n behind CLOffset,
+ // if bNoAdditionalFormats==false also generate additional i18n formats.
+ SVL_DLLPRIVATE void ImpGenerateFormats(SvNFLanguageData& rCurrentLanguage,
+ const NativeNumberWrapper* pNatNum, sal_uInt32 CLOffset,
+ bool bNoAdditionalFormats);
+
+ // Create builtin formats for language/country if necessary, return CLOffset
+ SVL_DLLPRIVATE sal_uInt32 ImpGenerateCL(SvNFLanguageData& rCurrentLanguage,
+ const NativeNumberWrapper* pNatNum, LanguageType eLnge);
+
+ // Generate additional formats provided by i18n
+ SVL_DLLPRIVATE void ImpGenerateAdditionalFormats(
+ SvNFLanguageData& rCurrentLanguage, const NativeNumberWrapper* pNatNum, sal_uInt32 CLOffset,
+ css::uno::Reference<css::i18n::XNumberFormatCode> const& rNumberFormatCode,
+ bool bAfterChangingSystemCL);
+
+ // called by SvNumberFormatterRegistry_Impl::Notify if the default system currency changes
+ SVL_DLLPRIVATE void ResetDefaultSystemCurrency();
+
+ SVL_DLLPRIVATE bool PutEntry(SvNFLanguageData& rCurrentLanguage,
+ const NativeNumberWrapper* pNatNum, OUString& rString,
+ sal_Int32& nCheckPos, SvNumFormatType& nType, sal_uInt32& nKey,
+ LanguageType eLnge = LANGUAGE_DONTKNOW,
+ bool bReplaceBooleanEquivalent = true);
+
+ SVL_DLLPRIVATE SvNumberformat*
+ ImpInsertFormat(SvNFLanguageData& rCurrentLanguage, const NativeNumberWrapper* pNatNum,
+ const css::i18n::NumberFormatCode& rCode, sal_uInt32 nPos,
+ bool bAfterChangingSystemCL = false, sal_Int16 nOrgIndex = 0);
+
+ SVL_DLLPRIVATE sal_uInt32 ImpGetStandardFormat(SvNFLanguageData& rCurrentLanguage,
+ const NativeNumberWrapper* pNatNum,
+ SvNumFormatType eType, sal_uInt32 CLOffset,
+ LanguageType eLnge);
+
+ // Return the format index of the currency format of the current locale.
+ // Format is created if not already present.
+ SVL_DLLPRIVATE sal_uInt32 ImpGetDefaultCurrencyFormat(SvNFLanguageData& rCurrentLanguage,
+ const NativeNumberWrapper* pNatNum,
+ sal_uInt32 CLOffset, LanguageType eLnge);
+
+ // Return the format index of the currency format of the system locale.
+ // Format is created if not already present.
+ SVL_DLLPRIVATE sal_uInt32 ImpGetDefaultSystemCurrencyFormat(SvNFLanguageData& rCurrentLanguage,
+ const NativeNumberWrapper* pNatNum);
+
+ SVL_DLLPRIVATE std::pair<sal_uInt32, bool>
+ ImpGetDefaultFormat(SvNumFormatType nType, sal_uInt32 nSearch, sal_uInt32 CLOffset) const;
+
+ SVL_DLLPRIVATE static sal_Int32
+ ImpGetFormatCodeIndex(const SvNFLanguageData& rCurrentLanguage,
+ css::uno::Sequence<css::i18n::NumberFormatCode>& rSeq,
+ const NfIndexTableOffset nTabOff);
+
+ SVL_DLLPRIVATE static void ImpAdjustFormatCodeDefault(const SvNFLanguageData& rCurrentLanguage,
+ css::i18n::NumberFormatCode* pFormatArr,
+ sal_Int32 nCnt);
+};
+
+class SVL_DLLPUBLIC SvNFEngine
+{
+public:
+ typedef std::function<sal_uInt32(SvNFLanguageData& rCurrentLanguage,
+ const NativeNumberWrapper* pNatNum, LanguageType eLnge)>
+ GetCLOffset;
+ typedef std::function<void(sal_uInt32 nSearch, sal_uInt32 nFormat)> CacheFormat;
+
+ typedef std::function<sal_uInt32(SvNFLanguageData& rCurrentLanguage,
+ const NativeNumberWrapper* pNatNum, sal_uInt32 CLOffset,
+ LanguageType eLnge)>
+ GetDefaultCurrency;
+
+ struct Accessor
+ {
+ GetCLOffset mGetCLOffset;
+ CacheFormat mCacheFormat;
+ GetDefaultCurrency mGetDefaultCurrency;
+ };
+
+ static Accessor GetRWPolicy(SvNFFormatData& rFormatData);
+ static Accessor GetROPolicy(const SvNFFormatData& rFormatData);
+
+ static void ChangeIntl(SvNFLanguageData& rCurrentLanguage, LanguageType eLnge);
+ static void ChangeNullDate(SvNFLanguageData& rCurrentLanguage, sal_uInt16 nDay,
+ sal_uInt16 nMonth, sal_Int16 nYear);
+
+ static sal_uInt32 GetFormatIndex(SvNFLanguageData& rCurrentLanguage, const Accessor& rFuncs,
+ const NativeNumberWrapper* pNatNum, NfIndexTableOffset nTabOff,
+ LanguageType eLnge);
+
+ static sal_uInt32 GetFormatForLanguageIfBuiltIn(SvNFLanguageData& rCurrentLanguage,
+ const NativeNumberWrapper* pNatNum,
+ const Accessor& rFunc, sal_uInt32 nFormat,
+ LanguageType eLnge);
+
+ static bool IsNumberFormat(SvNFLanguageData& rCurrentLanguage,
+ const SvNFFormatData& rFormatData,
+ const NativeNumberWrapper* pNatNum, const Accessor& rFunc,
+ const OUString& sString, sal_uInt32& F_Index, double& fOutNumber,
+ SvNumInputOptions eInputOptions = SvNumInputOptions::NONE);
+
+ static sal_uInt32 GetStandardFormat(SvNFLanguageData& rCurrentLanguage,
+ const SvNFFormatData& rFormatData,
+ const NativeNumberWrapper* pNatNum, const Accessor& rFunc,
+ SvNumFormatType eType, LanguageType eLnge);
+
+ static sal_uInt32 GetStandardFormat(SvNFLanguageData& rCurrentLanguage,
+ const SvNFFormatData& rFormatData,
+ const NativeNumberWrapper* pNatNum, const Accessor& rFuncs,
+ sal_uInt32 nFIndex, SvNumFormatType eType,
+ LanguageType eLnge);
+
+ static sal_uInt32 GetStandardFormat(SvNFLanguageData& rCurrentLanguage,
+ const SvNFFormatData& rFormatData,
+ const NativeNumberWrapper* pNatNum, const Accessor& rFuncs,
+ double fNumber, sal_uInt32 nFIndex, SvNumFormatType eType,
+ LanguageType eLnge);
+
+ static sal_uInt32 GetStandardIndex(SvNFLanguageData& rCurrentLanguage,
+ const SvNFFormatData& rFormatData,
+ const NativeNumberWrapper* pNatNum, const Accessor& rFuncs,
+ LanguageType eLnge = LANGUAGE_DONTKNOW);
+
+ static sal_uInt32 GetTimeFormat(SvNFLanguageData& rCurrentLanguage,
+ const SvNFFormatData& rFormatData,
+ const NativeNumberWrapper* pNatNum, const Accessor& rFuncs,
+ double fNumber, LanguageType eLnge, bool bForceDuration);
+
+ /// Return the decimal separator matching the locale of the given format
+ static OUString GetFormatDecimalSep(SvNFLanguageData& rCurrentLanguage,
+ const SvNFFormatData& rFormatData, sal_uInt32 nFormat);
+
+ /// Count of decimals
+ static sal_uInt16 GetFormatPrecision(SvNFLanguageData& rCurrentLanguage,
+ const SvNFFormatData& rFormatData, sal_uInt32 nFormat);
+
+ static void GetInputLineString(SvNFLanguageData& rCurrentLanguage,
+ const SvNFFormatData& rFormatData,
+ const NativeNumberWrapper* pNatNum, const Accessor& rFuncs,
+ const double& fOutNumber, sal_uInt32 nFIndex,
+ OUString& sOutString, bool bFiltering, bool bForceSystemLocale);
+
+ static sal_uInt32 GetEditFormat(SvNFLanguageData& rCurrentLanguage,
+ const SvNFFormatData& rFormatData,
+ const NativeNumberWrapper* pNatNum, const Accessor& rFuncs,
+ double fNumber, sal_uInt32 nFIndex, SvNumFormatType eType,
+ const SvNumberformat* pFormat, LanguageType eForLocale);
+
+ static void GetOutputString(SvNFLanguageData& rCurrentLanguage,
+ const SvNFFormatData& rFormatData,
+ const NativeNumberWrapper* pNatNum, const Accessor& rFuncs,
+ const double& fOutNumber, sal_uInt32 nFIndex, OUString& sOutString,
+ const Color** ppColor, bool bUseStarFormat);
+
+ static void GetOutputString(SvNFLanguageData& rCurrentLanguage,
+ const SvNFFormatData& rFormatData, const OUString& sString,
+ sal_uInt32 nFIndex, OUString& sOutString, const Color** ppColor,
+ bool bUseStarFormat);
+
+ static bool GetPreviewString(SvNFLanguageData& rCurrentLanguage,
+ const SvNFFormatData& rFormatData,
+ const NativeNumberWrapper* pNatNum, const Accessor& rFuncs,
+ const OUString& sFormatString, double fPreviewNumber,
+ OUString& sOutString, const Color** ppColor, LanguageType eLnge,
+ bool bUseStarFormat);
+
+ static bool GetPreviewString(SvNFLanguageData& rCurrentLanguage,
+ const SvNFFormatData& rFormatData,
+ const NativeNumberWrapper* pNatNum, const Accessor& rFuncs,
+ const OUString& sFormatString, const OUString& sPreviewString,
+ OUString& sOutString, const Color** ppColor,
+ LanguageType eLnge = LANGUAGE_DONTKNOW);
+
+ static bool GetPreviewStringGuess(SvNFLanguageData& rCurrentLanguage,
+ const SvNFFormatData& rFormatData,
+ const NativeNumberWrapper* pNatNum, const Accessor& rFuncs,
+ const OUString& sFormatString, double fPreviewNumber,
+ OUString& sOutString, const Color** ppColor,
+ LanguageType eLnge);
+
+ static OUString GenerateFormat(SvNFLanguageData& rCurrentLanguage,
+ const SvNFFormatData& rFormatData,
+ const NativeNumberWrapper* pNatNum, const Accessor& rFuncs,
+ sal_uInt32 nIndex, LanguageType eLnge, bool bThousand,
+ bool IsRed, sal_uInt16 nPrecision, sal_uInt16 nLeadingZeros);
+
+private:
+ static sal_uInt32 ImpGetDefaultFormat(const SvNFFormatData& rFormatData,
+ const SvNFEngine::CacheFormat& rFunc,
+ SvNumFormatType nType, sal_uInt32 CLOffset);
+ static sal_uInt32
+ ImpGetStandardFormat(SvNFLanguageData& rCurrentLanguage, const SvNFFormatData& rFormatData,
+ const NativeNumberWrapper* pNatNum, const SvNFEngine::Accessor& rFuncs,
+ SvNumFormatType eType, sal_uInt32 CLOffset, LanguageType eLnge);
+
+ static sal_uInt32 DefaultCurrencyRW(SvNFFormatData& rFormatData,
+ SvNFLanguageData& rCurrentLanguage,
+ const NativeNumberWrapper* pNatNum, sal_uInt32 CLOffset,
+ LanguageType eLnge);
+ static sal_uInt32 DefaultCurrencyRO(const SvNFFormatData& rFormatData, SvNFLanguageData&,
+ const NativeNumberWrapper*, sal_uInt32 CLOffset,
+ LanguageType eLnge);
+
+ static sal_uInt32 GetCLOffsetRW(SvNFFormatData& rFormatData, SvNFLanguageData& rCurrentLanguage,
+ const NativeNumberWrapper* pNatNum, LanguageType eLnge);
+ static sal_uInt32 GetCLOffsetRO(const SvNFFormatData& rFormatData, SvNFLanguageData&,
+ const NativeNumberWrapper*, LanguageType eLnge);
+
+ static void CacheFormatRW(SvNFFormatData& rFormatData, sal_uInt32 nSearch, sal_uInt32 nFormat);
+ static void CacheFormatRO(const SvNFFormatData& rFormatData, sal_uInt32 nSearch,
+ sal_uInt32 nFormat);
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/svl/numformat.hxx b/include/svl/numformat.hxx
index 47e85cd0fa5a..7acecbcbc2b4 100644
--- a/include/svl/numformat.hxx
+++ b/include/svl/numformat.hxx
@@ -19,22 +19,8 @@
#pragma once
#include <svl/svldllapi.h>
-#include <com/sun/star/i18n/XNumberFormatCode.hpp>
-#include <com/sun/star/uno/XComponentContext.hpp>
-#include <i18nlangtag/lang.h>
-#include <tools/link.hxx>
-#include <svl/nfkeytab.hxx>
-#include <svl/ondemand.hxx>
-#include <svl/zforlist.hxx>
-#include <unotools/charclass.hxx>
-
-#include <map>
-
-class Color;
-class ImpSvNumberformatScan;
-class ImpSvNumberInputScan;
-class SvNumberFormatterRegistry_Impl;
-class NfCurrencyTable;
+
+#include <svl/nfengine.hxx>
class SVL_DLLPUBLIC SvNumberFormatter
{
@@ -246,7 +232,7 @@ public:
sal_uInt16& nPrecision, sal_uInt16& nLeadingCnt);
/// Count of decimals
- sal_uInt16 GetFormatPrecision(sal_uInt32 nFormat) const;
+ sal_uInt16 GetFormatPrecision(sal_uInt32 nFormat);
/// Count of integer digits
sal_uInt16 GetFormatIntegerDigits(sal_uInt32 nFormat) const;
@@ -381,10 +367,7 @@ public:
static sal_uInt16 ExpandTwoDigitYear(sal_uInt16 nYear, sal_uInt16 nTwoDigitYearStart);
/// Return the decimal separator matching the locale of the given format
- OUString GetFormatDecimalSep(sal_uInt32 nFormat) const;
-
- /// Return the decimal separator matching the given locale / LanguageType.
- OUString GetLangDecimalSep(LanguageType nLang) const;
+ OUString GetFormatDecimalSep(sal_uInt32 nFormat);
static void resetTheCurrencyTable();
@@ -554,50 +537,18 @@ public:
/** Access for unit tests. */
static size_t GetMaxDefaultColors();
- struct InputScannerPrivateAccess
- {
- friend class ImpSvNumberInputScan;
-
- private:
- InputScannerPrivateAccess() {}
- };
- /** Access for input scanner to temporarily (!) switch locales. */
- OnDemandLocaleDataWrapper& GetOnDemandLocaleDataWrapper(const InputScannerPrivateAccess&)
- {
- return xLocaleData;
- }
-
private:
mutable ::osl::Mutex m_aMutex;
css::uno::Reference<css::uno::XComponentContext> m_xContext;
const LanguageType IniLnge; // Initialized setting language/country
- LanguageType ActLnge; // Current setting language/country
- LanguageTag maLanguageTag;
- std::map<sal_uInt32, std::unique_ptr<SvNumberformat>>
- aFTable; // Table of format keys to format entries
- typedef std::map<sal_uInt32, sal_uInt32> DefaultFormatKeysMap;
- DefaultFormatKeysMap aDefaultFormatKeys; // Table of default standard to format keys
+ SvNFFormatData m_aFormatData;
+ SvNFEngine::Accessor m_aRWPolicy;
std::unique_ptr<SvNumberFormatTable> pFormatTable; // For the UI dialog
std::unique_ptr<SvNumberFormatterIndexTable>
pMergeTable; // List of indices for merging two formatters
- OnDemandCharClass xCharClass; // CharacterClassification
- OnDemandLocaleDataWrapper xLocaleData; // LocaleData switched between SYSTEM, ENGLISH and other
- OnDemandTransliterationWrapper xTransliteration; // Transliteration loaded on demand
- OnDemandCalendarWrapper xCalendar; // Calendar loaded on demand
+ SvNFLanguageData m_aCurrentLanguage;
OnDemandNativeNumberWrapper xNatNum; // Native number service loaded on demand
- std::unique_ptr<ImpSvNumberInputScan> pStringScanner; // Input string scanner
- std::unique_ptr<ImpSvNumberformatScan> pFormatScanner; // Format code string scanner
Link<sal_uInt16, Color*> aColorLink; // User defined color table CallBack
- sal_uInt32 MaxCLOffset; // Max language/country offset used
- sal_uInt32 nDefaultSystemCurrencyFormat; // NewCurrency matching SYSTEM locale
- NfEvalDateFormat eEvalDateFormat; // DateFormat evaluation
- bool bNoZero; // Zero value suppression
-
- // cached locale data items needed almost any time
- OUString aDecimalSep;
- OUString aDecimalSepAlt;
- OUString aThousandSep;
- OUString aDateSep;
SVL_DLLPRIVATE static volatile bool bCurrencyTableInitialized;
SVL_DLLPRIVATE static sal_uInt16 nSystemCurrencyPosition;
@@ -606,82 +557,42 @@ private:
// get the registry, create one if none exists
SVL_DLLPRIVATE static SvNumberFormatterRegistry_Impl& GetFormatterRegistry();
- // Generate builtin formats provided by i18n behind CLOffset,
- // if bNoAdditionalFormats==false also generate additional i18n formats.
- SVL_DLLPRIVATE void ImpGenerateFormats(sal_uInt32 CLOffset, bool bNoAdditionalFormats);
-
// Generate additional formats provided by i18n
SVL_DLLPRIVATE void ImpGenerateAdditionalFormats(
sal_uInt32 CLOffset,
css::uno::Reference<css::i18n::XNumberFormatCode> const& rNumberFormatCode,
bool bAfterChangingSystemCL);
- SVL_DLLPRIVATE SvNumberformat* ImpInsertFormat(const css::i18n::NumberFormatCode& rCode,
- sal_uInt32 nPos,
- bool bAfterChangingSystemCL = false,
- sal_Int16 nOrgIndex = 0);
-
- // Return CLOffset or (MaxCLOffset + SV_COUNTRY_LANGUAGE_OFFSET) if new language/country
- SVL_DLLPRIVATE sal_uInt32 ImpGetCLOffset(LanguageType eLnge) const;
-
// Test whether format code already exists, then return index key,
// otherwise NUMBERFORMAT_ENTRY_NOT_FOUND
SVL_DLLPRIVATE sal_uInt32 ImpIsEntry(std::u16string_view rString, sal_uInt32 CLOffset,
LanguageType eLnge) const;
- // Create builtin formats for language/country if necessary, return CLOffset
- SVL_DLLPRIVATE sal_uInt32 ImpGenerateCL(LanguageType eLnge);
-
// Create theCurrencyTable with all <type>NfCurrencyEntry</type>
SVL_DLLPRIVATE static void ImpInitCurrencyTable();
- // Return the format index of the currency format of the system locale.
- // Format is created if not already present.
- SVL_DLLPRIVATE sal_uInt32 ImpGetDefaultSystemCurrencyFormat();
-
- // Return the format index of the currency format of the current locale.
- // Format is created if not already present.
- SVL_DLLPRIVATE sal_uInt32 ImpGetDefaultCurrencyFormat();
-
- // Return the default format for a given type and current locale.
- // May ONLY be called from within GetStandardFormat().
- SVL_DLLPRIVATE sal_uInt32 ImpGetDefaultFormat(SvNumFormatType nType);
-
- // Return the index in a sequence of format codes matching an enum of
- // NfIndexTableOffset. If not found 0 is returned. If the sequence doesn't
- // contain any format code elements a default element is created and inserted.
- SVL_DLLPRIVATE sal_Int32 ImpGetFormatCodeIndex(
- css::uno::Sequence<css::i18n::NumberFormatCode>& rSeq, const NfIndexTableOffset nTabOff);
-
- // Adjust a sequence of format codes to contain only one (THE) default
- // instead of multiple defaults for short/medium/long types.
- // If there is no medium but a short and a long default the long is taken.
- // Non-PRODUCT version may check locale data for matching defaults in one
- // FormatElement group.
- SVL_DLLPRIVATE void ImpAdjustFormatCodeDefault(css::i18n::NumberFormatCode* pFormatArr,
- sal_Int32 nCount);
-
- // Obtain the format entry for a given key index.
- SVL_DLLPRIVATE SvNumberformat* GetFormatEntry(sal_uInt32 nKey);
- SVL_DLLPRIVATE const SvNumberformat* GetFormatEntry(sal_uInt32 nKey) const;
-
// used as a loop body inside of GetNewCurrencySymbolString() and GetCurrencyEntry()
static bool ImpLookupCurrencyEntryLoopBody(const NfCurrencyEntry*& pFoundEntry,
bool& bFoundBank, const NfCurrencyEntry* pData,
sal_uInt16 nPos, std::u16string_view rSymbol);
+ // called by SvNumberFormatterRegistry_Impl::Notify if the default system currency changes
+ SVL_DLLPRIVATE void ResetDefaultSystemCurrency();
+
// link to be set at <method>SvtSysLocaleOptions::SetCurrencyChangeLink()</method>
DECL_DLLPRIVATE_STATIC_LINK(SvNumberFormatter, CurrencyChangeLink, LinkParamNone*, void);
// Substitute a format during GetFormatEntry(), i.e. system formats.
- SVL_DLLPRIVATE SvNumberformat* ImpSubstituteEntry(SvNumberformat* pFormat,
- sal_uInt32* o_pRealKey = nullptr);
+ SVL_DLLPRIVATE const SvNumberformat* ImpSubstituteEntry(const SvNumberformat* pFormat,
+ sal_uInt32* o_pRealKey = nullptr);
// Whether nFIndex is a special builtin format
SVL_DLLPRIVATE bool ImpIsSpecialStandardFormat(sal_uInt32 nFIndex, LanguageType eLnge);
+ SVL_DLLPRIVATE static bool ImpIsSpecialStandardFormat(sal_uInt32 nFIndex, sal_uInt32 nCLOffset);
- // called by SvNumberFormatterRegistry_Impl::Notify if the default system currency changes
- SVL_DLLPRIVATE void ResetDefaultSystemCurrency();
+ SVL_DLLPRIVATE sal_uInt32 ImpGetOrGenerateCLOffset(LanguageType eLnge);
+
+ SVL_DLLPRIVATE LanguageType ImpResolveLanguage(LanguageType eLnge) const;
// Replace the SYSTEM language/country format codes. Called upon change of
// the user configurable locale.
@@ -700,28 +611,26 @@ public:
const css::uno::Reference<css::uno::XComponentContext>& GetComponentContext() const;
- //! The following method is not to be used from outside but must be
- //! public for the InputScanner.
- // return the current FormatScanner
- const ImpSvNumberformatScan* GetFormatScanner() const;
-
//! The following methods are not to be used from outside but must be
//! public for the InputScanner and FormatScanner.
// return current (!) Locale
- const LanguageTag& GetLanguageTag() const;
+ const LanguageTag& GetLanguageTag() const { return m_aCurrentLanguage.GetLanguageTag(); }
// return corresponding Transliteration wrapper
- const ::utl::TransliterationWrapper* GetTransliteration() const;
+ const ::utl::TransliterationWrapper* GetTransliteration() const
+ {
+ return m_aCurrentLanguage.GetTransliteration();
+ }
// return the corresponding CharacterClassification wrapper
- const CharClass* GetCharClass() const;
+ const CharClass* GetCharClass() const { return m_aCurrentLanguage.GetCharClass(); }
// return the corresponding LocaleData wrapper
- const LocaleDataWrapper* GetLocaleData() const;
+ const LocaleDataWrapper* GetLocaleData() const { return m_aCurrentLanguage.GetLocaleData(); }
// return the corresponding Calendar wrapper
- CalendarWrapper* GetCalendar() const;
+ CalendarWrapper* GetCalendar() const { return m_aCurrentLanguage.GetCalendar(); }
// return the corresponding NativeNumberSupplier wrapper
const NativeNumberWrapper* GetNatNum() const;
@@ -729,19 +638,19 @@ public:
// cached locale data items
// return the corresponding decimal separator
- const OUString& GetNumDecimalSep() const;
+ const OUString& GetNumDecimalSep() const { return m_aCurrentLanguage.GetNumDecimalSep(); }
// return the corresponding decimal separator alternative
- const OUString& GetNumDecimalSepAlt() const;
+ const OUString& GetNumDecimalSepAlt() const { return m_aCurrentLanguage.GetNumDecimalSepAlt(); }
// return the corresponding group (AKA thousand) separator
- const OUString& GetNumThousandSep() const;
+ const OUString& GetNumThousandSep() const { return m_aCurrentLanguage.GetNumThousandSep(); }
// return the corresponding date separator
- const OUString& GetDateSep() const;
+ const OUString& GetDateSep() const { return m_aCurrentLanguage.GetDateSep(); }
- // checks for decimal separator and optional alternative
- bool IsDecimalSep(std::u16string_view rStr) const;
+ const SvNFFormatData& GetROFormatData() const { return m_aFormatData; }
+ const SvNFLanguageData& GetROLanguageData() const { return m_aCurrentLanguage; }
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/svl/zformat.hxx b/include/svl/zformat.hxx
index f60e74783d5c..ed13abfcb63c 100644
--- a/include/svl/zformat.hxx
+++ b/include/svl/zformat.hxx
@@ -32,8 +32,12 @@ namespace com::sun::star::i18n { struct NativeNumberXmlAttributes2; }
class Color;
+class SvNFLanguageData;
+
class ImpSvNumberformatScan; // format code string scanner
class ImpSvNumberInputScan; // input string scanner
+class NativeNumberWrapper;
+class SvNFFormatData;
class SvNumberFormatter;
enum SvNumberformatLimitOps
@@ -171,6 +175,7 @@ public:
SvNumberformat( OUString& rString,
ImpSvNumberformatScan* pSc,
ImpSvNumberInputScan* pISc,
+ const NativeNumberWrapper* pNatNum,
sal_Int32& nCheckPos,
LanguageType& eLan,
bool bReplaceBooleanEquivalent = true );
@@ -239,11 +244,11 @@ public:
* Get output string from a numeric value that fits the number of
* characters specified.
*/
- bool GetOutputString( double fNumber, sal_uInt16 nCharCount, OUString& rOutString ) const;
+ bool GetOutputString( double fNumber, sal_uInt16 nCharCount, OUString& rOutString, const NativeNumberWrapper* pNatNum ) const;
// bStarFlag: Take *n format as ESC n
- bool GetOutputString( double fNumber, OUString& OutString, const Color** ppColor, bool bStarFlag = false ) const;
- void GetOutputString( std::u16string_view sString, OUString& OutString, const Color** ppColor, bool bStarFlag = false ) const;
+ bool GetOutputString( double fNumber, OUString& OutString, const Color** ppColor, const NativeNumberWrapper* pNatNum, bool bStarFlag = false) const;
+ void GetOutputString( std::u16string_view sString, OUString& OutString, const Color** ppColor, bool bStarFlag = false) const;
// True if type text
bool IsTextFormat() const { return bool(eType & SvNumFormatType::TEXT); }
@@ -283,7 +288,7 @@ public:
//! Read/write access on a special sal_uInt16 component, may only be used on the
//! standard format 0, 10000, ... and only by the number formatter!
- struct FormatterPrivateAccess { friend SvNumberFormatter; private: FormatterPrivateAccess() {} };
+ struct FormatterPrivateAccess { friend SvNumberFormatter; friend SvNFFormatData; private: FormatterPrivateAccess() {} };
sal_uInt16 GetLastInsertKey( const FormatterPrivateAccess& ) const
{ return NumFor[0].Info().nThousand; }
void SetLastInsertKey( sal_uInt16 nKey, const FormatterPrivateAccess& )
@@ -457,7 +462,8 @@ public:
// rAttr.Number not empty if NatNum attributes are to be stored
void GetNatNumXml(
css::i18n::NativeNumberXmlAttributes2& rAttr,
- sal_uInt16 nNumFor ) const;
+ sal_uInt16 nNumFor,
+ const NativeNumberWrapper* pNatNum ) const;
/** Return empty string if no NatNum modifier or invalid nNumFor
otherwise return "[NatNum1]" or "[NatNum12 ...]" */
OUString GetNatNumModifierString( sal_uInt16 nNumFor = 0 ) const;
@@ -551,7 +557,7 @@ private:
const CharClass& rChrCls() const;
const LocaleDataWrapper& rLoc() const;
CalendarWrapper& GetCal() const;
- const SvNumberFormatter& GetFormatter() const;
+ const SvNFLanguageData& GetCurrentLanguageData() const;
// divide in substrings and color conditions
SVL_DLLPRIVATE short ImpNextSymbol( OUStringBuffer& rString,
@@ -606,9 +612,12 @@ private:
const LocaleType & aTmpLocale );
// standard number output
- SVL_DLLPRIVATE void ImpGetOutputStandard( double& fNumber, OUString& OutString ) const;
- SVL_DLLPRIVATE void ImpGetOutputStandard( double& fNumber, OUStringBuffer& OutString ) const;
- SVL_DLLPRIVATE void ImpGetOutputStdToPrecision( double& rNumber, OUString& rOutString, sal_uInt16 nPrecision ) const;
+ SVL_DLLPRIVATE void ImpGetOutputStandard(double& fNumber, OUString& OutString,
+ const NativeNumberWrapper* pNatNum) const;
+ SVL_DLLPRIVATE void ImpGetOutputStandard(double& fNumber, OUStringBuffer& OutString,
+ const NativeNumberWrapper* pNatNum) const;
+ SVL_DLLPRIVATE void ImpGetOutputStdToPrecision(double& rNumber, OUString& rOutString, sal_uInt16 nPrecision,
+ const NativeNumberWrapper* pNatNum) const;
// numbers in input line
SVL_DLLPRIVATE void ImpGetOutputInputLine( double fNumber, OUString& OutString ) const;
@@ -621,7 +630,9 @@ private:
// Helper function for number strings
// append string symbols, insert leading 0 or ' ', or ...
- SVL_DLLPRIVATE bool ImpNumberFill(OUStringBuffer& sStr,
+ SVL_DLLPRIVATE bool ImpNumberFill(
+ const NativeNumberWrapper* pNatNum,
+ OUStringBuffer& sStr,
double& rNumber,
sal_Int32& k,
sal_uInt16& j,
@@ -631,7 +642,9 @@ private:
bool bInsertRightBlank = false ) const;
// Helper function to fill in the integer part and the group (AKA thousand) separators
- SVL_DLLPRIVATE bool ImpNumberFillWithThousands(OUStringBuffer& sStr,
+ SVL_DLLPRIVATE bool ImpNumberFillWithThousands(
+ const NativeNumberWrapper* pNatNum,
+ OUStringBuffer& sStr,
double& rNumber,
sal_Int32 k,
sal_uInt16 j,
@@ -649,7 +662,8 @@ private:
sal_Int32 & nDigitCount,
utl::DigitGroupingIterator & ) const;
- SVL_DLLPRIVATE bool ImpDecimalFill( OUStringBuffer& sStr,
+ SVL_DLLPRIVATE bool ImpDecimalFill(const NativeNumberWrapper* pNatNum,
+ OUStringBuffer& sStr,
double& rNumber,
sal_Int32 nDecPos,
sal_uInt16 j,
@@ -673,23 +687,28 @@ private:
SVL_DLLPRIVATE bool ImpGetFractionOutput(double fNumber,
sal_uInt16 nIx,
bool bStarFlag,
+ const NativeNumberWrapper* pNatNum,
OUStringBuffer& OutString) const;
SVL_DLLPRIVATE bool ImpGetScientificOutput(double fNumber,
sal_uInt16 nIx,
bool bStarFlag,
+ const NativeNumberWrapper* pNatNum,
OUStringBuffer& OutString) const;
SVL_DLLPRIVATE bool ImpGetDateOutput( double fNumber,
sal_uInt16 nIx,
bool bStarFlag,
+ const NativeNumberWrapper* pNatNum,
OUStringBuffer& OutString ) const;
SVL_DLLPRIVATE bool ImpGetTimeOutput( double fNumber,
sal_uInt16 nIx,
bool bStarFlag,
+ const NativeNumberWrapper* pNatNum,
OUStringBuffer& OutString ) const;
SVL_DLLPRIVATE bool ImpGetDateTimeOutput( double fNumber,
sal_uInt16 nIx,
bool bStarFlag,
+ const NativeNumberWrapper* pNatNum,
OUStringBuffer& OutString ) const;
// Switches to the "gregorian" calendar if the current calendar is
@@ -707,26 +726,28 @@ private:
SVL_DLLPRIVATE bool ImpGetLogicalOutput( double fNumber,
sal_uInt16 nIx,
- OUStringBuffer& OutString ) const;
+ const NativeNumberWrapper* pNatNum,
+ OUStringBuffer& OutString) const;
SVL_DLLPRIVATE bool ImpGetNumberOutput( double fNumber,
sal_uInt16 nIx,
bool bStarFlag,
- OUStringBuffer& OutString ) const;
+ const NativeNumberWrapper* pNatNum,
+ OUStringBuffer& OutString) const;
SVL_DLLPRIVATE void ImpCopyNumberformat( const SvNumberformat& rFormat );
// normal digits or other digits, depending on ImpSvNumFor.aNatNum,
// [NatNum1], [NatNum2], ...
- SVL_DLLPRIVATE OUString ImpGetNatNumString( const SvNumberNatNum& rNum, sal_Int64 nVal,
- sal_uInt16 nMinDigits ) const;
+ SVL_DLLPRIVATE static OUString ImpGetNatNumString(const SvNumberNatNum& rNum, sal_Int64 nVal,
+ sal_uInt16 nMinDigits, const NativeNumberWrapper* pNatNum);
- OUString ImpIntToString( sal_uInt16 nIx, sal_Int64 nVal, sal_uInt16 nMinDigits = 0 ) const
+ OUString ImpIntToString(const NativeNumberWrapper* pNatNum, sal_uInt16 nIx, sal_Int64 nVal, sal_uInt16 nMinDigits = 0 ) const
{
const SvNumberNatNum& rNum = NumFor[nIx].GetNatNum();
if ( nMinDigits || rNum.IsComplete() )
{
- return ImpGetNatNumString( rNum, nVal, nMinDigits );
+ return ImpGetNatNumString( rNum, nVal, nMinDigits, pNatNum );
}
return OUString::number(nVal);
}
@@ -738,29 +759,15 @@ private:
// nFractionDecimals, unless nMinimumInputLineDecimals>0 is given for input
// line string where extra trailing "0" are discarded.
SVL_DLLPRIVATE sal_uInt16 ImpGetFractionOfSecondString( OUStringBuffer& rBuf, double fFractionOfSecond,
- int nFractionDecimals, bool bAddOneRoundingDecimal, sal_uInt16 nIx, sal_uInt16 nMinimumInputLineDecimals ) const;
+ int nFractionDecimals, bool bAddOneRoundingDecimal, sal_uInt16 nIx, sal_uInt16 nMinimumInputLineDecimals,
+ const NativeNumberWrapper* pNatNum) const;
// transliterate according to NativeNumber
- SVL_DLLPRIVATE OUString impTransliterateImpl(const OUString& rStr, const SvNumberNatNum& rNum) const;
- SVL_DLLPRIVATE void impTransliterateImpl(OUStringBuffer& rStr, const SvNumberNatNum& rNum) const;
- SVL_DLLPRIVATE OUString impTransliterateImpl(const OUString& rStr, const SvNumberNatNum& rNum, sal_uInt16 nDateKey) const;
-
- OUString impTransliterate(const OUString& rStr, const SvNumberNatNum& rNum) const
- {
- return rNum.IsComplete() ? impTransliterateImpl(rStr, rNum) : rStr;
- }
-
- SVL_DLLPRIVATE void impTransliterate(OUStringBuffer& rStr, const SvNumberNatNum& rNum) const
- {
- if(rNum.IsComplete())
- {
- impTransliterateImpl(rStr, rNum);
- }
- }
+ SVL_DLLPRIVATE OUString impTransliterateImpl(const OUString& rStr, const SvNumberNatNum& rNum, sal_uInt16 nDateKey, const NativeNumberWrapper* pNatNum) const;
- OUString impTransliterate(const OUString& rStr, const SvNumberNatNum& rNum, sal_uInt16 nDateKey) const
+ OUString impTransliterate(const OUString& rStr, const SvNumberNatNum& rNum, sal_uInt16 nDateKey, const NativeNumberWrapper* pNatNum) const
{
- return rNum.IsComplete() ? impTransliterateImpl(rStr, rNum, nDateKey) : rStr;
+ return rNum.IsComplete() ? impTransliterateImpl(rStr, rNum, nDateKey, pNatNum) : rStr;
}
};