diff options
author | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-03-21 17:25:35 +0000 |
---|---|---|
committer | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-03-22 21:50:59 +0100 |
commit | c6c6126aa3e8de256091b829b98b5943db6a8be6 (patch) | |
tree | 92f6d9235eaa8fb25e477fe2667396a56a285174 | |
parent | c900850742efd4e1fb7c79c13c1b9a17fcd4981d (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>
-rw-r--r-- | include/svl/nfengine.hxx | 432 | ||||
-rw-r--r-- | include/svl/numformat.hxx | 151 | ||||
-rw-r--r-- | include/svl/zformat.hxx | 81 | ||||
-rw-r--r-- | sc/source/ui/view/output2.cxx | 4 | ||||
-rw-r--r-- | sc/source/ui/view/viewfunc.cxx | 2 | ||||
-rw-r--r-- | svl/source/numbers/zforfind.cxx | 115 | ||||
-rw-r--r-- | svl/source/numbers/zforfind.hxx | 7 | ||||
-rw-r--r-- | svl/source/numbers/zforlist.cxx | 1971 | ||||
-rw-r--r-- | svl/source/numbers/zformat.cxx | 267 | ||||
-rw-r--r-- | svl/source/numbers/zforscan.cxx | 91 | ||||
-rw-r--r-- | svl/source/numbers/zforscan.hxx | 20 | ||||
-rw-r--r-- | sw/source/uibase/utlui/numfmtlb.cxx | 2 | ||||
-rw-r--r-- | xmloff/source/style/xmlnumfe.cxx | 2 |
13 files changed, 2018 insertions, 1127 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; } }; diff --git a/sc/source/ui/view/output2.cxx b/sc/source/ui/view/output2.cxx index dd9a7ba0e1a5..8a18ea06a084 100644 --- a/sc/source/ui/view/output2.cxx +++ b/sc/source/ui/view/output2.cxx @@ -646,7 +646,7 @@ bool ScDrawStringsVars::SetTextToWidthOrHash( ScRefCellValue& rCell, tools::Long sal_uInt16 nNumDigits = static_cast<sal_uInt16>(nWidth / nMaxDigit); { OUString sTempOut(aString); - if (!pNumFormat->GetOutputString(fVal, nNumDigits, sTempOut)) + if (!pNumFormat->GetOutputString(fVal, nNumDigits, sTempOut, pOutput->mpDoc->GetFormatTable()->GetNatNum())) { aString = sTempOut; // Failed to get output string. Bail out. @@ -685,7 +685,7 @@ bool ScDrawStringsVars::SetTextToWidthOrHash( ScRefCellValue& rCell, tools::Long // Re-calculate. nNumDigits = static_cast<sal_uInt16>(nWidth / nMaxDigit); OUString sTempOut(aString); - if (!pNumFormat->GetOutputString(fVal, nNumDigits, sTempOut)) + if (!pNumFormat->GetOutputString(fVal, nNumDigits, sTempOut, pOutput->mpDoc->GetFormatTable()->GetNatNum())) { aString = sTempOut; // Failed to get output string. Bail out. diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx index 370097507f06..76e575886ced 100644 --- a/sc/source/ui/view/viewfunc.cxx +++ b/sc/source/ui/view/viewfunc.cxx @@ -2991,7 +2991,7 @@ void ScViewFunc::ChangeNumFmtDecimals( bool bIncrement ) // the ways of the Numberformatters are unfathomable, so try: OUString aOut; const Color* pCol; - pOldEntry->GetOutputString( nVal, aOut, &pCol ); + pOldEntry->GetOutputString( nVal, aOut, &pCol, pFormatter->GetNatNum() ); nPrecision = 0; // 'E' for exponential is fixed in Numberformatter diff --git a/svl/source/numbers/zforfind.cxx b/svl/source/numbers/zforfind.cxx index c1898104a905..350129da68d7 100644 --- a/svl/source/numbers/zforfind.cxx +++ b/svl/source/numbers/zforfind.cxx @@ -72,22 +72,21 @@ const sal_Unicode cNoBreakSpace = 0xA0; const sal_Unicode cNarrowNoBreakSpace = 0x202F; const bool kDefaultEra = true; // Gregorian CE, positive year -ImpSvNumberInputScan::ImpSvNumberInputScan( SvNumberFormatter* pFormatterP ) +ImpSvNumberInputScan::ImpSvNumberInputScan(SvNFLanguageData& rCurrentLanguage) : + mrCurrentLanguageData(rCurrentLanguage), bTextInitialized( false ), bScanGenitiveMonths( false ), bScanPartitiveMonths( false ), eScannedType( SvNumFormatType::UNDEFINED ), eSetType( SvNumFormatType::UNDEFINED ) { - pFormatter = pFormatterP; moNullDate.emplace( 30,12,1899 ); nYear2000 = SvNumberFormatter::GetYear2000Default(); Reset(); ChangeIntl(); } - ImpSvNumberInputScan::~ImpSvNumberInputScan() { } @@ -130,21 +129,20 @@ void ImpSvNumberInputScan::Reset() } // native number transliteration if necessary -static void TransformInput( SvNumberFormatter const * pFormatter, OUString& rStr ) +static void TransformInput(const NativeNumberWrapper* pNatNum, const SvNFLanguageData& rCurrentLanguage, OUString& rStr) { sal_Int32 nPos, nLen; for ( nPos = 0, nLen = rStr.getLength(); nPos < nLen; ++nPos ) { if ( 256 <= rStr[ nPos ] && - pFormatter->GetCharClass()->isDigit( rStr, nPos ) ) + rCurrentLanguage.GetCharClass()->isDigit( rStr, nPos ) ) { break; } } if ( nPos < nLen ) { - rStr = pFormatter->GetNatNum()->getNativeNumberString( rStr, - pFormatter->GetLanguageTag().getLocale(), 0 ); + rStr = pNatNum->getNativeNumberString(rStr, rCurrentLanguage.GetLanguageTag().getLocale(), 0); } } @@ -291,7 +289,7 @@ bool ImpSvNumberInputScan::SkipThousands( const sal_Unicode*& pStr, bool res = false; OUStringBuffer sBuff(rSymbol); sal_Unicode cToken; - const OUString& rThSep = pFormatter->GetNumThousandSep(); + const OUString& rThSep = mrCurrentLanguageData.GetNumThousandSep(); const sal_Unicode* pHere = pStr; ScanState eState = SsStart; sal_Int32 nCounter = 0; // counts 3 digits @@ -466,7 +464,7 @@ bool ImpSvNumberInputScan::StringContainsWord( const OUString& rWhat, if (nPos+1 < nIndex) return true; // Surrogate, assume these to be new words. - const sal_Int32 nType = pFormatter->GetCharClass()->getCharacterType( rString, nPos); + const sal_Int32 nType = mrCurrentLanguageData.GetCharClass()->getCharacterType( rString, nPos); using namespace ::com::sun::star::i18n; if ((nType & (KCharacterType::UPPER | KCharacterType::LOWER | KCharacterType::DIGIT)) != 0) @@ -539,7 +537,7 @@ inline bool ImpSvNumberInputScan::GetThousandSep( std::u16string_view rString, sal_Int32& nPos, sal_uInt16 nStringPos ) const { - const OUString& rSep = pFormatter->GetNumThousandSep(); + const OUString& rSep = mrCurrentLanguageData.GetNumThousandSep(); // Is it an ordinary space instead of a no-break space? bool bSpaceBreak = (rSep[0] == cNoBreakSpace || rSep[0] == cNarrowNoBreakSpace) && rString[0] == u' ' && @@ -551,7 +549,7 @@ inline bool ImpSvNumberInputScan::GetThousandSep( std::u16string_view rString, return false; // no? => out } - utl::DigitGroupingIterator aGrouping( pFormatter->GetLocaleData()->getDigitGrouping()); + utl::DigitGroupingIterator aGrouping( mrCurrentLanguageData.GetLocaleData()->getDigitGrouping()); // Match ,### in {3} or ,## in {3,2} /* FIXME: this could be refined to match ,## in {3,2} only if ,##,## or * ,##,### and to match ,### in {3,2} only if it's the last. However, @@ -580,7 +578,7 @@ short ImpSvNumberInputScan::GetLogical( std::u16string_view rString ) const { short res; - const ImpSvNumberformatScan* pFS = pFormatter->GetFormatScanner(); + const ImpSvNumberformatScan* pFS = mrCurrentLanguageData.GetFormatScanner(); if ( rString == pFS->GetTrueString() ) { res = 1; @@ -611,7 +609,7 @@ short ImpSvNumberInputScan::GetMonth( const OUString& rString, sal_Int32& nPos ) { InitText(); } - sal_Int16 nMonths = pFormatter->GetCalendar()->getNumberOfMonthsInYear(); + sal_Int16 nMonths = mrCurrentLanguageData.GetCalendar()->getNumberOfMonthsInYear(); for ( sal_Int16 i = 0; i < nMonths; i++ ) { if ( bScanGenitiveMonths && StringContainsWord( pUpperGenitiveMonthText[i], rString, nPos ) ) @@ -650,7 +648,7 @@ short ImpSvNumberInputScan::GetMonth( const OUString& rString, sal_Int32& nPos ) res = sal::static_int_cast< short >(-(i+1)); // negative break; // for } - else if (i == 2 && pFormatter->GetLanguageTag().getLanguage() == "de") + else if (i == 2 && mrCurrentLanguageData.GetLanguageTag().getLanguage() == "de") { if (pUpperAbbrevMonthText[i] == u"M\u00C4R" && StringContainsWord( "MRZ", rString, nPos)) { // Accept MRZ for MÄR @@ -689,7 +687,7 @@ short ImpSvNumberInputScan::GetMonth( const OUString& rString, sal_Int32& nPos ) // Brutal hack for German locales that know "Januar" or "Jänner". /* TODO: add alternative month names to locale data? if there are * more languages... */ - const LanguageTag& rLanguageTag = pFormatter->GetLanguageTag(); + const LanguageTag& rLanguageTag = mrCurrentLanguageData.GetLanguageTag(); if (rLanguageTag.getLanguage() == "de") { if (rLanguageTag.getCountry() == "AT") @@ -744,7 +742,7 @@ int ImpSvNumberInputScan::GetDayOfWeek( const OUString& rString, sal_Int32& nPos { InitText(); } - sal_Int16 nDays = pFormatter->GetCalendar()->getNumberOfDaysInWeek(); + sal_Int16 nDays = mrCurrentLanguageData.GetCalendar()->getNumberOfDaysInWeek(); for ( sal_Int16 i = 0; i < nDays; i++ ) { if ( StringContainsWord( pUpperDayText[i], rString, nPos ) ) @@ -778,8 +776,8 @@ bool ImpSvNumberInputScan::GetCurrency( const OUString& rString, sal_Int32& nPos if ( !aUpperCurrSymbol.getLength() ) { // If no format specified the currency of the currently active locale. LanguageType eLang = (mpFormat ? mpFormat->GetLanguage() : - pFormatter->GetLocaleData()->getLanguageTag().getLanguageType()); - aUpperCurrSymbol = pFormatter->GetCharClass()->uppercase( + mrCurrentLanguageData.GetLocaleData()->getLanguageTag().getLanguageType()); + aUpperCurrSymbol = mrCurrentLanguageData.GetCharClass()->uppercase( SvNumberFormatter::GetCurrencyEntry( eLang ).GetSymbol() ); } if ( StringContains( aUpperCurrSymbol, rString, nPos ) ) @@ -794,7 +792,7 @@ bool ImpSvNumberInputScan::GetCurrency( const OUString& rString, sal_Int32& nPos { if ( aSymbol.getLength() <= rString.getLength() - nPos ) { - aSymbol = pFormatter->GetCharClass()->uppercase(aSymbol); + aSymbol = mrCurrentLanguageData.GetCharClass()->uppercase(aSymbol); if ( StringContains( aSymbol, rString, nPos ) ) { nPos = nPos + aSymbol.getLength(); @@ -826,8 +824,8 @@ bool ImpSvNumberInputScan::GetTimeAmPm( const OUString& rString, sal_Int32& nPos if ( rString.getLength() > nPos ) { - const CharClass* pChr = pFormatter->GetCharClass(); - const LocaleDataWrapper* pLoc = pFormatter->GetLocaleData(); + const CharClass* pChr = mrCurrentLanguageData.GetCharClass(); + const LocaleDataWrapper* pLoc = mrCurrentLanguageData.GetLocaleData(); if ( StringContains( pChr->uppercase( pLoc->getTimeAM() ), rString, nPos ) ) { nAmPm = 1; @@ -855,13 +853,13 @@ inline bool ImpSvNumberInputScan::GetDecSep( std::u16string_view rString, sal_In { if ( static_cast<sal_Int32>(rString.size()) > nPos ) { - const OUString& rSep = pFormatter->GetNumDecimalSep(); + const OUString& rSep = mrCurrentLanguageData.GetNumDecimalSep(); if ( o3tl::starts_with(rString.substr(nPos), rSep) ) { nPos = nPos + rSep.getLength(); return true; } - const OUString& rSepAlt = pFormatter->GetNumDecimalSepAlt(); + const OUString& rSepAlt = mrCurrentLanguageData.GetNumDecimalSepAlt(); if ( !rSepAlt.isEmpty() && o3tl::starts_with(rString.substr(nPos), rSepAlt) ) { nPos = nPos + rSepAlt.getLength(); @@ -891,7 +889,7 @@ inline bool ImpSvNumberInputScan::GetTime100SecSep( std::u16string_view rString, } // Even in an otherwise ISO 8601 string be lenient and accept the // locale defined separator. - const OUString& rSep = pFormatter->GetLocaleData()->getTime100SecSep(); + const OUString& rSep = mrCurrentLanguageData.GetLocaleData()->getTime100SecSep(); if ( o3tl::starts_with(rString.substr(nPos), rSep)) { nPos = nPos + rSep.getLength(); @@ -1086,7 +1084,7 @@ sal_uInt16 ImpSvNumberInputScan::ImplGetDay( sal_uInt16 nIndex ) const sal_uInt16 ImpSvNumberInputScan::ImplGetMonth( sal_uInt16 nIndex ) const { // Preset invalid month number - sal_uInt16 nRes = pFormatter->GetCalendar()->getNumberOfMonthsInYear(); + sal_uInt16 nRes = mrCurrentLanguageData.GetCalendar()->getNumberOfMonthsInYear(); if (sStrArray[nNums[nIndex]].getLength() <= 2) { @@ -1207,7 +1205,7 @@ bool ImpSvNumberInputScan::IsAcceptableIso8601() { if (mpFormat && (mpFormat->GetType() & SvNumFormatType::DATE)) { - switch (pFormatter->GetEvalDateFormat()) + switch (mrCurrentLanguageData.GetEvalDateFormat()) { case NF_EVALDATEFORMAT_INTL: return CanForceToIso8601( GetDateOrder()); @@ -1316,19 +1314,19 @@ bool ImpSvNumberInputScan::IsAcceptedDatePattern( sal_uInt16 nStartPatternAt ) else if (!sDateAcceptancePatterns.hasElements()) { // The current locale is the format's locale, if a format is present. - const NfEvalDateFormat eEDF = pFormatter->GetEvalDateFormat(); - if (!mpFormat || eEDF == NF_EVALDATEFORMAT_FORMAT || mpFormat->GetLanguage() == pFormatter->GetLanguage()) + const NfEvalDateFormat eEDF = mrCurrentLanguageData.GetEvalDateFormat(); + if (!mpFormat || eEDF == NF_EVALDATEFORMAT_FORMAT || mpFormat->GetLanguage() == mrCurrentLanguageData.GetIniLanguage()) { - sDateAcceptancePatterns = pFormatter->GetLocaleData()->getDateAcceptancePatterns(); + sDateAcceptancePatterns = mrCurrentLanguageData.GetLocaleData()->getDateAcceptancePatterns(); } else { - OnDemandLocaleDataWrapper& xLocaleData = pFormatter->GetOnDemandLocaleDataWrapper( - SvNumberFormatter::InputScannerPrivateAccess()); + OnDemandLocaleDataWrapper& xLocaleData = mrCurrentLanguageData.GetOnDemandLocaleDataWrapper( + SvNFLanguageData::InputScannerPrivateAccess()); const LanguageTag aSaveLocale( xLocaleData->getLanguageTag() ); assert(mpFormat->GetLanguage() == aSaveLocale.getLanguageType()); // prerequisite // Obtain formatter's locale's (e.g. system) patterns. - xLocaleData.changeLocale( LanguageTag( pFormatter->GetLanguage())); + xLocaleData.changeLocale( LanguageTag( mrCurrentLanguageData.GetIniLanguage())); const css::uno::Sequence<OUString> aLocalePatterns( xLocaleData->getDateAcceptancePatterns()); // Reset to format's locale. xLocaleData.changeLocale( aSaveLocale); @@ -1365,7 +1363,7 @@ bool ImpSvNumberInputScan::IsAcceptedDatePattern( sal_uInt16 nStartPatternAt ) } nDatePatternStart = nStartPatternAt; // remember start particle - const sal_Int32 nMonthsInYear = pFormatter->GetCalendar()->getNumberOfMonthsInYear(); + const sal_Int32 nMonthsInYear = mrCurrentLanguageData.GetCalendar()->getNumberOfMonthsInYear(); for (sal_Int32 nPattern=0; nPattern < sDateAcceptancePatterns.getLength(); ++nPattern) { @@ -1375,8 +1373,8 @@ bool ImpSvNumberInputScan::IsAcceptedDatePattern( sal_uInt16 nStartPatternAt ) // Ignore a pattern that would match numeric input with decimal // separator. It may had been read from configuration or resulted // from the locales' patterns concatenation above. - if ( rPat[1] == pFormatter->GetLocaleData()->getNumDecimalSep().toChar() - || rPat[1] == pFormatter->GetLocaleData()->getNumDecimalSepAlt().toChar()) + if ( rPat[1] == mrCurrentLanguageData.GetLocaleData()->getNumDecimalSep().toChar() + || rPat[1] == mrCurrentLanguageData.GetLocaleData()->getNumDecimalSepAlt().toChar()) { SAL_WARN("svl.numbers", "ignoring date acceptance pattern with decimal separator ambiguity: " << rPat); continue; // for, next pattern @@ -1660,7 +1658,7 @@ DateOrder ImpSvNumberInputScan::GetDateOrder( bool bFromFormatIfNoPattern ) if (bFromFormatIfNoPattern && mpFormat) return mpFormat->GetDateOrder(); else - return pFormatter->GetLocaleData()->getDateOrder(); + return mrCurrentLanguageData.GetLocaleData()->getDateOrder(); } switch ((nOrder & 0xff0000) >> 16) { @@ -1726,7 +1724,7 @@ DateOrder ImpSvNumberInputScan::GetDateOrder( bool bFromFormatIfNoPattern ) } } SAL_WARN( "svl.numbers", "ImpSvNumberInputScan::GetDateOrder: undefined, falling back to locale's default"); - return pFormatter->GetLocaleData()->getDateOrder(); + return mrCurrentLanguageData.GetLocaleData()->getDateOrder(); } LongDateOrder ImpSvNumberInputScan::GetMiddleMonthLongDateOrder( bool bFormatTurn, @@ -1782,7 +1780,7 @@ bool ImpSvNumberInputScan::GetDateRef( double& fDays, sal_uInt16& nCounter ) int nFormatOrder; if ( mpFormat && (mpFormat->GetType() & SvNumFormatType::DATE) ) { - eEDF = pFormatter->GetEvalDateFormat(); + eEDF = mrCurrentLanguageData.GetEvalDateFormat(); switch ( eEDF ) { case NF_EVALDATEFORMAT_INTL : @@ -1805,8 +1803,8 @@ bool ImpSvNumberInputScan::GetDateRef( double& fDays, sal_uInt16& nCounter ) } bool res = true; - const LocaleDataWrapper* pLoc = pFormatter->GetLocaleData(); - CalendarWrapper* pCal = pFormatter->GetCalendar(); + const LocaleDataWrapper* pLoc = mrCurrentLanguageData.GetLocaleData(); + CalendarWrapper* pCal = mrCurrentLanguageData.GetCalendar(); for ( int nTryOrder = 1; nTryOrder <= nFormatOrder; nTryOrder++ ) { pCal->setGregorianDateTime( Date( Date::SYSTEM ) ); // today @@ -2459,7 +2457,7 @@ bool ImpSvNumberInputScan::ScanStartString( const OUString& rString ) if (nDayOfWeek < 0) { SkipChar( '.', rString, nTempPos ); // abbreviated - SkipString( pFormatter->GetLocaleData()->getLongDateDayOfWeekSep(), rString, nTempPos ); + SkipString( mrCurrentLanguageData.GetLocaleData()->getLongDateDayOfWeekSep(), rString, nTempPos ); SkipBlanks( rString, nTempPos); short nTempTempMonth = GetMonth( rString, nTempPos); if (nTempTempMonth) @@ -2513,7 +2511,7 @@ bool ImpSvNumberInputScan::ScanStartString( const OUString& rString ) { // full long name SkipBlanks(rString, nPos); - SkipString( pFormatter->GetLocaleData()->getLongDateDayOfWeekSep(), rString, nPos ); + SkipString( mrCurrentLanguageData.GetLocaleData()->getLongDateDayOfWeekSep(), rString, nPos ); } SkipBlanks(rString, nPos); nTempMonth = GetMonth(rString, nPos); @@ -2698,12 +2696,12 @@ bool ImpSvNumberInputScan::ScanMidString( const OUString& rString, sal_uInt16 nS nThousand++; } - const LocaleDataWrapper* pLoc = pFormatter->GetLocaleData(); + const LocaleDataWrapper* pLoc = mrCurrentLanguageData.GetLocaleData(); bool bSignedYear = false; bool bDate = SkipDatePatternSeparator( nStringPos, nPos, bSignedYear); // 12/31 31.12. 12/31/1999 31.12.1999 if (!bDate) { - const OUString& rDate = pFormatter->GetDateSep(); + const OUString& rDate = mrCurrentLanguageData.GetDateSep(); SkipBlanks(rString, nPos); bDate = SkipString( rDate, rString, nPos); // 10. 10- 10/ } @@ -3087,7 +3085,7 @@ bool ImpSvNumberInputScan::ScanEndString( const OUString& rString ) eScannedType = SvNumFormatType::PERCENT; } - const LocaleDataWrapper* pLoc = pFormatter->GetLocaleData(); + const LocaleDataWrapper* pLoc = mrCurrentLanguageData.GetLocaleData(); const OUString& rTime = pLoc->getTimeSep(); if ( SkipString(rTime, rString, nPos) ) // 10: { @@ -3120,7 +3118,7 @@ bool ImpSvNumberInputScan::ScanEndString( const OUString& rString ) bool bDate = SkipDatePatternSeparator( nStringsCnt-1, nPos, bSignedYear); // 12/31 31.12. 12/31/1999 31.12.1999 if (!bDate) { - const OUString& rDate = pFormatter->GetDateSep(); + const OUString& rDate = mrCurrentLanguageData.GetDateSep(); bDate = SkipString( rDate, rString, nPos); // 10. 10- 10/ } if (bDate && bSignDetectedHere) @@ -3234,7 +3232,7 @@ bool ImpSvNumberInputScan::ScanEndString( const OUString& rString ) { // day of week is just parsed away sal_Int32 nOldPos = nPos; - const OUString& rSep = pFormatter->GetLocaleData()->getLongDateDayOfWeekSep(); + const OUString& rSep = mrCurrentLanguageData.GetLocaleData()->getLongDateDayOfWeekSep(); if ( StringContains( rSep, rString, nPos ) ) { nPos = nPos + rSep.getLength(); @@ -3292,7 +3290,7 @@ bool ImpSvNumberInputScan::ScanStringNumFor( const OUString& rString, // S { return false; } - const ::utl::TransliterationWrapper* pTransliteration = pFormatter->GetTransliteration(); + const ::utl::TransliterationWrapper* pTransliteration = mrCurrentLanguageData.GetTransliteration(); const OUString* pStr; OUString aString( rString ); bool bFound = false; @@ -3445,7 +3443,7 @@ bool ImpSvNumberInputScan::IsNumberFormatMain( const OUString& rString, / if (eSetType == SvNumFormatType::FRACTION) // Fraction 1 = 1/1 { if (i >= nStringsCnt || // no end string nor decimal separator - pFormatter->IsDecimalSep( sStrArray[i])) + mrCurrentLanguageData.IsDecimalSep( sStrArray[i])) { eScannedType = SvNumFormatType::FRACTION; nMatchedAllStrings &= ~nMatchedVirgin; @@ -3468,7 +3466,7 @@ bool ImpSvNumberInputScan::IsNumberFormatMain( const OUString& rString, / eScannedType == SvNumFormatType::UNDEFINED && // not date or currency nDecPos == 0 && // no previous decimal separator (i >= nStringsCnt || // no end string nor decimal separator - pFormatter->IsDecimalSep( sStrArray[i])) + mrCurrentLanguageData.IsDecimalSep( sStrArray[i])) ) { eScannedType = SvNumFormatType::FRACTION; @@ -3742,8 +3740,8 @@ bool ImpSvNumberInputScan::MatchedReturn() void ImpSvNumberInputScan::InitText() { sal_Int32 j, nElems; - const CharClass* pChrCls = pFormatter->GetCharClass(); - const CalendarWrapper* pCal = pFormatter->GetCalendar(); + const CharClass* pChrCls = mrCurrentLanguageData.GetCharClass(); + const CalendarWrapper* pCal = mrCurrentLanguageData.GetCalendar(); pUpperMonthText.reset(); pUpperAbbrevMonthText.reset(); @@ -3816,13 +3814,13 @@ void ImpSvNumberInputScan::InitText() */ void ImpSvNumberInputScan::ChangeIntl() { - sal_Unicode cDecSep = pFormatter->GetNumDecimalSep()[0]; + sal_Unicode cDecSep = mrCurrentLanguageData.GetNumDecimalSep()[0]; bDecSepInDateSeps = ( cDecSep == '-' || - cDecSep == pFormatter->GetDateSep()[0] ); + cDecSep == mrCurrentLanguageData.GetDateSep()[0] ); if (!bDecSepInDateSeps) { - sal_Unicode cDecSepAlt = pFormatter->GetNumDecimalSepAlt().toChar(); - bDecSepInDateSeps = cDecSepAlt && (cDecSepAlt == '-' || cDecSepAlt == pFormatter->GetDateSep()[0]); + sal_Unicode cDecSepAlt = mrCurrentLanguageData.GetNumDecimalSepAlt().toChar(); + bDecSepInDateSeps = cDecSepAlt && (cDecSepAlt == '-' || cDecSepAlt == mrCurrentLanguageData.GetDateSep()[0]); } bTextInitialized = false; aUpperCurrSymbol.clear(); @@ -3854,6 +3852,7 @@ bool ImpSvNumberInputScan::IsNumberFormat( const OUString& rString, // s SvNumFormatType& F_Type, // IN: old type, OUT: new type double& fOutNumber, // OUT: number if convertible const SvNumberformat* pFormat, // maybe a number format to match against + const NativeNumberWrapper* pNatNum, SvNumInputOptions eInputOptions ) { bool res; // return value @@ -3871,9 +3870,9 @@ bool ImpSvNumberInputScan::IsNumberFormat( const OUString& rString, // s else { // NoMoreUpperNeeded, all comparisons on UpperCase - OUString aString = pFormatter->GetCharClass()->uppercase( rString ); + OUString aString = mrCurrentLanguageData.GetCharClass()->uppercase( rString ); // convert native number to ASCII if necessary - TransformInput(pFormatter, aString); + TransformInput(pNatNum, mrCurrentLanguageData, aString); res = IsNumberFormatMain( aString, pFormat ); } diff --git a/svl/source/numbers/zforfind.hxx b/svl/source/numbers/zforfind.hxx index dea732b93297..fbcb615926bd 100644 --- a/svl/source/numbers/zforfind.hxx +++ b/svl/source/numbers/zforfind.hxx @@ -28,7 +28,7 @@ #include <optional> class SvNumberformat; -class SvNumberFormatter; +class SvNFLanguageData; enum class SvNumFormatType : sal_Int16; #define SV_MAX_COUNT_INPUT_STRINGS 20 // max count of substrings in input scanner @@ -36,7 +36,7 @@ enum class SvNumFormatType : sal_Int16; class ImpSvNumberInputScan { public: - explicit ImpSvNumberInputScan( SvNumberFormatter* pFormatter ); + explicit ImpSvNumberInputScan(SvNFLanguageData& rCurrentLanguage); ~ImpSvNumberInputScan(); /*!*/ void ChangeIntl(); // MUST be called if language changes @@ -51,6 +51,7 @@ public: SvNumFormatType& F_Type, /// format type (in + out) double& fOutNumber, /// value determined (out) const SvNumberformat* pFormat, /// number format to which compare against + const NativeNumberWrapper* pNatNum, SvNumInputOptions eInputOptions); /// after IsNumberFormat: get decimal position @@ -76,7 +77,7 @@ public: bool HasIso8601Tsep() const { return bIso8601Tsep; } private: - SvNumberFormatter* pFormatter; + SvNFLanguageData& mrCurrentLanguageData; const SvNumberformat* mpFormat; //* The format to compare against, if any std::unique_ptr<OUString[]> pUpperMonthText; //* Array of month names, uppercase std::unique_ptr<OUString[]> pUpperAbbrevMonthText; //* Array of month names, abbreviated, uppercase diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx index ace560bad560..c98f94a11353 100644 --- a/svl/source/numbers/zforlist.cxx +++ b/svl/source/numbers/zforlist.cxx @@ -271,22 +271,29 @@ sal_uInt16 SvNumberFormatter::nSystemCurrencyPosition = 0; const sal_uInt16 SvNumberFormatter::UNLIMITED_PRECISION = ::std::numeric_limits<sal_uInt16>::max(); const sal_uInt16 SvNumberFormatter::INPUTSTRING_PRECISION = ::std::numeric_limits<sal_uInt16>::max()-1; -SvNumberFormatter::SvNumberFormatter( const Reference< XComponentContext >& rxContext, - LanguageType eLang ) - : m_xContext( rxContext ) - , IniLnge(eLang != LANGUAGE_DONTKNOW ? eLang : UNKNOWN_SUBSTITUTE) - , ActLnge(IniLnge) - , maLanguageTag(IniLnge) - , MaxCLOffset(0) - , nDefaultSystemCurrencyFormat(NUMBERFORMAT_ENTRY_NOT_FOUND) +void SvNFEngine::ChangeIntl(SvNFLanguageData& rCurrentLanguage, LanguageType eLnge) +{ + rCurrentLanguage.ChangeIntl(eLnge); +} + +void SvNFEngine::ChangeNullDate(SvNFLanguageData& rCurrentLanguage, sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear) +{ + rCurrentLanguage.pFormatScanner->ChangeNullDate(nDay, nMonth, nYear); + rCurrentLanguage.pStringScanner->ChangeNullDate(nDay, nMonth, nYear); +} + +SvNFLanguageData::SvNFLanguageData(const Reference<XComponentContext>& rxContext, LanguageType eLang, + const SvNumberFormatter& rColorCallback) + : xContext(rxContext) + , IniLnge(eLang) + , ActLnge(eLang) + , aLanguageTag(eLang) , eEvalDateFormat(NF_EVALDATEFORMAT_INTL) - , bNoZero(false) { - xCharClass.changeLocale( m_xContext, maLanguageTag ); - xLocaleData.init( m_xContext, maLanguageTag ); - xCalendar.init( m_xContext, maLanguageTag.getLocale() ); - xTransliteration.init( m_xContext, IniLnge ); - xNatNum.init( m_xContext ); + xCharClass.changeLocale(xContext, aLanguageTag); + xLocaleData.init(xContext, aLanguageTag); + xCalendar.init(xContext, aLanguageTag.getLocale()); + xTransliteration.init(xContext, ActLnge); // cached locale data items const LocaleDataWrapper* pLoc = GetLocaleData(); @@ -295,43 +302,99 @@ SvNumberFormatter::SvNumberFormatter( const Reference< XComponentContext >& rxCo aThousandSep = pLoc->getNumThousandSep(); aDateSep = pLoc->getDateSep(); - pStringScanner.reset( new ImpSvNumberInputScan( this ) ); - pFormatScanner.reset( new ImpSvNumberformatScan( this ) ); - ImpGenerateFormats( 0, false ); // 0 .. 999 for initialized language formats + pStringScanner.reset(new ImpSvNumberInputScan(*this)); + pFormatScanner.reset(new ImpSvNumberformatScan(*this, rColorCallback)); +} - ::osl::MutexGuard aGuard( GetGlobalMutex() ); - GetFormatterRegistry().Insert( this ); +SvNFLanguageData::SvNFLanguageData(const SvNFLanguageData& rOther) + : xContext(rOther.xContext) + , IniLnge(rOther.IniLnge) + , ActLnge(rOther.ActLnge) + , aLanguageTag(rOther.aLanguageTag) + , aDecimalSep(rOther.aDecimalSep) + , aDecimalSepAlt(rOther.aDecimalSepAlt) + , aThousandSep(rOther.aThousandSep) + , aDateSep(rOther.aDateSep) + , eEvalDateFormat(rOther.eEvalDateFormat) +{ + xCharClass.changeLocale(xContext, aLanguageTag); + xLocaleData.init(xContext, aLanguageTag); + xCalendar.init(xContext, aLanguageTag.getLocale()); + xTransliteration.init(xContext, ActLnge); + + pStringScanner.reset(new ImpSvNumberInputScan(*this)); + pFormatScanner.reset(new ImpSvNumberformatScan(*this, rOther.pFormatScanner->getColorCallback())); } -SvNumberFormatter::~SvNumberFormatter() +SvNFLanguageData::~SvNFLanguageData() { - { - ::osl::MutexGuard aGuard( GetGlobalMutex() ); - pFormatterRegistry->Remove( this ); - if ( !pFormatterRegistry->Count() ) - { - delete pFormatterRegistry; - pFormatterRegistry = nullptr; - } - } +} - aFTable.clear(); - ClearMergeTable(); +const LocaleDataWrapper* SvNFLanguageData::GetLocaleData() const { return xLocaleData.get(); } + +const CharClass* SvNFLanguageData::GetCharClass() const { return xCharClass.get(); } + +CalendarWrapper* SvNFLanguageData::GetCalendar() const { return xCalendar.get(); } + +const ::utl::TransliterationWrapper* SvNFLanguageData::GetTransliteration() const +{ + return xTransliteration.get(); } +const LanguageTag& SvNFLanguageData::GetLanguageTag() const { return aLanguageTag; } -void SvNumberFormatter::ChangeIntl(LanguageType eLnge) +const ImpSvNumberformatScan* SvNFLanguageData::GetFormatScanner() const { return pFormatScanner.get(); } + +const OUString& SvNFLanguageData::GetNumDecimalSep() const { return aDecimalSep; } + +const OUString& SvNFLanguageData::GetNumDecimalSepAlt() const { return aDecimalSepAlt; } + +const OUString& SvNFLanguageData::GetNumThousandSep() const { return aThousandSep; } + +const OUString& SvNFLanguageData::GetDateSep() const { return aDateSep; } + +bool SvNFLanguageData::IsDecimalSep( std::u16string_view rStr ) const +{ + if (rStr == GetNumDecimalSep()) + return true; + if (GetNumDecimalSepAlt().isEmpty()) + return false; + return rStr == GetNumDecimalSepAlt(); +} + +OUString SvNFLanguageData::GetLangDecimalSep( LanguageType nLang ) const +{ + if (nLang == ActLnge) + { + return GetNumDecimalSep(); + } + OUString aRet; + LanguageType eSaveLang = xLocaleData.getCurrentLanguage(); + if (nLang == eSaveLang) + { + aRet = xLocaleData->getNumDecimalSep(); + } + else + { + LanguageTag aSaveLocale( xLocaleData->getLanguageTag() ); + const_cast<SvNFLanguageData*>(this)->xLocaleData.changeLocale( LanguageTag( nLang)); + aRet = xLocaleData->getNumDecimalSep(); + const_cast<SvNFLanguageData*>(this)->xLocaleData.changeLocale( aSaveLocale ); + } + return aRet; +} + +void SvNFLanguageData::ChangeIntl(LanguageType eLnge) { - ::osl::MutexGuard aGuard( GetInstanceMutex() ); if (ActLnge == eLnge) return; ActLnge = eLnge; - maLanguageTag.reset( eLnge ); - xCharClass.changeLocale( m_xContext, maLanguageTag ); - xLocaleData.changeLocale( maLanguageTag ); - xCalendar.changeLocale( maLanguageTag.getLocale() ); + aLanguageTag.reset( eLnge ); + xCharClass.changeLocale( xContext, aLanguageTag ); + xLocaleData.changeLocale( aLanguageTag ); + xCalendar.changeLocale( aLanguageTag.getLocale() ); xTransliteration.changeLocale( eLnge ); // cached locale data items, initialize BEFORE calling ChangeIntl below @@ -345,6 +408,43 @@ void SvNumberFormatter::ChangeIntl(LanguageType eLnge) pStringScanner->ChangeIntl(); } +SvNumberFormatter::SvNumberFormatter( const Reference< XComponentContext >& rxContext, + LanguageType eLang ) + : m_xContext( rxContext ) + , IniLnge(eLang != LANGUAGE_DONTKNOW ? eLang : UNKNOWN_SUBSTITUTE) + , m_aRWPolicy(SvNFEngine::GetRWPolicy(m_aFormatData)) + , m_aCurrentLanguage(rxContext, IniLnge, *this) +{ + xNatNum.init( m_xContext ); + + // 0 .. 999 for initialized language formats + m_aFormatData.ImpGenerateFormats(m_aCurrentLanguage, GetNatNum(), 0, false); + + ::osl::MutexGuard aGuard( GetGlobalMutex() ); + GetFormatterRegistry().Insert( this ); +} + +SvNumberFormatter::~SvNumberFormatter() +{ + { + ::osl::MutexGuard aGuard( GetGlobalMutex() ); + pFormatterRegistry->Remove( this ); + if ( !pFormatterRegistry->Count() ) + { + delete pFormatterRegistry; + pFormatterRegistry = nullptr; + } + } + + m_aFormatData.aFTable.clear(); + ClearMergeTable(); +} + +void SvNumberFormatter::ChangeIntl(LanguageType eLnge) +{ + ::osl::MutexGuard aGuard( GetInstanceMutex() ); + SvNFEngine::ChangeIntl(m_aCurrentLanguage, eLnge); +} // static ::osl::Mutex& SvNumberFormatter::GetGlobalMutex() @@ -393,44 +493,53 @@ void SvNumberFormatter::ChangeNullDate(sal_uInt16 nDay, sal_Int16 nYear) { ::osl::MutexGuard aGuard( GetInstanceMutex() ); - pFormatScanner->ChangeNullDate(nDay, nMonth, nYear); - pStringScanner->ChangeNullDate(nDay, nMonth, nYear); + SvNFEngine::ChangeNullDate(m_aCurrentLanguage, nDay, nMonth, nYear); +} + +const Date& SvNFLanguageData::GetNullDate() const +{ + return pFormatScanner->GetNullDate(); +} + +void SvNFLanguageData::ChangeStandardPrec(short nPrec) +{ + pFormatScanner->ChangeStandardPrec(nPrec); } const Date& SvNumberFormatter::GetNullDate() const { ::osl::MutexGuard aGuard( GetInstanceMutex() ); - return pFormatScanner->GetNullDate(); + return m_aCurrentLanguage.GetNullDate(); } void SvNumberFormatter::ChangeStandardPrec(short nPrec) { ::osl::MutexGuard aGuard( GetInstanceMutex() ); - pFormatScanner->ChangeStandardPrec(nPrec); + m_aCurrentLanguage.ChangeStandardPrec(nPrec); } void SvNumberFormatter::SetNoZero(bool bNZ) { ::osl::MutexGuard aGuard( GetInstanceMutex() ); - bNoZero = bNZ; + m_aFormatData.SetNoZero(bNZ); } sal_uInt16 SvNumberFormatter::GetStandardPrec() const { ::osl::MutexGuard aGuard( GetInstanceMutex() ); - return pFormatScanner->GetStandardPrec(); + return m_aCurrentLanguage.pFormatScanner->GetStandardPrec(); } bool SvNumberFormatter::GetNoZero() const { ::osl::MutexGuard aGuard( GetInstanceMutex() ); - return bNoZero; + return m_aFormatData.GetNoZero(); } void SvNumberFormatter::ReplaceSystemCL( LanguageType eOldLanguage ) { - sal_uInt32 nCLOffset = ImpGetCLOffset( LANGUAGE_SYSTEM ); - if ( nCLOffset > MaxCLOffset ) + sal_uInt32 nCLOffset = m_aFormatData.ImpGetCLOffset( LANGUAGE_SYSTEM ); + if ( nCLOffset > m_aFormatData.MaxCLOffset ) { return ; // no SYSTEM entries to replace } @@ -439,30 +548,30 @@ void SvNumberFormatter::ReplaceSystemCL( LanguageType eOldLanguage ) sal_uInt32 nKey; // remove old builtin formats - auto it = aFTable.find( nCLOffset ); - while ( it != aFTable.end() && (nKey = it->first) >= nCLOffset && nKey <= nMaxBuiltin ) + auto it = m_aFormatData.aFTable.find( nCLOffset ); + while ( it != m_aFormatData.aFTable.end() && (nKey = it->first) >= nCLOffset && nKey <= nMaxBuiltin ) { - it = aFTable.erase(it); + it = m_aFormatData.aFTable.erase(it); } // move additional and user defined to temporary table SvNumberFormatTable aOldTable; - while ( it != aFTable.end() && (nKey = it->first) >= nCLOffset && nKey < nNextCL ) + while ( it != m_aFormatData.aFTable.end() && (nKey = it->first) >= nCLOffset && nKey < nNextCL ) { aOldTable[ nKey ] = it->second.release(); - it = aFTable.erase(it); + it = m_aFormatData.aFTable.erase(it); } // generate new old builtin formats - // reset ActLnge otherwise ChangeIntl() wouldn't switch if already LANGUAGE_SYSTEM - ActLnge = LANGUAGE_DONTKNOW; + // reset m_aCurrentLanguage.ActLnge otherwise ChangeIntl() wouldn't switch if already LANGUAGE_SYSTEM + m_aCurrentLanguage.ActLnge = LANGUAGE_DONTKNOW; ChangeIntl( LANGUAGE_SYSTEM ); - ImpGenerateFormats( nCLOffset, true ); + m_aFormatData.ImpGenerateFormats(m_aCurrentLanguage, GetNatNum(), nCLOffset, true); // convert additional and user defined from old system to new system - SvNumberformat* pStdFormat = GetFormatEntry( nCLOffset + ZF_STANDARD ); + SvNumberformat* pStdFormat = m_aFormatData.GetFormatEntry( nCLOffset + ZF_STANDARD ); sal_uInt32 nLastKey = nMaxBuiltin; - pFormatScanner->SetConvertMode( eOldLanguage, LANGUAGE_SYSTEM, true , true); + m_aCurrentLanguage.pFormatScanner->SetConvertMode( eOldLanguage, LANGUAGE_SYSTEM, true , true); while ( !aOldTable.empty() ) { nKey = aOldTable.begin()->first; @@ -480,8 +589,8 @@ void SvNumberFormatter::ReplaceSystemCL( LanguageType eOldLanguage ) LanguageType eLge = eOldLanguage; // ConvertMode changes this bool bCheck = false; sal_Int32 nCheckPos = -1; - std::unique_ptr<SvNumberformat> pNewEntry(new SvNumberformat( aString, pFormatScanner.get(), - pStringScanner.get(), nCheckPos, eLge )); + std::unique_ptr<SvNumberformat> pNewEntry(new SvNumberformat( aString, m_aCurrentLanguage.pFormatScanner.get(), + m_aCurrentLanguage.pStringScanner.get(), GetNatNum(), nCheckPos, eLge )); if ( nCheckPos == 0 ) { SvNumFormatType eCheckType = pNewEntry->GetType(); @@ -494,14 +603,14 @@ void SvNumberFormatter::ReplaceSystemCL( LanguageType eOldLanguage ) pNewEntry->SetType( SvNumFormatType::DEFINED ); } - if ( aFTable.emplace( nKey, std::move(pNewEntry) ).second ) + if ( m_aFormatData.aFTable.emplace( nKey, std::move(pNewEntry) ).second ) { bCheck = true; } } DBG_ASSERT( bCheck, "SvNumberFormatter::ReplaceSystemCL: couldn't convert" ); } - pFormatScanner->SetConvertMode(false); + m_aCurrentLanguage.pFormatScanner->SetConvertMode(false); pStdFormat->SetLastInsertKey( sal_uInt16(nLastKey - nCLOffset), SvNumberformat::FormatterPrivateAccess() ); // append new system additional formats @@ -514,72 +623,43 @@ const css::uno::Reference<css::uno::XComponentContext>& SvNumberFormatter::GetCo return m_xContext; } -const ImpSvNumberformatScan* SvNumberFormatter::GetFormatScanner() const { return pFormatScanner.get(); } - -const LanguageTag& SvNumberFormatter::GetLanguageTag() const { return maLanguageTag; } - -const ::utl::TransliterationWrapper* SvNumberFormatter::GetTransliteration() const -{ - return xTransliteration.get(); -} - -const CharClass* SvNumberFormatter::GetCharClass() const { return xCharClass.get(); } - -const LocaleDataWrapper* SvNumberFormatter::GetLocaleData() const { return xLocaleData.get(); } - -CalendarWrapper* SvNumberFormatter::GetCalendar() const { return xCalendar.get(); } - const NativeNumberWrapper* SvNumberFormatter::GetNatNum() const { return xNatNum.get(); } -const OUString& SvNumberFormatter::GetNumDecimalSep() const { return aDecimalSep; } - -const OUString& SvNumberFormatter::GetNumDecimalSepAlt() const { return aDecimalSepAlt; } - -const OUString& SvNumberFormatter::GetNumThousandSep() const { return aThousandSep; } - -const OUString& SvNumberFormatter::GetDateSep() const { return aDateSep; } - -bool SvNumberFormatter::IsDecimalSep( std::u16string_view rStr ) const +bool SvNFFormatData::IsTextFormat(sal_uInt32 F_Index) const { - if (rStr == GetNumDecimalSep()) - return true; - if (GetNumDecimalSepAlt().isEmpty()) - return false; - return rStr == GetNumDecimalSepAlt(); + const SvNumberformat* pFormat = GetFormatEntry(F_Index); + return pFormat && pFormat->IsTextFormat(); } bool SvNumberFormatter::IsTextFormat(sal_uInt32 F_Index) const { ::osl::MutexGuard aGuard( GetInstanceMutex() ); - const SvNumberformat* pFormat = GetFormatEntry(F_Index); - - return pFormat && pFormat->IsTextFormat(); + return m_aFormatData.IsTextFormat(F_Index); } -bool SvNumberFormatter::PutEntry(OUString& rString, +bool SvNFFormatData::PutEntry(SvNFLanguageData& rCurrentLanguage, + const NativeNumberWrapper* pNatNum, + OUString& rString, sal_Int32& nCheckPos, SvNumFormatType& nType, sal_uInt32& nKey, // format key LanguageType eLnge, bool bReplaceBooleanEquivalent) { - ::osl::MutexGuard aGuard( GetInstanceMutex() ); nKey = 0; if (rString.isEmpty()) // empty string { nCheckPos = 1; // -> Error return false; } - if (eLnge == LANGUAGE_DONTKNOW) - { - eLnge = IniLnge; - } - ChangeIntl(eLnge); // change locale if necessary + eLnge = rCurrentLanguage.ImpResolveLanguage(eLnge); + rCurrentLanguage.ChangeIntl(eLnge); // change locale if necessary LanguageType eLge = eLnge; // non-const for ConvertMode bool bCheck = false; std::unique_ptr<SvNumberformat> p_Entry(new SvNumberformat(rString, - pFormatScanner.get(), - pStringScanner.get(), + rCurrentLanguage.pFormatScanner.get(), + rCurrentLanguage.pStringScanner.get(), + pNatNum, nCheckPos, eLge, bReplaceBooleanEquivalent)); @@ -598,7 +678,7 @@ bool SvNumberFormatter::PutEntry(OUString& rString, nType = SvNumFormatType::DEFINED; } - sal_uInt32 CLOffset = ImpGenerateCL(eLge); // create new standard formats if necessary + sal_uInt32 CLOffset = ImpGenerateCL(rCurrentLanguage, pNatNum, eLge); // create new standard formats if necessary nKey = ImpIsEntry(p_Entry->GetFormatstring(),CLOffset, eLge); if (nKey == NUMBERFORMAT_ENTRY_NOT_FOUND) // only in not yet present @@ -624,6 +704,17 @@ bool SvNumberFormatter::PutEntry(OUString& rString, return bCheck; } +bool SvNumberFormatter::PutEntry(OUString& rString, + sal_Int32& nCheckPos, + SvNumFormatType& nType, + sal_uInt32& nKey, // format key + LanguageType eLnge, + bool bReplaceBooleanEquivalent) +{ + ::osl::MutexGuard aGuard( GetInstanceMutex() ); + return m_aFormatData.PutEntry(m_aCurrentLanguage, GetNatNum(), rString, nCheckPos, nType, nKey, eLnge, bReplaceBooleanEquivalent); +} + bool SvNumberFormatter::PutandConvertEntry(OUString& rString, sal_Int32& nCheckPos, SvNumFormatType& nType, @@ -639,23 +730,23 @@ bool SvNumberFormatter::PutandConvertEntry(OUString& rString, { eNewLnge = IniLnge; } - pFormatScanner->SetConvertMode(eLnge, eNewLnge, false, bConvertDateOrder); + m_aCurrentLanguage.pFormatScanner->SetConvertMode(eLnge, eNewLnge, false, bConvertDateOrder); bRes = PutEntry(rString, nCheckPos, nType, nKey, eLnge, bReplaceBooleanEquivalent); - pFormatScanner->SetConvertMode(false); + m_aCurrentLanguage.pFormatScanner->SetConvertMode(false); if (bReplaceBooleanEquivalent && nCheckPos == 0 && nType == SvNumFormatType::DEFINED && nKey != NUMBERFORMAT_ENTRY_NOT_FOUND) { // The boolean string formats are always "user defined" without any // other type. - const SvNumberformat* pEntry = GetFormatEntry(nKey); + const SvNumberformat* pEntry = m_aFormatData.GetFormatEntry(nKey); if (pEntry && pEntry->GetType() == SvNumFormatType::DEFINED) { // Replace boolean string format with Boolean in target locale, in // case the source strings are the target locale's. const OUString aSaveString = rString; ChangeIntl(eNewLnge); - if (pFormatScanner->ReplaceBooleanEquivalent( rString)) + if (m_aCurrentLanguage.pFormatScanner->ReplaceBooleanEquivalent( rString)) { const sal_Int32 nSaveCheckPos = nCheckPos; const SvNumFormatType nSaveType = nType; @@ -693,9 +784,9 @@ bool SvNumberFormatter::PutandConvertEntrySystem(OUString& rString, { eNewLnge = IniLnge; } - pFormatScanner->SetConvertMode(eLnge, eNewLnge, true, true); + m_aCurrentLanguage.pFormatScanner->SetConvertMode(eLnge, eNewLnge, true, true); bRes = PutEntry(rString, nCheckPos, nType, nKey, eLnge); - pFormatScanner->SetConvertMode(false); + m_aCurrentLanguage.pFormatScanner->SetConvertMode(false); return bRes; } @@ -778,7 +869,7 @@ sal_uInt32 SvNumberFormatter::GetIndexPuttingAndConverting( OUString & rString, void SvNumberFormatter::DeleteEntry(sal_uInt32 nKey) { ::osl::MutexGuard aGuard( GetInstanceMutex() ); - aFTable.erase(nKey); + m_aFormatData.aFTable.erase(nKey); } void SvNumberFormatter::GetUsedLanguages( std::vector<LanguageType>& rList ) @@ -787,9 +878,9 @@ void SvNumberFormatter::GetUsedLanguages( std::vector<LanguageType>& rList ) rList.clear(); sal_uInt32 nOffset = 0; - while (nOffset <= MaxCLOffset) + while (nOffset <= m_aFormatData.MaxCLOffset) { - SvNumberformat* pFormat = GetFormatEntry(nOffset); + SvNumberformat* pFormat = m_aFormatData.GetFormatEntry(nOffset); if (pFormat) { rList.push_back( pFormat->GetLanguage() ); @@ -804,7 +895,7 @@ void SvNumberFormatter::FillKeywordTable( NfKeywordTable& rKeywords, { ::osl::MutexGuard aGuard( GetInstanceMutex() ); ChangeIntl( eLang ); - const NfKeywordTable & rTable = pFormatScanner->GetKeywords(); + const NfKeywordTable & rTable = m_aCurrentLanguage.pFormatScanner->GetKeywords(); for ( sal_uInt16 i = 0; i < NF_KEYWORD_ENTRIES_COUNT; ++i ) { rKeywords[i] = rTable[i]; @@ -867,15 +958,15 @@ void SvNumberFormatter::FillKeywordTableForExcel( NfKeywordTable& rKeywords ) } -static OUString lcl_buildBooleanStringFormat( SvNumberformat* pEntry ) +static OUString lcl_buildBooleanStringFormat( SvNumberformat* pEntry, const NativeNumberWrapper* pNatNum ) { // Build Boolean number format, which needs non-zero and zero subformat // codes with TRUE and FALSE strings. const Color* pColor = nullptr; OUString aFormatStr, aTemp; - pEntry->GetOutputString( 1.0, aTemp, &pColor ); + pEntry->GetOutputString( 1.0, aTemp, &pColor, pNatNum ); aFormatStr += "\"" + aTemp + "\";\"" + aTemp + "\";\""; - pEntry->GetOutputString( 0.0, aTemp, &pColor ); + pEntry->GetOutputString( 0.0, aTemp, &pColor, pNatNum ); aFormatStr += aTemp + "\""; return aFormatStr; } @@ -896,7 +987,7 @@ OUString SvNumberFormatter::GetFormatStringForExcel( sal_uInt32 nKey, const NfKe // locales. You can't have both. We could force to English for all // locales like below, but Excel would display English strings then // even for the system locale matching this locale. YMMV. - aFormatStr = lcl_buildBooleanStringFormat( const_cast< SvNumberformat* >(pEntry)); + aFormatStr = lcl_buildBooleanStringFormat( const_cast< SvNumberformat* >(pEntry), GetNatNum() ); } else { @@ -932,15 +1023,15 @@ OUString SvNumberFormatter::GetFormatStringForExcel( sal_uInt32 nKey, const NfKe // >"VRAI";"VRAI";"FAUX"< recognized as real boolean and // properly converted. Then written as // >"TRUE";"TRUE";"FALSE"< - aFormatStr = lcl_buildBooleanStringFormat( const_cast< SvNumberformat* >(pEntry)); + aFormatStr = lcl_buildBooleanStringFormat( const_cast< SvNumberformat* >(pEntry), GetNatNum() ); } else { - // GetLocaleData() returns the current locale's data, so switch + // m_aCurrentLanguage.GetLocaleData() returns the current locale's data, so switch // before (which doesn't do anything if it was the same locale // already). rTempFormatter.ChangeIntl( LANGUAGE_ENGLISH_US); - aFormatStr = pEntry->GetMappedFormatstring( rKeywords, *rTempFormatter.GetLocaleData(), nLang, + aFormatStr = pEntry->GetMappedFormatstring( rKeywords, *rTempFormatter.m_aCurrentLanguage.GetLocaleData(), nLang, bSystemLanguage); } } @@ -961,7 +1052,7 @@ OUString SvNumberFormatter::GetKeyword( LanguageType eLnge, sal_uInt16 nIndex ) { ::osl::MutexGuard aGuard( GetInstanceMutex() ); ChangeIntl(eLnge); - const NfKeywordTable & rTable = pFormatScanner->GetKeywords(); + const NfKeywordTable & rTable = m_aCurrentLanguage.pFormatScanner->GetKeywords(); if ( nIndex < NF_KEYWORD_ENTRIES_COUNT ) { return rTable[nIndex]; @@ -975,11 +1066,19 @@ OUString SvNumberFormatter::GetStandardName( LanguageType eLnge ) { ::osl::MutexGuard aGuard( GetInstanceMutex() ); ChangeIntl( eLnge ); - return pFormatScanner->GetStandardName(); + return m_aCurrentLanguage.pFormatScanner->GetStandardName(); +} + +SvNFFormatData::SvNFFormatData() + : MaxCLOffset(0) + , nDefaultSystemCurrencyFormat(NUMBERFORMAT_ENTRY_NOT_FOUND) + , bNoZero(false) +{ } +SvNFFormatData::~SvNFFormatData() = default; -sal_uInt32 SvNumberFormatter::ImpGetCLOffset(LanguageType eLnge) const +sal_uInt32 SvNFFormatData::ImpGetCLOffset(LanguageType eLnge) const { sal_uInt32 nOffset = 0; while (nOffset <= MaxCLOffset) @@ -994,9 +1093,9 @@ sal_uInt32 SvNumberFormatter::ImpGetCLOffset(LanguageType eLnge) const return nOffset; } -sal_uInt32 SvNumberFormatter::ImpIsEntry(std::u16string_view rString, - sal_uInt32 nCLOffset, - LanguageType eLnge) const +sal_uInt32 SvNFFormatData::ImpIsEntry(std::u16string_view rString, + sal_uInt32 nCLOffset, + LanguageType eLnge) const { sal_uInt32 res = NUMBERFORMAT_ENTRY_NOT_FOUND; auto it = aFTable.find( nCLOffset); @@ -1015,6 +1114,13 @@ sal_uInt32 SvNumberFormatter::ImpIsEntry(std::u16string_view rString, return res; } +sal_uInt32 SvNumberFormatter::ImpIsEntry(std::u16string_view rString, + sal_uInt32 nCLOffset, + LanguageType eLnge) const +{ + return m_aFormatData.ImpIsEntry(rString, nCLOffset, eLnge); +} + SvNumberFormatTable& SvNumberFormatter::GetFirstEntryTable( SvNumFormatType& eType, sal_uInt32& FIndex, @@ -1028,7 +1134,7 @@ SvNumberFormatTable& SvNumberFormatter::GetFirstEntryTable( } else { - SvNumberformat* pFormat = GetFormatEntry(FIndex); + SvNumberformat* pFormat = m_aFormatData.GetFormatEntry(FIndex); if (!pFormat) { rLnge = IniLnge; @@ -1059,23 +1165,23 @@ SvNumberFormatTable& SvNumberFormatter::GetFirstEntryTable( return GetEntryTable(eTypetmp, FIndex, rLnge); } -sal_uInt32 SvNumberFormatter::ImpGenerateCL( LanguageType eLnge ) +sal_uInt32 SvNFFormatData::ImpGenerateCL(SvNFLanguageData& rCurrentLanguage, const NativeNumberWrapper* pNatNum, LanguageType eLnge) { - ChangeIntl(eLnge); - sal_uInt32 CLOffset = ImpGetCLOffset(ActLnge); + rCurrentLanguage.ChangeIntl(eLnge); + sal_uInt32 CLOffset = ImpGetCLOffset(rCurrentLanguage.ActLnge); if (CLOffset > MaxCLOffset) { // new CL combination if (LocaleDataWrapper::areChecksEnabled()) { - const LanguageTag& rLoadedLocale = xLocaleData->getLoadedLanguageTag(); - if ( !rLoadedLocale.equals( maLanguageTag ) ) + const LanguageTag& rLoadedLocale = rCurrentLanguage.xLocaleData->getLoadedLanguageTag(); + if ( !rLoadedLocale.equals( rCurrentLanguage.aLanguageTag ) ) { - LocaleDataWrapper::outputCheckMessage( xLocaleData->appendLocaleInfo( u"SvNumberFormatter::ImpGenerateCL: locales don't match:" )); + LocaleDataWrapper::outputCheckMessage( rCurrentLanguage.xLocaleData->appendLocaleInfo( u"SvNumberFormatter::ImpGenerateCL: locales don't match:" )); } // test XML locale data FormatElement entries { - uno::Sequence< i18n::FormatElement > xSeq = xLocaleData->getAllFormats(); + uno::Sequence< i18n::FormatElement > xSeq = rCurrentLanguage.xLocaleData->getAllFormats(); // A test for completeness of formatindex="0" ... // formatindex="47" is not needed here since it is done in // ImpGenerateFormats(). @@ -1102,14 +1208,14 @@ sal_uInt32 SvNumberFormatter::ImpGenerateCL( LanguageType eLnge ) + xSeq[j].formatKey + ") " + aDupes; - LocaleDataWrapper::outputCheckMessage( xLocaleData->appendLocaleInfo( aMsg )); + LocaleDataWrapper::outputCheckMessage( rCurrentLanguage.xLocaleData->appendLocaleInfo( aMsg )); } } } } MaxCLOffset += SV_COUNTRY_LANGUAGE_OFFSET; - ImpGenerateFormats( MaxCLOffset, false/*bNoAdditionalFormats*/ ); + ImpGenerateFormats(rCurrentLanguage, pNatNum, MaxCLOffset, false/*bNoAdditionalFormats*/ ); CLOffset = MaxCLOffset; } return CLOffset; @@ -1120,8 +1226,8 @@ SvNumberFormatTable& SvNumberFormatter::ChangeCL(SvNumFormatType eType, LanguageType eLnge) { ::osl::MutexGuard aGuard( GetInstanceMutex() ); - ImpGenerateCL(eLnge); - return GetEntryTable(eType, FIndex, ActLnge); + m_aFormatData.ImpGenerateCL(m_aCurrentLanguage, GetNatNum(), eLnge); + return GetEntryTable(eType, FIndex, m_aCurrentLanguage.ActLnge); } SvNumberFormatTable& SvNumberFormatter::GetEntryTable( @@ -1139,17 +1245,17 @@ SvNumberFormatTable& SvNumberFormatter::GetEntryTable( pFormatTable.reset( new SvNumberFormatTable ); } ChangeIntl(eLnge); - sal_uInt32 CLOffset = ImpGetCLOffset(ActLnge); + sal_uInt32 CLOffset = m_aFormatData.ImpGetCLOffset(m_aCurrentLanguage.ActLnge); // Might generate and insert a default format for the given type // (e.g. currency) => has to be done before collecting formats. - sal_uInt32 nDefaultIndex = GetStandardFormat( eType, ActLnge ); + sal_uInt32 nDefaultIndex = GetStandardFormat( eType, m_aCurrentLanguage.ActLnge ); - auto it = aFTable.find( CLOffset); + auto it = m_aFormatData.aFTable.find( CLOffset); if (eType == SvNumFormatType::ALL) { - while (it != aFTable.end() && it->second->GetLanguage() == ActLnge) + while (it != m_aFormatData.aFTable.end() && it->second->GetLanguage() == m_aCurrentLanguage.ActLnge) { // copy all entries to output table (*pFormatTable)[ it->first ] = it->second.get(); ++it; @@ -1157,7 +1263,7 @@ SvNumberFormatTable& SvNumberFormatter::GetEntryTable( } else { - while (it != aFTable.end() && it->second->GetLanguage() == ActLnge) + while (it != m_aFormatData.aFTable.end() && it->second->GetLanguage() == m_aCurrentLanguage.ActLnge) { // copy entries of queried type to output table if ((it->second->GetType()) & eType) (*pFormatTable)[ it->first ] = it->second.get(); @@ -1167,8 +1273,8 @@ SvNumberFormatTable& SvNumberFormatter::GetEntryTable( if ( !pFormatTable->empty() ) { // select default if queried format doesn't exist or queried type or // language differ from existing format - SvNumberformat* pEntry = GetFormatEntry(FIndex); - if ( !pEntry || !(pEntry->GetType() & eType) || pEntry->GetLanguage() != ActLnge ) + SvNumberformat* pEntry = m_aFormatData.GetFormatEntry(FIndex); + if ( !pEntry || !(pEntry->GetType() & eType) || pEntry->GetLanguage() != m_aCurrentLanguage.ActLnge ) { FIndex = nDefaultIndex; } @@ -1176,20 +1282,58 @@ SvNumberFormatTable& SvNumberFormatter::GetEntryTable( return *pFormatTable; } -bool SvNumberFormatter::IsNumberFormat(const OUString& sString, - sal_uInt32& F_Index, - double& fOutNumber, - SvNumInputOptions eInputOptions) +namespace { + +const SvNumberformat* ImpSubstituteEntry(SvNFLanguageData& rCurrentLanguage, const SvNFFormatData& rFormatData, + const NativeNumberWrapper* pNatNum, const SvNFEngine::Accessor& rFuncs, + const SvNumberformat* pFormat, sal_uInt32* o_pRealKey) { - ::osl::MutexGuard aGuard( GetInstanceMutex() ); + if (!pFormat || !pFormat->IsSubstituted()) + return pFormat; + + // XXX NOTE: substitution can not be done in GetFormatEntry() as otherwise + // to be substituted formats would "vanish", i.e. from the number formatter + // dialog or when exporting to Excel. + + sal_uInt32 nKey; + if (pFormat->IsSystemTimeFormat()) + { + /* TODO: should we have NF_TIME_SYSTEM for consistency? */ + nKey = SvNFEngine::GetStandardFormat(rCurrentLanguage, rFormatData, pNatNum, rFuncs, + SvNumFormatType::TIME, LANGUAGE_SYSTEM); + } + else if (pFormat->IsSystemLongDateFormat()) + /* TODO: either that above, or have a long option for GetStandardFormat() */ + { + nKey = SvNFEngine::GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, + NF_DATE_SYSTEM_LONG, LANGUAGE_SYSTEM); + } + else + return pFormat; + if (o_pRealKey) + *o_pRealKey = nKey; + return rFormatData.GetFormatEntry(nKey); +} + +} + +bool SvNFEngine::IsNumberFormat(SvNFLanguageData& rCurrentLanguage, + const SvNFFormatData& rFormatData, + const NativeNumberWrapper* pNatNum, const Accessor& rFuncs, + const OUString& sString, + sal_uInt32& F_Index, + double& fOutNumber, + SvNumInputOptions eInputOptions) +{ SvNumFormatType FType; // For the 0 General format directly use the init/system locale and avoid // all overhead that is associated with a format passed to the scanner. - const SvNumberformat* pFormat = (F_Index == 0 ? nullptr : ImpSubstituteEntry( GetFormatEntry(F_Index))); + const SvNumberformat* pFormat = (F_Index == 0 ? nullptr : + ::ImpSubstituteEntry(rCurrentLanguage, rFormatData, pNatNum, rFuncs, rFormatData.GetFormatEntry(F_Index), nullptr)); if (!pFormat) { - ChangeIntl(IniLnge); + rCurrentLanguage.ChangeIntl(rCurrentLanguage.IniLnge); FType = SvNumFormatType::NUMBER; } else @@ -1199,7 +1343,7 @@ bool SvNumberFormatter::IsNumberFormat(const OUString& sString, { FType = SvNumFormatType::DEFINED; } - ChangeIntl(pFormat->GetLanguage()); + rCurrentLanguage.ChangeIntl(pFormat->GetLanguage()); // Avoid scanner overhead with the General format of any locale. // These are never substituted above so safe to ignore. if ((F_Index % SV_COUNTRY_LANGUAGE_OFFSET) == 0) @@ -1217,73 +1361,85 @@ bool SvNumberFormatter::IsNumberFormat(const OUString& sString, } else { - res = pStringScanner->IsNumberFormat(sString, RType, fOutNumber, pFormat, eInputOptions); + res = rCurrentLanguage.pStringScanner->IsNumberFormat(sString, RType, fOutNumber, pFormat, pNatNum, eInputOptions); } - if (res && !IsCompatible(FType, RType)) // non-matching type + if (res && !SvNumberFormatter::IsCompatible(FType, RType)) // non-matching type { switch ( RType ) { case SvNumFormatType::DATE : // Preserve ISO 8601 input. - if (pStringScanner->CanForceToIso8601( DateOrder::Invalid)) + if (rCurrentLanguage.pStringScanner->CanForceToIso8601( DateOrder::Invalid)) { - F_Index = GetFormatIndex( NF_DATE_DIN_YYYYMMDD, ActLnge ); + F_Index = GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_DATE_DIN_YYYYMMDD, rCurrentLanguage.ActLnge ); } else { - F_Index = GetStandardFormat( RType, ActLnge ); + F_Index = GetStandardFormat(rCurrentLanguage, rFormatData, pNatNum, rFuncs, RType, rCurrentLanguage.ActLnge); } break; case SvNumFormatType::TIME : - if ( pStringScanner->GetDecPos() ) + if ( rCurrentLanguage.pStringScanner->GetDecPos() ) { // 100th seconds - if ( pStringScanner->GetNumericsCount() > 3 || fOutNumber < 0.0 ) + if ( rCurrentLanguage.pStringScanner->GetNumericsCount() > 3 || fOutNumber < 0.0 ) { - F_Index = GetFormatIndex( NF_TIME_HH_MMSS00, ActLnge ); + F_Index = GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_TIME_HH_MMSS00, rCurrentLanguage.ActLnge); } else { - F_Index = GetFormatIndex( NF_TIME_MMSS00, ActLnge ); + F_Index = GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_TIME_MMSS00, rCurrentLanguage.ActLnge); } } else if ( fOutNumber >= 1.0 || fOutNumber < 0.0 ) { - F_Index = GetFormatIndex( NF_TIME_HH_MMSS, ActLnge ); + F_Index = GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_TIME_HH_MMSS, rCurrentLanguage.ActLnge); } else { - F_Index = GetStandardFormat( RType, ActLnge ); + F_Index = GetStandardFormat(rCurrentLanguage, rFormatData, pNatNum, rFuncs, RType, rCurrentLanguage.ActLnge ); } break; case SvNumFormatType::DATETIME : // Preserve ISO 8601 input. - if (pStringScanner->HasIso8601Tsep()) + if (rCurrentLanguage.pStringScanner->HasIso8601Tsep()) { - if (pStringScanner->GetDecPos()) - F_Index = GetFormatIndex( NF_DATETIME_ISO_YYYYMMDDTHHMMSS000, ActLnge ); + if (rCurrentLanguage.pStringScanner->GetDecPos()) + F_Index = GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_DATETIME_ISO_YYYYMMDDTHHMMSS000, rCurrentLanguage.ActLnge); else - F_Index = GetFormatIndex( NF_DATETIME_ISO_YYYYMMDDTHHMMSS, ActLnge ); + F_Index = GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_DATETIME_ISO_YYYYMMDDTHHMMSS, rCurrentLanguage.ActLnge); } - else if (pStringScanner->CanForceToIso8601( DateOrder::Invalid)) + else if (rCurrentLanguage.pStringScanner->CanForceToIso8601( DateOrder::Invalid)) { - if (pStringScanner->GetDecPos()) - F_Index = GetFormatIndex( NF_DATETIME_ISO_YYYYMMDD_HHMMSS000, ActLnge ); + if (rCurrentLanguage.pStringScanner->GetDecPos()) + F_Index = GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_DATETIME_ISO_YYYYMMDD_HHMMSS000, rCurrentLanguage.ActLnge); else - F_Index = GetFormatIndex( NF_DATETIME_ISO_YYYYMMDD_HHMMSS, ActLnge ); + F_Index = GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_DATETIME_ISO_YYYYMMDD_HHMMSS, rCurrentLanguage.ActLnge); } else { - F_Index = GetStandardFormat( RType, ActLnge ); + F_Index = GetStandardFormat(rCurrentLanguage, rFormatData, pNatNum, rFuncs, RType, rCurrentLanguage.ActLnge); } break; default: - F_Index = GetStandardFormat( RType, ActLnge ); + F_Index = GetStandardFormat(rCurrentLanguage, rFormatData, pNatNum, rFuncs, RType, rCurrentLanguage.ActLnge); } } return res; } +bool SvNumberFormatter::IsNumberFormat(const OUString& sString, + sal_uInt32& F_Index, + double& fOutNumber, + SvNumInputOptions eInputOptions) +{ + ::osl::MutexGuard aGuard( GetInstanceMutex() ); + + return SvNFEngine::IsNumberFormat(m_aCurrentLanguage, m_aFormatData, GetNatNum(), + m_aRWPolicy, sString, F_Index, fOutNumber, + eInputOptions); +} + LanguageType SvNumberFormatter::GetLanguage() const { return IniLnge; // immutable @@ -1354,10 +1510,8 @@ bool SvNumberFormatter::IsCompatible(SvNumFormatType eOldType, SvNumFormatType e } } - -sal_uInt32 SvNumberFormatter::ImpGetDefaultFormat( SvNumFormatType nType ) +static sal_uInt32 ImpGetSearchOffset(SvNumFormatType nType, sal_uInt32 CLOffset) { - sal_uInt32 CLOffset = ImpGetCLOffset( ActLnge ); sal_uInt32 nSearch; switch( nType ) { @@ -1382,8 +1536,146 @@ sal_uInt32 SvNumberFormatter::ImpGetDefaultFormat( SvNumFormatType nType ) default: nSearch = CLOffset + ZF_STANDARD; } + return nSearch; +} + +sal_uInt32 SvNFEngine::ImpGetDefaultFormat(const SvNFFormatData& rFormatData, + const SvNFEngine::CacheFormat& rFunc, + SvNumFormatType nType, sal_uInt32 CLOffset) +{ + sal_uInt32 nSearch = ImpGetSearchOffset(nType, CLOffset); + + std::pair<sal_uInt32, bool> aRes = rFormatData.ImpGetDefaultFormat(nType, nSearch, CLOffset); + const sal_uInt32 nDefaultFormat = aRes.first; + const bool bShouldCache = aRes.second; + if (bShouldCache) + rFunc(nSearch, nDefaultFormat); + return nDefaultFormat; +} + +namespace { + + sal_uInt32 ImpGetFormatIndex(NfIndexTableOffset nTabOff, sal_uInt32 nCLOffset) + { + if (nTabOff >= NF_INDEX_TABLE_ENTRIES) + return NUMBERFORMAT_ENTRY_NOT_FOUND; + + if (indexTable[nTabOff] == NUMBERFORMAT_ENTRY_NOT_FOUND) + return NUMBERFORMAT_ENTRY_NOT_FOUND; + + return nCLOffset + indexTable[nTabOff]; + } + + bool ImpIsSpecialStandardFormat(sal_uInt32 nFIndex, sal_uInt32 nCLOffset) + { + return + nFIndex == ImpGetFormatIndex( NF_TIME_MMSS00, nCLOffset ) || + nFIndex == ImpGetFormatIndex( NF_TIME_HH_MMSS00, nCLOffset ) || + nFIndex == ImpGetFormatIndex( NF_TIME_HH_MMSS, nCLOffset ) + ; + } + + bool ImpIsSpecialStandardFormat(SvNFLanguageData& rCurrentLanguage, + const NativeNumberWrapper* pNatNum, const SvNFEngine::Accessor& rFuncs, + sal_uInt32 nFIndex, LanguageType eLnge) + { + eLnge = rCurrentLanguage.ImpResolveLanguage(eLnge); + sal_uInt32 nCLOffset = rFuncs.mGetCLOffset(rCurrentLanguage, pNatNum, eLnge); // create new standard formats if necessary (and allowed) + return ::ImpIsSpecialStandardFormat(nFIndex, nCLOffset); + } +} + +sal_uInt32 SvNFEngine::ImpGetStandardFormat(SvNFLanguageData& rCurrentLanguage, + const SvNFFormatData& rFormatData, + const NativeNumberWrapper* pNatNum, + const SvNFEngine::Accessor& rFuncs, + SvNumFormatType eType, + sal_uInt32 CLOffset, + LanguageType eLnge) +{ + switch(eType) + { + case SvNumFormatType::CURRENCY: + return rFuncs.mGetDefaultCurrency(rCurrentLanguage, pNatNum, CLOffset, eLnge); + case SvNumFormatType::DURATION : + return ImpGetFormatIndex(NF_TIME_HH_MMSS, CLOffset); + case SvNumFormatType::DATE: + case SvNumFormatType::TIME: + case SvNumFormatType::DATETIME: + case SvNumFormatType::PERCENT: + case SvNumFormatType::SCIENTIFIC: + return ImpGetDefaultFormat(rFormatData, rFuncs.mCacheFormat, eType, CLOffset); + case SvNumFormatType::FRACTION: + return CLOffset + ZF_STANDARD_FRACTION; + case SvNumFormatType::LOGICAL: + return CLOffset + ZF_STANDARD_LOGICAL; + case SvNumFormatType::TEXT: + return CLOffset + ZF_STANDARD_TEXT; + case SvNumFormatType::ALL: + case SvNumFormatType::DEFINED: + case SvNumFormatType::NUMBER: + case SvNumFormatType::UNDEFINED: + default: + return CLOffset + ZF_STANDARD; + } +} + +sal_uInt32 SvNFEngine::GetStandardFormat(SvNFLanguageData& rCurrentLanguage, + const SvNFFormatData& rFormatData, + const NativeNumberWrapper* pNatNum, const Accessor& rFuncs, + SvNumFormatType eType, + LanguageType eLnge) +{ + eLnge = rCurrentLanguage.ImpResolveLanguage(eLnge); + + sal_uInt32 nCLOffset = rFuncs.mGetCLOffset(rCurrentLanguage, pNatNum, eLnge); // create new standard formats if necessary (and allowed) + + return ImpGetStandardFormat(rCurrentLanguage, rFormatData, pNatNum, rFuncs, eType, nCLOffset, eLnge); +} + +sal_uInt32 SvNumberFormatter::GetStandardFormat( SvNumFormatType eType, LanguageType eLnge ) +{ + ::osl::MutexGuard aGuard(GetInstanceMutex()); + return SvNFEngine::GetStandardFormat(m_aCurrentLanguage, m_aFormatData, GetNatNum(), m_aRWPolicy, eType, eLnge); +} + +bool SvNumberFormatter::ImpIsSpecialStandardFormat(sal_uInt32 nFIndex, LanguageType eLnge) +{ + ::osl::MutexGuard aGuard(GetInstanceMutex()); + return ::ImpIsSpecialStandardFormat(m_aCurrentLanguage, GetNatNum(), m_aRWPolicy, nFIndex, eLnge); +} + +sal_uInt32 SvNumberFormatter::ImpGetOrGenerateCLOffset(LanguageType eLnge) +{ + ::osl::MutexGuard aGuard(GetInstanceMutex()); + sal_uInt32 nCLOffset = m_aFormatData.ImpGetCLOffset(eLnge); + if (nCLOffset > m_aFormatData.MaxCLOffset) + { + nCLOffset = m_aFormatData.ImpGenerateCL(m_aCurrentLanguage, GetNatNum(), eLnge); // create new standard formats if necessary + } + return nCLOffset; +} + +sal_uInt32 SvNFEngine::GetStandardFormat(SvNFLanguageData& rCurrentLanguage, + const SvNFFormatData& rFormatData, + const NativeNumberWrapper* pNatNum, const Accessor& rFuncs, + sal_uInt32 nFIndex, SvNumFormatType eType, LanguageType eLnge) +{ + eLnge = rCurrentLanguage.ImpResolveLanguage(eLnge); + + sal_uInt32 nCLOffset = rFuncs.mGetCLOffset(rCurrentLanguage, pNatNum, eLnge); // create new standard formats if necessary (and allowed) + + if (::ImpIsSpecialStandardFormat(nFIndex, nCLOffset)) + return nFIndex; + + return ImpGetStandardFormat(rCurrentLanguage, rFormatData, pNatNum, rFuncs, eType, nCLOffset, eLnge); +} - DefaultFormatKeysMap::const_iterator it = aDefaultFormatKeys.find( nSearch); +//return a std::pair with the result and true/false if that result should be cached in aDefaultFormatKeys +std::pair<sal_uInt32, bool> SvNFFormatData::ImpGetDefaultFormat(SvNumFormatType nType, sal_uInt32 nSearch, sal_uInt32 CLOffset) const +{ + bool bShouldCache = false; + DefaultFormatKeysMap::const_iterator it = aDefaultFormatKeys.find(nSearch); sal_uInt32 nDefaultFormat = (it != aDefaultFormatKeys.end() ? it->second : NUMBERFORMAT_ENTRY_NOT_FOUND); if ( nDefaultFormat == NUMBERFORMAT_ENTRY_NOT_FOUND ) @@ -1429,71 +1721,25 @@ sal_uInt32 SvNumberFormatter::ImpGetDefaultFormat( SvNumFormatType nType ) nDefaultFormat = CLOffset + ZF_STANDARD; } } - aDefaultFormatKeys[ nSearch ] = nDefaultFormat; + bShouldCache = true; } - return nDefaultFormat; -} - - -sal_uInt32 SvNumberFormatter::GetStandardFormat( SvNumFormatType eType, LanguageType eLnge ) -{ - ::osl::MutexGuard aGuard( GetInstanceMutex() ); - if (eLnge == LANGUAGE_DONTKNOW) - { - eLnge = IniLnge; - } - sal_uInt32 CLOffset = ImpGenerateCL(eLnge); - switch(eType) - { - case SvNumFormatType::CURRENCY: - return ( eLnge == LANGUAGE_SYSTEM ) ? ImpGetDefaultSystemCurrencyFormat() : ImpGetDefaultCurrencyFormat(); - case SvNumFormatType::DURATION : - return GetFormatIndex( NF_TIME_HH_MMSS, eLnge); - case SvNumFormatType::DATE: - case SvNumFormatType::TIME: - case SvNumFormatType::DATETIME: - case SvNumFormatType::PERCENT: - case SvNumFormatType::SCIENTIFIC: - return ImpGetDefaultFormat( eType ); - case SvNumFormatType::FRACTION: - return CLOffset + ZF_STANDARD_FRACTION; - case SvNumFormatType::LOGICAL: - return CLOffset + ZF_STANDARD_LOGICAL; - case SvNumFormatType::TEXT: - return CLOffset + ZF_STANDARD_TEXT; - case SvNumFormatType::ALL: - case SvNumFormatType::DEFINED: - case SvNumFormatType::NUMBER: - case SvNumFormatType::UNDEFINED: - default: - return CLOffset + ZF_STANDARD; - } -} - -bool SvNumberFormatter::ImpIsSpecialStandardFormat( sal_uInt32 nFIndex, - LanguageType eLnge ) -{ - ::osl::MutexGuard aGuard( GetInstanceMutex() ); - return - nFIndex == GetFormatIndex( NF_TIME_MMSS00, eLnge ) || - nFIndex == GetFormatIndex( NF_TIME_HH_MMSS00, eLnge ) || - nFIndex == GetFormatIndex( NF_TIME_HH_MMSS, eLnge ) - ; + return std::make_pair(nDefaultFormat, bShouldCache); } sal_uInt32 SvNumberFormatter::GetStandardFormat( sal_uInt32 nFIndex, SvNumFormatType eType, LanguageType eLnge ) { - ::osl::MutexGuard aGuard( GetInstanceMutex() ); - if ( ImpIsSpecialStandardFormat( nFIndex, eLnge ) ) - return nFIndex; - else - return GetStandardFormat( eType, eLnge ); + ::osl::MutexGuard aGuard(GetInstanceMutex()); + + return SvNFEngine::GetStandardFormat(m_aCurrentLanguage, m_aFormatData, GetNatNum(), + m_aRWPolicy, nFIndex, eType, eLnge); } -sal_uInt32 SvNumberFormatter::GetTimeFormat( double fNumber, LanguageType eLnge, bool bForceDuration ) +sal_uInt32 SvNFEngine::GetTimeFormat(SvNFLanguageData& rCurrentLanguage, + const SvNFFormatData& rFormatData, + const NativeNumberWrapper* pNatNum, const Accessor& rFuncs, + double fNumber, LanguageType eLnge, bool bForceDuration) { - ::osl::MutexGuard aGuard( GetInstanceMutex() ); bool bSign; if ( fNumber < 0.0 ) { @@ -1506,16 +1752,44 @@ sal_uInt32 SvNumberFormatter::GetTimeFormat( double fNumber, LanguageType eLnge, if ( floor( fSeconds + 0.5 ) * 100 != floor( fSeconds * 100 + 0.5 ) ) { // with 100th seconds if ( bForceDuration || bSign || fSeconds >= 3600 ) - return GetFormatIndex( NF_TIME_HH_MMSS00, eLnge ); + return GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_TIME_HH_MMSS00, eLnge); else - return GetFormatIndex( NF_TIME_MMSS00, eLnge ); + return GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_TIME_MMSS00, eLnge); } else { if ( bForceDuration || bSign || fNumber >= 1.0 ) - return GetFormatIndex( NF_TIME_HH_MMSS, eLnge ); + return GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_TIME_HH_MMSS, eLnge); else - return GetStandardFormat( SvNumFormatType::TIME, eLnge ); + return GetStandardFormat(rCurrentLanguage, rFormatData, pNatNum, rFuncs, SvNumFormatType::TIME, eLnge); + } +} + +sal_uInt32 SvNumberFormatter::GetTimeFormat( double fNumber, LanguageType eLnge, bool bForceDuration ) +{ + ::osl::MutexGuard aGuard( GetInstanceMutex() ); + + return SvNFEngine::GetTimeFormat(m_aCurrentLanguage, m_aFormatData, GetNatNum(), m_aRWPolicy, + fNumber, eLnge, bForceDuration); +} + +sal_uInt32 SvNFEngine::GetStandardFormat(SvNFLanguageData& rCurrentLanguage, + const SvNFFormatData& rFormatData, + const NativeNumberWrapper* pNatNum, const Accessor& rFuncs, + double fNumber, sal_uInt32 nFIndex, + SvNumFormatType eType, LanguageType eLnge) +{ + if (::ImpIsSpecialStandardFormat(rCurrentLanguage, pNatNum, rFuncs, nFIndex, eLnge)) + return nFIndex; + + switch( eType ) + { + case SvNumFormatType::DURATION : + return GetTimeFormat(rCurrentLanguage, rFormatData, pNatNum, rFuncs, fNumber, eLnge, true); + case SvNumFormatType::TIME : + return GetTimeFormat(rCurrentLanguage, rFormatData, pNatNum, rFuncs, fNumber, eLnge, false); + default: + return GetStandardFormat(rCurrentLanguage, rFormatData, pNatNum, rFuncs, eType, eLnge ); } } @@ -1573,12 +1847,14 @@ sal_uInt32 SvNumberFormatter::GuessDateTimeFormat( SvNumFormatType& rType, doubl return nRet; } -sal_uInt32 SvNumberFormatter::GetEditFormat( double fNumber, sal_uInt32 nFIndex, - SvNumFormatType eType, - SvNumberformat const * pFormat, - LanguageType eForLocale ) +sal_uInt32 SvNFEngine::GetEditFormat(SvNFLanguageData& rCurrentLanguage, + const SvNFFormatData& rFormatData, + const NativeNumberWrapper* pNatNum, const Accessor& rFuncs, + double fNumber, sal_uInt32 nFIndex, + SvNumFormatType eType, + const SvNumberformat* pFormat, + LanguageType eForLocale) { - ::osl::MutexGuard aGuard( GetInstanceMutex() ); const LanguageType eLang = (pFormat ? pFormat->GetLanguage() : LANGUAGE_SYSTEM); if (eForLocale == LANGUAGE_DONTKNOW) eForLocale = eLang; @@ -1590,25 +1866,25 @@ sal_uInt32 SvNumberFormatter::GetEditFormat( double fNumber, sal_uInt32 nFIndex, { // Preserve ISO 8601 format. bool bIsoDate = - nFIndex == GetFormatIndex( NF_DATE_DIN_YYYYMMDD, eLang) || - nFIndex == GetFormatIndex( NF_DATE_DIN_YYMMDD, eLang) || - nFIndex == GetFormatIndex( NF_DATE_DIN_MMDD, eLang) || + nFIndex == GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_DATE_DIN_YYYYMMDD, eLang) || + nFIndex == GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_DATE_DIN_YYMMDD, eLang) || + nFIndex == GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_DATE_DIN_MMDD, eLang) || (pFormat && pFormat->IsIso8601( 0 )); if (rtl::math::approxFloor( fNumber) != fNumber) { // fdo#34977 preserve time when editing even if only date was // displayed. if (bIsoDate) - nKey = GetFormatIndex( NF_DATETIME_ISO_YYYYMMDD_HHMMSS, eForLocale); + nKey = GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_DATETIME_ISO_YYYYMMDD_HHMMSS, eForLocale); else - nKey = GetFormatIndex( NF_DATETIME_SYS_DDMMYYYY_HHMMSS, eForLocale ); + nKey = GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_DATETIME_SYS_DDMMYYYY_HHMMSS, eForLocale); } else { if (bIsoDate) - nKey = GetFormatIndex( NF_DATE_ISO_YYYYMMDD, eForLocale); + nKey = GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_DATE_ISO_YYYYMMDD, eForLocale); else - nKey = GetFormatIndex( NF_DATE_SYS_DDMMYYYY, eForLocale ); + nKey = GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_DATE_SYS_DDMMYYYY, eForLocale); } } break; @@ -1619,56 +1895,70 @@ sal_uInt32 SvNumberFormatter::GetEditFormat( double fNumber, sal_uInt32 nFIndex, * of a signed 16-bit. 32k hours are 3.7 years ... or * 1903-09-26 if date. */ if (fabs( fNumber) * 24 < 0x7fff) - nKey = GetTimeFormat( fNumber, eForLocale, true); + nKey = GetTimeFormat(rCurrentLanguage, rFormatData, pNatNum, rFuncs, fNumber, eForLocale, true); // Preserve duration, use [HH]:MM:SS instead of time. else - nKey = GetFormatIndex( NF_DATETIME_SYS_DDMMYYYY_HHMMSS, eForLocale ); + nKey = GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_DATETIME_SYS_DDMMYYYY_HHMMSS, eForLocale); // Assume that a large value is a datetime with only time // displayed. } else - nKey = GetStandardFormat( fNumber, nFIndex, eType, eForLocale ); + nKey = GetStandardFormat(rCurrentLanguage, rFormatData, pNatNum, rFuncs, fNumber, nFIndex, eType, eForLocale); break; case SvNumFormatType::DURATION : - nKey = GetTimeFormat( fNumber, eForLocale, true); + nKey = GetTimeFormat(rCurrentLanguage, rFormatData, pNatNum, rFuncs, fNumber, eForLocale, true); break; case SvNumFormatType::DATETIME : - if (nFIndex == GetFormatIndex( NF_DATETIME_ISO_YYYYMMDDTHHMMSS, eLang)) - nKey = GetFormatIndex( NF_DATETIME_ISO_YYYYMMDDTHHMMSS, eForLocale ); - else if (nFIndex == GetFormatIndex( NF_DATETIME_ISO_YYYYMMDDTHHMMSS000, eLang)) - nKey = GetFormatIndex( NF_DATETIME_ISO_YYYYMMDDTHHMMSS000, eForLocale ); - else if (nFIndex == GetFormatIndex( NF_DATETIME_ISO_YYYYMMDD_HHMMSS000, eLang)) - nKey = GetFormatIndex( NF_DATETIME_ISO_YYYYMMDD_HHMMSS000, eForLocale ); - else if (nFIndex == GetFormatIndex( NF_DATETIME_ISO_YYYYMMDD_HHMMSS, eLang) || (pFormat && pFormat->IsIso8601( 0 ))) - nKey = GetFormatIndex( NF_DATETIME_ISO_YYYYMMDD_HHMMSS, eForLocale ); + if (nFIndex == GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_DATETIME_ISO_YYYYMMDDTHHMMSS, eLang)) + nKey = GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_DATETIME_ISO_YYYYMMDDTHHMMSS, eForLocale ); + else if (nFIndex == GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_DATETIME_ISO_YYYYMMDDTHHMMSS000, eLang)) + nKey = GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_DATETIME_ISO_YYYYMMDDTHHMMSS000, eForLocale ); + else if (nFIndex == GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_DATETIME_ISO_YYYYMMDD_HHMMSS000, eLang)) + nKey = GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_DATETIME_ISO_YYYYMMDD_HHMMSS000, eForLocale ); + else if (nFIndex == GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_DATETIME_ISO_YYYYMMDD_HHMMSS, eLang) || (pFormat && pFormat->IsIso8601( 0 ))) + nKey = GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_DATETIME_ISO_YYYYMMDD_HHMMSS, eForLocale ); else - nKey = GetFormatIndex( NF_DATETIME_SYS_DDMMYYYY_HHMMSS, eForLocale ); + nKey = GetFormatIndex(rCurrentLanguage, rFuncs, pNatNum, NF_DATETIME_SYS_DDMMYYYY_HHMMSS, eForLocale ); break; case SvNumFormatType::NUMBER: - nKey = GetStandardFormat( eType, eForLocale ); + nKey = GetStandardFormat(rCurrentLanguage, rFormatData, pNatNum, rFuncs, eType, eForLocale); break; default: - nKey = GetStandardFormat( fNumber, nFIndex, eType, eForLocale ); + nKey = GetStandardFormat(rCurrentLanguage, rFormatData, pNatNum, rFuncs, fNumber, nFIndex, eType, eForLocale ); } return nKey; } -void SvNumberFormatter::GetInputLineString(const double& fOutNumber, - sal_uInt32 nFIndex, - OUString& sOutString, - bool bFiltering, bool bForceSystemLocale) +sal_uInt32 SvNumberFormatter::GetEditFormat( double fNumber, sal_uInt32 nFIndex, + SvNumFormatType eType, + SvNumberformat const * pFormat, + LanguageType eForLocale ) { ::osl::MutexGuard aGuard( GetInstanceMutex() ); + return SvNFEngine::GetEditFormat(m_aCurrentLanguage, m_aFormatData, GetNatNum(), + m_aRWPolicy, fNumber, nFIndex, + eType, pFormat, eForLocale); +} + +void SvNFEngine::GetInputLineString(SvNFLanguageData& rCurrentLanguage, + const SvNFFormatData& rFormatData, + const NativeNumberWrapper* pNatNum, const Accessor& rFuncs, + const double& fOutNumber, + sal_uInt32 nFIndex, + OUString& sOutString, + bool bFiltering, bool bForceSystemLocale) +{ const Color* pColor; sal_uInt32 nRealKey = nFIndex; - SvNumberformat* pFormat = ImpSubstituteEntry( GetFormatEntry( nFIndex ), &nRealKey); + + const SvNumberformat* pFormat = ImpSubstituteEntry(rCurrentLanguage, rFormatData, + pNatNum, rFuncs, + rFormatData.GetFormatEntry(nFIndex), &nRealKey); if (!pFormat) - { - pFormat = GetFormatEntry(ZF_STANDARD); - } + pFormat = rFormatData.GetFormatEntry(ZF_STANDARD); LanguageType eLang = pFormat->GetLanguage(); - ChangeIntl( eLang ); + rCurrentLanguage.ChangeIntl(eLang); SvNumFormatType eType = pFormat->GetMaskedType(); if (eType == SvNumFormatType::ALL) @@ -1681,7 +1971,7 @@ void SvNumberFormatter::GetInputLineString(const double& fOutNumber, } const SvNumFormatType eTypeOrig = eType; - sal_uInt16 nOldPrec = pFormatScanner->GetStandardPrec(); + sal_uInt16 nOldPrec = rCurrentLanguage.pFormatScanner->GetStandardPrec(); bool bPrecChanged = false; if (eType == SvNumFormatType::NUMBER || eType == SvNumFormatType::PERCENT || @@ -1693,18 +1983,19 @@ void SvNumberFormatter::GetInputLineString(const double& fOutNumber, { eType = SvNumFormatType::NUMBER; } - ChangeStandardPrec(INPUTSTRING_PRECISION); + rCurrentLanguage.ChangeStandardPrec(SvNumberFormatter::INPUTSTRING_PRECISION); bPrecChanged = true; } // if bFiltering true keep the nRealKey format if (!bFiltering) { - sal_uInt32 nKey = GetEditFormat( fOutNumber, nRealKey, eType, pFormat, - bForceSystemLocale ? LANGUAGE_SYSTEM : LANGUAGE_DONTKNOW); + sal_uInt32 nKey = GetEditFormat(rCurrentLanguage, rFormatData, pNatNum, rFuncs, + fOutNumber, nRealKey, eType, pFormat, + bForceSystemLocale ? LANGUAGE_SYSTEM : LANGUAGE_DONTKNOW); if (nKey != nRealKey) { - pFormat = GetFormatEntry( nKey ); + pFormat = rFormatData.GetFormatEntry( nKey ); } } assert(pFormat); @@ -1712,10 +2003,10 @@ void SvNumberFormatter::GetInputLineString(const double& fOutNumber, { if ( eType == SvNumFormatType::TIME && pFormat->GetFormatPrecision() ) { - ChangeStandardPrec(INPUTSTRING_PRECISION); + rCurrentLanguage.ChangeStandardPrec(SvNumberFormatter::INPUTSTRING_PRECISION); bPrecChanged = true; } - pFormat->GetOutputString(fOutNumber, sOutString, &pColor); + pFormat->GetOutputString(fOutNumber, sOutString, &pColor, pNatNum); // The #FMT error string must not be used for input as it would lead to // data loss. This can happen for at least date(+time). Fall back to a @@ -1723,36 +2014,45 @@ void SvNumberFormatter::GetInputLineString(const double& fOutNumber, // constructed with. if (eTypeOrig != SvNumFormatType::NUMBER && sOutString == ImpSvNumberformatScan::sErrStr) { - pFormat = GetFormatEntry(ZF_STANDARD); + pFormat = rFormatData.GetFormatEntry(ZF_STANDARD); assert(pFormat); if (pFormat) { - ChangeStandardPrec(INPUTSTRING_PRECISION); + rCurrentLanguage.ChangeStandardPrec(SvNumberFormatter::INPUTSTRING_PRECISION); bPrecChanged = true; - pFormat->GetOutputString(fOutNumber, sOutString, &pColor); + pFormat->GetOutputString(fOutNumber, sOutString, &pColor, pNatNum); } } assert(sOutString != ImpSvNumberformatScan::sErrStr); } if (bPrecChanged) { - ChangeStandardPrec(nOldPrec); + rCurrentLanguage.ChangeStandardPrec(nOldPrec); } } -void SvNumberFormatter::GetOutputString(const OUString& sString, - sal_uInt32 nFIndex, - OUString& sOutString, - const Color** ppColor, - bool bUseStarFormat ) +void SvNumberFormatter::GetInputLineString(const double& fOutNumber, + sal_uInt32 nFIndex, + OUString& sOutString, + bool bFiltering, bool bForceSystemLocale) { ::osl::MutexGuard aGuard( GetInstanceMutex() ); - SvNumberformat* pFormat = GetFormatEntry( nFIndex ); + SvNFEngine::GetInputLineString(m_aCurrentLanguage, m_aFormatData, GetNatNum(), + m_aRWPolicy, fOutNumber, nFIndex, sOutString, + bFiltering, bForceSystemLocale); +} + +void SvNFEngine::GetOutputString(SvNFLanguageData& rCurrentLanguage, + const SvNFFormatData& rFormatData, + const OUString& sString, sal_uInt32 nFIndex, OUString& sOutString, + const Color** ppColor, bool bUseStarFormat) +{ + const SvNumberformat* pFormat = rFormatData.GetFormatEntry( nFIndex ); // ImpSubstituteEntry() is unnecessary here because so far only numeric // (time and date) are substituted. if (!pFormat) { - pFormat = GetFormatEntry(ZF_STANDARD_TEXT); + pFormat = rFormatData.GetFormatEntry(ZF_STANDARD_TEXT); } if (!pFormat->IsTextFormat() && !pFormat->HasTextFormat()) { @@ -1761,66 +2061,91 @@ void SvNumberFormatter::GetOutputString(const OUString& sString, } else { - ChangeIntl(pFormat->GetLanguage()); + rCurrentLanguage.ChangeIntl(pFormat->GetLanguage()); pFormat->GetOutputString(sString, sOutString, ppColor, bUseStarFormat); } } -void SvNumberFormatter::GetOutputString(const double& fOutNumber, +void SvNumberFormatter::GetOutputString(const OUString& sString, sal_uInt32 nFIndex, OUString& sOutString, const Color** ppColor, bool bUseStarFormat ) { ::osl::MutexGuard aGuard( GetInstanceMutex() ); - if (bNoZero && fOutNumber == 0.0) + SvNFEngine::GetOutputString(m_aCurrentLanguage, m_aFormatData, + sString, nFIndex, sOutString, + ppColor, bUseStarFormat); +} + +void SvNFEngine::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) +{ + if (rFormatData.GetNoZero() && fOutNumber == 0.0) { sOutString.clear(); return; } - SvNumberformat* pFormat = ImpSubstituteEntry( GetFormatEntry( nFIndex )); + const SvNumberformat* pFormat = ImpSubstituteEntry(rCurrentLanguage, rFormatData, + pNatNum, rFuncs, + rFormatData.GetFormatEntry(nFIndex), nullptr); if (!pFormat) - pFormat = GetFormatEntry(ZF_STANDARD); - ChangeIntl(pFormat->GetLanguage()); - pFormat->GetOutputString(fOutNumber, sOutString, ppColor, bUseStarFormat); + pFormat = rFormatData.GetFormatEntry(ZF_STANDARD); + rCurrentLanguage.ChangeIntl(pFormat->GetLanguage()); + pFormat->GetOutputString(fOutNumber, sOutString, ppColor, pNatNum, bUseStarFormat); } -bool SvNumberFormatter::GetPreviewString(const OUString& sFormatString, - double fPreviewNumber, - OUString& sOutString, - const Color** ppColor, - LanguageType eLnge, - bool bUseStarFormat ) +void SvNumberFormatter::GetOutputString(const double& fOutNumber, + sal_uInt32 nFIndex, + OUString& sOutString, + const Color** ppColor, + bool bUseStarFormat ) { ::osl::MutexGuard aGuard( GetInstanceMutex() ); + SvNFEngine::GetOutputString(m_aCurrentLanguage, m_aFormatData, GetNatNum(), + m_aRWPolicy, fOutNumber, nFIndex, sOutString, + ppColor, bUseStarFormat); +} + +bool SvNFEngine::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) +{ if (sFormatString.isEmpty()) // no empty string - { return false; - } - if (eLnge == LANGUAGE_DONTKNOW) - { - eLnge = IniLnge; - } - ChangeIntl(eLnge); // change locale if necessary - eLnge = ActLnge; + eLnge = rCurrentLanguage.ImpResolveLanguage(eLnge); + rCurrentLanguage.ChangeIntl(eLnge); // change locale if necessary + eLnge = rCurrentLanguage.ActLnge; sal_Int32 nCheckPos = -1; OUString sTmpString = sFormatString; SvNumberformat aEntry(sTmpString, - pFormatScanner.get(), - pStringScanner.get(), + rCurrentLanguage.pFormatScanner.get(), + rCurrentLanguage.pStringScanner.get(), + pNatNum, nCheckPos, eLnge); if (nCheckPos == 0) // String ok { - sal_uInt32 CLOffset = ImpGenerateCL(eLnge); // create new standard formats if necessary - sal_uInt32 nKey = ImpIsEntry(aEntry.GetFormatstring(),CLOffset, eLnge); + sal_uInt32 nCLOffset = rFuncs.mGetCLOffset(rCurrentLanguage, pNatNum, eLnge); // create new standard formats if necessary (and allowed) + sal_uInt32 nKey = rFormatData.ImpIsEntry(aEntry.GetFormatstring(), nCLOffset, eLnge); if (nKey != NUMBERFORMAT_ENTRY_NOT_FOUND) // already present { - GetOutputString(fPreviewNumber, nKey, sOutString, ppColor, bUseStarFormat); + GetOutputString(rCurrentLanguage, rFormatData, pNatNum, rFuncs, fPreviewNumber, nKey, sOutString, ppColor, bUseStarFormat); } else { - aEntry.GetOutputString(fPreviewNumber, sOutString, ppColor, bUseStarFormat); + aEntry.GetOutputString(fPreviewNumber, sOutString, ppColor, pNatNum, bUseStarFormat); } return true; } @@ -1830,32 +2155,46 @@ bool SvNumberFormatter::GetPreviewString(const OUString& sFormatString, } } -bool SvNumberFormatter::GetPreviewStringGuess( const OUString& sFormatString, - double fPreviewNumber, - OUString& sOutString, - const Color** ppColor, - LanguageType eLnge ) +bool SvNumberFormatter::GetPreviewString(const OUString& sFormatString, + double fPreviewNumber, + OUString& sOutString, + const Color** ppColor, + LanguageType eLnge, + bool bUseStarFormat ) { ::osl::MutexGuard aGuard( GetInstanceMutex() ); + return SvNFEngine::GetPreviewString(m_aCurrentLanguage, m_aFormatData, + GetNatNum(), m_aRWPolicy, + sFormatString, fPreviewNumber, + sOutString, ppColor, eLnge, + bUseStarFormat); +} + +bool SvNFEngine::GetPreviewStringGuess(SvNFLanguageData& rCurrentLanguage, + const SvNFFormatData& rFormatData, + const NativeNumberWrapper* pNatNum, + const Accessor& rFuncs, + const OUString& sFormatString, + double fPreviewNumber, + OUString& sOutString, + const Color** ppColor, + LanguageType eLnge) +{ if (sFormatString.isEmpty()) // no empty string - { return false; - } - if (eLnge == LANGUAGE_DONTKNOW) - { - eLnge = IniLnge; - } - ChangeIntl( eLnge ); - eLnge = ActLnge; + eLnge = rCurrentLanguage.ImpResolveLanguage(eLnge); + rCurrentLanguage.ChangeIntl(eLnge); + eLnge = rCurrentLanguage.ActLnge; bool bEnglish = (eLnge == LANGUAGE_ENGLISH_US); - OUString aFormatStringUpper( xCharClass->uppercase( sFormatString ) ); - sal_uInt32 nCLOffset = ImpGenerateCL( eLnge ); - sal_uInt32 nKey = ImpIsEntry( aFormatStringUpper, nCLOffset, eLnge ); + OUString aFormatStringUpper( rCurrentLanguage.xCharClass->uppercase( sFormatString ) ); + sal_uInt32 nCLOffset = rFuncs.mGetCLOffset(rCurrentLanguage, pNatNum, eLnge); // create new standard formats if necessary (and allowed) + sal_uInt32 nKey = rFormatData.ImpIsEntry(aFormatStringUpper, nCLOffset, eLnge); if ( nKey != NUMBERFORMAT_ENTRY_NOT_FOUND ) { // Target format present - GetOutputString( fPreviewNumber, nKey, sOutString, ppColor ); + GetOutputString(rCurrentLanguage, rFormatData, pNatNum, rFuncs, + fPreviewNumber, nKey, sOutString, ppColor, false); return true; } @@ -1866,35 +2205,35 @@ bool SvNumberFormatter::GetPreviewStringGuess( const OUString& sFormatString, if ( bEnglish ) { sTmpString = sFormatString; - pEntry.emplace( sTmpString, pFormatScanner.get(), - pStringScanner.get(), nCheckPos, eLnge ); + pEntry.emplace( sTmpString, rCurrentLanguage.pFormatScanner.get(), + rCurrentLanguage.pStringScanner.get(), pNatNum, nCheckPos, eLnge ); } else { - nCLOffset = ImpGenerateCL( LANGUAGE_ENGLISH_US ); - nKey = ImpIsEntry( aFormatStringUpper, nCLOffset, LANGUAGE_ENGLISH_US ); + nCLOffset = rFuncs.mGetCLOffset(rCurrentLanguage, pNatNum, LANGUAGE_ENGLISH_US); + nKey = rFormatData.ImpIsEntry(aFormatStringUpper, nCLOffset, LANGUAGE_ENGLISH_US); bool bEnglishFormat = (nKey != NUMBERFORMAT_ENTRY_NOT_FOUND); // Try English -> other or convert english to other LanguageType eFormatLang = LANGUAGE_ENGLISH_US; - pFormatScanner->SetConvertMode( LANGUAGE_ENGLISH_US, eLnge, false, false); + rCurrentLanguage.pFormatScanner->SetConvertMode( LANGUAGE_ENGLISH_US, eLnge, false, false); sTmpString = sFormatString; - pEntry.emplace( sTmpString, pFormatScanner.get(), - pStringScanner.get(), nCheckPos, eFormatLang ); - pFormatScanner->SetConvertMode( false ); - ChangeIntl( eLnge ); + pEntry.emplace( sTmpString, rCurrentLanguage.pFormatScanner.get(), + rCurrentLanguage.pStringScanner.get(), pNatNum, nCheckPos, eFormatLang ); + rCurrentLanguage.pFormatScanner->SetConvertMode( false ); + rCurrentLanguage.ChangeIntl(eLnge); if ( !bEnglishFormat ) { - if ( nCheckPos != 0 || xTransliteration->isEqual( sFormatString, + if ( nCheckPos != 0 || rCurrentLanguage.xTransliteration->isEqual( sFormatString, pEntry->GetFormatstring() ) ) { // other Format // Force locale's keywords. - pFormatScanner->ChangeIntl( ImpSvNumberformatScan::KeywordLocalization::LocaleLegacy ); + rCurrentLanguage.pFormatScanner->ChangeIntl( ImpSvNumberformatScan::KeywordLocalization::LocaleLegacy ); sTmpString = sFormatString; - pEntry.emplace( sTmpString, pFormatScanner.get(), - pStringScanner.get(), nCheckPos, eLnge ); + pEntry.emplace( sTmpString, rCurrentLanguage.pFormatScanner.get(), + rCurrentLanguage.pStringScanner.get(), pNatNum, nCheckPos, eLnge ); } else { @@ -1902,21 +2241,21 @@ bool SvNumberFormatter::GetPreviewStringGuess( const OUString& sFormatString, sal_Int32 nCheckPos2 = -1; // try other --> english eFormatLang = eLnge; - pFormatScanner->SetConvertMode( eLnge, LANGUAGE_ENGLISH_US, false, false); + rCurrentLanguage.pFormatScanner->SetConvertMode( eLnge, LANGUAGE_ENGLISH_US, false, false); sTmpString = sFormatString; - SvNumberformat aEntry2( sTmpString, pFormatScanner.get(), - pStringScanner.get(), nCheckPos2, eFormatLang ); - pFormatScanner->SetConvertMode( false ); - ChangeIntl( eLnge ); - if ( nCheckPos2 == 0 && !xTransliteration->isEqual( sFormatString, + SvNumberformat aEntry2( sTmpString, rCurrentLanguage.pFormatScanner.get(), + rCurrentLanguage.pStringScanner.get(), pNatNum, nCheckPos2, eFormatLang ); + rCurrentLanguage.pFormatScanner->SetConvertMode( false ); + rCurrentLanguage.ChangeIntl(eLnge); + if ( nCheckPos2 == 0 && !rCurrentLanguage.xTransliteration->isEqual( sFormatString, aEntry2.GetFormatstring() ) ) { // other Format // Force locale's keywords. - pFormatScanner->ChangeIntl( ImpSvNumberformatScan::KeywordLocalization::LocaleLegacy ); + rCurrentLanguage.pFormatScanner->ChangeIntl( ImpSvNumberformatScan::KeywordLocalization::LocaleLegacy ); sTmpString = sFormatString; - pEntry.emplace( sTmpString, pFormatScanner.get(), - pStringScanner.get(), nCheckPos, eLnge ); + pEntry.emplace( sTmpString, rCurrentLanguage.pFormatScanner.get(), + rCurrentLanguage.pStringScanner.get(), pNatNum, nCheckPos, eLnge ); } } } @@ -1924,45 +2263,58 @@ bool SvNumberFormatter::GetPreviewStringGuess( const OUString& sFormatString, if (nCheckPos == 0) // String ok { - ImpGenerateCL( eLnge ); // create new standard formats if necessary - pEntry->GetOutputString( fPreviewNumber, sOutString, ppColor ); + rFuncs.mGetCLOffset(rCurrentLanguage, pNatNum, eLnge); // create new standard formats if necessary + pEntry->GetOutputString( fPreviewNumber, sOutString, ppColor, pNatNum ); return true; } return false; } -bool SvNumberFormatter::GetPreviewString( const OUString& sFormatString, - const OUString& sPreviewString, - OUString& sOutString, - const Color** ppColor, - LanguageType eLnge ) +bool SvNumberFormatter::GetPreviewStringGuess( const OUString& sFormatString, + double fPreviewNumber, + OUString& sOutString, + const Color** ppColor, + LanguageType eLnge ) { ::osl::MutexGuard aGuard( GetInstanceMutex() ); + return SvNFEngine::GetPreviewStringGuess(m_aCurrentLanguage, m_aFormatData, + GetNatNum(), m_aRWPolicy, + sFormatString, fPreviewNumber, + sOutString, ppColor, eLnge); +} + +bool SvNFEngine::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) +{ if (sFormatString.isEmpty()) // no empty string - { return false; - } - if (eLnge == LANGUAGE_DONTKNOW) - { - eLnge = IniLnge; - } - ChangeIntl(eLnge); // switch if needed - eLnge = ActLnge; + eLnge = rCurrentLanguage.ImpResolveLanguage(eLnge); + rCurrentLanguage.ChangeIntl(eLnge); // switch if needed + eLnge = rCurrentLanguage.ActLnge; sal_Int32 nCheckPos = -1; OUString sTmpString = sFormatString; SvNumberformat aEntry( sTmpString, - pFormatScanner.get(), - pStringScanner.get(), + rCurrentLanguage.pFormatScanner.get(), + rCurrentLanguage.pStringScanner.get(), + pNatNum, nCheckPos, eLnge); if (nCheckPos == 0) // String ok { // May have to create standard formats for this locale. - sal_uInt32 CLOffset = ImpGenerateCL(eLnge); - sal_uInt32 nKey = ImpIsEntry( aEntry.GetFormatstring(), CLOffset, eLnge); + sal_uInt32 nCLOffset = rFuncs.mGetCLOffset(rCurrentLanguage, pNatNum, eLnge); + sal_uInt32 nKey = rFormatData.ImpIsEntry( aEntry.GetFormatstring(), nCLOffset, eLnge); if (nKey != NUMBERFORMAT_ENTRY_NOT_FOUND) // already present { - GetOutputString( sPreviewString, nKey, sOutString, ppColor); + GetOutputString(rCurrentLanguage, rFormatData, + sPreviewString, nKey, sOutString, ppColor, false); } else { @@ -1987,6 +2339,19 @@ bool SvNumberFormatter::GetPreviewString( const OUString& sFormatString, } } +bool SvNumberFormatter::GetPreviewString( const OUString& sFormatString, + const OUString& sPreviewString, + OUString& sOutString, + const Color** ppColor, + LanguageType eLnge ) +{ + ::osl::MutexGuard aGuard( GetInstanceMutex() ); + return SvNFEngine::GetPreviewString(m_aCurrentLanguage, m_aFormatData, + GetNatNum(), m_aRWPolicy, + sFormatString, sPreviewString, + sOutString, ppColor, eLnge); +} + sal_uInt32 SvNumberFormatter::TestNewString(const OUString& sFormatString, LanguageType eLnge) { @@ -2000,18 +2365,19 @@ sal_uInt32 SvNumberFormatter::TestNewString(const OUString& sFormatString, eLnge = IniLnge; } ChangeIntl(eLnge); // change locale if necessary - eLnge = ActLnge; + eLnge = m_aCurrentLanguage.ActLnge; sal_uInt32 nRes; sal_Int32 nCheckPos = -1; OUString sTmpString = sFormatString; SvNumberformat aEntry(sTmpString, - pFormatScanner.get(), - pStringScanner.get(), + m_aCurrentLanguage.pFormatScanner.get(), + m_aCurrentLanguage.pStringScanner.get(), + GetNatNum(), nCheckPos, eLnge); if (nCheckPos == 0) // String ok { - sal_uInt32 CLOffset = ImpGenerateCL(eLnge); // create new standard formats if necessary + sal_uInt32 CLOffset = m_aFormatData.ImpGenerateCL(m_aCurrentLanguage, GetNatNum(), eLnge); // create new standard formats if necessary nRes = ImpIsEntry(aEntry.GetFormatstring(),CLOffset, eLnge); // already present? } @@ -2022,12 +2388,14 @@ sal_uInt32 SvNumberFormatter::TestNewString(const OUString& sFormatString, return nRes; } -SvNumberformat* SvNumberFormatter::ImpInsertFormat( const css::i18n::NumberFormatCode& rCode, - sal_uInt32 nPos, bool bAfterChangingSystemCL, - sal_Int16 nOrgIndex ) +SvNumberformat* SvNFFormatData::ImpInsertFormat(SvNFLanguageData& rCurrentLanguage, + const NativeNumberWrapper* pNatNum, + const css::i18n::NumberFormatCode& rCode, + sal_uInt32 nPos, bool bAfterChangingSystemCL, + sal_Int16 nOrgIndex) { SAL_WARN_IF( NF_INDEX_TABLE_RESERVED_START <= rCode.Index && rCode.Index < NF_INDEX_TABLE_ENTRIES, - "svl.numbers", "i18npool locale '" << maLanguageTag.getBcp47() << + "svl.numbers", "i18npool locale '" << rCurrentLanguage.aLanguageTag.getBcp47() << "' uses reserved formatIndex value " << rCode.Index << ", next free: " << NF_INDEX_TABLE_ENTRIES << " Please see description in include/svl/zforlist.hxx at end of enum NfIndexTableOffset"); assert( (rCode.Index < NF_INDEX_TABLE_RESERVED_START || NF_INDEX_TABLE_ENTRIES <= rCode.Index) && @@ -2049,16 +2417,17 @@ SvNumberformat* SvNumberFormatter::ImpInsertFormat( const css::i18n::NumberForma OUString::number( rCode.Index) + ":\n" + rCode.Code; - LocaleDataWrapper::outputCheckMessage( xLocaleData->appendLocaleInfo( aMsg)); + LocaleDataWrapper::outputCheckMessage( rCurrentLanguage.xLocaleData->appendLocaleInfo( aMsg)); } } } sal_Int32 nCheckPos = 0; std::unique_ptr<SvNumberformat> pFormat(new SvNumberformat(aCodeStr, - pFormatScanner.get(), - pStringScanner.get(), + rCurrentLanguage.pFormatScanner.get(), + rCurrentLanguage.pStringScanner.get(), + pNatNum, nCheckPos, - ActLnge)); + rCurrentLanguage.ActLnge)); if (nCheckPos != 0) { if (LocaleDataWrapper::areChecksEnabled()) @@ -2067,14 +2436,14 @@ SvNumberformat* SvNumberFormatter::ImpInsertFormat( const css::i18n::NumberForma OUString::number( rCode.Index ) + "\n" + rCode.Code; - LocaleDataWrapper::outputCheckMessage( xLocaleData->appendLocaleInfo( aMsg)); + LocaleDataWrapper::outputCheckMessage( rCurrentLanguage.xLocaleData->appendLocaleInfo( aMsg)); } return nullptr; } if ( rCode.Index >= NF_INDEX_TABLE_RESERVED_START ) { sal_uInt32 nCLOffset = nPos - (nPos % SV_COUNTRY_LANGUAGE_OFFSET); - sal_uInt32 nKey = ImpIsEntry( aCodeStr, nCLOffset, ActLnge ); + sal_uInt32 nKey = ImpIsEntry( aCodeStr, nCLOffset, rCurrentLanguage.ActLnge ); if ( nKey != NUMBERFORMAT_ENTRY_NOT_FOUND ) { // If bAfterChangingSystemCL there will definitely be some dups, @@ -2096,7 +2465,7 @@ SvNumberformat* SvNumberFormatter::ImpInsertFormat( const css::i18n::NumberForma + OUString::number( rCode.Index ) + "\n" + rCode.Code; - LocaleDataWrapper::outputCheckMessage( xLocaleData->appendLocaleInfo( aMsg)); + LocaleDataWrapper::outputCheckMessage( rCurrentLanguage.xLocaleData->appendLocaleInfo( aMsg)); } } } @@ -2110,7 +2479,7 @@ SvNumberformat* SvNumberFormatter::ImpInsertFormat( const css::i18n::NumberForma + OUString::number( rCode.Index ) + "\n" + rCode.Code; - LocaleDataWrapper::outputCheckMessage( xLocaleData->appendLocaleInfo( aMsg)); + LocaleDataWrapper::outputCheckMessage( rCurrentLanguage.xLocaleData->appendLocaleInfo( aMsg)); } return nullptr; } @@ -2126,7 +2495,7 @@ SvNumberformat* SvNumberFormatter::ImpInsertFormat( const css::i18n::NumberForma + OUString::number( rCode.Index ) + "\n" + rCode.Code; - LocaleDataWrapper::outputCheckMessage( xLocaleData->appendLocaleInfo( aMsg)); + LocaleDataWrapper::outputCheckMessage( rCurrentLanguage.xLocaleData->appendLocaleInfo( aMsg)); } else { @@ -2149,7 +2518,7 @@ void SvNumberFormatter::GetFormatSpecialInfo(sal_uInt32 nFormat, { ::osl::MutexGuard aGuard( GetInstanceMutex() ); - SvNumberformat* pFormat = GetFormatEntry( nFormat ); + SvNumberformat* pFormat = m_aFormatData.GetFormatEntry( nFormat ); if (pFormat) pFormat->GetFormatSpecialInfo(bThousand, IsRed, nPrecision, nLeadingCnt); @@ -2157,69 +2526,59 @@ void SvNumberFormatter::GetFormatSpecialInfo(sal_uInt32 nFormat, { bThousand = false; IsRed = false; - nPrecision = pFormatScanner->GetStandardPrec(); + nPrecision = m_aCurrentLanguage.pFormatScanner->GetStandardPrec(); nLeadingCnt = 0; } } -sal_uInt16 SvNumberFormatter::GetFormatPrecision( sal_uInt32 nFormat ) const +sal_uInt16 SvNFEngine::GetFormatPrecision(SvNFLanguageData& rCurrentLanguage, + const SvNFFormatData& rFormatData, + sal_uInt32 nFormat) { - ::osl::MutexGuard aGuard( GetInstanceMutex() ); - const SvNumberformat* pFormat = GetFormatEntry( nFormat ); - if ( pFormat ) + const SvNumberformat* pFormat = rFormatData.GetFormatEntry(nFormat); + if (pFormat) return pFormat->GetFormatPrecision(); - else - return pFormatScanner->GetStandardPrec(); + return rCurrentLanguage.pFormatScanner->GetStandardPrec(); +} + +sal_uInt16 SvNumberFormatter::GetFormatPrecision( sal_uInt32 nFormat ) +{ + ::osl::MutexGuard aGuard( GetInstanceMutex() ); + return SvNFEngine::GetFormatPrecision(m_aCurrentLanguage, m_aFormatData, nFormat); } sal_uInt16 SvNumberFormatter::GetFormatIntegerDigits( sal_uInt32 nFormat ) const { ::osl::MutexGuard aGuard( GetInstanceMutex() ); - const SvNumberformat* pFormat = GetFormatEntry( nFormat ); + const SvNumberformat* pFormat = m_aFormatData.GetFormatEntry( nFormat ); if ( pFormat ) return pFormat->GetFormatIntegerDigits(); else return 1; } -OUString SvNumberFormatter::GetFormatDecimalSep( sal_uInt32 nFormat ) const +OUString SvNFEngine::GetFormatDecimalSep(SvNFLanguageData& rCurrentLanguage, + const SvNFFormatData& rFormatData, + sal_uInt32 nFormat) { - ::osl::MutexGuard aGuard( GetInstanceMutex() ); - const SvNumberformat* pFormat = GetFormatEntry(nFormat); + const SvNumberformat* pFormat = rFormatData.GetFormatEntry(nFormat); if (!pFormat) - { - return GetNumDecimalSep(); - } - return GetLangDecimalSep( pFormat->GetLanguage()); + return rCurrentLanguage.GetNumDecimalSep(); + return rCurrentLanguage.GetLangDecimalSep(pFormat->GetLanguage()); } -OUString SvNumberFormatter::GetLangDecimalSep( LanguageType nLang ) const +OUString SvNumberFormatter::GetFormatDecimalSep( sal_uInt32 nFormat ) { ::osl::MutexGuard aGuard( GetInstanceMutex() ); - if (nLang == ActLnge) - { - return GetNumDecimalSep(); - } - OUString aRet; - LanguageType eSaveLang = xLocaleData.getCurrentLanguage(); - if (nLang == eSaveLang) - { - aRet = xLocaleData->getNumDecimalSep(); - } - else - { - LanguageTag aSaveLocale( xLocaleData->getLanguageTag() ); - const_cast<SvNumberFormatter*>(this)->xLocaleData.changeLocale( LanguageTag( nLang)); - aRet = xLocaleData->getNumDecimalSep(); - const_cast<SvNumberFormatter*>(this)->xLocaleData.changeLocale( aSaveLocale ); - } - return aRet; + return SvNFEngine::GetFormatDecimalSep(m_aCurrentLanguage, + m_aFormatData, + nFormat); } bool SvNumberFormatter::IsNatNum12( sal_uInt32 nFIndex ) const { ::osl::MutexGuard aGuard( GetInstanceMutex() ); - const SvNumberformat* pFormat = GetFormatEntry( nFIndex ); + const SvNumberformat* pFormat = m_aFormatData.GetFormatEntry( nFIndex ); return pFormat && pFormat->GetNatNumModifierString().startsWith( "[NatNum12" ); } @@ -2235,11 +2594,11 @@ sal_uInt32 SvNumberFormatter::GetFormatSpecialInfo( const OUString& rFormatStrin eLnge = IniLnge; } ChangeIntl(eLnge); // change locale if necessary - eLnge = ActLnge; + eLnge = m_aCurrentLanguage.ActLnge; OUString aTmpStr( rFormatString ); sal_Int32 nCheckPos = 0; - SvNumberformat aFormat( aTmpStr, pFormatScanner.get(), - pStringScanner.get(), nCheckPos, eLnge ); + SvNumberformat aFormat( aTmpStr, m_aCurrentLanguage.pFormatScanner.get(), + m_aCurrentLanguage.pStringScanner.get(), GetNatNum(), nCheckPos, eLnge ); if ( nCheckPos == 0 ) { aFormat.GetFormatSpecialInfo( bThousand, IsRed, nPrecision, nLeadingCnt ); @@ -2248,16 +2607,15 @@ sal_uInt32 SvNumberFormatter::GetFormatSpecialInfo( const OUString& rFormatStrin { bThousand = false; IsRed = false; - nPrecision = pFormatScanner->GetStandardPrec(); + nPrecision = m_aCurrentLanguage.pFormatScanner->GetStandardPrec(); nLeadingCnt = 0; } return nCheckPos; } -OUString SvNumberFormatter::GetCalcCellReturn( sal_uInt32 nFormat ) const +OUString SvNFFormatData::GetCalcCellReturn(sal_uInt32 nFormat) const { - ::osl::MutexGuard aGuard( GetInstanceMutex() ); - const SvNumberformat* pFormat = GetFormatEntry( nFormat ); + const SvNumberformat* pFormat = GetFormatEntry(nFormat); if (!pFormat) return "G"; @@ -2287,7 +2645,7 @@ OUString SvNumberFormatter::GetCalcCellReturn( sal_uInt32 nFormat ) const default: { bAppendPrec = false; - switch (GetIndexTableOffset( nFormat )) + switch (SvNumberFormatter::GetIndexTableOffset(nFormat)) { case NF_DATE_SYSTEM_SHORT: case NF_DATE_SYS_DMMMYY: @@ -2328,9 +2686,18 @@ OUString SvNumberFormatter::GetCalcCellReturn( sal_uInt32 nFormat ) const return aStr; } -sal_Int32 SvNumberFormatter::ImpGetFormatCodeIndex( - css::uno::Sequence< css::i18n::NumberFormatCode >& rSeq, - const NfIndexTableOffset nTabOff ) +OUString SvNumberFormatter::GetCalcCellReturn( sal_uInt32 nFormat ) const +{ + ::osl::MutexGuard aGuard( GetInstanceMutex() ); + return m_aFormatData.GetCalcCellReturn(nFormat); +} + +// 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. +sal_Int32 SvNFFormatData::ImpGetFormatCodeIndex(const SvNFLanguageData& rCurrentLanguage, + css::uno::Sequence<css::i18n::NumberFormatCode>& rSeq, + const NfIndexTableOffset nTabOff) { auto pSeq = std::find_if(std::cbegin(rSeq), std::cend(rSeq), [nTabOff](const css::i18n::NumberFormatCode& rCode) { return rCode.Index == nTabOff; }); @@ -2343,7 +2710,7 @@ sal_Int32 SvNumberFormatter::ImpGetFormatCodeIndex( { // currency entries with decimals might not exist, e.g. Italian Lira OUString aMsg = "SvNumberFormatter::ImpGetFormatCodeIndex: not found: " + OUString::number( nTabOff ); - LocaleDataWrapper::outputCheckMessage( xLocaleData->appendLocaleInfo(aMsg)); + LocaleDataWrapper::outputCheckMessage( rCurrentLanguage.xLocaleData->appendLocaleInfo(aMsg)); } if ( rSeq.hasElements() ) { @@ -2371,15 +2738,19 @@ sal_Int32 SvNumberFormatter::ImpGetFormatCodeIndex( else { // we need at least _some_ format rSeq = { css::i18n::NumberFormatCode() }; - rSeq.getArray()[0].Code = "0" + GetNumDecimalSep() + "############"; + rSeq.getArray()[0].Code = "0" + rCurrentLanguage.GetNumDecimalSep() + "############"; } return 0; } - -void SvNumberFormatter::ImpAdjustFormatCodeDefault( - css::i18n::NumberFormatCode * pFormatArr, - sal_Int32 nCnt ) +// 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. +void SvNFFormatData::ImpAdjustFormatCodeDefault(const SvNFLanguageData& rCurrentLanguage, + css::i18n::NumberFormatCode * pFormatArr, + sal_Int32 nCnt) { if ( !nCnt ) return; @@ -2431,7 +2802,7 @@ void SvNumberFormatter::ImpAdjustFormatCodeDefault( aMsg.insert(0, "SvNumberFormatter::ImpAdjustFormatCodeDefault: "); aMsg.append("\nXML locale data FormatElement formatindex: " + OUString::number(static_cast<sal_Int32>(pFormatArr[nElem].Index))); - LocaleDataWrapper::outputCheckMessage(xLocaleData->appendLocaleInfo(aMsg)); + LocaleDataWrapper::outputCheckMessage(rCurrentLanguage.xLocaleData->appendLocaleInfo(aMsg)); aMsg.setLength(0); } } @@ -2446,7 +2817,7 @@ void SvNumberFormatter::ImpAdjustFormatCodeDefault( aMsg.insert(0, "SvNumberFormatter::ImpAdjustFormatCodeDefault: "); aMsg.append("\nXML locale data FormatElement group of: "); LocaleDataWrapper::outputCheckMessage( - xLocaleData->appendLocaleInfo(Concat2View(aMsg + pFormatArr[0].NameID))); + rCurrentLanguage.xLocaleData->appendLocaleInfo(Concat2View(aMsg + pFormatArr[0].NameID))); aMsg.setLength(0); } } @@ -2478,7 +2849,7 @@ void SvNumberFormatter::ImpAdjustFormatCodeDefault( pFormatArr[nDef].Default = true; } -SvNumberformat* SvNumberFormatter::GetFormatEntry( sal_uInt32 nKey ) +SvNumberformat* SvNFFormatData::GetEntry(sal_uInt32 nKey) const { auto it = aFTable.find( nKey); if (it != aFTable.end()) @@ -2486,18 +2857,35 @@ SvNumberformat* SvNumberFormatter::GetFormatEntry( sal_uInt32 nKey ) return nullptr; } -const SvNumberformat* SvNumberFormatter::GetFormatEntry( sal_uInt32 nKey ) const +SvNumberformat* SvNFFormatData::GetFormatEntry(sal_uInt32 nKey) +{ + return GetEntry(nKey); +} + +const SvNumberformat* SvNFFormatData::GetFormatEntry(sal_uInt32 nKey) const +{ + return GetEntry(nKey); +} + +SvNumFormatType SvNFFormatData::GetType(sal_uInt32 nFIndex) const { - return GetEntry( nKey); + SvNumFormatType eType; + const SvNumberformat* pFormat = GetFormatEntry(nFIndex); + if (!pFormat) + eType = SvNumFormatType::UNDEFINED; + else + { + eType = pFormat->GetMaskedType(); + if (eType == SvNumFormatType::ALL) + eType = SvNumFormatType::DEFINED; + } + return eType; } const SvNumberformat* SvNumberFormatter::GetEntry( sal_uInt32 nKey ) const { - ::osl::MutexGuard aGuard( GetInstanceMutex() ); - auto it = aFTable.find( nKey); - if (it != aFTable.end()) - return it->second.get(); - return nullptr; + ::osl::MutexGuard aGuard(GetInstanceMutex()); + return m_aFormatData.GetFormatEntry(nKey); } const SvNumberformat* SvNumberFormatter::GetSubstitutedEntry( sal_uInt32 nKey, sal_uInt32 & o_rNewKey ) const @@ -2507,60 +2895,40 @@ const SvNumberformat* SvNumberFormatter::GetSubstitutedEntry( sal_uInt32 nKey, s // ImpSubstituteEntry() may have to add the LANGUAGE_SYSTEM formats if not // already present (which in practice most times they are). SvNumberFormatter* pThis = const_cast<SvNumberFormatter*>(this); - return pThis->ImpSubstituteEntry( pThis->GetFormatEntry( nKey), &o_rNewKey); + return pThis->ImpSubstituteEntry( pThis->m_aFormatData.GetFormatEntry( nKey), &o_rNewKey); } -SvNumberformat* SvNumberFormatter::ImpSubstituteEntry( SvNumberformat* pFormat, sal_uInt32 * o_pRealKey ) +const SvNumberformat* SvNumberFormatter::ImpSubstituteEntry( const SvNumberformat* pFormat, sal_uInt32 * o_pRealKey ) { - if (!pFormat || !pFormat->IsSubstituted()) - return pFormat; - - // XXX NOTE: substitution can not be done in GetFormatEntry() as otherwise - // to be substituted formats would "vanish", i.e. from the number formatter - // dialog or when exporting to Excel. - - sal_uInt32 nKey; - if (pFormat->IsSystemTimeFormat()) - /* TODO: should we have NF_TIME_SYSTEM for consistency? */ - nKey = GetStandardFormat( SvNumFormatType::TIME, LANGUAGE_SYSTEM); - else if (pFormat->IsSystemLongDateFormat()) - /* TODO: either that above, or have a long option for GetStandardFormat() */ - nKey = GetFormatIndex( NF_DATE_SYSTEM_LONG, LANGUAGE_SYSTEM); - else - return pFormat; - - if (o_pRealKey) - *o_pRealKey = nKey; - auto it = aFTable.find( nKey); - return it == aFTable.end() ? nullptr : it->second.get(); + return ::ImpSubstituteEntry(m_aCurrentLanguage, m_aFormatData, GetNatNum(), m_aRWPolicy, pFormat, o_pRealKey); } -void SvNumberFormatter::ImpGenerateFormats( sal_uInt32 CLOffset, bool bNoAdditionalFormats ) +void SvNFFormatData::ImpGenerateFormats(SvNFLanguageData& rCurrentLanguage, const NativeNumberWrapper* pNatNum, sal_uInt32 CLOffset, bool bNoAdditionalFormats ) { - bool bOldConvertMode = pFormatScanner->GetConvertMode(); + bool bOldConvertMode = rCurrentLanguage.pFormatScanner->GetConvertMode(); if (bOldConvertMode) { - pFormatScanner->SetConvertMode(false); // switch off for this function + rCurrentLanguage.pFormatScanner->SetConvertMode(false); // switch off for this function } - css::lang::Locale aLocale = GetLanguageTag().getLocale(); - css::uno::Reference< css::i18n::XNumberFormatCode > xNFC = i18n::NumberFormatMapper::create( m_xContext ); + css::lang::Locale aLocale = rCurrentLanguage.GetLanguageTag().getLocale(); + css::uno::Reference< css::i18n::XNumberFormatCode > xNFC = i18n::NumberFormatMapper::create(rCurrentLanguage.GetComponentContext()); sal_Int32 nIdx; // Number uno::Sequence< i18n::NumberFormatCode > aFormatSeq = xNFC->getAllFormatCode( i18n::KNumberFormatUsage::FIXED_NUMBER, aLocale ); - ImpAdjustFormatCodeDefault( aFormatSeq.getArray(), aFormatSeq.getLength() ); + ImpAdjustFormatCodeDefault(rCurrentLanguage, aFormatSeq.getArray(), aFormatSeq.getLength() ); // General - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_NUMBER_STANDARD ); - SvNumberformat* pStdFormat = ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_NUMBER_STANDARD ); + SvNumberformat* pStdFormat = ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD /* NF_NUMBER_STANDARD */ ); if (pStdFormat) { // This is _the_ standard format. if (LocaleDataWrapper::areChecksEnabled() && pStdFormat->GetType() != SvNumFormatType::NUMBER) { - LocaleDataWrapper::outputCheckMessage( xLocaleData-> + LocaleDataWrapper::outputCheckMessage( rCurrentLanguage.xLocaleData-> appendLocaleInfo( u"SvNumberFormatter::ImpGenerateFormats: General format not NUMBER")); } pStdFormat->SetType( SvNumFormatType::NUMBER ); @@ -2571,18 +2939,18 @@ void SvNumberFormatter::ImpGenerateFormats( sal_uInt32 CLOffset, bool bNoAdditio { if (LocaleDataWrapper::areChecksEnabled()) { - LocaleDataWrapper::outputCheckMessage( xLocaleData-> + LocaleDataWrapper::outputCheckMessage( rCurrentLanguage.xLocaleData-> appendLocaleInfo( u"SvNumberFormatter::ImpGenerateFormats: General format not insertable, nothing will work")); } } { // Boolean - OUString aFormatCode = pFormatScanner->GetBooleanString(); + OUString aFormatCode = rCurrentLanguage.pFormatScanner->GetBooleanString(); sal_Int32 nCheckPos = 0; - std::unique_ptr<SvNumberformat> pNewFormat(new SvNumberformat( aFormatCode, pFormatScanner.get(), - pStringScanner.get(), nCheckPos, ActLnge )); + std::unique_ptr<SvNumberformat> pNewFormat(new SvNumberformat( aFormatCode, rCurrentLanguage.pFormatScanner.get(), + rCurrentLanguage.pStringScanner.get(), pNatNum, nCheckPos, rCurrentLanguage.ActLnge )); pNewFormat->SetType(SvNumFormatType::LOGICAL); pNewFormat->SetStandard(); if ( !aFTable.emplace(CLOffset + ZF_STANDARD_LOGICAL /* NF_BOOLEAN */, @@ -2593,8 +2961,8 @@ void SvNumberFormatter::ImpGenerateFormats( sal_uInt32 CLOffset, bool bNoAdditio // Text aFormatCode = "@"; - pNewFormat.reset(new SvNumberformat( aFormatCode, pFormatScanner.get(), - pStringScanner.get(), nCheckPos, ActLnge )); + pNewFormat.reset(new SvNumberformat( aFormatCode, rCurrentLanguage.pFormatScanner.get(), + rCurrentLanguage.pStringScanner.get(), pNatNum, nCheckPos, rCurrentLanguage.ActLnge )); pNewFormat->SetType(SvNumFormatType::TEXT); pNewFormat->SetStandard(); if ( !aFTable.emplace( CLOffset + ZF_STANDARD_TEXT /* NF_TEXT */, @@ -2605,43 +2973,43 @@ void SvNumberFormatter::ImpGenerateFormats( sal_uInt32 CLOffset, bool bNoAdditio } // 0 - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_NUMBER_INT ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_NUMBER_INT ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD+1 /* NF_NUMBER_INT */ ); // 0.00 - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_NUMBER_DEC2 ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_NUMBER_DEC2 ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD+2 /* NF_NUMBER_DEC2 */ ); // #,##0 - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_NUMBER_1000INT ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_NUMBER_1000INT ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD+3 /* NF_NUMBER_1000INT */ ); // #,##0.00 - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_NUMBER_1000DEC2 ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_NUMBER_1000DEC2 ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD+4 /* NF_NUMBER_1000DEC2 */ ); // #.##0,00 System country/language dependent - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_NUMBER_SYSTEM ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_NUMBER_SYSTEM ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD+5 /* NF_NUMBER_SYSTEM */ ); // Percent number aFormatSeq = xNFC->getAllFormatCode( i18n::KNumberFormatUsage::PERCENT_NUMBER, aLocale ); - ImpAdjustFormatCodeDefault( aFormatSeq.getArray(), aFormatSeq.getLength() ); + ImpAdjustFormatCodeDefault(rCurrentLanguage, aFormatSeq.getArray(), aFormatSeq.getLength() ); // 0% - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_PERCENT_INT ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_PERCENT_INT ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_PERCENT /* NF_PERCENT_INT */ ); // 0.00% - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_PERCENT_DEC2 ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_PERCENT_DEC2 ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_PERCENT+1 /* NF_PERCENT_DEC2 */ ); @@ -2651,223 +3019,223 @@ void SvNumberFormatter::ImpGenerateFormats( sal_uInt32 CLOffset, bool bNoAdditio if (LocaleDataWrapper::areChecksEnabled()) { // though no default desired here, test for correctness of locale data - ImpAdjustFormatCodeDefault( aFormatSeq.getArray(), aFormatSeq.getLength() ); + ImpAdjustFormatCodeDefault(rCurrentLanguage, aFormatSeq.getArray(), aFormatSeq.getLength() ); } // #,##0 - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_CURRENCY_1000INT ); + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_CURRENCY_1000INT ); // Just copy the format, to avoid COW on sequence after each possible reallocation auto aFormat = aFormatSeq[nIdx]; aFormat.Default = false; - ImpInsertFormat( aFormat, + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormat, CLOffset + ZF_STANDARD_CURRENCY /* NF_CURRENCY_1000INT */ ); // #,##0.00 - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_CURRENCY_1000DEC2 ); + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_CURRENCY_1000DEC2 ); aFormat = aFormatSeq[nIdx]; aFormat.Default = false; - ImpInsertFormat( aFormat, + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormat, CLOffset + ZF_STANDARD_CURRENCY+1 /* NF_CURRENCY_1000DEC2 */ ); // #,##0 negative red - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_CURRENCY_1000INT_RED ); + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_CURRENCY_1000INT_RED ); aFormat = aFormatSeq[nIdx]; aFormat.Default = false; - ImpInsertFormat(aFormat, + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormat, CLOffset + ZF_STANDARD_CURRENCY+2 /* NF_CURRENCY_1000INT_RED */ ); // #,##0.00 negative red - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_CURRENCY_1000DEC2_RED ); + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_CURRENCY_1000DEC2_RED ); aFormat = aFormatSeq[nIdx]; aFormat.Default = false; - ImpInsertFormat(aFormat, + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormat, CLOffset + ZF_STANDARD_CURRENCY+3 /* NF_CURRENCY_1000DEC2_RED */ ); // #,##0.00 USD - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_CURRENCY_1000DEC2_CCC ); + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_CURRENCY_1000DEC2_CCC ); aFormat = aFormatSeq[nIdx]; aFormat.Default = false; - ImpInsertFormat( aFormat, + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormat, CLOffset + ZF_STANDARD_CURRENCY+4 /* NF_CURRENCY_1000DEC2_CCC */ ); // #.##0,-- - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_CURRENCY_1000DEC2_DASHED ); + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_CURRENCY_1000DEC2_DASHED ); aFormat = aFormatSeq[nIdx]; aFormat.Default = false; - ImpInsertFormat(aFormat, + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormat, CLOffset + ZF_STANDARD_CURRENCY+5 /* NF_CURRENCY_1000DEC2_DASHED */ ); // Date aFormatSeq = xNFC->getAllFormatCode( i18n::KNumberFormatUsage::DATE, aLocale ); - ImpAdjustFormatCodeDefault( aFormatSeq.getArray(), aFormatSeq.getLength() ); + ImpAdjustFormatCodeDefault(rCurrentLanguage, aFormatSeq.getArray(), aFormatSeq.getLength() ); // DD.MM.YY System - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_SYSTEM_SHORT ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_DATE_SYSTEM_SHORT ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_DATE /* NF_DATE_SYSTEM_SHORT */ ); // NN DD.MMM YY - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_DEF_NNDDMMMYY ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_DATE_DEF_NNDDMMMYY ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_DATE+1 /* NF_DATE_DEF_NNDDMMMYY */ ); // DD.MM.YY def/System - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_SYS_MMYY ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_DATE_SYS_MMYY ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_DATE+2 /* NF_DATE_SYS_MMYY */ ); // DD MMM - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_SYS_DDMMM ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_DATE_SYS_DDMMM ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_DATE+3 /* NF_DATE_SYS_DDMMM */ ); // MMMM - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_MMMM ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_DATE_MMMM ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_DATE+4 /* NF_DATE_MMMM */ ); // QQ YY - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_QQJJ ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_DATE_QQJJ ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_DATE+5 /* NF_DATE_QQJJ */ ); // DD.MM.YYYY was DD.MM.[YY]YY - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_SYS_DDMMYYYY ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_DATE_SYS_DDMMYYYY ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_DATE+6 /* NF_DATE_SYS_DDMMYYYY */ ); // DD.MM.YY def/System - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_SYS_DDMMYY ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_DATE_SYS_DDMMYY ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_DATE+7 /* NF_DATE_SYS_DDMMYY */ ); // NNN, D. MMMM YYYY System // Long day of week: "NNNN" instead of "NNN," because of compatibility - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_SYSTEM_LONG ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_DATE_SYSTEM_LONG ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_DATE+8 /* NF_DATE_SYSTEM_LONG */ ); // Hard coded but system (regional settings) delimiters dependent long date formats // D. MMM YY def/System - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_SYS_DMMMYY ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_DATE_SYS_DMMMYY ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_DATE+9 /* NF_DATE_SYS_DMMMYY */ ); // D. MMM YYYY def/System - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_SYS_DMMMYYYY ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_DATE_SYS_DMMMYYYY ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_DATE_SYS_DMMMYYYY /* NF_DATE_SYS_DMMMYYYY */ ); // D. MMMM YYYY def/System - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_SYS_DMMMMYYYY ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_DATE_SYS_DMMMMYYYY ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_DATE_SYS_DMMMMYYYY /* NF_DATE_SYS_DMMMMYYYY */ ); // NN, D. MMM YY def/System - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_SYS_NNDMMMYY ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_DATE_SYS_NNDMMMYY ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_DATE_SYS_NNDMMMYY /* NF_DATE_SYS_NNDMMMYY */ ); // NN, D. MMMM YYYY def/System - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_SYS_NNDMMMMYYYY ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_DATE_SYS_NNDMMMMYYYY ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_DATE_SYS_NNDMMMMYYYY /* NF_DATE_SYS_NNDMMMMYYYY */ ); // NNN, D. MMMM YYYY def/System - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_SYS_NNNNDMMMMYYYY ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_DATE_SYS_NNNNDMMMMYYYY ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_DATE_SYS_NNNNDMMMMYYYY /* NF_DATE_SYS_NNNNDMMMMYYYY */ ); // Hard coded DIN (Deutsche Industrie Norm) and EN (European Norm) date formats // D. MMM. YYYY DIN/EN - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_DIN_DMMMYYYY ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_DATE_DIN_DMMMYYYY ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_DATE_DIN_DMMMYYYY /* NF_DATE_DIN_DMMMYYYY */ ); // D. MMMM YYYY DIN/EN - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_DIN_DMMMMYYYY ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_DATE_DIN_DMMMMYYYY ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_DATE_DIN_DMMMMYYYY /* NF_DATE_DIN_DMMMMYYYY */ ); // MM-DD DIN/EN - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_DIN_MMDD ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_DATE_DIN_MMDD ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_DATE_DIN_MMDD /* NF_DATE_DIN_MMDD */ ); // YY-MM-DD DIN/EN - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_DIN_YYMMDD ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_DATE_DIN_YYMMDD ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_DATE_DIN_YYMMDD /* NF_DATE_DIN_YYMMDD */ ); // YYYY-MM-DD DIN/EN/ISO - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_DIN_YYYYMMDD ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_DATE_DIN_YYYYMMDD ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_DATE_DIN_YYYYMMDD /* NF_DATE_DIN_YYYYMMDD */ ); // Time aFormatSeq = xNFC->getAllFormatCode( i18n::KNumberFormatUsage::TIME, aLocale ); - ImpAdjustFormatCodeDefault( aFormatSeq.getArray(), aFormatSeq.getLength() ); + ImpAdjustFormatCodeDefault(rCurrentLanguage, aFormatSeq.getArray(), aFormatSeq.getLength() ); // HH:MM - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_TIME_HHMM ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_TIME_HHMM ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_TIME /* NF_TIME_HHMM */ ); // HH:MM:SS - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_TIME_HHMMSS ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_TIME_HHMMSS ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_TIME+1 /* NF_TIME_HHMMSS */ ); // HH:MM AM/PM - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_TIME_HHMMAMPM ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_TIME_HHMMAMPM ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_TIME+2 /* NF_TIME_HHMMAMPM */ ); // HH:MM:SS AM/PM - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_TIME_HHMMSSAMPM ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_TIME_HHMMSSAMPM ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_TIME+3 /* NF_TIME_HHMMSSAMPM */ ); // [HH]:MM:SS - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_TIME_HH_MMSS ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_TIME_HH_MMSS ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_TIME+4 /* NF_TIME_HH_MMSS */ ); // MM:SS,00 - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_TIME_MMSS00 ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_TIME_MMSS00 ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_TIME+5 /* NF_TIME_MMSS00 */ ); // [HH]:MM:SS,00 - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_TIME_HH_MMSS00 ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_TIME_HH_MMSS00 ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_TIME+6 /* NF_TIME_HH_MMSS00 */ ); // DateTime aFormatSeq = xNFC->getAllFormatCode( i18n::KNumberFormatUsage::DATE_TIME, aLocale ); - ImpAdjustFormatCodeDefault( aFormatSeq.getArray(), aFormatSeq.getLength() ); + ImpAdjustFormatCodeDefault(rCurrentLanguage, aFormatSeq.getArray(), aFormatSeq.getLength() ); // DD.MM.YY HH:MM System - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATETIME_SYSTEM_SHORT_HHMM ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_DATETIME_SYSTEM_SHORT_HHMM ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_DATETIME /* NF_DATETIME_SYSTEM_SHORT_HHMM */ ); // DD.MM.YYYY HH:MM:SS System - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATETIME_SYS_DDMMYYYY_HHMMSS ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_DATETIME_SYS_DDMMYYYY_HHMMSS ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_DATETIME+1 /* NF_DATETIME_SYS_DDMMYYYY_HHMMSS */ ); // DD.MM.YYYY HH:MM System - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATETIME_SYS_DDMMYYYY_HHMM ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_DATETIME_SYS_DDMMYYYY_HHMM ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_DATETIME+2 /* NF_DATETIME_SYS_DDMMYYYY_HHMM */ ); - const NfKeywordTable & rKeyword = pFormatScanner->GetKeywords(); + const NfKeywordTable & rKeyword = rCurrentLanguage.pFormatScanner->GetKeywords(); i18n::NumberFormatCode aSingleFormatCode; aSingleFormatCode.Usage = i18n::KNumberFormatUsage::DATE_TIME; @@ -2879,7 +3247,7 @@ void SvNumberFormatter::ImpGenerateFormats( sal_uInt32 CLOffset, bool bNoAdditio rKeyword[NF_KEY_HH] + ":" + rKeyword[NF_KEY_MMI] + ":" + rKeyword[NF_KEY_SS]; - SvNumberformat* pFormat = ImpInsertFormat( aSingleFormatCode, + SvNumberformat* pFormat = ImpInsertFormat(rCurrentLanguage, pNatNum, aSingleFormatCode, CLOffset + ZF_STANDARD_DATETIME+3 /* NF_DATETIME_ISO_YYYYMMDD_HHMMSS */ ); assert(pFormat); @@ -2891,9 +3259,9 @@ void SvNumberFormatter::ImpGenerateFormats( sal_uInt32 CLOffset, bool bNoAdditio rKeyword[NF_KEY_DD] + " " + rKeyword[NF_KEY_HH] + ":" + rKeyword[NF_KEY_MMI] + ":" + - rKeyword[NF_KEY_SS] + GetLocaleData()->getTime100SecSep() + + rKeyword[NF_KEY_SS] + rCurrentLanguage.GetLocaleData()->getTime100SecSep() + "000"; - pFormat = ImpInsertFormat( aSingleFormatCode, + pFormat = ImpInsertFormat(rCurrentLanguage, pNatNum, aSingleFormatCode, CLOffset + ZF_STANDARD_DATETIME+4 /* NF_DATETIME_ISO_YYYYMMDD_HHMMSS000 */ ); assert(pFormat); @@ -2905,7 +3273,7 @@ void SvNumberFormatter::ImpGenerateFormats( sal_uInt32 CLOffset, bool bNoAdditio rKeyword[NF_KEY_HH] + ":" + rKeyword[NF_KEY_MMI] + ":" + rKeyword[NF_KEY_SS]; - pFormat = ImpInsertFormat( aSingleFormatCode, + pFormat = ImpInsertFormat(rCurrentLanguage, pNatNum, aSingleFormatCode, CLOffset + ZF_STANDARD_DATETIME+5 /* NF_DATETIME_ISO_YYYYMMDDTHHMMSS */ ); assert(pFormat); pFormat->SetComment("ISO 8601"); // not to be localized @@ -2917,9 +3285,9 @@ void SvNumberFormatter::ImpGenerateFormats( sal_uInt32 CLOffset, bool bNoAdditio rKeyword[NF_KEY_DD] + "\"T\"" + rKeyword[NF_KEY_HH] + ":" + rKeyword[NF_KEY_MMI] + ":" + - rKeyword[NF_KEY_SS] + (GetLocaleData()->getTime100SecSep() == "." ? "." : ",") + + rKeyword[NF_KEY_SS] + (rCurrentLanguage.GetLocaleData()->getTime100SecSep() == "." ? "." : ",") + "000"; - pFormat = ImpInsertFormat( aSingleFormatCode, + pFormat = ImpInsertFormat(rCurrentLanguage, pNatNum, aSingleFormatCode, CLOffset + ZF_STANDARD_DATETIME+6 /* NF_DATETIME_ISO_YYYYMMDDTHHMMSS000 */ ); assert(pFormat); pFormat->SetComment("ISO 8601"); // not to be localized @@ -2927,16 +3295,16 @@ void SvNumberFormatter::ImpGenerateFormats( sal_uInt32 CLOffset, bool bNoAdditio // Scientific number aFormatSeq = xNFC->getAllFormatCode( i18n::KNumberFormatUsage::SCIENTIFIC_NUMBER, aLocale ); - ImpAdjustFormatCodeDefault( aFormatSeq.getArray(), aFormatSeq.getLength() ); + ImpAdjustFormatCodeDefault(rCurrentLanguage, aFormatSeq.getArray(), aFormatSeq.getLength() ); // 0.00E+000 - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_SCIENTIFIC_000E000 ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_SCIENTIFIC_000E000 ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_SCIENTIFIC /* NF_SCIENTIFIC_000E000 */ ); // 0.00E+00 - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_SCIENTIFIC_000E00 ); - ImpInsertFormat( aFormatSeq[nIdx], + nIdx = ImpGetFormatCodeIndex(rCurrentLanguage, aFormatSeq, NF_SCIENTIFIC_000E00 ); + ImpInsertFormat(rCurrentLanguage, pNatNum, aFormatSeq[nIdx], CLOffset + ZF_STANDARD_SCIENTIFIC+1 /* NF_SCIENTIFIC_000E00 */ ); @@ -2945,71 +3313,71 @@ void SvNumberFormatter::ImpGenerateFormats( sal_uInt32 CLOffset, bool bNoAdditio // # ?/? aSingleFormatCode.Code = "# ?/?"; - ImpInsertFormat( aSingleFormatCode, + ImpInsertFormat(rCurrentLanguage, pNatNum, aSingleFormatCode, CLOffset + ZF_STANDARD_FRACTION /* NF_FRACTION_1D */ ); // # ??/?? //! "??/" would be interpreted by the compiler as a trigraph for '\' aSingleFormatCode.Code = "# ?\?/?\?"; - ImpInsertFormat( aSingleFormatCode, + ImpInsertFormat(rCurrentLanguage, pNatNum, aSingleFormatCode, CLOffset + ZF_STANDARD_FRACTION+1 /* NF_FRACTION_2D */ ); // # ???/??? //! "??/" would be interpreted by the compiler as a trigraph for '\' aSingleFormatCode.Code = "# ?\?\?/?\?\?"; - ImpInsertFormat( aSingleFormatCode, + ImpInsertFormat(rCurrentLanguage, pNatNum, aSingleFormatCode, CLOffset + ZF_STANDARD_FRACTION+2 /* NF_FRACTION_3D */ ); // # ?/2 aSingleFormatCode.Code = "# ?/2"; - ImpInsertFormat( aSingleFormatCode, + ImpInsertFormat(rCurrentLanguage, pNatNum, aSingleFormatCode, CLOffset + ZF_STANDARD_FRACTION+3 /* NF_FRACTION_2 */ ); // # ?/4 aSingleFormatCode.Code = "# ?/4"; - ImpInsertFormat( aSingleFormatCode, + ImpInsertFormat(rCurrentLanguage, pNatNum, aSingleFormatCode, CLOffset + ZF_STANDARD_FRACTION+4 /* NF_FRACTION_4 */ ); // # ?/8 aSingleFormatCode.Code = "# ?/8"; - ImpInsertFormat( aSingleFormatCode, + ImpInsertFormat(rCurrentLanguage, pNatNum, aSingleFormatCode, CLOffset + ZF_STANDARD_FRACTION+5 /* NF_FRACTION_8 */ ); // # ??/16 aSingleFormatCode.Code = "# ?\?/16"; - ImpInsertFormat( aSingleFormatCode, + ImpInsertFormat(rCurrentLanguage, pNatNum, aSingleFormatCode, CLOffset + ZF_STANDARD_FRACTION+6 /* NF_FRACTION_16 */ ); // # ??/10 aSingleFormatCode.Code = "# ?\?/10"; - ImpInsertFormat( aSingleFormatCode, + ImpInsertFormat(rCurrentLanguage, pNatNum, aSingleFormatCode, CLOffset + ZF_STANDARD_FRACTION+7 /* NF_FRACTION_10 */ ); // # ??/100 aSingleFormatCode.Code = "# ?\?/100"; - ImpInsertFormat( aSingleFormatCode, + ImpInsertFormat(rCurrentLanguage, pNatNum, aSingleFormatCode, CLOffset + ZF_STANDARD_FRACTION+8 /* NF_FRACTION_100 */ ); // Week of year aSingleFormatCode.Code = rKeyword[NF_KEY_WW]; - ImpInsertFormat( aSingleFormatCode, + ImpInsertFormat(rCurrentLanguage, pNatNum, aSingleFormatCode, CLOffset + ZF_STANDARD_DATE_WW /* NF_DATE_WW */ ); // Now all additional format codes provided by I18N, but only if not // changing SystemCL, then they are appended last after user defined. if ( !bNoAdditionalFormats ) { - ImpGenerateAdditionalFormats( CLOffset, xNFC, false ); + ImpGenerateAdditionalFormats(rCurrentLanguage, pNatNum, CLOffset, xNFC, false); } if (bOldConvertMode) { - pFormatScanner->SetConvertMode(true); + rCurrentLanguage.pFormatScanner->SetConvertMode(true); } } - -void SvNumberFormatter::ImpGenerateAdditionalFormats( sal_uInt32 CLOffset, +void SvNFFormatData::ImpGenerateAdditionalFormats(SvNFLanguageData& rCurrentLanguage, + const NativeNumberWrapper* pNatNum, sal_uInt32 CLOffset, css::uno::Reference< css::i18n::XNumberFormatCode > const & rNumberFormatCode, bool bAfterChangingSystemCL ) { @@ -3020,14 +3388,14 @@ void SvNumberFormatter::ImpGenerateAdditionalFormats( sal_uInt32 CLOffset, return ; } sal_uInt32 nPos = CLOffset + pStdFormat->GetLastInsertKey( SvNumberformat::FormatterPrivateAccess() ); - css::lang::Locale aLocale = GetLanguageTag().getLocale(); + css::lang::Locale aLocale = rCurrentLanguage.GetLanguageTag().getLocale(); // All currencies, this time with [$...] which was stripped in // ImpGenerateFormats for old "automatic" currency formats. uno::Sequence< i18n::NumberFormatCode > aFormatSeq = rNumberFormatCode->getAllFormatCode( i18n::KNumberFormatUsage::CURRENCY, aLocale ); sal_Int32 nCodes = aFormatSeq.getLength(); auto aNonConstRange = asNonConstRange(aFormatSeq); - ImpAdjustFormatCodeDefault( aNonConstRange.begin(), nCodes); + ImpAdjustFormatCodeDefault(rCurrentLanguage, aNonConstRange.begin(), nCodes); for ( i18n::NumberFormatCode& rFormat : aNonConstRange ) { if ( nPos - CLOffset >= SV_COUNTRY_LANGUAGE_OFFSET ) @@ -3045,7 +3413,7 @@ void SvNumberFormatter::ImpGenerateAdditionalFormats( sal_uInt32 CLOffset, //! no default on currency bool bDefault = rFormat.Default; rFormat.Default = false; - if ( SvNumberformat* pNewFormat = ImpInsertFormat( rFormat, nPos+1, + if ( SvNumberformat* pNewFormat = ImpInsertFormat(rCurrentLanguage, pNatNum, rFormat, nPos+1, bAfterChangingSystemCL, nOrgIndex ) ) { pNewFormat->SetAdditionalBuiltin(); @@ -3063,7 +3431,7 @@ void SvNumberFormatter::ImpGenerateAdditionalFormats( sal_uInt32 CLOffset, // There is no harm though, on first invocation ImpGetDefaultFormat() will // use the first default encountered. aFormatSeq = rNumberFormatCode->getAllFormatCodes( aLocale ); - for (const auto& rFormat : aFormatSeq) + for ( const auto& rFormat : std::as_const(aFormatSeq) ) { if ( nPos - CLOffset >= SV_COUNTRY_LANGUAGE_OFFSET ) { @@ -3072,7 +3440,7 @@ void SvNumberFormatter::ImpGenerateAdditionalFormats( sal_uInt32 CLOffset, } if ( rFormat.Index >= NF_INDEX_TABLE_RESERVED_START ) { - if ( SvNumberformat* pNewFormat = ImpInsertFormat( rFormat, nPos+1, + if ( SvNumberformat* pNewFormat = ImpInsertFormat(rCurrentLanguage, pNatNum, rFormat, nPos+1, bAfterChangingSystemCL ) ) { pNewFormat->SetAdditionalBuiltin(); @@ -3084,6 +3452,13 @@ void SvNumberFormatter::ImpGenerateAdditionalFormats( sal_uInt32 CLOffset, pStdFormat->SetLastInsertKey( static_cast<sal_uInt16>(nPos - CLOffset), SvNumberformat::FormatterPrivateAccess() ); } +void SvNumberFormatter::ImpGenerateAdditionalFormats( sal_uInt32 CLOffset, + css::uno::Reference< css::i18n::XNumberFormatCode > const & rNumberFormatCode, + bool bAfterChangingSystemCL ) +{ + m_aFormatData.ImpGenerateAdditionalFormats(m_aCurrentLanguage, GetNatNum(), CLOffset, rNumberFormatCode, bAfterChangingSystemCL); +} + namespace { // return position of a special character @@ -3122,28 +3497,26 @@ sal_Int32 ImpPosToken(const OUStringBuffer & sFormat, sal_Unicode token, sal_Int } -OUString SvNumberFormatter::GenerateFormat(sal_uInt32 nIndex, - LanguageType eLnge, - bool bThousand, - bool IsRed, - sal_uInt16 nPrecision, - sal_uInt16 nLeadingZeros) +OUString SvNFEngine::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) { - ::osl::MutexGuard aGuard( GetInstanceMutex() ); - if (eLnge == LANGUAGE_DONTKNOW) - { - eLnge = IniLnge; - } - - const SvNumberformat* pFormat = GetFormatEntry( nIndex ); + eLnge = rCurrentLanguage.ImpResolveLanguage(eLnge); + const SvNumberformat* pFormat = rFormatData.GetFormatEntry( nIndex ); const SvNumFormatType eType = (pFormat ? pFormat->GetMaskedType() : SvNumFormatType::UNDEFINED); - ImpGenerateCL(eLnge); // create new standard formats if necessary + rFuncs.mGetCLOffset(rCurrentLanguage, pNatNum, eLnge); // create new standard formats if necessary (and allowed) - utl::DigitGroupingIterator aGrouping( xLocaleData->getDigitGrouping()); + utl::DigitGroupingIterator aGrouping( rCurrentLanguage.xLocaleData->getDigitGrouping()); // always group of 3 for Engineering notation const sal_Int32 nDigitsInFirstGroup = ( bThousand && (eType == SvNumFormatType::SCIENTIFIC) ) ? 3 : aGrouping.get(); - const OUString& rThSep = GetNumThousandSep(); + const OUString& rThSep = rCurrentLanguage.GetNumThousandSep(); OUStringBuffer sString; using comphelper::string::padToLength; @@ -3194,7 +3567,7 @@ OUString SvNumberFormatter::GenerateFormat(sal_uInt32 nIndex, } if (nPrecision > 0 && eType != SvNumFormatType::FRACTION && !( eType & SvNumFormatType::TIME ) ) { - sString.append(GetNumDecimalSep()); + sString.append(rCurrentLanguage.GetNumDecimalSep()); padToLength(sString, sString.getLength() + nPrecision, '0'); } @@ -3233,15 +3606,15 @@ OUString SvNumberFormatter::GenerateFormat(sal_uInt32 nIndex, bool isNegNatNum12 = sNegNatNumModifier.startsWith( "[NatNum12" ); if ( !isPosNatNum12 || !isNegNatNum12 ) { - if ( GetNewCurrencySymbolString( nIndex, aCurr, &pEntry, &bBank ) ) + if (rFormatData.GetNewCurrencySymbolString(nIndex, aCurr, &pEntry, &bBank)) { if ( pEntry ) { sal_uInt16 nPosiForm = NfCurrencyEntry::GetEffectivePositiveFormat( - xLocaleData->getCurrPositiveFormat(), + rCurrentLanguage.xLocaleData->getCurrPositiveFormat(), pEntry->GetPositiveFormat(), bBank ); sal_uInt16 nNegaForm = NfCurrencyEntry::GetEffectiveNegativeFormat( - xLocaleData->getCurrNegativeFormat(), + rCurrentLanguage.xLocaleData->getCurrNegativeFormat(), pEntry->GetNegativeFormat(), bBank ); if ( !isPosNatNum12 ) pEntry->CompletePositiveFormatString( sString, bBank, nPosiForm ); @@ -3251,11 +3624,11 @@ OUString SvNumberFormatter::GenerateFormat(sal_uInt32 nIndex, else { // assume currency abbreviation (AKA banking symbol), not symbol sal_uInt16 nPosiForm = NfCurrencyEntry::GetEffectivePositiveFormat( - xLocaleData->getCurrPositiveFormat(), - xLocaleData->getCurrPositiveFormat(), true ); + rCurrentLanguage.xLocaleData->getCurrPositiveFormat(), + rCurrentLanguage.xLocaleData->getCurrPositiveFormat(), true ); sal_uInt16 nNegaForm = NfCurrencyEntry::GetEffectiveNegativeFormat( - xLocaleData->getCurrNegativeFormat(), - xLocaleData->getCurrNegativeFormat(), true ); + rCurrentLanguage.xLocaleData->getCurrNegativeFormat(), + rCurrentLanguage.xLocaleData->getCurrNegativeFormat(), true ); if ( !isPosNatNum12 ) NfCurrencyEntry::CompletePositiveFormatString( sString, aCurr, nPosiForm ); if ( !isNegNatNum12 ) @@ -3265,19 +3638,19 @@ OUString SvNumberFormatter::GenerateFormat(sal_uInt32 nIndex, else { // "automatic" old style OUString aSymbol, aAbbrev; - GetCompatibilityCurrency( aSymbol, aAbbrev ); + rCurrentLanguage.GetCompatibilityCurrency(aSymbol, aAbbrev); if ( !isPosNatNum12 ) NfCurrencyEntry::CompletePositiveFormatString( sString, - aSymbol, xLocaleData->getCurrPositiveFormat() ); + aSymbol, rCurrentLanguage.xLocaleData->getCurrPositiveFormat() ); if ( !isNegNatNum12 ) NfCurrencyEntry::CompleteNegativeFormatString( sNegStr, - aSymbol, xLocaleData->getCurrNegativeFormat() ); + aSymbol, rCurrentLanguage.xLocaleData->getCurrNegativeFormat() ); } } sString.append( ';' ); if (IsRed) { - sString.append("[" +pFormatScanner->GetRedString() + "]"); + sString.append("[" + rCurrentLanguage.pFormatScanner->GetRedString() + "]"); } sString.append( sNegNatNumModifier ); if ( isNegNatNum12 ) @@ -3321,7 +3694,7 @@ OUString SvNumberFormatter::GenerateFormat(sal_uInt32 nIndex, if (IsRed) { - sTmpStr.append("[" + pFormatScanner->GetRedString() + "]"); + sTmpStr.append("[" + rCurrentLanguage.pFormatScanner->GetRedString() + "]"); } sTmpStr.append( sNegNatNumModifier ); @@ -3340,10 +3713,25 @@ OUString SvNumberFormatter::GenerateFormat(sal_uInt32 nIndex, return sString.makeStringAndClear(); } +OUString SvNumberFormatter::GenerateFormat(sal_uInt32 nIndex, + LanguageType eLnge, + bool bThousand, + bool IsRed, + sal_uInt16 nPrecision, + sal_uInt16 nLeadingZeros) +{ + ::osl::MutexGuard aGuard( GetInstanceMutex() ); + return SvNFEngine::GenerateFormat(m_aCurrentLanguage, m_aFormatData, + GetNatNum(), m_aRWPolicy, + nIndex, eLnge, + bThousand, IsRed, + nPrecision, nLeadingZeros); +} + bool SvNumberFormatter::IsUserDefined(sal_uInt32 F_Index) const { ::osl::MutexGuard aGuard( GetInstanceMutex() ); - const SvNumberformat* pFormat = GetFormatEntry(F_Index); + const SvNumberformat* pFormat = m_aFormatData.GetFormatEntry(F_Index); return pFormat && (pFormat->GetType() & SvNumFormatType::DEFINED); } @@ -3356,15 +3744,15 @@ bool SvNumberFormatter::IsUserDefined(std::u16string_view sStr, { eLnge = IniLnge; } - sal_uInt32 CLOffset = ImpGenerateCL(eLnge); // create new standard formats if necessary - eLnge = ActLnge; + sal_uInt32 CLOffset = m_aFormatData.ImpGenerateCL(m_aCurrentLanguage, GetNatNum(), eLnge); // create new standard formats if necessary + eLnge = m_aCurrentLanguage.ActLnge; sal_uInt32 nKey = ImpIsEntry(sStr, CLOffset, eLnge); if (nKey == NUMBERFORMAT_ENTRY_NOT_FOUND) { return true; } - SvNumberformat* pEntry = GetFormatEntry( nKey ); + SvNumberformat* pEntry = m_aFormatData.GetFormatEntry( nKey ); return pEntry && (pEntry->GetType() & SvNumFormatType::DEFINED); } @@ -3376,38 +3764,32 @@ sal_uInt32 SvNumberFormatter::GetEntryKey(std::u16string_view sStr, { eLnge = IniLnge; } - sal_uInt32 CLOffset = ImpGenerateCL(eLnge); // create new standard formats if necessary + sal_uInt32 CLOffset = m_aFormatData.ImpGenerateCL(m_aCurrentLanguage, GetNatNum(), eLnge); // create new standard formats if necessary return ImpIsEntry(sStr, CLOffset, eLnge); } +sal_uInt32 SvNFEngine::GetStandardIndex(SvNFLanguageData& rCurrentLanguage, + const SvNFFormatData& rFormatData, + const NativeNumberWrapper* pNatNum, + const Accessor& rFuncs, + LanguageType eLnge) +{ + return SvNFEngine::GetStandardFormat(rCurrentLanguage, rFormatData, + pNatNum, rFuncs, + SvNumFormatType::NUMBER, eLnge); +} + sal_uInt32 SvNumberFormatter::GetStandardIndex(LanguageType eLnge) { ::osl::MutexGuard aGuard( GetInstanceMutex() ); - if (eLnge == LANGUAGE_DONTKNOW) - { - eLnge = IniLnge; - } - return GetStandardFormat(SvNumFormatType::NUMBER, eLnge); + return SvNFEngine::GetStandardIndex(m_aCurrentLanguage, m_aFormatData, GetNatNum(), + m_aRWPolicy, eLnge); } SvNumFormatType SvNumberFormatter::GetType(sal_uInt32 nFIndex) const { - ::osl::MutexGuard aGuard( GetInstanceMutex() ); - SvNumFormatType eType; - const SvNumberformat* pFormat = GetFormatEntry( nFIndex ); - if (!pFormat) - { - eType = SvNumFormatType::UNDEFINED; - } - else - { - eType = pFormat->GetMaskedType(); - if (eType == SvNumFormatType::ALL) - { - eType = SvNumFormatType::DEFINED; - } - } - return eType; + ::osl::MutexGuard aGuard(GetInstanceMutex()); + return m_aFormatData.GetType(nFIndex); } void SvNumberFormatter::ClearMergeTable() @@ -3434,22 +3816,22 @@ SvNumberFormatterIndexTable* SvNumberFormatter::MergeFormatter(SvNumberFormatter sal_uInt32 nCLOffset = 0; sal_uInt32 nOldKey, nOffset, nNewKey; - for (const auto& rEntry : rTable.aFTable) + for (const auto& rEntry : rTable.m_aFormatData.aFTable) { SvNumberformat* pFormat = rEntry.second.get(); nOldKey = rEntry.first; nOffset = nOldKey % SV_COUNTRY_LANGUAGE_OFFSET; // relative index if (nOffset == 0) // 1st format of CL { - nCLOffset = ImpGenerateCL(pFormat->GetLanguage()); + nCLOffset = m_aFormatData.ImpGenerateCL(m_aCurrentLanguage, GetNatNum(), pFormat->GetLanguage()); } if (nOffset <= SV_MAX_COUNT_STANDARD_FORMATS) // Std.form. { nNewKey = nCLOffset + nOffset; - if (aFTable.find( nNewKey) == aFTable.end()) // not already present + if (m_aFormatData.aFTable.find( nNewKey) == m_aFormatData.aFTable.end()) // not already present { - std::unique_ptr<SvNumberformat> pNewEntry(new SvNumberformat( *pFormat, *pFormatScanner )); - if (!aFTable.emplace( nNewKey, std::move(pNewEntry)).second) + std::unique_ptr<SvNumberformat> pNewEntry(new SvNumberformat( *pFormat, *m_aCurrentLanguage.pFormatScanner )); + if (!m_aFormatData.aFTable.emplace( nNewKey, std::move(pNewEntry)).second) { SAL_WARN( "svl.numbers", "SvNumberFormatter::MergeFormatter: dup position"); } @@ -3461,20 +3843,20 @@ SvNumberFormatterIndexTable* SvNumberFormatter::MergeFormatter(SvNumberFormatter } else // user defined { - std::unique_ptr<SvNumberformat> pNewEntry(new SvNumberformat( *pFormat, *pFormatScanner )); + std::unique_ptr<SvNumberformat> pNewEntry(new SvNumberformat( *pFormat, *m_aCurrentLanguage.pFormatScanner )); nNewKey = ImpIsEntry(pNewEntry->GetFormatstring(), nCLOffset, pFormat->GetLanguage()); if (nNewKey == NUMBERFORMAT_ENTRY_NOT_FOUND) // only if not present yet { - SvNumberformat* pStdFormat = GetFormatEntry(nCLOffset + ZF_STANDARD); + SvNumberformat* pStdFormat = m_aFormatData.GetFormatEntry(nCLOffset + ZF_STANDARD); sal_uInt32 nPos = nCLOffset + pStdFormat->GetLastInsertKey( SvNumberformat::FormatterPrivateAccess() ); nNewKey = nPos+1; if (nNewKey - nCLOffset >= SV_COUNTRY_LANGUAGE_OFFSET) { SAL_WARN( "svl.numbers", "SvNumberFormatter::MergeFormatter: too many formats for CL"); } - else if (!aFTable.emplace( nNewKey, std::move(pNewEntry)).second) + else if (!m_aFormatData.aFTable.emplace( nNewKey, std::move(pNewEntry)).second) { SAL_WARN( "svl.numbers", "SvNumberFormatter::MergeFormatter: dup position"); } @@ -3511,40 +3893,133 @@ SvNumberFormatterMergeMap SvNumberFormatter::ConvertMergeTableToMap() return aMap; } +namespace +{ + bool IsFormatSimpleBuiltIn(const SvNFLanguageData& rCurrentLanguage, sal_uInt32 nFormat, LanguageType eLnge) + { + if (nFormat < SV_COUNTRY_LANGUAGE_OFFSET && eLnge == rCurrentLanguage.GetIniLanguage()) + return true; // it stays as it is + + sal_uInt32 nOffset = nFormat % SV_COUNTRY_LANGUAGE_OFFSET; // relative index + if (nOffset > SV_MAX_COUNT_STANDARD_FORMATS) + return true; // not a built-in format + + return false; + } +} + +sal_uInt32 SvNFEngine::GetCLOffsetRO(const SvNFFormatData& rFormatData, SvNFLanguageData&, const NativeNumberWrapper*, LanguageType eLnge) +{ + sal_uInt32 nCLOffset = rFormatData.ImpGetCLOffset(eLnge); + assert(nCLOffset >= rFormatData.MaxCLOffset && "Language must have already been encountered"); + return nCLOffset; +} + +void SvNFEngine::CacheFormatRO(const SvNFFormatData&, sal_uInt32, sal_uInt32) +{ + assert(false && "not really fatal, just not cached"); +} + +sal_uInt32 SvNFEngine::GetCLOffsetRW(SvNFFormatData& rFormatData, SvNFLanguageData& rCurrentLanguage, const NativeNumberWrapper* pNatNum, LanguageType eLnge) +{ + return rFormatData.ImpGenerateCL(rCurrentLanguage, pNatNum, eLnge); // create new standard formats if necessary +} + +void SvNFEngine::CacheFormatRW(SvNFFormatData& rFormatData, sal_uInt32 nSearch, sal_uInt32 nFormat) +{ + rFormatData.aDefaultFormatKeys[nSearch] = nFormat; +} + +sal_uInt32 SvNFEngine::DefaultCurrencyRW(SvNFFormatData& rFormatData, SvNFLanguageData& rCurrentLanguage, const NativeNumberWrapper* pNatNum, sal_uInt32 CLOffset, LanguageType eLnge) +{ + if (eLnge == LANGUAGE_SYSTEM) + return rFormatData.ImpGetDefaultSystemCurrencyFormat(rCurrentLanguage, pNatNum); + return rFormatData.ImpGetDefaultCurrencyFormat(rCurrentLanguage, pNatNum, CLOffset, eLnge); +} + +sal_uInt32 SvNFEngine::DefaultCurrencyRO(const SvNFFormatData& rFormatData, SvNFLanguageData&, const NativeNumberWrapper*, sal_uInt32 CLOffset, LanguageType eLnge) +{ + if (eLnge == LANGUAGE_SYSTEM) + { + assert(rFormatData.nDefaultSystemCurrencyFormat != NUMBERFORMAT_ENTRY_NOT_FOUND); + return rFormatData.nDefaultSystemCurrencyFormat; + } + + SvNFFormatData::DefaultFormatKeysMap::const_iterator it = rFormatData.aDefaultFormatKeys.find(CLOffset + ZF_STANDARD_CURRENCY); + assert(it != rFormatData.aDefaultFormatKeys.end() && it->second != NUMBERFORMAT_ENTRY_NOT_FOUND); + return it->second; +} + +SvNFEngine::Accessor SvNFEngine::GetRWPolicy(SvNFFormatData& rFormatData) +{ + return + { + std::bind(SvNFEngine::GetCLOffsetRW, std::ref(rFormatData), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), + std::bind(SvNFEngine::CacheFormatRW, std::ref(rFormatData), std::placeholders::_1, std::placeholders::_2), + std::bind(SvNFEngine::DefaultCurrencyRW, std::ref(rFormatData), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4) + }; +} + +SvNFEngine::Accessor SvNFEngine::GetROPolicy(const SvNFFormatData& rFormatData) +{ + return + { + std::bind(SvNFEngine::GetCLOffsetRO, std::ref(rFormatData), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), + std::bind(SvNFEngine::CacheFormatRO, std::ref(rFormatData), std::placeholders::_1, std::placeholders::_2), + std::bind(SvNFEngine::DefaultCurrencyRO, std::ref(rFormatData), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4) + }; +} + +sal_uInt32 SvNFEngine::GetFormatForLanguageIfBuiltIn(SvNFLanguageData& rCurrentLanguage, + const NativeNumberWrapper* pNatNum, + const Accessor& rFuncs, + sal_uInt32 nFormat, LanguageType eLnge) +{ + eLnge = rCurrentLanguage.ImpResolveLanguage(eLnge); + + if (IsFormatSimpleBuiltIn(rCurrentLanguage, nFormat, eLnge)) + return nFormat; + + sal_uInt32 nCLOffset = rFuncs.mGetCLOffset(rCurrentLanguage, pNatNum, eLnge); + sal_uInt32 nOffset = nFormat % SV_COUNTRY_LANGUAGE_OFFSET; // relative index + return nCLOffset + nOffset; +} + sal_uInt32 SvNumberFormatter::GetFormatForLanguageIfBuiltIn( sal_uInt32 nFormat, LanguageType eLnge ) { - if ( eLnge == LANGUAGE_DONTKNOW ) - eLnge = IniLnge; // IniLnge never changes - if ( nFormat < SV_COUNTRY_LANGUAGE_OFFSET && eLnge == IniLnge ) - return nFormat; // it stays as it is - sal_uInt32 nOffset = nFormat % SV_COUNTRY_LANGUAGE_OFFSET; // relative index - if ( nOffset > SV_MAX_COUNT_STANDARD_FORMATS ) - return nFormat; // not a built-in format + ::osl::MutexGuard aGuard(GetInstanceMutex()); + return SvNFEngine::GetFormatForLanguageIfBuiltIn(m_aCurrentLanguage, GetNatNum(), m_aRWPolicy, nFormat, eLnge); +} - ::osl::MutexGuard aGuard( GetInstanceMutex() ); - sal_uInt32 nCLOffset = ImpGenerateCL(eLnge); // create new standard formats if necessary - return nCLOffset + nOffset; +LanguageType SvNFLanguageData::ImpResolveLanguage(LanguageType eLnge) const +{ + return eLnge == LANGUAGE_DONTKNOW ? IniLnge : eLnge; } -sal_uInt32 SvNumberFormatter::GetFormatIndex( NfIndexTableOffset nTabOff, - LanguageType eLnge ) +LanguageType SvNumberFormatter::ImpResolveLanguage(LanguageType eLnge) const { - if (nTabOff >= NF_INDEX_TABLE_ENTRIES) - return NUMBERFORMAT_ENTRY_NOT_FOUND; + return m_aCurrentLanguage.ImpResolveLanguage(eLnge); +} - if (eLnge == LANGUAGE_DONTKNOW) - eLnge = IniLnge; +sal_uInt32 SvNFEngine::GetFormatIndex(SvNFLanguageData& rCurrentLanguage, const Accessor& rFuncs, + const NativeNumberWrapper* pNatNum, NfIndexTableOffset nTabOff, + LanguageType eLnge) +{ + eLnge = rCurrentLanguage.ImpResolveLanguage(eLnge); - if (indexTable[nTabOff] == NUMBERFORMAT_ENTRY_NOT_FOUND) - return NUMBERFORMAT_ENTRY_NOT_FOUND; + sal_uInt32 nCLOffset = rFuncs.mGetCLOffset(rCurrentLanguage, pNatNum, eLnge); // create new standard formats if necessary (and allowed) - ::osl::MutexGuard aGuard( GetInstanceMutex() ); - sal_uInt32 nCLOffset = ImpGenerateCL(eLnge); // create new standard formats if necessary - return nCLOffset + indexTable[nTabOff]; + return ImpGetFormatIndex(nTabOff, nCLOffset); } -//static +sal_uInt32 SvNumberFormatter::GetFormatIndex(NfIndexTableOffset nTabOff, LanguageType eLnge) +{ + ::osl::MutexGuard aGuard(GetInstanceMutex()); + return SvNFEngine::GetFormatIndex(m_aCurrentLanguage, m_aRWPolicy, GetNatNum(), nTabOff, eLnge); +} + +// static NfIndexTableOffset SvNumberFormatter::GetIndexTableOffset(sal_uInt32 nFormat) { sal_uInt32 nOffset = nFormat % SV_COUNTRY_LANGUAGE_OFFSET; // relative index @@ -3564,30 +4039,29 @@ NfIndexTableOffset SvNumberFormatter::GetIndexTableOffset(sal_uInt32 nFormat) void SvNumberFormatter::SetEvalDateFormat( NfEvalDateFormat eEDF ) { ::osl::MutexGuard aGuard( GetInstanceMutex() ); - eEvalDateFormat = eEDF; + m_aCurrentLanguage.SetEvalDateFormat(eEDF); } NfEvalDateFormat SvNumberFormatter::GetEvalDateFormat() const { ::osl::MutexGuard aGuard( GetInstanceMutex() ); - return eEvalDateFormat; + return m_aCurrentLanguage.GetEvalDateFormat(); } void SvNumberFormatter::SetYear2000( sal_uInt16 nVal ) { ::osl::MutexGuard aGuard( GetInstanceMutex() ); - pStringScanner->SetYear2000( nVal ); + m_aCurrentLanguage.pStringScanner->SetYear2000( nVal ); } sal_uInt16 SvNumberFormatter::GetYear2000() const { ::osl::MutexGuard aGuard( GetInstanceMutex() ); - return pStringScanner->GetYear2000(); + return m_aCurrentLanguage.pStringScanner->GetYear2000(); } - -sal_uInt16 SvNumberFormatter::ExpandTwoDigitYear( sal_uInt16 nYear ) const +sal_uInt16 SvNFLanguageData::ExpandTwoDigitYear( sal_uInt16 nYear ) const { if ( nYear < 100 ) return SvNumberFormatter::ExpandTwoDigitYear( nYear, @@ -3595,6 +4069,10 @@ sal_uInt16 SvNumberFormatter::ExpandTwoDigitYear( sal_uInt16 nYear ) const return nYear; } +sal_uInt16 SvNumberFormatter::ExpandTwoDigitYear( sal_uInt16 nYear ) const +{ + return m_aCurrentLanguage.ExpandTwoDigitYear(nYear); +} // static sal_uInt16 SvNumberFormatter::GetYear2000Default() @@ -3738,29 +4216,35 @@ void SvNumberFormatter::SetDefaultSystemCurrency( std::u16string_view rAbbrev, L nSystemCurrencyPosition = 0; // not found => simple SYSTEM } -void SvNumberFormatter::ResetDefaultSystemCurrency() +void SvNFFormatData::ResetDefaultSystemCurrency() { nDefaultSystemCurrencyFormat = NUMBERFORMAT_ENTRY_NOT_FOUND; } +void SvNumberFormatter::ResetDefaultSystemCurrency() +{ + m_aFormatData.ResetDefaultSystemCurrency(); +} + void SvNumberFormatter::InvalidateDateAcceptancePatterns() { - pStringScanner->InvalidateDateAcceptancePatterns(); + m_aCurrentLanguage.pStringScanner->InvalidateDateAcceptancePatterns(); } -sal_uInt32 SvNumberFormatter::ImpGetDefaultSystemCurrencyFormat() +sal_uInt32 SvNFFormatData::ImpGetDefaultSystemCurrencyFormat(SvNFLanguageData& rCurrentLanguage, + const NativeNumberWrapper* pNatNum) { if ( nDefaultSystemCurrencyFormat == NUMBERFORMAT_ENTRY_NOT_FOUND ) { sal_Int32 nCheck; SvNumFormatType nType; NfWSStringsDtor aCurrList; - sal_uInt16 nDefault = GetCurrencyFormatStrings( aCurrList, - GetCurrencyEntry( LANGUAGE_SYSTEM ), false ); + sal_uInt16 nDefault = rCurrentLanguage.GetCurrencyFormatStrings( aCurrList, + SvNumberFormatter::GetCurrencyEntry( LANGUAGE_SYSTEM ), false ); DBG_ASSERT( aCurrList.size(), "where is the NewCurrency System standard format?!?" ); // if already loaded or user defined nDefaultSystemCurrencyFormat // will be set to the right value - PutEntry( aCurrList[ nDefault ], nCheck, nType, + PutEntry(rCurrentLanguage, pNatNum, aCurrList[ nDefault ], nCheck, nType, nDefaultSystemCurrencyFormat, LANGUAGE_SYSTEM ); DBG_ASSERT( nCheck == 0, "NewCurrency CheckError" ); DBG_ASSERT( nDefaultSystemCurrencyFormat != NUMBERFORMAT_ENTRY_NOT_FOUND, @@ -3769,10 +4253,9 @@ sal_uInt32 SvNumberFormatter::ImpGetDefaultSystemCurrencyFormat() return nDefaultSystemCurrencyFormat; } - -sal_uInt32 SvNumberFormatter::ImpGetDefaultCurrencyFormat() +sal_uInt32 SvNFFormatData::ImpGetDefaultCurrencyFormat(SvNFLanguageData& rCurrentLanguage, const NativeNumberWrapper* pNatNum, + sal_uInt32 CLOffset, LanguageType eLnge) { - sal_uInt32 CLOffset = ImpGetCLOffset( ActLnge ); DefaultFormatKeysMap::const_iterator it = aDefaultFormatKeys.find( CLOffset + ZF_STANDARD_CURRENCY ); sal_uInt32 nDefaultCurrencyFormat = (it != aDefaultFormatKeys.end() ? it->second : NUMBERFORMAT_ENTRY_NOT_FOUND); @@ -3797,16 +4280,16 @@ sal_uInt32 SvNumberFormatter::ImpGetDefaultCurrencyFormat() { // none found, create one sal_Int32 nCheck; NfWSStringsDtor aCurrList; - sal_uInt16 nDefault = GetCurrencyFormatStrings( aCurrList, - GetCurrencyEntry( ActLnge ), false ); + sal_uInt16 nDefault = rCurrentLanguage.GetCurrencyFormatStrings( aCurrList, + SvNumberFormatter::GetCurrencyEntry(eLnge), false ); DBG_ASSERT( aCurrList.size(), "where is the NewCurrency standard format?" ); if ( !aCurrList.empty() ) { // if already loaded or user defined nDefaultSystemCurrencyFormat // will be set to the right value SvNumFormatType nType; - PutEntry( aCurrList[ nDefault ], nCheck, nType, - nDefaultCurrencyFormat, ActLnge ); + PutEntry(rCurrentLanguage, pNatNum, aCurrList[ nDefault ], nCheck, nType, + nDefaultCurrencyFormat, eLnge ); DBG_ASSERT( nCheck == 0, "NewCurrency CheckError" ); DBG_ASSERT( nDefaultCurrencyFormat != NUMBERFORMAT_ENTRY_NOT_FOUND, "nDefaultCurrencyFormat == NUMBERFORMAT_ENTRY_NOT_FOUND" ); @@ -3875,12 +4358,10 @@ bool SvNumberFormatter::ImpLookupCurrencyEntryLoopBody( return true; } - -bool SvNumberFormatter::GetNewCurrencySymbolString( sal_uInt32 nFormat, OUString& rStr, - const NfCurrencyEntry** ppEntry /* = NULL */, - bool* pBank /* = NULL */ ) const +bool SvNFFormatData::GetNewCurrencySymbolString(sal_uInt32 nFormat, OUString& rStr, + const NfCurrencyEntry** ppEntry /* = NULL */, + bool* pBank /* = NULL */) const { - ::osl::MutexGuard aGuard( GetInstanceMutex() ); if ( ppEntry ) *ppEntry = nullptr; if ( pBank ) @@ -3897,7 +4378,7 @@ bool SvNumberFormatter::GetNewCurrencySymbolString( sal_uInt32 nFormat, OUString { bool bFoundBank = false; // we definitely need an entry matching the format code string - const NfCurrencyEntry* pFoundEntry = GetCurrencyEntry( + const NfCurrencyEntry* pFoundEntry = SvNumberFormatter::GetCurrencyEntry( bFoundBank, aSymbol, aExtension, pFormat->GetLanguage(), true ); if ( pFoundEntry ) @@ -3934,6 +4415,13 @@ bool SvNumberFormatter::GetNewCurrencySymbolString( sal_uInt32 nFormat, OUString return false; } +bool SvNumberFormatter::GetNewCurrencySymbolString( sal_uInt32 nFormat, OUString& rStr, + const NfCurrencyEntry** ppEntry /* = NULL */, + bool* pBank /* = NULL */ ) const +{ + ::osl::MutexGuard aGuard( GetInstanceMutex() ); + return m_aFormatData.GetNewCurrencySymbolString(nFormat, rStr, ppEntry, pBank); +} // static const NfCurrencyEntry* SvNumberFormatter::GetCurrencyEntry( bool & bFoundBank, @@ -4027,10 +4515,8 @@ const NfCurrencyEntry* SvNumberFormatter::GetCurrencyEntry( bool & bFoundBank, return pFoundEntry; } - -void SvNumberFormatter::GetCompatibilityCurrency( OUString& rSymbol, OUString& rAbbrev ) const +void SvNFLanguageData::GetCompatibilityCurrency( OUString& rSymbol, OUString& rAbbrev ) const { - ::osl::MutexGuard aGuard( GetInstanceMutex() ); const css::uno::Sequence< css::i18n::Currency2 > xCurrencies( xLocaleData->getAllCurrencies() ); @@ -4053,6 +4539,11 @@ void SvNumberFormatter::GetCompatibilityCurrency( OUString& rSymbol, OUString& r } } +void SvNumberFormatter::GetCompatibilityCurrency( OUString& rSymbol, OUString& rAbbrev ) const +{ + ::osl::MutexGuard aGuard( GetInstanceMutex() ); + m_aCurrentLanguage.GetCompatibilityCurrency(rSymbol, rAbbrev); +} static void lcl_CheckCurrencySymbolPosition( const NfCurrencyEntry& rCurr ) { @@ -4277,12 +4768,10 @@ static std::ptrdiff_t addToCurrencyFormatsList( NfWSStringsDtor& rStrArr, const return rStrArr.size() - 1; } - -sal_uInt16 SvNumberFormatter::GetCurrencyFormatStrings( NfWSStringsDtor& rStrArr, - const NfCurrencyEntry& rCurr, - bool bBank ) const +sal_uInt16 SvNFLanguageData::GetCurrencyFormatStrings(NfWSStringsDtor& rStrArr, + const NfCurrencyEntry& rCurr, + bool bBank) const { - ::osl::MutexGuard aGuard( GetInstanceMutex() ); OUString aRed = "[" + pFormatScanner->GetRedString() + "]"; @@ -4365,6 +4854,14 @@ sal_uInt16 SvNumberFormatter::GetCurrencyFormatStrings( NfWSStringsDtor& rStrArr return nDefault; } +sal_uInt16 SvNumberFormatter::GetCurrencyFormatStrings( NfWSStringsDtor& rStrArr, + const NfCurrencyEntry& rCurr, + bool bBank ) const +{ + ::osl::MutexGuard aGuard(GetInstanceMutex()); + return m_aCurrentLanguage.GetCurrencyFormatStrings(rStrArr, rCurr, bBank); +} + sal_uInt32 SvNumberFormatter::GetMergeFormatIndex( sal_uInt32 nOldFmt ) const { ::osl::MutexGuard aGuard( GetInstanceMutex() ); @@ -4909,12 +5406,12 @@ sal_uInt16 NfCurrencyEntry::GetEffectiveNegativeFormat( sal_uInt16 nIntlFormat, const NfKeywordTable & SvNumberFormatter::GetKeywords( sal_uInt32 nKey ) { osl::MutexGuard aGuard( GetInstanceMutex() ); - const SvNumberformat* pFormat = GetFormatEntry( nKey); + const SvNumberformat* pFormat = m_aFormatData.GetFormatEntry( nKey); if (pFormat) ChangeIntl( pFormat->GetLanguage()); else ChangeIntl( IniLnge); - return pFormatScanner->GetKeywords(); + return m_aCurrentLanguage.pFormatScanner->GetKeywords(); } // static diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx index 69d3335ef71b..5e1bbf6cd9b0 100644 --- a/svl/source/numbers/zformat.cxx +++ b/svl/source/numbers/zformat.cxx @@ -751,6 +751,7 @@ static bool lcl_isNatNum12Currency( std::u16string_view sParam ) SvNumberformat::SvNumberformat(OUString& rString, ImpSvNumberformatScan* pSc, ImpSvNumberInputScan* pISc, + const NativeNumberWrapper* pNatNum, sal_Int32& nCheckPos, LanguageType& eLan, bool bReplaceBooleanEquivalent) @@ -766,7 +767,7 @@ SvNumberformat::SvNumberformat(OUString& rString, // replace all occurrences by a simple space. // The same for Narrow No-Break Space just in case some locale uses it. // The tokens will be changed to the LocaleData separator again later on. - const OUString& rThSep = GetFormatter().GetNumThousandSep(); + const OUString& rThSep = GetCurrentLanguageData().GetNumThousandSep(); if ( rThSep.getLength() == 1) { const sal_Unicode cNBSp = 0xA0; @@ -781,7 +782,7 @@ SvNumberformat::SvNumberformat(OUString& rString, OUString aConvertToDecSep; if (rScan.GetConvertMode()) { - aConvertFromDecSep = GetFormatter().GetNumDecimalSep(); + aConvertFromDecSep = GetCurrentLanguageData().GetNumDecimalSep(); maLocale.meLanguage = rScan.GetNewLnge(); eLan = maLocale.meLanguage; // Make sure to return switch } @@ -811,7 +812,7 @@ SvNumberformat::SvNumberformat(OUString& rString, // Original language/country may have to be reestablished if (rScan.GetConvertMode()) { - rScan.GetNumberformatter()->ChangeIntl(rScan.GetTmpLnge()); + rScan.GetCurrentLanguageData().ChangeIntl(rScan.GetTmpLnge()); } OUString sInsertCalendar; // a calendar resulting from parsing LCID OUString sStr; @@ -844,7 +845,7 @@ SvNumberformat::SvNumberformat(OUString& rString, { sal_Int32 nDecPos; SvNumFormatType F_Type = SvNumFormatType::UNDEFINED; - if (!pISc->IsNumberFormat(sStr, F_Type, fNumber, nullptr, SvNumInputOptions::NONE) || + if (!pISc->IsNumberFormat(sStr, F_Type, fNumber, nullptr, pNatNum, SvNumInputOptions::NONE) || ( F_Type != SvNumFormatType::NUMBER && F_Type != SvNumFormatType::SCIENTIFIC) ) { @@ -857,7 +858,7 @@ SvNumberformat::SvNumberformat(OUString& rString, else if (rScan.GetConvertMode() && ((nDecPos = sStr.indexOf( aConvertFromDecSep)) >= 0)) { if (aConvertToDecSep.isEmpty()) - aConvertToDecSep = GetFormatter().GetLangDecimalSep( rScan.GetNewLnge()); + aConvertToDecSep = GetCurrentLanguageData().GetLangDecimalSep( rScan.GetNewLnge()); if (aConvertToDecSep != aConvertFromDecSep) { const OUString aStr( sStr.replaceAt( nDecPos, @@ -2050,14 +2051,16 @@ OUString SvNumberformat::StripNewCurrencyDelimiters( const OUString& rStr ) return aTmp.makeStringAndClear(); } -void SvNumberformat::ImpGetOutputStandard(double& fNumber, OUStringBuffer& rOutString) const +void SvNumberformat::ImpGetOutputStandard(double& fNumber, OUStringBuffer& rOutString, + const NativeNumberWrapper* pNatNum) const { OUString sTemp; - ImpGetOutputStandard(fNumber, sTemp); + ImpGetOutputStandard(fNumber, sTemp, pNatNum); rOutString = sTemp; } -void SvNumberformat::ImpGetOutputStandard(double& fNumber, OUString& rOutString) const +void SvNumberformat::ImpGetOutputStandard(double& fNumber, OUString& rOutString, + const NativeNumberWrapper* pNatNum) const { sal_uInt16 nStandardPrec = rScan.GetStandardPrec(); @@ -2066,11 +2069,11 @@ void SvNumberformat::ImpGetOutputStandard(double& fNumber, OUString& rOutString) nStandardPrec = ::std::min(nStandardPrec, static_cast<sal_uInt16>(14)); // limits to 14 decimals rOutString = ::rtl::math::doubleToUString( fNumber, rtl_math_StringFormat_E2, nStandardPrec /*2*/, - GetFormatter().GetNumDecimalSep()[0]); + GetCurrentLanguageData().GetNumDecimalSep()[0]); } else { - ImpGetOutputStdToPrecision(fNumber, rOutString, nStandardPrec); + ImpGetOutputStdToPrecision(fNumber, rOutString, nStandardPrec, pNatNum); } } @@ -2093,9 +2096,41 @@ bool checkForAll0s(const T& rString, sal_Int32 nIdx=0) return true; } +OUString impTransliterateImpl(const OUString& rStr, + const SvNumberNatNum& rNum, + const NativeNumberWrapper* pNatNum) +{ + css::lang::Locale aLocale( LanguageTag( rNum.GetLang() ).getLocale() ); + return pNatNum->getNativeNumberStringParams(rStr, aLocale, rNum.GetNatNum(), rNum.GetParams()); +} + +void impTransliterateImpl(OUStringBuffer& rStr, + const SvNumberNatNum& rNum, + const NativeNumberWrapper* pNatNum) +{ + css::lang::Locale aLocale( LanguageTag( rNum.GetLang() ).getLocale() ); + + rStr = pNatNum->getNativeNumberStringParams( + OUString::unacquired(rStr), aLocale, rNum.GetNatNum(), rNum.GetParams()); +} + +OUString impTransliterate(const OUString& rStr, const SvNumberNatNum& rNum, const NativeNumberWrapper* pNatNum) +{ + return rNum.IsComplete() ? impTransliterateImpl(rStr, rNum, pNatNum) : rStr; +} + +void impTransliterate(OUStringBuffer& rStr, const SvNumberNatNum& rNum, const NativeNumberWrapper* pNatNum) +{ + if(rNum.IsComplete()) + { + impTransliterateImpl(rStr, rNum, pNatNum); + } +} + } -void SvNumberformat::ImpGetOutputStdToPrecision(double& rNumber, OUString& rOutString, sal_uInt16 nPrecision) const +void SvNumberformat::ImpGetOutputStdToPrecision(double& rNumber, OUString& rOutString, sal_uInt16 nPrecision, + const NativeNumberWrapper* pNatNum) const { // Make sure the precision doesn't go over the maximum allowable precision. nPrecision = ::std::min(UPPER_PRECISION, nPrecision); @@ -2107,12 +2142,12 @@ void SvNumberformat::ImpGetOutputStdToPrecision(double& rNumber, OUString& rOutS rOutString = ::rtl::math::doubleToUString( rNumber, rtl_math_StringFormat_F, nPrecision /*2*/, - GetFormatter().GetNumDecimalSep()[0], true ); + GetCurrentLanguageData().GetNumDecimalSep()[0], true ); if (rOutString[0] == '-' && checkForAll0s(rOutString, 1)) { rOutString = comphelper::string::stripStart(rOutString, '-'); // not -0 } - rOutString = impTransliterate(rOutString, NumFor[0].GetNatNum()); + rOutString = ::impTransliterate(rOutString, NumFor[0].GetNatNum(), pNatNum); } void SvNumberformat::ImpGetOutputInputLine(double fNumber, OUString& OutString) const @@ -2138,7 +2173,7 @@ void SvNumberformat::ImpGetOutputInputLine(double fNumber, OUString& OutString) OutString = ::rtl::math::doubleToUString( fNumber, rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, - GetFormatter().GetNumDecimalSep()[0], true ); + GetCurrentLanguageData().GetNumDecimalSep()[0], true ); if ( eType & SvNumFormatType::PERCENT && bModified) { @@ -2249,7 +2284,7 @@ void SvNumberformat::GetOutputString(std::u16string_view sString, namespace { void lcl_GetOutputStringScientific(double fNumber, sal_uInt16 nCharCount, - const SvNumberFormatter& rFormatter, OUString& rOutString) + const SvNFLanguageData& rLanguageData, OUString& rOutString) { bool bSign = std::signbit(fNumber); @@ -2268,7 +2303,7 @@ void lcl_GetOutputStringScientific(double fNumber, sal_uInt16 nCharCount, nPrec = ::std::min(nPrec, static_cast<sal_uInt16>(14)); // limit to 14 decimals. rOutString = ::rtl::math::doubleToUString(fNumber, rtl_math_StringFormat_E2, - nPrec, rFormatter.GetNumDecimalSep()[0], true ); + nPrec, rLanguageData.GetNumDecimalSep()[0], true ); } OUString lcl_GetPercentString(const ImpSvNumberformatInfo &rInfo, sal_uInt16 nCnt) @@ -2400,7 +2435,7 @@ OUString SvNumberformat::GetIntegerFractionDelimiterString( sal_uInt16 nNumFor ) return lcl_GetIntegerFractionDelimiterString( rInfo, nCnt ); } -bool SvNumberformat::GetOutputString(double fNumber, sal_uInt16 nCharCount, OUString& rOutString) const +bool SvNumberformat::GetOutputString(double fNumber, sal_uInt16 nCharCount, OUString& rOutString, const NativeNumberWrapper* pNatNum) const { if (eType != SvNumFormatType::NUMBER) { @@ -2414,7 +2449,7 @@ bool SvNumberformat::GetOutputString(double fNumber, sal_uInt16 nCharCount, OUSt } if (fTestNum < EXP_LOWER_BOUND) { - lcl_GetOutputStringScientific(fNumber, nCharCount, GetFormatter(), rOutString); + lcl_GetOutputStringScientific(fNumber, nCharCount, GetCurrentLanguageData(), rOutString); return true; } @@ -2424,7 +2459,7 @@ bool SvNumberformat::GetOutputString(double fNumber, sal_uInt16 nCharCount, OUSt if (nDigitPre > 15) { - lcl_GetOutputStringScientific(fNumber, nCharCount, GetFormatter(), rOutString); + lcl_GetOutputStringScientific(fNumber, nCharCount, GetCurrentLanguageData(), rOutString); return true; } @@ -2439,11 +2474,11 @@ bool SvNumberformat::GetOutputString(double fNumber, sal_uInt16 nCharCount, OUSt // Subtract the decimal point. --nPrec; } - ImpGetOutputStdToPrecision(fNumber, rOutString, nPrec); + ImpGetOutputStdToPrecision(fNumber, rOutString, nPrec, pNatNum); if (rOutString.getLength() > nCharCount) { // String still wider than desired. Switch to scientific notation. - lcl_GetOutputStringScientific(fNumber, nCharCount, GetFormatter(), rOutString); + lcl_GetOutputStringScientific(fNumber, nCharCount, GetCurrentLanguageData(), rOutString); } return true; } @@ -2476,6 +2511,7 @@ sal_uInt16 SvNumberformat::GetSubformatIndex (double fNumber ) const bool SvNumberformat::GetOutputString(double fNumber, OUString& OutString, const Color** ppColor, + const NativeNumberWrapper* pNatNum, bool bStarFlag) const { bool bRes = false; @@ -2496,7 +2532,7 @@ bool SvNumberformat::GetOutputString(double fNumber, OUStringBuffer sBuff(64); if (eType & SvNumFormatType::TEXT) { - ImpGetOutputStandard(fNumber, sBuff); + ImpGetOutputStandard(fNumber, sBuff, pNatNum); OutString = sBuff.makeStringAndClear(); return false; } @@ -2544,35 +2580,35 @@ bool SvNumberformat::GetOutputString(double fNumber, OutString = ::rtl::math::doubleToUString( fNumber, rtl_math_StringFormat_F, rtl_math_DecimalPlaces_Max, - GetFormatter().GetNumDecimalSep()[0], true); + GetCurrentLanguageData().GetNumDecimalSep()[0], true); else OutString = ::rtl::math::doubleToUString( fNumber, rtl_math_StringFormat_E2, rtl_math_DecimalPlaces_Max, - GetFormatter().GetNumDecimalSep()[0], true); + GetCurrentLanguageData().GetNumDecimalSep()[0], true); } else { OutString = ::rtl::math::doubleToUString( fNumber, rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, - GetFormatter().GetNumDecimalSep()[0], true); + GetCurrentLanguageData().GetNumDecimalSep()[0], true); } return false; } - ImpGetOutputStandard(fNumber, sBuff); + ImpGetOutputStandard(fNumber, sBuff, pNatNum); bHadStandard = true; break; case SvNumFormatType::DATE: - bRes |= ImpGetDateOutput(fNumber, 0, bStarFlag, sBuff); + bRes |= ImpGetDateOutput(fNumber, 0, bStarFlag, pNatNum, sBuff); bHadStandard = true; break; case SvNumFormatType::TIME: - bRes |= ImpGetTimeOutput(fNumber, 0, bStarFlag, sBuff); + bRes |= ImpGetTimeOutput(fNumber, 0, bStarFlag, pNatNum, sBuff); bHadStandard = true; break; case SvNumFormatType::DATETIME: - bRes |= ImpGetDateTimeOutput(fNumber, 0, bStarFlag, sBuff); + bRes |= ImpGetDateTimeOutput(fNumber, 0, bStarFlag, pNatNum, sBuff); bHadStandard = true; break; default: break; @@ -2596,7 +2632,7 @@ bool SvNumberformat::GetOutputString(double fNumber, } else if (nCnt == 0) // Else Standard Format { - ImpGetOutputStandard(fNumber, sBuff); + ImpGetOutputStandard(fNumber, sBuff, pNatNum); OutString = sBuff.makeStringAndClear(); return false; } @@ -2634,27 +2670,27 @@ bool SvNumberformat::GetOutputString(double fNumber, } break; case SvNumFormatType::DATE: - bRes |= ImpGetDateOutput(fNumber, nIx, bStarFlag, sBuff); + bRes |= ImpGetDateOutput(fNumber, nIx, bStarFlag, pNatNum, sBuff); break; case SvNumFormatType::TIME: - bRes |= ImpGetTimeOutput(fNumber, nIx, bStarFlag, sBuff); + bRes |= ImpGetTimeOutput(fNumber, nIx, bStarFlag, pNatNum, sBuff); break; case SvNumFormatType::DATETIME: - bRes |= ImpGetDateTimeOutput(fNumber, nIx, bStarFlag, sBuff); + bRes |= ImpGetDateTimeOutput(fNumber, nIx, bStarFlag, pNatNum, sBuff); break; case SvNumFormatType::NUMBER: case SvNumFormatType::PERCENT: case SvNumFormatType::CURRENCY: - bRes |= ImpGetNumberOutput(fNumber, nIx, bStarFlag, sBuff); + bRes |= ImpGetNumberOutput(fNumber, nIx, bStarFlag, pNatNum, sBuff); break; case SvNumFormatType::LOGICAL: - bRes |= ImpGetLogicalOutput(fNumber, nIx, sBuff); + bRes |= ImpGetLogicalOutput(fNumber, nIx, pNatNum, sBuff); break; case SvNumFormatType::FRACTION: - bRes |= ImpGetFractionOutput(fNumber, nIx, bStarFlag, sBuff); + bRes |= ImpGetFractionOutput(fNumber, nIx, bStarFlag, pNatNum, sBuff); break; case SvNumFormatType::SCIENTIFIC: - bRes |= ImpGetScientificOutput(fNumber, nIx, bStarFlag, sBuff); + bRes |= ImpGetScientificOutput(fNumber, nIx, bStarFlag, pNatNum, sBuff); break; default: break; } @@ -2666,6 +2702,7 @@ bool SvNumberformat::GetOutputString(double fNumber, bool SvNumberformat::ImpGetScientificOutput(double fNumber, sal_uInt16 nIx, bool bStarFlag, + const NativeNumberWrapper* pNatNum, OUStringBuffer& sStr) const { bool bRes = false; @@ -2769,7 +2806,7 @@ bool SvNumberformat::ImpGetScientificOutput(double fNumber, } // restore leading zeros or blanks according to format '0' or '?' tdf#156449 - bRes |= ImpNumberFill(ExpStr, fNumber, k, j, nIx, NF_SYMBOLTYPE_EXP, bStarFlag); + bRes |= ImpNumberFill(pNatNum, ExpStr, fNumber, k, j, nIx, NF_SYMBOLTYPE_EXP, bStarFlag); bool bCont = true; @@ -2801,7 +2838,7 @@ bool SvNumberformat::ImpGetScientificOutput(double fNumber, } else { - bRes |= ImpDecimalFill(sStr, fNumber, nDecPos, j, nIx, false, bStarFlag); + bRes |= ImpDecimalFill(pNatNum, sStr, fNumber, nDecPos, j, nIx, false, bStarFlag); } if (bSign) @@ -2900,6 +2937,7 @@ void SvNumberformat::ImpGetFractionElements ( double& fNumber, sal_uInt16 nIx, bool SvNumberformat::ImpGetFractionOutput(double fNumber, sal_uInt16 nIx, bool bStarFlag, + const NativeNumberWrapper* pNatNum, OUStringBuffer& sBuff) const { bool bRes = false; @@ -2947,7 +2985,7 @@ bool SvNumberformat::ImpGetFractionOutput(double fNumber, char aBuf[100]; o3tl::sprintf( aBuf, "%.f", fNum ); // simple rounded integer sStr.appendAscii( aBuf ); - impTransliterate(sStr, NumFor[nIx].GetNatNum()); + ::impTransliterate(sStr, NumFor[nIx].GetNatNum(), pNatNum); } bool bHideFraction = (rInfo.nCntPre > 0 && nFrac == 0 && (sNumeratorFormat.indexOf('0') < 0) @@ -2959,14 +2997,14 @@ bool SvNumberformat::ImpGetFractionOutput(double fNumber, } else // if there are some '0' in format, force display of fraction { - sFrac = ImpIntToString( nIx, nFrac ); - sDiv = ImpIntToString( nIx, nDiv ); + sFrac = ImpIntToString(pNatNum, nIx, nFrac); + sDiv = ImpIntToString(pNatNum, nIx, nDiv); } sal_uInt16 j = nCnt-1; // Last symbol -> backwards sal_Int32 k; // Denominator - bRes |= ImpNumberFill(sDiv, fNumber, k, j, nIx, NF_SYMBOLTYPE_FRAC, bStarFlag, true); + bRes |= ImpNumberFill(pNatNum, sDiv, fNumber, k, j, nIx, NF_SYMBOLTYPE_FRAC, bStarFlag, true); bool bCont = true; if (rInfo.nTypeArray[j] == NF_SYMBOLTYPE_FRAC) @@ -2997,7 +3035,7 @@ bool SvNumberformat::ImpGetFractionOutput(double fNumber, } else { - bRes |= ImpNumberFill(sFrac, fNumber, k, j, nIx, NF_SYMBOLTYPE_FRACBLANK, bStarFlag); + bRes |= ImpNumberFill(pNatNum, sFrac, fNumber, k, j, nIx, NF_SYMBOLTYPE_FRACBLANK, bStarFlag); bCont = false; // there is no integer part? if (rInfo.nTypeArray[j] == NF_SYMBOLTYPE_FRACBLANK) { @@ -3042,7 +3080,7 @@ bool SvNumberformat::ImpGetFractionOutput(double fNumber, else { k = sStr.getLength(); // After last figure - bRes |= ImpNumberFillWithThousands(sStr, fNumber, k, j, nIx, + bRes |= ImpNumberFillWithThousands(pNatNum, sStr, fNumber, k, j, nIx, rInfo.nCntPre, bStarFlag); } if (bSign && (nFrac != 0 || fNum != 0.0)) @@ -3056,7 +3094,8 @@ bool SvNumberformat::ImpGetFractionOutput(double fNumber, } sal_uInt16 SvNumberformat::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 { if (!nFractionDecimals) return 0; @@ -3076,12 +3115,12 @@ sal_uInt16 SvNumberformat::ImpGetFractionOfSecondString( OUStringBuffer& rBuf, d { rBuf.append('0'); } - impTransliterate(rBuf, NumFor[nIx].GetNatNum()); + ::impTransliterate(rBuf, NumFor[nIx].GetNatNum(), pNatNum); nFractionDecimals = rBuf.getLength(); } else { - impTransliterate(rBuf, NumFor[nIx].GetNatNum()); + ::impTransliterate(rBuf, NumFor[nIx].GetNatNum(), pNatNum); } return static_cast<sal_uInt16>(nFractionDecimals); } @@ -3089,6 +3128,7 @@ sal_uInt16 SvNumberformat::ImpGetFractionOfSecondString( OUStringBuffer& rBuf, d bool SvNumberformat::ImpGetTimeOutput(double fNumber, sal_uInt16 nIx, bool bStarFlag, + const NativeNumberWrapper* pNatNum, OUStringBuffer& sBuff) const { using namespace ::com::sun::star::i18n; @@ -3131,7 +3171,7 @@ bool SvNumberformat::ImpGetTimeOutput(double fNumber, nMin = nCMinute; nSec = nCSecond; nCntPost = ImpGetFractionOfSecondString( sSecStr, fFractionOfSecond, nCntPost, true, nIx, - (bInputLine ? rInfo.nCntPost : 0)); + (bInputLine ? rInfo.nCntPost : 0), pNatNum ); } else { @@ -3148,7 +3188,7 @@ bool SvNumberformat::ImpGetTimeOutput(double fNumber, sal_uInt32 nSeconds = static_cast<sal_uInt32>(fTime); nCntPost = ImpGetFractionOfSecondString( sSecStr, fTime - nSeconds, nCntPost, false, nIx, - (bInputLine ? rInfo.nCntPost : 0)); + (bInputLine ? rInfo.nCntPost : 0), pNatNum ); if (rInfo.nThousand == 3) // [ss] { @@ -3262,22 +3302,22 @@ bool SvNumberformat::ImpGetTimeOutput(double fNumber, } break; case NF_KEY_MI: // M - sBuff.append(ImpIntToString( nIx, nMin )); + sBuff.append(ImpIntToString(pNatNum, nIx, nMin )); break; case NF_KEY_MMI: // MM - sBuff.append(ImpIntToString( nIx, nMin, 2 )); + sBuff.append(ImpIntToString(pNatNum, nIx, nMin, 2 )); break; case NF_KEY_H: // H - sBuff.append(ImpIntToString( nIx, nHour )); + sBuff.append(ImpIntToString(pNatNum, nIx, nHour )); break; case NF_KEY_HH: // HH - sBuff.append(ImpIntToString( nIx, nHour, 2 )); + sBuff.append(ImpIntToString(pNatNum, nIx, nHour, 2 )); break; case NF_KEY_S: // S - sBuff.append(ImpIntToString( nIx, nSec )); + sBuff.append(ImpIntToString(pNatNum, nIx, nSec )); break; case NF_KEY_SS: // SS - sBuff.append(ImpIntToString( nIx, nSec, 2 )); + sBuff.append(ImpIntToString(pNatNum, nIx, nSec, 2 )); break; default: break; @@ -3709,6 +3749,7 @@ static bool lcl_getValidDate( const DateTime& rNullDate, const DateTime& rEpochS bool SvNumberformat::ImpGetDateOutput(double fNumber, sal_uInt16 nIx, bool bStarFlag, + const NativeNumberWrapper* pNatNum, OUStringBuffer& sBuff) const { using namespace ::com::sun::star::i18n; @@ -3794,7 +3835,7 @@ bool SvNumberformat::ImpGetDateOutput(double fNumber, // for example, Catalan "de març", but "d'abril" etc. if ( bUseSpellout ) { - aStr = impTransliterate(aStr, NumFor[nIx].GetNatNum(), rInfo.nTypeArray[i]); + aStr = impTransliterate(aStr, NumFor[nIx].GetNatNum(), rInfo.nTypeArray[i], pNatNum); } sBuff.append(aStr); break; @@ -3815,7 +3856,7 @@ bool SvNumberformat::ImpGetDateOutput(double fNumber, nNatNum); if ( bUseSpellout ) { - aStr = impTransliterate(aStr, NumFor[nIx].GetNatNum(), rInfo.nTypeArray[i]); + aStr = impTransliterate(aStr, NumFor[nIx].GetNatNum(), rInfo.nTypeArray[i], pNatNum); } sBuff.append(aStr); break; @@ -3830,7 +3871,7 @@ bool SvNumberformat::ImpGetDateOutput(double fNumber, // NatNum12: support variants of preposition, suffixation or article if ( bUseSpellout ) { - aStr = impTransliterate(aStr, NumFor[nIx].GetNatNum(), rInfo.nTypeArray[i]); + aStr = impTransliterate(aStr, NumFor[nIx].GetNatNum(), rInfo.nTypeArray[i], pNatNum); } sBuff.append(aStr); break; @@ -3846,7 +3887,7 @@ bool SvNumberformat::ImpGetDateOutput(double fNumber, // NatNum12: support at least capitalize, upper, lower, title if ( bUseSpellout ) { - aStr = impTransliterate(aStr, NumFor[nIx].GetNatNum(), rInfo.nTypeArray[i]); + aStr = impTransliterate(aStr, NumFor[nIx].GetNatNum(), rInfo.nTypeArray[i], pNatNum); } sBuff.append(aStr); if ( bOtherCalendar ) @@ -3863,7 +3904,7 @@ bool SvNumberformat::ImpGetDateOutput(double fNumber, // NatNum12: support variants of preposition, suffixation or article if ( bUseSpellout ) { - aStr = impTransliterate(aStr, NumFor[nIx].GetNatNum(), rInfo.nTypeArray[i]); + aStr = impTransliterate(aStr, NumFor[nIx].GetNatNum(), rInfo.nTypeArray[i], pNatNum); } sBuff.append(aStr); if ( bOtherCalendar ) @@ -3906,14 +3947,14 @@ bool SvNumberformat::ImpGetDateOutput(double fNumber, // without suddenly being hit by the 2-digit year magic. OUStringBuffer aBuf; padToLength(aBuf, 4 - aStr.getLength(), '0'); - impTransliterate(aBuf, NumFor[nIx].GetNatNum()); + ::impTransliterate(aBuf, NumFor[nIx].GetNatNum(), pNatNum); aBuf.append(aStr); aStr = aBuf.makeStringAndClear(); } // NatNum12: support variants of preposition, suffixation or article if ( bUseSpellout ) { - aStr = impTransliterate(aStr, NumFor[nIx].GetNatNum(), rInfo.nTypeArray[i]); + aStr = impTransliterate(aStr, NumFor[nIx].GetNatNum(), rInfo.nTypeArray[i], pNatNum); } sBuff.append(aStr); if ( bOtherCalendar ) @@ -3934,7 +3975,7 @@ bool SvNumberformat::ImpGetDateOutput(double fNumber, // NatNum12: support at least capitalize, upper, lower, title if ( bUseSpellout ) { - aStr = impTransliterate(aStr, NumFor[nIx].GetNatNum(), rInfo.nTypeArray[i]); + aStr = impTransliterate(aStr, NumFor[nIx].GetNatNum(), rInfo.nTypeArray[i], pNatNum); } sBuff.append(aStr); break; @@ -3944,7 +3985,7 @@ bool SvNumberformat::ImpGetDateOutput(double fNumber, // NatNum12: support variants of preposition, suffixation or article if ( bUseSpellout ) { - aStr = impTransliterate(aStr, NumFor[nIx].GetNatNum(), rInfo.nTypeArray[i]); + aStr = impTransliterate(aStr, NumFor[nIx].GetNatNum(), rInfo.nTypeArray[i], pNatNum); } sBuff.append(aStr); break; @@ -3953,7 +3994,7 @@ bool SvNumberformat::ImpGetDateOutput(double fNumber, sBuff.append(rLoc().getLongDateDayOfWeekSep()); break; case NF_KEY_WW : // WW - sBuff.append(ImpIntToString( nIx, + sBuff.append(ImpIntToString(pNatNum, nIx, rCal.getValue( CalendarFieldIndex::WEEK_OF_YEAR ))); break; case NF_KEY_G: // G @@ -3980,6 +4021,7 @@ bool SvNumberformat::ImpGetDateOutput(double fNumber, bool SvNumberformat::ImpGetDateTimeOutput(double fNumber, sal_uInt16 nIx, bool bStarFlag, + const NativeNumberWrapper* pNatNum, OUStringBuffer& sBuff) const { using namespace ::com::sun::star::i18n; @@ -4044,14 +4086,14 @@ bool SvNumberformat::ImpGetDateTimeOutput(double fNumber, nMin = nCMinute; nSec = nCSecond; nCntPost = ImpGetFractionOfSecondString( sSecStr, fFractionOfSecond, nCntPost, true, nIx, - (bInputLine ? rInfo.nCntPost : 0)); + (bInputLine ? rInfo.nCntPost : 0), pNatNum ); } else { sal_uInt32 nSeconds = static_cast<sal_uInt32>(floor( fTime )); nCntPost = ImpGetFractionOfSecondString( sSecStr, fTime - nSeconds, nCntPost, false, nIx, - (bInputLine ? rInfo.nCntPost : 0)); + (bInputLine ? rInfo.nCntPost : 0), pNatNum ); if (rInfo.nThousand == 3) // [ss] { @@ -4167,22 +4209,22 @@ bool SvNumberformat::ImpGetDateTimeOutput(double fNumber, } break; case NF_KEY_MI: // M - sBuff.append(ImpIntToString( nIx, nMin )); + sBuff.append(ImpIntToString(pNatNum, nIx, nMin )); break; case NF_KEY_MMI: // MM - sBuff.append(ImpIntToString( nIx, nMin, 2 )); + sBuff.append(ImpIntToString(pNatNum, nIx, nMin, 2 )); break; case NF_KEY_H: // H - sBuff.append(ImpIntToString( nIx, nHour )); + sBuff.append(ImpIntToString(pNatNum, nIx, nHour )); break; case NF_KEY_HH: // HH - sBuff.append(ImpIntToString( nIx, nHour, 2 )); + sBuff.append(ImpIntToString(pNatNum, nIx, nHour, 2 )); break; case NF_KEY_S: // S - sBuff.append(ImpIntToString( nIx, nSec )); + sBuff.append(ImpIntToString(pNatNum, nIx, nSec )); break; case NF_KEY_SS: // SS - sBuff.append(ImpIntToString( nIx, nSec, 2 )); + sBuff.append(ImpIntToString(pNatNum, nIx, nSec, 2 )); break; case NF_KEY_M: // M sBuff.append(rCal.getDisplayString( @@ -4276,7 +4318,7 @@ bool SvNumberformat::ImpGetDateTimeOutput(double fNumber, // without suddenly being hit by the 2-digit year magic. OUStringBuffer aBuf; padToLength(aBuf, 4 - aYear.getLength(), '0'); - impTransliterate(aBuf, NumFor[nIx].GetNatNum()); + ::impTransliterate(aBuf, NumFor[nIx].GetNatNum(), pNatNum); aBuf.append(aYear); sBuff.append(aBuf); } @@ -4309,7 +4351,7 @@ bool SvNumberformat::ImpGetDateTimeOutput(double fNumber, sBuff.append(rLoc().getLongDateDayOfWeekSep()); break; case NF_KEY_WW : // WW - sBuff.append(ImpIntToString( nIx, rCal.getValue( CalendarFieldIndex::WEEK_OF_YEAR ))); + sBuff.append(ImpIntToString(pNatNum, nIx, rCal.getValue( CalendarFieldIndex::WEEK_OF_YEAR ))); break; case NF_KEY_G: // G ImpAppendEraG( sBuff, rCal, nNatNum ); @@ -4334,6 +4376,7 @@ bool SvNumberformat::ImpGetDateTimeOutput(double fNumber, bool SvNumberformat::ImpGetLogicalOutput(double fNumber, sal_uInt16 nIx, + const NativeNumberWrapper* pNatNum, OUStringBuffer& sStr) const { bool bRes = false; @@ -4351,13 +4394,14 @@ bool SvNumberformat::ImpGetLogicalOutput(double fNumber, break; } } - impTransliterate(sStr, NumFor[nIx].GetNatNum()); + ::impTransliterate(sStr, NumFor[nIx].GetNatNum(), pNatNum); return bRes; } bool SvNumberformat::ImpGetNumberOutput(double fNumber, sal_uInt16 nIx, bool bStarFlag, + const NativeNumberWrapper* pNatNum, OUStringBuffer& sStr) const { bool bRes = false; @@ -4464,16 +4508,17 @@ bool SvNumberformat::ImpGetNumberOutput(double fNumber, // Edit backwards: j = NumFor[nIx].GetCount()-1; // Last symbol // Decimal places: - bRes |= ImpDecimalFill( sStr, fNumber, nDecPos, j, nIx, bInteger, bStarFlag ); + bRes |= ImpDecimalFill(pNatNum, sStr, fNumber, nDecPos, j, nIx, bInteger, bStarFlag); if (bSign) { sStr.insert(0, '-'); } - impTransliterate(sStr, NumFor[nIx].GetNatNum()); + ::impTransliterate(sStr, NumFor[nIx].GetNatNum(), pNatNum); return bRes; } -bool SvNumberformat::ImpDecimalFill( OUStringBuffer& sStr, // number string +bool SvNumberformat::ImpDecimalFill(const NativeNumberWrapper* pNatNum, + OUStringBuffer& sStr, // number string double& rNumber, // number sal_Int32 nDecPos, // decimals start sal_uInt16 j, // symbol index within format code @@ -4577,7 +4622,7 @@ bool SvNumberformat::ImpDecimalFill( OUStringBuffer& sStr, // number string case NF_KEY_GENERAL: // Standard in the String { OUStringBuffer sNum; - ImpGetOutputStandard(rNumber, sNum); + ImpGetOutputStandard(rNumber, sNum, pNatNum); sNum.stripStart('-'); sStr.insert(k, sNum); break; @@ -4589,19 +4634,20 @@ bool SvNumberformat::ImpDecimalFill( OUStringBuffer& sStr, // number string } // of while } // of decimal places - bRes |= ImpNumberFillWithThousands(sStr, rNumber, k, j, nIx, // Fill with . if needed + bRes |= ImpNumberFillWithThousands(pNatNum, sStr, rNumber, k, j, nIx, // Fill with . if needed rInfo.nCntPre, bStarFlag, bFilled ); return bRes; } -bool SvNumberformat::ImpNumberFillWithThousands( OUStringBuffer& sBuff, // number string +bool SvNumberformat::ImpNumberFillWithThousands( const NativeNumberWrapper* pNatNum, + OUStringBuffer& sBuff, // number string double& rNumber, // number sal_Int32 k, // position within string sal_uInt16 j, // symbol index within format code sal_uInt16 nIx, // subformat index sal_Int32 nDigCnt, // count of integer digits in format - bool bStarFlag, // Take *n format as ESC n + bool bStarFlag, bool bAddDecSep) const // add decimal separator if necessary { bool bRes = false; @@ -4611,7 +4657,7 @@ bool SvNumberformat::ImpNumberFillWithThousands( OUStringBuffer& sBuff, // numb const ImpSvNumberformatInfo& rInfo = NumFor[nIx].Info(); // no normal thousands separators if number divided by thousands bool bDoThousands = (rInfo.nThousand == 0); - utl::DigitGroupingIterator aGrouping( GetFormatter().GetLocaleData()->getDigitGrouping()); + utl::DigitGroupingIterator aGrouping( GetCurrentLanguageData().GetLocaleData()->getDigitGrouping()); while (!bStop) // backwards { @@ -4738,7 +4784,7 @@ bool SvNumberformat::ImpNumberFillWithThousands( OUStringBuffer& sBuff, // numb case NF_KEY_GENERAL: // "General" in string { OUStringBuffer sNum; - ImpGetOutputStandard(rNumber, sNum); + ImpGetOutputStandard(rNumber, sNum, pNatNum); sNum.stripStart('-'); sBuff.insert(k, sNum); break; @@ -4766,7 +4812,7 @@ void SvNumberformat::ImpDigitFill(OUStringBuffer& sStr, // number string { if (NumFor[nIx].Info().bThousand) // Only if grouping fill in separators { - const OUString& rThousandSep = GetFormatter().GetNumThousandSep(); + const OUString& rThousandSep = GetCurrentLanguageData().GetNumThousandSep(); while (k > nStart) { if (nDigitCount == rGrouping.getPos()) @@ -4784,13 +4830,14 @@ void SvNumberformat::ImpDigitFill(OUStringBuffer& sStr, // number string } } -bool SvNumberformat::ImpNumberFill( OUStringBuffer& sBuff, // number string +bool SvNumberformat::ImpNumberFill( const NativeNumberWrapper* pNatNum, + OUStringBuffer& sBuff, // number string double& rNumber, // number for "General" format sal_Int32& k, // position within string sal_uInt16& j, // symbol index within format code sal_uInt16 nIx, // subformat index short eSymbolType, // type of stop condition - bool bStarFlag, // Take *n format as ESC n + bool bStarFlag, bool bInsertRightBlank) const // insert blank on right for denominator (default = false) { bool bRes = false; @@ -4875,7 +4922,7 @@ bool SvNumberformat::ImpNumberFill( OUStringBuffer& sBuff, // number string { OUStringBuffer sNum; bFoundNumber = true; - ImpGetOutputStandard(rNumber, sNum); + ImpGetOutputStandard(rNumber, sNum, pNatNum); sNum.stripStart('-'); sBuff.insert(k, sNum); } @@ -5627,8 +5674,10 @@ OUString SvNumberformat::GetMappedFormatstring( const NfKeywordTable& rKeywords, return aStr.makeStringAndClear(); } -OUString SvNumberformat::ImpGetNatNumString( const SvNumberNatNum& rNum, - sal_Int64 nVal, sal_uInt16 nMinDigits ) const +// static +OUString SvNumberformat::ImpGetNatNumString(const SvNumberNatNum& rNum, + sal_Int64 nVal, sal_uInt16 nMinDigits, + const NativeNumberWrapper* pNatNum) { OUString aStr; if ( nMinDigits ) @@ -5671,33 +5720,17 @@ OUString SvNumberformat::ImpGetNatNumString( const SvNumberNatNum& rNum, { aStr = OUString::number( nVal ); } - return impTransliterate(aStr, rNum); -} - -OUString SvNumberformat::impTransliterateImpl(const OUString& rStr, - const SvNumberNatNum& rNum ) const -{ - css::lang::Locale aLocale( LanguageTag( rNum.GetLang() ).getLocale() ); - return GetFormatter().GetNatNum()->getNativeNumberStringParams(rStr, aLocale, rNum.GetNatNum(), - rNum.GetParams()); -} - -void SvNumberformat::impTransliterateImpl(OUStringBuffer& rStr, - const SvNumberNatNum& rNum ) const -{ - css::lang::Locale aLocale( LanguageTag( rNum.GetLang() ).getLocale() ); - - rStr = GetFormatter().GetNatNum()->getNativeNumberStringParams( - OUString::unacquired(rStr), aLocale, rNum.GetNatNum(), rNum.GetParams()); + return ::impTransliterate(aStr, rNum, pNatNum); } OUString SvNumberformat::impTransliterateImpl(const OUString& rStr, const SvNumberNatNum& rNum, - const sal_uInt16 nDateKey) const + const sal_uInt16 nDateKey, + const NativeNumberWrapper* pNatNum) const { // no KEYWORD=argument list in NatNum12 if (rNum.GetParams().indexOf('=') == -1) - return impTransliterateImpl( rStr, rNum); + return ::impTransliterateImpl( rStr, rNum, pNatNum); const NfKeywordTable & rKeywords = rScan.GetKeywords(); @@ -5724,13 +5757,13 @@ OUString SvNumberformat::impTransliterateImpl(const OUString& rStr, css::lang::Locale aLocale( LanguageTag( rNum.GetLang() ).getLocale() ); - return GetFormatter().GetNatNum()->getNativeNumberStringParams( + return pNatNum->getNativeNumberStringParams( rStr, aLocale, rNum.GetNatNum(), rNum.GetParams().copy(nField + nKeywordLen, nFieldEnd - nField - nKeywordLen)); } void SvNumberformat::GetNatNumXml( css::i18n::NativeNumberXmlAttributes2& rAttr, - sal_uInt16 nNumFor ) const + sal_uInt16 nNumFor, const NativeNumberWrapper* pNatNum ) const { if ( nNumFor <= 3 ) { @@ -5745,7 +5778,7 @@ void SvNumberformat::GetNatNumXml( css::i18n::NativeNumberXmlAttributes2& rAttr, * adapted, and whether to fill Spellout or something different * should be internal there. */ css::i18n::NativeNumberXmlAttributes aTmp( - GetFormatter().GetNatNum()->convertToXmlAttributes( + pNatNum->convertToXmlAttributes( aLocale, rNum.GetNatNum())); rAttr.Locale = aTmp.Locale; rAttr.Format = aTmp.Format; @@ -6088,9 +6121,9 @@ CalendarWrapper& SvNumberformat::GetCal() const return rScan.GetCal(); } -const SvNumberFormatter& SvNumberformat::GetFormatter() const +const SvNFLanguageData& SvNumberformat::GetCurrentLanguageData() const { - return *rScan.GetNumberformatter(); + return rScan.GetCurrentLanguageData(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/numbers/zforscan.cxx b/svl/source/numbers/zforscan.cxx index 537c19415ff7..f112d4d19ea4 100644 --- a/svl/source/numbers/zforscan.cxx +++ b/svl/source/numbers/zforscan.cxx @@ -121,15 +121,17 @@ static const std::u16string_view& GermanColorName(size_t i) return sGermanColorNames[i]; } -ImpSvNumberformatScan::ImpSvNumberformatScan( SvNumberFormatter* pFormatterP ) +ImpSvNumberformatScan::ImpSvNumberformatScan(SvNFLanguageData& rCurrentLanguageData, + const SvNumberFormatter& rColorCallback) : maNullDate( 30, 12, 1899) + , mrCurrentLanguageData(rCurrentLanguageData) + , mrColorCallback(rColorCallback) , eNewLnge(LANGUAGE_DONTKNOW) , eTmpLnge(LANGUAGE_DONTKNOW) , nCurrPos(-1) , meKeywordLocalization(KeywordLocalization::AllowEnglish) { - pFormatter = pFormatterP; - xNFC = css::i18n::NumberFormatMapper::create( pFormatter->GetComponentContext() ); + xNFC = css::i18n::NumberFormatMapper::create(rCurrentLanguageData.GetComponentContext()); bConvertMode = false; mbConvertDateOrder = false; bConvertSystemToSystem = false; @@ -167,7 +169,7 @@ void ImpSvNumberformatScan::InitSpecialKeyword( NfKeywordIndex eIdx ) const { case NF_KEY_TRUE : const_cast<ImpSvNumberformatScan*>(this)->sKeyword[NF_KEY_TRUE] = - pFormatter->GetCharClass()->uppercase( pFormatter->GetLocaleData()->getTrueWord() ); + mrCurrentLanguageData.GetCharClass()->uppercase( mrCurrentLanguageData.GetLocaleData()->getTrueWord() ); if ( sKeyword[NF_KEY_TRUE].isEmpty() ) { SAL_WARN( "svl.numbers", "InitSpecialKeyword: TRUE_WORD?" ); @@ -176,7 +178,7 @@ void ImpSvNumberformatScan::InitSpecialKeyword( NfKeywordIndex eIdx ) const break; case NF_KEY_FALSE : const_cast<ImpSvNumberformatScan*>(this)->sKeyword[NF_KEY_FALSE] = - pFormatter->GetCharClass()->uppercase( pFormatter->GetLocaleData()->getFalseWord() ); + mrCurrentLanguageData.GetCharClass()->uppercase( mrCurrentLanguageData.GetLocaleData()->getFalseWord() ); if ( sKeyword[NF_KEY_FALSE].isEmpty() ) { SAL_WARN( "svl.numbers", "InitSpecialKeyword: FALSE_WORD?" ); @@ -192,9 +194,9 @@ void ImpSvNumberformatScan::InitCompatCur() const { ImpSvNumberformatScan* pThis = const_cast<ImpSvNumberformatScan*>(this); // currency symbol for old style ("automatic") compatibility format codes - pFormatter->GetCompatibilityCurrency( pThis->sCurSymbol, pThis->sCurAbbrev ); + mrCurrentLanguageData.GetCompatibilityCurrency( pThis->sCurSymbol, pThis->sCurAbbrev ); // currency symbol upper case - pThis->sCurString = pFormatter->GetCharClass()->uppercase( sCurSymbol ); + pThis->sCurString = mrCurrentLanguageData.GetCharClass()->uppercase( sCurSymbol ); bCompatCurNeedInit = false; } @@ -258,8 +260,8 @@ void ImpSvNumberformatScan::SetDependentKeywords() using namespace ::com::sun::star; using namespace ::com::sun::star::uno; - const CharClass* pCharClass = pFormatter->GetCharClass(); - const LocaleDataWrapper* pLocaleData = pFormatter->GetLocaleData(); + const CharClass* pCharClass = mrCurrentLanguageData.GetCharClass(); + const LocaleDataWrapper* pLocaleData = mrCurrentLanguageData.GetLocaleData(); // #80023# be sure to generate keywords for the loaded Locale, not for the // requested Locale, otherwise number format codes might not match const LanguageTag& rLoadedLocale = pLocaleData->getLoadedLanguageTag(); @@ -540,7 +542,7 @@ void ImpSvNumberformatScan::ChangeStandardPrec(sal_uInt16 nPrec) const Color* ImpSvNumberformatScan::GetColor(OUString& sStr) const { - OUString sString = pFormatter->GetCharClass()->uppercase(sStr); + OUString sString = mrCurrentLanguageData.GetCharClass()->uppercase(sStr); const NfKeywordTable & rKeyword = GetKeywords(); size_t i = 0; while (i < NF_MAX_DEFAULT_COLORS && sString != rKeyword[NF_KEY_FIRSTCOLOR+i] ) @@ -549,7 +551,7 @@ const Color* ImpSvNumberformatScan::GetColor(OUString& sStr) const } if (i >= NF_MAX_DEFAULT_COLORS && meKeywordLocalization == KeywordLocalization::AllowEnglish) { - LanguageType eLang = pFormatter->GetLocaleData()->getLoadedLanguageTag().getLanguageType( false); + LanguageType eLang = mrCurrentLanguageData.GetLocaleData()->getLoadedLanguageTag().getLanguageType( false); if ( eLang.anyOf( LANGUAGE_GERMAN, LANGUAGE_GERMAN_SWISS, @@ -628,7 +630,7 @@ const Color* ImpSvNumberformatScan::GetColor(OUString& sStr) const sal_Int32 nIndex = sString.toInt32(); if (nIndex > 0 && nIndex <= 64) { - pResult = pFormatter->GetUserDefColor(static_cast<sal_uInt16>(nIndex)-1); + pResult = GetUserDefColor(static_cast<sal_uInt16>(nIndex)-1); } } } @@ -655,7 +657,7 @@ const Color* ImpSvNumberformatScan::GetColor(OUString& sStr) const short ImpSvNumberformatScan::GetKeyWord( const OUString& sSymbol, sal_Int32 nPos, bool& rbFoundEnglish ) const { - OUString sString = pFormatter->GetCharClass()->uppercase( sSymbol, nPos, sSymbol.getLength() - nPos ); + OUString sString = mrCurrentLanguageData.GetCharClass()->uppercase( sSymbol, nPos, sSymbol.getLength() - nPos ); const NfKeywordTable & rKeyword = GetKeywords(); // #77026# for the Xcl perverts: the GENERAL keyword is recognized anywhere if (sString.startsWith( rKeyword[NF_KEY_GENERAL] )) @@ -760,8 +762,8 @@ short ImpSvNumberformatScan::Next_Symbol( const OUString& rStr, OUString& sSymbol ) const { InitKeywords(); - const CharClass* pChrCls = pFormatter->GetCharClass(); - const LocaleDataWrapper* pLoc = pFormatter->GetLocaleData(); + const CharClass* pChrCls = mrCurrentLanguageData.GetCharClass(); + const LocaleDataWrapper* pLoc = mrCurrentLanguageData.GetLocaleData(); short eType = 0; ScanState eState = SsStart; OUStringBuffer sSymbolBuffer; @@ -839,9 +841,9 @@ short ImpSvNumberformatScan::Next_Symbol( const OUString& rStr, sSymbolBuffer.append(OUStringChar(cToken)); break; default : - if (StringEqualsChar( pFormatter->GetNumDecimalSep(), cToken) || - StringEqualsChar( pFormatter->GetNumThousandSep(), cToken) || - StringEqualsChar( pFormatter->GetDateSep(), cToken) || + if (StringEqualsChar( mrCurrentLanguageData.GetNumDecimalSep(), cToken) || + StringEqualsChar( mrCurrentLanguageData.GetNumThousandSep(), cToken) || + StringEqualsChar( mrCurrentLanguageData.GetDateSep(), cToken) || StringEqualsChar( pLoc->getTimeSep(), cToken) || StringEqualsChar( pLoc->getTime100SecSep(), cToken)) { @@ -1017,7 +1019,7 @@ sal_Int32 ImpSvNumberformatScan::Symbol_Division(const OUString& rString) { nCurrPos = -1; // Do we have some sort of currency? - OUString sString = pFormatter->GetCharClass()->uppercase(rString); + OUString sString = mrCurrentLanguageData.GetCharClass()->uppercase(rString); sal_Int32 nCPos = 0; while (nCPos >= 0 && nCPos < sString.getLength()) { @@ -1248,7 +1250,7 @@ bool ImpSvNumberformatScan::Is100SecZero( sal_uInt16 i, bool bHadDecSep ) const sal_Int32 ImpSvNumberformatScan::ScanType() { - const LocaleDataWrapper* pLoc = pFormatter->GetLocaleData(); + const LocaleDataWrapper* pLoc = mrCurrentLanguageData.GetLocaleData(); sal_Int32 nPos = 0; sal_uInt16 i = 0; @@ -1505,7 +1507,7 @@ sal_Int32 ImpSvNumberformatScan::ScanType() { eScannedType = SvNumFormatType::UNDEFINED; } - else if ( sStrArray[i] != pFormatter->GetDateSep() ) + else if ( sStrArray[i] != mrCurrentLanguageData.GetDateSep() ) { return nPos; } @@ -1544,7 +1546,7 @@ sal_Int32 ImpSvNumberformatScan::ScanType() { eScannedType = SvNumFormatType::UNDEFINED; } - else if ( pFormatter->GetDateSep() != sStrArray[i] && + else if ( mrCurrentLanguageData.GetDateSep() != sStrArray[i] && pLoc->getTimeSep() != sStrArray[i] ) { return nPos; @@ -1730,12 +1732,12 @@ void ImpSvNumberformatScan::SwapArrayElements( size_t nPos1, size_t nPos2 ) sal_Int32 ImpSvNumberformatScan::FinalScan( OUString& rString ) { - const LocaleDataWrapper* pLoc = pFormatter->GetLocaleData(); + const LocaleDataWrapper* pLoc = mrCurrentLanguageData.GetLocaleData(); // save values for convert mode - OUString sOldDecSep = pFormatter->GetNumDecimalSep(); - OUString sOldThousandSep = pFormatter->GetNumThousandSep(); - OUString sOldDateSep = pFormatter->GetDateSep(); + OUString sOldDecSep = mrCurrentLanguageData.GetNumDecimalSep(); + OUString sOldThousandSep = mrCurrentLanguageData.GetNumThousandSep(); + OUString sOldDateSep = mrCurrentLanguageData.GetDateSep(); OUString sOldTimeSep = pLoc->getTimeSep(); OUString sOldTime100SecSep= pLoc->getTime100SecSep(); OUString sOldCurSymbol = GetCurSymbol(); @@ -1761,9 +1763,9 @@ sal_Int32 ImpSvNumberformatScan::FinalScan( OUString& rString ) // change locale data et al if (bConvertMode) { - pFormatter->ChangeIntl(eNewLnge); + mrCurrentLanguageData.ChangeIntl(eNewLnge); //! pointer may have changed - pLoc = pFormatter->GetLocaleData(); + pLoc = mrCurrentLanguageData.GetLocaleData(); //! init new keywords InitKeywords(); // Adapt date order to target locale, but Excel does not handle date @@ -1771,7 +1773,7 @@ sal_Int32 ImpSvNumberformatScan::FinalScan( OUString& rString ) // though it does exchange separators, tdf#113889 bNewDateOrder = (mbConvertDateOrder && eOldDateOrder != pLoc->getDateOrder()); } - const CharClass* pChrCls = pFormatter->GetCharClass(); + const CharClass* pChrCls = mrCurrentLanguageData.GetCharClass(); sal_Int32 nPos = 0; // error correction position sal_uInt16 i = 0; // symbol loop counter @@ -1944,11 +1946,11 @@ sal_Int32 ImpSvNumberformatScan::FinalScan( OUString& rString ) sal_Unicode cSaved = cHere; // Handle not pre-known separators in switch. sal_Unicode cSimplified; - if (StringEqualsChar( pFormatter->GetNumThousandSep(), cHere)) + if (StringEqualsChar( mrCurrentLanguageData.GetNumThousandSep(), cHere)) { cSimplified = ','; } - else if (StringEqualsChar( pFormatter->GetNumDecimalSep(), cHere)) + else if (StringEqualsChar( mrCurrentLanguageData.GetNumDecimalSep(), cHere)) { cSimplified = '.'; } @@ -2078,7 +2080,7 @@ sal_Int32 ImpSvNumberformatScan::FinalScan( OUString& rString ) // strange, those French... bool bFirst = true; // set a hard No-Break Space or ConvertMode - const OUString& rSepF = pFormatter->GetNumThousandSep(); + const OUString& rSepF = mrCurrentLanguageData.GetNumThousandSep(); while ( i < nStringsCnt && sStrArray[i] == sOldThousandSep && StringEqualsChar( sOldThousandSep, NextChar(i) ) ) @@ -2141,7 +2143,7 @@ sal_Int32 ImpSvNumberformatScan::FinalScan( OUString& rString ) nThousand++; nTypeArray[i] = NF_SYMBOLTYPE_THSEP; nPos = nPos + sStrArray[i].getLength(); - sStrArray[i] = pFormatter->GetNumThousandSep(); + sStrArray[i] = mrCurrentLanguageData.GetNumThousandSep(); i++; } while (i < nStringsCnt && sStrArray[i] == sOldThousandSep); @@ -2193,7 +2195,7 @@ sal_Int32 ImpSvNumberformatScan::FinalScan( OUString& rString ) { nPos = nPos + sStrArray[i].getLength(); nTypeArray[i] = NF_SYMBOLTYPE_DECSEP; - sStrArray[i] = pFormatter->GetNumDecimalSep(); + sStrArray[i] = mrCurrentLanguageData.GetNumDecimalSep(); bDecSep = true; nDecPos = i; nCntPre = nCounter; @@ -2432,7 +2434,7 @@ sal_Int32 ImpSvNumberformatScan::FinalScan( OUString& rString ) { DBG_ASSERT( sStrArray[i].getLength() == 1, "ImpSvNumberformatScan::FinalScan: combined digits in group separator insertion"); - if (!InsertSymbol( i, NF_SYMBOLTYPE_THSEP, pFormatter->GetNumThousandSep())) + if (!InsertSymbol( i, NF_SYMBOLTYPE_THSEP, mrCurrentLanguageData.GetNumThousandSep())) { // nPos isn't correct here, but signals error return nPos; @@ -2486,7 +2488,7 @@ sal_Int32 ImpSvNumberformatScan::FinalScan( OUString& rString ) nPos = nPos + sStrArray[i].getLength(); if (bConvertMode) { - sStrArray[i] = pFormatter->GetDateSep(); + sStrArray[i] = mrCurrentLanguageData.GetDateSep(); } i++; } @@ -2800,7 +2802,7 @@ sal_Int32 ImpSvNumberformatScan::FinalScan( OUString& rString ) { nTypeArray[i] = NF_SYMBOLTYPE_DATESEP; if (bConvertMode) - sStrArray[i] = pFormatter->GetDateSep(); + sStrArray[i] = mrCurrentLanguageData.GetDateSep(); } else { @@ -3131,16 +3133,16 @@ sal_Int32 ImpSvNumberformatScan::FinalScan( OUString& rString ) case '.': case '/': if (!(eScannedType & SvNumFormatType::DATE) && - (StringEqualsChar( pFormatter->GetNumThousandSep(), c) || - StringEqualsChar( pFormatter->GetNumDecimalSep(), c) || + (StringEqualsChar( mrCurrentLanguageData.GetNumThousandSep(), c) || + StringEqualsChar( mrCurrentLanguageData.GetNumDecimalSep(), c) || (c == ' ' && - (StringEqualsChar( pFormatter->GetNumThousandSep(), cNoBreakSpace) || - StringEqualsChar( pFormatter->GetNumThousandSep(), cNarrowNoBreakSpace))))) + (StringEqualsChar( mrCurrentLanguageData.GetNumThousandSep(), cNoBreakSpace) || + StringEqualsChar( mrCurrentLanguageData.GetNumThousandSep(), cNarrowNoBreakSpace))))) { rString += sStrArray[i]; } else if ((eScannedType & SvNumFormatType::DATE) && - StringEqualsChar( pFormatter->GetDateSep(), c)) + StringEqualsChar( mrCurrentLanguageData.GetDateSep(), c)) { rString += sStrArray[i]; } @@ -3329,4 +3331,9 @@ bool ImpSvNumberformatScan::ReplaceBooleanEquivalent( OUString& rString ) return false; } +Color* ImpSvNumberformatScan::GetUserDefColor(sal_uInt16 nIndex) const +{ + return mrColorCallback.GetUserDefColor(nIndex); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/numbers/zforscan.hxx b/svl/source/numbers/zforscan.hxx index c160dd424e48..41136c5e5b0b 100644 --- a/svl/source/numbers/zforscan.hxx +++ b/svl/source/numbers/zforscan.hxx @@ -29,7 +29,7 @@ #include <tools/date.hxx> #include <unotools/localedatawrapper.hxx> -class SvNumberFormatter; +class SvNFLanguageData; struct ImpSvNumberformatInfo; @@ -50,7 +50,8 @@ public: AllowEnglish ///< allow English keywords as well as localized keywords }; - explicit ImpSvNumberformatScan( SvNumberFormatter* pFormatter ); + explicit ImpSvNumberformatScan(SvNFLanguageData& rCurrentLanguageData, + const SvNumberFormatter& rColorCallback); ~ImpSvNumberformatScan(); void ChangeIntl( KeywordLocalization eKeywordLocalization = KeywordLocalization::AllowEnglish ); // Replaces Keywords @@ -63,9 +64,9 @@ public: sal_uInt16 nCnt); // Copies the FormatInfo sal_uInt16 GetResultStringsCnt() const { return nResultStringsCnt; } - const CharClass& GetChrCls() const { return *pFormatter->GetCharClass(); } - const LocaleDataWrapper& GetLoc() const { return *pFormatter->GetLocaleData(); } - CalendarWrapper& GetCal() const { return *pFormatter->GetCalendar(); } + const CharClass& GetChrCls() const { return *mrCurrentLanguageData.GetCharClass(); } + const LocaleDataWrapper& GetLoc() const { return *mrCurrentLanguageData.GetLocaleData(); } + CalendarWrapper& GetCal() const { return *mrCurrentLanguageData.GetCalendar(); } const NfKeywordTable & GetKeywords() const { @@ -170,11 +171,13 @@ public: /// set Thai T speciality void SetNatNumModifier( sal_uInt8 n ) { nNatNumModifier = n; } - SvNumberFormatter* GetNumberformatter() { return pFormatter; } // Access to formatter (for zformat.cxx) + SvNFLanguageData& GetCurrentLanguageData() { return mrCurrentLanguageData; } // Access to formatter (for zformat.cxx) /// Get type scanned (so far). SvNumFormatType GetScannedType() const { return eScannedType; } + const SvNumberFormatter& getColorCallback() const { return mrColorCallback; } + static constexpr OUString sErrStr = u"#FMT"_ustr; // String for error output private: // Private section @@ -184,7 +187,8 @@ private: // Private section Date maNullDate; // 30Dec1899 OUString sNameStandardFormat; // "Standard" sal_uInt16 nStandardPrec; // Default Precision for Standardformat - SvNumberFormatter* pFormatter; // Pointer to the FormatList + SvNFLanguageData& mrCurrentLanguageData; // Reference to the Language Data + const SvNumberFormatter& mrColorCallback; // Reference to the Color Callback supplier css::uno::Reference< css::i18n::XNumberFormatCode > xNFC; OUString sStrArray[NF_MAX_FORMAT_SYMBOLS]; // Array of symbols @@ -292,6 +296,8 @@ private: // Private section /** Swap nTypeArray and sStrArray elements at positions. */ void SwapArrayElements( size_t nPos1, size_t nPos2 ); + Color* GetUserDefColor(sal_uInt16 nIndex) const; + static bool StringEqualsChar( std::u16string_view rStr, sal_Unicode ch ) { return rStr.size() == 1 && rStr[0] == ch; } diff --git a/sw/source/uibase/utlui/numfmtlb.cxx b/sw/source/uibase/utlui/numfmtlb.cxx index ad601c981716..491eeaa88a9a 100644 --- a/sw/source/uibase/utlui/numfmtlb.cxx +++ b/sw/source/uibase/utlui/numfmtlb.cxx @@ -263,7 +263,7 @@ void SwNumFormatBase::SetFormatType(const SvNumFormatType nFormatType) if( nFormat == pFormatter->GetFormatIndex( NF_NUMBER_STANDARD, m_eCurLanguage ) - || pFormat->GetOutputString( fVal, sValue, &pCol ) + || pFormat->GetOutputString( fVal, sValue, &pCol, pFormatter->GetNatNum() ) || nFormatType == SvNumFormatType::UNDEFINED ) { sValue = pFormat->GetFormatstring(); diff --git a/xmloff/source/style/xmlnumfe.cxx b/xmloff/source/style/xmlnumfe.cxx index f86893c6708e..ada2cd494665 100644 --- a/xmloff/source/style/xmlnumfe.cxx +++ b/xmloff/source/style/xmlnumfe.cxx @@ -1247,7 +1247,7 @@ void SvXMLNumFmtExport::ExportPart_Impl( const SvNumberformat& rFormat, sal_uInt // Native number transliteration css::i18n::NativeNumberXmlAttributes2 aAttr; - rFormat.GetNatNumXml( aAttr, nPart ); + rFormat.GetNatNumXml( aAttr, nPart, m_pFormatter->GetNatNum() ); if ( !aAttr.Format.isEmpty() ) { assert(aAttr.Spellout.isEmpty()); // mutually exclusive |