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