lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / svl / source / numbers / zforscan.hxx
blob0080d1dfeef329639465fe76e82ff588c6c42def
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 OUString& GetErrorString() { return sErrStr; }
95 static const ::std::vector<Color> & GetStandardColors()
97 return StandardColor;
99 static size_t GetMaxDefaultColors()
101 return NF_MAX_DEFAULT_COLORS;
104 const Date& GetNullDate() const { return maNullDate; }
105 const OUString& GetStandardName() const
107 if ( bKeywordsNeedInit )
109 InitKeywords();
111 return sNameStandardFormat;
113 sal_uInt16 GetStandardPrec() const { return nStandardPrec; }
114 static const Color& GetRedColor() { return StandardColor[4]; }
115 Color* GetColor(OUString& sStr); // Set main colors or defines colors
117 // the compatibility currency symbol for old automatic currency formats
118 const OUString& GetCurSymbol() const
120 if ( bCompatCurNeedInit )
122 InitCompatCur();
124 return sCurSymbol;
127 // the compatibility currency abbreviation for CCC format code
128 const OUString& GetCurAbbrev() const
130 if ( bCompatCurNeedInit )
132 InitCompatCur();
134 return sCurAbbrev;
137 // the compatibility currency symbol upper case for old automatic currency formats
138 const OUString& GetCurString() const
140 if ( bCompatCurNeedInit )
142 InitCompatCur();
144 return sCurString;
147 /// Replace Boolean equivalent format codes with proper Boolean format.
148 void ReplaceBooleanEquivalent( OUString& rString );
150 void SetConvertMode(LanguageType eTmpLge, LanguageType eNewLge,
151 bool bSystemToSystem, bool bConvertDateOrder)
153 bConvertMode = true;
154 eNewLnge = eNewLge;
155 eTmpLnge = eTmpLge;
156 bConvertSystemToSystem = bSystemToSystem;
157 mbConvertDateOrder = bConvertDateOrder;
159 // Only changes the bool variable, in order to temporarily pause the convert mode
160 void SetConvertMode(bool bMode) { bConvertMode = bMode; }
161 bool GetConvertMode() const { return bConvertMode; }
162 LanguageType GetNewLnge() const { return eNewLnge; } // Read access on ConvertMode and convert country/language
163 LanguageType GetTmpLnge() const { return eTmpLnge; } // Read access on StartCountry/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 private: // Private section
176 NfKeywordTable sKeyword; // Syntax keywords
177 static const NfKeywordTable sEnglishKeyword; // English Syntax keywords
178 static ::std::vector<Color> StandardColor; // Standard color array
179 static bool bStandardColorNeedInitialization; // initialize Standard color array
180 static ::std::vector<OUString> sGermanColorNames; // German color names 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"
213 static const OUString sErrStr; // String for error output
215 bool bConvertMode; // Set in the convert mode
216 bool mbConvertDateOrder; // Set in the convert mode whether to convert date particles order
218 LanguageType eNewLnge; // Language/country which the scanned string is converted to (for Excel filter)
219 LanguageType eTmpLnge; // Language/country which the scanned string is converted from (for Excel filter)
221 bool bConvertSystemToSystem; // Whether the conversion is from one system locale to another system locale
222 // (in this case the automatic currency symbol is converted too).
224 sal_Int32 nCurrPos; // Position of currency symbol
226 sal_uInt8 nNatNumModifier; // Thai T speciality
228 KeywordLocalization meKeywordLocalization; ///< which keywords localization to scan
230 // Copy assignment is forbidden and not implemented.
231 ImpSvNumberformatScan (const ImpSvNumberformatScan &) = delete;
232 ImpSvNumberformatScan & operator= (const ImpSvNumberformatScan &) = delete;
234 void InitKeywords() const;
235 void InitSpecialKeyword( NfKeywordIndex eIdx ) const;
236 void InitCompatCur() const;
238 void SetDependentKeywords();
239 // Sets the language dependent keywords
240 void SkipStrings(sal_uInt16& i, sal_Int32& nPos) const;// Skips StringSymbols
241 sal_uInt16 PreviousKeyword(sal_uInt16 i) const; // Returns index of the preceding one
242 // Keyword or 0
243 sal_uInt16 NextKeyword(sal_uInt16 i) const; // Returns index of the next one
244 // Keyword or 0
245 sal_Unicode PreviousChar(sal_uInt16 i) const; // Returns last char before index skips EMPTY, STRING, STAR, BLANK
246 sal_Unicode NextChar(sal_uInt16 i) const; // Returns first following char
247 short PreviousType( sal_uInt16 i ) const; // Returns type before position skips EMPTY
248 bool IsLastBlankBeforeFrac(sal_uInt16 i) const; // True <=> there won't be a ' ' until the '/'
249 void Reset(); // Reset all variables before starting the analysis
251 /** Determine keyword at nPos.
252 @param rbFoundEnglish set if English instead of locale's keyword
253 found, never cleared, thus init with false.
254 @return 0 if not found, else keyword enumeration.
256 short GetKeyWord( const OUString& sSymbol,
257 sal_Int32 nPos,
258 bool& rbFoundEnglish ) const;
260 bool IsAmbiguousE( short nKey ) const // whether nKey is ambiguous E of NF_KEY_E/NF_KEY_EC
262 return (nKey == NF_KEY_EC || nKey == NF_KEY_E) &&
263 (GetKeywords()[NF_KEY_EC] == GetKeywords()[NF_KEY_E]);
266 // if 0 at strArray[i] is of S,00 or SS,00 or SS"any"00 in ScanType() or FinalScan()
267 bool Is100SecZero( sal_uInt16 i, bool bHadDecSep ) const;
269 short Next_Symbol(const OUString& rStr,
270 sal_Int32& nPos,
271 OUString& sSymbol) const; // Next Symbol
272 sal_Int32 Symbol_Division(const OUString& rString);// Initial lexical scan
273 sal_Int32 ScanType(); // Analysis of the Format type
274 sal_Int32 FinalScan( OUString& rString ); // Final analysis with supplied type
276 // -1:= error, return nPos in FinalScan; 0:= no calendar, 1:= calendar found
277 int FinalScanGetCalendar( sal_Int32& nPos, sal_uInt16& i, sal_uInt16& nResultStringsCnt );
279 /** Insert symbol into nTypeArray and sStrArray, e.g. grouping separator.
280 If at nPos-1 a symbol type NF_SYMBOLTYPE_EMPTY is present, that is
281 reused instead of shifting all one up and nPos is decremented! */
282 bool InsertSymbol( sal_uInt16 & nPos, svt::NfSymbolType eType, const OUString& rStr );
284 /** Whether two key symbols are adjacent separated by date separator.
285 This can only be used at the end of FinalScan() after
286 NF_SYMBOLTYPE_DATESEP has already been set.
288 bool IsDateFragment( size_t nPos1, size_t nPos2 ) const;
290 /** Swap nTypeArray and sStrArray elements at positions. */
291 void SwapArrayElements( size_t nPos1, size_t nPos2 );
293 static bool StringEqualsChar( const OUString& rStr, sal_Unicode ch )
294 { return rStr.getLength() == 1 && rStr[0] == ch; }
296 // remove "..." and \... quotes from rStr, return how many chars removed
297 static sal_Int32 RemoveQuotes( OUString& rStr );
300 #endif // INCLUDED_SVL_SOURCE_NUMBERS_ZFORSCAN_HXX
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */