summaryrefslogtreecommitdiff
path: root/psprint
diff options
context:
space:
mode:
authorRüdiger Timm <rt@openoffice.org>2007-07-03 12:59:14 +0000
committerRüdiger Timm <rt@openoffice.org>2007-07-03 12:59:14 +0000
commit04e9d69f1dfea29a00c94bedb08d1156b3fffd0d (patch)
tree66ea8848b2c2e81b142734ed28af7c6fafa0da7b /psprint
parentf7cbe3ffc2c774df892b19f49b9b6a5a1f4a89c4 (diff)
INTEGRATION: CWS vcl79 (1.14.40); FILE MERGED
2007/05/31 08:32:53 pl 1.14.40.2: #i49079# use rtl::math functions instead of creating own double<->string conversion 2007/05/21 11:00:38 pl 1.14.40.1: #i77444# remove a warning ?
Diffstat (limited to 'psprint')
-rw-r--r--psprint/source/helper/strhelper.cxx285
1 files changed, 2 insertions, 283 deletions
diff --git a/psprint/source/helper/strhelper.cxx b/psprint/source/helper/strhelper.cxx
index 138e06008d0b..a15e2d8c0dfc 100644
--- a/psprint/source/helper/strhelper.cxx
+++ b/psprint/source/helper/strhelper.cxx
@@ -4,9 +4,9 @@
*
* $RCSfile: strhelper.cxx,v $
*
- * $Revision: 1.14 $
+ * $Revision: 1.15 $
*
- * last change: $Author: vg $ $Date: 2006-11-21 17:04:12 $
+ * last change: $Author: rt $ $Date: 2007-07-03 13:59:14 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@@ -36,17 +36,7 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_psprint.hxx"
#include <psprint/strhelper.hxx>
-#if defined(SOLARIS) || defined(IRIX)
-#include <ieeefp.h> // finite
-#endif
#include <sal/alloca.h>
-#include <cstdlib>
-#include <cstring>
-#include <rtl/math.hxx>
-
-#if defined (FREEBSD)
-using namespace __gnu_cxx; //for isnan #iz27753 for FreeBSD
-#endif
namespace psp {
@@ -456,275 +446,4 @@ ByteString WhitespaceToSpace( const ByteString& rLine, BOOL bProtect )
return aRet;
}
-static double fExpValues[] =
-{
- 1.0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10,
- 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20
-};
-
-static double calcPow10( int nExp )
-{
- BOOL bNeg = nExp < 0;
- nExp = bNeg ? -nExp : nExp;
- double fRet = 1.0;
- while( nExp >= 20 )
- {
- fRet *= fExpValues[20];
- nExp -= 20;
- }
- fRet *= fExpValues[ nExp ];
- return bNeg ? 1.0/fRet : fRet;
-}
-
-double StringToDouble( const String& rStr )
-{
- const sal_Unicode* pStr = rStr.GetBuffer();
- const sal_Unicode* pOrg = pStr;
- const int nLen = rStr.Len();
-
- BOOL bExp = FALSE, bNeg = FALSE, bNegExp = FALSE, bDecimal=FALSE;
- int nExp = 0;
- double fRet = 0.0, fDiv = 0.1;
-
- while( isSpace( *pStr ) )
- pStr++;
- for( ; pStr - pOrg < nLen; pStr++ )
- {
- if( *pStr >= '0' && *pStr <= '9' )
- {
- if( bExp )
- nExp = nExp*10 + ( *pStr - '0' );
- else if( ! bDecimal )
- fRet = 10.0 * fRet + (double)( *pStr - '0' );
- else
- {
- fRet += fDiv * (double)( *pStr - '0' );
- fDiv /= 10.0;
- }
- }
- else if( *pStr == '.' )
- {
- if( bExp || bDecimal )
- break;
- bDecimal = TRUE;
- }
- else if( *pStr == '-' )
- {
- if( bExp )
- {
- if( nExp != 0 )
- break;
- bNegExp = ! bNegExp;
- }
- else
- {
- if( fRet != 0.0 )
- break;
- bNeg = ! bNeg;
- }
- }
- else if( *pStr == '+' )
- {
- if( bExp && nExp != 0 )
- break;
- if( fRet != 0.0 )
- break;
- }
- else if( *pStr == 'e' || *pStr == 'E' )
- {
- if( bExp )
- break;
- bExp = TRUE;
- }
- else
- break;
- }
- if( bExp )
- {
- nExp = bNegExp ? -nExp : nExp;
- fRet *= calcPow10( nExp );
- }
- return bNeg ? -fRet : fRet;
-}
-
-double StringToDouble( const ByteString& rStr )
-{
- const char* pStr = rStr.GetBuffer();
- const char* pOrg = pStr;
- const int nLen = rStr.Len();
-
- BOOL bExp = FALSE, bNeg = FALSE, bNegExp = FALSE, bDecimal=FALSE;
- int nExp = 0;
- double fRet = 0.0, fDiv = 0.1;
-
- while( isSpace( *pStr ) )
- pStr++;
- for( ; pStr - pOrg < nLen; pStr++ )
- {
- if( *pStr >= '0' && *pStr <= '9' )
- {
- if( bExp )
- nExp = nExp*10 + ( *pStr - '0' );
- else if( ! bDecimal )
- fRet = 10.0 * fRet + (double)( *pStr - '0' );
- else
- {
- fRet += fDiv * (double)( *pStr - '0' );
- fDiv /= 10.0;
- }
- }
- else if( *pStr == '.' )
- {
- if( bExp || bDecimal )
- break;
- bDecimal = TRUE;
- }
- else if( *pStr == '-' )
- {
- if( bExp )
- {
- if( nExp != 0 )
- break;
- bNegExp = ! bNegExp;
- }
- else
- {
- if( fRet != 0.0 )
- break;
- bNeg = ! bNeg;
- }
- }
- else if( *pStr == '+' )
- {
- if( bExp && nExp != 0 )
- break;
- if( fRet != 0.0 )
- break;
- }
- else if( *pStr == 'e' || *pStr == 'E' )
- {
- if( bExp )
- break;
- bExp = TRUE;
- }
- else
- break;
- }
- if( bExp )
- {
- nExp = bNegExp ? -nExp : nExp;
- fRet *= calcPow10( nExp );
- }
- return bNeg ? -fRet : fRet;
-}
-
-int getValueOfDouble( char* pBuffer, double f, int nPrecision )
-{
- char* pOrigin = pBuffer;
-
- if( ! finite( f ) )
- {
- strncpy( pBuffer, "Inf", 3 );
- return 3;
- }
-
- if( ::rtl::math::isNan( f ) )
- {
- strncpy( pBuffer, "NaN", 3 );
- return 3;
- }
-
- if( f == 0.0 )
- {
- strncpy( pBuffer, "0", 3 );
- return 1;
- }
-
- if( f < 0.0 )
- {
- *pBuffer++ = '-';
- f = -f;
- }
- int exponent = (int)log10( f );
- if( exponent < 4 && exponent > -4 )
- exponent = 0;
- f /= pow( 10, (double) exponent );
-
- int nInt = (int)f;
- f -= nInt;
- // f should really not be 1.0 after this, but some
- // hardware implementations seem to round at this point
- // this should take care of *.9999999999...
- if( f == 1.0 || log10( 1.0 - f ) <= -nPrecision )
- {
- nInt++;
- f = 0.0;
- }
-
- char pReverseBuffer[12];
- int nRev = 0;
- do
- {
- pReverseBuffer[ nRev++ ] = ( nInt % 10 ) + '0';
- nInt /= 10;
- } while( nInt );
- while( nRev-- )
- *pBuffer++ = pReverseBuffer[ nRev ];
-
- if( f || exponent )
- {
- *pBuffer++ = '.';
- do
- {
- f *= 10;
- nInt = (int)f;
- f -= nInt;
- // f should really not be 1.0 after this, but some
- // hardware implementations seem to round at this point
- // this should take care of *.*9999999...
- if( f == 1.0 || log10( 1.0 - f ) <= -nPrecision )
- {
- nInt++;
- f = 0.0;
- }
- *pBuffer++ = nInt + '0';
- nPrecision--;
- } while( f && nPrecision != 0);
- }
- if( exponent )
- {
- *pBuffer++ = 'e';
- if( exponent < 0 )
- {
- *pBuffer++ = '-';
- exponent = -exponent;
- }
- nRev = 0;
- do
- {
- pReverseBuffer[ nRev++ ] = (exponent % 10) + '0';
- exponent /= 10;
- } while( exponent );
- while( nRev-- )
- *pBuffer++ = pReverseBuffer[ nRev ];
- }
- *pBuffer++ = 0;
-
- return (pBuffer - pOrigin)-1;
-}
-
-ByteString DoubleToByteString( double f, int nPrecision )
-{
- char buffer[128];
- getValueOfDouble( buffer, f, nPrecision );
- return ByteString( buffer );
-}
-
-String DoubleToString( double f, int nPrecision )
-{
- char buffer[128];
- getValueOfDouble( buffer, f, nPrecision );
- return String::CreateFromAscii( buffer );
-}
-
} // namespace