LibreOffice Module svl (master) 1
zforscan.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#ifndef INCLUDED_SVL_SOURCE_NUMBERS_ZFORSCAN_HXX
20#define INCLUDED_SVL_SOURCE_NUMBERS_ZFORSCAN_HXX
21
22#include <i18nlangtag/lang.h>
23#include <rtl/ustring.hxx>
24#include <svl/nfkeytab.hxx>
25#include <svl/nfsymbol.hxx>
26#include <svl/numformat.hxx>
27#include <svl/zforlist.hxx>
28#include <tools/color.hxx>
29#include <tools/date.hxx>
31
34
35
36const size_t NF_MAX_DEFAULT_COLORS = 10;
37
38// Hack: nThousand==1000 => "Default" occurs in format string
39const sal_uInt16 FLAG_STANDARD_IN_FORMAT = 1000;
40
42{
43public:
44
47 {
48 LocaleLegacy,
49 EnglishOnly,
50 AllowEnglish
51 };
52
55 void ChangeIntl( KeywordLocalization eKeywordLocalization = KeywordLocalization::AllowEnglish ); // Replaces Keywords
56
57 void ChangeNullDate(sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear); // Replaces reference date
58 void ChangeStandardPrec(sal_uInt16 nPrec); // Replaces standard precision
59
60 sal_Int32 ScanFormat( OUString& rString ); // Call scan analysis
61
63 sal_uInt16 nCnt); // Copies the FormatInfo
64 sal_uInt16 GetResultStringsCnt() const { return nResultStringsCnt; }
65
66 const CharClass& GetChrCls() const { return *pFormatter->GetCharClass(); }
67 const LocaleDataWrapper& GetLoc() const { return *pFormatter->GetLocaleData(); }
69
71 {
73 {
75 }
76 return sKeyword;
77 }
78
80 {
81 return sEnglishKeyword;
82 }
83
84 // Keywords used in output like true and false
85 const OUString& GetSpecialKeyword( NfKeywordIndex eIdx ) const
86 {
87 if ( sKeyword[eIdx].isEmpty() )
88 {
89 InitSpecialKeyword( eIdx );
90 }
91 return sKeyword[eIdx];
92 }
93 const OUString& GetTrueString() const { return GetSpecialKeyword( NF_KEY_TRUE ); }
94 const OUString& GetFalseString() const { return GetSpecialKeyword( NF_KEY_FALSE ); }
95 const OUString& GetRedString() const { return GetKeywords()[NF_KEY_RED]; }
96 const OUString& GetBooleanString() const { return GetKeywords()[NF_KEY_BOOLEAN]; }
97 static const ::std::vector<Color> & GetStandardColors()
98 {
99 return StandardColor;
100 }
101 static size_t GetMaxDefaultColors()
102 {
104 }
105
106 const Date& GetNullDate() const { return maNullDate; }
107 const OUString& GetStandardName() const
108 {
109 if ( bKeywordsNeedInit )
110 {
111 InitKeywords();
112 }
113 return sNameStandardFormat;
114 }
115 sal_uInt16 GetStandardPrec() const { return nStandardPrec; }
116 static const Color& GetRedColor() { return StandardColor[4]; }
117 const Color* GetColor(OUString& sStr) const; // Set main colors or defines colors
118
119 // the compatibility currency symbol for old automatic currency formats
120 const OUString& GetCurSymbol() const
121 {
122 if ( bCompatCurNeedInit )
123 {
125 }
126 return sCurSymbol;
127 }
128
129 // the compatibility currency abbreviation for CCC format code
130 const OUString& GetCurAbbrev() const
131 {
132 if ( bCompatCurNeedInit )
133 {
135 }
136 return sCurAbbrev;
137 }
138
139 // the compatibility currency symbol upper case for old automatic currency formats
140 const OUString& GetCurString() const
141 {
142 if ( bCompatCurNeedInit )
143 {
145 }
146 return sCurString;
147 }
148
150 bool ReplaceBooleanEquivalent( OUString& rString );
151
153 bool bSystemToSystem, bool bConvertDateOrder)
154 {
155 bConvertMode = true;
156 eNewLnge = eNewLge;
157 eTmpLnge = eTmpLge;
158 bConvertSystemToSystem = bSystemToSystem;
159 mbConvertDateOrder = bConvertDateOrder;
160 }
161 // Only changes the bool variable, in order to temporarily pause the convert mode
162 void SetConvertMode(bool bMode) { bConvertMode = bMode; }
163 bool GetConvertMode() const { return bConvertMode; }
164 LanguageType GetNewLnge() const { return eNewLnge; } // Read access on ConvertMode and convert country/language
165 LanguageType GetTmpLnge() const { return eTmpLnge; } // Read access on StartCountry/Language
166 void SetNewLnge( LanguageType e ) { eNewLnge = e; } // Set new convert country/language
167
172
173 SvNumberFormatter* GetNumberformatter() { return pFormatter; } // Access to formatter (for zformat.cxx)
174
177
178 static constexpr OUStringLiteral sErrStr = u"#FMT"; // String for error output
179
180private: // Private section
181 NfKeywordTable sKeyword; // Syntax keywords
182 static const NfKeywordTable sEnglishKeyword; // English Syntax keywords
183 static const ::std::vector<Color> StandardColor; // Standard color array
184 Date maNullDate; // 30Dec1899
185 OUString sNameStandardFormat; // "Standard"
186 sal_uInt16 nStandardPrec; // Default Precision for Standardformat
187 SvNumberFormatter* pFormatter; // Pointer to the FormatList
188 css::uno::Reference< css::i18n::XNumberFormatCode > xNFC;
189
190 OUString sStrArray[NF_MAX_FORMAT_SYMBOLS]; // Array of symbols
191 short nTypeArray[NF_MAX_FORMAT_SYMBOLS]; // Array of infos
192 // External Infos:
193 sal_uInt16 nResultStringsCnt; // Result symbol count
194 SvNumFormatType eScannedType; // Type according to scan
195 bool bThousand; // With thousands marker
196 sal_uInt16 nThousand; // Counts ... series
197 sal_uInt16 nCntPre; // Counts digits of integral part
198 sal_uInt16 nCntPost; // Counts digits of fractional part
199 sal_uInt16 nCntExp; // Counts exponent digits AM/PM
200 // Internal info:
201 sal_uInt16 nStringsCnt; // Symbol count
202 sal_uInt16 nExpPos; // Internal position of E
203 sal_uInt16 nBlankPos; // Internal position of the Blank
204 short nDecPos; // Internal position of the ,
205 bool bExp; // Set when reading E
206 bool bFrac; // Set when reading /
207 bool bBlank; // Set when reading ' ' (Fraction)
208 bool bDecSep; // Set on first ,
209 mutable bool bKeywordsNeedInit; // Locale dependent keywords need to be initialized
210 mutable bool bCompatCurNeedInit; // Locale dependent compatibility currency need to be initialized
211 OUString sCurSymbol; // Currency symbol for compatibility format codes
212 OUString sCurString; // Currency symbol in upper case
213 OUString sCurAbbrev; // Currency abbreviation
214 OUString sBooleanEquivalent1; // "TRUE";"TRUE";"FALSE"
215 OUString sBooleanEquivalent2; // [>0]"TRUE";[<0]"TRUE";"FALSE"
216
217 bool bConvertMode; // Set in the convert mode
218 bool mbConvertDateOrder; // Set in the convert mode whether to convert date particles order
219
220 LanguageType eNewLnge; // Language/country which the scanned string is converted to (for Excel filter)
221 LanguageType eTmpLnge; // Language/country which the scanned string is converted from (for Excel filter)
222
223 bool bConvertSystemToSystem; // Whether the conversion is from one system locale to another system locale
224 // (in this case the automatic currency symbol is converted too).
225
226 sal_Int32 nCurrPos; // Position of currency symbol
227
228 sal_uInt8 nNatNumModifier; // Thai T speciality
229
231
232 // Copy assignment is forbidden and not implemented.
235
236 void InitKeywords() const;
237 void InitSpecialKeyword( NfKeywordIndex eIdx ) const;
238 void InitCompatCur() const;
239
241 // Sets the language dependent keywords
242 void SkipStrings(sal_uInt16& i, sal_Int32& nPos) const;// Skips StringSymbols
243 sal_uInt16 PreviousKeyword(sal_uInt16 i) const; // Returns index of the preceding one
244 // Keyword or 0
245 sal_uInt16 NextKeyword(sal_uInt16 i) const; // Returns index of the next one
246 // Keyword or 0
247 sal_Unicode PreviousChar(sal_uInt16 i) const; // Returns last char before index skips EMPTY, STRING, STAR, BLANK
248 sal_Unicode NextChar(sal_uInt16 i) const; // Returns first following char
249 short PreviousType( sal_uInt16 i ) const; // Returns type before position skips EMPTY
250 bool IsLastBlankBeforeFrac(sal_uInt16 i) const; // True <=> there won't be a ' ' until the '/'
251 void Reset(); // Reset all variables before starting the analysis
252
258 short GetKeyWord( const OUString& sSymbol,
259 sal_Int32 nPos,
260 bool& rbFoundEnglish ) const;
261
262 bool IsAmbiguousE( short nKey ) const // whether nKey is ambiguous E of NF_KEY_E/NF_KEY_EC
263 {
264 return (nKey == NF_KEY_EC || nKey == NF_KEY_E) &&
266 }
267
268 // if 0 at strArray[i] is of S,00 or SS,00 or SS"any"00 in ScanType() or FinalScan()
269 bool Is100SecZero( sal_uInt16 i, bool bHadDecSep ) const;
270
271 short Next_Symbol(const OUString& rStr,
272 sal_Int32& nPos,
273 OUString& sSymbol) const; // Next Symbol
274 sal_Int32 Symbol_Division(const OUString& rString);// Initial lexical scan
275 sal_Int32 ScanType(); // Analysis of the Format type
276 sal_Int32 FinalScan( OUString& rString ); // Final analysis with supplied type
277
278 // -1:= error, return nPos in FinalScan; 0:= no calendar, 1:= calendar found
279 int FinalScanGetCalendar( sal_Int32& nPos, sal_uInt16& i, sal_uInt16& nResultStringsCnt );
280
284 bool InsertSymbol( sal_uInt16 & nPos, svt::NfSymbolType eType, const OUString& rStr );
285
290 bool IsDateFragment( size_t nPos1, size_t nPos2 ) const;
291
293 void SwapArrayElements( size_t nPos1, size_t nPos2 );
294
295 static bool StringEqualsChar( std::u16string_view rStr, sal_Unicode ch )
296 { return rStr.size() == 1 && rStr[0] == ch; }
297
298 // remove "..." and \... quotes from rStr, return how many chars removed
299 static sal_Int32 RemoveQuotes( OUString& rStr );
300};
301
302#endif // INCLUDED_SVL_SOURCE_NUMBERS_ZFORSCAN_HXX
303
304/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 nStringsCnt
Definition: zforscan.hxx:201
css::uno::Reference< css::i18n::XNumberFormatCode > xNFC
Definition: zforscan.hxx:188
sal_Int32 Symbol_Division(const OUString &rString)
Definition: zforscan.cxx:1016
short Next_Symbol(const OUString &rStr, sal_Int32 &nPos, OUString &sSymbol) const
Definition: zforscan.cxx:758
void InitSpecialKeyword(NfKeywordIndex eIdx) const
Definition: zforscan.cxx:164
const OUString & GetCurSymbol() const
Definition: zforscan.hxx:120
sal_uInt16 nResultStringsCnt
Definition: zforscan.hxx:193
OUString sNameStandardFormat
Definition: zforscan.hxx:185
OUString sStrArray[NF_MAX_FORMAT_SYMBOLS]
Definition: zforscan.hxx:190
sal_uInt16 NextKeyword(sal_uInt16 i) const
Definition: zforscan.cxx:1110
short GetKeyWord(const OUString &sSymbol, sal_Int32 nPos, bool &rbFoundEnglish) const
Determine keyword at nPos.
Definition: zforscan.cxx:656
static const ::std::vector< Color > StandardColor
Definition: zforscan.hxx:183
void SetConvertMode(LanguageType eTmpLge, LanguageType eNewLge, bool bSystemToSystem, bool bConvertDateOrder)
Definition: zforscan.hxx:152
static bool StringEqualsChar(std::u16string_view rStr, sal_Unicode ch)
Definition: zforscan.hxx:295
void SkipStrings(sal_uInt16 &i, sal_Int32 &nPos) const
Definition: zforscan.cxx:1081
const OUString & GetSpecialKeyword(NfKeywordIndex eIdx) const
Definition: zforscan.hxx:85
const OUString & GetTrueString() const
Definition: zforscan.hxx:93
sal_Unicode NextChar(sal_uInt16 i) const
Definition: zforscan.cxx:1164
sal_uInt16 nBlankPos
Definition: zforscan.hxx:203
static const Color & GetRedColor()
Definition: zforscan.hxx:116
sal_uInt16 GetStandardPrec() const
Definition: zforscan.hxx:115
void ChangeIntl(KeywordLocalization eKeywordLocalization=KeywordLocalization::AllowEnglish)
Definition: zforscan.cxx:154
sal_uInt8 nNatNumModifier
Definition: zforscan.hxx:228
sal_uInt16 nThousand
Definition: zforscan.hxx:196
const Date & GetNullDate() const
Definition: zforscan.hxx:106
void CopyInfo(ImpSvNumberformatInfo *pInfo, sal_uInt16 nCnt)
Definition: zforscan.cxx:3295
bool ReplaceBooleanEquivalent(OUString &rString)
Replace Boolean equivalent format codes with proper Boolean format.
Definition: zforscan.cxx:3318
short PreviousType(sal_uInt16 i) const
Definition: zforscan.cxx:1128
void ChangeStandardPrec(sal_uInt16 nPrec)
Definition: zforscan.cxx:536
sal_uInt16 nStandardPrec
Definition: zforscan.hxx:186
const OUString & GetRedString() const
Definition: zforscan.hxx:95
CalendarWrapper & GetCal() const
Definition: zforscan.hxx:68
int FinalScanGetCalendar(sal_Int32 &nPos, sal_uInt16 &i, sal_uInt16 &nResultStringsCnt)
Definition: zforscan.cxx:1673
void SwapArrayElements(size_t nPos1, size_t nPos2)
Swap nTypeArray and sStrArray elements at positions.
Definition: zforscan.cxx:1725
static const NfKeywordTable & GetEnglishKeywords()
Definition: zforscan.hxx:79
const OUString & GetBooleanString() const
Definition: zforscan.hxx:96
const CharClass & GetChrCls() const
Definition: zforscan.hxx:66
sal_Int32 FinalScan(OUString &rString)
Definition: zforscan.cxx:1731
const OUString & GetFalseString() const
Definition: zforscan.hxx:94
void InitCompatCur() const
Definition: zforscan.cxx:191
bool IsAmbiguousE(short nKey) const
Definition: zforscan.hxx:262
ImpSvNumberformatScan & operator=(const ImpSvNumberformatScan &)=delete
bool IsLastBlankBeforeFrac(sal_uInt16 i) const
Definition: zforscan.cxx:1186
const LocaleDataWrapper & GetLoc() const
Definition: zforscan.hxx:67
LanguageType eTmpLnge
Definition: zforscan.hxx:221
bool Is100SecZero(sal_uInt16 i, bool bHadDecSep) const
Definition: zforscan.cxx:1240
static const ::std::vector< Color > & GetStandardColors()
Definition: zforscan.hxx:97
sal_Int32 ScanFormat(OUString &rString)
Definition: zforscan.cxx:3281
const NfKeywordTable & GetKeywords() const
Definition: zforscan.hxx:70
SvNumFormatType eScannedType
Definition: zforscan.hxx:194
const OUString & GetCurAbbrev() const
Definition: zforscan.hxx:130
const OUString & GetCurString() const
Definition: zforscan.hxx:140
sal_uInt16 PreviousKeyword(sal_uInt16 i) const
Definition: zforscan.cxx:1092
short nTypeArray[NF_MAX_FORMAT_SYMBOLS]
Definition: zforscan.hxx:191
sal_Unicode PreviousChar(sal_uInt16 i) const
Definition: zforscan.cxx:1142
LanguageType GetTmpLnge() const
Definition: zforscan.hxx:165
ImpSvNumberformatScan(SvNumberFormatter *pFormatter)
Definition: zforscan.cxx:124
KeywordLocalization meKeywordLocalization
which keywords localization to scan
Definition: zforscan.hxx:230
void SetNewLnge(LanguageType e)
Definition: zforscan.hxx:166
SvNumberFormatter * GetNumberformatter()
Definition: zforscan.hxx:173
bool InsertSymbol(sal_uInt16 &nPos, svt::NfSymbolType eType, const OUString &rStr)
Insert symbol into nTypeArray and sStrArray, e.g.
Definition: zforscan.cxx:1644
static const NfKeywordTable sEnglishKeyword
Definition: zforscan.hxx:182
void InitKeywords() const
Definition: zforscan.cxx:201
KeywordLocalization
Specify what keyword localization is allowed when scanning the format code.
Definition: zforscan.hxx:47
@ AllowEnglish
allow English keywords as well as localized keywords
static sal_Int32 RemoveQuotes(OUString &rStr)
Definition: zforscan.cxx:3261
LanguageType GetNewLnge() const
Definition: zforscan.hxx:164
const OUString & GetStandardName() const
Definition: zforscan.hxx:107
SvNumberFormatter * pFormatter
Definition: zforscan.hxx:187
void ChangeNullDate(sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 nYear)
Definition: zforscan.cxx:520
bool GetConvertMode() const
Definition: zforscan.hxx:163
OUString sBooleanEquivalent1
Definition: zforscan.hxx:214
sal_uInt8 GetNatNumModifier() const
get Thai T speciality
Definition: zforscan.hxx:169
sal_Int32 ScanType()
Definition: zforscan.cxx:1249
NfKeywordTable sKeyword
Definition: zforscan.hxx:181
void SetNatNumModifier(sal_uInt8 n)
set Thai T speciality
Definition: zforscan.hxx:171
void SetConvertMode(bool bMode)
Definition: zforscan.hxx:162
OUString sBooleanEquivalent2
Definition: zforscan.hxx:215
static size_t GetMaxDefaultColors()
Definition: zforscan.hxx:101
sal_uInt16 GetResultStringsCnt() const
Definition: zforscan.hxx:64
SvNumFormatType GetScannedType() const
Get type scanned (so far).
Definition: zforscan.hxx:176
bool IsDateFragment(size_t nPos1, size_t nPos2) const
Whether two key symbols are adjacent separated by date separator.
Definition: zforscan.cxx:1720
LanguageType eNewLnge
Definition: zforscan.hxx:220
static constexpr OUStringLiteral sErrStr
Definition: zforscan.hxx:178
const Color * GetColor(OUString &sStr) const
Definition: zforscan.cxx:541
ImpSvNumberformatScan(const ImpSvNumberformatScan &)=delete
CalendarWrapper * GetCalendar() const
Definition: zforlist.cxx:545
const CharClass * GetCharClass() const
Definition: zforlist.cxx:541
const LocaleDataWrapper * GetLocaleData() const
Definition: zforlist.cxx:543
float u
sal_Int64 n
NfSymbolType
Number formatter's symbol types of a token, if not key words, which are >0.
Definition: nfsymbol.hxx:35
::std::array< OUString, NF_KEYWORD_ENTRIES_COUNT > NfKeywordTable
Definition: nfkeytab.hxx:98
NfKeywordIndex
For ImpSvNumberformatScan: first the short symbols, then the long symbols! e.g.
Definition: nfkeytab.hxx:35
@ NF_KEY_EC
Definition: nfkeytab.hxx:64
@ NF_KEY_BOOLEAN
Definition: nfkeytab.hxx:74
@ NF_KEY_TRUE
Definition: nfkeytab.hxx:79
@ NF_KEY_E
Definition: nfkeytab.hxx:37
@ NF_KEY_RED
Definition: nfkeytab.hxx:87
@ NF_KEY_FALSE
Definition: nfkeytab.hxx:80
unsigned char sal_uInt8
sal_uInt16 sal_Unicode
constexpr size_t NF_MAX_FORMAT_SYMBOLS
Definition: zforlist.hxx:41
SvNumFormatType
MAX_ULONG.
Definition: zforlist.hxx:50
const sal_uInt16 FLAG_STANDARD_IN_FORMAT
Definition: zforscan.hxx:39
const size_t NF_MAX_DEFAULT_COLORS
Definition: zforscan.hxx:36