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