LCOV - code coverage report
Current view: top level - libreoffice/svl/source/numbers - zforscan.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 42 54 77.8 %
Date: 2012-12-17 Functions: 23 29 79.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10