LCOV - code coverage report
Current view: top level - basic/source/sbx - sbxform.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 405 0.0 %
Date: 2012-08-25 Functions: 0 23 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 605 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                 :            : 
      21                 :            : #include <stdlib.h>
      22                 :            : 
      23                 :            : #include <basic/sbxform.hxx>
      24                 :            : 
      25                 :            : /*
      26                 :            : TODO: are there any Star-Basic characteristics unconsidered?
      27                 :            : 
      28                 :            :         what means: * as placeholder
      29                 :            : 
      30                 :            : COMMENT: Visual-Basic treats the following (invalid) format-strings
      31                 :            :       as shown:
      32                 :            : 
      33                 :            :         ##0##.##0##     --> ##000.000##
      34                 :            : 
      35                 :            :       (this class behaves the same way)
      36                 :            : */
      37                 :            : 
      38                 :            : #include <stdio.h>          // for: sprintf()
      39                 :            : #include <float.h>          // for: DBL_DIG, DBL_EPSILON
      40                 :            : #include <math.h>           // for: floor(), fabs(), log10(), pow()
      41                 :            : 
      42                 :            : //=================================================================
      43                 :            : //=========================== DEFINES =============================
      44                 :            : //=================================================================
      45                 :            : 
      46                 :            : #define _NO_DIGIT                   -1
      47                 :            : 
      48                 :            : #define MAX_NO_OF_EXP_DIGITS        5
      49                 :            :                     // +4 because of the value range: between -308 and +308
      50                 :            :                     // +1 for closing 0
      51                 :            : #define MAX_NO_OF_DIGITS            DBL_DIG
      52                 :            : #define MAX_DOUBLE_BUFFER_LENGTH    MAX_NO_OF_DIGITS + 9
      53                 :            :                     // +1 for leading sign
      54                 :            :                     // +1 for digit before the decimal point
      55                 :            :                     // +1 for decimal point
      56                 :            :                     // +2 for exponent E and exp. leading sign
      57                 :            :                     // +3 for the exponent's value
      58                 :            :                     // +1 for closing 0
      59                 :            : 
      60                 :            : // Defines for the digits:
      61                 :            : #define ASCII_0                     '0' // 48
      62                 :            : #define ASCII_9                     '9' // 57
      63                 :            : 
      64                 :            : #define CREATE_1000SEP_CHAR         '@'
      65                 :            : 
      66                 :            : #define FORMAT_SEPARATOR            ';'
      67                 :            : 
      68                 :            : // predefined formats for the Format$()-command:
      69                 :            : #define BASICFORMAT_GENERALNUMBER   "General Number"
      70                 :            : #define BASICFORMAT_CURRENCY        "Currency"
      71                 :            : #define BASICFORMAT_FIXED           "Fixed"
      72                 :            : #define BASICFORMAT_STANDARD        "Standard"
      73                 :            : #define BASICFORMAT_PERCENT         "Percent"
      74                 :            : #define BASICFORMAT_SCIENTIFIC      "Scientific"
      75                 :            : #define BASICFORMAT_YESNO           "Yes/No"
      76                 :            : #define BASICFORMAT_TRUEFALSE       "True/False"
      77                 :            : #define BASICFORMAT_ONOFF           "On/Off"
      78                 :            : 
      79                 :            : #define EMPTYFORMATSTRING           ""
      80                 :            : 
      81                 :            : // Comment: Visual-Basic has a maximum of 12 positions after the
      82                 :            : //          decimal point for floating-point-numbers.
      83                 :            : // all format-strings are compatible to Visual-Basic:
      84                 :            : #define GENERALNUMBER_FORMAT        "0.############"
      85                 :            : #define CURRENCY_FORMAT             "@$0.00;@($0.00)"
      86                 :            : #define FIXED_FORMAT                "0.00"
      87                 :            : #define STANDARD_FORMAT             "@0.00"
      88                 :            : #define PERCENT_FORMAT              "0.00%"
      89                 :            : #define SCIENTIFIC_FORMAT           "#.00E+00"
      90                 :            : // Comment: the character @ means that thousand-separators shall
      91                 :            : //          be generated. That's a StarBasic 'extension'.
      92                 :            : 
      93                 :            : //=================================================================
      94                 :            : 
      95                 :            : 
      96                 :          0 : double get_number_of_digits( double dNumber )
      97                 :            : //double floor_log10_fabs( double dNumber )
      98                 :            : {
      99         [ #  # ]:          0 :     if( dNumber==0.0 )
     100                 :          0 :         return 0.0; // used to be 1.0, now 0.0 because of #40025;
     101                 :            :     else
     102                 :          0 :         return floor( log10( fabs( dNumber ) ) );
     103                 :            : }
     104                 :            : 
     105                 :            : //=================================================================
     106                 :            : //======================= IMPLEMENTATION ==========================
     107                 :            : //=================================================================
     108                 :            : 
     109                 :          0 : SbxBasicFormater::SbxBasicFormater( sal_Unicode _cDecPoint, sal_Unicode _cThousandSep,
     110                 :            :                       String _sOnStrg,
     111                 :            :                       String _sOffStrg,
     112                 :            :                       String _sYesStrg,
     113                 :            :                       String _sNoStrg,
     114                 :            :                       String _sTrueStrg,
     115                 :            :                       String _sFalseStrg,
     116                 :            :                       String _sCurrencyStrg,
     117 [ #  # ][ #  # ]:          0 :                       String _sCurrencyFormatStrg )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     118                 :            : {
     119                 :          0 :     cDecPoint = _cDecPoint;
     120                 :          0 :     cThousandSep = _cThousandSep;
     121         [ #  # ]:          0 :     sOnStrg = _sOnStrg;
     122         [ #  # ]:          0 :     sOffStrg = _sOffStrg;
     123         [ #  # ]:          0 :     sYesStrg = _sYesStrg;
     124         [ #  # ]:          0 :     sNoStrg = _sNoStrg;
     125         [ #  # ]:          0 :     sTrueStrg = _sTrueStrg;
     126         [ #  # ]:          0 :     sFalseStrg = _sFalseStrg;
     127         [ #  # ]:          0 :     sCurrencyStrg = _sCurrencyStrg;
     128         [ #  # ]:          0 :     sCurrencyFormatStrg = _sCurrencyFormatStrg;
     129                 :          0 : }
     130                 :            : 
     131                 :            : // function for ouput of a error-text (for debugging)
     132                 :            : // displaces all characters of the string, starting from nStartPos
     133                 :            : // for one position to larger indexes, i. e. place for a new
     134                 :            : // character (which is to be inserted) is created.
     135                 :            : // ATTENTION: the string MUST be long enough!
     136                 :          0 : inline void SbxBasicFormater::ShiftString( String& sStrg, sal_uInt16 nStartPos )
     137                 :            : {
     138                 :          0 :     sStrg.Erase( nStartPos,1 );
     139                 :          0 : }
     140                 :            : 
     141                 :          0 : inline void SbxBasicFormater::StrAppendChar( String& sStrg, sal_Unicode ch )
     142                 :            : {
     143                 :          0 :     sStrg.Insert( ch );
     144                 :          0 : }
     145                 :            : 
     146                 :          0 : void SbxBasicFormater::AppendDigit( String& sStrg, short nDigit )
     147                 :            : {
     148 [ #  # ][ #  # ]:          0 :     if( nDigit>=0 && nDigit<=9 )
     149                 :          0 :         StrAppendChar( sStrg, (sal_Unicode)(nDigit+ASCII_0) );
     150                 :          0 : }
     151                 :            : 
     152                 :          0 : void SbxBasicFormater::LeftShiftDecimalPoint( String& sStrg )
     153                 :            : {
     154                 :          0 :     sal_uInt16 nPos = sStrg.Search( cDecPoint );
     155                 :            : 
     156         [ #  # ]:          0 :     if( nPos!=STRING_NOTFOUND )
     157                 :            :     {
     158                 :            :         // swap decimal point
     159                 :          0 :         sStrg.SetChar( nPos, sStrg.GetChar( nPos - 1 ) );
     160                 :          0 :         sStrg.SetChar( nPos-1, cDecPoint );
     161                 :            :     }
     162                 :          0 : }
     163                 :            : 
     164                 :            : // returns a flag if rounding a 9
     165                 :          0 : void SbxBasicFormater::StrRoundDigit( String& sStrg, short nPos, sal_Bool& bOverflow )
     166                 :            : {
     167         [ #  # ]:          0 :     if( nPos<0 )
     168                 :          0 :         return;
     169                 :            : 
     170                 :          0 :     bOverflow = sal_False;
     171                 :            : 
     172                 :          0 :     sal_Unicode c = sStrg.GetChar( nPos );
     173 [ #  # ][ #  # ]:          0 :     if( nPos>0 && (c == cDecPoint || c == cThousandSep) )
                 [ #  # ]
     174                 :            :     {
     175                 :          0 :         StrRoundDigit( sStrg,nPos-1,bOverflow );
     176                 :            :         // CHANGE from 9.3.1997: end the method immediately after recursive call!
     177                 :          0 :         return;
     178                 :            :     }
     179                 :            :     // skip non-digits:
     180                 :            :     // COMMENT:
     181                 :            :     // in a valid format-string the number's output should be done
     182                 :            :     // in one piece, i. e. special characters should ONLY be in
     183                 :            :     // front OR behind the number and not right in the middle of
     184                 :            :     // the format information for the number
     185 [ #  # ][ #  # ]:          0 :     while( nPos>=0 && (sStrg.GetChar( nPos )<ASCII_0 || sStrg.GetChar( nPos )>ASCII_9) )
         [ #  # ][ #  # ]
     186                 :          0 :         nPos--;
     187                 :            : 
     188         [ #  # ]:          0 :     if( nPos==-1 )
     189                 :            :     {
     190                 :          0 :         ShiftString( sStrg,0 );
     191                 :          0 :         sStrg.SetChar( 0, '1' );
     192                 :          0 :         bOverflow = sal_True;
     193                 :            :     }
     194                 :            :     else
     195                 :            :     {
     196                 :          0 :         sal_Unicode c2 = sStrg.GetChar( nPos );
     197 [ #  # ][ #  # ]:          0 :         if( c2 >= ASCII_0 && c2 <= ASCII_9 )
     198                 :            :         {
     199         [ #  # ]:          0 :             if( c2 == ASCII_9 )
     200                 :            :             {
     201                 :          0 :                 sStrg.SetChar( nPos, '0' );
     202                 :          0 :                 StrRoundDigit( sStrg,nPos-1,bOverflow );
     203                 :            :             }
     204                 :            :             else
     205                 :          0 :                 sStrg.SetChar( nPos, c2+1 );
     206                 :            :         }
     207                 :            :         else
     208                 :            :         {
     209                 :          0 :             ShiftString( sStrg,nPos+1 );
     210                 :          0 :             sStrg.SetChar( nPos+1, '1' );
     211                 :          0 :             bOverflow = sal_True;
     212                 :            :         }
     213                 :            :     }
     214                 :            : }
     215                 :            : 
     216                 :            : 
     217                 :          0 : void SbxBasicFormater::StrRoundDigit( String& sStrg, short nPos )
     218                 :            : {
     219                 :            :     sal_Bool bOverflow;
     220                 :            : 
     221         [ #  # ]:          0 :     StrRoundDigit( sStrg,nPos,bOverflow );
     222                 :          0 : }
     223                 :            : 
     224                 :          0 : void SbxBasicFormater::ParseBack( String& sStrg, const String& sFormatStrg,
     225                 :            :                                   short nFormatPos )
     226                 :            : {
     227   [ #  #  #  #  :          0 :     for( short i=nFormatPos;
           #  # ][ #  # ]
     228                 :          0 :          i>0 && sFormatStrg.GetChar( i ) == '#' && sStrg.GetChar( (sStrg.Len()-1) ) == '0';
     229                 :            :          i-- )
     230                 :          0 :          { sStrg.Erase( sStrg.Len()-1 ); }
     231                 :          0 : }
     232                 :            : 
     233                 :            : #ifdef _with_sprintf
     234                 :            : 
     235                 :            : 
     236                 :          0 : void SbxBasicFormater::InitScan( double _dNum )
     237                 :            : {
     238                 :            :     char sBuffer[ MAX_DOUBLE_BUFFER_LENGTH ];
     239                 :            : 
     240                 :          0 :     dNum = _dNum;
     241         [ #  # ]:          0 :     InitExp( get_number_of_digits( dNum ) );
     242                 :            :     // maximum of 15 positions behind the decimal point, example: -1.234000000000000E-001
     243                 :          0 :     /*int nCount =*/ sprintf( sBuffer,"%+22.15lE",dNum );
     244         [ #  # ]:          0 :     sSciNumStrg.AssignAscii( sBuffer );
     245                 :          0 : }
     246                 :            : 
     247                 :            : 
     248                 :          0 : void SbxBasicFormater::InitExp( double _dNewExp )
     249                 :            : {
     250                 :            :     char sBuffer[ MAX_DOUBLE_BUFFER_LENGTH ];
     251                 :          0 :     nNumExp = (short)_dNewExp;
     252                 :          0 :     /*int nCount =*/ sprintf( sBuffer,"%+i",nNumExp );
     253         [ #  # ]:          0 :     sNumExpStrg.AssignAscii( sBuffer );
     254                 :          0 :     nExpExp = (short)get_number_of_digits( (double)nNumExp );
     255                 :          0 : }
     256                 :            : 
     257                 :            : 
     258                 :          0 : short SbxBasicFormater::GetDigitAtPosScan( short nPos, sal_Bool& bFoundFirstDigit )
     259                 :            : {
     260                 :            :     // trying to read a higher digit,
     261                 :            :     // e. g. position 4 in 1.234,
     262                 :            :     // or to read a digit outside of the
     263                 :            :     // number's dissolution (double)
     264 [ #  # ][ #  # ]:          0 :     if( nPos>nNumExp || abs(nNumExp-nPos)>MAX_NO_OF_DIGITS )
     265                 :          0 :         return _NO_DIGIT;
     266                 :            :     // determine the index of the position in the number-string:
     267                 :            :     // skip the leading sign
     268                 :          0 :     sal_uInt16 no = 1;
     269                 :            :     // skip the decimal point if necessary
     270         [ #  # ]:          0 :     if( nPos<nNumExp )
     271                 :          0 :         no++;
     272                 :          0 :     no += nNumExp-nPos;
     273                 :            :     // query of the number's first valid digit --> set flag
     274         [ #  # ]:          0 :     if( nPos==nNumExp )
     275                 :          0 :         bFoundFirstDigit = sal_True;
     276                 :          0 :     return (short)(sSciNumStrg.GetChar( no ) - ASCII_0);
     277                 :            : }
     278                 :            : 
     279                 :          0 : short SbxBasicFormater::GetDigitAtPosExpScan( short nPos, sal_Bool& bFoundFirstDigit )
     280                 :            : {
     281         [ #  # ]:          0 :     if( nPos>nExpExp )
     282                 :          0 :         return -1;
     283                 :            : 
     284                 :          0 :     sal_uInt16 no = 1;
     285                 :          0 :     no += nExpExp-nPos;
     286                 :            : 
     287         [ #  # ]:          0 :     if( nPos==nExpExp )
     288                 :          0 :         bFoundFirstDigit = sal_True;
     289                 :          0 :     return (short)(sNumExpStrg.GetChar( no ) - ASCII_0);
     290                 :            : }
     291                 :            : 
     292                 :            : // a value for the exponent can be given because the number maybe shall
     293                 :            : // not be displayed in a normed way (e. g. 1.2345e-03) but maybe 123.345e-3 !
     294                 :          0 : short SbxBasicFormater::GetDigitAtPosExpScan( double dNewExponent, short nPos,
     295                 :            :                                               sal_Bool& bFoundFirstDigit )
     296                 :            : {
     297                 :          0 :     InitExp( dNewExponent );
     298                 :            : 
     299                 :          0 :     return GetDigitAtPosExpScan( nPos,bFoundFirstDigit );
     300                 :            : }
     301                 :            : 
     302                 :            : #else
     303                 :            : 
     304                 :            : /* Problems with the following method:
     305                 :            : 
     306                 :            : TODO: an 'intelligent' peek-parser might be needed to detect rounding
     307                 :            :       mistakes at double-numbers - e. g. for  0.00115 #.#e-000
     308                 :            : 
     309                 :            :   problem with: format( 0.3345 ,  "0.000" )
     310                 :            :   problem with: format( 0.00115 , "0.0000" )
     311                 :            : 
     312                 :            : */
     313                 :            : // returns the digit at the given '10 system'-position,
     314                 :            : // i. e. positive nPos for positions before the decimal
     315                 :            : // point and negative for positions after.
     316                 :            : // nPos==0 means first position after the decimalpoint, so 10^0.
     317                 :            : // returns 0..9 for valid digits and -1 for not existing,
     318                 :            : // i. e. if the passed number is too small
     319                 :            : // (e. g. position 5 of dNumber=123).
     320                 :            : // Furthermore in dNextNumber the number shorted by leading
     321                 :            : // positions (till nPos) is returned, e. g.
     322                 :            : //   GetDigitAtPos( 3434.565 , 2 , dNewNumber ) --> dNewNumber = 434.565
     323                 :            : // In bFoundFirstDigit a flag is set if a digit has been found,
     324                 :            : // this is used to prevent 'errors' on parsing 202
     325                 :            : // ATTENTION: apparently there are sometimes still problems with rounding mistakes!
     326                 :            : short SbxBasicFormater::GetDigitAtPos( double dNumber, short nPos,
     327                 :            :                                 double& dNextNumber, sal_Bool& bFoundFirstDigit )
     328                 :            : {
     329                 :            :     double dDigit;
     330                 :            :     short  nMaxDigit;
     331                 :            : 
     332                 :            :     dNumber = fabs( dNumber );
     333                 :            : 
     334                 :            :     nMaxDigit = (short)get_number_of_digits( dNumber );
     335                 :            :     // error only at numbers > 0, i. e. for digits before
     336                 :            :     // the decimal point
     337                 :            :     if( nMaxDigit<nPos && !bFoundFirstDigit && nPos>=0 )
     338                 :            :         return _NO_DIGIT;
     339                 :            : 
     340                 :            :     bFoundFirstDigit = sal_True;
     341                 :            :     for( short i=nMaxDigit; i>=nPos; i-- )
     342                 :            :     {
     343                 :            :         double dI = (double)i;
     344                 :            :         double dTemp1 = pow( 10.0,dI );
     345                 :            : 
     346                 :            :         dDigit = floor( pow( 10.0,log10( fabs( dNumber ) )-dI ) );
     347                 :            :         dNumber -= dTemp1 * dDigit;
     348                 :            :     }
     349                 :            :     // for optimized loop run
     350                 :            :     dNextNumber = dNumber;
     351                 :            : 
     352                 :            :     return RoundDigit( dDigit );
     353                 :            : }
     354                 :            : 
     355                 :            : 
     356                 :            : short SbxBasicFormater::RoundDigit( double dNumber )
     357                 :            : {
     358                 :            :     if( dNumber<0.0 || dNumber>10.0 )
     359                 :            :         return -1;
     360                 :            :     short nTempHigh = (short)(dNumber+0.5); // maybe floor( )
     361                 :            :     return nTempHigh;
     362                 :            : }
     363                 :            : 
     364                 :            : #endif
     365                 :            : 
     366                 :            : // Copies the respective part of the format-string, if existing, and returns it.
     367                 :            : // So a new string is created, which has to be freed by the caller later.
     368                 :          0 : String SbxBasicFormater::GetPosFormatString( const String& sFormatStrg, sal_Bool & bFound )
     369                 :            : {
     370                 :          0 :     bFound = sal_False;     // default...
     371         [ #  # ]:          0 :     sal_uInt16 nPos = sFormatStrg.Search( FORMAT_SEPARATOR );
     372                 :            : 
     373         [ #  # ]:          0 :     if( nPos!=STRING_NOTFOUND )
     374                 :            :     {
     375                 :          0 :         bFound = sal_True;
     376                 :            :         // the format-string for positive numbers is
     377                 :            :         // everything before the first ';'
     378         [ #  # ]:          0 :         return sFormatStrg.Copy( 0,nPos );
     379                 :            :     }
     380                 :            : 
     381         [ #  # ]:          0 :     String aRetStr;
     382         [ #  # ]:          0 :     aRetStr.AssignAscii( EMPTYFORMATSTRING );
     383 [ #  # ][ #  # ]:          0 :     return aRetStr;
     384                 :            : }
     385                 :            : 
     386                 :            : // see also GetPosFormatString()
     387                 :          0 : String SbxBasicFormater::GetNegFormatString( const String& sFormatStrg, sal_Bool & bFound )
     388                 :            : {
     389                 :          0 :     bFound = sal_False;     // default...
     390         [ #  # ]:          0 :     sal_uInt16 nPos = sFormatStrg.Search( FORMAT_SEPARATOR );
     391                 :            : 
     392         [ #  # ]:          0 :     if( nPos!=STRING_NOTFOUND )
     393                 :            :     {
     394                 :            :         // the format-string for negative numbers is
     395                 :            :         // everything between the first and the second ';'
     396         [ #  # ]:          0 :         String sTempStrg = sFormatStrg.Copy( nPos+1 );
     397         [ #  # ]:          0 :         nPos = sTempStrg.Search( FORMAT_SEPARATOR );
     398                 :          0 :         bFound = sal_True;
     399         [ #  # ]:          0 :         if( nPos==STRING_NOTFOUND )
     400         [ #  # ]:          0 :             return sTempStrg;
     401                 :            :         else
     402 [ #  # ][ #  # ]:          0 :             return sTempStrg.Copy( 0,nPos );
     403                 :            :     }
     404         [ #  # ]:          0 :     String aRetStr;
     405         [ #  # ]:          0 :     aRetStr.AssignAscii( EMPTYFORMATSTRING );
     406 [ #  # ][ #  # ]:          0 :     return aRetStr;
     407                 :            : }
     408                 :            : 
     409                 :            : // see also GetPosFormatString()
     410                 :          0 : String SbxBasicFormater::Get0FormatString( const String& sFormatStrg, sal_Bool & bFound )
     411                 :            : {
     412                 :          0 :     bFound = sal_False;     // default...
     413         [ #  # ]:          0 :     sal_uInt16 nPos = sFormatStrg.Search( FORMAT_SEPARATOR );
     414                 :            : 
     415         [ #  # ]:          0 :     if( nPos!=STRING_NOTFOUND )
     416                 :            :     {
     417                 :            :         // the format string for the zero is
     418                 :            :         // everything after the second ';'
     419         [ #  # ]:          0 :         String sTempStrg = sFormatStrg.Copy( nPos+1 );
     420         [ #  # ]:          0 :         nPos = sTempStrg.Search( FORMAT_SEPARATOR );
     421         [ #  # ]:          0 :         if( nPos!=STRING_NOTFOUND )
     422                 :            :         {
     423                 :          0 :             bFound = sal_True;
     424 [ #  # ][ #  # ]:          0 :             sTempStrg = sTempStrg.Copy( nPos+1 );
                 [ #  # ]
     425         [ #  # ]:          0 :             nPos = sTempStrg.Search( FORMAT_SEPARATOR );
     426         [ #  # ]:          0 :             if( nPos==STRING_NOTFOUND )
     427         [ #  # ]:          0 :                 return sTempStrg;
     428                 :            :             else
     429         [ #  # ]:          0 :                 return sTempStrg.Copy( 0,nPos );
     430 [ #  # ][ #  # ]:          0 :         }
     431                 :            :     }
     432                 :            : 
     433         [ #  # ]:          0 :     String aRetStr;
     434         [ #  # ]:          0 :     aRetStr.AssignAscii( EMPTYFORMATSTRING );
     435 [ #  # ][ #  # ]:          0 :     return aRetStr;
     436                 :            : }
     437                 :            : 
     438                 :            : // see also GetPosFormatString()
     439                 :          0 : String SbxBasicFormater::GetNullFormatString( const String& sFormatStrg, sal_Bool & bFound )
     440                 :            : {
     441                 :          0 :     bFound = sal_False;     // default...
     442         [ #  # ]:          0 :     sal_uInt16 nPos = sFormatStrg.Search( FORMAT_SEPARATOR );
     443                 :            : 
     444         [ #  # ]:          0 :     if( nPos!=STRING_NOTFOUND )
     445                 :            :     {
     446                 :            :         // the format-string for the Null is
     447                 :            :         // everything after the third ';'
     448         [ #  # ]:          0 :         String sTempStrg = sFormatStrg.Copy( nPos+1 );
     449         [ #  # ]:          0 :         nPos = sTempStrg.Search( FORMAT_SEPARATOR );
     450         [ #  # ]:          0 :         if( nPos!=STRING_NOTFOUND )
     451                 :            :         {
     452 [ #  # ][ #  # ]:          0 :             sTempStrg = sTempStrg.Copy( nPos+1 );
                 [ #  # ]
     453         [ #  # ]:          0 :             nPos = sTempStrg.Search( FORMAT_SEPARATOR );
     454         [ #  # ]:          0 :             if( nPos!=STRING_NOTFOUND )
     455                 :            :             {
     456                 :          0 :                 bFound = sal_True;
     457         [ #  # ]:          0 :                 return sTempStrg.Copy( nPos+1 );
     458                 :            :             }
     459 [ #  # ][ #  # ]:          0 :         }
     460                 :            :     }
     461                 :            : 
     462         [ #  # ]:          0 :     String aRetStr;
     463         [ #  # ]:          0 :     aRetStr.AssignAscii( EMPTYFORMATSTRING );
     464 [ #  # ][ #  # ]:          0 :     return aRetStr;
     465                 :            : }
     466                 :            : 
     467                 :            : 
     468                 :            : // returns value <> 0 in case of an error
     469                 :          0 : short SbxBasicFormater::AnalyseFormatString( const String& sFormatStrg,
     470                 :            :                 short& nNoOfDigitsLeft, short& nNoOfDigitsRight,
     471                 :            :                 short& nNoOfOptionalDigitsLeft,
     472                 :            :                 short& nNoOfExponentDigits, short& nNoOfOptionalExponentDigits,
     473                 :            :                 sal_Bool& bPercent, sal_Bool& bCurrency, sal_Bool& bScientific,
     474                 :            :                 sal_Bool& bGenerateThousandSeparator,
     475                 :            :                 short& nMultipleThousandSeparators )
     476                 :            : {
     477                 :            :     sal_uInt16 nLen;
     478                 :          0 :     short nState = 0;
     479                 :            : 
     480                 :          0 :     nLen = sFormatStrg.Len();
     481                 :          0 :     nNoOfDigitsLeft = 0;
     482                 :          0 :     nNoOfDigitsRight = 0;
     483                 :          0 :     nNoOfOptionalDigitsLeft = 0;
     484                 :          0 :     nNoOfExponentDigits = 0;
     485                 :          0 :     nNoOfOptionalExponentDigits = 0;
     486                 :          0 :     bPercent = sal_False;
     487                 :          0 :     bCurrency = sal_False;
     488                 :          0 :     bScientific = sal_False;
     489                 :            :     // from 11.7.97: as soon as a comma (point?) is found in the format string,
     490                 :            :     // all three decimal powers are marked (i. e. thousand, million, ...)
     491                 :          0 :     bGenerateThousandSeparator = sFormatStrg.Search( ',' ) != STRING_NOTFOUND;
     492                 :          0 :     nMultipleThousandSeparators = 0;
     493                 :            : 
     494         [ #  # ]:          0 :     for( sal_uInt16 i=0; i<nLen; i++ )
     495                 :            :     {
     496                 :          0 :         sal_Unicode c = sFormatStrg.GetChar( i );
     497   [ #  #  #  #  :          0 :         switch( c ) {
             #  #  #  #  
                      # ]
     498                 :            :             case '#':
     499                 :            :             case '0':
     500         [ #  # ]:          0 :                 if( nState==0 )
     501                 :            :                 {
     502                 :          0 :                     nNoOfDigitsLeft++;
     503                 :            : // TODO  here maybe better error inspection of the mantissa for valid syntax (see grammar)h
     504                 :            :                     // ATTENTION: 'undefined' behaviour if # and 0 are combined!
     505                 :            :                     // REMARK: #-placeholders are actually useless for
     506                 :            :                     // scientific display before the decimal point!
     507         [ #  # ]:          0 :                     if( c=='#' )
     508                 :          0 :                         nNoOfOptionalDigitsLeft++;
     509                 :            :                 }
     510         [ #  # ]:          0 :                 else if( nState==1 )
     511                 :          0 :                     nNoOfDigitsRight++;
     512         [ #  # ]:          0 :                 else if( nState==-1 )   // search 0 in the exponent
     513                 :            :                 {
     514         [ #  # ]:          0 :                     if( c=='#' )    // # switches on the condition
     515                 :            :                     {
     516                 :          0 :                         nNoOfOptionalExponentDigits++;
     517                 :          0 :                         nState = -2;
     518                 :            :                     }
     519                 :          0 :                     nNoOfExponentDigits++;
     520                 :            :                 }
     521         [ #  # ]:          0 :                 else if( nState==-2 )   // search # in the exponent
     522                 :            :                 {
     523         [ #  # ]:          0 :                     if( c=='0' )
     524                 :            :                         // ERROR: 0 after # in the exponent is NOT allowed!!
     525                 :          0 :                         return -4;
     526                 :          0 :                     nNoOfOptionalExponentDigits++;
     527                 :          0 :                     nNoOfExponentDigits++;
     528                 :            :                 }
     529                 :          0 :                 break;
     530                 :            :             case '.':
     531                 :          0 :                 nState++;
     532         [ #  # ]:          0 :                 if( nState>1 )
     533                 :          0 :                     return -1;  // ERROR: too many decimal points
     534                 :          0 :                 break;
     535                 :            :             case '%':
     536                 :          0 :                 bPercent = sal_True;
     537                 :          0 :                 break;
     538                 :            :             case '(':
     539                 :          0 :                 bCurrency = sal_True;
     540                 :          0 :                 break;
     541                 :            :             case ',':
     542                 :            :             {
     543                 :          0 :                 sal_Unicode ch = sFormatStrg.GetChar( i+1 );
     544                 :            : 
     545 [ #  # ][ #  # ]:          0 :                 if( ch!=0 && (ch==',' || ch=='.') )
                 [ #  # ]
     546                 :          0 :                     nMultipleThousandSeparators++;
     547                 :          0 :             }   break;
     548                 :            :             case 'e':
     549                 :            :             case 'E':
     550                 :            :                 // #i13821 not when no digits before
     551 [ #  # ][ #  # ]:          0 :                 if( nNoOfDigitsLeft > 0 || nNoOfDigitsRight > 0 )
     552                 :            :                 {
     553                 :          0 :                      nState = -1;   // abort counting digits
     554                 :          0 :                     bScientific = sal_True;
     555                 :            :                 }
     556                 :          0 :                 break;
     557                 :            :             // OWN command-character which turns on
     558                 :            :             // the creation of thousand-separators
     559                 :            :             case '\\':
     560                 :            :                 // Ignore next char
     561                 :          0 :                 i++;
     562                 :          0 :                 break;
     563                 :            :             case CREATE_1000SEP_CHAR:
     564                 :          0 :                 bGenerateThousandSeparator = sal_True;
     565                 :          0 :                 break;
     566                 :            :         }
     567                 :            :     }
     568                 :          0 :     return 0;
     569                 :            : }
     570                 :            : 
     571                 :            : // the flag bCreateSign says that at the mantissa a leading sign
     572                 :            : // shall be created
     573                 :          0 : void SbxBasicFormater::ScanFormatString( double dNumber,
     574                 :            :                                 const String& sFormatStrg, String& sReturnStrg,
     575                 :            :                                 sal_Bool bCreateSign )
     576                 :            : {
     577                 :            :     short   /*nErr,*/nNoOfDigitsLeft,nNoOfDigitsRight,nNoOfOptionalDigitsLeft,
     578                 :            :             nNoOfExponentDigits,nNoOfOptionalExponentDigits,
     579                 :            :             nMultipleThousandSeparators;
     580                 :            :     sal_Bool    bPercent,bCurrency,bScientific,bGenerateThousandSeparator;
     581                 :            : 
     582 [ #  # ][ #  # ]:          0 :     sReturnStrg = String();
                 [ #  # ]
     583                 :            : 
     584                 :            :     // analyse the format-string, i. e. determine the following values:
     585                 :            :     /*
     586                 :            :             - number of digits before decimal point
     587                 :            :             - number of digits after decimal point
     588                 :            :             - optional digits before decimal point
     589                 :            :             - number of digits in the exponent
     590                 :            :             - optional digits in the exponent
     591                 :            :             - percent-character found?
     592                 :            :             - () for negative leading sign?
     593                 :            :             - exponetial-notation?
     594                 :            :             - shall thousand-separators be generated?
     595                 :            :             - is a percent-character being found? --> dNumber *= 100.0;
     596                 :            :             - are there thousand-separators in a row?
     597                 :            :                 ,, or ,. --> dNumber /= 1000.0;
     598                 :            :             - other errors? multiple decimal points, E's, etc.
     599                 :            :         --> errors are simply ignored at the moment
     600                 :            :     */
     601                 :            :     AnalyseFormatString( sFormatStrg,nNoOfDigitsLeft,nNoOfDigitsRight,
     602                 :            :                     nNoOfOptionalDigitsLeft,nNoOfExponentDigits,
     603                 :            :                     nNoOfOptionalExponentDigits,
     604                 :            :                     bPercent,bCurrency,bScientific,bGenerateThousandSeparator,
     605         [ #  # ]:          0 :                     nMultipleThousandSeparators );
     606                 :            :         // special handling for special characters
     607         [ #  # ]:          0 :         if( bPercent )
     608                 :          0 :             dNumber *= 100.0;
     609                 :            : // TODO: this condition (,, or ,.) is NOT Visual-Basic compatible!
     610                 :            :         // Question: shall this stay here (requirements)?
     611         [ #  # ]:          0 :         if( nMultipleThousandSeparators )
     612                 :          0 :             dNumber /= 1000.0;
     613                 :            : 
     614                 :            :         double dExponent;
     615                 :            :         short i,nLen;
     616                 :            :         short nState,nDigitPos,nExponentPos,nMaxDigit,nMaxExponentDigit;
     617                 :            :         sal_Bool bFirstDigit,bFirstExponentDigit,bFoundFirstDigit,
     618                 :            :              bIsNegative,bZeroSpaceOn, bSignHappend,bDigitPosNegative;
     619                 :            : 
     620                 :          0 :         bSignHappend = sal_False;
     621                 :          0 :         bFoundFirstDigit = sal_False;
     622                 :          0 :         bIsNegative = dNumber<0.0;
     623                 :          0 :         nLen = sFormatStrg.Len();
     624                 :          0 :         dExponent = get_number_of_digits( dNumber );
     625                 :          0 :         nExponentPos = 0;
     626                 :          0 :         nMaxExponentDigit = 0;
     627                 :          0 :         nMaxDigit = (short)dExponent;
     628                 :          0 :         bDigitPosNegative = false;
     629         [ #  # ]:          0 :         if( bScientific )
     630                 :            :         {
     631                 :          0 :             dExponent = dExponent - (double)(nNoOfDigitsLeft-1);
     632                 :          0 :             nDigitPos = nMaxDigit;
     633                 :          0 :             nMaxExponentDigit = (short)get_number_of_digits( dExponent );
     634                 :          0 :             nExponentPos = nNoOfExponentDigits-1 - nNoOfOptionalExponentDigits;
     635                 :            :         }
     636                 :            :         else
     637                 :            :         {
     638                 :          0 :             nDigitPos = nNoOfDigitsLeft-1; // counting starts at 0, 10^0
     639                 :            :             // no exponent-data is needed here!
     640                 :          0 :             bDigitPosNegative = (nDigitPos < 0);
     641                 :            :         }
     642                 :          0 :         bFirstDigit = sal_True;
     643                 :          0 :         bFirstExponentDigit = sal_True;
     644                 :          0 :         nState = 0; // 0 --> mantissa; 1 --> exponent
     645                 :          0 :         bZeroSpaceOn = 0;
     646                 :            : 
     647                 :            : 
     648                 :            : #ifdef _with_sprintf
     649         [ #  # ]:          0 :         InitScan( dNumber );
     650                 :            : #endif
     651                 :            :         // scanning the format-string:
     652                 :          0 :         sal_Unicode cForce = 0;
     653         [ #  # ]:          0 :         for( i=0; i<nLen; i++ )
     654                 :            :         {
     655                 :            :             sal_Unicode c;
     656         [ #  # ]:          0 :             if( cForce )
     657                 :            :             {
     658                 :          0 :                 c = cForce;
     659                 :          0 :                 cForce = 0;
     660                 :            :             }
     661                 :            :             else
     662                 :            :             {
     663                 :          0 :                 c = sFormatStrg.GetChar( i );
     664                 :            :             }
     665   [ #  #  #  #  :          0 :             switch( c ) {
          #  #  #  #  #  
                #  #  # ]
     666                 :            :                 case '0':
     667                 :            :                 case '#':
     668         [ #  # ]:          0 :                     if( nState==0 )
     669                 :            :                     {
     670                 :            :                     // handling of the mantissa
     671         [ #  # ]:          0 :                         if( bFirstDigit )
     672                 :            :                         {
     673                 :            :                             // remark: at bCurrency the negative
     674                 :            :                             //         leading sign shall be shown with ()
     675 [ #  # ][ #  # ]:          0 :                             if( bIsNegative && !bCreateSign && !bSignHappend )
                 [ #  # ]
     676                 :            :                             {
     677                 :          0 :                                 bSignHappend = sal_True;
     678         [ #  # ]:          0 :                                 StrAppendChar( sReturnStrg,'-' );
     679                 :            :                             }
     680                 :            :                             // output redundant positions, i. e. those which
     681                 :            :                             // are undocumented by the format-string
     682         [ #  # ]:          0 :                             if( nMaxDigit>nDigitPos )
     683                 :            :                             {
     684         [ #  # ]:          0 :                                 for( short j=nMaxDigit; j>nDigitPos; j-- )
     685                 :            :                                 {
     686                 :            :                                     short nTempDigit;
     687                 :            : #ifdef _with_sprintf
     688         [ #  # ]:          0 :                                     AppendDigit( sReturnStrg,nTempDigit = GetDigitAtPosScan( j,bFoundFirstDigit ) );
     689                 :            : #else
     690                 :            :                                     AppendDigit( sReturnStrg,nTempDigit = GetDigitAtPos( dNumber,j,dNumber,bFoundFirstDigit ) );
     691                 :            : #endif
     692                 :            : 
     693         [ #  # ]:          0 :                                     if( nTempDigit!=_NO_DIGIT )
     694                 :          0 :                                         bFirstDigit = sal_False;
     695                 :            : 
     696 [ #  # ][ #  # ]:          0 :                                     if( bGenerateThousandSeparator && ( c=='0' || nMaxDigit>=nDigitPos ) && j>0 && (j % 3 == 0) )
         [ #  # ][ #  # ]
                 [ #  # ]
     697         [ #  # ]:          0 :                                         StrAppendChar( sReturnStrg,cThousandSep );
     698                 :            :                                 }
     699                 :            :                             }
     700                 :            :                         }
     701                 :            : 
     702 [ #  # ][ #  # ]:          0 :                         if( nMaxDigit<nDigitPos && ( c=='0' || bZeroSpaceOn ) )
                 [ #  # ]
     703                 :            :                         {
     704         [ #  # ]:          0 :                             AppendDigit( sReturnStrg,0 );
     705                 :            : 
     706                 :          0 :                             bFirstDigit = sal_False;
     707                 :          0 :                             bZeroSpaceOn = 1;
     708                 :            :                             // Remark: in Visual-Basic the first 0 turns on the 0 for
     709                 :            :                             //         all the following # (up to the decimal point),
     710                 :            :                             //         this behaviour is simulated here with the flag.
     711                 :            : 
     712 [ #  # ][ #  # ]:          0 :                             if( bGenerateThousandSeparator && ( c=='0' || nMaxDigit>=nDigitPos ) && nDigitPos>0 && (nDigitPos % 3 == 0) )
         [ #  # ][ #  # ]
                 [ #  # ]
     713         [ #  # ]:          0 :                                 StrAppendChar( sReturnStrg,cThousandSep );
     714                 :            :                         }
     715                 :            :                         else
     716                 :            :                         {
     717                 :            :                             short nTempDigit;
     718                 :            : #ifdef _with_sprintf
     719         [ #  # ]:          0 :                             AppendDigit( sReturnStrg,nTempDigit = GetDigitAtPosScan( nDigitPos,bFoundFirstDigit ) );
     720                 :            : #else
     721                 :            :                             AppendDigit( sReturnStrg,nTempDigit = GetDigitAtPos( dNumber,nDigitPos,dNumber,bFoundFirstDigit ) );
     722                 :            : #endif
     723                 :            : 
     724         [ #  # ]:          0 :                             if( nTempDigit!=_NO_DIGIT )
     725                 :          0 :                                 bFirstDigit = sal_False;
     726                 :            : 
     727 [ #  # ][ #  # ]:          0 :                             if( bGenerateThousandSeparator && ( c=='0' || nMaxDigit>=nDigitPos ) && nDigitPos>0 && (nDigitPos % 3 == 0) )
         [ #  # ][ #  # ]
                 [ #  # ]
     728         [ #  # ]:          0 :                                 StrAppendChar( sReturnStrg,cThousandSep );
     729                 :            :                         }
     730                 :            : 
     731                 :          0 :                         nDigitPos--;
     732                 :            :                     }
     733                 :            :                     else
     734                 :            :                     {
     735                 :            :                     // handling the exponent
     736         [ #  # ]:          0 :                         if( bFirstExponentDigit )
     737                 :            :                         {
     738                 :            :                             // leading sign has been given out at e/E already
     739                 :          0 :                             bFirstExponentDigit = sal_False;
     740         [ #  # ]:          0 :                             if( nMaxExponentDigit>nExponentPos )
     741                 :            :                             // output redundant positions, i. e. those which
     742                 :            :                             // are undocumented by the format-string
     743                 :            :                             {
     744         [ #  # ]:          0 :                                 for( short j=nMaxExponentDigit; j>nExponentPos; j-- )
     745                 :            :                                 {
     746                 :            : #ifdef _with_sprintf
     747 [ #  # ][ #  # ]:          0 :                                     AppendDigit( sReturnStrg,GetDigitAtPosExpScan( dExponent,j,bFoundFirstDigit ) );
     748                 :            : #else
     749                 :            :                                     AppendDigit( sReturnStrg,GetDigitAtPos( dExponent,j,dExponent,bFoundFirstDigit ) );
     750                 :            : #endif
     751                 :            :                                 }
     752                 :            :                             }
     753                 :            :                         }
     754                 :            : 
     755 [ #  # ][ #  # ]:          0 :                         if( nMaxExponentDigit<nExponentPos && c=='0' )
     756         [ #  # ]:          0 :                             AppendDigit( sReturnStrg,0 );
     757                 :            :                         else
     758                 :            : #ifdef _with_sprintf
     759 [ #  # ][ #  # ]:          0 :                             AppendDigit( sReturnStrg,GetDigitAtPosExpScan( dExponent,nExponentPos,bFoundFirstDigit ) );
     760                 :            : #else
     761                 :            :                             AppendDigit( sReturnStrg,GetDigitAtPos( dExponent,nExponentPos,dExponent,bFoundFirstDigit ) );
     762                 :            : #endif
     763                 :          0 :                         nExponentPos--;
     764                 :            :                     }
     765                 :          0 :                     break;
     766                 :            :                 case '.':
     767         [ #  # ]:          0 :                     if( bDigitPosNegative ) // #i13821: If no digits before .
     768                 :            :                     {
     769                 :          0 :                         bDigitPosNegative = false;
     770                 :          0 :                         nDigitPos = 0;
     771                 :          0 :                         cForce = '#';
     772                 :          0 :                         i-=2;
     773                 :          0 :                         break;
     774                 :            :                     }
     775         [ #  # ]:          0 :                     StrAppendChar( sReturnStrg,cDecPoint );
     776                 :          0 :                     break;
     777                 :            :                 case '%':
     778                 :            :                     // maybe remove redundant 0s, e. g. 4.500e4 in 0.0##e-00
     779         [ #  # ]:          0 :                     ParseBack( sReturnStrg,sFormatStrg,i-1 );
     780         [ #  # ]:          0 :                     sReturnStrg.Insert('%');
     781                 :          0 :                     break;
     782                 :            :                 case 'e':
     783                 :            :                 case 'E':
     784                 :            :                     // does mantissa have to be rounded, before the exponent is displayed?
     785                 :            :                     {
     786                 :            :                         // is there a mantissa at all?
     787         [ #  # ]:          0 :                         if( bFirstDigit )
     788                 :            :                         {
     789                 :            :                             // apparently not, i. e. invalid format string, e. g. E000.00
     790                 :            :                             // so ignore these e and E characters
     791                 :            :                             // maybe output an error (like in Visual Basic)?
     792                 :            : 
     793                 :            :                             // #i13821: VB 6 behaviour
     794         [ #  # ]:          0 :                             StrAppendChar( sReturnStrg,c );
     795                 :            :                             break;
     796                 :            :                         }
     797                 :            : 
     798                 :          0 :                         sal_Bool bOverflow = sal_False;
     799                 :            : #ifdef _with_sprintf
     800                 :          0 :                         short nNextDigit = GetDigitAtPosScan( nDigitPos,bFoundFirstDigit );
     801                 :            : #else
     802                 :            :                         short nNextDigit = GetDigitAtPos( dNumber,nDigitPos,dNumber,bFoundFirstDigit );
     803                 :            : #endif
     804         [ #  # ]:          0 :                         if( nNextDigit>=5 )
     805         [ #  # ]:          0 :                             StrRoundDigit( sReturnStrg,sReturnStrg.Len()-1,bOverflow );
     806         [ #  # ]:          0 :                         if( bOverflow )
     807                 :            :                         {
     808                 :            :                             // a leading 9 has been rounded
     809         [ #  # ]:          0 :                             LeftShiftDecimalPoint( sReturnStrg );
     810         [ #  # ]:          0 :                             sReturnStrg.SetChar( sReturnStrg.Len()-1 , 0 );
     811                 :          0 :                             dExponent += 1.0;
     812                 :            :                         }
     813                 :            :                         // maybe remove redundant 0s, e. g. 4.500e4 in 0.0##e-00
     814         [ #  # ]:          0 :                         ParseBack( sReturnStrg,sFormatStrg,i-1 );
     815                 :            :                     }
     816                 :            :                     // change the scanner's condition
     817                 :          0 :                     nState++;
     818                 :            :                     // output exponent character
     819         [ #  # ]:          0 :                     StrAppendChar( sReturnStrg,c );
     820                 :            :                     // i++; // MANIPULATION of the loop-variable!
     821                 :          0 :                     c = sFormatStrg.GetChar( ++i );
     822                 :            :                     // output leading sign / exponent
     823         [ #  # ]:          0 :                     if( c!=0 )
     824                 :            :                     {
     825         [ #  # ]:          0 :                         if( c=='-' )
     826                 :            :                         {
     827         [ #  # ]:          0 :                             if( dExponent<0.0 )
     828         [ #  # ]:          0 :                                 StrAppendChar( sReturnStrg,'-' );
     829                 :            :                         }
     830         [ #  # ]:          0 :                         else if( c=='+' )
     831                 :            :                         {
     832         [ #  # ]:          0 :                             if( dExponent<0.0 )
     833         [ #  # ]:          0 :                                 StrAppendChar( sReturnStrg,'-' );
     834                 :            :                             else
     835         [ #  # ]:          0 :                                 StrAppendChar( sReturnStrg,'+' );
     836                 :            :                         }
     837                 :            :                     }
     838                 :          0 :                     break;
     839                 :            :                 case ',':
     840                 :          0 :                     break;
     841                 :            :                 case ';':
     842                 :          0 :                     break;
     843                 :            :                 case '(':
     844                 :            :                 case ')':
     845                 :            :                     // maybe remove redundant 0s, e. g. 4.500e4 in 0.0##e-00
     846         [ #  # ]:          0 :                     ParseBack( sReturnStrg,sFormatStrg,i-1 );
     847         [ #  # ]:          0 :                     if( bIsNegative )
     848         [ #  # ]:          0 :                         StrAppendChar( sReturnStrg,c );
     849                 :          0 :                     break;
     850                 :            :                 case '$':
     851                 :            :                     // append the string for the currency:
     852         [ #  # ]:          0 :                     sReturnStrg += sCurrencyStrg;
     853                 :          0 :                     break;
     854                 :            :                 case ' ':
     855                 :            :                 case '-':
     856                 :            :                 case '+':
     857         [ #  # ]:          0 :                     ParseBack( sReturnStrg,sFormatStrg,i-1 );
     858         [ #  # ]:          0 :                     StrAppendChar( sReturnStrg,c );
     859                 :          0 :                     break;
     860                 :            :                 case '\\':
     861         [ #  # ]:          0 :                     ParseBack( sReturnStrg,sFormatStrg,i-1 );
     862                 :            :                     // special character found, output next
     863                 :            :                     // character directly (if existing)
     864                 :          0 :                     c = sFormatStrg.GetChar( ++i );
     865         [ #  # ]:          0 :                     if( c!=0 )
     866         [ #  # ]:          0 :                         StrAppendChar( sReturnStrg,c );
     867                 :          0 :                     break;
     868                 :            :                 case CREATE_1000SEP_CHAR:
     869                 :            :                     // ignore here, action has already been
     870                 :            :                     // executed in AnalyseFormatString
     871                 :          0 :                     break;
     872                 :            :                 default:
     873                 :            :                     // output characters and digits, too (like in Visual-Basic)
     874 [ #  # ][ #  # ]:          0 :                     if( ( c>='a' && c<='z' ) ||
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     875                 :            :                         ( c>='A' && c<='Z' ) ||
     876                 :            :                         ( c>='1' && c<='9' ) )
     877         [ #  # ]:          0 :                         StrAppendChar( sReturnStrg,c );
     878                 :            :             }
     879                 :            :         }
     880                 :            : 
     881                 :            :         // scan completed - rounding necessary?
     882         [ #  # ]:          0 :         if( !bScientific )
     883                 :            :         {
     884                 :            : #ifdef _with_sprintf
     885                 :          0 :             short nNextDigit = GetDigitAtPosScan( nDigitPos,bFoundFirstDigit );
     886                 :            : #else
     887                 :            :             short nNextDigit = GetDigitAtPos( dNumber,nDigitPos,dNumber,bFoundFirstDigit );
     888                 :            : #endif
     889         [ #  # ]:          0 :             if( nNextDigit>=5 )
     890         [ #  # ]:          0 :                 StrRoundDigit( sReturnStrg,sReturnStrg.Len()-1 );
     891                 :            :         }
     892                 :            : 
     893         [ #  # ]:          0 :         if( nNoOfDigitsRight>0 )
     894         [ #  # ]:          0 :             ParseBack( sReturnStrg,sFormatStrg,sFormatStrg.Len()-1 );
     895                 :          0 : }
     896                 :            : 
     897                 :          0 : String SbxBasicFormater::BasicFormatNull( String sFormatStrg )
     898                 :            : {
     899                 :            :     sal_Bool bNullFormatFound;
     900         [ #  # ]:          0 :     String sNullFormatStrg = GetNullFormatString( sFormatStrg,bNullFormatFound );
     901                 :            : 
     902         [ #  # ]:          0 :     if( bNullFormatFound )
     903         [ #  # ]:          0 :         return sNullFormatStrg;
     904         [ #  # ]:          0 :     String aRetStr;
     905         [ #  # ]:          0 :     aRetStr.AssignAscii( "null" );
     906 [ #  # ][ #  # ]:          0 :     return aRetStr;
                 [ #  # ]
     907                 :            : }
     908                 :            : 
     909                 :          0 : String SbxBasicFormater::BasicFormat( double dNumber, String sFormatStrg )
     910                 :            : {
     911                 :            :     sal_Bool bPosFormatFound,bNegFormatFound,b0FormatFound;
     912                 :            : 
     913                 :            :     // analyse format-string concerning predefined formats:
     914 [ #  # ][ #  # ]:          0 :     if( sFormatStrg.EqualsIgnoreCaseAscii( BASICFORMAT_GENERALNUMBER ) )
     915         [ #  # ]:          0 :         sFormatStrg.AssignAscii( GENERALNUMBER_FORMAT );
     916 [ #  # ][ #  # ]:          0 :     if( sFormatStrg.EqualsIgnoreCaseAscii( BASICFORMAT_CURRENCY ) )
     917         [ #  # ]:          0 :         sFormatStrg = sCurrencyFormatStrg; // old: CURRENCY_FORMAT;
     918 [ #  # ][ #  # ]:          0 :     if( sFormatStrg.EqualsIgnoreCaseAscii( BASICFORMAT_FIXED ) )
     919         [ #  # ]:          0 :         sFormatStrg.AssignAscii( FIXED_FORMAT );
     920 [ #  # ][ #  # ]:          0 :     if( sFormatStrg.EqualsIgnoreCaseAscii( BASICFORMAT_STANDARD ) )
     921         [ #  # ]:          0 :         sFormatStrg.AssignAscii( STANDARD_FORMAT );
     922 [ #  # ][ #  # ]:          0 :     if( sFormatStrg.EqualsIgnoreCaseAscii( BASICFORMAT_PERCENT ) )
     923         [ #  # ]:          0 :         sFormatStrg.AssignAscii( PERCENT_FORMAT );
     924 [ #  # ][ #  # ]:          0 :     if( sFormatStrg.EqualsIgnoreCaseAscii( BASICFORMAT_SCIENTIFIC ) )
     925         [ #  # ]:          0 :         sFormatStrg.AssignAscii( SCIENTIFIC_FORMAT );
     926 [ #  # ][ #  # ]:          0 :     if( sFormatStrg.EqualsIgnoreCaseAscii( BASICFORMAT_YESNO ) )
     927 [ #  # ][ #  # ]:          0 :         return ( dNumber==0.0 ) ? sNoStrg : sYesStrg ;
     928 [ #  # ][ #  # ]:          0 :     if( sFormatStrg.EqualsIgnoreCaseAscii( BASICFORMAT_TRUEFALSE ) )
     929 [ #  # ][ #  # ]:          0 :         return ( dNumber==0.0 ) ? sFalseStrg : sTrueStrg ;
     930 [ #  # ][ #  # ]:          0 :     if( sFormatStrg.EqualsIgnoreCaseAscii( BASICFORMAT_ONOFF ) )
     931 [ #  # ][ #  # ]:          0 :         return ( dNumber==0.0 ) ? sOffStrg : sOnStrg ;
     932                 :            : 
     933                 :            :     // analyse format-string concerning ';', i. e. format-strings for
     934                 :            :     // positive-, negative- and 0-values
     935         [ #  # ]:          0 :     String sPosFormatStrg = GetPosFormatString( sFormatStrg, bPosFormatFound );
     936         [ #  # ]:          0 :     String sNegFormatStrg = GetNegFormatString( sFormatStrg, bNegFormatFound );
     937         [ #  # ]:          0 :     String s0FormatStrg = Get0FormatString( sFormatStrg, b0FormatFound );
     938                 :            : 
     939         [ #  # ]:          0 :     String sReturnStrg;
     940         [ #  # ]:          0 :     String sTempStrg;
     941                 :            : 
     942         [ #  # ]:          0 :     if( dNumber==0.0 )
     943                 :            :     {
     944         [ #  # ]:          0 :         sTempStrg = sFormatStrg;
     945         [ #  # ]:          0 :         if( b0FormatFound )
     946                 :            :         {
     947 [ #  # ][ #  # ]:          0 :             if( s0FormatStrg.Len() == 0 && bPosFormatFound )
                 [ #  # ]
     948         [ #  # ]:          0 :                 sTempStrg = sPosFormatStrg;
     949                 :            :             else
     950         [ #  # ]:          0 :                 sTempStrg = s0FormatStrg;
     951                 :            :         }
     952         [ #  # ]:          0 :         else if( bPosFormatFound )
     953                 :            :         {
     954         [ #  # ]:          0 :             sTempStrg = sPosFormatStrg;
     955                 :            :         }
     956         [ #  # ]:          0 :         ScanFormatString( dNumber, sTempStrg, sReturnStrg,/*bCreateSign=*/sal_False );
     957                 :            :     }
     958                 :            :     else
     959                 :            :     {
     960         [ #  # ]:          0 :         if( dNumber<0.0 )
     961                 :            :         {
     962         [ #  # ]:          0 :             if( bNegFormatFound )
     963                 :            :             {
     964 [ #  # ][ #  # ]:          0 :                 if( sNegFormatStrg.Len() == 0 && bPosFormatFound )
                 [ #  # ]
     965                 :            :                 {
     966         [ #  # ]:          0 :                     sTempStrg = rtl::OUString("-");
     967         [ #  # ]:          0 :                     sTempStrg += sPosFormatStrg;
     968                 :            :                 }
     969                 :            :                 else
     970         [ #  # ]:          0 :                     sTempStrg = sNegFormatStrg;
     971                 :            :            }
     972                 :            :             else
     973         [ #  # ]:          0 :                 sTempStrg = sFormatStrg;
     974                 :            :             // if NO format-string especially for negative
     975                 :            :             // values is given, output the leading sign
     976         [ #  # ]:          0 :             ScanFormatString( dNumber, sTempStrg, sReturnStrg,/*bCreateSign=*/bNegFormatFound/*sNegFormatStrg!=EMPTYFORMATSTRING*/ );
     977                 :            :         }
     978                 :            :         else // if( dNumber>0.0 )
     979                 :            :         {
     980                 :            :             ScanFormatString( dNumber,
     981                 :            :                     (/*sPosFormatStrg!=EMPTYFORMATSTRING*/bPosFormatFound ? sPosFormatStrg : sFormatStrg),
     982 [ #  # ][ #  # ]:          0 :                     sReturnStrg,/*bCreateSign=*/sal_False );
     983                 :            :         }
     984                 :            :     }
     985 [ #  # ][ #  # ]:          0 :     return sReturnStrg;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     986                 :            : }
     987                 :            : 
     988                 :          0 : sal_Bool SbxBasicFormater::isBasicFormat( String sFormatStrg )
     989                 :            : {
     990         [ #  # ]:          0 :     if( sFormatStrg.EqualsIgnoreCaseAscii( BASICFORMAT_GENERALNUMBER ) )
     991                 :          0 :         return sal_True;
     992         [ #  # ]:          0 :     if( sFormatStrg.EqualsIgnoreCaseAscii( BASICFORMAT_CURRENCY ) )
     993                 :          0 :         return sal_True;
     994         [ #  # ]:          0 :     if( sFormatStrg.EqualsIgnoreCaseAscii( BASICFORMAT_FIXED ) )
     995                 :          0 :         return sal_True;
     996         [ #  # ]:          0 :     if( sFormatStrg.EqualsIgnoreCaseAscii( BASICFORMAT_STANDARD ) )
     997                 :          0 :         return sal_True;
     998         [ #  # ]:          0 :     if( sFormatStrg.EqualsIgnoreCaseAscii( BASICFORMAT_PERCENT ) )
     999                 :          0 :         return sal_True;
    1000         [ #  # ]:          0 :     if( sFormatStrg.EqualsIgnoreCaseAscii( BASICFORMAT_SCIENTIFIC ) )
    1001                 :          0 :         return sal_True;
    1002         [ #  # ]:          0 :     if( sFormatStrg.EqualsIgnoreCaseAscii( BASICFORMAT_YESNO ) )
    1003                 :          0 :         return sal_True;
    1004         [ #  # ]:          0 :     if( sFormatStrg.EqualsIgnoreCaseAscii( BASICFORMAT_TRUEFALSE ) )
    1005                 :          0 :         return sal_True;
    1006         [ #  # ]:          0 :     if( sFormatStrg.EqualsIgnoreCaseAscii( BASICFORMAT_ONOFF ) )
    1007                 :          0 :         return sal_True;
    1008                 :          0 :     return sal_False;
    1009                 :            : }
    1010                 :            : 
    1011                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10