summaryrefslogtreecommitdiff
path: root/basic/source
diff options
context:
space:
mode:
authorTor Lillqvist <tml@iki.fi>2021-12-02 12:37:07 +0200
committerAndras Timar <andras.timar@collabora.com>2022-02-14 11:25:40 +0100
commit5fba7aec166fcadc1198fdd8dbefb3faec48c6c6 (patch)
tree65d683c0924dfef14a9b3017980e9fc52c3ef2ef /basic/source
parent6fbe2bace6551b07bf8e26a3f1bd6b252ec043ab (diff)
Make the tdf#97983 changes to BASIC optional
If you want to keep the string to floating point conversion semantics in BASIC as they were in LibreOffice 6, you can either set the LIBREOFFICE6FLOATINGPOINTMODE environment variable to some non-empty value, or set the org.openoffice.Office.Scripting/Basic/Compatibility/ UseLibreOffice6FloatingPointConversion flag in the Expert Configuration. (Or use a registry modification file with that effect.) Adapt the relevant unit test accordingly. Thanks to Mike Kaganski for showing how to access the setting in the LibreOffice registry from Basic. Change-Id: I13d6d5d834e1bb81ef8df489db2b1da79f01dfc5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125756 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'basic/source')
-rw-r--r--basic/source/inc/rtlproto.hxx1
-rw-r--r--basic/source/runtime/methods1.cxx10
-rw-r--r--basic/source/sbx/sbxbool.cxx3
-rw-r--r--basic/source/sbx/sbxbyte.cxx3
-rw-r--r--basic/source/sbx/sbxchar.cxx3
-rw-r--r--basic/source/sbx/sbxdbl.cxx3
-rw-r--r--basic/source/sbx/sbxint.cxx7
-rw-r--r--basic/source/sbx/sbxlng.cxx3
-rw-r--r--basic/source/sbx/sbxscan.cxx3
-rw-r--r--basic/source/sbx/sbxsng.cxx3
-rw-r--r--basic/source/sbx/sbxuint.cxx3
-rw-r--r--basic/source/sbx/sbxulng.cxx3
-rw-r--r--basic/source/sbx/sbxvalue.cxx5
-rw-r--r--basic/source/sbx/sbxvar.cxx5
14 files changed, 39 insertions, 16 deletions
diff --git a/basic/source/inc/rtlproto.hxx b/basic/source/inc/rtlproto.hxx
index 7347ead45dc1..65efa4f0a746 100644
--- a/basic/source/inc/rtlproto.hxx
+++ b/basic/source/inc/rtlproto.hxx
@@ -355,6 +355,7 @@ extern void SbRtl_CDec(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
extern void SbRtl_Partition(StarBASIC * pBasic, SbxArray & rPar, bool bWrite); // Fong
+extern bool LibreOffice6FloatingPointMode();
extern double Now_Impl();
extern void Wait_Impl( bool bDurationBased, SbxArray& rPar );
diff --git a/basic/source/runtime/methods1.cxx b/basic/source/runtime/methods1.cxx
index 7e2d0c771a37..4e471362932b 100644
--- a/basic/source/runtime/methods1.cxx
+++ b/basic/source/runtime/methods1.cxx
@@ -61,6 +61,9 @@
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/i18n/LocaleCalendar2.hpp>
#include <com/sun/star/sheet/XFunctionAccess.hpp>
+
+#include <officecfg/Office/Scripting.hxx>
+
#include <memory>
using namespace comphelper;
@@ -2970,6 +2973,13 @@ void SbRtl_CompatibilityMode(StarBASIC *, SbxArray & rPar, bool)
rPar.Get(0)->PutBool(bEnabled);
}
+bool LibreOffice6FloatingPointMode()
+{
+ static bool bMode = std::getenv("LIBREOFFICE6FLOATINGPOINTMODE") != nullptr;
+
+ return bMode || officecfg::Office::Scripting::Basic::Compatibility::UseLibreOffice6FloatingPointConversion::get();
+}
+
void SbRtl_Input(StarBASIC *, SbxArray & rPar, bool)
{
// 2 parameters needed
diff --git a/basic/source/sbx/sbxbool.cxx b/basic/source/sbx/sbxbool.cxx
index 723939fb0c4a..0b5f2111eca8 100644
--- a/basic/source/sbx/sbxbool.cxx
+++ b/basic/source/sbx/sbxbool.cxx
@@ -21,6 +21,7 @@
#include <basic/sberrors.hxx>
#include "sbxconv.hxx"
#include "sbxres.hxx"
+#include <rtlproto.hxx>
enum SbxBOOL ImpGetBool( const SbxValues* p )
{
@@ -80,7 +81,7 @@ enum SbxBOOL ImpGetBool( const SbxValues* p )
double n;
SbxDataType t;
sal_uInt16 nLen = 0;
- if( ImpScan( *p->pOUString, n, t, &nLen, true ) == ERRCODE_NONE )
+ if( ImpScan( *p->pOUString, n, t, &nLen, !LibreOffice6FloatingPointMode() ) == ERRCODE_NONE )
{
if( nLen == p->pOUString->getLength() )
{
diff --git a/basic/source/sbx/sbxbyte.cxx b/basic/source/sbx/sbxbyte.cxx
index 4974213dc7a1..1892167121c2 100644
--- a/basic/source/sbx/sbxbyte.cxx
+++ b/basic/source/sbx/sbxbyte.cxx
@@ -24,6 +24,7 @@
//#include <basic/sbx.hxx>
#include <basic/sberrors.hxx>
#include "sbxconv.hxx"
+#include <rtlproto.hxx>
#include <rtl/math.hxx>
@@ -165,7 +166,7 @@ start:
{
double d;
SbxDataType t;
- if( ImpScan( *p->pOUString, d, t, nullptr, true ) != ERRCODE_NONE )
+ if( ImpScan( *p->pOUString, d, t, nullptr, !LibreOffice6FloatingPointMode() ) != ERRCODE_NONE )
nRes = 0;
else if( d > SbxMAXBYTE )
{
diff --git a/basic/source/sbx/sbxchar.cxx b/basic/source/sbx/sbxchar.cxx
index d25ccc083d7c..36bd8d60d482 100644
--- a/basic/source/sbx/sbxchar.cxx
+++ b/basic/source/sbx/sbxchar.cxx
@@ -20,6 +20,7 @@
#include <vcl/errcode.hxx>
#include <basic/sberrors.hxx>
#include "sbxconv.hxx"
+#include <rtlproto.hxx>
#include <rtl/math.hxx>
@@ -147,7 +148,7 @@ start:
{
double d;
SbxDataType t;
- if( ImpScan( *p->pOUString, d, t, nullptr, true ) != ERRCODE_NONE )
+ if( ImpScan( *p->pOUString, d, t, nullptr, !LibreOffice6FloatingPointMode() ) != ERRCODE_NONE )
nRes = 0;
else if( d > SbxMAXCHAR )
{
diff --git a/basic/source/sbx/sbxdbl.cxx b/basic/source/sbx/sbxdbl.cxx
index a2fed927496d..7956db39afa0 100644
--- a/basic/source/sbx/sbxdbl.cxx
+++ b/basic/source/sbx/sbxdbl.cxx
@@ -22,6 +22,7 @@
#include <o3tl/float_int_conversion.hxx>
#include <vcl/errcode.hxx>
#include "sbxconv.hxx"
+#include <rtlproto.hxx>
#include <runtime.hxx>
double ImpGetDouble( const SbxValues* p )
@@ -81,7 +82,7 @@ double ImpGetDouble( const SbxValues* p )
{
double d;
SbxDataType t;
- if( ImpScan( *p->pOUString, d, t, nullptr, true ) != ERRCODE_NONE )
+ if( ImpScan( *p->pOUString, d, t, nullptr, !LibreOffice6FloatingPointMode() ) != ERRCODE_NONE )
{
nRes = 0;
#if HAVE_FEATURE_SCRIPTING
diff --git a/basic/source/sbx/sbxint.cxx b/basic/source/sbx/sbxint.cxx
index a28b810eb8c7..634053c8d138 100644
--- a/basic/source/sbx/sbxint.cxx
+++ b/basic/source/sbx/sbxint.cxx
@@ -24,6 +24,7 @@
#include <vcl/errcode.hxx>
#include <basic/sberrors.hxx>
#include "sbxconv.hxx"
+#include <rtlproto.hxx>
#include <rtl/math.hxx>
@@ -158,7 +159,7 @@ start:
{
double d;
SbxDataType t;
- if( ImpScan( *p->pOUString, d, t, nullptr, true ) != ERRCODE_NONE )
+ if( ImpScan( *p->pOUString, d, t, nullptr, !LibreOffice6FloatingPointMode() ) != ERRCODE_NONE )
nRes = 0;
else if( !o3tl::convertsToAtMost(o3tl::roundAway(d), SbxMAXINT) )
{
@@ -443,7 +444,7 @@ start:
// Check if really 0 or invalid conversion
double d;
SbxDataType t;
- if( ImpScan( *p->pOUString, d, t, nullptr, true ) != ERRCODE_NONE )
+ if( ImpScan( *p->pOUString, d, t, nullptr, !LibreOffice6FloatingPointMode() ) != ERRCODE_NONE )
nRes = 0;
else
nRes = static_cast<sal_Int64>(d);
@@ -704,7 +705,7 @@ start:
// Check if really 0 or invalid conversion
double d;
SbxDataType t;
- if( ImpScan( *p->pOUString, d, t, nullptr, true ) != ERRCODE_NONE )
+ if( ImpScan( *p->pOUString, d, t, nullptr, !LibreOffice6FloatingPointMode() ) != ERRCODE_NONE )
nRes = 0;
else if( !o3tl::convertsToAtMost(o3tl::roundAway(d), SAL_MAX_UINT64) )
{
diff --git a/basic/source/sbx/sbxlng.cxx b/basic/source/sbx/sbxlng.cxx
index bda401b981db..def6b985209a 100644
--- a/basic/source/sbx/sbxlng.cxx
+++ b/basic/source/sbx/sbxlng.cxx
@@ -23,6 +23,7 @@
#include <vcl/errcode.hxx>
#include <basic/sberrors.hxx>
#include "sbxconv.hxx"
+#include <rtlproto.hxx>
#include <rtl/math.hxx>
@@ -121,7 +122,7 @@ start:
{
double d;
SbxDataType t;
- if( ImpScan( *p->pOUString, d, t, nullptr, true ) != ERRCODE_NONE )
+ if( ImpScan( *p->pOUString, d, t, nullptr, !LibreOffice6FloatingPointMode() ) != ERRCODE_NONE )
nRes = 0;
else if( !o3tl::convertsToAtMost(o3tl::roundAway(d), SbxMAXLNG) )
{
diff --git a/basic/source/sbx/sbxscan.cxx b/basic/source/sbx/sbxscan.cxx
index 5fb56ba1d8fd..dc63df5a5a97 100644
--- a/basic/source/sbx/sbxscan.cxx
+++ b/basic/source/sbx/sbxscan.cxx
@@ -26,6 +26,7 @@
#include <vcl/errcode.hxx>
#include <unotools/resmgr.hxx>
#include "sbxconv.hxx"
+#include <rtlproto.hxx>
#include <unotools/syslocale.hxx>
#include <unotools/charclass.hxx>
@@ -422,7 +423,7 @@ bool SbxValue::Scan( const OUString& rSrc, sal_uInt16* pLen )
{
double n;
SbxDataType t;
- eRes = ImpScan( rSrc, n, t, pLen, true );
+ eRes = ImpScan( rSrc, n, t, pLen, !LibreOffice6FloatingPointMode() );
if( eRes == ERRCODE_NONE )
{
if( !IsFixed() )
diff --git a/basic/source/sbx/sbxsng.cxx b/basic/source/sbx/sbxsng.cxx
index a8129b8cd48d..2addb8086c3d 100644
--- a/basic/source/sbx/sbxsng.cxx
+++ b/basic/source/sbx/sbxsng.cxx
@@ -23,6 +23,7 @@
#include <vcl/errcode.hxx>
#include <basic/sberrors.hxx>
#include "sbxconv.hxx"
+#include <rtlproto.hxx>
float ImpGetSingle( const SbxValues* p )
{
@@ -109,7 +110,7 @@ start:
{
double d;
SbxDataType t;
- if( ImpScan( *p->pOUString, d, t, nullptr, true ) != ERRCODE_NONE )
+ if( ImpScan( *p->pOUString, d, t, nullptr, !LibreOffice6FloatingPointMode() ) != ERRCODE_NONE )
nRes = 0;
else if( d > SbxMAXSNG )
{
diff --git a/basic/source/sbx/sbxuint.cxx b/basic/source/sbx/sbxuint.cxx
index a3751e2661a4..be001204ab5d 100644
--- a/basic/source/sbx/sbxuint.cxx
+++ b/basic/source/sbx/sbxuint.cxx
@@ -23,6 +23,7 @@
#include <vcl/errcode.hxx>
#include <basic/sberrors.hxx>
#include "sbxconv.hxx"
+#include <rtlproto.hxx>
sal_uInt16 ImpGetUShort( const SbxValues* p )
{
@@ -154,7 +155,7 @@ start:
{
double d;
SbxDataType t;
- if( ImpScan( *p->pOUString, d, t, nullptr, true ) != ERRCODE_NONE )
+ if( ImpScan( *p->pOUString, d, t, nullptr, !LibreOffice6FloatingPointMode() ) != ERRCODE_NONE )
nRes = 0;
else if( !o3tl::convertsToAtMost(o3tl::roundAway(d), SbxMAXUINT) )
{
diff --git a/basic/source/sbx/sbxulng.cxx b/basic/source/sbx/sbxulng.cxx
index bcb1ce0f2778..bf25bb09bf89 100644
--- a/basic/source/sbx/sbxulng.cxx
+++ b/basic/source/sbx/sbxulng.cxx
@@ -23,6 +23,7 @@
#include <vcl/errcode.hxx>
#include <basic/sberrors.hxx>
#include "sbxconv.hxx"
+#include <rtlproto.hxx>
sal_uInt32 ImpGetULong( const SbxValues* p )
{
@@ -121,7 +122,7 @@ start:
{
double d;
SbxDataType t;
- if( ImpScan( *p->pOUString, d, t, nullptr, true ) != ERRCODE_NONE )
+ if( ImpScan( *p->pOUString, d, t, nullptr, !LibreOffice6FloatingPointMode() ) != ERRCODE_NONE )
nRes = 0;
else if( !o3tl::convertsToAtMost(o3tl::roundAway(d), SbxMAXULNG) )
{
diff --git a/basic/source/sbx/sbxvalue.cxx b/basic/source/sbx/sbxvalue.cxx
index 628166387a02..242445790caf 100644
--- a/basic/source/sbx/sbxvalue.cxx
+++ b/basic/source/sbx/sbxvalue.cxx
@@ -30,6 +30,7 @@
#include <basic/sbx.hxx>
#include <sbunoobj.hxx>
#include "sbxconv.hxx"
+#include <rtlproto.hxx>
#include <runtime.hxx>
@@ -1325,7 +1326,7 @@ bool SbxValue::LoadData( SvStream& r, sal_uInt16 )
RTL_TEXTENCODING_ASCII_US);
double d;
SbxDataType t;
- if( ImpScan( aVal, d, t, nullptr, true ) != ERRCODE_NONE || t == SbxDOUBLE )
+ if( ImpScan( aVal, d, t, nullptr, !LibreOffice6FloatingPointMode() ) != ERRCODE_NONE || t == SbxDOUBLE )
{
aData.nSingle = 0.0F;
return false;
@@ -1340,7 +1341,7 @@ bool SbxValue::LoadData( SvStream& r, sal_uInt16 )
OUString aVal = read_uInt16_lenPrefixed_uInt8s_ToOUString(r,
RTL_TEXTENCODING_ASCII_US);
SbxDataType t;
- if( ImpScan( aVal, aData.nDouble, t, nullptr, true ) != ERRCODE_NONE )
+ if( ImpScan( aVal, aData.nDouble, t, nullptr, !LibreOffice6FloatingPointMode() ) != ERRCODE_NONE )
{
aData.nDouble = 0.0;
return false;
diff --git a/basic/source/sbx/sbxvar.cxx b/basic/source/sbx/sbxvar.cxx
index 6097d25eb995..d2c9802c413b 100644
--- a/basic/source/sbx/sbxvar.cxx
+++ b/basic/source/sbx/sbxvar.cxx
@@ -26,6 +26,7 @@
#include <runtime.hxx>
#include "sbxres.hxx"
#include "sbxconv.hxx"
+#include <rtlproto.hxx>
#include <sbunoobj.hxx>
#include <rtl/character.hxx>
#include <rtl/ustrbuf.hxx>
@@ -440,7 +441,7 @@ bool SbxVariable::LoadData( SvStream& rStrm, sal_uInt16 nVer )
rStrm, RTL_TEXTENCODING_ASCII_US);
double d;
SbxDataType t;
- if( ImpScan( aTmpString, d, t, nullptr, true ) != ERRCODE_NONE || t == SbxDOUBLE )
+ if( ImpScan( aTmpString, d, t, nullptr, !LibreOffice6FloatingPointMode() ) != ERRCODE_NONE || t == SbxDOUBLE )
{
aTmp.nSingle = 0;
return false;
@@ -455,7 +456,7 @@ bool SbxVariable::LoadData( SvStream& rStrm, sal_uInt16 nVer )
aTmpString = read_uInt16_lenPrefixed_uInt8s_ToOUString(rStrm,
RTL_TEXTENCODING_ASCII_US);
SbxDataType t;
- if( ImpScan( aTmpString, aTmp.nDouble, t, nullptr, true ) != ERRCODE_NONE )
+ if( ImpScan( aTmpString, aTmp.nDouble, t, nullptr, !LibreOffice6FloatingPointMode() ) != ERRCODE_NONE )
{
aTmp.nDouble = 0;
return false;