bump product version to 5.0.4.1
[LibreOffice.git] / svl / source / numbers / zforscan.hxx
blob03d5efa5db33161693f87d0916bb0acf62be99d5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SVL_SOURCE_NUMBERS_ZFORSCAN_HXX
20 #define INCLUDED_SVL_SOURCE_NUMBERS_ZFORSCAN_HXX
22 #include <i18nlangtag/lang.h>
23 #include <rtl/ustring.hxx>
24 #include <svl/nfkeytab.hxx>
25 #include <svl/nfsymbol.hxx>
26 #include <tools/color.hxx>
27 #include <tools/date.hxx>
29 class SvNumberFormatter;
30 struct ImpSvNumberformatInfo;
33 const size_t NF_MAX_FORMAT_SYMBOLS = 100;
34 const size_t NF_MAX_DEFAULT_COLORS = 10;
36 // Hack: nThousand==1000 => "Default" occurs in format string
37 const sal_uInt16 FLAG_STANDARD_IN_FORMAT = 1000;
39 class ImpSvNumberformatScan
41 public:
43 ImpSvNumberformatScan( SvNumberFormatter* pFormatter );
44 ~ImpSvNumberformatScan();
45 void ChangeIntl(); // Replaces Keywords
47 void ChangeNullDate(sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear); // Replaces reference date
48 void ChangeStandardPrec(sal_uInt16 nPrec); // Replaces standard precision
50 sal_Int32 ScanFormat( OUString& rString ); // Call scan analysis
52 void CopyInfo(ImpSvNumberformatInfo* pInfo,
53 sal_uInt16 nAnz); // Copies the FormatInfo
54 sal_uInt16 GetAnzResStrings() const { return nAnzResStrings; }
56 const CharClass& GetChrCls() const { return *pFormatter->GetCharClass(); }
57 const LocaleDataWrapper& GetLoc() const { return *pFormatter->GetLocaleData(); }
58 CalendarWrapper& GetCal() const { return *pFormatter->GetCalendar(); }
60 const NfKeywordTable & GetKeywords() const
62 if ( bKeywordsNeedInit )
64 InitKeywords();
66 return sKeyword;
68 // Keywords used in output like true and false
69 const OUString& GetSpecialKeyword( NfKeywordIndex eIdx ) const
71 if ( sKeyword[eIdx].isEmpty() )
73 InitSpecialKeyword( eIdx );
75 return sKeyword[eIdx];
77 const OUString& GetTrueString() const { return GetSpecialKeyword( NF_KEY_TRUE ); }
78 const OUString& GetFalseString() const { return GetSpecialKeyword( NF_KEY_FALSE ); }
79 const OUString& GetColorString() const { return GetKeywords()[NF_KEY_COLOR]; }
80 const OUString& GetRedString() const { return GetKeywords()[NF_KEY_RED]; }
81 const OUString& GetBooleanString() const { return GetKeywords()[NF_KEY_BOOLEAN]; }
82 const OUString& GetErrorString() const { return sErrStr; }
84 Date* GetNullDate() const { return pNullDate; }
85 const OUString& GetStandardName() const
87 if ( bKeywordsNeedInit )
89 InitKeywords();
91 return sNameStandardFormat;
93 sal_uInt16 GetStandardPrec() const { return nStandardPrec; }
94 const Color& GetRedColor() const { return StandardColor[4]; }
95 Color* GetColor(OUString& sStr); // Set main colors or defines colors
97 // the compatibility currency symbol for old automatic currency formats
98 const OUString& GetCurSymbol() const
100 if ( bCompatCurNeedInit )
102 InitCompatCur();
104 return sCurSymbol;
107 // the compatibility currency abbreviation for CCC format code
108 const OUString& GetCurAbbrev() const
110 if ( bCompatCurNeedInit )
112 InitCompatCur();
114 return sCurAbbrev;
117 // the compatibility currency symbol upper case for old automatic currency formats
118 const OUString& GetCurString() const
120 if ( bCompatCurNeedInit )
122 InitCompatCur();
124 return sCurString;
127 void SetConvertMode(LanguageType eTmpLge, LanguageType eNewLge,
128 bool bSystemToSystem = false )
130 bConvertMode = true;
131 eNewLnge = eNewLge;
132 eTmpLnge = eTmpLge;
133 bConvertSystemToSystem = bSystemToSystem;
135 // Only changes the bool variable, in order to temporarily pause the convert mode
136 void SetConvertMode(bool bMode) { bConvertMode = bMode; }
137 bool GetConvertMode() const { return bConvertMode; }
138 LanguageType GetNewLnge() const { return eNewLnge; } // Read access on ConvertMode and convert country/language
139 LanguageType GetTmpLnge() const { return eTmpLnge; } // Read access on StartCountry/Language
141 /// get Thai T speciality
142 sal_uInt8 GetNatNumModifier() const { return nNatNumModifier; }
143 /// set Thai T speciality
144 void SetNatNumModifier( sal_uInt8 n ) { nNatNumModifier = n; }
146 SvNumberFormatter* GetNumberformatter() { return pFormatter; } // Access to formatter (for zformat.cxx)
148 private: // Private section
149 NfKeywordTable sKeyword; // Syntax keywords
150 Color StandardColor[NF_MAX_DEFAULT_COLORS]; // Standard color array
151 Date* pNullDate; // 30Dec1899
152 OUString sNameStandardFormat; // "Standard"
153 sal_uInt16 nStandardPrec; // Default Precision for Standardformat
154 SvNumberFormatter* pFormatter; // Pointer to the FormatList
156 OUString sStrArray[NF_MAX_FORMAT_SYMBOLS]; // Array of symbols
157 short nTypeArray[NF_MAX_FORMAT_SYMBOLS]; // Array of infos
158 // External Infos:
159 sal_uInt16 nAnzResStrings; // Result symbol count
160 short eScannedType; // Type according to scan
161 bool bThousand; // With thousands marker
162 sal_uInt16 nThousand; // Counts .... series
163 sal_uInt16 nCntPre; // Counts digits of integral part
164 sal_uInt16 nCntPost; // Counts digits of fractional part
165 sal_uInt16 nCntExp; // Counts exponent digits AM/PM
166 // Internal info:
167 sal_uInt16 nAnzStrings; // Symbol count
168 sal_uInt16 nRepPos; // Position of a '*'
169 sal_uInt16 nExpPos; // Internal position of E
170 sal_uInt16 nBlankPos; // Internal position of the Blank
171 short nDecPos; // Internal position of the ,
172 bool bExp; // Set when reading E
173 bool bFrac; // Set when reading /
174 bool bBlank; // Set when reading ' ' (Fraction)
175 bool bDecSep; // Set on first ,
176 mutable bool bKeywordsNeedInit; // Locale dependent keywords need to be initialized
177 mutable bool bCompatCurNeedInit; // Locale dependent compatibility currency need to be initialized
178 OUString sCurSymbol; // Currency symbol for compatibility format codes
179 OUString sCurString; // Currency symbol in upper case
180 OUString sCurAbbrev; // Currency abbreviation
181 OUString sErrStr; // String for error output
183 bool bConvertMode; // Set in the convert mode
185 LanguageType eNewLnge; // Language/country which the scanned string is converted to (for Excel filter)
186 LanguageType eTmpLnge; // Language/country which the scanned string is converted from (for Excel filter)
188 bool bConvertSystemToSystem; // Whether the conversion is from one system locale to another system locale
189 // (in this case the automatic currency symbol is converted too).
191 sal_Int32 nCurrPos; // Position of currency symbol
193 sal_uInt8 nNatNumModifier; // Thai T speciality
195 void InitKeywords() const;
196 void InitSpecialKeyword( NfKeywordIndex eIdx ) const;
197 void InitCompatCur() const;
199 void SetDependentKeywords();
200 // Sets the language dependent keywords
201 void SkipStrings(sal_uInt16& i, sal_Int32& nPos);// Skips StringSymbols
202 sal_uInt16 PreviousKeyword(sal_uInt16 i); // Returns index of the preceding one
203 // Keyword or 0
204 sal_uInt16 NextKeyword(sal_uInt16 i); // Returns index of the next one
205 // Keyword or 0
206 sal_Unicode PreviousChar(sal_uInt16 i); // Returns last char before index skips EMPTY, STRING, STAR, BLANK
207 sal_Unicode NextChar(sal_uInt16 i); // Returns first following char
208 short PreviousType( sal_uInt16 i ); // Returns type before position skips EMPTY
209 bool IsLastBlankBeforeFrac(sal_uInt16 i); // True <=> there won't be a ' ' until the '/'
210 void Reset(); // Reset all variables before starting the analysis
211 short GetKeyWord( const OUString& sSymbol, // Determine keyword at nPos
212 sal_Int32 nPos ); // Return 0 <=> not found
214 inline bool IsAmbiguousE( short nKey ) // whether nKey is ambiguous E of NF_KEY_E/NF_KEY_EC
216 return (nKey == NF_KEY_EC || nKey == NF_KEY_E) &&
217 (GetKeywords()[NF_KEY_EC] == GetKeywords()[NF_KEY_E]);
220 // if 0 at strArray[i] is of S,00 or SS,00 or SS"any"00 in ScanType() or FinalScan()
221 bool Is100SecZero( sal_uInt16 i, bool bHadDecSep );
223 short Next_Symbol(const OUString& rStr,
224 sal_Int32& nPos,
225 OUString& sSymbol); // Next Symbol
226 sal_Int32 Symbol_Division(const OUString& rString);// Initial lexical scan
227 sal_Int32 ScanType(); // Analysis of the Format type
228 sal_Int32 FinalScan( OUString& rString ); // Final analysis with supplied type
230 // -1:= error, return nPos in FinalScan; 0:= no calendar, 1:= calendar found
231 int FinalScanGetCalendar( sal_Int32& nPos, sal_uInt16& i, sal_uInt16& nAnzResStrings );
233 /** Insert symbol into nTypeArray and sStrArray, e.g. grouping separator.
234 If at nPos-1 a symbol type NF_SYMBOLTYPE_EMPTY is present, that is
235 reused instead of shifting all one up and nPos is decremented! */
236 bool InsertSymbol( sal_uInt16 & nPos, svt::NfSymbolType eType, const OUString& rStr );
238 static inline bool StringEqualsChar( const OUString& rStr, sal_Unicode ch )
239 { return rStr.getLength() == 1 && rStr[0] == ch; }
241 // remove "..." and \... quotes from rStr, return how many chars removed
242 static sal_Int32 RemoveQuotes( OUString& rStr );
245 #endif // INCLUDED_SVL_SOURCE_NUMBERS_ZFORSCAN_HXX
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */