nss: upgrade to release 3.73
[LibreOffice.git] / svl / source / numbers / zforscan.hxx
blobdc7c35aea3070502fd78b66a275cdc79dd68f31c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_SVL_SOURCE_NUMBERS_ZFORSCAN_HXX
20 #define INCLUDED_SVL_SOURCE_NUMBERS_ZFORSCAN_HXX
22 #include <i18nlangtag/lang.h>
23 #include <rtl/ustring.hxx>
24 #include <svl/nfkeytab.hxx>
25 #include <svl/nfsymbol.hxx>
26 #include <tools/color.hxx>
27 #include <tools/date.hxx>
29 class SvNumberFormatter;
30 struct ImpSvNumberformatInfo;
33 const size_t NF_MAX_DEFAULT_COLORS = 10;
35 // Hack: nThousand==1000 => "Default" occurs in format string
36 const sal_uInt16 FLAG_STANDARD_IN_FORMAT = 1000;
38 class ImpSvNumberformatScan
40 public:
42 /** Specify what keyword localization is allowed when scanning the format code. */
43 enum class KeywordLocalization
45 LocaleLegacy, ///< unfortunately localized in few locales, otherwise English
46 EnglishOnly, ///< only English, no localized keywords
47 AllowEnglish ///< allow English keywords as well as localized keywords
50 explicit ImpSvNumberformatScan( SvNumberFormatter* pFormatter );
51 ~ImpSvNumberformatScan();
52 void ChangeIntl( KeywordLocalization eKeywordLocalization = KeywordLocalization::AllowEnglish ); // Replaces Keywords
54 void ChangeNullDate(sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear); // Replaces reference date
55 void ChangeStandardPrec(sal_uInt16 nPrec); // Replaces standard precision
57 sal_Int32 ScanFormat( OUString& rString ); // Call scan analysis
59 void CopyInfo(ImpSvNumberformatInfo* pInfo,
60 sal_uInt16 nCnt); // Copies the FormatInfo
61 sal_uInt16 GetResultStringsCnt() const { return nResultStringsCnt; }
63 const CharClass& GetChrCls() const { return *pFormatter->GetCharClass(); }
64 const LocaleDataWrapper& GetLoc() const { return *pFormatter->GetLocaleData(); }
65 CalendarWrapper& GetCal() const { return *pFormatter->GetCalendar(); }
67 const NfKeywordTable & GetKeywords() const
69 if ( bKeywordsNeedInit )
71 InitKeywords();
73 return sKeyword;
76 static const NfKeywordTable & GetEnglishKeywords()
78 return sEnglishKeyword;
81 // Keywords used in output like true and false
82 const OUString& GetSpecialKeyword( NfKeywordIndex eIdx ) const
84 if ( sKeyword[eIdx].isEmpty() )
86 InitSpecialKeyword( eIdx );
88 return sKeyword[eIdx];
90 const OUString& GetTrueString() const { return GetSpecialKeyword( NF_KEY_TRUE ); }
91 const OUString& GetFalseString() const { return GetSpecialKeyword( NF_KEY_FALSE ); }
92 const OUString& GetRedString() const { return GetKeywords()[NF_KEY_RED]; }
93 const OUString& GetBooleanString() const { return GetKeywords()[NF_KEY_BOOLEAN]; }
94 static const ::std::vector<Color> & GetStandardColors()
96 return StandardColor;
98 static size_t GetMaxDefaultColors()
100 return NF_MAX_DEFAULT_COLORS;
103 const Date& GetNullDate() const { return maNullDate; }
104 const OUString& GetStandardName() const
106 if ( bKeywordsNeedInit )
108 InitKeywords();
110 return sNameStandardFormat;
112 sal_uInt16 GetStandardPrec() const { return nStandardPrec; }
113 static const Color& GetRedColor() { return StandardColor[4]; }
114 const Color* GetColor(OUString& sStr) const; // Set main colors or defines colors
116 // the compatibility currency symbol for old automatic currency formats
117 const OUString& GetCurSymbol() const
119 if ( bCompatCurNeedInit )
121 InitCompatCur();
123 return sCurSymbol;
126 // the compatibility currency abbreviation for CCC format code
127 const OUString& GetCurAbbrev() const
129 if ( bCompatCurNeedInit )
131 InitCompatCur();
133 return sCurAbbrev;
136 // the compatibility currency symbol upper case for old automatic currency formats
137 const OUString& GetCurString() const
139 if ( bCompatCurNeedInit )
141 InitCompatCur();
143 return sCurString;
146 /// Replace Boolean equivalent format codes with proper Boolean format.
147 void ReplaceBooleanEquivalent( OUString& rString );
149 void SetConvertMode(LanguageType eTmpLge, LanguageType eNewLge,
150 bool bSystemToSystem, bool bConvertDateOrder)
152 bConvertMode = true;
153 eNewLnge = eNewLge;
154 eTmpLnge = eTmpLge;
155 bConvertSystemToSystem = bSystemToSystem;
156 mbConvertDateOrder = bConvertDateOrder;
158 // Only changes the bool variable, in order to temporarily pause the convert mode
159 void SetConvertMode(bool bMode) { bConvertMode = bMode; }
160 bool GetConvertMode() const { return bConvertMode; }
161 LanguageType GetNewLnge() const { return eNewLnge; } // Read access on ConvertMode and convert country/language
162 LanguageType GetTmpLnge() const { return eTmpLnge; } // Read access on StartCountry/Language
163 void SetNewLnge( LanguageType e ) { eNewLnge = e; } // Set new convert country/language
165 /// get Thai T speciality
166 sal_uInt8 GetNatNumModifier() const { return nNatNumModifier; }
167 /// set Thai T speciality
168 void SetNatNumModifier( sal_uInt8 n ) { nNatNumModifier = n; }
170 SvNumberFormatter* GetNumberformatter() { return pFormatter; } // Access to formatter (for zformat.cxx)
172 /// Get type scanned (so far).
173 SvNumFormatType GetScannedType() const { return eScannedType; }
175 static constexpr OUStringLiteral sErrStr = u"#FMT"; // String for error output
177 private: // Private section
178 NfKeywordTable sKeyword; // Syntax keywords
179 static const NfKeywordTable sEnglishKeyword; // English Syntax keywords
180 static const ::std::vector<Color> StandardColor; // Standard color array
181 Date maNullDate; // 30Dec1899
182 OUString sNameStandardFormat; // "Standard"
183 sal_uInt16 nStandardPrec; // Default Precision for Standardformat
184 SvNumberFormatter* pFormatter; // Pointer to the FormatList
185 css::uno::Reference< css::i18n::XNumberFormatCode > xNFC;
187 OUString sStrArray[NF_MAX_FORMAT_SYMBOLS]; // Array of symbols
188 short nTypeArray[NF_MAX_FORMAT_SYMBOLS]; // Array of infos
189 // External Infos:
190 sal_uInt16 nResultStringsCnt; // Result symbol count
191 SvNumFormatType eScannedType; // Type according to scan
192 bool bThousand; // With thousands marker
193 sal_uInt16 nThousand; // Counts ... series
194 sal_uInt16 nCntPre; // Counts digits of integral part
195 sal_uInt16 nCntPost; // Counts digits of fractional part
196 sal_uInt16 nCntExp; // Counts exponent digits AM/PM
197 // Internal info:
198 sal_uInt16 nStringsCnt; // Symbol count
199 sal_uInt16 nExpPos; // Internal position of E
200 sal_uInt16 nBlankPos; // Internal position of the Blank
201 short nDecPos; // Internal position of the ,
202 bool bExp; // Set when reading E
203 bool bFrac; // Set when reading /
204 bool bBlank; // Set when reading ' ' (Fraction)
205 bool bDecSep; // Set on first ,
206 mutable bool bKeywordsNeedInit; // Locale dependent keywords need to be initialized
207 mutable bool bCompatCurNeedInit; // Locale dependent compatibility currency need to be initialized
208 OUString sCurSymbol; // Currency symbol for compatibility format codes
209 OUString sCurString; // Currency symbol in upper case
210 OUString sCurAbbrev; // Currency abbreviation
211 OUString sBooleanEquivalent1; // "TRUE";"TRUE";"FALSE"
212 OUString sBooleanEquivalent2; // [>0]"TRUE";[<0]"TRUE";"FALSE"
214 bool bConvertMode; // Set in the convert mode
215 bool mbConvertDateOrder; // Set in the convert mode whether to convert date particles order
217 LanguageType eNewLnge; // Language/country which the scanned string is converted to (for Excel filter)
218 LanguageType eTmpLnge; // Language/country which the scanned string is converted from (for Excel filter)
220 bool bConvertSystemToSystem; // Whether the conversion is from one system locale to another system locale
221 // (in this case the automatic currency symbol is converted too).
223 sal_Int32 nCurrPos; // Position of currency symbol
225 sal_uInt8 nNatNumModifier; // Thai T speciality
227 KeywordLocalization meKeywordLocalization; ///< which keywords localization to scan
229 // Copy assignment is forbidden and not implemented.
230 ImpSvNumberformatScan (const ImpSvNumberformatScan &) = delete;
231 ImpSvNumberformatScan & operator= (const ImpSvNumberformatScan &) = delete;
233 void InitKeywords() const;
234 void InitSpecialKeyword( NfKeywordIndex eIdx ) const;
235 void InitCompatCur() const;
237 void SetDependentKeywords();
238 // Sets the language dependent keywords
239 void SkipStrings(sal_uInt16& i, sal_Int32& nPos) const;// Skips StringSymbols
240 sal_uInt16 PreviousKeyword(sal_uInt16 i) const; // Returns index of the preceding one
241 // Keyword or 0
242 sal_uInt16 NextKeyword(sal_uInt16 i) const; // Returns index of the next one
243 // Keyword or 0
244 sal_Unicode PreviousChar(sal_uInt16 i) const; // Returns last char before index skips EMPTY, STRING, STAR, BLANK
245 sal_Unicode NextChar(sal_uInt16 i) const; // Returns first following char
246 short PreviousType( sal_uInt16 i ) const; // Returns type before position skips EMPTY
247 bool IsLastBlankBeforeFrac(sal_uInt16 i) const; // True <=> there won't be a ' ' until the '/'
248 void Reset(); // Reset all variables before starting the analysis
250 /** Determine keyword at nPos.
251 @param rbFoundEnglish set if English instead of locale's keyword
252 found, never cleared, thus init with false.
253 @return 0 if not found, else keyword enumeration.
255 short GetKeyWord( const OUString& sSymbol,
256 sal_Int32 nPos,
257 bool& rbFoundEnglish ) const;
259 bool IsAmbiguousE( short nKey ) const // whether nKey is ambiguous E of NF_KEY_E/NF_KEY_EC
261 return (nKey == NF_KEY_EC || nKey == NF_KEY_E) &&
262 (GetKeywords()[NF_KEY_EC] == GetKeywords()[NF_KEY_E]);
265 // if 0 at strArray[i] is of S,00 or SS,00 or SS"any"00 in ScanType() or FinalScan()
266 bool Is100SecZero( sal_uInt16 i, bool bHadDecSep ) const;
268 short Next_Symbol(const OUString& rStr,
269 sal_Int32& nPos,
270 OUString& sSymbol) const; // Next Symbol
271 sal_Int32 Symbol_Division(const OUString& rString);// Initial lexical scan
272 sal_Int32 ScanType(); // Analysis of the Format type
273 sal_Int32 FinalScan( OUString& rString ); // Final analysis with supplied type
275 // -1:= error, return nPos in FinalScan; 0:= no calendar, 1:= calendar found
276 int FinalScanGetCalendar( sal_Int32& nPos, sal_uInt16& i, sal_uInt16& nResultStringsCnt );
278 /** Insert symbol into nTypeArray and sStrArray, e.g. grouping separator.
279 If at nPos-1 a symbol type NF_SYMBOLTYPE_EMPTY is present, that is
280 reused instead of shifting all one up and nPos is decremented! */
281 bool InsertSymbol( sal_uInt16 & nPos, svt::NfSymbolType eType, const OUString& rStr );
283 /** Whether two key symbols are adjacent separated by date separator.
284 This can only be used at the end of FinalScan() after
285 NF_SYMBOLTYPE_DATESEP has already been set.
287 bool IsDateFragment( size_t nPos1, size_t nPos2 ) const;
289 /** Swap nTypeArray and sStrArray elements at positions. */
290 void SwapArrayElements( size_t nPos1, size_t nPos2 );
292 static bool StringEqualsChar( const OUString& rStr, sal_Unicode ch )
293 { return rStr.getLength() == 1 && rStr[0] == ch; }
295 // remove "..." and \... quotes from rStr, return how many chars removed
296 static sal_Int32 RemoveQuotes( OUString& rStr );
299 #endif // INCLUDED_SVL_SOURCE_NUMBERS_ZFORSCAN_HXX
301 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */