xref: /trunk/main/svl/source/numbers/zforscan.hxx (revision 39a19a47)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _ZFORSCAN_HXX
24 #define _ZFORSCAN_HXX
25 
26 #include <tools/string.hxx>
27 #include <tools/date.hxx>
28 #include <i18npool/lang.h>
29 #include <tools/color.hxx>
30 #include <svl/nfkeytab.hxx>
31 #include <svl/nfsymbol.hxx>
32 
33 class SvNumberFormatter;
34 struct ImpSvNumberformatInfo;
35 
36 
37 const size_t NF_MAX_FORMAT_SYMBOLS   = 100;
38 const size_t NF_MAX_DEFAULT_COLORS   = 10;
39 
40 // Hack: nThousand==1000 => "Default" occurs in format string
41 const sal_uInt16 FLAG_STANDARD_IN_FORMAT = 1000;
42 
43 class ImpSvNumberformatScan
44 {
45 public:
46 
47 	ImpSvNumberformatScan( SvNumberFormatter* pFormatter );
48 	~ImpSvNumberformatScan();
49 	void ChangeIntl();							// tauscht Keywords aus
50 
51 	void ChangeNullDate(sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear);
52 												// tauscht Referenzdatum aus
53     void ChangeStandardPrec(sal_uInt16 nPrec);  // tauscht Standardprecision aus
54 
55 	xub_StrLen ScanFormat( String& rString, String& rComment );	// Aufruf der Scan-Analyse
56 
57 	void CopyInfo(ImpSvNumberformatInfo* pInfo,
58 					 sal_uInt16 nAnz);				// Kopiert die FormatInfo
GetAnzResStrings() const59 	sal_uInt16 GetAnzResStrings() const				{ return nAnzResStrings; }
60 
GetChrCls() const61 	const CharClass& GetChrCls() const			{ return *pFormatter->GetCharClass(); }
GetLoc() const62 	const LocaleDataWrapper& GetLoc() const		{ return *pFormatter->GetLocaleData(); }
GetCal() const63 	CalendarWrapper& GetCal() const				{ return *pFormatter->GetCalendar(); }
64 
GetKeywords() const65     const NfKeywordTable & GetKeywords() const
66         {
67             if ( bKeywordsNeedInit )
68                 InitKeywords();
69             return sKeyword;
70         }
71     // Keywords used in output like sal_True and sal_False
GetSpecialKeyword(NfKeywordIndex eIdx) const72     const String& GetSpecialKeyword( NfKeywordIndex eIdx ) const
73         {
74             if ( !sKeyword[eIdx].Len() )
75                 InitSpecialKeyword( eIdx );
76             return sKeyword[eIdx];
77         }
GetTrueString() const78     const String& GetTrueString() const     { return GetSpecialKeyword( NF_KEY_TRUE ); }
GetFalseString() const79     const String& GetFalseString() const    { return GetSpecialKeyword( NF_KEY_FALSE ); }
GetColorString() const80     const String& GetColorString() const    { return GetKeywords()[NF_KEY_COLOR]; }
GetRedString() const81     const String& GetRedString() const      { return GetKeywords()[NF_KEY_RED]; }
GetBooleanString() const82     const String& GetBooleanString() const  { return GetKeywords()[NF_KEY_BOOLEAN]; }
GetErrorString() const83 	const String& GetErrorString() const  	{ return sErrStr; }
84 
GetNullDate() const85 	Date* GetNullDate() const					{ return pNullDate; }
GetStandardName() const86     const String& GetStandardName() const
87         {
88             if ( bKeywordsNeedInit )
89                 InitKeywords();
90             return sNameStandardFormat;
91         }
GetStandardPrec() const92     sal_uInt16 GetStandardPrec() const          { return nStandardPrec; }
GetRedColor() const93 	const Color& GetRedColor() const			{ return StandardColor[4]; }
94 	Color* GetColor(String& sStr);			// Setzt Hauptfarben oder
95 												// definierte Farben
96 
97     // the compatibility currency symbol for old automatic currency formats
GetCurSymbol() const98     const String& GetCurSymbol() const
99         {
100             if ( bCompatCurNeedInit )
101                 InitCompatCur();
102             return sCurSymbol;
103         }
104 
105     // the compatibility currency abbreviation for CCC format code
GetCurAbbrev() const106     const String& GetCurAbbrev() const
107         {
108             if ( bCompatCurNeedInit )
109                 InitCompatCur();
110             return sCurAbbrev;
111         }
112 
113     // the compatibility currency symbol upper case for old automatic currency formats
GetCurString() const114     const String& GetCurString() const
115         {
116             if ( bCompatCurNeedInit )
117                 InitCompatCur();
118             return sCurString;
119         }
120 
SetConvertMode(LanguageType eTmpLge,LanguageType eNewLge,sal_Bool bSystemToSystem=sal_False)121 	void SetConvertMode(LanguageType eTmpLge, LanguageType eNewLge,
122 			sal_Bool bSystemToSystem = sal_False )
123 	{
124 		bConvertMode = sal_True;
125 		eNewLnge = eNewLge;
126 		eTmpLnge = eTmpLge;
127 		bConvertSystemToSystem = bSystemToSystem;
128 	}
SetConvertMode(sal_Bool bMode)129 	void SetConvertMode(sal_Bool bMode) { bConvertMode = bMode; }
130 												// Veraendert nur die Bool-Variable
131 												// (zum temporaeren Unterbrechen des
132 												// Convert-Modus)
GetConvertMode() const133 	sal_Bool GetConvertMode() const     { return bConvertMode; }
GetNewLnge() const134 	LanguageType GetNewLnge() const { return eNewLnge; }
135 												// Lesezugriff auf ConvertMode
136 												// und Konvertierungsland/Spr.
GetTmpLnge() const137 	LanguageType GetTmpLnge() const { return eTmpLnge; }
138 												// Lesezugriff auf
139 												// und Ausgangsland/Spr.
140 
141                                                 /// get Thai T speciality
GetNatNumModifier() const142     sal_uInt8 GetNatNumModifier() const      { return nNatNumModifier; }
143                                                 /// set Thai T speciality
SetNatNumModifier(sal_uInt8 n)144     void SetNatNumModifier( sal_uInt8 n )    { nNatNumModifier = n; }
145 
GetNumberformatter()146 	SvNumberFormatter* GetNumberformatter() { return pFormatter; }
147 												// Zugriff auf Formatierer
148 												// (fuer zformat.cxx)
149 
150 
151 private:							// ---- privater Teil
152 	NfKeywordTable sKeyword; 					// Schluesselworte der Syntax
153 	Color StandardColor[NF_MAX_DEFAULT_COLORS];
154 												// Array der Standardfarben
155 	Date* pNullDate;							// 30Dec1899
156 	String sNameStandardFormat;				// "Standard"
157     sal_uInt16 nStandardPrec;                   // default Precision for Standardformat
158 	SvNumberFormatter* pFormatter;				// Pointer auf die Formatliste
159 
160 	String sStrArray[NF_MAX_FORMAT_SYMBOLS];    // Array der Symbole
161 	short nTypeArray[NF_MAX_FORMAT_SYMBOLS];    // Array der Infos
162 												// externe Infos:
163 	sal_uInt16 nAnzResStrings;						// Anzahl der Ergebnissymbole
164 #if !(defined SOLARIS && defined X86)
165 	short eScannedType;							// Typ gemaess Scan
166 #else
167 	int eScannedType;							// wg. Optimierung
168 #endif
169 	sal_Bool bThousand;								// Mit Tausenderpunkt
170 	sal_uInt16 nThousand;							// Zaehlt ....-Folgen
171 	sal_uInt16 nCntPre;								// Zaehlt Vorkommastellen
172 	sal_uInt16 nCntPost;							// Zaehlt Nachkommastellen
173 	sal_uInt16 nCntExp;								// Zaehlt Exp.Stellen, AM/PM
174 												// interne Infos:
175 	sal_uInt16 nAnzStrings;							// Anzahl der Symbole
176 	sal_uInt16 nRepPos;								// Position eines '*'
177 	sal_uInt16 nExpPos;								// interne Position des E
178 	sal_uInt16 nBlankPos;							// interne Position des Blank
179 	short nDecPos;								// interne Pos. des ,
180 	sal_Bool bExp;									// wird bei Lesen des E gesetzt
181 	sal_Bool bFrac;									// wird bei Lesen des / gesetzt
182 	sal_Bool bBlank;								// wird bei ' '(Fraction) ges.
183 	sal_Bool bDecSep;								// Wird beim ersten , gesetzt
184     mutable sal_Bool bKeywordsNeedInit;             // Locale dependent keywords need to be initialized
185     mutable sal_Bool bCompatCurNeedInit;            // Locale dependent compatibility currency need to be initialized
186     String sCurSymbol;                          // Currency symbol for compatibility format codes
187     String sCurString;                          // Currency symbol in upper case
188     String sCurAbbrev;                          // Currency abbreviation
189     String sErrStr;                             // String fuer Fehlerausgaben
190 
191 	sal_Bool bConvertMode;							// Wird im Convert-Mode gesetzt
192 												// Land/Sprache, in die der
193 	LanguageType eNewLnge;						// gescannte String konvertiert
194 												// wird (fuer Excel Filter)
195 												// Land/Sprache, aus der der
196 	LanguageType eTmpLnge;						// gescannte String konvertiert
197 												// wird (fuer Excel Filter)
198 	sal_Bool bConvertSystemToSystem;				// Whether the conversion is
199 												// from one system locale to
200 												// another system locale (in
201 												// this case the automatic
202 												// currency symbol is converted
203 												// too).
204 
205 	xub_StrLen nCurrPos;						// Position des Waehrungssymbols
206 
207     sal_uInt8 nNatNumModifier;                       // Thai T speciality
208 
209     void InitKeywords() const;
210     void InitSpecialKeyword( NfKeywordIndex eIdx ) const;
211     void InitCompatCur() const;
212 
213 #ifdef _ZFORSCAN_CXX				// ----- private Methoden -----
214 	void SetDependentKeywords();
215 												// Setzt die Sprachabh. Keyw.
216 	void SkipStrings(sal_uInt16& i,xub_StrLen& nPos);// Ueberspringt StringSymbole
217 	sal_uInt16 PreviousKeyword(sal_uInt16 i);			// Gibt Index des vorangeh.
218 												// Schluesselworts oder 0
219 	sal_uInt16 NextKeyword(sal_uInt16 i);				// Gibt Index des naechsten
220 												// Schluesselworts oder 0
221 	sal_Unicode PreviousChar(sal_uInt16 i);				// Gibt letzten Buchstaben
222 												// vor der Position,
223 												// skipt EMPTY, STRING, STAR, BLANK
224 	sal_Unicode NextChar(sal_uInt16 i);					// Gibt ersten Buchst. danach
225 	short PreviousType( sal_uInt16 i );				// Gibt Typ vor Position,
226 												// skipt EMPTY
227 	sal_Bool IsLastBlankBeforeFrac(sal_uInt16 i);		// True <=> es kommt kein ' '
228 												// mehr bis zum '/'
229 	void Reset();								// Reset aller Variablen
230 												// vor Analysestart
231 	short GetKeyWord( const String& sSymbol,	// determine keyword at nPos
232 		xub_StrLen nPos );                      // return 0 <=> not found
233 
IsAmbiguousE(short nKey)234 	inline sal_Bool IsAmbiguousE( short nKey )		// whether nKey is ambiguous E of NF_KEY_E/NF_KEY_EC
235 		{
236 			return (nKey == NF_KEY_EC || nKey == NF_KEY_E) &&
237                 (GetKeywords()[NF_KEY_EC] == GetKeywords()[NF_KEY_E]);
238 		}
239 
240     // if 0 at strArray[i] is of S,00 or SS,00 or SS"any"00 in ScanType() or FinalScan()
241     sal_Bool Is100SecZero( sal_uInt16 i, sal_Bool bHadDecSep );
242 
243 	short Next_Symbol(const String& rStr,
244 						xub_StrLen& nPos,
245 					  String& sSymbol);       // Naechstes Symbol
246 	xub_StrLen Symbol_Division(const String& rString);// lexikalische Voranalyse
247 	xub_StrLen ScanType(const String& rString);	// Analyse des Formattyps
248 	xub_StrLen FinalScan( String& rString, String& rComment );	// Endanalyse mit Vorgabe
249 												// des Typs
250 	// -1:= error, return nPos in FinalScan; 0:= no calendar, 1:= calendar found
251 	int FinalScanGetCalendar( xub_StrLen& nPos, sal_uInt16& i, sal_uInt16& nAnzResStrings );
252 
253     /** Insert symbol into nTypeArray and sStrArray, e.g. grouping separator.
254         If at nPos-1 a symbol type NF_SYMBOLTYPE_EMPTY is present, that is
255         reused instead of shifting all one up and nPos is decremented! */
256     bool InsertSymbol( sal_uInt16 & nPos, svt::NfSymbolType eType, const String& rStr );
257 
StringEqualsChar(const String & rStr,sal_Unicode ch)258 	static inline sal_Bool StringEqualsChar( const String& rStr, sal_Unicode ch )
259 		{ return rStr.GetChar(0) == ch && rStr.Len() == 1; }
260 		// Yes, for efficiency get the character first and then compare length
261 		// because in most places where this is used the string is one char.
262 
263 	// remove "..." and \... quotes from rStr, return how many chars removed
264 	static xub_StrLen RemoveQuotes( String& rStr );
265 
266 #endif //_ZFORSCAN_CXX
267 };
268 
269 
270 
271 #endif	// _ZFORSCAN_HXX
272