2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2005-04-13 08:25:31 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 11:19:34 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2005-04-13 08:25:31 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2005-04-13 08:25:31 +00:00
|
|
|
*
|
2008-04-11 11:19:34 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2005-04-13 08:25:31 +00:00
|
|
|
*
|
2008-04-11 11:19:34 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2005-04-13 08:25:31 +00:00
|
|
|
*
|
2008-04-11 11:19:34 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2005-04-13 08:25:31 +00:00
|
|
|
*
|
2008-04-11 11:19:34 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2005-04-13 08:25:31 +00:00
|
|
|
*
|
2008-04-11 11:19:34 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2005-04-13 08:25:31 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#include <tools/errcode.hxx>
|
2007-06-27 13:31:47 +00:00
|
|
|
#include <basic/sbx.hxx>
|
2005-04-13 08:25:31 +00:00
|
|
|
#include "sbxconv.hxx"
|
|
|
|
|
2009-10-16 00:05:16 +02:00
|
|
|
#include "unotools/syslocale.hxx"
|
2005-04-13 08:25:31 +00:00
|
|
|
|
2006-06-19 16:51:12 +00:00
|
|
|
#if defined ( UNX )
|
2005-04-13 08:25:31 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <vcl/svapp.hxx>
|
|
|
|
#include <math.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include "sbxres.hxx"
|
2007-06-27 13:31:47 +00:00
|
|
|
#include <basic/sbxbase.hxx>
|
2012-02-27 16:26:41 +02:00
|
|
|
#include <basic/sbxfac.hxx>
|
2007-06-27 13:31:47 +00:00
|
|
|
#include <basic/sbxform.hxx>
|
2010-04-09 11:05:09 +02:00
|
|
|
#include <svtools/svtools.hrc>
|
2005-04-13 08:25:31 +00:00
|
|
|
|
|
|
|
#include "basrid.hxx"
|
2008-10-28 08:22:18 +00:00
|
|
|
#include "runtime.hxx"
|
2005-04-13 08:25:31 +00:00
|
|
|
|
2011-09-24 00:36:53 +01:00
|
|
|
#include <rtl/strbuf.hxx>
|
2009-10-16 00:05:16 +02:00
|
|
|
#include <svl/zforlist.hxx>
|
2008-01-28 13:01:14 +00:00
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
|
|
|
|
|
2005-04-13 08:25:31 +00:00
|
|
|
void ImpGetIntntlSep( sal_Unicode& rcDecimalSep, sal_Unicode& rcThousandSep )
|
|
|
|
{
|
|
|
|
SvtSysLocale aSysLocale;
|
|
|
|
const LocaleDataWrapper& rData = aSysLocale.GetLocaleData();
|
|
|
|
rcDecimalSep = rData.getNumDecimalSep().GetBuffer()[0];
|
|
|
|
rcThousandSep = rData.getNumThousandSep().GetBuffer()[0];
|
|
|
|
}
|
|
|
|
|
2011-08-27 21:37:14 +02:00
|
|
|
// scanning a string according to BASIC-conventions
|
|
|
|
// but exponent may also be a D, so data type is SbxDOUBLED
|
|
|
|
// conversion error if data type is fixed and it doesn't fit
|
2005-04-13 08:25:31 +00:00
|
|
|
|
2010-08-13 13:28:45 +02:00
|
|
|
SbxError ImpScan( const ::rtl::OUString& rWSrc, double& nVal, SbxDataType& rType,
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_uInt16* pLen, sal_Bool bAllowIntntl, sal_Bool bOnlyIntntl )
|
2005-04-13 08:25:31 +00:00
|
|
|
{
|
2010-08-13 13:28:45 +02:00
|
|
|
::rtl::OString aBStr( ::rtl::OUStringToOString( rWSrc, RTL_TEXTENCODING_ASCII_US ) );
|
2005-04-13 08:25:31 +00:00
|
|
|
|
|
|
|
char cIntntlComma, cIntntl1000;
|
|
|
|
char cNonIntntlComma = '.';
|
|
|
|
|
2006-10-12 13:33:35 +00:00
|
|
|
sal_Unicode cDecimalSep, cThousandSep = 0;
|
2005-04-13 08:25:31 +00:00
|
|
|
if( bAllowIntntl || bOnlyIntntl )
|
|
|
|
{
|
|
|
|
ImpGetIntntlSep( cDecimalSep, cThousandSep );
|
|
|
|
cIntntlComma = (char)cDecimalSep;
|
|
|
|
cIntntl1000 = (char)cThousandSep;
|
|
|
|
}
|
2011-08-27 21:37:14 +02:00
|
|
|
|
2005-04-13 08:25:31 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
cIntntlComma = cNonIntntlComma;
|
2011-08-27 21:37:14 +02:00
|
|
|
cIntntl1000 = cNonIntntlComma;
|
2005-04-13 08:25:31 +00:00
|
|
|
}
|
2011-08-27 21:37:14 +02:00
|
|
|
|
2005-04-13 08:25:31 +00:00
|
|
|
if( bOnlyIntntl )
|
|
|
|
{
|
|
|
|
cNonIntntlComma = cIntntlComma;
|
|
|
|
cIntntl1000 = (char)cThousandSep;
|
|
|
|
}
|
|
|
|
|
2010-08-13 13:28:45 +02:00
|
|
|
const char* pStart = aBStr.getStr();
|
2005-04-13 08:25:31 +00:00
|
|
|
const char* p = pStart;
|
|
|
|
char buf[ 80 ], *q = buf;
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_Bool bRes = sal_True;
|
|
|
|
sal_Bool bMinus = sal_False;
|
2005-04-13 08:25:31 +00:00
|
|
|
nVal = 0;
|
|
|
|
SbxDataType eScanType = SbxSINGLE;
|
|
|
|
while( *p &&( *p == ' ' || *p == '\t' ) ) p++;
|
|
|
|
if( *p == '-' )
|
2011-01-10 14:40:57 +01:00
|
|
|
p++, bMinus = sal_True;
|
2005-04-13 08:25:31 +00:00
|
|
|
if( isdigit( *p ) ||( (*p == cNonIntntlComma || *p == cIntntlComma ||
|
|
|
|
*p == cIntntl1000) && isdigit( *(p+1 ) ) ) )
|
|
|
|
{
|
2011-08-27 21:37:14 +02:00
|
|
|
short exp = 0;
|
|
|
|
short comma = 0;
|
|
|
|
short ndig = 0;
|
|
|
|
short ncdig = 0; // number of digits after decimal point
|
2011-09-24 00:36:53 +01:00
|
|
|
rtl::OStringBuffer aSearchStr(RTL_CONSTASCII_STRINGPARAM("0123456789DEde"));
|
|
|
|
aSearchStr.append(cNonIntntlComma);
|
2005-04-13 08:25:31 +00:00
|
|
|
if( cIntntlComma != cNonIntntlComma )
|
2011-09-24 00:36:53 +01:00
|
|
|
aSearchStr.append(cIntntlComma);
|
2005-04-13 08:25:31 +00:00
|
|
|
if( bOnlyIntntl )
|
2011-09-24 00:36:53 +01:00
|
|
|
aSearchStr.append(cIntntl1000);
|
|
|
|
const char* pSearchStr = aSearchStr.getStr();
|
2005-04-13 08:25:31 +00:00
|
|
|
while( strchr( pSearchStr, *p ) && *p )
|
|
|
|
{
|
|
|
|
if( bOnlyIntntl && *p == cIntntl1000 )
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( *p == cNonIntntlComma || *p == cIntntlComma )
|
|
|
|
{
|
2011-08-27 21:37:14 +02:00
|
|
|
// always insert '.' so that atof works
|
2005-04-13 08:25:31 +00:00
|
|
|
p++;
|
|
|
|
if( ++comma > 1 )
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
*q++ = '.';
|
|
|
|
}
|
|
|
|
else if( strchr( "DdEe", *p ) )
|
|
|
|
{
|
|
|
|
if( ++exp > 1 )
|
|
|
|
{
|
|
|
|
p++; continue;
|
|
|
|
}
|
|
|
|
if( toupper( *p ) == 'D' )
|
|
|
|
eScanType = SbxDOUBLE;
|
|
|
|
*q++ = 'E'; p++;
|
2011-08-27 21:37:14 +02:00
|
|
|
|
2005-04-13 08:25:31 +00:00
|
|
|
if( *p == '+' )
|
|
|
|
p++;
|
|
|
|
else
|
|
|
|
if( *p == '-' )
|
|
|
|
*q++ = *p++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*q++ = *p++;
|
|
|
|
if( comma && !exp ) ncdig++;
|
|
|
|
}
|
|
|
|
if( !exp ) ndig++;
|
|
|
|
}
|
|
|
|
*q = 0;
|
2011-08-27 21:37:14 +02:00
|
|
|
|
2005-04-13 08:25:31 +00:00
|
|
|
if( comma > 1 || exp > 1 )
|
2011-01-10 14:40:57 +01:00
|
|
|
bRes = sal_False;
|
2011-08-27 21:37:14 +02:00
|
|
|
|
2005-04-13 08:25:31 +00:00
|
|
|
if( !comma && !exp )
|
|
|
|
{
|
|
|
|
if( nVal >= SbxMININT && nVal <= SbxMAXINT )
|
|
|
|
eScanType = SbxINTEGER;
|
|
|
|
else if( nVal >= SbxMINLNG && nVal <= SbxMAXLNG )
|
|
|
|
eScanType = SbxLONG;
|
|
|
|
}
|
|
|
|
|
|
|
|
nVal = atof( buf );
|
2006-10-12 13:33:35 +00:00
|
|
|
ndig = ndig - comma;
|
2011-08-27 21:37:14 +02:00
|
|
|
// too many numbers for SINGLE?
|
2005-04-13 08:25:31 +00:00
|
|
|
if( ndig > 15 || ncdig > 6 )
|
|
|
|
eScanType = SbxDOUBLE;
|
|
|
|
|
2011-08-27 21:37:14 +02:00
|
|
|
// type detection?
|
2005-04-13 08:25:31 +00:00
|
|
|
if( strchr( "%!&#", *p ) && *p ) p++;
|
|
|
|
}
|
2011-08-27 21:37:14 +02:00
|
|
|
// hex/octal number? read in and convert:
|
2005-04-13 08:25:31 +00:00
|
|
|
else if( *p == '&' )
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
eScanType = SbxLONG;
|
|
|
|
const char *cmp = "0123456789ABCDEF";
|
|
|
|
char base = 16;
|
|
|
|
char ndig = 8;
|
|
|
|
char xch = *p++;
|
|
|
|
switch( toupper( xch ) )
|
|
|
|
{
|
|
|
|
case 'O': cmp = "01234567"; base = 8; ndig = 11; break;
|
|
|
|
case 'H': break;
|
2011-01-10 14:40:57 +01:00
|
|
|
default : bRes = sal_False;
|
2005-04-13 08:25:31 +00:00
|
|
|
}
|
|
|
|
long l = 0;
|
|
|
|
int i;
|
|
|
|
while( isalnum( *p ) )
|
|
|
|
{
|
2006-10-12 13:33:35 +00:00
|
|
|
char ch = sal::static_int_cast< char >( toupper( *p ) );
|
2005-04-13 08:25:31 +00:00
|
|
|
p++;
|
|
|
|
if( strchr( cmp, ch ) ) *q++ = ch;
|
2011-01-10 14:40:57 +01:00
|
|
|
else bRes = sal_False;
|
2005-04-13 08:25:31 +00:00
|
|
|
}
|
|
|
|
*q = 0;
|
|
|
|
for( q = buf; *q; q++ )
|
|
|
|
{
|
|
|
|
i =( *q & 0xFF ) - '0';
|
|
|
|
if( i > 9 ) i -= 7;
|
|
|
|
l =( l * base ) + i;
|
|
|
|
if( !ndig-- )
|
2011-01-10 14:40:57 +01:00
|
|
|
bRes = sal_False;
|
2005-04-13 08:25:31 +00:00
|
|
|
}
|
|
|
|
if( *p == '&' ) p++;
|
|
|
|
nVal = (double) l;
|
|
|
|
if( l >= SbxMININT && l <= SbxMAXINT )
|
|
|
|
eScanType = SbxINTEGER;
|
|
|
|
}
|
2012-03-05 21:41:31 +02:00
|
|
|
#ifndef DISABLE_SCRIPTING
|
2008-10-28 08:22:18 +00:00
|
|
|
else if ( SbiRuntime::isVBAEnabled() )
|
|
|
|
{
|
|
|
|
OSL_TRACE("Reporting error converting");
|
|
|
|
return SbxERR_CONVERSION;
|
|
|
|
}
|
2012-03-05 21:41:31 +02:00
|
|
|
#endif
|
2005-04-13 08:25:31 +00:00
|
|
|
if( pLen )
|
2011-01-10 14:40:57 +01:00
|
|
|
*pLen = (sal_uInt16) ( p - pStart );
|
2005-04-13 08:25:31 +00:00
|
|
|
if( !bRes )
|
|
|
|
return SbxERR_CONVERSION;
|
|
|
|
if( bMinus )
|
|
|
|
nVal = -nVal;
|
|
|
|
rType = eScanType;
|
|
|
|
return SbxERR_OK;
|
|
|
|
}
|
|
|
|
|
2011-08-27 21:37:14 +02:00
|
|
|
// port for CDbl in the Basic
|
2011-01-10 14:40:57 +01:00
|
|
|
SbxError SbxValue::ScanNumIntnl( const String& rSrc, double& nVal, sal_Bool bSingle )
|
2005-04-13 08:25:31 +00:00
|
|
|
{
|
|
|
|
SbxDataType t;
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_uInt16 nLen = 0;
|
2005-04-13 08:25:31 +00:00
|
|
|
SbxError nRetError = ImpScan( rSrc, nVal, t, &nLen,
|
2011-01-10 14:40:57 +01:00
|
|
|
/*bAllowIntntl*/sal_False, /*bOnlyIntntl*/sal_True );
|
2011-08-27 21:37:14 +02:00
|
|
|
// read completely?
|
2005-04-13 08:25:31 +00:00
|
|
|
if( nRetError == SbxERR_OK && nLen != rSrc.Len() )
|
|
|
|
nRetError = SbxERR_CONVERSION;
|
|
|
|
|
|
|
|
if( bSingle )
|
|
|
|
{
|
|
|
|
SbxValues aValues( nVal );
|
2011-08-27 21:37:14 +02:00
|
|
|
nVal = (double)ImpGetSingle( &aValues ); // here error at overflow
|
2005-04-13 08:25:31 +00:00
|
|
|
}
|
|
|
|
return nRetError;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static double roundArray[] = {
|
|
|
|
5.0e+0, 0.5e+0, 0.5e-1, 0.5e-2, 0.5e-3, 0.5e-4, 0.5e-5, 0.5e-6, 0.5e-7,
|
|
|
|
0.5e-8, 0.5e-9, 0.5e-10,0.5e-11,0.5e-12,0.5e-13,0.5e-14,0.5e-15 };
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
|*
|
2011-01-10 14:40:57 +01:00
|
|
|
|* void myftoa( double, char *, short, short, sal_Bool, sal_Bool )
|
2005-04-13 08:25:31 +00:00
|
|
|
|*
|
2011-08-27 21:37:14 +02:00
|
|
|
|* description: conversion double --> ASCII
|
|
|
|
|* parameters: double the number
|
|
|
|
|* char * target buffer
|
|
|
|
|* short number of positions after decimal point
|
|
|
|
|* short range of the exponent ( 0=no E )
|
|
|
|
|* sal_Bool sal_True: with 1000-separators
|
|
|
|
|* sal_Bool sal_True: output without formatting
|
2005-04-13 08:25:31 +00:00
|
|
|
|*
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
static void myftoa( double nNum, char * pBuf, short nPrec, short nExpWidth,
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_Bool bPt, sal_Bool bFix, sal_Unicode cForceThousandSep = 0 )
|
2005-04-13 08:25:31 +00:00
|
|
|
{
|
|
|
|
|
2011-08-27 21:37:14 +02:00
|
|
|
short nExp = 0;
|
|
|
|
short nDig = nPrec + 1;
|
|
|
|
short nDec; // number of positions before decimal point
|
2011-02-10 14:48:51 +01:00
|
|
|
register int i;
|
2005-04-13 08:25:31 +00:00
|
|
|
|
|
|
|
sal_Unicode cDecimalSep, cThousandSep;
|
|
|
|
ImpGetIntntlSep( cDecimalSep, cThousandSep );
|
|
|
|
if( cForceThousandSep )
|
|
|
|
cThousandSep = cForceThousandSep;
|
|
|
|
|
2011-08-27 21:37:14 +02:00
|
|
|
// compute exponent
|
2005-04-13 08:25:31 +00:00
|
|
|
nExp = 0;
|
|
|
|
if( nNum > 0.0 )
|
|
|
|
{
|
|
|
|
while( nNum < 1.0 ) nNum *= 10.0, nExp--;
|
|
|
|
while( nNum >= 10.0 ) nNum /= 10.0, nExp++;
|
|
|
|
}
|
|
|
|
if( !bFix && !nExpWidth )
|
2006-10-12 13:33:35 +00:00
|
|
|
nDig = nDig + nExp;
|
2005-04-13 08:25:31 +00:00
|
|
|
else if( bFix && !nPrec )
|
|
|
|
nDig = nExp + 1;
|
|
|
|
|
2011-08-27 21:37:14 +02:00
|
|
|
// round number
|
2005-04-13 08:25:31 +00:00
|
|
|
if( (nNum += roundArray [( nDig > 16 ) ? 16 : nDig] ) >= 10.0 )
|
|
|
|
{
|
|
|
|
nNum = 1.0;
|
|
|
|
++nExp;
|
|
|
|
if( !nExpWidth ) ++nDig;
|
|
|
|
}
|
|
|
|
|
2011-08-27 21:37:14 +02:00
|
|
|
// determine positions before decimal point
|
2005-04-13 08:25:31 +00:00
|
|
|
if( !nExpWidth )
|
|
|
|
{
|
|
|
|
if( nExp < 0 )
|
|
|
|
{
|
2011-08-27 21:37:14 +02:00
|
|
|
// #41691: also a 0 at bFix
|
2005-04-13 08:25:31 +00:00
|
|
|
*pBuf++ = '0';
|
|
|
|
if( nPrec ) *pBuf++ = (char)cDecimalSep;
|
|
|
|
i = -nExp - 1;
|
|
|
|
if( nDig <= 0 ) i = nPrec;
|
|
|
|
while( i-- ) *pBuf++ = '0';
|
|
|
|
nDec = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nDec = nExp+1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nDec = 1;
|
|
|
|
|
2011-08-27 21:37:14 +02:00
|
|
|
// output number
|
2005-04-13 08:25:31 +00:00
|
|
|
if( nDig > 0 )
|
|
|
|
{
|
2011-02-10 14:48:51 +01:00
|
|
|
register int digit;
|
2005-04-13 08:25:31 +00:00
|
|
|
for( i = 0 ; ; ++i )
|
|
|
|
{
|
|
|
|
if( i < 16 )
|
|
|
|
{
|
|
|
|
digit = (int) nNum;
|
2006-10-12 13:33:35 +00:00
|
|
|
*pBuf++ = sal::static_int_cast< char >(digit + '0');
|
2005-04-13 08:25:31 +00:00
|
|
|
nNum =( nNum - digit ) * 10.0;
|
|
|
|
} else
|
|
|
|
*pBuf++ = '0';
|
|
|
|
if( --nDig == 0 ) break;
|
|
|
|
if( nDec )
|
|
|
|
{
|
|
|
|
nDec--;
|
|
|
|
if( !nDec )
|
|
|
|
*pBuf++ = (char)cDecimalSep;
|
|
|
|
else if( !(nDec % 3 ) && bPt )
|
|
|
|
*pBuf++ = (char)cThousandSep;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-27 21:37:14 +02:00
|
|
|
// output exponent
|
2005-04-13 08:25:31 +00:00
|
|
|
if( nExpWidth )
|
|
|
|
{
|
|
|
|
if( nExpWidth < 3 ) nExpWidth = 3;
|
|
|
|
nExpWidth -= 2;
|
|
|
|
*pBuf++ = 'E';
|
|
|
|
*pBuf++ =( nExp < 0 ) ?( (nExp = -nExp ), '-' ) : '+';
|
|
|
|
while( nExpWidth > 3 ) *pBuf++ = '0', nExpWidth--;
|
|
|
|
if( nExp >= 100 || nExpWidth == 3 )
|
|
|
|
{
|
2006-10-12 13:33:35 +00:00
|
|
|
*pBuf++ = sal::static_int_cast< char >(nExp/100 + '0');
|
2005-04-13 08:25:31 +00:00
|
|
|
nExp %= 100;
|
|
|
|
}
|
|
|
|
if( nExp/10 || nExpWidth >= 2 )
|
2006-10-12 13:33:35 +00:00
|
|
|
*pBuf++ = sal::static_int_cast< char >(nExp/10 + '0');
|
|
|
|
*pBuf++ = sal::static_int_cast< char >(nExp%10 + '0');
|
2005-04-13 08:25:31 +00:00
|
|
|
}
|
|
|
|
*pBuf = 0;
|
|
|
|
}
|
|
|
|
|
2011-08-27 21:37:14 +02:00
|
|
|
// The number is prepared unformattedly with the given number of
|
|
|
|
// NK-positions. A leading minus is added if applicable.
|
|
|
|
// This routine is public because it's also used by the Put-functions
|
|
|
|
// in the class SbxImpSTRING.
|
2005-04-13 08:25:31 +00:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma optimize( "", off )
|
2007-11-13 14:23:45 +00:00
|
|
|
#pragma warning(disable: 4748) // "... because optimizations are disabled ..."
|
2005-04-13 08:25:31 +00:00
|
|
|
#endif
|
|
|
|
|
2011-01-10 14:40:57 +01:00
|
|
|
void ImpCvtNum( double nNum, short nPrec, ::rtl::OUString& rRes, sal_Bool bCoreString )
|
2005-04-13 08:25:31 +00:00
|
|
|
{
|
|
|
|
char *q;
|
|
|
|
char cBuf[ 40 ], *p = cBuf;
|
|
|
|
|
|
|
|
sal_Unicode cDecimalSep, cThousandSep;
|
|
|
|
ImpGetIntntlSep( cDecimalSep, cThousandSep );
|
|
|
|
if( bCoreString )
|
|
|
|
cDecimalSep = '.';
|
|
|
|
|
|
|
|
if( nNum < 0.0 ) {
|
|
|
|
nNum = -nNum;
|
|
|
|
*p++ = '-';
|
|
|
|
}
|
|
|
|
double dMaxNumWithoutExp = (nPrec == 6) ? 1E6 : 1E14;
|
2010-11-03 22:08:26 -06:00
|
|
|
myftoa( nNum, p, nPrec,( nNum &&( nNum < 1E-1 || nNum >= dMaxNumWithoutExp ) ) ? 4:0,
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_False, sal_True, cDecimalSep );
|
2011-08-27 21:37:14 +02:00
|
|
|
// remove trailing zeros
|
2005-04-13 08:25:31 +00:00
|
|
|
for( p = cBuf; *p &&( *p != 'E' ); p++ ) {}
|
|
|
|
q = p; p--;
|
|
|
|
while( nPrec && *p == '0' ) nPrec--, p--;
|
|
|
|
if( *p == cDecimalSep ) p--;
|
|
|
|
while( *q ) *++p = *q++;
|
|
|
|
*++p = 0;
|
2010-08-13 13:28:45 +02:00
|
|
|
rRes = ::rtl::OUString::createFromAscii( cBuf );
|
2005-04-13 08:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma optimize( "", on )
|
|
|
|
#endif
|
|
|
|
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_Bool ImpConvStringExt( ::rtl::OUString& rSrc, SbxDataType eTargetType )
|
2005-04-13 08:25:31 +00:00
|
|
|
{
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_Bool bChanged = sal_False;
|
2010-08-13 13:28:45 +02:00
|
|
|
::rtl::OUString aNewString;
|
2005-04-13 08:25:31 +00:00
|
|
|
|
2011-08-27 21:37:14 +02:00
|
|
|
// only special cases are handled, nothing on default
|
2005-04-13 08:25:31 +00:00
|
|
|
switch( eTargetType )
|
|
|
|
{
|
2011-08-27 21:37:14 +02:00
|
|
|
// consider international for floating point
|
2005-04-13 08:25:31 +00:00
|
|
|
case SbxSINGLE:
|
|
|
|
case SbxDOUBLE:
|
|
|
|
case SbxCURRENCY:
|
|
|
|
{
|
2010-08-13 13:28:45 +02:00
|
|
|
::rtl::OString aBStr( ::rtl::OUStringToOString( rSrc, RTL_TEXTENCODING_ASCII_US ) );
|
2005-04-13 08:25:31 +00:00
|
|
|
|
|
|
|
sal_Unicode cDecimalSep, cThousandSep;
|
|
|
|
ImpGetIntntlSep( cDecimalSep, cThousandSep );
|
|
|
|
aNewString = rSrc;
|
|
|
|
|
|
|
|
if( cDecimalSep != (sal_Unicode)'.' )
|
|
|
|
{
|
2010-08-13 13:28:45 +02:00
|
|
|
sal_Int32 nPos = aNewString.indexOf( cDecimalSep );
|
|
|
|
if( nPos != -1 )
|
2005-04-13 08:25:31 +00:00
|
|
|
{
|
2010-08-13 13:28:45 +02:00
|
|
|
sal_Unicode* pStr = (sal_Unicode*)aNewString.getStr();
|
|
|
|
pStr[nPos] = (sal_Unicode)'.';
|
2011-01-10 14:40:57 +01:00
|
|
|
bChanged = sal_True;
|
2005-04-13 08:25:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-08-27 21:37:14 +02:00
|
|
|
// check as string in case of sal_Bool sal_True and sal_False
|
2005-04-13 08:25:31 +00:00
|
|
|
case SbxBOOL:
|
|
|
|
{
|
2012-02-18 23:18:57 +09:00
|
|
|
if( rSrc.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("true")) )
|
2005-04-13 08:25:31 +00:00
|
|
|
{
|
2010-08-13 13:28:45 +02:00
|
|
|
aNewString = ::rtl::OUString::valueOf( (sal_Int32)SbxTRUE );
|
2011-01-10 14:40:57 +01:00
|
|
|
bChanged = sal_True;
|
2005-04-13 08:25:31 +00:00
|
|
|
}
|
|
|
|
else
|
2012-02-18 23:18:57 +09:00
|
|
|
if( rSrc.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("false")) )
|
2005-04-13 08:25:31 +00:00
|
|
|
{
|
2010-08-13 13:28:45 +02:00
|
|
|
aNewString = ::rtl::OUString::valueOf( (sal_Int32)SbxFALSE );
|
2011-01-10 14:40:57 +01:00
|
|
|
bChanged = sal_True;
|
2005-04-13 08:25:31 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-06-19 16:51:12 +00:00
|
|
|
default: break;
|
2005-04-13 08:25:31 +00:00
|
|
|
}
|
2011-08-27 21:37:14 +02:00
|
|
|
|
2005-04-13 08:25:31 +00:00
|
|
|
if( bChanged )
|
|
|
|
rSrc = aNewString;
|
|
|
|
return bChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-27 21:37:14 +02:00
|
|
|
// formatted number output
|
|
|
|
// the return value is the number of characters used
|
|
|
|
// from the format
|
2005-04-13 08:25:31 +00:00
|
|
|
|
|
|
|
#ifdef _old_format_code_
|
2011-08-27 21:37:14 +02:00
|
|
|
// leave the code provisionally to copy the previous implementation
|
2005-04-13 08:25:31 +00:00
|
|
|
|
2011-01-10 14:40:57 +01:00
|
|
|
static sal_uInt16 printfmtnum( double nNum, XubString& rRes, const XubString& rWFmt )
|
2005-04-13 08:25:31 +00:00
|
|
|
{
|
|
|
|
const String& rFmt = rWFmt;
|
2011-08-27 21:37:14 +02:00
|
|
|
char cFill = ' '; // filling characters
|
|
|
|
char cPre = 0; // start character ( maybe "$" )
|
|
|
|
short nExpDig= 0; // number of exponent positions
|
|
|
|
short nPrec = 0; // number of positions after decimal point
|
|
|
|
short nWidth = 0; // number range completely
|
|
|
|
short nLen; // length of converted number
|
|
|
|
sal_Bool bPoint = sal_False; // sal_True: with 1000 seperators
|
|
|
|
sal_Bool bTrail = sal_False; // sal_True, if following minus
|
|
|
|
sal_Bool bSign = sal_False; // sal_True: always with leading sign
|
|
|
|
sal_Bool bNeg = sal_False; // sal_True: number is negative
|
|
|
|
char cBuf [1024]; // number buffer
|
2005-04-13 08:25:31 +00:00
|
|
|
char * p;
|
|
|
|
const char* pFmt = rFmt;
|
|
|
|
rRes.Erase();
|
2011-08-27 21:37:14 +02:00
|
|
|
// catch $$ and **, is simply output as character
|
2005-04-13 08:25:31 +00:00
|
|
|
if( *pFmt == '$' )
|
|
|
|
if( *++pFmt != '$' ) rRes += '$';
|
|
|
|
if( *pFmt == '*' )
|
|
|
|
if( *++pFmt != '*' ) rRes += '*';
|
|
|
|
|
|
|
|
switch( *pFmt++ )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case '+':
|
2011-01-10 14:40:57 +01:00
|
|
|
bSign = sal_True; nWidth++; break;
|
2005-04-13 08:25:31 +00:00
|
|
|
case '*':
|
|
|
|
nWidth++; cFill = '*';
|
|
|
|
if( *pFmt == '$' ) nWidth++, pFmt++, cPre = '$';
|
|
|
|
break;
|
|
|
|
case '$':
|
|
|
|
nWidth++; cPre = '$'; break;
|
|
|
|
case '#':
|
|
|
|
case '.':
|
|
|
|
case ',':
|
|
|
|
pFmt--; break;
|
|
|
|
}
|
2011-08-27 21:37:14 +02:00
|
|
|
// pre point
|
2005-04-13 08:25:31 +00:00
|
|
|
for( ;; )
|
|
|
|
{
|
|
|
|
while( *pFmt == '#' ) pFmt++, nWidth++;
|
2011-08-27 21:37:14 +02:00
|
|
|
// 1000 separators?
|
2005-04-13 08:25:31 +00:00
|
|
|
if( *pFmt == ',' )
|
|
|
|
{
|
2011-01-10 14:40:57 +01:00
|
|
|
nWidth++; pFmt++; bPoint = sal_True;
|
2005-04-13 08:25:31 +00:00
|
|
|
} else break;
|
|
|
|
}
|
2011-08-27 21:37:14 +02:00
|
|
|
// after point
|
2005-04-13 08:25:31 +00:00
|
|
|
if( *pFmt == '.' )
|
|
|
|
{
|
|
|
|
while( *++pFmt == '#' ) nPrec++;
|
|
|
|
nWidth += nPrec + 1;
|
|
|
|
}
|
2011-08-27 21:37:14 +02:00
|
|
|
// exponent
|
2005-04-13 08:25:31 +00:00
|
|
|
while( *pFmt == '^' )
|
|
|
|
pFmt++, nExpDig++, nWidth++;
|
2011-08-27 21:37:14 +02:00
|
|
|
// following minus
|
2005-04-13 08:25:31 +00:00
|
|
|
if( !bSign && *pFmt == '-' )
|
2011-01-10 14:40:57 +01:00
|
|
|
pFmt++, bTrail = sal_True;
|
2005-04-13 08:25:31 +00:00
|
|
|
|
2011-08-27 21:37:14 +02:00
|
|
|
// convert number
|
2005-04-13 08:25:31 +00:00
|
|
|
if( nPrec > 15 ) nPrec = 15;
|
2011-01-10 14:40:57 +01:00
|
|
|
if( nNum < 0.0 ) nNum = -nNum, bNeg = sal_True;
|
2005-04-13 08:25:31 +00:00
|
|
|
p = cBuf;
|
|
|
|
if( bSign ) *p++ = bNeg ? '-' : '+';
|
2011-01-10 14:40:57 +01:00
|
|
|
myftoa( nNum, p, nPrec, nExpDig, bPoint, sal_False );
|
2005-04-13 08:25:31 +00:00
|
|
|
nLen = strlen( cBuf );
|
|
|
|
|
2011-08-27 21:37:14 +02:00
|
|
|
// overflow?
|
2005-04-13 08:25:31 +00:00
|
|
|
if( cPre ) nLen++;
|
|
|
|
if( nLen > nWidth ) rRes += '%';
|
|
|
|
else {
|
|
|
|
nWidth -= nLen;
|
|
|
|
while( nWidth-- ) rRes += (xub_Unicode)cFill;
|
|
|
|
if( cPre ) rRes += (xub_Unicode)cPre;
|
|
|
|
}
|
|
|
|
rRes += (xub_Unicode*)&(cBuf[0]);
|
|
|
|
if( bTrail )
|
|
|
|
rRes += bNeg ? '-' : ' ';
|
|
|
|
|
2011-01-10 14:40:57 +01:00
|
|
|
return (sal_uInt16) ( pFmt - (const char*) rFmt );
|
2005-04-13 08:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif //_old_format_code_
|
|
|
|
|
2011-01-10 14:40:57 +01:00
|
|
|
static sal_uInt16 printfmtstr( const XubString& rStr, XubString& rRes, const XubString& rFmt )
|
2005-04-13 08:25:31 +00:00
|
|
|
{
|
|
|
|
const xub_Unicode* pStr = rStr.GetBuffer();
|
|
|
|
const xub_Unicode* pFmtStart = rFmt.GetBuffer();
|
|
|
|
const xub_Unicode* pFmt = pFmtStart;
|
|
|
|
rRes.Erase();
|
|
|
|
switch( *pFmt )
|
|
|
|
{
|
|
|
|
case '!':
|
|
|
|
rRes += *pStr++; pFmt++; break;
|
|
|
|
case '\\':
|
|
|
|
do
|
|
|
|
{
|
|
|
|
rRes += *pStr ? *pStr++ : static_cast< xub_Unicode >(' ');
|
|
|
|
pFmt++;
|
|
|
|
} while( *pFmt != '\\' );
|
|
|
|
rRes += *pStr ? *pStr++ : static_cast< xub_Unicode >(' ');
|
|
|
|
pFmt++; break;
|
|
|
|
case '&':
|
|
|
|
rRes = rStr;
|
|
|
|
pFmt++; break;
|
|
|
|
default:
|
|
|
|
rRes = rStr;
|
|
|
|
break;
|
|
|
|
}
|
2011-01-10 14:40:57 +01:00
|
|
|
return (sal_uInt16) ( pFmt - pFmtStart );
|
2005-04-13 08:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_Bool SbxValue::Scan( const XubString& rSrc, sal_uInt16* pLen )
|
2005-04-13 08:25:31 +00:00
|
|
|
{
|
|
|
|
SbxError eRes = SbxERR_OK;
|
|
|
|
if( !CanWrite() )
|
|
|
|
eRes = SbxERR_PROP_READONLY;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
double n;
|
|
|
|
SbxDataType t;
|
|
|
|
eRes = ImpScan( rSrc, n, t, pLen );
|
|
|
|
if( eRes == SbxERR_OK )
|
|
|
|
{
|
|
|
|
if( !IsFixed() )
|
|
|
|
SetType( t );
|
|
|
|
PutDouble( n );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( eRes )
|
|
|
|
{
|
2011-01-10 14:40:57 +01:00
|
|
|
SetError( eRes ); return sal_False;
|
2005-04-13 08:25:31 +00:00
|
|
|
}
|
|
|
|
else
|
2011-01-10 14:40:57 +01:00
|
|
|
return sal_True;
|
2005-04-13 08:25:31 +00:00
|
|
|
}
|
|
|
|
|
2005-09-29 17:42:37 +00:00
|
|
|
|
|
|
|
ResMgr* implGetResMgr( void )
|
|
|
|
{
|
|
|
|
static ResMgr* pResMgr = NULL;
|
|
|
|
if( !pResMgr )
|
|
|
|
{
|
|
|
|
::com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILocale();
|
2012-02-23 17:01:23 +01:00
|
|
|
pResMgr = ResMgr::CreateResMgr("sb", aLocale );
|
2005-09-29 17:42:37 +00:00
|
|
|
}
|
|
|
|
return pResMgr;
|
|
|
|
}
|
|
|
|
|
|
|
|
class SbxValueFormatResId : public ResId
|
|
|
|
{
|
|
|
|
public:
|
2011-01-10 14:40:57 +01:00
|
|
|
SbxValueFormatResId( sal_uInt16 nId )
|
2007-04-26 07:33:49 +00:00
|
|
|
: ResId( nId, *implGetResMgr() )
|
2005-09-29 17:42:37 +00:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-02 09:04:30 +00:00
|
|
|
enum VbaFormatType
|
|
|
|
{
|
|
|
|
VBA_FORMAT_TYPE_OFFSET, // standard number format
|
|
|
|
VBA_FORMAT_TYPE_USERDEFINED, // user defined number format
|
|
|
|
VBA_FORMAT_TYPE_NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VbaFormatInfo
|
|
|
|
{
|
|
|
|
VbaFormatType meType;
|
|
|
|
const char* mpVbaFormat; // Format string in vba
|
|
|
|
NfIndexTableOffset meOffset; // SvNumberFormatter format index, if meType = VBA_FORMAT_TYPE_OFFSET
|
|
|
|
const char* mpOOoFormat; // if meType = VBA_FORMAT_TYPE_USERDEFINED
|
|
|
|
};
|
|
|
|
|
|
|
|
#define VBA_FORMAT_OFFSET( pcUtf8, eOffset ) \
|
|
|
|
{ VBA_FORMAT_TYPE_OFFSET, pcUtf8, eOffset, 0 }
|
|
|
|
|
|
|
|
#define VBA_FORMAT_USERDEFINED( pcUtf8, pcDefinedUtf8 ) \
|
|
|
|
{ VBA_FORMAT_TYPE_USERDEFINED, pcUtf8, NF_NUMBER_STANDARD, pcDefinedUtf8 }
|
|
|
|
|
|
|
|
static VbaFormatInfo pFormatInfoTable[] =
|
|
|
|
{
|
|
|
|
VBA_FORMAT_OFFSET( "Long Date", NF_DATE_SYSTEM_LONG ),
|
|
|
|
VBA_FORMAT_USERDEFINED( "Medium Date", "DD-MMM-YY" ),
|
|
|
|
VBA_FORMAT_OFFSET( "Short Date", NF_DATE_SYSTEM_SHORT ),
|
|
|
|
VBA_FORMAT_USERDEFINED( "Long Time", "H:MM:SS AM/PM" ),
|
|
|
|
VBA_FORMAT_OFFSET( "Medium Time", NF_TIME_HHMMAMPM ),
|
|
|
|
VBA_FORMAT_OFFSET( "Short Time", NF_TIME_HHMM ),
|
|
|
|
VBA_FORMAT_OFFSET( "ddddd", NF_DATE_SYSTEM_SHORT ),
|
|
|
|
VBA_FORMAT_OFFSET( "dddddd", NF_DATE_SYSTEM_LONG ),
|
|
|
|
VBA_FORMAT_USERDEFINED( "ttttt", "H:MM:SS AM/PM" ),
|
|
|
|
VBA_FORMAT_OFFSET( "ww", NF_DATE_WW ),
|
|
|
|
{ VBA_FORMAT_TYPE_NULL, 0, NF_INDEX_TABLE_ENTRIES, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
VbaFormatInfo* getFormatInfo( const String& rFmt )
|
|
|
|
{
|
|
|
|
VbaFormatInfo* pInfo = NULL;
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_Int16 i = 0;
|
2008-07-02 09:04:30 +00:00
|
|
|
while( (pInfo = pFormatInfoTable + i )->mpVbaFormat != NULL )
|
|
|
|
{
|
|
|
|
if( rFmt.EqualsIgnoreCaseAscii( pInfo->mpVbaFormat ) )
|
|
|
|
break;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return pInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define VBAFORMAT_GENERALDATE "General Date"
|
|
|
|
#define VBAFORMAT_C "c"
|
|
|
|
#define VBAFORMAT_N "n"
|
|
|
|
#define VBAFORMAT_NN "nn"
|
|
|
|
#define VBAFORMAT_W "w"
|
|
|
|
#define VBAFORMAT_Y "y"
|
|
|
|
#define VBAFORMAT_LOWERCASE "<"
|
|
|
|
#define VBAFORMAT_UPPERCASE ">"
|
|
|
|
|
|
|
|
// From methods1.cxx
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_Int16 implGetWeekDay( double aDate, bool bFirstDayParam = false, sal_Int16 nFirstDay = 0 );
|
2008-07-02 09:04:30 +00:00
|
|
|
// from methods.cxx
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_Int16 implGetMinute( double dDate );
|
|
|
|
sal_Int16 implGetDateYear( double aDate );
|
|
|
|
sal_Bool implDateSerial( sal_Int16 nYear, sal_Int16 nMonth, sal_Int16 nDay, double& rdRet );
|
2008-07-02 09:04:30 +00:00
|
|
|
|
2005-04-13 08:25:31 +00:00
|
|
|
void SbxValue::Format( XubString& rRes, const XubString* pFmt ) const
|
|
|
|
{
|
2006-06-19 16:51:12 +00:00
|
|
|
short nComma = 0;
|
2006-10-12 13:33:35 +00:00
|
|
|
double d = 0;
|
2008-01-28 13:01:14 +00:00
|
|
|
|
2008-07-02 09:04:30 +00:00
|
|
|
// pflin, It is better to use SvNumberFormatter to handle the date/time/number format.
|
|
|
|
// the SvNumberFormatter output is mostly compatible with
|
|
|
|
// VBA output besides the OOo-basic output
|
2008-01-28 13:01:14 +00:00
|
|
|
if( pFmt && !SbxBasicFormater::isBasicFormat( *pFmt ) )
|
|
|
|
{
|
2008-07-02 09:04:30 +00:00
|
|
|
String aStr = GetString();
|
|
|
|
|
|
|
|
if( pFmt->EqualsIgnoreCaseAscii( VBAFORMAT_LOWERCASE ) )
|
|
|
|
{
|
|
|
|
rRes = aStr.ToLowerAscii();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if( pFmt->EqualsIgnoreCaseAscii( VBAFORMAT_UPPERCASE ) )
|
|
|
|
{
|
|
|
|
rRes = aStr.ToUpperAscii();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-28 13:01:14 +00:00
|
|
|
LanguageType eLangType = GetpApp()->GetSettings().GetLanguage();
|
|
|
|
com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >
|
|
|
|
xFactory = comphelper::getProcessServiceFactory();
|
|
|
|
SvNumberFormatter aFormatter( xFactory, eLangType );
|
|
|
|
|
|
|
|
sal_uInt32 nIndex;
|
2008-07-02 09:04:30 +00:00
|
|
|
double nNumber;
|
|
|
|
Color* pCol;
|
|
|
|
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_Bool bSuccess = aFormatter.IsNumberFormat( aStr, nIndex, nNumber );
|
2008-01-28 13:01:14 +00:00
|
|
|
|
2008-07-02 09:04:30 +00:00
|
|
|
// number format, use SvNumberFormatter to handle it.
|
|
|
|
if( bSuccess )
|
2008-01-28 13:01:14 +00:00
|
|
|
{
|
2011-02-10 14:48:51 +01:00
|
|
|
xub_StrLen nCheckPos = 0;
|
|
|
|
short nType;
|
2008-07-02 09:04:30 +00:00
|
|
|
String aFmtStr = *pFmt;
|
|
|
|
VbaFormatInfo* pInfo = getFormatInfo( aFmtStr );
|
|
|
|
if( pInfo && pInfo->meType != VBA_FORMAT_TYPE_NULL )
|
|
|
|
{
|
|
|
|
if( pInfo->meType == VBA_FORMAT_TYPE_OFFSET )
|
|
|
|
{
|
|
|
|
nIndex = aFormatter.GetFormatIndex( pInfo->meOffset, eLangType );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aFmtStr.AssignAscii( pInfo->mpOOoFormat );
|
|
|
|
aFormatter.PutandConvertEntry( aFmtStr, nCheckPos, nType, nIndex, LANGUAGE_ENGLISH, eLangType );
|
|
|
|
}
|
|
|
|
aFormatter.GetOutputString( nNumber, nIndex, rRes, &pCol );
|
|
|
|
}
|
|
|
|
else if( aFmtStr.EqualsIgnoreCaseAscii( VBAFORMAT_GENERALDATE )
|
|
|
|
|| aFmtStr.EqualsIgnoreCaseAscii( VBAFORMAT_C ))
|
|
|
|
{
|
|
|
|
if( nNumber <=-1.0 || nNumber >= 1.0 )
|
|
|
|
{
|
|
|
|
// short date
|
|
|
|
nIndex = aFormatter.GetFormatIndex( NF_DATE_SYSTEM_SHORT, eLangType );
|
|
|
|
aFormatter.GetOutputString( nNumber, nIndex, rRes, &pCol );
|
|
|
|
|
|
|
|
// long time
|
|
|
|
if( floor( nNumber ) != nNumber )
|
|
|
|
{
|
|
|
|
aFmtStr.AssignAscii( "H:MM:SS AM/PM" );
|
|
|
|
aFormatter.PutandConvertEntry( aFmtStr, nCheckPos, nType, nIndex, LANGUAGE_ENGLISH, eLangType );
|
|
|
|
String aTime;
|
|
|
|
aFormatter.GetOutputString( nNumber, nIndex, aTime, &pCol );
|
|
|
|
rRes.AppendAscii(" ");
|
|
|
|
rRes += aTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// long time only
|
|
|
|
aFmtStr.AssignAscii( "H:MM:SS AM/PM" );
|
|
|
|
aFormatter.PutandConvertEntry( aFmtStr, nCheckPos, nType, nIndex, LANGUAGE_ENGLISH, eLangType );
|
|
|
|
aFormatter.GetOutputString( nNumber, nIndex, rRes, &pCol );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( aFmtStr.EqualsIgnoreCaseAscii( VBAFORMAT_N )
|
|
|
|
|| aFmtStr.EqualsIgnoreCaseAscii( VBAFORMAT_NN ))
|
|
|
|
{
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_Int32 nMin = implGetMinute( nNumber );
|
2008-07-02 09:04:30 +00:00
|
|
|
if( nMin < 10 && aFmtStr.EqualsIgnoreCaseAscii( VBAFORMAT_NN ) )
|
|
|
|
{
|
|
|
|
// Minute in two digits
|
|
|
|
sal_Unicode* p = rRes.AllocBuffer( 2 );
|
|
|
|
*p++ = '0';
|
|
|
|
*p = sal_Unicode( '0' + nMin );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-08 17:35:47 +01:00
|
|
|
rRes = rtl::OUString::valueOf(nMin);
|
2008-07-02 09:04:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( aFmtStr.EqualsIgnoreCaseAscii( VBAFORMAT_W ))
|
|
|
|
{
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_Int32 nWeekDay = implGetWeekDay( nNumber );
|
2012-04-08 17:35:47 +01:00
|
|
|
rRes = rtl::OUString::valueOf(nWeekDay);
|
2008-07-02 09:04:30 +00:00
|
|
|
}
|
|
|
|
else if( aFmtStr.EqualsIgnoreCaseAscii( VBAFORMAT_Y ))
|
|
|
|
{
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_Int16 nYear = implGetDateYear( nNumber );
|
2008-07-02 09:04:30 +00:00
|
|
|
double dBaseDate;
|
|
|
|
implDateSerial( nYear, 1, 1, dBaseDate );
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_Int32 nYear32 = 1 + sal_Int32( nNumber - dBaseDate );
|
2012-04-08 17:35:47 +01:00
|
|
|
rRes = rtl::OUString::valueOf(nYear32);
|
2008-07-02 09:04:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aFormatter.PutandConvertEntry( aFmtStr, nCheckPos, nType, nIndex, LANGUAGE_ENGLISH, eLangType );
|
|
|
|
aFormatter.GetOutputString( nNumber, nIndex, rRes, &pCol );
|
|
|
|
}
|
|
|
|
|
2008-01-28 13:01:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-13 08:25:31 +00:00
|
|
|
SbxDataType eType = GetType();
|
|
|
|
switch( eType )
|
|
|
|
{
|
|
|
|
case SbxCHAR:
|
|
|
|
case SbxBYTE:
|
|
|
|
case SbxINTEGER:
|
|
|
|
case SbxUSHORT:
|
|
|
|
case SbxLONG:
|
|
|
|
case SbxULONG:
|
|
|
|
case SbxINT:
|
|
|
|
case SbxUINT:
|
2011-08-27 21:37:14 +02:00
|
|
|
case SbxNULL: // #45929 NULL with a little cheating
|
2005-04-13 08:25:31 +00:00
|
|
|
nComma = 0; goto cvt;
|
|
|
|
case SbxSINGLE:
|
|
|
|
nComma = 6; goto cvt;
|
|
|
|
case SbxDOUBLE:
|
|
|
|
nComma = 14;
|
|
|
|
|
|
|
|
cvt:
|
|
|
|
if( eType != SbxNULL )
|
|
|
|
d = GetDouble();
|
|
|
|
|
2011-08-27 21:37:14 +02:00
|
|
|
// #45355 another point to jump in for isnumeric-String
|
2005-04-13 08:25:31 +00:00
|
|
|
cvt2:
|
|
|
|
if( pFmt )
|
|
|
|
{
|
2011-09-19 00:50:11 +01:00
|
|
|
SbxAppData& rAppData = GetSbxData_Impl();
|
2005-04-13 08:25:31 +00:00
|
|
|
|
|
|
|
LanguageType eLangType = GetpApp()->GetSettings().GetLanguage();
|
2011-09-19 00:50:11 +01:00
|
|
|
if( rAppData.pBasicFormater )
|
2005-04-13 08:25:31 +00:00
|
|
|
{
|
2011-09-19 00:50:11 +01:00
|
|
|
if( rAppData.eBasicFormaterLangType != eLangType )
|
2005-04-13 08:25:31 +00:00
|
|
|
{
|
2011-09-19 00:50:11 +01:00
|
|
|
delete rAppData.pBasicFormater;
|
|
|
|
rAppData.pBasicFormater = NULL;
|
2005-04-13 08:25:31 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-19 00:50:11 +01:00
|
|
|
rAppData.eBasicFormaterLangType = eLangType;
|
2005-04-13 08:25:31 +00:00
|
|
|
|
2011-08-27 21:37:14 +02:00
|
|
|
|
2011-09-19 00:50:11 +01:00
|
|
|
if( !rAppData.pBasicFormater )
|
2005-04-13 08:25:31 +00:00
|
|
|
{
|
|
|
|
SvtSysLocale aSysLocale;
|
|
|
|
const LocaleDataWrapper& rData = aSysLocale.GetLocaleData();
|
|
|
|
sal_Unicode cComma = rData.getNumDecimalSep().GetBuffer()[0];
|
|
|
|
sal_Unicode c1000 = rData.getNumThousandSep().GetBuffer()[0];
|
|
|
|
String aCurrencyStrg = rData.getCurrSymbol();
|
|
|
|
|
2011-08-27 21:37:14 +02:00
|
|
|
// initialize the Basic-formater help object:
|
|
|
|
// get resources for predefined output
|
|
|
|
// of the Format()-command, e. g. for "On/Off"
|
2005-09-29 17:42:37 +00:00
|
|
|
String aOnStrg = String( SbxValueFormatResId(
|
2005-04-13 08:25:31 +00:00
|
|
|
STR_BASICKEY_FORMAT_ON ) );
|
2005-09-29 17:42:37 +00:00
|
|
|
String aOffStrg = String( SbxValueFormatResId(
|
2005-04-13 08:25:31 +00:00
|
|
|
STR_BASICKEY_FORMAT_OFF) );
|
2005-09-29 17:42:37 +00:00
|
|
|
String aYesStrg = String( SbxValueFormatResId(
|
2005-04-13 08:25:31 +00:00
|
|
|
STR_BASICKEY_FORMAT_YES) );
|
2005-09-29 17:42:37 +00:00
|
|
|
String aNoStrg = String( SbxValueFormatResId(
|
2005-04-13 08:25:31 +00:00
|
|
|
STR_BASICKEY_FORMAT_NO) );
|
2005-09-29 17:42:37 +00:00
|
|
|
String aTrueStrg = String( SbxValueFormatResId(
|
2005-04-13 08:25:31 +00:00
|
|
|
STR_BASICKEY_FORMAT_TRUE) );
|
2005-09-29 17:42:37 +00:00
|
|
|
String aFalseStrg = String( SbxValueFormatResId(
|
2005-04-13 08:25:31 +00:00
|
|
|
STR_BASICKEY_FORMAT_FALSE) );
|
2005-09-29 17:42:37 +00:00
|
|
|
String aCurrencyFormatStrg = String( SbxValueFormatResId(
|
2005-04-13 08:25:31 +00:00
|
|
|
STR_BASICKEY_FORMAT_CURRENCY) );
|
2011-08-27 21:37:14 +02:00
|
|
|
|
2011-09-19 00:50:11 +01:00
|
|
|
rAppData.pBasicFormater
|
2005-04-13 08:25:31 +00:00
|
|
|
= new SbxBasicFormater( cComma,c1000,aOnStrg,aOffStrg,
|
|
|
|
aYesStrg,aNoStrg,aTrueStrg,aFalseStrg,
|
|
|
|
aCurrencyStrg,aCurrencyFormatStrg );
|
|
|
|
}
|
2011-08-27 21:37:14 +02:00
|
|
|
// Remark: For performance reasons there's only ONE BasicFormater-
|
|
|
|
// object created and 'stored', so that the expensive resource-
|
|
|
|
// loading is saved (for country-specific predefined outputs,
|
|
|
|
// e. g. "On/Off") and the continous string-creation
|
|
|
|
// operations, too.
|
|
|
|
// BUT: therefore this code is NOT multithreading capable!
|
|
|
|
|
|
|
|
// here are problems with ;;;Null because this method is only
|
|
|
|
// called, if SbxValue is a number!!!
|
2011-09-19 00:50:11 +01:00
|
|
|
// in addition rAppData.pBasicFormater->BasicFormatNull( *pFmt ); could be called!
|
2005-04-13 08:25:31 +00:00
|
|
|
if( eType != SbxNULL )
|
|
|
|
{
|
2011-09-19 00:50:11 +01:00
|
|
|
rRes = rAppData.pBasicFormater->BasicFormat( d ,*pFmt );
|
2005-04-13 08:25:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-19 00:50:11 +01:00
|
|
|
rRes = rAppData.pBasicFormater->BasicFormatNull( *pFmt );
|
2005-04-13 08:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
2010-08-13 13:28:45 +02:00
|
|
|
{
|
|
|
|
::rtl::OUString aTmpString( rRes );
|
|
|
|
ImpCvtNum( GetDouble(), nComma, aTmpString );
|
|
|
|
rRes = aTmpString;
|
|
|
|
}
|
2005-04-13 08:25:31 +00:00
|
|
|
break;
|
|
|
|
case SbxSTRING:
|
|
|
|
if( pFmt )
|
|
|
|
{
|
2011-08-27 21:37:14 +02:00
|
|
|
// #45355 converting if numeric
|
2005-04-13 08:25:31 +00:00
|
|
|
if( IsNumericRTL() )
|
|
|
|
{
|
2011-01-10 14:40:57 +01:00
|
|
|
ScanNumIntnl( GetString(), d, /*bSingle*/sal_False );
|
2005-04-13 08:25:31 +00:00
|
|
|
goto cvt2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printfmtstr( GetString(), rRes, *pFmt );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rRes = GetString();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rRes = GetString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|