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