LCOV - code coverage report
Current view: top level - solver/unxlngi6.pro/inc/basic - sbxform.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 1 0.0 %
Date: 2012-08-25 Functions: 0 1 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 18 0.0 %

           Branch data     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                 :            : 
      20                 :            : #ifndef _SBXFORM_HXX
      21                 :            : #define _SBXFORM_HXX
      22                 :            : 
      23                 :            : //====================================================================
      24                 :            : // Implementation class for Basic command: Format$( d,formatStr )
      25                 :            : //====================================================================
      26                 :            : /*
      27                 :            :   Grammar of format string (a try):
      28                 :            :   -----------------------------------------------
      29                 :            : 
      30                 :            :   format_string     := {\special_char} general_format | scientific_format {\special_char} {;format_string}
      31                 :            :   general_format    := {#[,]}{0[,]}[.{0}{#}]
      32                 :            :   scientific_format := {0}[.{0}{#}](e | E)(+ | -){#}{0}
      33                 :            : 
      34                 :            :   percent_char      := '%'
      35                 :            :   special_char      := \char | + | - | ( | ) | $ | space_char
      36                 :            :   char              := all_ascii_chars
      37                 :            :   space_char        := ' '
      38                 :            : 
      39                 :            :   {}    repeated multiple times (incl. zero times)
      40                 :            :   []    exactly one or zero times
      41                 :            :   ()    parenthesis, e.g. (e | E) means e or E times
      42                 :            : 
      43                 :            :   Additional predefined formats for the format string:
      44                 :            :     "General Number"
      45                 :            :     "Currency"
      46                 :            :     "Fixed"
      47                 :            :     "Standard"
      48                 :            :     "Percent"
      49                 :            :     "Scientific"
      50                 :            :     "Yes/No"
      51                 :            :     "True/False"
      52                 :            :     "On/Off"
      53                 :            : 
      54                 :            :  Note: invalid format string are ignored just as in VisualBasic, the output is
      55                 :            :        probably 'undefined'. ASCII letters are outputted directly.
      56                 :            : 
      57                 :            :  Constraints in VisualBasic:
      58                 :            :     - the exponent (scientific syntax) has a maximum of three digits!
      59                 :            : 
      60                 :            :  Constraints of new implementation:
      61                 :            :     - the '+' sign is not allowed as wildcard in the mantissa
      62                 :            : 
      63                 :            :  TODO:
      64                 :            :     - Date formatting
      65                 :            :         Wildcards are: 'h', 'm', 's', 'y'
      66                 :            :         predefined String-Constants/Commands:
      67                 :            :             "AMPM", "Long Date", "Long Time"
      68                 :            : */
      69                 :            : 
      70                 :            : /*
      71                 :            :   There are two possibilities to get the number of digits of a number:
      72                 :            : 
      73                 :            :         a) use sprintf()
      74                 :            :         b) use log10() and pow() digit
      75                 :            : */
      76                 :            : #define _with_sprintf   // use a)
      77                 :            : 
      78                 :            : #include <tools/string.hxx>
      79                 :            : #include "basicdllapi.h"
      80                 :            : 
      81 [ #  # ][ #  # ]:          0 : class BASIC_DLLPUBLIC SbxBasicFormater {
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      82                 :            :   public:
      83                 :            :     // Constructor takes signs for decimal point, thousand separation sign
      84                 :            :     // and necessary resource strings.
      85                 :            :     SbxBasicFormater( sal_Unicode _cDecPoint, sal_Unicode _cThousandSep,
      86                 :            :                       String _sOnStrg,
      87                 :            :                       String _sOffStrg,
      88                 :            :                       String _sYesStrg,
      89                 :            :                       String _sNoStrg,
      90                 :            :                       String _sTrueStrg,
      91                 :            :                       String _sFalseStrg,
      92                 :            :                       String _sCurrencyStrg,
      93                 :            :                       String _sCurrencyFormatStrg );
      94                 :            : 
      95                 :            :     /* Basic command: Format$( number,format-string )
      96                 :            : 
      97                 :            :        Parameter:
      98                 :            :         dNumber     : number to be formated
      99                 :            :         sFormatStrg : the Format-String, e.g. ###0.0###
     100                 :            : 
     101                 :            :        Return value:
     102                 :            :         String containing the formatted output
     103                 :            :     */
     104                 :            :     String  BasicFormat( double dNumber, String sFormatStrg );
     105                 :            :     String  BasicFormatNull( String sFormatStrg );
     106                 :            : 
     107                 :            :     static  sal_Bool isBasicFormat( String sFormatStrg );
     108                 :            : 
     109                 :            :   private:
     110                 :            :     BASIC_DLLPRIVATE inline void    ShiftString( String& sStrg, sal_uInt16 nStartPos );
     111                 :            :     BASIC_DLLPRIVATE inline void    StrAppendChar( String& sStrg, sal_Unicode ch );
     112                 :            :     BASIC_DLLPRIVATE void   AppendDigit( String& sStrg, short nDigit );
     113                 :            :     BASIC_DLLPRIVATE void   LeftShiftDecimalPoint( String& sStrg );
     114                 :            :     BASIC_DLLPRIVATE void   StrRoundDigit( String& sStrg, short nPos, sal_Bool& bOverflow );
     115                 :            :     BASIC_DLLPRIVATE void   StrRoundDigit( String& sStrg, short nPos );
     116                 :            :     BASIC_DLLPRIVATE void   ParseBack( String& sStrg, const String& sFormatStrg,
     117                 :            :                 short nFormatPos );
     118                 :            : #ifdef _with_sprintf
     119                 :            :     // Methods for string conversion with sprintf():
     120                 :            :     BASIC_DLLPRIVATE void   InitScan( double _dNum );
     121                 :            :     BASIC_DLLPRIVATE void   InitExp( double _dNewExp );
     122                 :            :     BASIC_DLLPRIVATE short  GetDigitAtPosScan( short nPos, sal_Bool& bFoundFirstDigit );
     123                 :            :     BASIC_DLLPRIVATE short  GetDigitAtPosExpScan( double dNewExponent, short nPos,
     124                 :            :                 sal_Bool& bFoundFirstDigit );
     125                 :            :     BASIC_DLLPRIVATE short  GetDigitAtPosExpScan( short nPos, sal_Bool& bFoundFirstDigit );
     126                 :            : #else
     127                 :            :     // Methods for direct 'calculation' with log10() and pow():
     128                 :            :     BASIC_DLLPRIVATE short  GetDigitAtPos( double dNumber, short nPos, double& dNextNumber,
     129                 :            :                 sal_Bool& bFoundFirstDigit );
     130                 :            :     BASIC_DLLPRIVATE short  RoundDigit( double dNumber );
     131                 :            : #endif
     132                 :            :     BASIC_DLLPRIVATE String GetPosFormatString( const String& sFormatStrg, sal_Bool & bFound );
     133                 :            :     BASIC_DLLPRIVATE String GetNegFormatString( const String& sFormatStrg, sal_Bool & bFound );
     134                 :            :     BASIC_DLLPRIVATE String Get0FormatString( const String& sFormatStrg, sal_Bool & bFound );
     135                 :            :     BASIC_DLLPRIVATE String GetNullFormatString( const String& sFormatStrg, sal_Bool & bFound );
     136                 :            :     BASIC_DLLPRIVATE short  AnalyseFormatString( const String& sFormatStrg,
     137                 :            :                 short& nNoOfDigitsLeft, short& nNoOfDigitsRight,
     138                 :            :                 short& nNoOfOptionalDigitsLeft,
     139                 :            :                 short& nNoOfExponentDigits,
     140                 :            :                 short& nNoOfOptionalExponentDigits,
     141                 :            :                 sal_Bool& bPercent, sal_Bool& bCurrency, sal_Bool& bScientific,
     142                 :            :                 sal_Bool& bGenerateThousandSeparator,
     143                 :            :                 short& nMultipleThousandSeparators );
     144                 :            :     BASIC_DLLPRIVATE void   ScanFormatString( double dNumber, const String& sFormatStrg,
     145                 :            :                 String& sReturnStrg, sal_Bool bCreateSign );
     146                 :            : 
     147                 :            :     //*** Data ***
     148                 :            :     sal_Unicode cDecPoint;      // sign for the decimal point
     149                 :            :     sal_Unicode cThousandSep;   // sign for thousand delimiter
     150                 :            :     // Text for output:
     151                 :            :     String  sOnStrg;
     152                 :            :     String  sOffStrg;
     153                 :            :     String  sYesStrg;
     154                 :            :     String  sNoStrg;
     155                 :            :     String  sTrueStrg;
     156                 :            :     String  sFalseStrg;
     157                 :            :     String  sCurrencyStrg;
     158                 :            :     String  sCurrencyFormatStrg;
     159                 :            : 
     160                 :            :     //*** temporary data for scan loop ***
     161                 :            :     //-----------------------------------------------
     162                 :            :     // String containing the number in scientific format
     163                 :            :     String  sSciNumStrg;
     164                 :            :     // String containing the exponent of the number
     165                 :            :     String  sNumExpStrg;
     166                 :            :     double  dNum;           // the number that is scanned
     167                 :            :     short   nNumExp;        // the exponent of the number
     168                 :            :     short   nExpExp;        // the number of digits in the exponent
     169                 :            : };
     170                 :            : 
     171                 :            : #endif
     172                 :            : 
     173                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10