Line data Source code
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 <tools/color.hxx>
27 : #include <tools/date.hxx>
28 :
29 : class SvNumberFormatter;
30 : struct ImpSvNumberformatInfo;
31 :
32 :
33 : const size_t NF_MAX_FORMAT_SYMBOLS = 100;
34 : const size_t NF_MAX_DEFAULT_COLORS = 10;
35 :
36 : // Hack: nThousand==1000 => "Default" occurs in format string
37 : const sal_uInt16 FLAG_STANDARD_IN_FORMAT = 1000;
38 :
39 : class ImpSvNumberformatScan
40 : {
41 : public:
42 :
43 : ImpSvNumberformatScan( SvNumberFormatter* pFormatter );
44 : ~ImpSvNumberformatScan();
45 : void ChangeIntl(); // Replaces Keywords
46 :
47 : void ChangeNullDate(sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear); // Replaces reference date
48 : void ChangeStandardPrec(sal_uInt16 nPrec); // Replaces standard precision
49 :
50 : sal_Int32 ScanFormat( OUString& rString ); // Call scan analysis
51 :
52 : void CopyInfo(ImpSvNumberformatInfo* pInfo,
53 : sal_uInt16 nAnz); // Copies the FormatInfo
54 688667 : sal_uInt16 GetAnzResStrings() const { return nAnzResStrings; }
55 :
56 80798 : const CharClass& GetChrCls() const { return *pFormatter->GetCharClass(); }
57 28 : const LocaleDataWrapper& GetLoc() const { return *pFormatter->GetLocaleData(); }
58 7572 : CalendarWrapper& GetCal() const { return *pFormatter->GetCalendar(); }
59 :
60 2718039 : const NfKeywordTable & GetKeywords() const
61 : {
62 2718039 : if ( bKeywordsNeedInit )
63 : {
64 20192 : InitKeywords();
65 : }
66 2718039 : return sKeyword;
67 : }
68 : // Keywords used in output like true and false
69 16374 : const OUString& GetSpecialKeyword( NfKeywordIndex eIdx ) const
70 : {
71 16374 : if ( sKeyword[eIdx].isEmpty() )
72 : {
73 7042 : InitSpecialKeyword( eIdx );
74 : }
75 16374 : return sKeyword[eIdx];
76 : }
77 8124 : const OUString& GetTrueString() const { return GetSpecialKeyword( NF_KEY_TRUE ); }
78 8250 : const OUString& GetFalseString() const { return GetSpecialKeyword( NF_KEY_FALSE ); }
79 0 : const OUString& GetColorString() const { return GetKeywords()[NF_KEY_COLOR]; }
80 282 : const OUString& GetRedString() const { return GetKeywords()[NF_KEY_RED]; }
81 7824 : const OUString& GetBooleanString() const { return GetKeywords()[NF_KEY_BOOLEAN]; }
82 0 : const OUString& GetErrorString() const { return sErrStr; }
83 :
84 8216 : Date* GetNullDate() const { return pNullDate; }
85 552 : const OUString& GetStandardName() const
86 : {
87 552 : if ( bKeywordsNeedInit )
88 : {
89 8 : InitKeywords();
90 : }
91 552 : return sNameStandardFormat;
92 : }
93 181215 : sal_uInt16 GetStandardPrec() const { return nStandardPrec; }
94 0 : const Color& GetRedColor() const { return StandardColor[4]; }
95 : Color* GetColor(OUString& sStr); // Set main colors or defines colors
96 :
97 : // the compatibility currency symbol for old automatic currency formats
98 688667 : const OUString& GetCurSymbol() const
99 : {
100 688667 : if ( bCompatCurNeedInit )
101 : {
102 0 : InitCompatCur();
103 : }
104 688667 : return sCurSymbol;
105 : }
106 :
107 : // the compatibility currency abbreviation for CCC format code
108 0 : const OUString& GetCurAbbrev() const
109 : {
110 0 : if ( bCompatCurNeedInit )
111 : {
112 0 : InitCompatCur();
113 : }
114 0 : return sCurAbbrev;
115 : }
116 :
117 : // the compatibility currency symbol upper case for old automatic currency formats
118 1378462 : const OUString& GetCurString() const
119 : {
120 1378462 : if ( bCompatCurNeedInit )
121 : {
122 0 : InitCompatCur();
123 : }
124 1378462 : return sCurString;
125 : }
126 :
127 14132 : void SetConvertMode(LanguageType eTmpLge, LanguageType eNewLge,
128 : bool bSystemToSystem = false )
129 : {
130 14132 : bConvertMode = true;
131 14132 : eNewLnge = eNewLge;
132 14132 : eTmpLnge = eTmpLge;
133 14132 : bConvertSystemToSystem = bSystemToSystem;
134 14132 : }
135 : // Only changes the bool variable, in order to temporarily pause the convert mode
136 14484 : void SetConvertMode(bool bMode) { bConvertMode = bMode; }
137 1268022 : bool GetConvertMode() const { return bConvertMode; }
138 13978 : LanguageType GetNewLnge() const { return eNewLnge; } // Read access on ConvertMode and convert country/language
139 20450 : LanguageType GetTmpLnge() const { return eTmpLnge; } // Read access on StartCountry/Language
140 :
141 : /// get Thai T speciality
142 688663 : sal_uInt8 GetNatNumModifier() const { return nNatNumModifier; }
143 : /// set Thai T speciality
144 0 : void SetNatNumModifier( sal_uInt8 n ) { nNatNumModifier = n; }
145 :
146 691364 : SvNumberFormatter* GetNumberformatter() { return pFormatter; } // Access to formatter (for zformat.cxx)
147 :
148 : private: // Private section
149 : NfKeywordTable sKeyword; // Syntax keywords
150 : Color StandardColor[NF_MAX_DEFAULT_COLORS]; // Standard color array
151 : Date* pNullDate; // 30Dec1899
152 : OUString sNameStandardFormat; // "Standard"
153 : sal_uInt16 nStandardPrec; // Default Precision for Standardformat
154 : SvNumberFormatter* pFormatter; // Pointer to the FormatList
155 :
156 : OUString sStrArray[NF_MAX_FORMAT_SYMBOLS]; // Array of symbols
157 : short nTypeArray[NF_MAX_FORMAT_SYMBOLS]; // Array of infos
158 : // External Infos:
159 : sal_uInt16 nAnzResStrings; // Result symbol count
160 : short eScannedType; // Type according to scan
161 : bool bThousand; // With thousands marker
162 : sal_uInt16 nThousand; // Counts .... series
163 : sal_uInt16 nCntPre; // Counts digits of integral part
164 : sal_uInt16 nCntPost; // Counts digits of fractional part
165 : sal_uInt16 nCntExp; // Counts exponent digits AM/PM
166 : // Internal info:
167 : sal_uInt16 nAnzStrings; // Symbol count
168 : sal_uInt16 nRepPos; // Position of a '*'
169 : sal_uInt16 nExpPos; // Internal position of E
170 : sal_uInt16 nBlankPos; // Internal position of the Blank
171 : short nDecPos; // Internal position of the ,
172 : bool bExp; // Set when reading E
173 : bool bFrac; // Set when reading /
174 : bool bBlank; // Set when reading ' ' (Fraction)
175 : bool bDecSep; // Set on first ,
176 : mutable bool bKeywordsNeedInit; // Locale dependent keywords need to be initialized
177 : mutable bool bCompatCurNeedInit; // Locale dependent compatibility currency need to be initialized
178 : OUString sCurSymbol; // Currency symbol for compatibility format codes
179 : OUString sCurString; // Currency symbol in upper case
180 : OUString sCurAbbrev; // Currency abbreviation
181 : OUString sErrStr; // String for error output
182 :
183 : bool bConvertMode; // Set in the convert mode
184 :
185 : LanguageType eNewLnge; // Language/country which the scanned string is converted to (for Excel filter)
186 : LanguageType eTmpLnge; // Language/country which the scanned string is converted from (for Excel filter)
187 :
188 : bool bConvertSystemToSystem; // Whether the conversion is from one system locale to another system locale
189 : // (in this case the automatic currency symbol is converted too).
190 :
191 : sal_Int32 nCurrPos; // Position of currency symbol
192 :
193 : sal_uInt8 nNatNumModifier; // Thai T speciality
194 :
195 : void InitKeywords() const;
196 : void InitSpecialKeyword( NfKeywordIndex eIdx ) const;
197 : void InitCompatCur() const;
198 :
199 : void SetDependentKeywords();
200 : // Sets the language dependent keywords
201 : void SkipStrings(sal_uInt16& i, sal_Int32& nPos);// Skips StringSymbols
202 : sal_uInt16 PreviousKeyword(sal_uInt16 i); // Returns index of the preceding one
203 : // Keyword or 0
204 : sal_uInt16 NextKeyword(sal_uInt16 i); // Returns index of the next one
205 : // Keyword or 0
206 : sal_Unicode PreviousChar(sal_uInt16 i); // Returns last char before index skips EMPTY, STRING, STAR, BLANK
207 : sal_Unicode NextChar(sal_uInt16 i); // Returns first following char
208 : short PreviousType( sal_uInt16 i ); // Returns type before position skips EMPTY
209 : bool IsLastBlankBeforeFrac(sal_uInt16 i); // True <=> there won't be a ' ' until the '/'
210 : void Reset(); // Reset all variables before starting the analysis
211 : short GetKeyWord( const OUString& sSymbol, // Determine keyword at nPos
212 : sal_Int32 nPos ); // Return 0 <=> not found
213 :
214 1242029 : inline bool IsAmbiguousE( short nKey ) // whether nKey is ambiguous E of NF_KEY_E/NF_KEY_EC
215 : {
216 1343896 : return (nKey == NF_KEY_EC || nKey == NF_KEY_E) &&
217 1343896 : (GetKeywords()[NF_KEY_EC] == GetKeywords()[NF_KEY_E]);
218 : }
219 :
220 : // if 0 at strArray[i] is of S,00 or SS,00 or SS"any"00 in ScanType() or FinalScan()
221 : bool Is100SecZero( sal_uInt16 i, bool bHadDecSep );
222 :
223 : short Next_Symbol(const OUString& rStr,
224 : sal_Int32& nPos,
225 : OUString& sSymbol); // Next Symbol
226 : sal_Int32 Symbol_Division(const OUString& rString);// Initial lexical scan
227 : sal_Int32 ScanType(); // Analysis of the Format type
228 : sal_Int32 FinalScan( OUString& rString ); // Final analysis with supplied type
229 :
230 : // -1:= error, return nPos in FinalScan; 0:= no calendar, 1:= calendar found
231 : int FinalScanGetCalendar( sal_Int32& nPos, sal_uInt16& i, sal_uInt16& nAnzResStrings );
232 :
233 : /** Insert symbol into nTypeArray and sStrArray, e.g. grouping separator.
234 : If at nPos-1 a symbol type NF_SYMBOLTYPE_EMPTY is present, that is
235 : reused instead of shifting all one up and nPos is decremented! */
236 : bool InsertSymbol( sal_uInt16 & nPos, svt::NfSymbolType eType, const OUString& rStr );
237 :
238 12482666 : static inline bool StringEqualsChar( const OUString& rStr, sal_Unicode ch )
239 12482666 : { return rStr.getLength() == 1 && rStr[0] == ch; }
240 :
241 : // remove "..." and \... quotes from rStr, return how many chars removed
242 : static sal_Int32 RemoveQuotes( OUString& rStr );
243 : };
244 :
245 : #endif // INCLUDED_SVL_SOURCE_NUMBERS_ZFORSCAN_HXX
246 :
247 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|