Branch data 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 _ZFORSCAN_HXX
20 : : #define _ZFORSCAN_HXX
21 : :
22 : : #include <tools/string.hxx>
23 : : #include <tools/date.hxx>
24 : : #include <i18npool/lang.h>
25 : : #include <tools/color.hxx>
26 : : #include <svl/nfkeytab.hxx>
27 : : #include <svl/nfsymbol.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(); // tauscht Keywords aus
46 : :
47 : : void ChangeNullDate(sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear);
48 : : // tauscht Referenzdatum aus
49 : : void ChangeStandardPrec(sal_uInt16 nPrec); // tauscht Standardprecision aus
50 : :
51 : : xub_StrLen ScanFormat( String& rString ); // Aufruf der Scan-Analyse
52 : :
53 : : void CopyInfo(ImpSvNumberformatInfo* pInfo,
54 : : sal_uInt16 nAnz); // Kopiert die FormatInfo
55 : 199160 : sal_uInt16 GetAnzResStrings() const { return nAnzResStrings; }
56 : :
57 : 45306 : const CharClass& GetChrCls() const { return *pFormatter->GetCharClass(); }
58 : 0 : const LocaleDataWrapper& GetLoc() const { return *pFormatter->GetLocaleData(); }
59 : 690 : CalendarWrapper& GetCal() const { return *pFormatter->GetCalendar(); }
60 : :
61 : 765974 : const NfKeywordTable & GetKeywords() const
62 : : {
63 [ + + ]: 765974 : if ( bKeywordsNeedInit )
64 : 5032 : InitKeywords();
65 : 765974 : return sKeyword;
66 : : }
67 : : // Keywords used in output like true and false
68 : 5696 : const String& GetSpecialKeyword( NfKeywordIndex eIdx ) const
69 : : {
70 [ + + ]: 5696 : if ( !sKeyword[eIdx].Len() )
71 : 250 : InitSpecialKeyword( eIdx );
72 : 5696 : return sKeyword[eIdx];
73 : : }
74 : 2836 : const String& GetTrueString() const { return GetSpecialKeyword( NF_KEY_TRUE ); }
75 : 2860 : const String& GetFalseString() const { return GetSpecialKeyword( NF_KEY_FALSE ); }
76 : 0 : const String& GetColorString() const { return GetKeywords()[NF_KEY_COLOR]; }
77 : 97 : const String& GetRedString() const { return GetKeywords()[NF_KEY_RED]; }
78 : 2440 : const String& GetBooleanString() const { return GetKeywords()[NF_KEY_BOOLEAN]; }
79 : 0 : const String& GetErrorString() const { return sErrStr; }
80 : :
81 : 1866 : Date* GetNullDate() const { return pNullDate; }
82 : 99 : const String& GetStandardName() const
83 : : {
84 [ - + ]: 99 : if ( bKeywordsNeedInit )
85 : 0 : InitKeywords();
86 : 99 : return sNameStandardFormat;
87 : : }
88 : 132098 : sal_uInt16 GetStandardPrec() const { return nStandardPrec; }
89 : 0 : const Color& GetRedColor() const { return StandardColor[4]; }
90 : : Color* GetColor(String& sStr); // Setzt Hauptfarben oder
91 : : // definierte Farben
92 : :
93 : : // the compatibility currency symbol for old automatic currency formats
94 : 199160 : const String& GetCurSymbol() const
95 : : {
96 [ - + ]: 199160 : if ( bCompatCurNeedInit )
97 : 0 : InitCompatCur();
98 : 199160 : return sCurSymbol;
99 : : }
100 : :
101 : : // the compatibility currency abbreviation for CCC format code
102 : 0 : const String& GetCurAbbrev() const
103 : : {
104 [ # # ]: 0 : if ( bCompatCurNeedInit )
105 : 0 : InitCompatCur();
106 : 0 : return sCurAbbrev;
107 : : }
108 : :
109 : : // the compatibility currency symbol upper case for old automatic currency formats
110 : 398608 : const String& GetCurString() const
111 : : {
112 [ - + ]: 398608 : if ( bCompatCurNeedInit )
113 : 0 : InitCompatCur();
114 : 398608 : return sCurString;
115 : : }
116 : :
117 : 5296 : void SetConvertMode(LanguageType eTmpLge, LanguageType eNewLge,
118 : : bool bSystemToSystem = false )
119 : : {
120 : 5296 : bConvertMode = true;
121 : 5296 : eNewLnge = eNewLge;
122 : 5296 : eTmpLnge = eTmpLge;
123 : 5296 : bConvertSystemToSystem = bSystemToSystem;
124 : 5296 : }
125 : 5406 : void SetConvertMode(bool bMode) { bConvertMode = bMode; }
126 : : // Veraendert nur die Bool-Variable
127 : : // (zum temporaeren Unterbrechen des
128 : : // Convert-Modus)
129 : 369630 : bool GetConvertMode() const { return bConvertMode; }
130 : 3481 : LanguageType GetNewLnge() const { return eNewLnge; }
131 : : // Lesezugriff auf ConvertMode
132 : : // und Konvertierungsland/Spr.
133 : 4894 : LanguageType GetTmpLnge() const { return eTmpLnge; }
134 : : // Lesezugriff auf
135 : : // und Ausgangsland/Spr.
136 : :
137 : : /// get Thai T speciality
138 : 199160 : sal_uInt8 GetNatNumModifier() const { return nNatNumModifier; }
139 : : /// set Thai T speciality
140 : 0 : void SetNatNumModifier( sal_uInt8 n ) { nNatNumModifier = n; }
141 : :
142 : 238855 : SvNumberFormatter* GetNumberformatter() { return pFormatter; }
143 : : // Zugriff auf Formatierer
144 : : // (fuer zformat.cxx)
145 : :
146 : :
147 : : private: // ---- privater Teil
148 : : NfKeywordTable sKeyword; // Schluesselworte der Syntax
149 : : Color StandardColor[NF_MAX_DEFAULT_COLORS];
150 : : // Array der Standardfarben
151 : : Date* pNullDate; // 30Dec1899
152 : : String sNameStandardFormat; // "Standard"
153 : : sal_uInt16 nStandardPrec; // default Precision for Standardformat
154 : : SvNumberFormatter* pFormatter; // Pointer auf die Formatliste
155 : :
156 : : String sStrArray[NF_MAX_FORMAT_SYMBOLS]; // Array der Symbole
157 : : short nTypeArray[NF_MAX_FORMAT_SYMBOLS]; // Array der Infos
158 : : // externe Infos:
159 : : sal_uInt16 nAnzResStrings; // Anzahl der Ergebnissymbole
160 : : #if !(defined SOLARIS && defined X86)
161 : : short eScannedType; // Typ gemaess Scan
162 : : #else
163 : : int eScannedType; // wg. Optimierung
164 : : #endif
165 : : bool bThousand; // Mit Tausenderpunkt
166 : : sal_uInt16 nThousand; // Zaehlt ....-Folgen
167 : : sal_uInt16 nCntPre; // Zaehlt Vorkommastellen
168 : : sal_uInt16 nCntPost; // Zaehlt Nachkommastellen
169 : : sal_uInt16 nCntExp; // Zaehlt Exp.Stellen, AM/PM
170 : : // interne Infos:
171 : : sal_uInt16 nAnzStrings; // Anzahl der Symbole
172 : : sal_uInt16 nRepPos; // Position eines '*'
173 : : sal_uInt16 nExpPos; // interne Position des E
174 : : sal_uInt16 nBlankPos; // interne Position des Blank
175 : : short nDecPos; // interne Pos. des ,
176 : : bool bExp; // wird bei Lesen des E gesetzt
177 : : bool bFrac; // wird bei Lesen des / gesetzt
178 : : bool bBlank; // wird bei ' '(Fraction) ges.
179 : : bool bDecSep; // Wird beim ersten , gesetzt
180 : : mutable bool bKeywordsNeedInit; // Locale dependent keywords need to be initialized
181 : : mutable bool bCompatCurNeedInit; // Locale dependent compatibility currency need to be initialized
182 : : String sCurSymbol; // Currency symbol for compatibility format codes
183 : : String sCurString; // Currency symbol in upper case
184 : : String sCurAbbrev; // Currency abbreviation
185 : : String sErrStr; // String fuer Fehlerausgaben
186 : :
187 : : bool bConvertMode; // Wird im Convert-Mode gesetzt
188 : : // Land/Sprache, in die der
189 : : LanguageType eNewLnge; // gescannte String konvertiert
190 : : // wird (fuer Excel Filter)
191 : : // Land/Sprache, aus der der
192 : : LanguageType eTmpLnge; // gescannte String konvertiert
193 : : // wird (fuer Excel Filter)
194 : : bool bConvertSystemToSystem; // Whether the conversion is
195 : : // from one system locale to
196 : : // another system locale (in
197 : : // this case the automatic
198 : : // currency symbol is converted
199 : : // too).
200 : :
201 : : xub_StrLen nCurrPos; // Position des Waehrungssymbols
202 : :
203 : : sal_uInt8 nNatNumModifier; // Thai T speciality
204 : :
205 : : void InitKeywords() const;
206 : : void InitSpecialKeyword( NfKeywordIndex eIdx ) const;
207 : : void InitCompatCur() const;
208 : :
209 : : #ifdef _ZFORSCAN_CXX // ----- private Methoden -----
210 : : void SetDependentKeywords();
211 : : // Setzt die Sprachabh. Keyw.
212 : : void SkipStrings(sal_uInt16& i,xub_StrLen& nPos);// Ueberspringt StringSymbole
213 : : sal_uInt16 PreviousKeyword(sal_uInt16 i); // Gibt Index des vorangeh.
214 : : // Schluesselworts oder 0
215 : : sal_uInt16 NextKeyword(sal_uInt16 i); // Gibt Index des naechsten
216 : : // Schluesselworts oder 0
217 : : sal_Unicode PreviousChar(sal_uInt16 i); // Gibt letzten Buchstaben
218 : : // vor der Position,
219 : : // skipt EMPTY, STRING, STAR, BLANK
220 : : sal_Unicode NextChar(sal_uInt16 i); // Gibt ersten Buchst. danach
221 : : short PreviousType( sal_uInt16 i ); // Gibt Typ vor Position,
222 : : // skipt EMPTY
223 : : bool IsLastBlankBeforeFrac(sal_uInt16 i); // True <=> es kommt kein ' '
224 : : // mehr bis zum '/'
225 : : void Reset(); // Reset aller Variablen
226 : : // vor Analysestart
227 : : short GetKeyWord( const String& sSymbol, // determine keyword at nPos
228 : : xub_StrLen nPos ); // return 0 <=> not found
229 : :
230 : 354092 : inline bool IsAmbiguousE( short nKey ) // whether nKey is ambiguous E of NF_KEY_E/NF_KEY_EC
231 : : {
232 : : return (nKey == NF_KEY_EC || nKey == NF_KEY_E) &&
233 [ + + ][ - + ]: 354092 : (GetKeywords()[NF_KEY_EC] == GetKeywords()[NF_KEY_E]);
[ + - ]
234 : : }
235 : :
236 : : // if 0 at strArray[i] is of S,00 or SS,00 or SS"any"00 in ScanType() or FinalScan()
237 : : bool Is100SecZero( sal_uInt16 i, bool bHadDecSep );
238 : :
239 : : short Next_Symbol(const String& rStr,
240 : : xub_StrLen& nPos,
241 : : String& sSymbol); // Naechstes Symbol
242 : : xub_StrLen Symbol_Division(const String& rString);// lexikalische Voranalyse
243 : : xub_StrLen ScanType(); // Analyse des Formattyps
244 : : xub_StrLen FinalScan( String& rString ); // Endanalyse mit Vorgabe des Typs
245 : :
246 : : // -1:= error, return nPos in FinalScan; 0:= no calendar, 1:= calendar found
247 : : int FinalScanGetCalendar( xub_StrLen& nPos, sal_uInt16& i, sal_uInt16& nAnzResStrings );
248 : :
249 : : /** Insert symbol into nTypeArray and sStrArray, e.g. grouping separator.
250 : : If at nPos-1 a symbol type NF_SYMBOLTYPE_EMPTY is present, that is
251 : : reused instead of shifting all one up and nPos is decremented! */
252 : : bool InsertSymbol( sal_uInt16 & nPos, svt::NfSymbolType eType, const String& rStr );
253 : :
254 : 3444097 : static inline bool StringEqualsChar( const String& rStr, sal_Unicode ch )
255 [ + + ][ + - ]: 3444097 : { return rStr.GetChar(0) == ch && rStr.Len() == 1; }
256 : : // Yes, for efficiency get the character first and then compare length
257 : : // because in most places where this is used the string is one char.
258 : :
259 : : // remove "..." and \... quotes from rStr, return how many chars removed
260 : : static xub_StrLen RemoveQuotes( String& rStr );
261 : :
262 : : #endif //_ZFORSCAN_CXX
263 : : };
264 : :
265 : :
266 : :
267 : : #endif // _ZFORSCAN_HXX
268 : :
269 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|