summaryrefslogtreecommitdiff
path: root/basic/source
diff options
context:
space:
mode:
Diffstat (limited to 'basic/source')
-rw-r--r--basic/source/basmgr/basicmanagerrepository.cxx54
-rw-r--r--basic/source/basmgr/basmgr.cxx190
-rw-r--r--basic/source/basmgr/vbahelper.cxx5
-rw-r--r--basic/source/classes/codecompletecache.cxx2
-rw-r--r--basic/source/classes/errobject.cxx6
-rw-r--r--basic/source/classes/eventatt.cxx37
-rw-r--r--basic/source/classes/image.cxx73
-rw-r--r--basic/source/classes/propacc.cxx53
-rw-r--r--basic/source/classes/sb.cxx202
-rw-r--r--basic/source/classes/sbunoobj.cxx303
-rw-r--r--basic/source/classes/sbxmod.cxx309
-rw-r--r--basic/source/comp/buffer.cxx4
-rw-r--r--basic/source/comp/codegen.cxx22
-rw-r--r--basic/source/comp/dim.cxx43
-rw-r--r--basic/source/comp/exprgen.cxx19
-rw-r--r--basic/source/comp/exprnode.cxx13
-rw-r--r--basic/source/comp/exprtree.cxx11
-rw-r--r--basic/source/comp/io.cxx47
-rw-r--r--basic/source/comp/loops.cxx110
-rw-r--r--basic/source/comp/parser.cxx104
-rw-r--r--basic/source/comp/scanner.cxx55
-rw-r--r--basic/source/comp/symtbl.cxx13
-rw-r--r--basic/source/comp/token.cxx17
-rw-r--r--basic/source/inc/buffer.hxx2
-rw-r--r--basic/source/inc/date.hxx10
-rw-r--r--basic/source/inc/dlgcont.hxx20
-rw-r--r--basic/source/inc/expr.hxx41
-rw-r--r--basic/source/inc/filefmt.hxx5
-rw-r--r--basic/source/inc/image.hxx8
-rw-r--r--basic/source/inc/iosys.hxx8
-rw-r--r--basic/source/inc/namecont.hxx248
-rw-r--r--basic/source/inc/parser.hxx1
-rw-r--r--basic/source/inc/propacc.hxx3
-rw-r--r--basic/source/inc/rtlproto.hxx101
-rw-r--r--basic/source/inc/runtime.hxx136
-rw-r--r--basic/source/inc/sbintern.hxx26
-rw-r--r--basic/source/inc/sbjsmod.hxx2
-rw-r--r--basic/source/inc/sbunoobj.hxx27
-rw-r--r--basic/source/inc/scanner.hxx10
-rw-r--r--basic/source/inc/scriptcont.hxx26
-rw-r--r--basic/source/inc/stdobj.hxx7
-rw-r--r--basic/source/inc/symtbl.hxx5
-rw-r--r--basic/source/inc/token.hxx2
-rw-r--r--basic/source/runtime/basrdll.cxx9
-rw-r--r--basic/source/runtime/comenumwrapper.cxx4
-rw-r--r--basic/source/runtime/comenumwrapper.hxx5
-rw-r--r--basic/source/runtime/ddectrl.cxx2
-rw-r--r--basic/source/runtime/ddectrl.hxx2
-rw-r--r--basic/source/runtime/dllmgr-none.cxx43
-rw-r--r--basic/source/runtime/dllmgr-x64.cxx65
-rw-r--r--basic/source/runtime/dllmgr-x86.cxx4
-rw-r--r--basic/source/runtime/dllmgr.hxx6
-rw-r--r--basic/source/runtime/inputbox.cxx16
-rw-r--r--basic/source/runtime/iosys.cxx32
-rw-r--r--basic/source/runtime/methods.cxx2787
-rw-r--r--basic/source/runtime/methods1.cxx666
-rw-r--r--basic/source/runtime/props.cxx105
-rw-r--r--basic/source/runtime/runtime.cxx452
-rw-r--r--basic/source/runtime/stdobj.cxx400
-rw-r--r--basic/source/runtime/stdobj1.cxx78
-rw-r--r--basic/source/sbx/sbxarray.cxx35
-rw-r--r--basic/source/sbx/sbxbase.cxx38
-rw-r--r--basic/source/sbx/sbxbool.cxx201
-rw-r--r--basic/source/sbx/sbxbyte.cxx312
-rw-r--r--basic/source/sbx/sbxchar.cxx300
-rw-r--r--basic/source/sbx/sbxcoll.cxx80
-rw-r--r--basic/source/sbx/sbxconv.hxx208
-rw-r--r--basic/source/sbx/sbxcurr.cxx461
-rw-r--r--basic/source/sbx/sbxdate.cxx284
-rw-r--r--basic/source/sbx/sbxdbl.cxx268
-rw-r--r--basic/source/sbx/sbxdec.cxx313
-rw-r--r--basic/source/sbx/sbxdec.hxx34
-rw-r--r--basic/source/sbx/sbxexec.cxx66
-rw-r--r--basic/source/sbx/sbxform.cxx176
-rw-r--r--basic/source/sbx/sbxint.cxx892
-rw-r--r--basic/source/sbx/sbxlng.cxx292
-rw-r--r--basic/source/sbx/sbxobj.cxx112
-rw-r--r--basic/source/sbx/sbxres.cxx94
-rw-r--r--basic/source/sbx/sbxscan.cxx791
-rw-r--r--basic/source/sbx/sbxsng.cxx282
-rw-r--r--basic/source/sbx/sbxstr.cxx2
-rw-r--r--basic/source/sbx/sbxuint.cxx291
-rw-r--r--basic/source/sbx/sbxulng.cxx267
-rw-r--r--basic/source/sbx/sbxvalue.cxx396
-rw-r--r--basic/source/sbx/sbxvar.cxx64
-rw-r--r--basic/source/uno/dlgcont.cxx78
-rw-r--r--basic/source/uno/modsizeexceeded.cxx15
-rw-r--r--basic/source/uno/namecont.cxx836
-rw-r--r--basic/source/uno/scriptcont.cxx124
89 files changed, 5567 insertions, 8801 deletions
diff --git a/basic/source/basmgr/basicmanagerrepository.cxx b/basic/source/basmgr/basicmanagerrepository.cxx
index a70c49eb1149..16f5b63626ce 100644
--- a/basic/source/basmgr/basicmanagerrepository.cxx
+++ b/basic/source/basmgr/basicmanagerrepository.cxx
@@ -27,13 +27,14 @@
#include <com/sun/star/document/XStorageBasedDocument.hpp>
#include <com/sun/star/document/XEmbeddedScripts.hpp>
#include <com/sun/star/frame/Desktop.hpp>
+#include <o3tl/string_view.hxx>
#include <svtools/ehdl.hxx>
#include <svtools/sfxecode.hxx>
#include <unotools/pathoptions.hxx>
#include <svl/hint.hxx>
#include <vcl/svapp.hxx>
#include <tools/debug.hxx>
-#include <tools/diagnose_ex.h>
+#include <comphelper/diagnose_ex.hxx>
#include <tools/urlobj.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/documentinfo.hxx>
@@ -42,6 +43,7 @@
#include <sot/storage.hxx>
#include <map>
+#include <mutex>
namespace basic
@@ -53,7 +55,7 @@ namespace basic
using ::com::sun::star::uno::XInterface;
using ::com::sun::star::uno::UNO_QUERY;
using ::com::sun::star::embed::XStorage;
- using ::com::sun::star::script::XPersistentLibraryContainer;
+ using ::com::sun::star::script::XStorageBasedLibraryContainer;
using ::com::sun::star::uno::UNO_QUERY_THROW;
using ::com::sun::star::uno::Exception;
using ::com::sun::star::document::XStorageBasedDocument;
@@ -166,15 +168,15 @@ namespace basic
*/
static bool impl_getDocumentLibraryContainers_nothrow(
const Reference< XModel >& _rxDocument,
- Reference< XPersistentLibraryContainer >& _out_rxBasicLibraries,
- Reference< XPersistentLibraryContainer >& _out_rxDialogLibraries
+ Reference<XStorageBasedLibraryContainer>& _out_rxBasicLibraries,
+ Reference<XStorageBasedLibraryContainer>& _out_rxDialogLibraries
);
/** initializes the given library containers, which belong to a document
*/
static void impl_initDocLibraryContainers_nothrow(
- const Reference< XPersistentLibraryContainer >& _rxBasicLibraries,
- const Reference< XPersistentLibraryContainer >& _rxDialogLibraries
+ const Reference<XStorageBasedLibraryContainer>& _rxBasicLibraries,
+ const Reference<XStorageBasedLibraryContainer>& _rxDialogLibraries
);
// OEventListenerAdapter overridables
@@ -206,8 +208,8 @@ namespace basic
{
tools::SvRef<SvRefBase>& repository = GetSbxData_Impl().mrImplRepository;
{
- static osl::Mutex aMutex;
- osl::MutexGuard aGuard(aMutex);
+ static std::mutex aMutex;
+ std::unique_lock aGuard(aMutex);
if (!repository)
repository = new ImplRepository;
}
@@ -270,12 +272,12 @@ namespace basic
OUString aAppBasicDir( aPathCFG.GetBasicPath() );
if ( aAppBasicDir.isEmpty() )
{
- aPathCFG.SetBasicPath("$(prog)");
+ aPathCFG.SetBasicPath(u"$(prog)"_ustr);
}
// Create basic and load it
// AppBasicDir is now a PATH
- INetURLObject aAppBasic( SvtPathOptions().SubstituteVariable("$(progurl)") );
+ INetURLObject aAppBasic( SvtPathOptions().SubstituteVariable(u"$(progurl)"_ustr) );
aAppBasic.insertName( Application::GetAppName() );
BasicManager* pBasicManager = new BasicManager( new StarBASIC, &aAppBasicDir );
@@ -283,7 +285,7 @@ namespace basic
// The first dir in the path as destination:
OUString aFileName( aAppBasic.getName() );
- aAppBasic = INetURLObject( aAppBasicDir.getToken(1, ';') );
+ aAppBasic = INetURLObject( o3tl::getToken(aAppBasicDir, 1, ';') );
DBG_ASSERT(aAppBasic.GetProtocol() != INetProtocol::NotValid,
OString("Invalid URL: \"" +
OUStringToOString(aAppBasicDir, osl_getThreadTextEncoding()) +
@@ -298,14 +300,14 @@ namespace basic
// Dialog container
rtl::Reference<SfxDialogLibraryContainer> pDialogCont = new SfxDialogLibraryContainer( Reference< XStorage >() );
- LibraryContainerInfo aInfo( pBasicCont, pDialogCont, static_cast< OldBasicPassword* >( pBasicCont.get() ) );
+ LibraryContainerInfo aInfo( pBasicCont, pDialogCont, pBasicCont.get() );
pBasicManager->SetLibraryContainerInfo( aInfo );
// global constants
// StarDesktop
- Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext();
- pBasicManager->SetGlobalUNOConstant( "StarDesktop", css::uno::Any( Desktop::create(xContext)));
+ const Reference< XComponentContext >& xContext = ::comphelper::getProcessComponentContext();
+ pBasicManager->SetGlobalUNOConstant( u"StarDesktop"_ustr, css::uno::Any( Desktop::create(xContext)));
// (BasicLibraries and DialogLibraries have automatically been added in SetLibraryContainerInfo)
@@ -369,10 +371,10 @@ namespace basic
Reference< XInterface > xNormalized( _rxDocumentModel, UNO_QUERY );
DBG_ASSERT( _rxDocumentModel.is(), "ImplRepository::impl_getLocationForModel: invalid model!" );
- return m_aStore.find(xNormalized) != m_aStore.end();
+ return m_aStore.contains(xNormalized);
}
- void ImplRepository::impl_initDocLibraryContainers_nothrow( const Reference< XPersistentLibraryContainer >& _rxBasicLibraries, const Reference< XPersistentLibraryContainer >& _rxDialogLibraries )
+ void ImplRepository::impl_initDocLibraryContainers_nothrow( const Reference<XStorageBasedLibraryContainer>& _rxBasicLibraries, const Reference<XStorageBasedLibraryContainer>& _rxDialogLibraries )
{
OSL_PRECOND( _rxBasicLibraries.is() && _rxDialogLibraries.is(),
"ImplRepository::impl_initDocLibraryContainers_nothrow: illegal library containers, this will crash!" );
@@ -380,7 +382,7 @@ namespace basic
try
{
// ensure there's a standard library in the basic container
- OUString aStdLibName( "Standard" );
+ static constexpr OUString aStdLibName( u"Standard"_ustr );
if ( !_rxBasicLibraries->hasByName( aStdLibName ) )
{
_rxBasicLibraries->createLibrary( aStdLibName );
@@ -411,8 +413,8 @@ namespace basic
// the document is not able to provide the storage it is based on.
return false;
}
- Reference< XPersistentLibraryContainer > xBasicLibs;
- Reference< XPersistentLibraryContainer > xDialogLibs;
+ Reference<XStorageBasedLibraryContainer> xBasicLibs;
+ Reference<XStorageBasedLibraryContainer> xDialogLibs;
if ( !impl_getDocumentLibraryContainers_nothrow( _rxDocumentModel, xBasicLibs, xDialogLibs ) )
{
m_aStore.erase(location);
@@ -428,8 +430,8 @@ namespace basic
OUString aAppBasicDir = SvtPathOptions().GetBasicPath();
// Storage and BaseURL are only needed by binary documents!
- tools::SvRef<SotStorage> xDummyStor = new SotStorage( OUString() );
- _out_rpBasicManager.reset(new BasicManager( *xDummyStor, OUString() /* TODO/LATER: xStorage */,
+ rtl::Reference<SotStorage> xDummyStor = new SotStorage(OUString());
+ _out_rpBasicManager.reset(new BasicManager( *xDummyStor, u"" /* TODO/LATER: xStorage */,
pAppBasic,
&aAppBasicDir, true ));
if ( !_out_rpBasicManager->GetErrors().empty() )
@@ -460,7 +462,7 @@ namespace basic
}
// knit the containers with the BasicManager
- LibraryContainerInfo aInfo( xBasicLibs, xDialogLibs, dynamic_cast< OldBasicPassword* >( xBasicLibs.get() ) );
+ LibraryContainerInfo aInfo( xBasicLibs, xDialogLibs, dynamic_cast< SfxScriptLibraryContainer* >( xBasicLibs.get() ) );
OSL_ENSURE( aInfo.mpOldBasicPassword, "ImplRepository::impl_createManagerForModel: wrong BasicLibraries implementation!" );
_out_rpBasicManager->SetLibraryContainerInfo( aInfo );
@@ -471,7 +473,7 @@ namespace basic
_out_rpBasicManager->GetLib(0)->SetParent( pAppBasic );
// global properties in the document's Basic
- _out_rpBasicManager->SetGlobalUNOConstant( "ThisComponent", css::uno::Any( _rxDocumentModel ) );
+ _out_rpBasicManager->SetGlobalUNOConstant( u"ThisComponent"_ustr, css::uno::Any( _rxDocumentModel ) );
// notify
impl_notifyCreationListeners( _rxDocumentModel, *_out_rpBasicManager );
@@ -517,15 +519,15 @@ namespace basic
bool ImplRepository::impl_getDocumentLibraryContainers_nothrow( const Reference< XModel >& _rxDocument,
- Reference< XPersistentLibraryContainer >& _out_rxBasicLibraries, Reference< XPersistentLibraryContainer >& _out_rxDialogLibraries )
+ Reference<XStorageBasedLibraryContainer>& _out_rxBasicLibraries, Reference<XStorageBasedLibraryContainer>& _out_rxDialogLibraries )
{
_out_rxBasicLibraries.clear();
_out_rxDialogLibraries.clear();
try
{
Reference< XEmbeddedScripts > xScripts( _rxDocument, UNO_QUERY_THROW );
- _out_rxBasicLibraries.set( xScripts->getBasicLibraries(), UNO_QUERY_THROW );
- _out_rxDialogLibraries.set( xScripts->getDialogLibraries(), UNO_QUERY_THROW );
+ _out_rxBasicLibraries.set( xScripts->getBasicLibraries() );
+ _out_rxDialogLibraries.set( xScripts->getDialogLibraries() );
}
catch( const Exception& )
{
diff --git a/basic/source/basmgr/basmgr.cxx b/basic/source/basmgr/basmgr.cxx
index 4dadf17d8f3f..bb11ec1963bc 100644
--- a/basic/source/basmgr/basmgr.cxx
+++ b/basic/source/basmgr/basmgr.cxx
@@ -17,6 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <utility>
#include <vcl/errinf.hxx>
#include <tools/stream.hxx>
#include <sot/storage.hxx>
@@ -27,10 +28,11 @@
#include <sot/storinfo.hxx>
#include <unotools/pathoptions.hxx>
#include <tools/debug.hxx>
-#include <tools/diagnose_ex.h>
+#include <comphelper/diagnose_ex.hxx>
#include <basic/sbmod.hxx>
#include <unotools/transliterationwrapper.hxx>
#include <sal/log.hxx>
+#include <o3tl/string_view.hxx>
#include <basic/sberrors.hxx>
#include <basic/sbuno.hxx>
@@ -39,6 +41,9 @@
#include <com/sun/star/script/XLibraryContainer.hpp>
#include <com/sun/star/script/XPersistentLibraryContainer.hpp>
+#include <scriptcont.hxx>
+
+#include <algorithm>
#include <memory>
#include <vector>
@@ -84,12 +89,12 @@ typedef WeakImplHelper< script::XStarBasicAccess > StarBasicAccessHelper;
// Version 2
// + bool bReference
-constexpr OUStringLiteral szStdLibName = u"Standard";
-constexpr OUStringLiteral szBasicStorage = u"StarBASIC";
-constexpr OUStringLiteral szOldManagerStream = u"BasicManager";
-constexpr OUStringLiteral szManagerStream = u"BasicManager2";
-constexpr OUStringLiteral szImbedded = u"LIBIMBEDDED";
-constexpr OStringLiteral szCryptingKey = "CryptedBasic";
+constexpr OUString szStdLibName = u"Standard"_ustr;
+constexpr OUString szBasicStorage = u"StarBASIC"_ustr;
+constexpr OUString szOldManagerStream = u"BasicManager"_ustr;
+constexpr OUString szManagerStream = u"BasicManager2"_ustr;
+constexpr OUString szImbedded = u"LIBIMBEDDED"_ustr;
+constexpr OString szCryptingKey = "CryptedBasic"_ostr;
const StreamMode eStreamReadMode = StreamMode::READ | StreamMode::NOCREATE | StreamMode::SHARE_DENYALL;
@@ -106,9 +111,9 @@ class BasMgrContainerListenerImpl: public ContainerListenerHelper
OUString maLibName; // empty -> no lib, but lib container
public:
- BasMgrContainerListenerImpl( BasicManager* pMgr, const OUString& aLibName )
+ BasMgrContainerListenerImpl( BasicManager* pMgr, OUString aLibName )
: mpMgr( pMgr )
- , maLibName( aLibName ) {}
+ , maLibName(std::move( aLibName )) {}
static void insertLibraryImpl( const uno::Reference< script::XLibraryContainer >& xScriptCont, BasicManager* pMgr,
const uno::Any& aLibAny, const OUString& aLibName );
@@ -296,19 +301,16 @@ void SAL_CALL BasMgrContainerListenerImpl::elementRemoved( const container::Cont
}
}
-BasicError::BasicError( ErrCode nId, BasicErrorReason nR )
+BasicError::BasicError( ErrCodeMsg nId )
+ : nErrorId(std::move(nId))
{
- nErrorId = nId;
- nReason = nR;
}
BasicError::BasicError( const BasicError& rErr )
+ : nErrorId(rErr.nErrorId)
{
- nErrorId = rErr.nErrorId;
- nReason = rErr.nReason;
}
-
class BasicLibInfo
{
private:
@@ -420,7 +422,7 @@ BasicLibInfo* BasicLibInfo::Create( SotStorageStream& rSStream )
return pInfo;
}
-BasicManager::BasicManager( SotStorage& rStorage, const OUString& rBaseURL, StarBASIC* pParentFromStdLib, OUString const * pLibPath, bool bDocMgr ) : mbDocMgr( bDocMgr )
+BasicManager::BasicManager( SotStorage& rStorage, std::u16string_view rBaseURL, StarBASIC* pParentFromStdLib, OUString const * pLibPath, bool bDocMgr ) : mbDocMgr( bDocMgr )
{
if( pLibPath )
{
@@ -509,12 +511,12 @@ static void copyToLibraryContainer( StarBASIC* pBasic, const LibraryContainerInf
}
}
-const uno::Reference< script::XPersistentLibraryContainer >& BasicManager::GetDialogLibraryContainer() const
+const uno::Reference< script::XStorageBasedLibraryContainer >& BasicManager::GetDialogLibraryContainer() const
{
return maContainerInfo.mxDialogCont;
}
-const uno::Reference< script::XPersistentLibraryContainer >& BasicManager::GetScriptLibraryContainer() const
+const uno::Reference< script::XStorageBasedLibraryContainer >& BasicManager::GetScriptLibraryContainer() const
{
return maContainerInfo.mxScriptCont;
}
@@ -528,7 +530,7 @@ void BasicManager::SetLibraryContainerInfo( const LibraryContainerInfo& rInfo )
{
// Register listener for lib container
uno::Reference< container::XContainerListener > xLibContainerListener
- = new BasMgrContainerListenerImpl( this, "" );
+ = new BasMgrContainerListenerImpl( this, u""_ustr );
uno::Reference< container::XContainer> xLibContainer( xScriptCont, uno::UNO_QUERY );
xLibContainer->addContainerListener( xLibContainerListener );
@@ -565,7 +567,7 @@ void BasicManager::SetLibraryContainerInfo( const LibraryContainerInfo& rInfo )
copyToLibraryContainer( pLib, maContainerInfo );
if (rpBasLibInfo->HasPassword())
{
- OldBasicPassword* pOldBasicPassword =
+ basic::SfxScriptLibraryContainer* pOldBasicPassword =
maContainerInfo.mpOldBasicPassword;
if( pOldBasicPassword )
{
@@ -578,8 +580,8 @@ void BasicManager::SetLibraryContainerInfo( const LibraryContainerInfo& rInfo )
}
}
- SetGlobalUNOConstant( "BasicLibraries", uno::Any( maContainerInfo.mxScriptCont ) );
- SetGlobalUNOConstant( "DialogLibraries", uno::Any( maContainerInfo.mxDialogCont ) );
+ SetGlobalUNOConstant( u"BasicLibraries"_ustr, uno::Any( maContainerInfo.mxScriptCont ) );
+ SetGlobalUNOConstant( u"DialogLibraries"_ustr, uno::Any( maContainerInfo.mxDialogCont ) );
}
BasicManager::BasicManager( StarBASIC* pSLib, OUString const * pLibPath, bool bDocMgr ) : mbDocMgr( bDocMgr )
@@ -605,8 +607,8 @@ void BasicManager::ImpMgrNotLoaded( const OUString& rStorageName )
{
// pErrInf is only destroyed if the error os processed by an
// ErrorHandler
- StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_MGROPEN, rStorageName, DialogMask::ButtonsOk );
- aErrors.emplace_back(*pErrInf, BasicErrorReason::OPENMGRSTREAM);
+ ErrCodeMsg aErrInf( ERRCODE_BASMGR_MGROPEN, rStorageName, DialogMask::ButtonsOk );
+ aErrors.emplace_back(aErrInf);
// Create a stdlib otherwise we crash!
BasicLibInfo* pStdLibInfo = CreateLibInfo();
@@ -629,9 +631,9 @@ void BasicManager::ImpCreateStdLib( StarBASIC* pParentFromStdLib )
pStdLib->SetFlag( SbxFlagBits::DontStore | SbxFlagBits::ExtSearch );
}
-void BasicManager::LoadBasicManager( SotStorage& rStorage, const OUString& rBaseURL )
+void BasicManager::LoadBasicManager( SotStorage& rStorage, std::u16string_view rBaseURL )
{
- tools::SvRef<SotStorageStream> xManagerStream = rStorage.OpenSotStream( szManagerStream, eStreamReadMode );
+ rtl::Reference<SotStorageStream> xManagerStream = rStorage.OpenSotStream( szManagerStream, eStreamReadMode );
OUString aStorName( rStorage.GetName() );
// #i13114 removed, DBG_ASSERT( aStorName.Len(), "No Storage Name!" );
@@ -647,7 +649,7 @@ void BasicManager::LoadBasicManager( SotStorage& rStorage, const OUString& rBase
OUString aRealStorageName = maStorageName; // for relative paths, can be modified through BaseURL
- if ( !rBaseURL.isEmpty() )
+ if ( !rBaseURL.empty() )
{
INetURLObject aObj( rBaseURL );
if ( aObj.GetProtocol() == INetProtocol::File )
@@ -723,7 +725,7 @@ void BasicManager::LoadBasicManager( SotStorage& rStorage, const OUString& rBase
void BasicManager::LoadOldBasicManager( SotStorage& rStorage )
{
- tools::SvRef<SotStorageStream> xManagerStream = rStorage.OpenSotStream( szOldManagerStream, eStreamReadMode );
+ rtl::Reference<SotStorageStream> xManagerStream = rStorage.OpenSotStream( szOldManagerStream, eStreamReadMode );
OUString aStorName( rStorage.GetName() );
DBG_ASSERT( aStorName.getLength(), "No Storage Name!" );
@@ -745,8 +747,8 @@ void BasicManager::LoadOldBasicManager( SotStorage& rStorage )
xManagerStream->Seek( nBasicStartOff );
if (!ImplLoadBasic( *xManagerStream, maLibs.front()->GetLibRef() ))
{
- StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_MGROPEN, aStorName, DialogMask::ButtonsOk );
- aErrors.emplace_back(*pErrInf, BasicErrorReason::OPENMGRSTREAM);
+ ErrCodeMsg aErrInf( ERRCODE_BASMGR_MGROPEN, aStorName, DialogMask::ButtonsOk );
+ aErrors.emplace_back(aErrInf);
// and it proceeds ...
}
xManagerStream->Seek( nBasicEndOff+1 ); // +1: 0x00 as separator
@@ -776,7 +778,7 @@ void BasicManager::LoadOldBasicManager( SotStorage& rStorage )
aLibRelStorage = aLibRelStorage.smartRel2Abs( aLibRelStorageName, bWasAbsolute);
DBG_ASSERT(!bWasAbsolute, "RelStorageName was absolute!" );
- tools::SvRef<SotStorage> xStorageRef;
+ rtl::Reference<SotStorage> xStorageRef;
if ( aLibAbsStorage == aCurStorage || aLibRelStorageName == szImbedded )
{
xStorageRef = &rStorage;
@@ -795,8 +797,8 @@ void BasicManager::LoadOldBasicManager( SotStorage& rStorage )
}
else
{
- StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_LIBLOAD, aStorName, DialogMask::ButtonsOk );
- aErrors.emplace_back(*pErrInf, BasicErrorReason::STORAGENOTFOUND);
+ ErrCodeMsg aErrInf( ERRCODE_BASMGR_LIBLOAD, aStorName, DialogMask::ButtonsOk );
+ aErrors.emplace_back(aErrInf);
}
} while (nLibPos>=0);
}
@@ -837,7 +839,7 @@ bool BasicManager::ImpLoadLibrary( BasicLibInfo* pLibInfo, SotStorage* pCurStora
{
aStorageName = GetStorageName();
}
- tools::SvRef<SotStorage> xStorage;
+ rtl::Reference<SotStorage> xStorage;
// The current must not be opened again...
if ( pCurStorage )
{
@@ -860,21 +862,21 @@ bool BasicManager::ImpLoadLibrary( BasicLibInfo* pLibInfo, SotStorage* pCurStora
{
xStorage = new SotStorage( false, aStorageName, eStorageReadMode );
}
- tools::SvRef<SotStorage> xBasicStorage = xStorage->OpenSotStorage( szBasicStorage, eStorageReadMode, false );
+ rtl::Reference<SotStorage> xBasicStorage = xStorage->OpenSotStorage( szBasicStorage, eStorageReadMode, false );
if ( !xBasicStorage.is() || xBasicStorage->GetError() )
{
- StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_MGROPEN, xStorage->GetName(), DialogMask::ButtonsOk );
- aErrors.emplace_back(*pErrInf, BasicErrorReason::OPENLIBSTORAGE);
+ ErrCodeMsg aErrInf( ERRCODE_BASMGR_MGROPEN, xStorage->GetName(), DialogMask::ButtonsOk );
+ aErrors.emplace_back(aErrInf);
}
else
{
// In the Basic-Storage every lib is in a Stream...
- tools::SvRef<SotStorageStream> xBasicStream = xBasicStorage->OpenSotStream( pLibInfo->GetLibName(), eStreamReadMode );
+ rtl::Reference<SotStorageStream> xBasicStream = xBasicStorage->OpenSotStream( pLibInfo->GetLibName(), eStreamReadMode );
if ( !xBasicStream.is() || xBasicStream->GetError() )
{
- StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_LIBLOAD , pLibInfo->GetLibName(), DialogMask::ButtonsOk );
- aErrors.emplace_back(*pErrInf, BasicErrorReason::OPENLIBSTREAM);
+ ErrCodeMsg aErrInf( ERRCODE_BASMGR_LIBLOAD , pLibInfo->GetLibName(), DialogMask::ButtonsOk );
+ aErrors.emplace_back(aErrInf);
}
else
{
@@ -896,8 +898,8 @@ bool BasicManager::ImpLoadLibrary( BasicLibInfo* pLibInfo, SotStorage* pCurStora
}
if ( !bLoaded )
{
- StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_LIBLOAD, pLibInfo->GetLibName(), DialogMask::ButtonsOk );
- aErrors.emplace_back(*pErrInf, BasicErrorReason::BASICLOADERROR);
+ ErrCodeMsg aErrInf( ERRCODE_BASMGR_LIBLOAD, pLibInfo->GetLibName(), DialogMask::ButtonsOk );
+ aErrors.emplace_back(aErrInf);
}
else
{
@@ -1080,8 +1082,8 @@ bool BasicManager::RemoveLib( sal_uInt16 nLib, bool bDelBasicFromStorage )
if( !nLib || nLib < maLibs.size() )
{
- StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_REMOVELIB, OUString(), DialogMask::ButtonsOk );
- aErrors.emplace_back(*pErrInf, BasicErrorReason::STDLIB);
+ ErrCodeMsg aErrInf( ERRCODE_BASMGR_REMOVELIB, OUString(), DialogMask::ButtonsOk );
+ aErrors.emplace_back(aErrInf);
return false;
}
@@ -1092,7 +1094,7 @@ bool BasicManager::RemoveLib( sal_uInt16 nLib, bool bDelBasicFromStorage )
if (bDelBasicFromStorage && !(*itLibInfo)->IsReference() &&
(!(*itLibInfo)->IsExtern() || SotStorage::IsStorageFile((*itLibInfo)->GetStorageName())))
{
- tools::SvRef<SotStorage> xStorage;
+ rtl::Reference<SotStorage> xStorage;
try
{
if (!(*itLibInfo)->IsExtern())
@@ -1111,13 +1113,13 @@ bool BasicManager::RemoveLib( sal_uInt16 nLib, bool bDelBasicFromStorage )
if (xStorage.is() && xStorage->IsStorage(szBasicStorage))
{
- tools::SvRef<SotStorage> xBasicStorage = xStorage->OpenSotStorage
+ rtl::Reference<SotStorage> xBasicStorage = xStorage->OpenSotStorage
( szBasicStorage, StreamMode::STD_READWRITE, false );
if ( !xBasicStorage.is() || xBasicStorage->GetError() )
{
- StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_REMOVELIB, OUString(), DialogMask::ButtonsOk );
- aErrors.emplace_back(*pErrInf, BasicErrorReason::OPENLIBSTORAGE);
+ ErrCodeMsg aErrInf( ERRCODE_BASMGR_REMOVELIB, OUString(), DialogMask::ButtonsOk );
+ aErrors.emplace_back(aErrInf);
}
else if (xBasicStorage->IsStream((*itLibInfo)->GetLibName()))
{
@@ -1214,14 +1216,14 @@ bool BasicManager::HasLib( std::u16string_view rName ) const
return false;
}
-OUString BasicManager::GetLibName( sal_uInt16 nLib )
+const OUString & BasicManager::GetLibName( sal_uInt16 nLib )
{
DBG_ASSERT( nLib < maLibs.size(), "Lib?!" );
if ( nLib < maLibs.size() )
{
return maLibs[nLib]->GetLibName();
}
- return OUString();
+ return EMPTY_OUSTRING;
}
bool BasicManager::LoadLib( sal_uInt16 nLib )
@@ -1251,8 +1253,8 @@ bool BasicManager::LoadLib( sal_uInt16 nLib )
}
else
{
- StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_LIBLOAD, OUString(), DialogMask::ButtonsOk );
- aErrors.emplace_back(*pErrInf, BasicErrorReason::LIBNOTFOUND);
+ ErrCodeMsg aErrInf( ERRCODE_BASMGR_LIBLOAD, OUString(), DialogMask::ButtonsOk );
+ aErrors.emplace_back(aErrInf);
}
return bDone;
}
@@ -1285,7 +1287,7 @@ StarBASIC* BasicManager::CreateLib( const OUString& rLibName, const OUString& Pa
{
try
{
- tools::SvRef<SotStorage> xStorage = new SotStorage(false, LinkTargetURL, StreamMode::READ | StreamMode::SHARE_DENYWRITE);
+ rtl::Reference<SotStorage> xStorage = new SotStorage(false, LinkTargetURL, StreamMode::READ | StreamMode::SHARE_DENYWRITE);
if (!xStorage->GetError())
{
pLib = AddLib(*xStorage, rLibName, true);
@@ -1366,28 +1368,27 @@ bool BasicManager::GetGlobalUNOConstant( const OUString& rName, uno::Any& aOut )
return bRes;
}
-uno::Any BasicManager::SetGlobalUNOConstant( const OUString& rName, const uno::Any& _rValue )
+void BasicManager::SetGlobalUNOConstant( const OUString& rName, const uno::Any& _rValue, css::uno::Any* pOldValue )
{
- uno::Any aOldValue;
-
StarBASIC* pStandardLib = GetStdLib();
OSL_PRECOND( pStandardLib, "BasicManager::SetGlobalUNOConstant: no lib to insert into!" );
if ( !pStandardLib )
- return aOldValue;
+ return;
- // obtain the old value
- SbxVariable* pVariable = pStandardLib->Find( rName, SbxClassType::Object );
- if ( pVariable )
- aOldValue = sbxToUnoValue( pVariable );
- SbxObjectRef xUnoObj = GetSbUnoObject( _rValue.getValueType ().getTypeName () , _rValue );
+ if (pOldValue)
+ {
+ // obtain the old value
+ SbxVariable* pVariable = pStandardLib->Find( rName, SbxClassType::Object );
+ if ( pVariable )
+ *pOldValue = sbxToUnoValue( pVariable );
+ }
+ SbxObjectRef xUnoObj = GetSbUnoObject( _rValue.getValueTypeName () , _rValue );
xUnoObj->SetName(rName);
xUnoObj->SetFlag( SbxFlagBits::DontStore );
pStandardLib->Insert( xUnoObj.get() );
-
- return aOldValue;
}
-bool BasicManager::LegacyPsswdBinaryLimitExceeded( std::vector< OUString >& _out_rModuleNames )
+bool BasicManager::ImgVersion12PsswdBinaryLimitExceeded( std::vector< OUString >& _out_rModuleNames )
{
try
{
@@ -1406,19 +1407,16 @@ bool BasicManager::LegacyPsswdBinaryLimitExceeded( std::vector< OUString >& _out
uno::Reference< container::XNameAccess > xScriptLibrary( xScripts->getByName( scriptElementName ), uno::UNO_QUERY_THROW );
const uno::Sequence< OUString > aElementNames( xScriptLibrary->getElementNames() );
- sal_Int32 nLen = aElementNames.getLength();
-
- std::vector< OUString > aBigModules( nLen );
- sal_Int32 nBigModules = 0;
+ std::vector<OUString> aBigModules;
for ( auto const & libraryElementName : aElementNames )
{
SbModule* pMod = pBasicLib->FindModule( libraryElementName );
- if ( pMod && pMod->ExceedsLegacyModuleSize() )
- aBigModules[ nBigModules++ ] = libraryElementName;
+ if ( pMod && pMod->ExceedsImgVersion12ModuleSize() )
+ aBigModules.push_back(libraryElementName);
}
- if ( nBigModules )
+ if (!aBigModules.empty())
{
_out_rModuleNames.swap(aBigModules);
return true;
@@ -1537,9 +1535,9 @@ ErrCode BasicManager::ExecuteMacro( OUString const& i_fullyQualifiedName, std::u
sal_Int32 nPos {0};
for (;;)
{
- aBuff.append( "\"" );
- aBuff.append( sArgs2.getToken(0, ',', nPos) );
- aBuff.append( "\"" );
+ aBuff.append( OUString::Concat("\"")
+ + o3tl::getToken(sArgs2, 0, ',', nPos)
+ + "\"" );
if (nPos<0)
break;
aBuff.append( "," );
@@ -1573,8 +1571,8 @@ class ModuleInfo_Impl : public ModuleInfoHelper
OUString maSource;
public:
- ModuleInfo_Impl( const OUString& aName, const OUString& aLanguage, const OUString& aSource )
- : maName( aName ), maLanguage( aLanguage), maSource( aSource ) {}
+ ModuleInfo_Impl( OUString aName, OUString aLanguage, OUString aSource )
+ : maName(std::move( aName )), maLanguage(std::move( aLanguage)), maSource(std::move( aSource )) {}
// Methods XStarBasicModuleInfo
virtual OUString SAL_CALL getName() override
@@ -1592,8 +1590,8 @@ class DialogInfo_Impl : public WeakImplHelper< script::XStarBasicDialogInfo >
uno::Sequence< sal_Int8 > mData;
public:
- DialogInfo_Impl( const OUString& aName, const uno::Sequence< sal_Int8 >& Data )
- : maName( aName ), mData( Data ) {}
+ DialogInfo_Impl( OUString aName, const uno::Sequence< sal_Int8 >& Data )
+ : maName(std::move( aName )), mData( Data ) {}
// Methods XStarBasicDialogInfo
virtual OUString SAL_CALL getName() override
@@ -1615,19 +1613,19 @@ class LibraryInfo_Impl : public WeakImplHelper< script::XStarBasicLibraryInfo >
public:
LibraryInfo_Impl
(
- const OUString& aName,
- uno::Reference< container::XNameContainer > const & xModuleContainer,
- uno::Reference< container::XNameContainer > const & xDialogContainer,
- const OUString& aPassword,
- const OUString& aExternaleSourceURL,
- const OUString& aLinkTargetURL
+ OUString aName,
+ uno::Reference< container::XNameContainer > xModuleContainer,
+ uno::Reference< container::XNameContainer > xDialogContainer,
+ OUString aPassword,
+ OUString aExternaleSourceURL,
+ OUString aLinkTargetURL
)
- : maName( aName )
- , mxModuleContainer( xModuleContainer )
- , mxDialogContainer( xDialogContainer )
- , maPassword( aPassword )
- , maExternaleSourceURL( aExternaleSourceURL )
- , maLinkTargetURL( aLinkTargetURL )
+ : maName(std::move( aName ))
+ , mxModuleContainer(std::move( xModuleContainer ))
+ , mxDialogContainer(std::move( xDialogContainer ))
+ , maPassword(std::move( aPassword ))
+ , maExternaleSourceURL(std::move( aExternaleSourceURL ))
+ , maLinkTargetURL(std::move( aLinkTargetURL ))
{}
// Methods XStarBasicLibraryInfo
@@ -1691,7 +1689,7 @@ uno::Any ModuleContainer_Impl::getByName( const OUString& aName )
SbModule* pMod = mpLib ? mpLib->FindModule( aName ) : nullptr;
if( !pMod )
throw container::NoSuchElementException();
- uno::Reference< script::XStarBasicModuleInfo > xMod = new ModuleInfo_Impl( aName, "StarBasic", pMod->GetSource32() );
+ uno::Reference< script::XStarBasicModuleInfo > xMod = new ModuleInfo_Impl( aName, u"StarBasic"_ustr, pMod->GetSource32() );
uno::Any aRetAny;
aRetAny <<= xMod;
return aRetAny;
@@ -1732,7 +1730,7 @@ void ModuleContainer_Impl::insertByName( const OUString& aName, const uno::Any&
const uno::Type& aAnyType = aElement.getValueType();
if( aModuleType != aAnyType )
{
- throw lang::IllegalArgumentException("types do not match", static_cast<cppu::OWeakObject*>(this), 2);
+ throw lang::IllegalArgumentException(u"types do not match"_ustr, getXWeak(), 2);
}
uno::Reference< script::XStarBasicModuleInfo > xMod;
aElement >>= xMod;
@@ -1759,7 +1757,7 @@ static uno::Sequence< sal_Int8 > implGetDialogData( SbxObject* pDialog )
uno::Sequence< sal_Int8 > aData( nLen );
sal_Int8* pDestData = aData.getArray();
const sal_Int8* pSrcData = static_cast<const sal_Int8*>(aMemStream.GetData());
- memcpy( pDestData, pSrcData, nLen );
+ std::copy( pSrcData, pSrcData + nLen, pDestData );
return aData;
}
@@ -1896,7 +1894,7 @@ void DialogContainer_Impl::insertByName( const OUString&, const uno::Any& aEleme
const uno::Type& aAnyType = aElement.getValueType();
if( aModuleType != aAnyType )
{
- throw lang::IllegalArgumentException("types do not match", static_cast<cppu::OWeakObject*>(this), 2);
+ throw lang::IllegalArgumentException(u"types do not match"_ustr, getXWeak(), 2);
}
uno::Reference< script::XStarBasicDialogInfo > xMod;
aElement >>= xMod;
@@ -2048,7 +2046,7 @@ typedef WeakImplHelper< script::XStarBasicAccess > StarBasicAccessHelper;
class StarBasicAccess_Impl : public StarBasicAccessHelper
{
BasicManager* mpMgr;
- uno::Reference< container::XNameContainer > mxLibContainer;
+ rtl::Reference< LibraryContainer_Impl > mxLibContainer;
public:
explicit StarBasicAccess_Impl( BasicManager* pMgr )
diff --git a/basic/source/basmgr/vbahelper.cxx b/basic/source/basmgr/vbahelper.cxx
index 7fa101a8259e..caccb9bfc16e 100644
--- a/basic/source/basmgr/vbahelper.cxx
+++ b/basic/source/basmgr/vbahelper.cxx
@@ -21,6 +21,7 @@
#include <basic/vbahelper.hxx>
#include <map>
+#include <mutex>
#include <vector>
#include <com/sun/star/container/XEnumeration.hpp>
#include <com/sun/star/frame/Desktop.hpp>
@@ -140,7 +141,7 @@ void lclIterateDocuments( ModifyDocumentFunc pModifyDocumentFunc, const uno::Ref
struct CurrDirPool
{
- ::osl::Mutex maMutex;
+ std::mutex maMutex;
std::map< OUString, OUString > maCurrDirs;
};
@@ -167,7 +168,7 @@ void registerCurrentDirectory( const uno::Reference< frame::XModel >& rxModel, c
static CurrDirPool StaticCurrDirPool;
CurrDirPool& rPool = StaticCurrDirPool;
- ::osl::MutexGuard aGuard( rPool.maMutex );
+ std::unique_lock aGuard( rPool.maMutex );
try
{
uno::Reference< frame::XModuleManager2 > xModuleManager( lclCreateModuleManager() );
diff --git a/basic/source/classes/codecompletecache.cxx b/basic/source/classes/codecompletecache.cxx
index 8f03797c32dd..26275b570306 100644
--- a/basic/source/classes/codecompletecache.cxx
+++ b/basic/source/classes/codecompletecache.cxx
@@ -146,7 +146,7 @@ void CodeCompleteDataCache::InsertLocalVar( const OUString& sProcName, const OUS
{
CodeCompleteVarTypes aTypes = aVarScopes[ sProcName ];
aTypes.emplace( sVarName, sVarType );
- aVarScopes[ sProcName ] = aTypes;
+ aVarScopes[ sProcName ] = std::move(aTypes);
}
}
diff --git a/basic/source/classes/errobject.cxx b/basic/source/classes/errobject.cxx
index 85423101b827..b2340fe3fc54 100644
--- a/basic/source/classes/errobject.cxx
+++ b/basic/source/classes/errobject.cxx
@@ -156,13 +156,13 @@ ErrObject::Raise( const uno::Any& Number, const uno::Any& Source, const uno::Any
OUString SAL_CALL
ErrObject::getDefaultPropertyName( )
{
- return "Number";
+ return u"Number"_ustr;
}
void ErrObject::setData( const uno::Any& Number, const uno::Any& Source, const uno::Any& Description, const uno::Any& HelpFile, const uno::Any& HelpContext )
{
if ( !Number.hasValue() )
- throw uno::RuntimeException("Missing Required Parameter" );
+ throw uno::RuntimeException(u"Missing Required Parameter"_ustr );
Number >>= m_nNumber;
Description >>= m_sDescription;
Source >>= m_sSource;
@@ -202,7 +202,7 @@ SbxErrObject::getErrObject()
static std::mutex aMutex;
std::scoped_lock aGuard(aMutex);
if (!rGlobErr)
- rGlobErr = new SbxErrObject("Err",
+ rGlobErr = new SbxErrObject(u"Err"_ustr,
uno::Any(uno::Reference<vba::XErrObject>(new ErrObject())));
}
return rGlobErr;
diff --git a/basic/source/classes/eventatt.cxx b/basic/source/classes/eventatt.cxx
index 6489d88d8339..2e5142b21fc7 100644
--- a/basic/source/classes/eventatt.cxx
+++ b/basic/source/classes/eventatt.cxx
@@ -39,7 +39,7 @@
#include <basic/basmgr.hxx>
#include <sal/log.hxx>
-#include <tools/diagnose_ex.h>
+#include <comphelper/diagnose_ex.hxx>
#include <vcl/svapp.hxx>
#include <sbunoobj.hxx>
#include <basic/sberrors.hxx>
@@ -58,7 +58,6 @@ using namespace ::com::sun::star::script;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::container;
-using namespace ::com::sun::star::reflection;
using namespace ::com::sun::star::awt;
using namespace ::com::sun::star::io;
using namespace ::cppu;
@@ -80,13 +79,13 @@ void SFURL_firing_impl( const ScriptEvent& aScriptEvent, Any* pRet, const Refere
}
else
{
- Reference< XComponentContext > xContext(
+ const Reference< XComponentContext >& xContext(
comphelper::getProcessComponentContext() );
Reference< provider::XScriptProviderFactory > xFactory =
provider::theMasterScriptProviderFactory::get( xContext );
Any aCtx;
- aCtx <<= OUString("user");
+ aCtx <<= u"user"_ustr;
xScriptProvider = xFactory->createScriptProvider( aCtx );
}
@@ -113,7 +112,7 @@ void SFURL_firing_impl( const ScriptEvent& aScriptEvent, Any* pRet, const Refere
Any result = xScript->invoke( inArgs, outIndex, outArgs );
if ( pRet )
{
- *pRet = result;
+ *pRet = std::move(result);
}
}
catch ( const RuntimeException& )
@@ -184,13 +183,13 @@ void BasicScriptListener_Impl::firing_impl( const ScriptEvent& aScriptEvent, Any
if( comphelper::string::getTokenCount(aMacro, '.') == 3 )
{
sal_Int32 nLast = 0;
- OUString aFullLibName = aMacro.getToken( 0, '.', nLast );
+ std::u16string_view aFullLibName = o3tl::getToken(aMacro, 0, '.', nLast );
- sal_Int32 nIndex = aFullLibName.indexOf( ':' );
- if (nIndex >= 0)
+ size_t nIndex = aFullLibName.find( ':' );
+ if (nIndex != std::u16string_view::npos)
{
- aLocation = aFullLibName.copy( 0, nIndex );
- aLibName = aFullLibName.copy( nIndex + 1 );
+ aLocation = aFullLibName.substr( 0, nIndex );
+ aLibName = aFullLibName.substr( nIndex + 1 );
}
aMacro = aMacro.copy( nLast );
@@ -227,11 +226,11 @@ void BasicScriptListener_Impl::firing_impl( const ScriptEvent& aScriptEvent, Any
StarBASICRef xLibSearchBasic;
if( aLocation == "application" )
{
- xLibSearchBasic = xAppStandardBasic;
+ xLibSearchBasic = std::move(xAppStandardBasic);
}
else if( aLocation == "document" )
{
- xLibSearchBasic = xDocStandardBasic;
+ xLibSearchBasic = std::move(xDocStandardBasic);
}
else
{
@@ -319,7 +318,7 @@ css::uno::Reference< css::container::XNameContainer > implFindDialogLibForDialog
{
css::uno::Reference< css::container::XNameContainer > aRetDlgLib;
- SbxVariable* pDlgLibContVar = pBasic->Find("DialogLibraries", SbxClassType::Object);
+ SbxVariable* pDlgLibContVar = pBasic->Find(u"DialogLibraries"_ustr, SbxClassType::Object);
if( auto pDlgLibContUnoObj = dynamic_cast<SbUnoObject*>( pDlgLibContVar) )
{
Any aDlgLibContAny = pDlgLibContUnoObj->getUnoAny();
@@ -406,7 +405,7 @@ css::uno::Reference< css::container::XNameContainer > implFindDialogLibForDialog
void RTL_Impl_CreateUnoDialog( SbxArray& rPar )
{
- Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() );
+ const Reference< XComponentContext >& xContext( comphelper::getProcessComponentContext() );
// We need at least 1 parameter
if (rPar.Count() < 2)
@@ -424,7 +423,7 @@ void RTL_Impl_CreateUnoDialog( SbxArray& rPar )
return;
}
Any aAnyISP = pUnoObj->getUnoAny();
- TypeClass eType = aAnyISP.getValueType().getTypeClass();
+ TypeClass eType = aAnyISP.getValueTypeClass();
if( eType != TypeClass_INTERFACE )
{
@@ -434,7 +433,7 @@ void RTL_Impl_CreateUnoDialog( SbxArray& rPar )
// Create new uno dialog
Reference< XNameContainer > xDialogModel( xContext->getServiceManager()->createInstanceWithContext(
- "com.sun.star.awt.UnoControlDialogModel", xContext), UNO_QUERY );
+ u"com.sun.star.awt.UnoControlDialogModel"_ustr, xContext), UNO_QUERY );
if( !xDialogModel.is() )
{
return;
@@ -456,13 +455,13 @@ void RTL_Impl_CreateUnoDialog( SbxArray& rPar )
try
{
bool bDecoration = true;
- OUString aDecorationPropName("Decoration");
+ OUString aDecorationPropName(u"Decoration"_ustr);
Any aDecorationAny = xDlgModPropSet->getPropertyValue( aDecorationPropName );
aDecorationAny >>= bDecoration;
if( !bDecoration )
{
xDlgModPropSet->setPropertyValue( aDecorationPropName, Any( true ) );
- xDlgModPropSet->setPropertyValue( "Title", Any( OUString() ) );
+ xDlgModPropSet->setPropertyValue( u"Title"_ustr, Any( OUString() ) );
}
}
catch(const UnknownPropertyException& )
@@ -500,7 +499,7 @@ void RTL_Impl_CreateUnoDialog( SbxArray& rPar )
if ( aDlgLib.is() )
{
bDocDialog = true;
- xModel = xNextModel;
+ xModel = std::move(xNextModel);
break;
}
}
diff --git a/basic/source/classes/image.cxx b/basic/source/classes/image.cxx
index 229dc8058518..1e12cf725a79 100644
--- a/basic/source/classes/image.cxx
+++ b/basic/source/classes/image.cxx
@@ -30,6 +30,7 @@
#include <codegen.hxx>
#include <memory>
#include <string_view>
+#include <algorithm>
SbiImage::SbiImage()
: bError(false)
@@ -124,11 +125,11 @@ bool SbiImage::Load( SvStream& r, sal_uInt32& nVersion )
nFlags = static_cast<SbiImageFlags>(nTmpFlags);
eCharSet = nCharSet;
eCharSet = GetSOLoadTextEncoding( eCharSet );
- bBadVer = ( nVersion > B_CURVERSION );
+ bBadVer = ( nVersion > B_IMG_VERSION_13 );
nDimBase = static_cast<sal_uInt16>(lDimBase);
}
- bool bLegacy = ( nVersion < B_EXT_IMG_VERSION );
+ bool bLegacy = ( nVersion < B_IMG_VERSION_12 );
sal_uInt64 nNext;
while( ( nNext = r.Tell() ) < nLast )
@@ -228,7 +229,7 @@ bool SbiImage::Load( SvStream& r, sal_uInt32& nVersion )
if (GetToUnicodePoolData(r, nLen, nNext))
{
OUString s = read_uInt16s_ToOUString(r, nLen);
- memcpy(pStrings.get(), s.getStr(), s.getLength() * sizeof(sal_Unicode));
+ std::copy_n(s.getStr(), s.getLength(), pStrings.get());
}
else
{
@@ -238,7 +239,8 @@ bool SbiImage::Load( SvStream& r, sal_uInt32& nVersion )
{
sal_uInt16 nOff2 = static_cast<sal_uInt16>(mvStringOffsets[j]);
OUString aStr(pByteStrings.get() + nOff2, strlen(pByteStrings.get() + nOff2), eCharSet);
- memcpy(pStrings.get() + nOff2, aStr.getStr(), (aStr.getLength() + 1) * sizeof(sal_Unicode));
+ std::copy_n(aStr.getStr(), aStr.getLength() + 1,
+ pStrings.get() + nOff2);
}
}
}
@@ -343,8 +345,8 @@ bool SbiImage::Load( SvStream& r, sal_uInt32& nVersion )
}
- pType->Remove( "Name", SbxClassType::DontCare );
- pType->Remove( "Parent", SbxClassType::DontCare );
+ pType->Remove( u"Name"_ustr, SbxClassType::DontCare );
+ pType->Remove( u"Parent"_ustr, SbxClassType::DontCare );
AddType(pType);
}
@@ -373,31 +375,13 @@ done:
bool SbiImage::Save( SvStream& r, sal_uInt32 nVer )
{
- bool bLegacy = ( nVer < B_EXT_IMG_VERSION );
-
- // detect if old code exceeds legacy limits
- // if so, then disallow save
- if ( bLegacy && ExceedsLegacyLimits() )
- {
- SbiImage aEmptyImg;
- aEmptyImg.aName = aName;
- aEmptyImg.Save( r, B_LEGACYVERSION );
- return true;
- }
// First of all the header
sal_uInt64 nStart = SbiOpenRecord( r, FileOffset::Module, 1 );
sal_uInt64 nPos;
eCharSet = GetSOStoreTextEncoding( eCharSet );
- if ( bLegacy )
- {
- r.WriteInt32( B_LEGACYVERSION );
- }
- else
- {
- r.WriteInt32( B_CURVERSION );
- }
- r .WriteInt32( eCharSet )
+ r .WriteInt32( nVer )
+ .WriteInt32( eCharSet )
.WriteInt32( nDimBase )
.WriteInt16( static_cast<sal_uInt16>(nFlags) )
.WriteInt16( 0 )
@@ -429,17 +413,7 @@ bool SbiImage::Save( SvStream& r, sal_uInt32 nVer )
if (aCode.size() && r.good())
{
nPos = SbiOpenRecord( r, FileOffset::PCode, 1 );
- if ( bLegacy )
- {
- PCodeBuffConvertor<sal_uInt32, sal_uInt16> aNewToLegacy(aCode.data(), aCode.size());
- aNewToLegacy.convert();
- aLegacyPCode = aNewToLegacy.GetBuffer();
- r.WriteBytes(aLegacyPCode.data(), aLegacyPCode.size());
- }
- else
- {
- r.WriteBytes(aCode.data(), aCode.size());
- }
+ r.WriteBytes(aCode.data(), aCode.size());
SbiCloseRecord( r, nPos );
}
// String-Pool?
@@ -458,7 +432,7 @@ bool SbiImage::Save( SvStream& r, sal_uInt32 nVer )
{
sal_uInt16 nOff = static_cast<sal_uInt16>(mvStringOffsets[ i ]);
OString aStr(OUStringToOString(std::u16string_view(pStrings.get() + nOff), eCharSet));
- memcpy( pByteStrings.get() + nOff, aStr.getStr(), (aStr.getLength() + 1) * sizeof( char ) );
+ std::copy_n(aStr.getStr(), aStr.getLength() + 1, pByteStrings.get() + nOff);
}
r.WriteUInt32( nStringSize );
r.WriteBytes(pByteStrings.get(), nStringSize);
@@ -468,7 +442,8 @@ bool SbiImage::Save( SvStream& r, sal_uInt32 nVer )
// old readers will not read this data after having read legacy data, and will proceed
// straight to the end of the record. So no version restriction here.
r.WriteUInt32(nUnicodeDataMagicNumber);
- write_uInt16s_FromOUString(r, std::u16string_view(pStrings.get(), nStringSize));
+ r.WriteUnicodeOrByteText(std::u16string_view(pStrings.get(), nStringSize),
+ RTL_TEXTENCODING_UNICODE);
SbiCloseRecord( r, nPos );
}
@@ -578,7 +553,7 @@ void SbiImage::MakeStrings( short nSize )
// growing in 1K-Steps
void SbiImage::AddString( const OUString& r )
{
- if( nStringIdx >= short(mvStringOffsets.size()) )
+ if( nStringIdx >= mvStringOffsets.size() )
{
bError = true;
}
@@ -596,17 +571,17 @@ void SbiImage::AddString( const OUString& r )
sal_uInt32 nNewLen = needed + 1024;
nNewLen &= 0xFFFFFC00; // trim to 1K border
std::unique_ptr<sal_Unicode[]> p(new sal_Unicode[nNewLen]);
- memcpy( p.get(), pStrings.get(), nStringSize * sizeof( sal_Unicode ) );
+ std::copy_n(pStrings.get(), nStringSize, p.get());
pStrings = std::move(p);
nStringSize = sal::static_int_cast< sal_uInt16 >(nNewLen);
}
if( !bError )
{
mvStringOffsets[ nStringIdx++ ] = nStringOff;
- memcpy( pStrings.get() + nStringOff, r.getStr(), len * sizeof( sal_Unicode ) );
+ std::copy_n(r.getStr(), len, pStrings.get() + nStringOff);
nStringOff = nStringOff + len;
// Last String? The update the size of the buffer
- if( nStringIdx >= short(mvStringOffsets.size()) )
+ if( nStringIdx >= mvStringOffsets.size() )
{
nStringSize = nStringOff;
}
@@ -643,14 +618,14 @@ void SbiImage::AddEnum(SbxObject* pObject) // Register enum type
}
// Note: IDs start with 1
-OUString SbiImage::GetString( short nId, SbxDataType *eType ) const
+OUString SbiImage::GetString( sal_uInt32 nId, SbxDataType *eType ) const
{
- if( nId && nId <= short(mvStringOffsets.size()) )
+ if( nId && nId <= mvStringOffsets.size() )
{
sal_uInt32 nOff = mvStringOffsets[ nId - 1 ];
sal_Unicode* pStr = pStrings.get() + nOff;
- sal_uInt32 nNextOff = (nId < short(mvStringOffsets.size())) ? mvStringOffsets[ nId ] : nStringSize;
+ sal_uInt32 nNextOff = (nId < mvStringOffsets.size()) ? mvStringOffsets[ nId ] : nStringSize;
sal_uInt32 nLen = nNextOff - nOff - 1;
// #i42467: Special treatment for vbNullChar
if (*pStr == 0)
@@ -715,4 +690,10 @@ bool SbiImage::ExceedsLegacyLimits()
return (nStringSize > 0xFF00) || (CalcLegacyOffset(aCode.size()) > 0xFF00);
}
+bool SbiImage::ExceedsImgVersion12Limits()
+{
+ const sal_Int16 nMax = std::numeric_limits<sal_Int16>::max();
+ return nStringSize >= nMax || CalcLegacyOffset(aCode.size()) >= nMax;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/classes/propacc.cxx b/basic/source/classes/propacc.cxx
index 06bba39073d7..bfee62092e31 100644
--- a/basic/source/classes/propacc.cxx
+++ b/basic/source/classes/propacc.cxx
@@ -54,17 +54,10 @@ Reference< XPropertySetInfo > SbPropertyValues::getPropertySetInfo()
// create on demand?
if (!m_xInfo.is())
{
- uno::Sequence<beans::Property> props(m_aPropVals.size());
- for (size_t n = 0; n < m_aPropVals.size(); ++n)
- {
- Property &rProp = props.getArray()[n];
- const PropertyValue &rPropVal = m_aPropVals[n];
- rProp.Name = rPropVal.Name;
- rProp.Handle = rPropVal.Handle;
- rProp.Type = cppu::UnoType<void>::get();
- rProp.Attributes = 0;
- }
- m_xInfo.set(new ::comphelper::PropertySetInfo(props));
+ assert(m_aPropInfos.empty());
+ for (auto const& it : m_aPropVals)
+ m_aPropInfos.emplace_back(it.Name, it.Handle, cppu::UnoType<void>::get(), 0, 0);
+ m_xInfo.set(new ::comphelper::PropertySetInfo(m_aPropInfos));
}
return m_xInfo;
}
@@ -136,12 +129,9 @@ Sequence< PropertyValue > SbPropertyValues::getPropertyValues()
void SbPropertyValues::setPropertyValues(const Sequence< PropertyValue >& rPropertyValues )
{
if (!m_aPropVals.empty())
- throw IllegalArgumentException("m_aPropVals not empty", static_cast<cppu::OWeakObject*>(this), -1);
+ throw IllegalArgumentException(u"m_aPropVals not empty"_ustr, getXWeak(), -1);
- for (const PropertyValue& i : rPropertyValues)
- {
- m_aPropVals.push_back(i);
- }
+ m_aPropVals.insert(m_aPropVals.end(), rPropertyValues.begin(), rPropertyValues.end());
}
@@ -157,26 +147,23 @@ void RTL_Impl_CreatePropertySet( SbxArray& rPar )
// Get class names of struct
- Reference< XInterface > xInterface = static_cast<OWeakObject*>(new SbPropertyValues());
+ Reference xInterface(getXWeak(new SbPropertyValues()));
SbxVariableRef refVar = rPar.Get(0);
- if( xInterface.is() )
+ // Set PropertyValues
+ Any aArgAsAny = sbxToUnoValue(rPar.Get(1),
+ cppu::UnoType<Sequence<PropertyValue>>::get() );
+ auto pArg = o3tl::doAccess<Sequence<PropertyValue>>(aArgAsAny);
+ Reference< XPropertyAccess > xPropAcc( xInterface, UNO_QUERY );
+ xPropAcc->setPropertyValues( *pArg );
+
+ // Build a SbUnoObject and return it
+ auto xUnoObj = tools::make_ref<SbUnoObject>( "stardiv.uno.beans.PropertySet", Any(xInterface) );
+ if( xUnoObj->getUnoAny().hasValue() )
{
- // Set PropertyValues
- Any aArgAsAny = sbxToUnoValue(rPar.Get(1),
- cppu::UnoType<Sequence<PropertyValue>>::get() );
- auto pArg = o3tl::doAccess<Sequence<PropertyValue>>(aArgAsAny);
- Reference< XPropertyAccess > xPropAcc( xInterface, UNO_QUERY );
- xPropAcc->setPropertyValues( *pArg );
-
- // Build a SbUnoObject and return it
- auto xUnoObj = tools::make_ref<SbUnoObject>( "stardiv.uno.beans.PropertySet", Any(xInterface) );
- if( xUnoObj->getUnoAny().hasValue() )
- {
- // Return object
- refVar->PutObject( xUnoObj.get() );
- return;
- }
+ // Return object
+ refVar->PutObject( xUnoObj.get() );
+ return;
}
// Object could not be created
diff --git a/basic/source/classes/sb.cxx b/basic/source/classes/sb.cxx
index c38a6c04989b..ae9f4d0adeed 100644
--- a/basic/source/classes/sb.cxx
+++ b/basic/source/classes/sb.cxx
@@ -18,6 +18,8 @@
*/
#include <sb.hxx>
+#include <o3tl/safeint.hxx>
+#include <osl/diagnose.h>
#include <rtl/ustrbuf.hxx>
#include <tools/stream.hxx>
#include <tools/debug.hxx>
@@ -47,9 +49,6 @@
#include <memory>
#include <unordered_map>
-#include <global.hxx>
-#include <unotools/transliterationwrapper.hxx>
-
#include <com/sun/star/script/ModuleType.hpp>
#include <com/sun/star/script/ModuleInfo.hpp>
@@ -57,7 +56,7 @@
using namespace ::com::sun::star::script;
-constexpr OUStringLiteral SB_RTLNAME = u"@SBRTL";
+constexpr OUString SB_RTLNAME = u"@SBRTL"_ustr;
// i#i68894#
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
@@ -138,7 +137,7 @@ void DocBasicItem::clearDependingVarsOnDelete( StarBASIC& rDeletedBasic )
void DocBasicItem::startListening()
{
Any aThisComp;
- mrDocBasic.GetUNOConstant( "ThisComponent", aThisComp );
+ mrDocBasic.GetUNOConstant( u"ThisComponent"_ustr, aThisComp );
Reference< util::XCloseBroadcaster > xCloseBC( aThisComp, UNO_QUERY );
mbDisposed = !xCloseBC.is();
if( xCloseBC.is() )
@@ -152,7 +151,7 @@ void DocBasicItem::stopListening()
if( mbDisposed ) return;
mbDisposed = true;
Any aThisComp;
- if (!mrDocBasic.GetUNOConstant("ThisComponent", aThisComp))
+ if (!mrDocBasic.GetUNOConstant(u"ThisComponent"_ustr, aThisComp))
return;
Reference< util::XCloseBroadcaster > xCloseBC( aThisComp, UNO_QUERY );
@@ -237,14 +236,14 @@ SbxObject* StarBASIC::getVBAGlobals( )
if ( !pVBAGlobals.is() )
{
Any aThisDoc;
- if ( GetUNOConstant("ThisComponent", aThisDoc) )
+ if ( GetUNOConstant(u"ThisComponent"_ustr, aThisDoc) )
{
Reference< XMultiServiceFactory > xDocFac( aThisDoc, UNO_QUERY );
if ( xDocFac.is() )
{
try
{
- xDocFac->createInstance("ooo.vba.VBAGlobals");
+ xDocFac->createInstance(u"ooo.vba.VBAGlobals"_ustr);
}
catch(const Exception& )
{
@@ -252,7 +251,7 @@ SbxObject* StarBASIC::getVBAGlobals( )
}
}
}
- pVBAGlobals = static_cast<SbUnoObject*>(Find( "VBAGlobals" , SbxClassType::DontCare ));
+ pVBAGlobals = static_cast<SbUnoObject*>(Find( u"VBAGlobals"_ustr , SbxClassType::DontCare ));
}
return pVBAGlobals.get();
}
@@ -424,11 +423,11 @@ SbxBaseRef SbiFactory::Create( sal_uInt16 nSbxId, sal_uInt32 nCreator )
case SBXID_BASIC:
return new StarBASIC( nullptr );
case SBXID_BASICMOD:
- return new SbModule( "" );
+ return new SbModule( u""_ustr );
case SBXID_BASICPROP:
- return new SbProperty( "", SbxVARIANT, nullptr );
+ return new SbProperty( u""_ustr, SbxVARIANT, nullptr );
case SBXID_BASICMETHOD:
- return new SbMethod( "", SbxVARIANT, nullptr );
+ return new SbMethod( u""_ustr, SbxVARIANT, nullptr );
case SBXID_JSCRIPTMOD:
return new SbJScriptModule;
case SBXID_JSCRIPTMETH:
@@ -450,14 +449,14 @@ SbxObjectRef SbiFactory::CreateObject( const OUString& rClass )
}
else if( rClass.equalsIgnoreAsciiCase( "Collection" ) )
{
- return new BasicCollection( "Collection" );
+ return new BasicCollection( u"Collection"_ustr );
}
else if( rClass.equalsIgnoreAsciiCase( "FileSystemObject" ) )
{
try
{
Reference< XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory(), UNO_SET_THROW );
- OUString aServiceName("ooo.vba.FileSystemObject");
+ OUString aServiceName(u"ooo.vba.FileSystemObject"_ustr);
Reference< XInterface > xInterface( xFactory->createInstance( aServiceName ), UNO_SET_THROW );
return new SbUnoObject( aServiceName, uno::Any( xInterface ) );
}
@@ -605,25 +604,23 @@ SbxObjectRef createUserTypeImpl( const OUString& rClassName )
return pRetObj;
}
-
-SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule )
- : SbModule( pClassModule->GetName() )
- , mpClassModule( pClassModule )
+SbClassModuleObject::SbClassModuleObject(SbModule& rClassModule)
+ : SbModule(rClassModule.GetName())
+ , mrClassModule(rClassModule)
, mbInitializeEventDone( false )
{
- aOUSource = pClassModule->aOUSource;
- aComment = pClassModule->aComment;
- // see comment in destructor about these two
- pImage.reset(pClassModule->pImage.get());
- pBreaks = pClassModule->pBreaks;
+ aOUSource = rClassModule.aOUSource;
+ aComment = rClassModule.aComment;
+ pImage = rClassModule.pImage;
+ pBreaks = rClassModule.pBreaks;
- SetClassName( pClassModule->GetName() );
+ SetClassName(rClassModule.GetName());
// Allow search only internally
ResetFlag( SbxFlagBits::GlobalSearch );
// Copy the methods from original class module
- SbxArray* pClassMethods = pClassModule->GetMethods().get();
+ SbxArray* pClassMethods = rClassModule.GetMethods().get();
sal_uInt32 nMethodCount = pClassMethods->Count();
sal_uInt32 i;
for( i = 0 ; i < nMethodCount ; i++ )
@@ -681,7 +678,7 @@ SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule )
}
// Copy the properties from original class module
- SbxArray* pClassProps = pClassModule->GetProperties();
+ SbxArray* pClassProps = rClassModule.GetProperties();
sal_uInt32 nPropertyCount = pClassProps->Count();
for( i = 0 ; i < nPropertyCount ; i++ )
{
@@ -722,17 +719,17 @@ SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule )
SbClassModuleObject* pClassModuleObj = dynamic_cast<SbClassModuleObject*>( pObjBase );
if( pClassModuleObj != nullptr )
{
- SbModule* pLclClassModule = pClassModuleObj->getClassModule();
- SbClassModuleObject* pNewObj = new SbClassModuleObject( pLclClassModule );
+ SbModule& rLclClassModule = pClassModuleObj->getClassModule();
+ SbClassModuleObject* pNewObj = new SbClassModuleObject(rLclClassModule);
pNewObj->SetName( pProp->GetName() );
- pNewObj->SetParent( pLclClassModule->pParent );
+ pNewObj->SetParent(rLclClassModule.pParent);
pNewProp->PutObject( pNewObj );
}
else if( aObjClass.equalsIgnoreAsciiCase( "Collection" ) )
{
- BasicCollection* pNewCollection = new BasicCollection( "Collection" );
+ BasicCollection* pNewCollection = new BasicCollection( u"Collection"_ustr );
pNewCollection->SetName( pProp->GetName() );
- pNewCollection->SetParent( pClassModule->pParent );
+ pNewCollection->SetParent(rClassModule.pParent);
pNewProp->PutObject( pNewCollection );
}
}
@@ -746,7 +743,7 @@ SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule )
}
}
SetModuleType( ModuleType::CLASS );
- mbVBACompat = pClassModule->mbVBACompat;
+ mbVBASupport = rClassModule.mbVBASupport;
}
SbClassModuleObject::~SbClassModuleObject()
@@ -757,11 +754,6 @@ SbClassModuleObject::~SbClassModuleObject()
if( const DocBasicItem* pDocBasicItem = lclFindDocBasicItem( pDocBasic ) )
if( !pDocBasicItem->isDocClosed() )
triggerTerminateEvent();
-
- // prevent the base class destructor from deleting these because
- // we do not actually own them
- pImage.release();
- pBreaks = nullptr;
}
void SbClassModuleObject::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
@@ -796,7 +788,7 @@ void SbClassModuleObject::triggerInitializeEvent()
mbInitializeEventDone = true;
// Search method
- SbxVariable* pMeth = SbxObject::Find("Class_Initialize", SbxClassType::Method);
+ SbxVariable* pMeth = SbxObject::Find(u"Class_Initialize"_ustr, SbxClassType::Method);
if( pMeth )
{
SbxValues aVals;
@@ -811,7 +803,7 @@ void SbClassModuleObject::triggerTerminateEvent()
return;
}
// Search method
- SbxVariable* pMeth = SbxObject::Find("Class_Terminate", SbxClassType::Method );
+ SbxVariable* pMeth = SbxObject::Find(u"Class_Terminate"_ustr, SbxClassType::Method );
if( pMeth )
{
SbxValues aVals;
@@ -882,7 +874,7 @@ SbxObjectRef SbClassFactory::CreateObject( const OUString& rClassName )
if( pVar )
{
SbModule* pVarMod = static_cast<SbModule*>(pVar);
- pRet = new SbClassModuleObject( pVarMod );
+ pRet = new SbClassModuleObject(*pVarMod);
}
return pRet;
}
@@ -895,7 +887,7 @@ SbModule* SbClassFactory::FindClass( const OUString& rClassName )
}
StarBASIC::StarBASIC( StarBASIC* p, bool bIsDocBasic )
- : SbxObject("StarBASIC"), bDocBasic( bIsDocBasic )
+ : SbxObject(u"StarBASIC"_ustr), bDocBasic( bIsDocBasic )
{
SetParent( p );
bNoRtl = bBreak = false;
@@ -903,18 +895,18 @@ StarBASIC::StarBASIC( StarBASIC* p, bool bIsDocBasic )
if( !GetSbData()->nInst++ )
{
- GetSbData()->pSbFac.reset( new SbiFactory );
- AddFactory( GetSbData()->pSbFac.get() );
- GetSbData()->pTypeFac.reset(new SbTypeFactory);
- AddFactory( GetSbData()->pTypeFac.get() );
+ GetSbData()->pSbFac.emplace();
+ AddFactory( &*GetSbData()->pSbFac );
+ GetSbData()->pTypeFac.emplace();
+ AddFactory( &*GetSbData()->pTypeFac );
GetSbData()->pClassFac.reset(new SbClassFactory);
AddFactory( GetSbData()->pClassFac.get() );
- GetSbData()->pOLEFac.reset(new SbOLEFactory);
- AddFactory( GetSbData()->pOLEFac.get() );
- GetSbData()->pFormFac.reset(new SbFormFactory);
- AddFactory( GetSbData()->pFormFac.get() );
- GetSbData()->pUnoFac.reset( new SbUnoFactory );
- AddFactory( GetSbData()->pUnoFac.get() );
+ GetSbData()->pOLEFac.emplace();
+ AddFactory( &*GetSbData()->pOLEFac );
+ GetSbData()->pFormFac.emplace();
+ AddFactory( &*GetSbData()->pFormFac );
+ GetSbData()->pUnoFac.emplace();
+ AddFactory( &*GetSbData()->pUnoFac );
}
pRtl = new SbiStdObject(SB_RTLNAME, this );
// Search via StarBasic is always global
@@ -942,17 +934,17 @@ StarBASIC::~StarBASIC()
if( !--GetSbData()->nInst )
{
- RemoveFactory( GetSbData()->pSbFac.get() );
+ RemoveFactory( &*GetSbData()->pSbFac );
GetSbData()->pSbFac.reset();
- RemoveFactory( GetSbData()->pUnoFac.get() );
+ RemoveFactory( &*GetSbData()->pUnoFac );
GetSbData()->pUnoFac.reset();
- RemoveFactory( GetSbData()->pTypeFac.get() );
+ RemoveFactory( &*GetSbData()->pTypeFac );
GetSbData()->pTypeFac.reset();
RemoveFactory( GetSbData()->pClassFac.get() );
GetSbData()->pClassFac.reset();
- RemoveFactory( GetSbData()->pOLEFac.get() );
+ RemoveFactory( &*GetSbData()->pOLEFac );
GetSbData()->pOLEFac.reset();
- RemoveFactory( GetSbData()->pFormFac.get() );
+ RemoveFactory( &*GetSbData()->pFormFac );
GetSbData()->pFormFac.reset();
if( SbiGlobals::pGlobals )
@@ -1076,7 +1068,7 @@ void StarBASIC::Remove( SbxVariable* pVar )
{
// #87540 Can be last reference!
SbModuleRef xVar = pModule;
- pModules.erase(std::remove(pModules.begin(), pModules.end(), xVar));
+ std::erase(pModules, xVar);
pVar->SetParent( nullptr );
EndListening( pVar->GetBroadcaster() );
}
@@ -1308,7 +1300,7 @@ SbxVariable* StarBASIC::Find( const OUString& rName, SbxClassType t )
}
}
}
- OUString aMainStr("Main");
+ static constexpr OUString aMainStr(u"Main"_ustr);
if( !pRes && pNamed && ( t == SbxClassType::Method || t == SbxClassType::DontCare ) &&
!pNamed->GetName().equalsIgnoreAsciiCase( aMainStr ) )
{
@@ -1327,11 +1319,11 @@ bool StarBASIC::Call( const OUString& rName, SbxArray* pParam )
if( !bRes )
{
ErrCode eErr = SbxBase::GetError();
- SbxBase::ResetError();
if( eErr != ERRCODE_NONE )
{
- RTError( eErr, OUString(), 0, 0, 0 );
+ RTError(eErr, SbxBase::GetErrorMsg(), 0, 0, 0);
}
+ SbxBase::ResetError();
}
return bRes;
}
@@ -1431,7 +1423,7 @@ sal_uInt16 StarBASIC::GetCol1() { return GetSbData()->nCol1; }
sal_uInt16 StarBASIC::GetCol2() { return GetSbData()->nCol2; }
// Specific to error handler
-ErrCode const & StarBASIC::GetErrorCode() { return GetSbData()->nCode; }
+ErrCodeMsg const & StarBASIC::GetErrorCode() { return GetSbData()->nCode; }
const OUString& StarBASIC::GetErrorText() { return GetSbData()->aErrMsg; }
// From 1996-03-29:
@@ -1533,7 +1525,7 @@ ErrCode StarBASIC::GetSfxFromVBError( sal_uInt16 nError )
}
// set Error- / Break-data
-void StarBASIC::SetErrorData( ErrCode nCode, sal_uInt16 nLine,
+void StarBASIC::SetErrorData( const ErrCodeMsg& nCode, sal_uInt16 nLine,
sal_uInt16 nCol1, sal_uInt16 nCol2 )
{
SbiGlobals& aGlobals = *GetSbData();
@@ -1564,7 +1556,7 @@ void StarBASIC::MakeErrorText( ErrCode nId, std::u16string_view aMsg )
OUString sError = BasResId(pErrorMsg);
OUStringBuffer aMsg1(sError);
// replace argument placeholder with %s
- OUString aSrgStr( "$(ARG1)" );
+ OUString aSrgStr( u"$(ARG1)"_ustr );
sal_Int32 nResult = sError.indexOf(aSrgStr);
if( nResult >= 0 )
@@ -1588,9 +1580,8 @@ void StarBASIC::MakeErrorText( ErrCode nId, std::u16string_view aMsg )
}
else if( nOldID != 0 )
{
- OUString aStdMsg = "Error " + OUString::number(nOldID) +
- ": No error text available!";
- GetSbData()->aErrMsg = aStdMsg;
+ GetSbData()->aErrMsg = "Error " + OUString::number(nOldID) +
+ ": No error text available!";
}
else
{
@@ -1622,11 +1613,12 @@ bool StarBASIC::CError( ErrCode code, const OUString& rMsg,
MakeErrorText( code, rMsg );
// Implementation of the code for the string transport to SFX-Error
+ ErrCodeMsg nErr = code;
if( !rMsg.isEmpty() )
{
- code = *new StringErrorInfo( code, rMsg );
+ nErr = ErrCodeMsg( code, rMsg );
}
- SetErrorData( code, l, c1, c2 );
+ SetErrorData( nErr, l, c1, c2 );
GetSbData()->bCompilerError = true;
bool bRet;
if( GetSbData()->aErrHdl.IsSet() )
@@ -1653,6 +1645,7 @@ bool StarBASIC::RTError( ErrCode code, const OUString& rMsg, sal_Int32 l, sal_In
MakeErrorText( c, rMsg );
// Implementation of the code for the string transport to SFX-Error
+ ErrCodeMsg nErr = code;
if( !rMsg.isEmpty() )
{
// very confusing, even though MakeErrorText sets up the error text
@@ -1663,15 +1656,15 @@ bool StarBASIC::RTError( ErrCode code, const OUString& rMsg, sal_Int32 l, sal_In
{
OUString aTmp = "\'" + OUString::number(SbxErrObject::getUnoErrObject()->getNumber()) +
"\'\n" + (!GetSbData()->aErrMsg.isEmpty() ? GetSbData()->aErrMsg : rMsg);
- code = *new StringErrorInfo( code, aTmp );
+ nErr = ErrCodeMsg( code, aTmp );
}
else
{
- code = *new StringErrorInfo( code, rMsg );
+ nErr = ErrCodeMsg( code, rMsg );
}
}
- SetErrorData( code, l, c1, c2 );
+ SetErrorData( nErr, l, c1, c2 );
if( GetSbData()->aErrHdl.IsSet() )
{
return GetSbData()->aErrHdl.Call( this );
@@ -1682,11 +1675,6 @@ bool StarBASIC::RTError( ErrCode code, const OUString& rMsg, sal_Int32 l, sal_In
}
}
-void StarBASIC::Error( ErrCode n )
-{
- Error( n, OUString() );
-}
-
void StarBASIC::Error( ErrCode n, const OUString& rMsg )
{
if( GetSbData()->pInst )
@@ -1724,7 +1712,7 @@ ErrCode StarBASIC::GetErrBasic()
}
// make the additional message for the RTL function error accessible
-OUString StarBASIC::GetErrorMsg()
+const OUString & StarBASIC::GetErrorMsg()
{
if( GetSbData()->pInst )
{
@@ -1732,7 +1720,7 @@ OUString StarBASIC::GetErrorMsg()
}
else
{
- return OUString();
+ return EMPTY_OUSTRING;
}
}
@@ -1837,12 +1825,12 @@ bool StarBASIC::LoadData( SvStream& r, sal_uInt16 nVer )
}
}
// HACK for SFX-Bullshit!
- SbxVariable* p = Find( "FALSE", SbxClassType::Property );
+ SbxVariable* p = Find( u"FALSE"_ustr, SbxClassType::Property );
if( p )
{
Remove( p );
}
- p = Find( "TRUE", SbxClassType::Property );
+ p = Find( u"TRUE"_ustr, SbxClassType::Property );
if( p )
{
Remove( p );
@@ -1854,22 +1842,28 @@ bool StarBASIC::LoadData( SvStream& r, sal_uInt16 nVer )
return true;
}
-bool StarBASIC::StoreData( SvStream& r ) const
+std::pair<bool, sal_uInt32> StarBASIC::StoreData( SvStream& r ) const
{
- if( !SbxObject::StoreData( r ) )
+ auto [bSuccess, nVersion] = SbxObject::StoreData(r);
+ if( !bSuccess )
{
- return false;
+ return { false, 0 };
}
assert(pModules.size() < SAL_MAX_UINT16);
r.WriteUInt16( static_cast<sal_uInt16>(pModules.size()));
for( const auto& rpModule: pModules )
{
- if( !rpModule->Store( r ) )
+ const auto [bSuccessModule, nVersionModule] = rpModule->Store(r);
+ if( !bSuccessModule )
{
- return false;
+ return { false, 0 };
+ }
+ else if (nVersionModule > nVersion)
+ {
+ nVersion = nVersionModule;
}
}
- return true;
+ return { true, nVersion };
}
bool StarBASIC::GetUNOConstant( const OUString& rName, css::uno::Any& aOut )
@@ -1894,7 +1888,7 @@ Reference< frame::XModel > StarBASIC::GetModelFromBasic( SbxObject* pBasic )
// look for the ThisComponent variable, first in the parent (which
// might be the document's Basic), then in the parent's parent (which might be
// the application Basic)
- static const OUStringLiteral sThisComponent( u"ThisComponent");
+ static constexpr OUStringLiteral sThisComponent( u"ThisComponent");
SbxVariable* pThisComponent = nullptr;
SbxObject* pLookup = pBasic->GetParent();
@@ -1941,9 +1935,13 @@ void StarBASIC::DetachAllDocBasicItems()
// #118116 Implementation Collection object
+// [-loplugin:ostr]
constexpr OUStringLiteral pCountStr = u"Count";
+// [-loplugin:ostr]
constexpr OUStringLiteral pAddStr = u"Add";
+// [-loplugin:ostr]
constexpr OUStringLiteral pItemStr = u"Item";
+// [-loplugin:ostr]
constexpr OUStringLiteral pRemoveStr = u"Remove";
constexpr sal_uInt16 nCountHash = SbxVariable::MakeHashCode(pCountStr);
constexpr sal_uInt16 nAddHash = SbxVariable::MakeHashCode(pAddStr);
@@ -1987,15 +1985,15 @@ void BasicCollection::Initialize()
if ( !xAddInfo.is() )
{
xAddInfo = new SbxInfo;
- xAddInfo->AddParam( "Item", SbxVARIANT );
- xAddInfo->AddParam( "Key", SbxVARIANT, SbxFlagBits::Read | SbxFlagBits::Optional );
- xAddInfo->AddParam( "Before", SbxVARIANT, SbxFlagBits::Read | SbxFlagBits::Optional );
- xAddInfo->AddParam( "After", SbxVARIANT, SbxFlagBits::Read | SbxFlagBits::Optional );
+ xAddInfo->AddParam( u"Item"_ustr, SbxVARIANT );
+ xAddInfo->AddParam( u"Key"_ustr, SbxVARIANT, SbxFlagBits::Read | SbxFlagBits::Optional );
+ xAddInfo->AddParam( u"Before"_ustr, SbxVARIANT, SbxFlagBits::Read | SbxFlagBits::Optional );
+ xAddInfo->AddParam( u"After"_ustr, SbxVARIANT, SbxFlagBits::Read | SbxFlagBits::Optional );
}
if ( !xItemInfo.is() )
{
xItemInfo = new SbxInfo;
- xItemInfo->AddParam( "Index", SbxVARIANT, SbxFlagBits::Read | SbxFlagBits::Optional);
+ xItemInfo->AddParam( u"Index"_ustr, SbxVARIANT, SbxFlagBits::Read | SbxFlagBits::Optional);
}
}
@@ -2070,26 +2068,26 @@ sal_Int32 BasicCollection::implGetIndex( SbxVariable const * pIndexVar )
return nIndex;
}
-sal_Int32 BasicCollection::implGetIndexForName(std::u16string_view rName)
+sal_Int32 BasicCollection::implGetIndexForName(const OUString& rName)
{
- sal_Int32 nIndex = -1;
sal_Int32 nCount = xItemArray->Count();
sal_Int32 nNameHash = MakeHashCode( rName );
// tdf#144245 - case-insensitive operation for non-ASCII characters
- utl::TransliterationWrapper& rTransliteration = SbGlobal::GetTransliteration();
+ OUString aNameCI; // Only initialize when matching hash found
for( sal_Int32 i = 0 ; i < nCount ; i++ )
{
SbxVariable* pVar = xItemArray->Get(i);
- if (pVar->GetHashCode() == nNameHash
- && rTransliteration.isEqual(pVar->GetName(), OUString(rName)))
+ if (pVar->GetHashCode() == nNameHash)
{
- nIndex = i;
- break;
+ if (aNameCI.isEmpty() && !rName.isEmpty())
+ aNameCI = SbxVariable::NameToCaseInsensitiveName(rName);
+ if (aNameCI == pVar->GetName(SbxNameType::CaseInsensitive))
+ return i;
}
}
- return nIndex;
+ return -1;
}
void BasicCollection::CollAdd( SbxArray* pPar_ )
@@ -2180,7 +2178,7 @@ void BasicCollection::CollItem( SbxArray* pPar_ )
SbxVariable* pRes = nullptr;
SbxVariable* p = pPar_->Get(1);
sal_Int32 nIndex = implGetIndex( p );
- if (nIndex >= 0 && nIndex < static_cast<sal_Int32>(xItemArray->Count()))
+ if (nIndex >= 0 && o3tl::make_unsigned(nIndex) < xItemArray->Count())
{
pRes = xItemArray->Get(nIndex);
}
@@ -2204,7 +2202,7 @@ void BasicCollection::CollRemove( SbxArray* pPar_ )
SbxVariable* p = pPar_->Get(1);
sal_Int32 nIndex = implGetIndex( p );
- if (nIndex >= 0 && nIndex < static_cast<sal_Int32>(xItemArray->Count()))
+ if (nIndex >= 0 && o3tl::make_unsigned(nIndex) < xItemArray->Count())
{
xItemArray->Remove( nIndex );
diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx
index 9e1d31fb4ac1..4dffb8fec5eb 100644
--- a/basic/source/classes/sbunoobj.cxx
+++ b/basic/source/classes/sbunoobj.cxx
@@ -19,15 +19,17 @@
#include <sal/config.h>
+#include <osl/diagnose.h>
#include <o3tl/any.hxx>
-#include <osl/mutex.hxx>
+#include <o3tl/safeint.hxx>
+#include <utility>
#include <vcl/svapp.hxx>
-#include <vcl/errcode.hxx>
+#include <comphelper/errcode.hxx>
#include <svl/hint.hxx>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/exc_hlp.hxx>
-#include <comphelper/interfacecontainer2.hxx>
+#include <comphelper/interfacecontainer4.hxx>
#include <comphelper/extract.hxx>
#include <comphelper/processfactory.hxx>
#include <cppuhelper/weakref.hxx>
@@ -38,6 +40,7 @@
#include <com/sun/star/script/ArrayWrapper.hpp>
#include <com/sun/star/script/CannotConvertException.hpp>
#include <com/sun/star/script/NativeObjectWrapper.hpp>
+#include <com/sun/star/sheet/XSheetCellCursor.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/uno/DeploymentException.hpp>
@@ -99,9 +102,9 @@ using namespace cppu;
// Identifiers for creating the strings for dbg_Properties
-constexpr OUStringLiteral ID_DBG_SUPPORTEDINTERFACES = u"Dbg_SupportedInterfaces";
-constexpr OUStringLiteral ID_DBG_PROPERTIES = u"Dbg_Properties";
-constexpr OUStringLiteral ID_DBG_METHODS = u"Dbg_Methods";
+constexpr OUString ID_DBG_SUPPORTEDINTERFACES = u"Dbg_SupportedInterfaces"_ustr;
+constexpr OUString ID_DBG_PROPERTIES = u"Dbg_Properties"_ustr;
+constexpr OUString ID_DBG_METHODS = u"Dbg_Methods"_ustr;
char const aSeqLevelStr[] = "[]";
@@ -187,19 +190,19 @@ static Reference< XHierarchicalNameAccess > const & getTypeProvider_Impl()
// Do we have already CoreReflection; if not obtain it
if( !xAccess.is() )
{
- Reference< XComponentContext > xContext(
+ const Reference< XComponentContext >& xContext(
comphelper::getProcessComponentContext() );
if( xContext.is() )
{
xContext->getValueByName(
- "/singletons/com.sun.star.reflection.theTypeDescriptionManager" )
+ u"/singletons/com.sun.star.reflection.theTypeDescriptionManager"_ustr )
>>= xAccess;
OSL_ENSURE( xAccess.is(), "### TypeDescriptionManager singleton not accessible!?" );
}
if( !xAccess.is() )
{
throw DeploymentException(
- "/singletons/com.sun.star.reflection.theTypeDescriptionManager singleton not accessible" );
+ u"/singletons/com.sun.star.reflection.theTypeDescriptionManager singleton not accessible"_ustr );
}
}
return xAccess;
@@ -213,7 +216,7 @@ static Reference< XTypeConverter > const & getTypeConverter_Impl()
// Do we have already CoreReflection; if not obtain it
if( !xTypeConverter.is() )
{
- Reference< XComponentContext > xContext(
+ const Reference< XComponentContext >& xContext(
comphelper::getProcessComponentContext() );
if( xContext.is() )
{
@@ -222,7 +225,7 @@ static Reference< XTypeConverter > const & getTypeConverter_Impl()
if( !xTypeConverter.is() )
{
throw DeploymentException(
- "com.sun.star.script.Converter service not accessible" );
+ u"com.sun.star.script.Converter service not accessible"_ustr );
}
}
return xTypeConverter;
@@ -234,12 +237,12 @@ SbUnoObject* createOLEObject_Impl( const OUString& aType )
{
static const Reference<XMultiServiceFactory> xOLEFactory = [] {
Reference<XMultiServiceFactory> xFactory;
- Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() );
+ const Reference< XComponentContext >& xContext( comphelper::getProcessComponentContext() );
if( xContext.is() )
{
Reference<XMultiComponentFactory> xSMgr = xContext->getServiceManager();
xFactory.set(
- xSMgr->createInstanceWithContext( "com.sun.star.bridge.OleObjectFactory", xContext ),
+ xSMgr->createInstanceWithContext( u"com.sun.star.bridge.OleObjectFactory"_ustr, xContext ),
UNO_QUERY );
}
return xFactory;
@@ -828,9 +831,9 @@ static Type getUnoTypeForSbxBaseType( SbxDataType eType )
case SbxDATE: {
SbiInstance* pInst = GetSbData()->pInst;
if( pInst && pInst->IsCompatibility() )
- aRetType = cppu::UnoType<double>::get();
- else
aRetType = cppu::UnoType<oleautomation::Date>::get();
+ else
+ aRetType = cppu::UnoType<double>::get();
}
break;
case SbxSTRING: aRetType = cppu::UnoType<OUString>::get(); break;
@@ -895,7 +898,7 @@ static Type getUnoTypeForSbxValue( const SbxValue* pVal )
aElementType = cppu::UnoType<Any>::get();
break;
}
- aElementType = aType;
+ aElementType = std::move(aType);
bNeedsInit = false;
}
else if( aElementType != aType )
@@ -932,7 +935,7 @@ static Type getUnoTypeForSbxValue( const SbxValue* pVal )
aElementType = cppu::UnoType<Any>::get();
break;
}
- aElementType = aType;
+ aElementType = std::move(aType);
bNeedsInit = false;
}
else if( aElementType != aType )
@@ -968,6 +971,12 @@ static Type getUnoTypeForSbxValue( const SbxValue* pVal )
// No object, convert basic type
else
{
+ if (eBaseType == SbxBYTE && pVal->GetByte() > 127)
+ {
+ // Basic Byte type is unsigned; cppu::UnoType<sal_uInt8> corresponds to UNO boolean,
+ // so values 128-255 are only representable starting with UNO short types
+ eBaseType = SbxUSHORT;
+ }
aRetType = getUnoTypeForSbxBaseType( eBaseType );
}
return aRetType;
@@ -987,8 +996,8 @@ static Any sbxToUnoValueImpl( const SbxValue* pVar, bool bBlockConversionToSmall
if( auto pClassModuleObj = dynamic_cast<SbClassModuleObject*>( xObj.get() ) )
{
Any aRetAny;
- SbModule* pClassModule = pClassModuleObj->getClassModule();
- if( pClassModule->createCOMWrapperForIface( aRetAny, pClassModuleObj ) )
+ SbModule& rClassModule = pClassModuleObj->getClassModule();
+ if (rClassModule.createCOMWrapperForIface(aRetAny, pClassModuleObj))
return aRetAny;
}
if( dynamic_cast<const SbUnoObject*>( xObj.get() ) == nullptr )
@@ -1048,19 +1057,10 @@ static Any sbxToUnoValueImpl( const SbxValue* pVar, bool bBlockConversionToSmall
aType = ::cppu::UnoType<sal_Int16>::get();
break;
}
- case TypeClass_UNSIGNED_SHORT:
- {
- sal_uInt16 n = pVar->GetUShort();
- if( n <= 255 )
- aType = cppu::UnoType<sal_uInt8>::get();
- break;
- }
case TypeClass_UNSIGNED_LONG:
{
sal_uInt32 n = pVar->GetLong();
- if( n <= 255 )
- aType = cppu::UnoType<sal_uInt8>::get();
- else if( n <= SbxMAXUINT )
+ if( n <= SbxMAXUINT )
aType = cppu::UnoType<cppu::UnoUnsignedShortType>::get();
break;
}
@@ -1187,6 +1187,15 @@ Any sbxToUnoValue( const SbxValue* pVar, const Type& rType, Property const * pUn
}
TypeClass eType = rType.getTypeClass();
+
+ // tdf#162431 - check for missing parameters
+ if (eType != TypeClass_ANY && eType != TypeClass_VOID && pVar->GetType() == SbxERROR)
+ {
+ SbxVariable* paSbxVariable = dynamic_cast<SbxVariable*>(const_cast<SbxValue*>(pVar));
+ if (paSbxVariable && SbiRuntime::IsMissing(paSbxVariable, 1))
+ StarBASIC::Error(ERRCODE_BASIC_NOT_OPTIONAL);
+ }
+
switch( eType )
{
case TypeClass_INTERFACE:
@@ -1534,7 +1543,7 @@ static Any invokeAutomationMethod( const OUString& Name, Sequence< Any > const &
for( sal_uInt32 j = 0 ; j < nLen ; j++ )
{
sal_Int16 iTarget = pIndices[ j ];
- if( iTarget >= static_cast<sal_Int16>(nParamCount) )
+ if( o3tl::make_unsigned(iTarget) >= nParamCount )
break;
unoToSbxValue(pParams->Get(j + 1), pNewValues[j]);
}
@@ -1607,9 +1616,7 @@ static OUString getDbgObjectName(SbUnoObject& rUnoObj)
{
aRet.append( "\n" );
}
- aRet.append( "\"" );
- aRet.append( aName );
- aRet.append( "\":" );
+ aRet.append( "\"" + aName + "\":" );
return aRet.makeStringAndClear();
}
@@ -1701,13 +1708,14 @@ bool checkUnoObjectType(SbUnoObject& rUnoObj, const OUString& rClass)
OUString aInterfaceName = xClass->getName();
if ( aInterfaceName == "com.sun.star.bridge.oleautomation.XAutomationObject" )
{
- // there is a hack in the extensions/source/ole/oleobj.cxx to return the typename of the automation object, lets check if it
- // matches
+ // there is a hack in the extensions/source/ole/oleobj.cxx
+ // to return the typename of the automation object, let's
+ // check if it matches
Reference< XInvocation > xInv( aToInspectObj, UNO_QUERY );
if ( xInv.is() )
{
OUString sTypeName;
- xInv->getValue( "$GetTypeName" ) >>= sTypeName;
+ xInv->getValue( u"$GetTypeName"_ustr ) >>= sTypeName;
if ( sTypeName.isEmpty() || sTypeName == "IDispatch" )
{
// can't check type, leave it pass
@@ -1741,16 +1749,16 @@ static OUString Impl_GetSupportedInterfaces(SbUnoObject& rUnoObj)
auto x = o3tl::tryAccess<Reference<XInterface>>(aToInspectObj);
if( !x )
{
- aRet.append( ID_DBG_SUPPORTEDINTERFACES );
- aRet.append( " not available.\n(TypeClass is not TypeClass_INTERFACE)\n" );
+ aRet.append( ID_DBG_SUPPORTEDINTERFACES
+ + " not available.\n(TypeClass is not TypeClass_INTERFACE)\n" );
}
else
{
Reference< XTypeProvider > xTypeProvider( *x, UNO_QUERY );
- aRet.append( "Supported interfaces by object " );
- aRet.append(getDbgObjectName(rUnoObj));
- aRet.append( "\n" );
+ aRet.append( "Supported interfaces by object "
+ + getDbgObjectName(rUnoObj)
+ + "\n" );
if( xTypeProvider.is() )
{
// get the interfaces of the implementation
@@ -1771,9 +1779,9 @@ static OUString Impl_GetSupportedInterfaces(SbUnoObject& rUnoObj)
typelib_TypeDescription * pTD = nullptr;
rType.getDescription( &pTD );
- aRet.append( "*** ERROR: No IdlClass for type \"" );
- aRet.append( pTD->pTypeName );
- aRet.append( "\"\n*** Please check type library\n" );
+ aRet.append( OUString::Concat("*** ERROR: No IdlClass for type \"")
+ + OUString::unacquired(&pTD->pTypeName)
+ + "\"\n*** Please check type library\n" );
}
}
}
@@ -1829,15 +1837,13 @@ static OUString Dbg_SbxDataType2String( SbxDataType eType )
// Debugging help method to display the properties of a SbUnoObjects
static OUString Impl_DumpProperties(SbUnoObject& rUnoObj)
{
- OUStringBuffer aRet;
- aRet.append("Properties of object ");
- aRet.append(getDbgObjectName(rUnoObj));
+ OUStringBuffer aRet("Properties of object " + getDbgObjectName(rUnoObj));
// analyse the Uno-Infos to recognise the arrays
Reference< XIntrospectionAccess > xAccess = rUnoObj.getIntrospectionAccess();
if( !xAccess.is() )
{
- Reference< XInvocation > xInvok = rUnoObj.getInvocation();
+ const Reference< XInvocation >& xInvok = rUnoObj.getInvocation();
if( xInvok.is() )
xAccess = xInvok->getIntrospection();
}
@@ -1889,8 +1895,7 @@ static OUString Impl_DumpProperties(SbUnoObject& rUnoObj)
aPropStr.append( Dbg_SbxDataType2String( eType ) );
if( bMaybeVoid )
aPropStr.append( "/void" );
- aPropStr.append( " " );
- aPropStr.append( pVar->GetName() );
+ aPropStr.append( " " + pVar->GetName() );
if( i == nPropCount - 1 )
aPropStr.append( "\n" );
@@ -1906,15 +1911,13 @@ static OUString Impl_DumpProperties(SbUnoObject& rUnoObj)
// Debugging help method to display the methods of an SbUnoObjects
static OUString Impl_DumpMethods(SbUnoObject& rUnoObj)
{
- OUStringBuffer aRet;
- aRet.append("Methods of object ");
- aRet.append(getDbgObjectName(rUnoObj));
+ OUStringBuffer aRet("Methods of object " + getDbgObjectName(rUnoObj));
// XIntrospectionAccess, so that the types of the parameter could be outputted
Reference< XIntrospectionAccess > xAccess = rUnoObj.getIntrospectionAccess();
if( !xAccess.is() )
{
- Reference< XInvocation > xInvok = rUnoObj.getInvocation();
+ const Reference< XInvocation >& xInvok = rUnoObj.getInvocation();
if( xInvok.is() )
xAccess = xInvok->getIntrospection();
}
@@ -1955,10 +1958,8 @@ static OUString Impl_DumpMethods(SbUnoObject& rUnoObj)
eType = SbxDataType( SbxOBJECT | SbxARRAY );
}
// output the name and the type
- aRet.append( Dbg_SbxDataType2String( eType ) );
- aRet.append( " " );
- aRet.append ( pVar->GetName() );
- aRet.append( " ( " );
+ aRet.append( Dbg_SbxDataType2String( eType )
+ + " " + pVar->GetName() + " ( " );
// the get-method mustn't have a parameter
Sequence< Reference< XIdlClass > > aParamsSeq = rxMethod->getParameterTypes();
@@ -2052,7 +2053,7 @@ void SbUnoObject::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
{
if ( pProp->isUnoStruct() )
{
- SbUnoStructRefObject* pSbUnoObject = new SbUnoStructRefObject( pProp->GetName(), aMember );
+ SbUnoStructRefObject* pSbUnoObject = new SbUnoStructRefObject( pProp->GetName(), std::move(aMember) );
SbxObjectRef xWrapper = static_cast<SbxObject*>(pSbUnoObject);
pVar->PutObject( xWrapper.get() );
}
@@ -2099,9 +2100,6 @@ void SbUnoObject::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
aRetAny = mxInvocation->getValue( pProp->GetName() );
// take over the value from Uno to Sbx
unoToSbxValue( pVar, aRetAny );
- if( pParams && bCanBeConsideredAMethod )
- pVar->SetParameters( nullptr );
-
}
catch( const Exception& )
{
@@ -2298,11 +2296,11 @@ SbUnoObject::SbUnoObject( const OUString& aName_, const Any& aUnoObj_ )
, bNativeCOMObject( false )
{
// beat out again the default properties of Sbx
- Remove( "Name", SbxClassType::DontCare );
- Remove( "Parent", SbxClassType::DontCare );
+ Remove( u"Name"_ustr, SbxClassType::DontCare );
+ Remove( u"Parent"_ustr, SbxClassType::DontCare );
// check the type of the objects
- TypeClass eType = aUnoObj_.getValueType().getTypeClass();
+ TypeClass eType = aUnoObj_.getValueTypeClass();
Reference< XInterface > x;
if( eType == TypeClass_INTERFACE )
{
@@ -2312,12 +2310,9 @@ SbUnoObject::SbUnoObject( const OUString& aName_, const Any& aUnoObj_ )
return;
}
- Reference< XTypeProvider > xTypeProvider;
// Did the object have an invocation itself?
mxInvocation.set( x, UNO_QUERY );
- xTypeProvider.set( x, UNO_QUERY );
-
if( mxInvocation.is() )
{
@@ -2325,6 +2320,7 @@ SbUnoObject::SbUnoObject( const OUString& aName_, const Any& aUnoObj_ )
mxExactNameInvocation.set( mxInvocation, UNO_QUERY );
// The remainder refers only to the introspection
+ Reference< XTypeProvider > xTypeProvider( x, UNO_QUERY );
if( !xTypeProvider.is() )
{
bNeedIntrospection = false;
@@ -2355,7 +2351,7 @@ SbUnoObject::SbUnoObject( const OUString& aName_, const Any& aUnoObj_ )
// insert the real name of the class
if( aName_.isEmpty() )
{
- aClassName_ = aUnoObj_.getValueType().getTypeName();
+ aClassName_ = aUnoObj_.getValueTypeName();
bSetClassName = true;
}
StructRefInfo aThisStruct( maTmpUnoObj, maTmpUnoObj.getValueType(), 0 );
@@ -2390,7 +2386,7 @@ void SbUnoObject::doIntrospection()
if( !bNeedIntrospection )
return;
- Reference<XComponentContext> xContext = comphelper::getProcessComponentContext();
+ const Reference<XComponentContext>& xContext = comphelper::getProcessComponentContext();
if (!xContext.is())
return;
@@ -2437,11 +2433,11 @@ void SbUnoObject::doIntrospection()
// Start of a list of all SbUnoMethod-Instances
-static SbUnoMethod* pFirst = nullptr;
+static SbUnoMethod* s_pFirst = nullptr;
void clearUnoMethodsForBasic( StarBASIC const * pBasic )
{
- SbUnoMethod* pMeth = pFirst;
+ SbUnoMethod* pMeth = s_pFirst;
while( pMeth )
{
SbxObject* pObject = pMeth->GetParent();
@@ -2456,8 +2452,8 @@ void clearUnoMethodsForBasic( StarBASIC const * pBasic )
// set the new StarBASIC as the parent of the module
// pObject->SetParent( NULL );
- if( pMeth == pFirst )
- pFirst = pMeth->pNext;
+ if( pMeth == s_pFirst )
+ s_pFirst = pMeth->pNext;
else if( pMeth->pPrev )
pMeth->pPrev->pNext = pMeth->pNext;
if( pMeth->pNext )
@@ -2470,7 +2466,7 @@ void clearUnoMethodsForBasic( StarBASIC const * pBasic )
pObject->SbxValue::Clear();
// start from the beginning after object clearing, the cycle will end since the method is removed each time
- pMeth = pFirst;
+ pMeth = s_pFirst;
}
else
pMeth = pMeth->pNext;
@@ -2482,7 +2478,7 @@ void clearUnoMethodsForBasic( StarBASIC const * pBasic )
void clearUnoMethods()
{
- SbUnoMethod* pMeth = pFirst;
+ SbUnoMethod* pMeth = s_pFirst;
while( pMeth )
{
pMeth->SbxValue::Clear();
@@ -2505,9 +2501,9 @@ SbUnoMethod::SbUnoMethod
pParamInfoSeq = nullptr;
// enregister the method in a list
- pNext = pFirst;
+ pNext = s_pFirst;
pPrev = nullptr;
- pFirst = this;
+ s_pFirst = this;
if( pNext )
pNext->pPrev = this;
}
@@ -2516,8 +2512,8 @@ SbUnoMethod::~SbUnoMethod()
{
pParamInfoSeq.reset();
- if( this == pFirst )
- pFirst = pNext;
+ if( this == s_pFirst )
+ s_pFirst = pNext;
else if( pPrev )
pPrev->pNext = pNext;
if( pNext )
@@ -2566,13 +2562,13 @@ SbUnoProperty::SbUnoProperty
const OUString& aName_,
SbxDataType eSbxType,
SbxDataType eRealSbxType,
- const Property& aUnoProp_,
+ Property aUnoProp_,
sal_Int32 nId_,
bool bInvocation,
bool bUnoStruct
)
: SbxProperty( aName_, eSbxType )
- , aUnoProp( aUnoProp_ )
+ , aUnoProp(std::move( aUnoProp_ ))
, nId( nId_ )
, mbInvocation( bInvocation )
, mRealType( eRealSbxType )
@@ -2587,6 +2583,27 @@ SbUnoProperty::SbUnoProperty
SbUnoProperty::~SbUnoProperty()
{}
+bool isVeryLargeUnoProperty(SbxVariable const * pVar)
+{
+ auto pUnoVar = dynamic_cast<const SbUnoProperty*>(pVar);
+ if (!pUnoVar)
+ return false;
+ // The ScCellRangeObj methods will attempt to generate massive strings,
+ // which will use up massive amounts of RAM and also lock of the program
+ // for some time.
+ const OUString & aUnoName = pUnoVar->getUnoName();
+ if (aUnoName == "DataArray" || aUnoName == "FormulaArray")
+ {
+ auto pParent = dynamic_cast<const SbUnoObject*>(pUnoVar->GetParent());
+ if (!pParent)
+ return false;
+ css::uno::Any aAny = const_cast<SbUnoObject*>(pParent)->getUnoAny();
+ css::uno::Reference<css::sheet::XSheetCellCursor> xCursor = aAny.query<css::sheet::XSheetCellCursor>();
+ if (xCursor)
+ return true;
+ }
+ return false;
+}
SbxVariable* SbUnoObject::Find( const OUString& rName, SbxClassType t )
{
@@ -2615,19 +2632,19 @@ SbxVariable* SbUnoObject::Find( const OUString& rName, SbxClassType t )
}
if( mxUnoAccess->hasProperty( aUName, PropertyConcept::ALL - PropertyConcept::DANGEROUS ) )
{
- const Property& rProp = mxUnoAccess->
+ const Property aProp = mxUnoAccess->
getProperty( aUName, PropertyConcept::ALL - PropertyConcept::DANGEROUS );
// If the property could be void the type had to be set to Variant
SbxDataType eSbxType;
- if( rProp.Attributes & PropertyAttribute::MAYBEVOID )
+ if( aProp.Attributes & PropertyAttribute::MAYBEVOID )
eSbxType = SbxVARIANT;
else
- eSbxType = unoToSbxType( rProp.Type.getTypeClass() );
+ eSbxType = unoToSbxType( aProp.Type.getTypeClass() );
- SbxDataType eRealSbxType = ( ( rProp.Attributes & PropertyAttribute::MAYBEVOID ) ? unoToSbxType( rProp.Type.getTypeClass() ) : eSbxType );
+ SbxDataType eRealSbxType = ( ( aProp.Attributes & PropertyAttribute::MAYBEVOID ) ? unoToSbxType( aProp.Type.getTypeClass() ) : eSbxType );
// create the property and superimpose it
- auto pProp = tools::make_ref<SbUnoProperty>( rProp.Name, eSbxType, eRealSbxType, rProp, 0, false, ( rProp.Type.getTypeClass() == css::uno::TypeClass_STRUCT ) );
+ auto pProp = tools::make_ref<SbUnoProperty>( aProp.Name, eSbxType, eRealSbxType, aProp, 0, false, ( aProp.Type.getTypeClass() == css::uno::TypeClass_STRUCT ) );
QuickInsert( pProp.get() );
pRes = pProp.get();
}
@@ -2635,12 +2652,12 @@ SbxVariable* SbUnoObject::Find( const OUString& rName, SbxClassType t )
MethodConcept::ALL - MethodConcept::DANGEROUS ) )
{
// address the method
- const Reference< XIdlMethod >& rxMethod = mxUnoAccess->
+ const Reference< XIdlMethod > xMethod = mxUnoAccess->
getMethod( aUName, MethodConcept::ALL - MethodConcept::DANGEROUS );
// create SbUnoMethod and superimpose it
- auto xMethRef = tools::make_ref<SbUnoMethod>( rxMethod->getName(),
- unoToSbxType( rxMethod->getReturnType() ), rxMethod, false );
+ auto xMethRef = tools::make_ref<SbUnoMethod>( xMethod->getName(),
+ unoToSbxType( xMethod->getReturnType() ), xMethod, false );
QuickInsert( xMethRef.get() );
pRes = xMethRef.get();
}
@@ -2756,15 +2773,15 @@ void SbUnoObject::implCreateDbgProperties()
Property aProp;
// Id == -1: display the implemented interfaces corresponding the ClassProvider
- auto xVarRef = tools::make_ref<SbUnoProperty>( OUString(ID_DBG_SUPPORTEDINTERFACES), SbxSTRING, SbxSTRING, aProp, -1, false, false );
+ auto xVarRef = tools::make_ref<SbUnoProperty>( ID_DBG_SUPPORTEDINTERFACES, SbxSTRING, SbxSTRING, aProp, -1, false, false );
QuickInsert( xVarRef.get() );
// Id == -2: output the properties
- xVarRef = tools::make_ref<SbUnoProperty>( OUString(ID_DBG_PROPERTIES), SbxSTRING, SbxSTRING, aProp, -2, false, false );
+ xVarRef = tools::make_ref<SbUnoProperty>( ID_DBG_PROPERTIES, SbxSTRING, SbxSTRING, aProp, -2, false, false );
QuickInsert( xVarRef.get() );
// Id == -3: output the Methods
- xVarRef = tools::make_ref<SbUnoProperty>( OUString(ID_DBG_METHODS), SbxSTRING, SbxSTRING, aProp, -3, false, false );
+ xVarRef = tools::make_ref<SbUnoProperty>( ID_DBG_METHODS, SbxSTRING, SbxSTRING, aProp, -3, false, false );
QuickInsert( xVarRef.get() );
}
@@ -3041,7 +3058,7 @@ void RTL_Impl_GetProcessServiceManager( SbxArray& rPar )
Reference< XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory() );
// Create a SbUnoObject out of it and return it
- SbUnoObjectRef xUnoObj = new SbUnoObject( "ProcessServiceManager", Any(xFactory) );
+ SbUnoObjectRef xUnoObj = new SbUnoObject( u"ProcessServiceManager"_ustr, Any(xFactory) );
refVar->PutObject( xUnoObj.get() );
}
@@ -3129,7 +3146,7 @@ void RTL_Impl_IsUnoStruct( SbxArray& rPar )
return;
}
Any aAny = obj->getUnoAny();
- TypeClass eType = aAny.getValueType().getTypeClass();
+ TypeClass eType = aAny.getValueTypeClass();
if( eType == TypeClass_STRUCT )
{
refVar->PutBool( true );
@@ -3162,7 +3179,7 @@ void RTL_Impl_EqualUnoObjects( SbxArray& rPar )
return;
}
Any aAny1 = obj1->getUnoAny();
- TypeClass eType1 = aAny1.getValueType().getTypeClass();
+ TypeClass eType1 = aAny1.getValueTypeClass();
if( eType1 != TypeClass_INTERFACE )
{
return;
@@ -3182,7 +3199,7 @@ void RTL_Impl_EqualUnoObjects( SbxArray& rPar )
return;
}
Any aAny2 = obj2->getUnoAny();
- TypeClass eType2 = aAny2.getValueType().getTypeClass();
+ TypeClass eType2 = aAny2.getValueTypeClass();
if( eType2 != TypeClass_INTERFACE )
{
return;
@@ -3233,7 +3250,7 @@ void VBAConstantHelper::init()
if ( isInited )
return;
- Reference< XTypeDescriptionEnumeration > xEnum = getTypeDescriptorEnumeration( "ooo.vba", {TypeClass_CONSTANTS}, TypeDescriptionSearchDepth_INFINITE );
+ Reference< XTypeDescriptionEnumeration > xEnum = getTypeDescriptorEnumeration( u"ooo.vba"_ustr, {TypeClass_CONSTANTS}, TypeDescriptionSearchDepth_INFINITE );
if ( !xEnum.is())
{
@@ -3272,14 +3289,14 @@ void VBAConstantHelper::init()
}
bool
-VBAConstantHelper::isVBAConstantType( const OUString& rName )
+VBAConstantHelper::isVBAConstantType( std::u16string_view rName )
{
init();
bool bConstant = false;
for (auto const& elem : aConstCache)
{
- if( rName.equalsIgnoreAsciiCase(elem) )
+ if( o3tl::equalsIgnoreAsciiCase(rName, elem) )
{
bConstant = true;
break;
@@ -3379,7 +3396,7 @@ SbxVariable* SbUnoClass::Find( const OUString& rName, SbxClassType )
try
{
Any aValue = xHarryName->getByHierarchicalName( aNewName );
- TypeClass eType = aValue.getValueType().getTypeClass();
+ TypeClass eType = aValue.getValueTypeClass();
// Interface located? Then it is a class
if( eType == TypeClass_INTERFACE )
@@ -3719,7 +3736,7 @@ SbUnoSingleton* findUnoSingleton( const OUString& rName )
SbUnoSingleton::SbUnoSingleton( const OUString& aName_ )
: SbxObject( aName_ )
{
- SbxVariableRef xGetMethodRef = new SbxMethod( "get", SbxOBJECT );
+ SbxVariableRef xGetMethodRef = new SbxMethod( u"get"_ustr, SbxOBJECT );
QuickInsert( xGetMethodRef.get() );
}
@@ -3740,7 +3757,7 @@ void SbUnoSingleton::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
Reference < XComponentContext > xFirstParamContext;
Any aArg1 = sbxToUnoValue(pParams->Get(1));
if( (aArg1 >>= xFirstParamContext) && xFirstParamContext.is() )
- xContextToUse = xFirstParamContext;
+ xContextToUse = std::move(xFirstParamContext);
}
if( !xContextToUse.is() )
@@ -3784,7 +3801,7 @@ public:
SbxObjectRef xSbxObj;
OUString aPrefixName;
- explicit BasicAllListener_Impl( const OUString& aPrefixName );
+ explicit BasicAllListener_Impl( OUString aPrefixName );
// Methods of XAllListener
virtual void SAL_CALL firing(const AllEventObject& Event) override;
@@ -3796,8 +3813,8 @@ public:
}
-BasicAllListener_Impl::BasicAllListener_Impl(const OUString& aPrefixName_)
- : aPrefixName( aPrefixName_ )
+BasicAllListener_Impl::BasicAllListener_Impl(OUString aPrefixName_)
+ : aPrefixName(std::move( aPrefixName_ ))
{
}
@@ -3882,7 +3899,7 @@ class InvocationToAllListenerMapper : public WeakImplHelper< XInvocation >
{
public:
InvocationToAllListenerMapper( const Reference< XIdlClass >& ListenerType,
- const Reference< XAllListener >& AllListener, const Any& Helper );
+ const Reference< XAllListener >& AllListener, Any Helper );
// XInvocation
virtual Reference< XIntrospectionAccess > SAL_CALL getIntrospection() override;
@@ -3923,10 +3940,10 @@ static Reference< XInterface > createAllListenerAdapter
// InvocationToAllListenerMapper
InvocationToAllListenerMapper::InvocationToAllListenerMapper
- ( const Reference< XIdlClass >& ListenerType, const Reference< XAllListener >& AllListener, const Any& Helper )
+ ( const Reference< XIdlClass >& ListenerType, const Reference< XAllListener >& AllListener, Any Helper )
: m_xAllListener( AllListener )
, m_xListenerType( ListenerType )
- , m_Helper( Helper )
+ , m_Helper(std::move( Helper ))
{
}
@@ -3973,7 +3990,7 @@ Any SAL_CALL InvocationToAllListenerMapper::invoke(const OUString& FunctionName,
}
AllEventObject aAllEvent;
- aAllEvent.Source = static_cast<OWeakObject*>(this);
+ aAllEvent.Source = getXWeak();
aAllEvent.Helper = m_Helper;
aAllEvent.ListenerType = Type(m_xListenerType->getTypeClass(), m_xListenerType->getName() );
aAllEvent.MethodName = FunctionName;
@@ -4032,7 +4049,7 @@ void SbRtl_CreateUnoListener(StarBASIC * pBasic, SbxArray & rPar, bool)
return;
// get the AllListenerAdapterService
- Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() );
+ const Reference< XComponentContext >& xContext( comphelper::getProcessComponentContext() );
// search the class
Reference< XIdlClass > xClass = xCoreReflection->forName( aListenerClassName );
@@ -4077,7 +4094,7 @@ void RTL_Impl_GetDefaultContext( SbxArray& rPar )
Any aContextAny( comphelper::getProcessComponentContext() );
- SbUnoObjectRef xUnoObj = new SbUnoObject( "DefaultContext", aContextAny );
+ SbUnoObjectRef xUnoObj = new SbUnoObject( u"DefaultContext"_ustr, aContextAny );
refVar->PutObject( xUnoObj.get() );
}
@@ -4126,9 +4143,8 @@ void RTL_Impl_CreateUnoValue( SbxArray& rPar )
bool bSuccess = implGetTypeByName( aValTypeName, aType );
if( bSuccess )
{
- Any aTypeAny( aType );
SbxVariableRef refVar = rPar.Get(0);
- SbxObjectRef xUnoAnyObject = new SbUnoAnyObject( aTypeAny );
+ SbxObjectRef xUnoAnyObject = new SbUnoAnyObject(Any(aType));
refVar->PutObject( xUnoAnyObject.get() );
}
return;
@@ -4166,12 +4182,12 @@ namespace {
class ModuleInvocationProxy : public WeakImplHelper< XInvocation, XComponent >
{
- ::osl::Mutex m_aMutex;
+ std::mutex m_aMutex;
OUString m_aPrefix;
SbxObjectRef m_xScopeObj;
bool m_bProxyIsClassModuleObject;
- ::comphelper::OInterfaceContainerHelper2 m_aListeners;
+ ::comphelper::OInterfaceContainerHelper4<XEventListener> m_aListeners;
public:
ModuleInvocationProxy( std::u16string_view aPrefix, SbxObjectRef const & xScopeObj );
@@ -4199,7 +4215,6 @@ public:
ModuleInvocationProxy::ModuleInvocationProxy( std::u16string_view aPrefix, SbxObjectRef const & xScopeObj )
: m_aPrefix( OUString::Concat(aPrefix) + "_" )
, m_xScopeObj( xScopeObj )
- , m_aListeners( m_aMutex )
{
m_bProxyIsClassModuleObject = xScopeObj.is() && dynamic_cast<const SbClassModuleObject*>( xScopeObj.get() ) != nullptr;
}
@@ -4300,17 +4315,13 @@ Any SAL_CALL ModuleInvocationProxy::invoke( const OUString& rFunction,
OUString aFunctionName = m_aPrefix
+ rFunction;
- bool bSetRescheduleBack = false;
- bool bOldReschedule = true;
+ bool bOldReschedule = false;
SbiInstance* pInst = GetSbData()->pInst;
if( pInst && pInst->IsCompatibility() )
{
bOldReschedule = pInst->IsReschedule();
if ( bOldReschedule )
- {
pInst->EnableReschedule( false );
- bSetRescheduleBack = true;
- }
}
SbxVariable* p = xScopeObj->Find( aFunctionName, SbxClassType::Method );
@@ -4345,7 +4356,7 @@ Any SAL_CALL ModuleInvocationProxy::invoke( const OUString& rFunction,
aRet = sbxToUnoValue( xValue.get() );
pMeth->SetParameters( nullptr );
- if( bSetRescheduleBack )
+ if (bOldReschedule)
pInst->EnableReschedule( bOldReschedule );
// TODO: OutParameter?
@@ -4355,22 +4366,24 @@ Any SAL_CALL ModuleInvocationProxy::invoke( const OUString& rFunction,
void SAL_CALL ModuleInvocationProxy::dispose()
{
- ::osl::MutexGuard aGuard( m_aMutex );
+ std::unique_lock aGuard( m_aMutex );
EventObject aEvent( static_cast<XComponent*>(this) );
- m_aListeners.disposeAndClear( aEvent );
+ m_aListeners.disposeAndClear( aGuard, aEvent );
m_xScopeObj = nullptr;
}
void SAL_CALL ModuleInvocationProxy::addEventListener( const Reference< XEventListener >& xListener )
{
- m_aListeners.addInterface( xListener );
+ std::unique_lock aGuard( m_aMutex );
+ m_aListeners.addInterface( aGuard, xListener );
}
void SAL_CALL ModuleInvocationProxy::removeEventListener( const Reference< XEventListener >& xListener )
{
- m_aListeners.removeInterface( xListener );
+ std::unique_lock aGuard( m_aMutex );
+ m_aListeners.removeInterface( aGuard, xListener );
}
@@ -4380,7 +4393,7 @@ Reference< XInterface > createComListener( const Any& aControlAny, const OUStrin
{
Reference< XInterface > xRet;
- Reference< XComponentContext > xContext(
+ const Reference< XComponentContext >& xContext(
comphelper::getProcessComponentContext() );
Reference< XMultiComponentFactory > xServiceMgr( xContext->getServiceManager() );
@@ -4391,7 +4404,7 @@ Reference< XInterface > createComListener( const Any& aControlAny, const OUStrin
try
{
xRet = xServiceMgr->createInstanceWithArgumentsAndContext(
- "com.sun.star.custom.UnoComListener",
+ u"com.sun.star.custom.UnoComListener"_ustr,
args, xContext );
}
catch( const Exception& )
@@ -4476,7 +4489,7 @@ void disposeComVariablesForBasic( StarBASIC const * pBasic )
ComponentRefVector& rv = pItem->m_vComImplementsObjects;
for (auto const& elem : rv)
{
- Reference< XComponent > xComponent( elem.get(), UNO_QUERY );
+ Reference< XComponent > xComponent( elem );
if (xComponent.is())
xComponent->dispose();
}
@@ -4492,12 +4505,12 @@ bool SbModule::createCOMWrapperForIface( Any& o_rRetAny, SbClassModuleObject* pP
// For now: Take first interface that allows to instantiate COM wrapper
// TODO: Check if support for multiple interfaces is needed
- Reference< XComponentContext > xContext(
+ const Reference< XComponentContext >& xContext(
comphelper::getProcessComponentContext() );
Reference< XMultiComponentFactory > xServiceMgr( xContext->getServiceManager() );
Reference< XSingleServiceFactory > xComImplementsFactory
(
- xServiceMgr->createInstanceWithContext( "com.sun.star.custom.ComImplementsFactory", xContext ),
+ xServiceMgr->createInstanceWithContext( u"com.sun.star.custom.ComImplementsFactory"_ustr, xContext ),
UNO_QUERY
);
if( !xComImplementsFactory.is() )
@@ -4576,7 +4589,7 @@ bool handleToStringForCOMObjects( SbxObject* pObj, SbxValue* pVal )
// Only for native COM objects
if( pUnoObj->isNativeCOMObject() )
{
- SbxVariableRef pMeth = pObj->Find( "toString", SbxClassType::Method );
+ SbxVariableRef pMeth = pObj->Find( u"toString"_ustr, SbxClassType::Method );
if ( pMeth.is() )
{
SbxValues aRes;
@@ -4631,7 +4644,7 @@ TypeClass StructRefInfo::getTypeClass() const
return maType.getTypeClass();
}
-SbUnoStructRefObject::SbUnoStructRefObject( const OUString& aName_, const StructRefInfo& rMemberInfo ) : SbxObject( aName_ ), maMemberInfo( rMemberInfo ), mbMemberCacheInit( false )
+SbUnoStructRefObject::SbUnoStructRefObject( const OUString& aName_, StructRefInfo aMemberInfo ) : SbxObject( aName_ ), maMemberInfo(std::move( aMemberInfo )), mbMemberCacheInit( false )
{
SetClassName( maMemberInfo.getTypeName() );
}
@@ -4679,7 +4692,8 @@ SbxVariable* SbUnoStructRefObject::Find( const OUString& rName, SbxClassType t )
Property aProp;
aProp.Name = rName;
aProp.Type = css::uno::Type( it->second->getTypeClass(), it->second->getTypeName() );
- SbUnoProperty* pProp = new SbUnoProperty( rName, eSbxType, eRealSbxType, aProp, 0, false, ( aProp.Type.getTypeClass() == css::uno::TypeClass_STRUCT) );
+ const bool bIsStruct = aProp.Type.getTypeClass() == css::uno::TypeClass_STRUCT;
+ SbUnoProperty* pProp = new SbUnoProperty( rName, eSbxType, eRealSbxType, std::move(aProp), 0, false, bIsStruct );
SbxVariableRef xVarRef = pProp;
QuickInsert( xVarRef.get() );
pRes = xVarRef.get();
@@ -4717,7 +4731,7 @@ void SbUnoStructRefObject::implCreateDbgProperties()
QuickInsert( xVarRef.get() );
// Id == -3: output the Methods
- xVarRef = new SbUnoProperty( ID_DBG_METHODS, SbxSTRING, SbxSTRING, aProp, -3, false, false );
+ xVarRef = new SbUnoProperty( ID_DBG_METHODS, SbxSTRING, SbxSTRING, std::move(aProp), -3, false, false );
QuickInsert( xVarRef.get() );
}
@@ -4739,7 +4753,8 @@ void SbUnoStructRefObject::implCreateAll()
Property aProp;
aProp.Name = rName;
aProp.Type = css::uno::Type( field.second->getTypeClass(), field.second->getTypeName() );
- SbUnoProperty* pProp = new SbUnoProperty( rName, eSbxType, eRealSbxType, aProp, 0, false, ( aProp.Type.getTypeClass() == css::uno::TypeClass_STRUCT) );
+ const bool bIsStruct = aProp.Type.getTypeClass() == css::uno::TypeClass_STRUCT;
+ SbUnoProperty* pProp = new SbUnoProperty( rName, eSbxType, eRealSbxType, std::move(aProp), 0, false, bIsStruct );
SbxVariableRef xVarRef = pProp;
QuickInsert( xVarRef.get() );
}
@@ -4756,9 +4771,7 @@ Any SbUnoStructRefObject::getUnoAny()
OUString SbUnoStructRefObject::Impl_DumpProperties()
{
- OUStringBuffer aRet;
- aRet.append("Properties of object ");
- aRet.append( getDbgObjectName() );
+ OUStringBuffer aRet("Properties of object " + getDbgObjectName() );
sal_uInt32 nPropCount = pProps->Count();
sal_uInt32 nPropsPerLine = 1 + nPropCount / 30;
@@ -4791,10 +4804,8 @@ OUString SbUnoStructRefObject::Impl_DumpProperties()
}
}
}
- aPropStr.append( Dbg_SbxDataType2String( eType ) );
-
- aPropStr.append( " " );
- aPropStr.append( pVar->GetName() );
+ aPropStr.append( Dbg_SbxDataType2String( eType )
+ + " " + pVar->GetName() );
if( i == nPropCount - 1 )
{
@@ -4915,9 +4926,7 @@ OUString SbUnoStructRefObject::getDbgObjectName() const
{
aRet.append( "\n" );
}
- aRet.append( "\"" );
- aRet.append( aName );
- aRet.append( "\":" );
+ aRet.append( "\"" + aName + "\":" );
return aRet.makeStringAndClear();
}
diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx
index cdd05c0c1f14..6558050e1325 100644
--- a/basic/source/classes/sbxmod.cxx
+++ b/basic/source/classes/sbxmod.cxx
@@ -18,9 +18,10 @@
*/
+#include <utility>
#include <vcl/svapp.hxx>
#include <tools/stream.hxx>
-#include <tools/diagnose_ex.h>
+#include <comphelper/diagnose_ex.hxx>
#include <svl/SfxBroadcaster.hxx>
#include <basic/codecompletecache.hxx>
#include <basic/sbx.hxx>
@@ -164,7 +165,7 @@ DocObjectWrapper::DocObjectWrapper( SbModule* pVar ) : m_pMod( pVar )
instances that are acquired during the call are released
before m_refCount is decremented again */
{
- m_xAggProxy->setDelegator( static_cast< cppu::OWeakObject * >( this ) );
+ m_xAggProxy->setDelegator( getXWeak() );
}
osl_atomic_decrement( &m_refCount );
@@ -198,7 +199,7 @@ DocObjectWrapper::invoke( const OUString& aFunctionName, const Sequence< Any >&
return m_xAggInv->invoke( aFunctionName, aParams, aOutParamIndex, aOutParam );
SbMethodRef pMethod = getMethod( aFunctionName );
if ( !pMethod.is() )
- throw RuntimeException();
+ throw RuntimeException(u"DocObjectWrapper::invoke - Could not get the method reference!"_ustr);
// check number of parameters
sal_Int32 nParamsCount = aParams.getLength();
SbxInfo* pInfo = pMethod->GetInfo();
@@ -216,7 +217,7 @@ DocObjectWrapper::invoke( const OUString& aFunctionName, const Sequence< Any >&
sal_Int32 nSbxCount = n - 1;
if ( nParamsCount < nSbxCount - nSbxOptional )
{
- throw RuntimeException( "wrong number of parameters!" );
+ throw RuntimeException( u"wrong number of parameters!"_ustr );
}
}
// set parameters
@@ -383,7 +384,7 @@ uno::Reference< frame::XModel > getDocumentModel( StarBASIC* pb )
if( pb && pb->IsDocBasic() )
{
uno::Any aDoc;
- if( pb->GetUNOConstant( "ThisComponent", aDoc ) )
+ if( pb->GetUNOConstant( u"ThisComponent"_ustr, aDoc ) )
xModel.set( aDoc, uno::UNO_QUERY );
}
return xModel;
@@ -395,7 +396,7 @@ static uno::Reference< vba::XVBACompatibility > getVBACompatibility( const uno::
try
{
uno::Reference< beans::XPropertySet > xModelProps( rxModel, uno::UNO_QUERY_THROW );
- xVBACompat.set( xModelProps->getPropertyValue( "BasicLibraries" ), uno::UNO_QUERY );
+ xVBACompat.set( xModelProps->getPropertyValue( u"BasicLibraries"_ustr ), uno::UNO_QUERY );
}
catch(const uno::Exception& )
{
@@ -415,16 +416,16 @@ static bool getDefaultVBAMode( StarBASIC* pb )
// A Basic module has set EXTSEARCH, so that the elements, that the module contains,
// could be found from other module.
-SbModule::SbModule( const OUString& rName, bool bVBACompat )
- : SbxObject( "StarBASICModule" ),
- pBreaks(nullptr), mbVBACompat( bVBACompat ), bIsProxyModule( false )
+SbModule::SbModule( const OUString& rName, bool bVBASupport )
+ : SbxObject( u"StarBASICModule"_ustr )
+ , mbVBASupport(bVBASupport), mbCompat(bVBASupport), bIsProxyModule(false)
{
SetName( rName );
SetFlag( SbxFlagBits::ExtSearch | SbxFlagBits::GlobalSearch );
SetModuleType( script::ModuleType::NORMAL );
// #i92642: Set name property to initial name
- SbxVariable* pNameProp = pProps->Find( "Name", SbxClassType::Property );
+ SbxVariable* pNameProp = pProps->Find( u"Name"_ustr, SbxClassType::Property );
if( pNameProp != nullptr )
{
pNameProp->PutString( GetName() );
@@ -435,7 +436,7 @@ SbModule::~SbModule()
{
SAL_INFO("basic","Module named " << GetName() << " is destructing");
pImage.reset();
- delete pBreaks;
+ pBreaks.reset();
pClassData.reset();
mxWrapper = nullptr;
}
@@ -801,11 +802,11 @@ void SbModule::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
void SbModule::SetSource32( const OUString& r )
{
// Default basic mode to library container mode, but... allow Option VBASupport 0/1 override
- SetVBACompat( getDefaultVBAMode( static_cast< StarBASIC*>( GetParent() ) ) );
+ SetVBASupport( getDefaultVBAMode( static_cast< StarBASIC*>( GetParent() ) ) );
aOUSource = r;
StartDefinitions();
SbiTokenizer aTok( r );
- aTok.SetCompatible( IsVBACompat() );
+ aTok.SetCompatible( IsVBASupport() );
while( !aTok.IsEof() )
{
@@ -836,12 +837,13 @@ void SbModule::SetSource32( const OUString& r )
eCurTok = aTok.Next();
if( eCurTok == COMPATIBLE )
{
+ mbCompat = true;
aTok.SetCompatible( true );
}
else if ( ( eCurTok == VBASUPPORT ) && ( aTok.Next() == NUMBER ) )
{
bool bIsVBA = ( aTok.GetDbl()== 1 );
- SetVBACompat( bIsVBA );
+ SetVBASupport( bIsVBA );
aTok.SetCompatible( bIsVBA );
}
}
@@ -855,13 +857,13 @@ void SbModule::SetSource32( const OUString& r )
sal_uInt16 nLine1 = aTok.GetLine();
if( aTok.Next() == SYMBOL )
{
- OUString aName_( aTok.GetSym() );
+ const OUString& rName_( aTok.GetSym() );
SbxDataType t = aTok.GetType();
if( t == SbxVARIANT && eEndTok == ENDSUB )
{
t = SbxVOID;
}
- pMeth = GetMethod( aName_, t );
+ pMeth = GetMethod( rName_, t );
pMeth->nLine1 = pMeth->nLine2 = nLine1;
// The method is for a start VALID
pMeth->bInvalid = false;
@@ -915,30 +917,30 @@ static void SendHint( SbxObject* pObj, SfxHintId nId, SbMethod* p )
SendHint_( pObj, nId, p );
}
-// #57841 Clear Uno-Objects, which were helt in RTL functions,
-// at the end of the program, so that nothing were helt.
+// #57841 Clear Uno-Objects, which were held in RTL functions,
+// at the end of the program, so that nothing is held
static void ClearUnoObjectsInRTL_Impl_Rek( StarBASIC* pBasic )
{
// delete the return value of CreateUnoService
- SbxVariable* pVar = pBasic->GetRtl()->Find( "CreateUnoService", SbxClassType::Method );
+ SbxVariable* pVar = pBasic->GetRtl()->Find( u"CreateUnoService"_ustr, SbxClassType::Method );
if( pVar )
{
pVar->SbxValue::Clear();
}
// delete the return value of CreateUnoDialog
- pVar = pBasic->GetRtl()->Find( "CreateUnoDialog", SbxClassType::Method );
+ pVar = pBasic->GetRtl()->Find( u"CreateUnoDialog"_ustr, SbxClassType::Method );
if( pVar )
{
pVar->SbxValue::Clear();
}
// delete the return value of CDec
- pVar = pBasic->GetRtl()->Find( "CDec", SbxClassType::Method );
+ pVar = pBasic->GetRtl()->Find( u"CDec"_ustr, SbxClassType::Method );
if( pVar )
{
pVar->SbxValue::Clear();
}
// delete return value of CreateObject
- pVar = pBasic->GetRtl()->Find( "CreateObject", SbxClassType::Method );
+ pVar = pBasic->GetRtl()->Find( u"CreateObject"_ustr, SbxClassType::Method );
if( pVar )
{
pVar->SbxValue::Clear();
@@ -973,18 +975,19 @@ static void ClearUnoObjectsInRTL_Impl( StarBASIC* pBasic )
}
-void SbModule::SetVBACompat( bool bCompat )
+void SbModule::SetVBASupport( bool bSupport )
{
- if( mbVBACompat == bCompat )
+ if( mbVBASupport == bSupport )
return;
- mbVBACompat = bCompat;
+ mbVBASupport = bSupport;
// initialize VBA document API
- if( mbVBACompat ) try
+ if( mbVBASupport ) try
{
+ mbCompat = true;
StarBASIC* pBasic = static_cast< StarBASIC* >( GetParent() );
uno::Reference< lang::XMultiServiceFactory > xFactory( getDocumentModel( pBasic ), uno::UNO_QUERY_THROW );
- xFactory->createInstance( "ooo.vba.VBAGlobals" );
+ xFactory->createInstance( u"ooo.vba.VBAGlobals"_ustr );
}
catch( Exception& )
{
@@ -1066,7 +1069,7 @@ namespace
// Run a Basic-subprogram
void SbModule::Run( SbMethod* pMeth )
{
- SAL_INFO("basic","About to run " << pMeth->GetName() << ", vba compatmode is " << mbVBACompat );
+ SAL_INFO("basic","About to run " << pMeth->GetName() << ", vba compatmode is " << mbVBASupport );
static sal_uInt16 nMaxCallLevel = 0;
@@ -1087,7 +1090,7 @@ void SbModule::Run( SbMethod* pMeth )
/* If a VBA script in a document is started, get the VBA compatibility
interface from the document Basic library container, and notify all
VBA script listeners about the started script. */
- if( mbVBACompat )
+ if( mbVBASupport )
{
StarBASIC* pBasic = static_cast< StarBASIC* >( GetParent() );
if( pBasic && pBasic->IsDocBasic() ) try
@@ -1104,7 +1107,7 @@ void SbModule::Run( SbMethod* pMeth )
// Launcher problem
// i80726 The Find below will generate an error in Testtool so we reset it unless there was one before already
bool bWasError = SbxBase::GetError() != ERRCODE_NONE;
- SbxVariable* pMSOMacroRuntimeLibVar = Find( "Launcher", SbxClassType::Object );
+ SbxVariable* pMSOMacroRuntimeLibVar = Find( u"Launcher"_ustr, SbxClassType::Object );
if ( !bWasError && (SbxBase::GetError() == ERRCODE_BASIC_PROC_UNDEFINED) )
SbxBase::ResetError();
if( pMSOMacroRuntimeLibVar )
@@ -1114,7 +1117,7 @@ void SbModule::Run( SbMethod* pMeth )
{
SbxFlagBits nGblFlag = pMSOMacroRuntimeLib->GetFlags() & SbxFlagBits::GlobalSearch;
pMSOMacroRuntimeLib->ResetFlag( SbxFlagBits::GlobalSearch );
- SbxVariable* pAppSymbol = pMSOMacroRuntimeLib->Find( "Application", SbxClassType::Method );
+ SbxVariable* pAppSymbol = pMSOMacroRuntimeLib->Find( u"Application"_ustr, SbxClassType::Method );
pMSOMacroRuntimeLib->SetFlag( nGblFlag );
if( pAppSymbol )
{
@@ -1165,21 +1168,19 @@ void SbModule::Run( SbMethod* pMeth )
pSbData->pInst->CalcBreakCallLevel( pMeth->GetDebugFlags() );
}
- auto xRuntimeGuard(std::make_unique<RunGuard>(this, pMeth, pMeth->nStart, pSbData, bDelInst));
-
- if ( mbVBACompat )
{
- pSbData->pInst->EnableCompatibility( true );
- }
+ RunGuard xRuntimeGuard(this, pMeth, pMeth->nStart, pSbData, bDelInst);
- xRuntimeGuard->run();
+ if (mbVBASupport)
+ pSbData->pInst->EnableCompatibility(true);
- xRuntimeGuard.reset();
+ xRuntimeGuard.run();
+ }
if( bDelInst )
{
- // #57841 Clear Uno-Objects, which were helt in RTL functions,
- // at the end of the program, so that nothing were helt.
+ // #57841 Clear Uno-Objects, which were held in RTL functions,
+ // at the end of the program, so that nothing is held.
ClearUnoObjectsInRTL_Impl( xBasic.get() );
clearNativeObjectWrapperVector();
@@ -1223,8 +1224,8 @@ void SbModule::Run( SbMethod* pMeth )
StarBASIC* pBasic = dynamic_cast<StarBASIC*>( GetParent() );
if( bDelInst )
{
- // #57841 Clear Uno-Objects, which were helt in RTL functions,
- // the end of the program, so that nothing were helt.
+ // #57841 Clear Uno-Objects, which were held in RTL functions,
+ // the end of the program, so that nothing is held.
ClearUnoObjectsInRTL_Impl( xBasic.get() );
delete pSbData->pInst;
@@ -1253,9 +1254,7 @@ void SbModule::RunInit()
pSbData->bRunInit = true;
// The init code starts always here
- auto xRuntimeGuard(std::make_unique<RunInitGuard>(this, nullptr, 0, pSbData));
- xRuntimeGuard->run();
- xRuntimeGuard.reset();
+ RunInitGuard(this, nullptr, 0, pSbData).run();
pImage->bInit = true;
pImage->bFirstInit = false;
@@ -1318,12 +1317,12 @@ void SbModule::ClearPrivateVars()
}
}
-void SbModule::implClearIfVarDependsOnDeletedBasic( SbxVariable* pVar, StarBASIC* pDeletedBasic )
+void SbModule::implClearIfVarDependsOnDeletedBasic(SbxVariable& rVar, StarBASIC* pDeletedBasic)
{
- if( pVar->SbxValue::GetType() != SbxOBJECT || dynamic_cast<const SbProcedureProperty*>( pVar) != nullptr )
+ if (rVar.SbxValue::GetType() != SbxOBJECT || dynamic_cast<const SbProcedureProperty*>(&rVar) != nullptr)
return;
- SbxObject* pObj = dynamic_cast<SbxObject*>( pVar->GetObject() );
+ SbxObject* pObj = dynamic_cast<SbxObject*>(rVar.GetObject());
if( pObj == nullptr )
return;
@@ -1338,7 +1337,7 @@ void SbModule::implClearIfVarDependsOnDeletedBasic( SbxVariable* pVar, StarBASIC
StarBASIC* pBasic = dynamic_cast<StarBASIC*>( p );
if( pBasic != nullptr && pBasic == pDeletedBasic )
{
- pVar->SbxValue::Clear();
+ rVar.SbxValue::Clear();
break;
}
}
@@ -1359,13 +1358,13 @@ void SbModule::ClearVarsDependingOnDeletedBasic( StarBASIC* pDeletedBasic )
for (sal_uInt32 j = 0; j < pArray->Count(); j++)
{
SbxVariable* pVar = pArray->Get(j);
- implClearIfVarDependsOnDeletedBasic( pVar, pDeletedBasic );
+ implClearIfVarDependsOnDeletedBasic(*pVar, pDeletedBasic);
}
}
}
else
{
- implClearIfVarDependsOnDeletedBasic( p, pDeletedBasic );
+ implClearIfVarDependsOnDeletedBasic(*p, pDeletedBasic);
}
}
}
@@ -1450,7 +1449,7 @@ const sal_uInt8* SbModule::FindNextStmnt( const sal_uInt8* p, sal_uInt16& nLine,
const sal_uInt8* SbModule::FindNextStmnt( const sal_uInt8* p, sal_uInt16& nLine, sal_uInt16& nCol,
bool bFollowJumps, const SbiImage* pImg ) const
{
- sal_uInt32 nPC = static_cast<sal_uInt32>( p - reinterpret_cast<const sal_uInt8*>(pImage->GetCode()) );
+ sal_uInt32 nPC = static_cast<sal_uInt32>( p - pImage->GetCode() );
while( nPC < pImage->GetCodeSize() )
{
SbiOpcode eOp = static_cast<SbiOpcode>( *p++ );
@@ -1460,7 +1459,7 @@ const sal_uInt8* SbModule::FindNextStmnt( const sal_uInt8* p, sal_uInt16& nLine,
SAL_WARN_IF( !pImg, "basic", "FindNextStmnt: pImg==NULL with FollowJumps option" );
sal_uInt32 nOp1 = *p++; nOp1 |= *p++ << 8;
nOp1 |= *p++ << 16; nOp1 |= *p++ << 24;
- p = reinterpret_cast<const sal_uInt8*>(pImg->GetCode()) + nOp1;
+ p = pImg->GetCode() + nOp1;
}
else if( eOp >= SbiOpcode::SbOP1_START && eOp <= SbiOpcode::SbOP1_END )
{
@@ -1497,7 +1496,7 @@ bool SbModule::IsBreakable( sal_uInt16 nLine ) const
{
if( !pImage )
return false;
- const sal_uInt8* p = reinterpret_cast<const sal_uInt8*>(pImage->GetCode());
+ const sal_uInt8* p = pImage->GetCode();
sal_uInt16 nl, nc;
while( ( p = FindNextStmnt( p, nl, nc ) ) != nullptr )
if( nl == nLine )
@@ -1526,7 +1525,7 @@ bool SbModule::SetBP( sal_uInt16 nLine )
if( !IsBreakable( nLine ) )
return false;
if( !pBreaks )
- pBreaks = new SbiBreakpoints;
+ pBreaks.reset(new SbiBreakpoints);
auto it = std::find_if(pBreaks->begin(), pBreaks->end(),
[&nLine](const sal_uInt16 b) { return b <= nLine; });
if (it != pBreaks->end() && *it == nLine)
@@ -1549,22 +1548,16 @@ bool SbModule::ClearBP( sal_uInt16 nLine )
[&nLine](const sal_uInt16 b) { return b <= nLine; });
bRes = (it != pBreaks->end()) && (*it == nLine);
if (bRes)
- {
pBreaks->erase(it);
- }
- if( pBreaks->empty() )
- {
- delete pBreaks;
- pBreaks = nullptr;
- }
+ if (pBreaks->empty())
+ pBreaks.reset();
}
return bRes;
}
void SbModule::ClearAllBP()
{
- delete pBreaks;
- pBreaks = nullptr;
+ pBreaks.reset();
}
void
@@ -1596,50 +1589,50 @@ bool SbModule::LoadData( SvStream& rStrm, sal_uInt16 nVer )
SetFlag( SbxFlagBits::ExtSearch | SbxFlagBits::GlobalSearch );
sal_uInt8 bImage;
rStrm.ReadUChar( bImage );
- if( bImage )
- {
- std::unique_ptr<SbiImage> p(new SbiImage);
- sal_uInt32 nImgVer = 0;
+ if( !bImage )
+ return true;
- if( !p->Load( rStrm, nImgVer ) )
- {
- return false;
- }
- // If the image is in old format, we fix up the method start offsets
- if ( nImgVer < B_EXT_IMG_VERSION )
- {
- fixUpMethodStart( false, p.get() );
- p->ReleaseLegacyBuffer();
- }
- aComment = p->aComment;
- SetName( p->aName );
- if( p->GetCodeSize() )
- {
- aOUSource = p->aOUSource;
- // Old version: image away
- if( nVer == 1 )
- {
- SetSource32( p->aOUSource );
- }
- else
- pImage = std::move(p);
- }
- else
+ std::unique_ptr<SbiImage> p(new SbiImage);
+ sal_uInt32 nImgVer = 0;
+
+ if( !p->Load( rStrm, nImgVer ) )
+ {
+ return false;
+ }
+ // If the image is in old format, we fix up the method start offsets
+ if ( nImgVer < B_IMG_VERSION_12 )
+ {
+ fixUpMethodStart( false, p.get() );
+ p->ReleaseLegacyBuffer();
+ }
+ aComment = p->aComment;
+ SetName( p->aName );
+ if( p->GetCodeSize() )
+ {
+ aOUSource = p->aOUSource;
+ // Old version: image away
+ if( nVer == 1 )
{
SetSource32( p->aOUSource );
}
+ else
+ pImage = std::move(p);
+ }
+ else
+ {
+ SetSource32( p->aOUSource );
}
return true;
}
-bool SbModule::StoreData( SvStream& rStrm ) const
+std::pair<bool, sal_uInt32> SbModule::StoreData( SvStream& rStrm ) const
{
bool bFixup = ( pImage && !pImage->ExceedsLegacyLimits() );
if ( bFixup )
fixUpMethodStart( true );
- bool bRet = SbxObject::StoreData( rStrm );
- if ( !bRet )
- return false;
+ const auto [bSuccess, nVersion] = SbxObject::StoreData(rStrm);
+ if (!bSuccess)
+ return { false, 0 };
if( pImage )
{
@@ -1651,10 +1644,10 @@ bool SbModule::StoreData( SvStream& rStrm ) const
// It should be noted that it probably isn't necessary
// It would be better not to store the image ( more flexible with
// formats )
- bool bRes = pImage->Save( rStrm, B_LEGACYVERSION );
+ bool bRes = pImage->Save( rStrm, nVersion );
if ( bFixup )
fixUpMethodStart( false ); // restore method starts
- return bRes;
+ return { bRes, nVersion };
}
else
@@ -1664,15 +1657,15 @@ bool SbModule::StoreData( SvStream& rStrm ) const
aImg.aComment = aComment;
aImg.aName = GetName();
rStrm.WriteUChar( 1 );
- return aImg.Save( rStrm );
+ return { aImg.Save(rStrm, nVersion), nVersion };
}
}
-bool SbModule::ExceedsLegacyModuleSize()
+bool SbModule::ExceedsImgVersion12ModuleSize()
{
if ( !IsCompiled() )
Compile();
- return pImage && pImage->ExceedsLegacyLimits();
+ return pImage && pImage->ExceedsImgVersion12Limits();
}
namespace {
@@ -1711,18 +1704,18 @@ void SbModule::GetCodeCompleteDataFromParse(CodeCompleteDataCache& aCache)
ErrorHdlResetter aErrHdl;
SbxBase::ResetError();
- auto pParser = std::make_unique<SbiParser>(static_cast<StarBASIC*>(GetParent()), this );
- pParser->SetCodeCompleting(true);
+ SbiParser aParser(static_cast<StarBASIC*>(GetParent()), this );
+ aParser.SetCodeCompleting(true);
- while( pParser->Parse() ) {}
- SbiSymPool* pPool = pParser->pPool;
+ while( aParser.Parse() ) {}
+ SbiSymPool* pPool = aParser.pPool;
aCache.Clear();
for( sal_uInt16 i = 0; i < pPool->GetSize(); ++i )
{
SbiSymDef* pSymDef = pPool->Get(i);
//std::cerr << "i: " << i << ", type: " << pSymDef->GetType() << "; name:" << pSymDef->GetName() << std::endl;
if( (pSymDef->GetType() != SbxEMPTY) && (pSymDef->GetType() != SbxNULL) )
- aCache.InsertGlobalVar( pSymDef->GetName(), pParser->aGblStrings.Find(pSymDef->GetTypeId()) );
+ aCache.InsertGlobalVar( pSymDef->GetName(), aParser.aGblStrings.Find(pSymDef->GetTypeId()) );
SbiSymPool& rChildPool = pSymDef->GetPool();
for(sal_uInt16 j = 0; j < rChildPool.GetSize(); ++j )
@@ -1730,13 +1723,13 @@ void SbModule::GetCodeCompleteDataFromParse(CodeCompleteDataCache& aCache)
SbiSymDef* pChildSymDef = rChildPool.Get(j);
//std::cerr << "j: " << j << ", type: " << pChildSymDef->GetType() << "; name:" << pChildSymDef->GetName() << std::endl;
if( (pChildSymDef->GetType() != SbxEMPTY) && (pChildSymDef->GetType() != SbxNULL) )
- aCache.InsertLocalVar( pSymDef->GetName(), pChildSymDef->GetName(), pParser->aGblStrings.Find(pChildSymDef->GetTypeId()) );
+ aCache.InsertLocalVar( pSymDef->GetName(), pChildSymDef->GetName(), aParser.aGblStrings.Find(pChildSymDef->GetTypeId()) );
}
}
}
-OUString SbModule::GetKeywordCase( const OUString& sKeyword )
+OUString SbModule::GetKeywordCase( std::u16string_view sKeyword )
{
return SbiParser::GetKeywordCase( sKeyword );
}
@@ -1745,7 +1738,7 @@ bool SbModule::HasExeCode()
{
// And empty Image always has the Global Chain set up
static const unsigned char pEmptyImage[] = { 0x45, 0x0 , 0x0, 0x0, 0x0 };
- // lets be stricter for the moment than VBA
+ // let's be stricter for the moment than VBA
if (!IsCompiled())
{
@@ -1768,7 +1761,8 @@ void SbModule::StoreBinaryData( SvStream& rStrm )
if (!Compile())
return;
- if (!SbxObject::StoreData(rStrm))
+ const auto [bSuccess, nVersion] = SbxObject::StoreData(rStrm);
+ if (!bSuccess)
return;
pImage->aOUSource.clear();
@@ -1776,7 +1770,7 @@ void SbModule::StoreBinaryData( SvStream& rStrm )
pImage->aName = GetName();
rStrm.WriteUChar(1);
- pImage->Save(rStrm);
+ pImage->Save(rStrm, nVersion);
pImage->aOUSource = aOUSource;
}
@@ -1902,7 +1896,7 @@ void SbModule::handleProcedureProperties( SfxBroadcaster& rBC, const SfxHint& rH
// Implementation SbJScriptModule (Basic module for JavaScript source code)
SbJScriptModule::SbJScriptModule()
- :SbModule( "" )
+ :SbModule( u""_ustr )
{
}
@@ -1917,15 +1911,16 @@ bool SbJScriptModule::LoadData( SvStream& rStrm, sal_uInt16 )
return true;
}
-bool SbJScriptModule::StoreData( SvStream& rStrm ) const
+std::pair<bool, sal_uInt32> SbJScriptModule::StoreData( SvStream& rStrm ) const
{
- if( !SbxObject::StoreData( rStrm ) )
- return false;
+ const auto [bSuccess, nVersion] = SbxObject::StoreData(rStrm);
+ if( !bSuccess )
+ return { false, 0 };
// Write the source string
OUString aTmp = aOUSource;
rStrm.WriteUniOrByteString( aTmp, osl_getThreadTextEncoding() );
- return true;
+ return { true, nVersion };
}
@@ -2007,16 +2002,24 @@ bool SbMethod::LoadData( SvStream& rStrm, sal_uInt16 nVer )
return true;
}
-bool SbMethod::StoreData( SvStream& rStrm ) const
+std::pair<bool, sal_uInt32> SbMethod::StoreData( SvStream& rStrm ) const
{
- if( !SbxMethod::StoreData( rStrm ) )
- return false;
+ auto [bSuccess, nVersion] = SbxMethod::StoreData(rStrm);
+ if( !bSuccess )
+ return { false, 0 };
//tdf#94617
- sal_Int16 nMax = std::numeric_limits<sal_Int16>::max();
- sal_Int16 nStartTemp = nStart % nMax;
- sal_uInt16 nDebugFlagsTemp = nStart / nMax;
- nDebugFlagsTemp |= 0x8000;
+ const sal_uInt32 nMax = std::numeric_limits<sal_Int16>::max();
+ // tdf#142391 - store method using binary format 0x13 only when actually needed, i.e.,
+ // when method starts at an offset that would overflow 16 bits
+ const sal_Int16 nStartTemp = nStart % nMax;
+ sal_uInt16 nDebugFlagsTemp = static_cast<sal_uInt16>(nDebugFlags);
+ if (nStart >= nMax)
+ {
+ assert(nStart <= nMax * 0x7FFF); // Larger addresses can't be stored in version 13
+ nDebugFlagsTemp = (nStart / nMax) | 0x8000;
+ nVersion = B_IMG_VERSION_13;
+ }
rStrm.WriteUInt16( nDebugFlagsTemp )
.WriteInt16( nLine1 )
@@ -2024,7 +2027,7 @@ bool SbMethod::StoreData( SvStream& rStrm ) const
.WriteInt16( nStartTemp )
.WriteBool( bInvalid );
- return true;
+ return { true, nVersion };
}
void SbMethod::GetLineRange( sal_uInt16& l1, sal_uInt16& l2 )
@@ -2062,6 +2065,9 @@ ErrCode SbMethod::Call( SbxValue* pRet, SbxVariable* pCaller )
if( bInvalid && !pMod_->Compile() )
StarBASIC::Error( ERRCODE_BASIC_BAD_PROP_VALUE );
+ // tdf#143582 - clear return value of the method before calling it
+ Clear();
+
Get( aVals );
if ( pRet )
pRet->Put( aVals );
@@ -2120,7 +2126,7 @@ void SbMethod::Broadcast( SfxHintId nHintId )
// Implementation of SbJScriptMethod (method class as a wrapper for JavaScript-functions)
SbJScriptMethod::SbJScriptMethod( SbxDataType t )
- : SbMethod( "", t, nullptr )
+ : SbMethod( u""_ustr, t, nullptr )
{
}
@@ -2134,7 +2140,7 @@ SbObjModule::SbObjModule( const OUString& rName, const css::script::ModuleInfo&
SetModuleType( mInfo.ModuleType );
if ( mInfo.ModuleType == script::ModuleType::FORM )
{
- SetClassName( "Form" );
+ SetClassName( u"Form"_ustr );
}
else if ( mInfo.ModuleObject.is() )
{
@@ -2149,19 +2155,19 @@ SbObjModule::~SbObjModule()
void
SbObjModule::SetUnoObject( const uno::Any& aObj )
{
- SbUnoObject* pUnoObj = dynamic_cast<SbUnoObject*>( pDocObject.get() );
+ SbUnoObject* pUnoObj = pDocObject.get();
if ( pUnoObj && pUnoObj->getUnoAny() == aObj ) // object is equal, nothing to do
return;
pDocObject = new SbUnoObject( GetName(), aObj );
css::uno::Reference< css::lang::XServiceInfo > xServiceInfo( aObj, css::uno::UNO_QUERY_THROW );
- if( xServiceInfo->supportsService( "ooo.vba.excel.Worksheet" ) )
+ if( xServiceInfo->supportsService( u"ooo.vba.excel.Worksheet"_ustr ) )
{
- SetClassName( "Worksheet" );
+ SetClassName( u"Worksheet"_ustr );
}
- else if( xServiceInfo->supportsService( "ooo.vba.excel.Workbook" ) )
+ else if( xServiceInfo->supportsService( u"ooo.vba.excel.Workbook"_ustr ) )
{
- SetClassName( "Workbook" );
+ SetClassName( u"Workbook"_ustr );
}
}
@@ -2206,8 +2212,8 @@ class FormObjEventListenerImpl:
public:
FormObjEventListenerImpl(const FormObjEventListenerImpl&) = delete;
const FormObjEventListenerImpl& operator=(const FormObjEventListenerImpl&) = delete;
- FormObjEventListenerImpl( SbUserFormModule* pUserForm, const uno::Reference< lang::XComponent >& xComponent, const uno::Reference< frame::XModel >& xModel ) :
- mpUserForm( pUserForm ), mxComponent( xComponent), mxModel( xModel ),
+ FormObjEventListenerImpl( SbUserFormModule* pUserForm, uno::Reference< lang::XComponent > xComponent, uno::Reference< frame::XModel > xModel ) :
+ mpUserForm( pUserForm ), mxComponent(std::move( xComponent)), mxModel(std::move( xModel )),
mbDisposed( false ), mbOpened( false ), mbActivated( false ), mbShowing( false )
{
if ( mxComponent.is() )
@@ -2377,6 +2383,7 @@ public:
// early disposing on document event "OnUnload", to be sure Basic still exists when calling VBA "UserForm_Terminate"
if( rEvent.EventName == GlobalEventConfig::GetEventName( GlobalEventId::CLOSEDOC ) )
{
+ SolarMutexGuard g;
removeListener();
mbDisposed = true;
if ( mpUserForm )
@@ -2466,41 +2473,41 @@ void SbUserFormModule::triggerMethod( const OUString& aMethodToRun, Sequence< An
void SbUserFormModule::triggerActivateEvent()
{
- triggerMethod( "UserForm_Activate" );
+ triggerMethod( u"UserForm_Activate"_ustr );
}
void SbUserFormModule::triggerDeactivateEvent()
{
- triggerMethod( "Userform_Deactivate" );
+ triggerMethod( u"Userform_Deactivate"_ustr );
}
void SbUserFormModule::triggerInitializeEvent()
{
if ( mbInit )
return;
- triggerMethod("Userform_Initialize");
+ triggerMethod(u"Userform_Initialize"_ustr);
mbInit = true;
}
void SbUserFormModule::triggerTerminateEvent()
{
- triggerMethod("Userform_Terminate");
+ triggerMethod(u"Userform_Terminate"_ustr);
mbInit=false;
}
void SbUserFormModule::triggerLayoutEvent()
{
- triggerMethod("Userform_Layout");
+ triggerMethod(u"Userform_Layout"_ustr);
}
void SbUserFormModule::triggerResizeEvent()
{
- triggerMethod("Userform_Resize");
+ triggerMethod(u"Userform_Resize"_ustr);
}
SbUserFormModuleInstance* SbUserFormModule::CreateInstance()
{
- SbUserFormModuleInstance* pInstance = new SbUserFormModuleInstance( this, GetName(), m_mInfo, IsVBACompat() );
+ SbUserFormModuleInstance* pInstance = new SbUserFormModuleInstance( this, GetName(), m_mInfo, IsVBASupport() );
return pInstance;
}
@@ -2539,7 +2546,7 @@ void SbUserFormModule::Unload()
Sequence< Any > aParams = { Any(nCancel), Any(sal_Int8(::ooo::vba::VbQueryClose::vbFormCode)) };
- triggerMethod( "Userform_QueryClose", aParams);
+ triggerMethod( u"Userform_QueryClose"_ustr, aParams);
aParams[0] >>= nCancel;
// basic boolean ( and what the user might use ) can be ambiguous ( e.g. basic true = -1 )
@@ -2555,7 +2562,7 @@ void SbUserFormModule::Unload()
triggerTerminateEvent();
}
// Search method
- SbxVariable* pMeth = SbObjModule::Find( "UnloadObject", SbxClassType::Method );
+ SbxVariable* pMeth = SbObjModule::Find( u"UnloadObject"_ustr, SbxClassType::Method );
if( !pMeth )
return;
@@ -2582,21 +2589,21 @@ void SbUserFormModule::InitObject()
{
try
{
- SbUnoObject* pGlobs = static_cast<SbUnoObject*>(GetParent()->Find( "VBAGlobals", SbxClassType::DontCare ));
+ SbUnoObject* pGlobs = static_cast<SbUnoObject*>(GetParent()->Find( u"VBAGlobals"_ustr, SbxClassType::DontCare ));
if ( m_xModel.is() && pGlobs )
{
// broadcast INITIALIZE_USERFORM script event before the dialog is created
Reference< script::vba::XVBACompatibility > xVBACompat( getVBACompatibility( m_xModel ), uno::UNO_SET_THROW );
xVBACompat->broadcastVBAScriptEvent( script::vba::VBAScriptEventId::INITIALIZE_USERFORM, GetName() );
uno::Reference< lang::XMultiServiceFactory > xVBAFactory( pGlobs->getUnoAny(), uno::UNO_QUERY_THROW );
- uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
- OUString sDialogUrl( "vnd.sun.star.script:" );
- OUString sProjectName( "Standard" );
+ const uno::Reference< uno::XComponentContext >& xContext = comphelper::getProcessComponentContext();
+ OUString sDialogUrl( u"vnd.sun.star.script:"_ustr );
+ OUString sProjectName( u"Standard"_ustr );
try
{
Reference< beans::XPropertySet > xProps( m_xModel, UNO_QUERY_THROW );
- uno::Reference< script::vba::XVBACompatibility > xVBAMode( xProps->getPropertyValue( "BasicLibraries" ), uno::UNO_QUERY_THROW );
+ uno::Reference< script::vba::XVBACompatibility > xVBAMode( xProps->getPropertyValue( u"BasicLibraries"_ustr ), uno::UNO_QUERY_THROW );
sProjectName = xVBAMode->getProjectName();
}
catch(const Exception& ) {}
@@ -2610,11 +2617,11 @@ void SbUserFormModule::InitObject()
uno::Sequence< uno::Any > aArgs
{
uno::Any(),
- makeAny(m_xDialog),
- makeAny(m_xModel),
- makeAny(GetParent()->GetName())
+ Any(m_xDialog),
+ Any(m_xModel),
+ Any(GetParent()->GetName())
};
- pDocObject = new SbUnoObject( GetName(), uno::Any( xVBAFactory->createInstanceWithArguments( "ooo.vba.msforms.UserForm", aArgs ) ) );
+ pDocObject = new SbUnoObject( GetName(), uno::Any( xVBAFactory->createInstanceWithArguments( u"ooo.vba.msforms.UserForm"_ustr, aArgs ) ) );
uno::Reference< lang::XComponent > xComponent( m_xDialog, uno::UNO_QUERY_THROW );
diff --git a/basic/source/comp/buffer.cxx b/basic/source/comp/buffer.cxx
index 07d1d85e53ee..0ff898fd6940 100644
--- a/basic/source/comp/buffer.cxx
+++ b/basic/source/comp/buffer.cxx
@@ -18,6 +18,7 @@
*/
#include <buffer.hxx>
+#include <basic/sberrors.hxx>
namespace
{
@@ -48,7 +49,6 @@ template <typename T> void SbiBuffer::append(T n)
m_aBuf.clear();
return;
}
- m_aBuf.reserve(m_aBuf.size() + sizeof(n));
write(std::back_inserter(m_aBuf), n);
}
@@ -82,7 +82,7 @@ void SbiBuffer::Chain( sal_uInt32 off )
if ((i + sizeof(sal_uInt32)) > GetSize())
{
m_aErrCode = ERRCODE_BASIC_INTERNAL_ERROR;
- m_sErrMsg = "BACKCHAIN";
+ m_sErrMsg = u"BACKCHAIN"_ustr;
break;
}
auto ip = m_aBuf.begin() + i;
diff --git a/basic/source/comp/codegen.cxx b/basic/source/comp/codegen.cxx
index 3442202a8ba1..ea3856269cf3 100644
--- a/basic/source/comp/codegen.cxx
+++ b/basic/source/comp/codegen.cxx
@@ -29,9 +29,9 @@
#include <cstddef>
#include <limits>
#include <algorithm>
-#include <string_view>
#include <osl/diagnose.h>
#include <rtl/ustrbuf.hxx>
+#include <o3tl/string_view.hxx>
#include <com/sun/star/script/ModuleType.hpp>
// nInc is the increment size of the buffers
@@ -92,7 +92,7 @@ sal_uInt32 SbiCodeGen::Gen( SbiOpcode eOpcode )
#ifdef DBG_UTIL
if( eOpcode < SbiOpcode::SbOP0_START || eOpcode > SbiOpcode::SbOP0_END )
- pParser->Error( ERRCODE_BASIC_INTERNAL_ERROR, "OPCODE1" );
+ pParser->Error( ERRCODE_BASIC_INTERNAL_ERROR, u"OPCODE1"_ustr );
#endif
GenStmnt();
aCode += static_cast<sal_uInt8>(eOpcode);
@@ -106,7 +106,7 @@ sal_uInt32 SbiCodeGen::Gen( SbiOpcode eOpcode, sal_uInt32 nOpnd )
#ifdef DBG_UTIL
if( eOpcode < SbiOpcode::SbOP1_START || eOpcode > SbiOpcode::SbOP1_END )
- pParser->Error( ERRCODE_BASIC_INTERNAL_ERROR, "OPCODE2" );
+ pParser->Error( ERRCODE_BASIC_INTERNAL_ERROR, u"OPCODE2"_ustr );
#endif
GenStmnt();
aCode += static_cast<sal_uInt8>(eOpcode);
@@ -122,7 +122,7 @@ sal_uInt32 SbiCodeGen::Gen( SbiOpcode eOpcode, sal_uInt32 nOpnd1, sal_uInt32 nOp
#ifdef DBG_UTIL
if( eOpcode < SbiOpcode::SbOP2_START || eOpcode > SbiOpcode::SbOP2_END )
- pParser->Error( ERRCODE_BASIC_INTERNAL_ERROR, "OPCODE3" );
+ pParser->Error( ERRCODE_BASIC_INTERNAL_ERROR, u"OPCODE3"_ustr );
#endif
GenStmnt();
aCode += static_cast<sal_uInt8>(eOpcode);
@@ -201,24 +201,24 @@ void SbiCodeGen::Save()
if( nIfaceCount )
{
int nPropPrefixFound = aProcName.indexOf("Property ");
- OUString aPureProcName = aProcName;
- OUString aPropPrefix;
+ std::u16string_view aPureProcName = aProcName;
+ std::u16string_view aPropPrefix;
if( nPropPrefixFound == 0 )
{
- aPropPrefix = aProcName.copy( 0, 13 ); // 13 == Len( "Property ?et " )
- aPureProcName = aProcName.copy( 13 );
+ aPropPrefix = aProcName.subView( 0, 13 ); // 13 == Len( "Property ?et " )
+ aPureProcName = aProcName.subView( 13 );
}
for( int i = 0 ; i < nIfaceCount ; i++ )
{
const OUString& rIfaceName = pParser->aIfaceVector[i];
- int nFound = aPureProcName.indexOf( rIfaceName );
- if( nFound == 0 && aPureProcName[rIfaceName.getLength()] == '_' )
+ bool bFound = o3tl::starts_with(aPureProcName, rIfaceName );
+ if( bFound && aPureProcName[rIfaceName.getLength()] == '_' )
{
if( nPropPrefixFound == 0 )
{
aIfaceProcName.append(aPropPrefix);
}
- aIfaceProcName.append(aPureProcName.subView(rIfaceName.getLength() + 1) );
+ aIfaceProcName.append(aPureProcName.substr(rIfaceName.getLength() + 1) );
aIfaceName = rIfaceName;
nPassCount = 2;
break;
diff --git a/basic/source/comp/dim.cxx b/basic/source/comp/dim.cxx
index cbc25b0152b4..16429d1b523f 100644
--- a/basic/source/comp/dim.cxx
+++ b/basic/source/comp/dim.cxx
@@ -63,13 +63,13 @@ SbiSymDef* SbiParser::VarDecl( SbiExprListPtr* ppDim, bool bStatic, bool bConst
if( bWithEvents )
pDef->SetWithEvents();
TypeDecl( *pDef );
- if( !ppDim && pDim )
+ if (ppDim)
+ *ppDim = std::move(pDim);
+ else if (pDim)
{
if(pDim->GetDims() )
- Error( ERRCODE_BASIC_EXPECTED, "()" );
+ Error( ERRCODE_BASIC_EXPECTED, u"()"_ustr );
}
- else if( ppDim )
- *ppDim = std::move(pDim);
return pDef;
}
@@ -704,8 +704,8 @@ void SbiParser::DefType()
}
}
- pType->Remove( "Name", SbxClassType::DontCare );
- pType->Remove( "Parent", SbxClassType::DontCare );
+ pType->Remove( u"Name"_ustr, SbxClassType::DontCare );
+ pType->Remove( u"Parent"_ustr, SbxClassType::DontCare );
rTypeArray->Insert(pType, rTypeArray->Count());
}
@@ -835,8 +835,8 @@ void SbiParser::DefEnum( bool bPrivate )
}
}
- pEnum->Remove( "Name", SbxClassType::DontCare );
- pEnum->Remove( "Parent", SbxClassType::DontCare );
+ pEnum->Remove( u"Name"_ustr, SbxClassType::DontCare );
+ pEnum->Remove( u"Parent"_ustr, SbxClassType::DontCare );
rEnumArray->Insert(pEnum, rEnumArray->Count());
}
@@ -987,20 +987,21 @@ SbiProcDef* SbiParser::ProcDecl( bool bDecl )
bool bError2 = true;
if( bOptional && bCompatible && eTok == EQ )
{
- auto pDefaultExpr = std::make_unique<SbiConstExpression>(this);
- SbxDataType eType2 = pDefaultExpr->GetType();
-
- sal_uInt16 nStringId;
- if( eType2 == SbxSTRING )
- {
- nStringId = aGblStrings.Add( pDefaultExpr->GetString() );
- }
- else
{
- nStringId = aGblStrings.Add( pDefaultExpr->GetValue(), eType2 );
+ SbiConstExpression aDefaultExpr(this);
+ SbxDataType eType2 = aDefaultExpr.GetType();
+
+ sal_uInt16 nStringId;
+ if (eType2 == SbxSTRING)
+ {
+ nStringId = aGblStrings.Add(aDefaultExpr.GetString());
+ }
+ else
+ {
+ nStringId = aGblStrings.Add(aDefaultExpr.GetValue(), eType2);
+ }
+ pPar->SetDefaultId(nStringId);
}
- pPar->SetDefaultId( nStringId );
- pDefaultExpr.reset();
eTok = Next();
if( eTok == COMMA || eTok == RPAREN )
@@ -1220,7 +1221,7 @@ void SbiParser::DefProc( bool bStatic, bool bPrivate )
}
else
{
- Error( ERRCODE_BASIC_EXPECTED, "Get or Let or Set" );
+ Error( ERRCODE_BASIC_EXPECTED, u"Get or Let or Set"_ustr );
}
}
diff --git a/basic/source/comp/exprgen.cxx b/basic/source/comp/exprgen.cxx
index 76f1ab776a63..4111e68fc0a2 100644
--- a/basic/source/comp/exprgen.cxx
+++ b/basic/source/comp/exprgen.cxx
@@ -58,7 +58,7 @@ const OpTable aOpTable [] = {
{ CAT, SbiOpcode::CAT_ },
{ LIKE, SbiOpcode::LIKE_ },
{ IS, SbiOpcode::IS_ },
- { NIL, SbiOpcode::NOP_ }};
+};
// Output of an element
void SbiExprNode::Gen( SbiCodeGen& rGen, RecursiveMode eRecMode )
@@ -136,12 +136,12 @@ void SbiExprNode::Gen( SbiCodeGen& rGen, RecursiveMode eRecMode )
eOp = SbiOpcode::FIND_STATIC_;
}
}
+
+ if (pWithParent_ != nullptr)
+ pWithParent_->Gen(rGen);
+
for( SbiExprNode* p = this; p; p = p->aVar.pNext )
{
- if( p == this && pWithParent_ != nullptr )
- {
- pWithParent_->Gen(rGen);
- }
p->GenElement( rGen, eOp );
eOp = SbiOpcode::ELEM_;
}
@@ -162,11 +162,12 @@ void SbiExprNode::Gen( SbiCodeGen& rGen, RecursiveMode eRecMode )
{
pRight->Gen(rGen);
}
- for( const OpTable* p = aOpTable; p->eTok != NIL; p++ )
+ for (const OpTable& op : aOpTable)
{
- if( p->eTok == eTok )
+ if (op.eTok == eTok)
{
- rGen.Gen( p->eOp ); break;
+ rGen.Gen(op.eOp);
+ break;
}
}
}
@@ -178,7 +179,7 @@ void SbiExprNode::GenElement( SbiCodeGen& rGen, SbiOpcode eOp )
{
#ifdef DBG_UTIL
if ((eOp < SbiOpcode::RTL_ || eOp > SbiOpcode::CALLC_) && eOp != SbiOpcode::FIND_G_ && eOp != SbiOpcode::FIND_CM_ && eOp != SbiOpcode::FIND_STATIC_)
- rGen.GetParser()->Error( ERRCODE_BASIC_INTERNAL_ERROR, "Opcode" );
+ rGen.GetParser()->Error( ERRCODE_BASIC_INTERNAL_ERROR, u"Opcode"_ustr );
#endif
SbiSymDef* pDef = aVar.pDef;
// The ID is either the position or the String-ID
diff --git a/basic/source/comp/exprnode.cxx b/basic/source/comp/exprnode.cxx
index 17bdbca25258..d6733e96d1ee 100644
--- a/basic/source/comp/exprnode.cxx
+++ b/basic/source/comp/exprnode.cxx
@@ -28,6 +28,7 @@
#include <basic/sberrors.hxx>
#include <rtl/math.hxx>
+#include <utility>
SbiExprNode::SbiExprNode( std::unique_ptr<SbiExprNode> l, SbiToken t, std::unique_ptr<SbiExprNode> r ) :
pLeft(std::move(l)),
@@ -50,8 +51,8 @@ SbiExprNode::SbiExprNode( double n, SbxDataType t ):
{
}
-SbiExprNode::SbiExprNode( const OUString& rVal ):
- aStrVal(rVal),
+SbiExprNode::SbiExprNode( OUString aVal ):
+ aStrVal(std::move(aVal)),
pWithParent(nullptr),
eNodeType(SbxSTRVAL),
eType(SbxSTRING),
@@ -117,7 +118,7 @@ SbiExprNode::~SbiExprNode()
SbiSymDef* SbiExprNode::GetVar()
{
- if( eNodeType == SbxVARVAL )
+ if (IsVariable())
return aVar.pDef;
else
return nullptr;
@@ -135,7 +136,7 @@ SbiSymDef* SbiExprNode::GetRealVar()
// From 1995-12-18
SbiExprNode* SbiExprNode::GetRealNode()
{
- if( eNodeType == SbxVARVAL )
+ if (IsVariable())
{
SbiExprNode* p = this;
while( p->aVar.pNext )
@@ -296,8 +297,8 @@ void SbiExprNode::FoldConstantsBinaryNode(SbiParser* pParser)
{
double nl = pLeft->nVal;
double nr = pRight->nVal;
- // tdf#141201 - round MOD literals to Integer values
- if (eTok == MOD)
+ // tdf#141201, tdf#147089 - round MOD/IDIV literals to Integer values
+ if (eTok == MOD || eTok == IDIV)
{
nl = rtl::math::round(nl);
nr = rtl::math::round(nr);
diff --git a/basic/source/comp/exprtree.cxx b/basic/source/comp/exprtree.cxx
index 6b101ce81ca6..2f0316428ce6 100644
--- a/basic/source/comp/exprtree.cxx
+++ b/basic/source/comp/exprtree.cxx
@@ -333,7 +333,9 @@ std::unique_ptr<SbiExprNode> SbiExpression::Term( const KeywordSymbolInfo* pKeyw
// from 16.12.95 (similar cases possible perhaps?!?)
if( eType == SbxOBJECT && pDef->GetType() == SbxVARIANT )
{
- pDef->SetType( SbxOBJECT );
+ // Do not modify the type of procedure arguments
+ if (pDef->GetScope() != SbPARAM)
+ pDef->SetType(SbxOBJECT);
}
else
{
@@ -352,7 +354,8 @@ std::unique_ptr<SbiExprNode> SbiExpression::Term( const KeywordSymbolInfo* pKeyw
if( bObj )
{
// from 8.1.95: Object may also be of the type SbxVARIANT
- if( pDef->GetType() == SbxVARIANT )
+ // (but do not modify type of procedure arguments)
+ if (pDef->GetType() == SbxVARIANT && pDef->GetScope() != SbPARAM)
pDef->SetType( SbxOBJECT );
// if we scan something with point,
// the type must be SbxOBJECT
@@ -719,7 +722,6 @@ std::unique_ptr<SbiExprNode> SbiExpression::Comp()
std::unique_ptr<SbiExprNode> pNd = Cat();
if( m_eMode != EXPRMODE_EMPTY_PAREN )
{
- short nCount = 0;
for( ;; )
{
SbiToken eTok = pParser->Peek();
@@ -734,7 +736,6 @@ std::unique_ptr<SbiExprNode> SbiExpression::Comp()
}
eTok = pParser->Next();
pNd = std::make_unique<SbiExprNode>( std::move(pNd), eTok, Cat() );
- nCount++;
}
}
return pNd;
@@ -1036,7 +1037,7 @@ SbiExprListPtr SbiExprList::ParseParameters( SbiParser* pParser, bool bStandalon
// tdf#106529: only fail here in strict mode (i.e. when compiled from IDE), and
// allow legacy code with missing closing parenthesis when started e.g. from
// extensions and event handlers
- if (comphelper::IsContextFlagActive("BasicStrict"))
+ if (comphelper::IsContextFlagActive(u"BasicStrict"_ustr))
{
pParser->Error(ERRCODE_BASIC_EXPECTED, RPAREN);
pExprList->bError = true;
diff --git a/basic/source/comp/io.cxx b/basic/source/comp/io.cxx
index 9e91413fd997..3973dca21de4 100644
--- a/basic/source/comp/io.cxx
+++ b/basic/source/comp/io.cxx
@@ -38,7 +38,7 @@ bool SbiParser::Channel( bool bAlways )
bRes = true;
}
else if( bAlways )
- Error( ERRCODE_BASIC_EXPECTED, "#" );
+ Error( ERRCODE_BASIC_EXPECTED, u"#"_ustr );
return bRes;
}
@@ -53,9 +53,7 @@ void SbiParser::Print()
{
if( !IsEoln( Peek() ) )
{
- auto pExpr = std::make_unique<SbiExpression>(this);
- pExpr->Gen();
- pExpr.reset();
+ SbiExpression(this).Gen();
Peek();
aGen.Gen( eCurTok == COMMA ? SbiOpcode::PRINTF_ : SbiOpcode::BPRINT_ );
}
@@ -82,9 +80,7 @@ void SbiParser::Write()
while( !bAbort )
{
- auto pExpr = std::make_unique<SbiExpression>(this);
- pExpr->Gen();
- pExpr.reset();
+ SbiExpression(this).Gen();
aGen.Gen( SbiOpcode::BWRITE_ );
if( Peek() == COMMA )
{
@@ -130,14 +126,15 @@ void SbiParser::Line()
void SbiParser::LineInput()
{
Channel( true );
- auto pExpr = std::make_unique<SbiExpression>( this, SbOPERAND );
- if( !pExpr->IsVariable() )
- Error( ERRCODE_BASIC_VAR_EXPECTED );
- if( pExpr->GetType() != SbxVARIANT && pExpr->GetType() != SbxSTRING )
- Error( ERRCODE_BASIC_CONVERSION );
- pExpr->Gen();
- aGen.Gen( SbiOpcode::LINPUT_ );
- pExpr.reset();
+ {
+ SbiExpression aExpr(this, SbOPERAND);
+ if (!aExpr.IsVariable())
+ Error(ERRCODE_BASIC_VAR_EXPECTED);
+ if (aExpr.GetType() != SbxVARIANT && aExpr.GetType() != SbxSTRING)
+ Error(ERRCODE_BASIC_CONVERSION);
+ aExpr.Gen();
+ aGen.Gen(SbiOpcode::LINPUT_);
+ }
aGen.Gen( SbiOpcode::CHAN0_ ); // ResetChannel() not in StepLINPUT() anymore
}
@@ -147,21 +144,17 @@ void SbiParser::Input()
{
aGen.Gen( SbiOpcode::RESTART_ );
Channel( true );
- auto pExpr = std::make_unique<SbiExpression>( this, SbOPERAND );
while( !bAbort )
{
- if( !pExpr->IsVariable() )
+ SbiExpression aExpr(this, SbOPERAND);
+ if (!aExpr.IsVariable())
Error( ERRCODE_BASIC_VAR_EXPECTED );
- pExpr->Gen();
+ aExpr.Gen();
aGen.Gen( SbiOpcode::INPUT_ );
- if( Peek() == COMMA )
- {
- Next();
- pExpr.reset(new SbiExpression( this, SbOPERAND ));
- }
- else break;
+ if (Peek() != COMMA)
+ break;
+ Next();
}
- pExpr.reset();
aGen.Gen( SbiOpcode::CHAN0_ );
}
@@ -236,7 +229,7 @@ void SbiParser::Open()
}
TestToken( AS );
// channel number
- auto pChan = std::make_unique<SbiExpression>( this );
+ SbiExpression aChan( this );
std::unique_ptr<SbiExpression> pLen;
if( Peek() == SYMBOL )
{
@@ -253,7 +246,7 @@ void SbiParser::Open()
// channel number
// file name
pLen->Gen();
- pChan->Gen();
+ aChan.Gen();
aFileName.Gen();
aGen.Gen( SbiOpcode::OPEN_, static_cast<sal_uInt32>(nMode), static_cast<sal_uInt32>(nFlags) );
bInStatement = false;
diff --git a/basic/source/comp/loops.cxx b/basic/source/comp/loops.cxx
index 07aac44943a6..4ad4d1fb08ae 100644
--- a/basic/source/comp/loops.cxx
+++ b/basic/source/comp/loops.cxx
@@ -22,6 +22,14 @@
#include <memory>
#include <basic/sberrors.hxx>
+#include <basic/sbmod.hxx>
+
+#include <rtl/ustrbuf.hxx>
+
+static bool EndsIfBranch(SbiToken eTok)
+{
+ return eTok == ELSEIF || eTok == ELSE || eTok == ENDIF;
+}
// Single-line IF and Multiline IF
@@ -38,20 +46,19 @@ void SbiParser::If()
// At the end of each block a jump to ENDIF must be inserted,
// so that the condition is not evaluated again at ELSEIF.
// The table collects all jump points.
-#define JMP_TABLE_SIZE 100
+ constexpr sal_uInt16 JMP_TABLE_SIZE = 100;
sal_uInt32 pnJmpToEndLbl[JMP_TABLE_SIZE]; // 100 ELSEIFs allowed
sal_uInt16 iJmp = 0; // current table index
// multiline IF
nEndLbl = aGen.Gen( SbiOpcode::JUMPF_, 0 );
eTok = Peek();
- while( !( eTok == ELSEIF || eTok == ELSE || eTok == ENDIF ) &&
- !bAbort && Parse() )
+ while (!EndsIfBranch(eTok) && !bAbort && Parse())
{
eTok = Peek();
if( IsEof() )
{
- Error( ERRCODE_BASIC_BAD_BLOCK, IF ); bAbort = true; return;
+ Error( ERRCODE_BASIC_BAD_BLOCK, ENDIF ); bAbort = true; return;
}
}
while( eTok == ELSEIF )
@@ -73,13 +80,12 @@ void SbiParser::If()
pCond.reset();
TestToken( THEN );
eTok = Peek();
- while( !( eTok == ELSEIF || eTok == ELSE || eTok == ENDIF ) &&
- !bAbort && Parse() )
+ while (!EndsIfBranch(eTok) && !bAbort && Parse())
{
eTok = Peek();
if( IsEof() )
{
- Error( ERRCODE_BASIC_BAD_BLOCK, ELSEIF ); bAbort = true; return;
+ Error( ERRCODE_BASIC_BAD_BLOCK, ENDIF ); bAbort = true; return;
}
}
}
@@ -95,7 +101,12 @@ void SbiParser::If()
}
else if( eTok == ENDIF )
Next();
-
+ else
+ {
+ Error(ERRCODE_BASIC_BAD_BLOCK, ENDIF);
+ bAbort = true;
+ return;
+ }
while( iJmp > 0 )
{
@@ -210,6 +221,11 @@ void SbiParser::For()
if( bForEach )
Next();
SbiExpression aLvalue( this, SbOPERAND );
+ if (!aLvalue.IsVariable())
+ {
+ bAbort = true;
+ return; // the error is already set in SbiExpression ctor
+ }
aLvalue.Gen(); // variable on the Stack
if( bForEach )
@@ -265,6 +281,63 @@ void SbiParser::For()
// WITH .. END WITH
+namespace
+{
+// Generate a '{_with_library.module_offset} = rVar'
+// Use the {_with_library.module_offset} in OpenBlock
+// The name of the variable can't be used by user: a name like [{_with_library.module_offset}]
+// is valid, but not without the square brackets
+struct WithLocalVar
+{
+ WithLocalVar(SbiParser& rParser, SbiExpression& rVar)
+ : m_rParser(rParser)
+ , m_aWithParent(createLocalVar(rParser))
+ {
+ // Assignment
+ m_aWithParent.Gen();
+ rVar.Gen();
+ m_rParser.aGen.Gen(SbiOpcode::PUTC_);
+ }
+
+ ~WithLocalVar()
+ {
+ // {_with_library.module_offset} = Nothing
+ m_aWithParent.Gen();
+ m_rParser.aGen.Gen(SbiOpcode::RTL_, m_rParser.aGblStrings.Add(u"Nothing"_ustr), SbxOBJECT);
+ m_rParser.aGen.Gen(SbiOpcode::PUTC_);
+ }
+
+ static SbiExpression createLocalVar(SbiParser& rParser)
+ {
+ // Create the unique name
+ OUStringBuffer moduleName(rParser.aGen.GetModule().GetName());
+ for (auto parent = rParser.aGen.GetModule().GetParent(); parent;
+ parent = parent->GetParent())
+ moduleName.insert(0, parent->GetName() + ".");
+
+ OUString uniqueName
+ = "{_with_" + moduleName + "_" + OUString::number(rParser.aGen.GetOffset()) + "}";
+ while (rParser.pPool->Find(uniqueName) != nullptr)
+ {
+ static sal_Int64 unique_suffix;
+ uniqueName = "{_with_" + moduleName + "_" + OUString::number(rParser.aGen.GetOffset())
+ + "_" + OUString::number(unique_suffix++) + "}";
+ }
+ SbiSymDef* pWithParentDef = new SbiSymDef(uniqueName);
+ pWithParentDef->SetType(SbxOBJECT);
+ rParser.pPool->Add(pWithParentDef);
+
+ // DIM local variable: work with Option Explicit
+ rParser.aGen.Gen(SbiOpcode::LOCAL_, pWithParentDef->GetId(), pWithParentDef->GetType());
+
+ return SbiExpression(&rParser, *pWithParentDef);
+ }
+
+ SbiParser& m_rParser;
+ SbiExpression m_aWithParent;
+};
+}
+
void SbiParser::With()
{
SbiExpression aVar( this, SbOPERAND );
@@ -279,24 +352,17 @@ void SbiParser::With()
else if( pDef->GetType() != SbxOBJECT )
Error( ERRCODE_BASIC_NEEDS_OBJECT );
-
pNode->SetType( SbxOBJECT );
- OpenBlock( NIL, aVar.GetExprNode() );
+ std::optional<WithLocalVar> oLocalVar;
+ if (pDef->GetProcDef())
+ oLocalVar.emplace(*this, aVar);
+
+ OpenBlock(NIL, oLocalVar ? oLocalVar->m_aWithParent.GetExprNode() : aVar.GetExprNode());
StmntBlock( ENDWITH );
CloseBlock();
}
-// LOOP/NEXT/WEND without construct
-
-void SbiParser::BadBlock()
-{
- if( eEndTok )
- Error( ERRCODE_BASIC_BAD_BLOCK, eEndTok );
- else
- Error( ERRCODE_BASIC_BAD_BLOCK, "Loop/Next/Wend" );
-}
-
// On expr Goto/Gosub n,n,n...
void SbiParser::OnGoto()
@@ -307,7 +373,7 @@ void SbiParser::OnGoto()
SbiToken eTok = Next();
if( eTok != GOTO && eTok != GOSUB )
{
- Error( ERRCODE_BASIC_EXPECTED, "GoTo/GoSub" );
+ Error( ERRCODE_BASIC_EXPECTED, u"GoTo/GoSub"_ustr );
eTok = GOTO;
}
@@ -528,7 +594,7 @@ void SbiParser::On()
TestToken( NEXT );
aGen.Gen( SbiOpcode::NOERROR_ );
}
- else Error( ERRCODE_BASIC_EXPECTED, "GoTo/Resume" );
+ else Error( ERRCODE_BASIC_EXPECTED, u"GoTo/Resume"_ustr );
}
}
diff --git a/basic/source/comp/parser.cxx b/basic/source/comp/parser.cxx
index 777db4071615..485a3f1cf4fd 100644
--- a/basic/source/comp/parser.cxx
+++ b/basic/source/comp/parser.cxx
@@ -85,10 +85,8 @@ const SbiStatement StmntTable [] = {
{ LET, &SbiParser::Assign, N, Y, }, // LET
{ LINE, &SbiParser::Line, N, Y, }, // LINE, -> LINE INPUT (#i92642)
{ LINEINPUT,&SbiParser::LineInput, N, Y, }, // LINE INPUT
-{ LOOP, &SbiParser::BadBlock, N, Y, }, // LOOP
{ LSET, &SbiParser::LSet, N, Y, }, // LSET
{ NAME, &SbiParser::Name, N, Y, }, // NAME
-{ NEXT, &SbiParser::BadBlock, N, Y, }, // NEXT
{ ON, &SbiParser::On, N, Y, }, // ON
{ OPEN, &SbiParser::Open, N, Y, }, // OPEN
{ OPTION, &SbiParser::Option, Y, N, }, // OPTION
@@ -106,13 +104,9 @@ const SbiStatement StmntTable [] = {
{ STOP, &SbiParser::Stop, N, Y, }, // STOP
{ SUB, &SbiParser::SubFunc, Y, N, }, // SUB
{ TYPE, &SbiParser::Type, Y, N, }, // TYPE
-{ UNTIL, &SbiParser::BadBlock, N, Y, }, // UNTIL
{ WHILE, &SbiParser::While, N, Y, }, // WHILE
-{ WEND, &SbiParser::BadBlock, N, Y, }, // WEND
{ WITH, &SbiParser::With, N, Y, }, // WITH
{ WRITE, &SbiParser::Write, N, Y, }, // WRITE
-
-{ NIL, nullptr, N, N }
};
SbiParser::SbiParser( StarBASIC* pb, SbModule* pm )
@@ -145,7 +139,7 @@ SbiParser::SbiParser( StarBASIC* pb, SbModule* pm )
rTypeArray = new SbxArray; // array for user defined types
rEnumArray = new SbxArray; // array for Enum types
- bVBASupportOn = pm->IsVBACompat();
+ bVBASupportOn = pm->IsVBASupport();
if ( bVBASupportOn )
EnableCompatibility();
@@ -196,7 +190,7 @@ bool SbiParser::HasGlobalCode()
void SbiParser::OpenBlock( SbiToken eTok, SbiExprNode* pVar )
{
SbiParseStack* p = new SbiParseStack;
- p->eExitTok = eTok;
+ p->eExitTok = (eTok == GET || eTok == LET || eTok == SET) ? PROPERTY : eTok; // #i109051
p->nChain = 0;
p->pWithVar = pWithVar;
p->pNext = pStack;
@@ -232,9 +226,7 @@ void SbiParser::Exit()
SbiToken eTok = Next();
for( SbiParseStack* p = pStack; p; p = p->pNext )
{
- SbiToken eExitTok = p->eExitTok;
- if( eTok == eExitTok ||
- (eTok == PROPERTY && (eExitTok == GET || eExitTok == LET) ) ) // #i109051
+ if (eTok == p->eExitTok)
{
p->nChain = aGen.Gen( SbiOpcode::JUMP_, p->nChain );
return;
@@ -364,8 +356,9 @@ bool SbiParser::Parse()
// end of parsing?
if( eCurTok == eEndTok ||
( bVBASupportOn && // #i109075
- (eCurTok == ENDFUNC || eCurTok == ENDPROPERTY || eCurTok == ENDSUB) &&
- (eEndTok == ENDFUNC || eEndTok == ENDPROPERTY || eEndTok == ENDSUB) ) )
+ eEndTok == ENDPROPERTY &&
+ (pProc && pProc->getPropertyMode() == PropertyMode::Get) &&
+ ( eCurTok == ENDFUNC || eCurTok == ENDSUB) ) )
{
Next();
if( eCurTok != NIL )
@@ -413,11 +406,9 @@ bool SbiParser::Parse()
// statement parsers
- const SbiStatement* p;
- for( p = StmntTable; p->eTok != NIL; p++ )
- if( p->eTok == eCurTok )
- break;
- if( p->eTok != NIL )
+ const auto p = std::find_if(std::begin(StmntTable), std::end(StmntTable),
+ [this](auto element) { return element.eTok == eCurTok; });
+ if (p != std::end(StmntTable))
{
if( !pProc && !p->bMain )
Error( ERRCODE_BASIC_NOT_IN_MAIN, eCurTok );
@@ -495,7 +486,7 @@ void SbiParser::Symbol( const KeywordSymbolInfo* pKeywordSymbolInfo )
bool bEQ = ( Peek() == EQ );
if( !bEQ && bVBASupportOn && aVar.IsBracket() )
- Error( ERRCODE_BASIC_EXPECTED, "=" );
+ Error( ERRCODE_BASIC_EXPECTED, u"="_ustr );
RecursiveMode eRecMode = ( bEQ ? PREVENT_CALL : FORCE_CALL );
bool bSpecialMidHandling = false;
@@ -553,6 +544,10 @@ void SbiParser::Symbol( const KeywordSymbolInfo* pKeywordSymbolInfo )
return;
}
}
+ else if (auto nLen = pDef->GetLen()) // Dim s As String * 123 ' 123 -> nLen
+ {
+ aGen.Gen(SbiOpcode::PAD_, nLen);
+ }
}
aGen.Gen( eOp );
}
@@ -566,15 +561,15 @@ void SbiParser::Assign()
SbiExpression aExpr( this );
aLvalue.Gen();
aExpr.Gen();
- sal_uInt16 nLen = 0;
- SbiSymDef* pDef = aLvalue.GetRealVar();
+ if (SbiSymDef* pDef = aLvalue.GetRealVar())
{
if( pDef->GetConstDef() )
Error( ERRCODE_BASIC_DUPLICATE_DEF, pDef->GetName() );
- nLen = aLvalue.GetRealVar()->GetLen();
+ if (auto nLen = pDef->GetLen()) // Dim s As String * 123 ' 123 -> nLen
+ {
+ aGen.Gen( SbiOpcode::PAD_, nLen );
+ }
}
- if( nLen )
- aGen.Gen( SbiOpcode::PAD_, nLen );
aGen.Gen( SbiOpcode::PUT_ );
}
@@ -595,11 +590,11 @@ void SbiParser::Set()
if( eTok == NEW )
{
Next();
- auto pTypeDef = std::make_unique<SbiSymDef>( OUString() );
- TypeDecl( *pTypeDef, true );
+ SbiSymDef aTypeDef( u""_ustr );
+ TypeDecl( aTypeDef, true );
aLvalue.Gen();
- aGen.Gen( SbiOpcode::CREATE_, pDef->GetId(), pTypeDef->GetTypeId() );
+ aGen.Gen( SbiOpcode::CREATE_, pDef->GetId(), aTypeDef.GetTypeId() );
aGen.Gen( SbiOpcode::SETCLASS_, pDef->GetTypeId() );
}
else
@@ -772,14 +767,14 @@ void SbiParser::Option()
nBase = static_cast<short>(nVal);
break;
}
- Error( ERRCODE_BASIC_EXPECTED, "0/1" );
+ Error( ERRCODE_BASIC_EXPECTED, u"0/1"_ustr );
break;
case PRIVATE:
{
OUString aString = SbiTokenizer::Symbol(Next());
if( !aString.equalsIgnoreAsciiCase("Module") )
{
- Error( ERRCODE_BASIC_EXPECTED, "Module" );
+ Error( ERRCODE_BASIC_EXPECTED, u"Module"_ustr );
}
break;
}
@@ -794,7 +789,7 @@ void SbiParser::Option()
}
else
{
- Error( ERRCODE_BASIC_EXPECTED, "Text/Binary" );
+ Error( ERRCODE_BASIC_EXPECTED, u"Text/Binary"_ustr );
}
break;
}
@@ -818,14 +813,14 @@ void SbiParser::Option()
}
// if the module setting is different
// reset it to what the Option tells us
- if ( bVBASupportOn != aGen.GetModule().IsVBACompat() )
+ if ( bVBASupportOn != aGen.GetModule().IsVBASupport() )
{
- aGen.GetModule().SetVBACompat( bVBASupportOn );
+ aGen.GetModule().SetVBASupport( bVBASupportOn );
}
break;
}
}
- Error( ERRCODE_BASIC_EXPECTED, "0/1" );
+ Error( ERRCODE_BASIC_EXPECTED, u"0/1"_ustr );
break;
default:
Error( ERRCODE_BASIC_BAD_OPTION, eCurTok );
@@ -849,32 +844,41 @@ static void addNumericConst(SbiSymPool& rPool, const OUString& pSym, double nVal
void SbiParser::AddConstants()
{
+ // tdf#153543 - shell constants
+ // See https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/shell-constants
+ addNumericConst(aPublics, u"vbHide"_ustr, 0);
+ addNumericConst(aPublics, u"vbNormalFocus"_ustr, 1);
+ addNumericConst(aPublics, u"vbMinimizedFocus"_ustr, 2);
+ addNumericConst(aPublics, u"vbMaximizedFocus"_ustr, 3);
+ addNumericConst(aPublics, u"vbNormalNoFocus"_ustr, 4);
+ addNumericConst(aPublics, u"vbMinimizedNoFocus"_ustr, 6);
+
// tdf#131563 - add vba color constants
// See https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/color-constants
- addNumericConst(aPublics, "vbBlack", 0x0);
- addNumericConst(aPublics, "vbRed", 0xFF);
- addNumericConst(aPublics, "vbGreen", 0xFF00);
- addNumericConst(aPublics, "vbYellow", 0xFFFF);
- addNumericConst(aPublics, "vbBlue", 0xFF0000);
- addNumericConst(aPublics, "vbMagenta", 0xFF00FF);
- addNumericConst(aPublics, "vbCyan", 0xFFFF00);
- addNumericConst(aPublics, "vbWhite", 0xFFFFFF);
+ addNumericConst(aPublics, u"vbBlack"_ustr, 0x0);
+ addNumericConst(aPublics, u"vbRed"_ustr, 0xFF);
+ addNumericConst(aPublics, u"vbGreen"_ustr, 0xFF00);
+ addNumericConst(aPublics, u"vbYellow"_ustr, 0xFFFF);
+ addNumericConst(aPublics, u"vbBlue"_ustr, 0xFF0000);
+ addNumericConst(aPublics, u"vbMagenta"_ustr, 0xFF00FF);
+ addNumericConst(aPublics, u"vbCyan"_ustr, 0xFFFF00);
+ addNumericConst(aPublics, u"vbWhite"_ustr, 0xFFFFFF);
// #113063 Create constant RTL symbols
- addStringConst( aPublics, "vbCr", "\x0D" );
- addStringConst( aPublics, "vbCrLf", "\x0D\x0A" );
- addStringConst( aPublics, "vbFormFeed", "\x0C" );
- addStringConst( aPublics, "vbLf", "\x0A" );
+ addStringConst( aPublics, u"vbCr"_ustr, u"\x0D"_ustr );
+ addStringConst( aPublics, u"vbCrLf"_ustr, u"\x0D\x0A"_ustr );
+ addStringConst( aPublics, u"vbFormFeed"_ustr, u"\x0C"_ustr );
+ addStringConst( aPublics, u"vbLf"_ustr, u"\x0A"_ustr );
#ifdef _WIN32
addStringConst( aPublics, "vbNewLine", "\x0D\x0A" );
#else
- addStringConst( aPublics, "vbNewLine", "\x0A" );
+ addStringConst( aPublics, u"vbNewLine"_ustr, u"\x0A"_ustr );
#endif
- addStringConst( aPublics, "vbNullString", "" );
- addStringConst( aPublics, "vbTab", "\x09" );
- addStringConst( aPublics, "vbVerticalTab", "\x0B" );
+ addStringConst( aPublics, u"vbNullString"_ustr, u""_ustr );
+ addStringConst( aPublics, u"vbTab"_ustr, u"\x09"_ustr );
+ addStringConst( aPublics, u"vbVerticalTab"_ustr, u"\x0B"_ustr );
- addStringConst( aPublics, "vbNullChar", OUString(u'\0') );
+ addStringConst( aPublics, u"vbNullChar"_ustr, OUString(u'\0') );
}
// ERROR n
diff --git a/basic/source/comp/scanner.cxx b/basic/source/comp/scanner.cxx
index a0d9b9ab6c76..a95ee3a994a4 100644
--- a/basic/source/comp/scanner.cxx
+++ b/basic/source/comp/scanner.cxx
@@ -27,9 +27,11 @@
#include <svl/numformat.hxx>
#include <svl/zforlist.hxx>
#include <rtl/character.hxx>
+#include <o3tl/string_view.hxx>
+#include <utility>
-SbiScanner::SbiScanner(const OUString& rBuf, StarBASIC* p)
- : aBuf(rBuf)
+SbiScanner::SbiScanner(OUString _aBuf, StarBASIC* p)
+ : aBuf(std::move(_aBuf))
, nLineIdx(-1)
, nSaveLineIdx(-1)
, pBasic(p)
@@ -53,6 +55,7 @@ SbiScanner::SbiScanner(const OUString& rBuf, StarBASIC* p)
, bVBASupportOn(false)
, bPrevLineExtentsComment(false)
, bClosingUnderscore(false)
+ , bLineEndsWithWhitespace(false)
, bInStatement(false)
{
}
@@ -160,8 +163,8 @@ void SbiScanner::scanGoto()
if(n + 1 < aLine.getLength())
{
- OUString aTemp = aLine.copy(n, 2);
- if(aTemp.equalsIgnoreAsciiCase("to"))
+ std::u16string_view aTemp = aLine.subView(n, 2);
+ if(o3tl::equalsIgnoreAsciiCase(aTemp, u"to"))
{
aSym = "goto";
nLineIdx += n + 2 - nCol;
@@ -186,6 +189,8 @@ bool SbiScanner::readLine()
while(nBufPos < nEnd && BasicCharClass::isWhitespace(aBuf[nEnd - 1]))
--nEnd;
+ // tdf#149402 - check if line ends with a whitespace
+ bLineEndsWithWhitespace = (n > nEnd);
aLine = aBuf.copy(nBufPos, nEnd - nBufPos);
// Fast-forward past the line ending
@@ -204,6 +209,17 @@ bool SbiScanner::readLine()
return true;
}
+// Function to check if a string is a valid compiler directive
+static bool isValidCompilerDirective(std::u16string_view directive)
+{
+ static constexpr std::string_view validDirectives[]
+ = { "if", "elseif", "else", "end", "const" };
+
+ return std::any_of(std::begin(validDirectives), std::end(validDirectives),
+ [&directive](const auto& valid)
+ { return o3tl::matchIgnoreAsciiCase(directive, valid); });
+}
+
bool SbiScanner::NextSym()
{
// memorize for the EOLN-case
@@ -215,7 +231,6 @@ bool SbiScanner::NextSym()
eScanType = SbxVARIANT;
aSym.clear();
bHash = bSymbol = bNumber = bSpaces = false;
- bool bCompilerDirective = false;
// read in line?
if (nLineIdx == -1)
@@ -251,6 +266,8 @@ bool SbiScanner::NextSym()
if(nCol < aLine.getLength() && aLine[nCol] == '#')
{
sal_Int32 nLineTempIdx = nLineIdx;
+ std::u16string_view candidate(aLine.subView(nCol + 1));
+
do
{
nLineTempIdx++;
@@ -261,9 +278,20 @@ bool SbiScanner::NextSym()
{
++nLineIdx;
++nCol;
- //ignore compiler directives (# is first non-space character)
+ //handle compiler directives (# is first non-space character)
if (nOldCol2 == 0)
- bCompilerDirective = true;
+ {
+ if (isValidCompilerDirective(candidate))
+ {
+ // Skip the whole line if starts with a hash and is a valid compiler directive
+ nCol = 0;
+ goto eoln;
+ }
+ else
+ {
+ GenError(ERRCODE_BASIC_SYNTAX);
+ }
+ }
else
bHash = true;
}
@@ -655,15 +683,16 @@ bool SbiScanner::NextSym()
PrevLineCommentLbl:
- if( bPrevLineExtentsComment || (eScanType != SbxSTRING &&
- ( bCompilerDirective ||
- aSym.startsWith("'") ||
- aSym.equalsIgnoreAsciiCase( "REM" ) ) ) )
+ if (bPrevLineExtentsComment ||
+ (eScanType != SbxSTRING &&
+ (aSym.startsWith("'") || aSym.equalsIgnoreAsciiCase("REM") || aSym.startsWith("#"))))
{
bPrevLineExtentsComment = false;
aSym = "REM";
sal_Int32 nLen = aLine.getLength() - nLineIdx;
- if( bCompatible && aLine[nLineIdx + nLen - 1] == '_' && aLine[nLineIdx + nLen - 2] == ' ' )
+ // tdf#149402 - don't extend comment if line ends in a whitespace (BasicCharClass::isWhitespace)
+ if (bCompatible && !bLineEndsWithWhitespace && aLine[nLineIdx + nLen - 1] == '_'
+ && aLine[nLineIdx + nLen - 2] == ' ')
bPrevLineExtentsComment = true;
nCol2 = nCol2 + nLen;
nLineIdx = -1;
@@ -701,6 +730,8 @@ eoln:
aSym = "\n";
nColLock = 0;
bClosingUnderscore = false;
+ // tdf#149157 - break multiline continuation in a comment after a new line
+ bPrevLineExtentsComment = false;
return true;
}
}
diff --git a/basic/source/comp/symtbl.cxx b/basic/source/comp/symtbl.cxx
index 9d4376b683fe..6f8b53ed0d5a 100644
--- a/basic/source/comp/symtbl.cxx
+++ b/basic/source/comp/symtbl.cxx
@@ -26,6 +26,7 @@
#include <stdio.h>
#include <rtl/character.hxx>
#include <basic/sberrors.hxx>
+#include <utility>
// All symbol names are laid down int the symbol-pool's stringpool, so that
// all symbols are handled in the same case. On saving the code-image, the
@@ -39,10 +40,10 @@ SbiStringPool::SbiStringPool( )
SbiStringPool::~SbiStringPool()
{}
-OUString SbiStringPool::Find( sal_uInt32 n ) const
+const OUString & SbiStringPool::Find( sal_uInt32 n ) const
{
if( n == 0 || n > aData.size() )
- return OUString();
+ return EMPTY_OUSTRING;
else
return aData[n - 1];
}
@@ -169,7 +170,7 @@ void SbiSymPool::Add( SbiSymDef* pDef )
{
#ifdef DBG_UTIL
- pParser->Error( ERRCODE_BASIC_INTERNAL_ERROR, "Dbl Pool" );
+ pParser->Error( ERRCODE_BASIC_INTERNAL_ERROR, u"Dbl Pool"_ustr );
#endif
return;
}
@@ -276,8 +277,8 @@ void SbiSymPool::CheckRefs()
}
}
-SbiSymDef::SbiSymDef( const OUString& rName ) :
- aName(rName),
+SbiSymDef::SbiSymDef( OUString _aName ) :
+ aName(std::move(_aName)),
eType(SbxEMPTY),
pIn(nullptr),
nLen(0),
@@ -493,7 +494,7 @@ void SbiProcDef::setPropertyMode( PropertyMode ePropMode )
// CompleteProcName includes "Property xxx "
// to avoid conflicts with other symbols
- OUString aCompleteProcName = "Property ";
+ OUString aCompleteProcName = u"Property "_ustr;
switch( mePropMode )
{
case PropertyMode::Get: aCompleteProcName += "Get "; break;
diff --git a/basic/source/comp/token.cxx b/basic/source/comp/token.cxx
index 9be47bf41ba1..864402c73aa7 100644
--- a/basic/source/comp/token.cxx
+++ b/basic/source/comp/token.cxx
@@ -22,6 +22,7 @@
#include <basic/sberrors.hxx>
#include <sal/macros.h>
+#include <o3tl/string_view.hxx>
#include <basiccharclass.hxx>
#include <token.hxx>
@@ -226,7 +227,7 @@ SbiTokenizer::SbiTokenizer( const OUString& rSrc, StarBASIC* pb )
void SbiTokenizer::Push( SbiToken t )
{
if( ePush != NIL )
- Error( ERRCODE_BASIC_INTERNAL_ERROR, "PUSH" );
+ Error( ERRCODE_BASIC_INTERNAL_ERROR, u"PUSH"_ustr );
else ePush = t;
}
@@ -273,13 +274,13 @@ const OUString& SbiTokenizer::Symbol( SbiToken t )
switch( t )
{
case NEG :
- aSym = "-";
+ aSym = u"-"_ustr;
return aSym;
case EOS :
- aSym = ":/CRLF";
+ aSym = u":/CRLF"_ustr;
return aSym;
case EOLN :
- aSym = "CRLF";
+ aSym = u"CRLF"_ustr;
return aSym;
default:
break;
@@ -295,7 +296,7 @@ const OUString& SbiTokenizer::Symbol( SbiToken t )
const sal_Unicode *p = aSym.getStr();
if (*p <= ' ')
{
- aSym = "???";
+ aSym = u"???"_ustr;
}
return aSym;
}
@@ -377,7 +378,7 @@ SbiToken SbiTokenizer::Next()
}
// valid token?
short lb = 0;
- short ub = SAL_N_ELEMENTS(aTokTable_Basic)-1;
+ short ub = std::size(aTokTable_Basic)-1;
short delta;
do
{
@@ -558,11 +559,11 @@ bool SbiTokenizer::MayBeLabel( bool bNeedsColon )
}
-OUString SbiTokenizer::GetKeywordCase( const OUString& sKeyword )
+OUString SbiTokenizer::GetKeywordCase( std::u16string_view sKeyword )
{
for( auto& rTok : aTokTable_Basic )
{
- if( sKeyword.equalsIgnoreAsciiCaseAscii(rTok.s) )
+ if( o3tl::equalsIgnoreAsciiCase(sKeyword, rTok.s) )
return OStringToOUString(rTok.s, RTL_TEXTENCODING_ASCII_US);
}
return OUString();
diff --git a/basic/source/inc/buffer.hxx b/basic/source/inc/buffer.hxx
index 3115a01a6c98..5c555d74c089 100644
--- a/basic/source/inc/buffer.hxx
+++ b/basic/source/inc/buffer.hxx
@@ -19,9 +19,9 @@
#pragma once
-#include <basic/sberrors.hxx>
#include <rtl/ustring.hxx>
#include <sal/types.h>
+#include <comphelper/errcode.hxx>
#include <vector>
// Stores all numbers big endian
diff --git a/basic/source/inc/date.hxx b/basic/source/inc/date.hxx
index 4b6cb115fbbf..5db9df621b9e 100644
--- a/basic/source/inc/date.hxx
+++ b/basic/source/inc/date.hxx
@@ -33,10 +33,11 @@ enum class SbDateCorrection
};
bool implDateSerial( sal_Int16 nYear, sal_Int16 nMonth, sal_Int16 nDay, bool bUseTwoDigitYear, SbDateCorrection eCorr, double& rdRet );
-double implTimeSerial( sal_Int16 nHour, sal_Int16 nMinute, sal_Int16 nSecond);
-bool implDateTimeSerial( sal_Int16 nYear, sal_Int16 nMonth, sal_Int16 nDay,
- sal_Int16 nHour, sal_Int16 nMinute, sal_Int16 nSecond,
- double& rdRet );
+double implTimeSerial(sal_Int16 nHour, sal_Int16 nMinute, sal_Int16 nSecond,
+ sal_Int32 nMilliSecond);
+bool implDateTimeSerial(sal_Int16 nYear, sal_Int16 nMonth, sal_Int16 nDay, sal_Int16 nHour,
+ sal_Int16 nMinute, sal_Int16 nSecond, sal_Int32 nMilliSecond,
+ double& rdRet);
sal_Int16 implGetWeekDay( double aDate, bool bFirstDayParam = false, sal_Int16 nFirstDay = 0 );
@@ -47,6 +48,7 @@ sal_Int16 implGetDateDay( double aDate );
sal_Int16 implGetHour( double dDate );
sal_Int16 implGetMinute( double dDate );
sal_Int16 implGetSecond( double dDate );
+sal_Int32 implGetNanoSecond(double dDate);
css::util::Date SbxDateToUNODate( const SbxValue* );
void SbxDateFromUNODate( SbxValue*, const css::util::Date& );
diff --git a/basic/source/inc/dlgcont.hxx b/basic/source/inc/dlgcont.hxx
index 58d1dbeb65f4..81d14d72bec2 100644
--- a/basic/source/inc/dlgcont.hxx
+++ b/basic/source/inc/dlgcont.hxx
@@ -60,10 +60,10 @@ class SfxDialogLibraryContainer final : public SfxLibraryContainer
virtual void onNewRootStorage() override;
- virtual const char* getInfoFileName() const override;
- virtual const char* getOldInfoFileName() const override;
- virtual const char* getLibElementFileExtension() const override;
- virtual const char* getLibrariesDir() const override;
+ virtual OUString getInfoFileName() const override;
+ virtual OUString getOldInfoFileName() const override;
+ virtual OUString getLibElementFileExtension() const override;
+ virtual OUString getLibrariesDir() const override;
public:
SfxDialogLibraryContainer();
@@ -85,11 +85,10 @@ public:
};
-typedef ::cppu::ImplHelper1 < css::resource::XStringResourceSupplier
+typedef cppu::ImplInheritanceHelper<SfxLibrary, css::resource::XStringResourceSupplier
> SfxDialogLibrary_BASE;
-class SfxDialogLibrary final : public SfxLibrary
- ,public SfxDialogLibrary_BASE
+class SfxDialogLibrary final : public SfxDialogLibrary_BASE
{
SfxDialogLibraryContainer* m_pParent;
css::uno::Reference< css::resource::XStringResourcePersistence> m_xStringResourcePersistence;
@@ -108,7 +107,7 @@ public:
SfxDialogLibrary
(
ModifiableHelper& _rModifiable,
- const OUString& aName,
+ OUString aName,
const css::uno::Reference< css::ucb::XSimpleFileAccess3 >& xSFI,
SfxDialogLibraryContainer* pParent
);
@@ -116,15 +115,12 @@ public:
SfxDialogLibrary
(
ModifiableHelper& _rModifiable,
- const OUString& aName,
+ OUString aName,
const css::uno::Reference< css::ucb::XSimpleFileAccess3 >& xSFI,
const OUString& aLibInfoFileURL, const OUString& aStorageURL, bool ReadOnly,
SfxDialogLibraryContainer* pParent
);
- DECLARE_XINTERFACE()
- DECLARE_XTYPEPROVIDER()
-
// XStringResourceSupplier
virtual css::uno::Reference< css::resource::XStringResourceResolver >
SAL_CALL getStringResource( ) override;
diff --git a/basic/source/inc/expr.hxx b/basic/source/inc/expr.hxx
index 93f344e89fac..2a74e2b2e672 100644
--- a/basic/source/inc/expr.hxx
+++ b/basic/source/inc/expr.hxx
@@ -31,7 +31,6 @@ class SbiExprList;
class SbiParser;
class SbiCodeGen;
class SbiSymDef;
-class SbiProcDef;
typedef std::unique_ptr<SbiExprList> SbiExprListPtr;
@@ -85,6 +84,25 @@ enum RecursiveMode
PREVENT_CALL
};
+class SbiExprList final { // class for parameters and dims
+ std::vector<std::unique_ptr<SbiExpression>> aData;
+ short nDim;
+ bool bError;
+ bool bBracket;
+public:
+ SbiExprList();
+ ~SbiExprList();
+ static SbiExprListPtr ParseParameters(SbiParser*, bool bStandaloneExpression = false, bool bPar = true);
+ static SbiExprListPtr ParseDimList( SbiParser* );
+ bool IsBracket() const { return bBracket; }
+ bool IsValid() const { return !bError; }
+ short GetSize() const { return aData.size(); }
+ short GetDims() const { return nDim; }
+ SbiExpression* Get( size_t );
+ void Gen( SbiCodeGen& rGen); // code generation
+ void addExpression( std::unique_ptr<SbiExpression>&& pExpr );
+};
+
class SbiExprNode final { // operators (and operands)
friend class SbiExpression;
friend class SbiConstExpression;
@@ -114,7 +132,7 @@ class SbiExprNode final { // operators (and operands)
public:
SbiExprNode();
SbiExprNode( double, SbxDataType );
- SbiExprNode( const OUString& );
+ SbiExprNode( OUString );
SbiExprNode( const SbiSymDef&, SbxDataType, SbiExprListPtr = nullptr );
SbiExprNode( std::unique_ptr<SbiExprNode>, SbiToken, std::unique_ptr<SbiExprNode> );
SbiExprNode( std::unique_ptr<SbiExprNode>, sal_uInt16 ); // #120061 TypeOf
@@ -205,23 +223,4 @@ public: // numeric constant
short GetShortValue();
};
-class SbiExprList final { // class for parameters and dims
- std::vector<std::unique_ptr<SbiExpression>> aData;
- short nDim;
- bool bError;
- bool bBracket;
-public:
- SbiExprList();
- ~SbiExprList();
- static SbiExprListPtr ParseParameters(SbiParser*, bool bStandaloneExpression = false, bool bPar = true);
- static SbiExprListPtr ParseDimList( SbiParser* );
- bool IsBracket() const { return bBracket; }
- bool IsValid() const { return !bError; }
- short GetSize() const { return aData.size(); }
- short GetDims() const { return nDim; }
- SbiExpression* Get( size_t );
- void Gen( SbiCodeGen& rGen); // code generation
- void addExpression( std::unique_ptr<SbiExpression>&& pExpr );
-};
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/inc/filefmt.hxx b/basic/source/inc/filefmt.hxx
index 25ba647ad743..38dfa95754f3 100644
--- a/basic/source/inc/filefmt.hxx
+++ b/basic/source/inc/filefmt.hxx
@@ -45,9 +45,8 @@
// new integer type suffix 'b')
//
-#define B_LEGACYVERSION 0x00000011
-#define B_EXT_IMG_VERSION 0x00000012
-#define B_CURVERSION 0x00000013
+#define B_IMG_VERSION_12 0x00000012
+#define B_IMG_VERSION_13 0x00000013
// The file contains either a module- or a library-record.
// Those records contain further records. Every record's got
diff --git a/basic/source/inc/image.hxx b/basic/source/inc/image.hxx
index b33009c1e029..5a4522bd91bf 100644
--- a/basic/source/inc/image.hxx
+++ b/basic/source/inc/image.hxx
@@ -23,6 +23,7 @@
#include <rtl/ustring.hxx>
#include "filefmt.hxx"
#include <o3tl/typed_flags_set.hxx>
+#include <cstddef>
#include <vector>
// This class reads in the image that's been produced by the compiler
@@ -56,7 +57,7 @@ class SbiImage {
sal_uInt16 nDimBase; // OPTION BASE value
rtl_TextEncoding eCharSet;
// temporary management-variable:
- short nStringIdx;
+ std::size_t nStringIdx;
sal_uInt32 nStringOff; // current Pos in the stringbuffer
// routines for the compiler:
void MakeStrings( short ); // establish StringPool
@@ -78,13 +79,13 @@ public:
bool Load( SvStream&, sal_uInt32& nVer );
// nVer is set to version
// of image
- bool Save( SvStream&, sal_uInt32 = B_CURVERSION );
+ bool Save( SvStream&, sal_uInt32 );
bool IsError() const { return bError; }
const sal_uInt8* GetCode() const { return aCode.data(); }
sal_uInt32 GetCodeSize() const { return aCode.size(); }
sal_uInt16 GetBase() const { return nDimBase; }
- OUString GetString( short nId, SbxDataType *eType = nullptr ) const;
+ OUString GetString( sal_uInt32 nId, SbxDataType *eType = nullptr ) const;
const SbxObject* FindType (const OUString& aTypeName) const;
const SbxArrayRef& GetEnums() const { return rEnums; }
@@ -95,6 +96,7 @@ public:
sal_uInt32 CalcNewOffset( sal_Int16 nOffset );
void ReleaseLegacyBuffer();
bool ExceedsLegacyLimits();
+ bool ExceedsImgVersion12Limits();
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/inc/iosys.hxx b/basic/source/inc/iosys.hxx
index ca5c6b275bcc..b562b13c2154 100644
--- a/basic/source/inc/iosys.hxx
+++ b/basic/source/inc/iosys.hxx
@@ -60,7 +60,7 @@ class SbiStream
public:
SbiStream();
~SbiStream();
- ErrCode const & Open( std::string_view, StreamMode, SbiStreamFlags, short );
+ ErrCode const & Open( const OUString&, StreamMode, SbiStreamFlags, short );
ErrCode const & Close();
ErrCode Read(OString&, sal_uInt16 = 0, bool bForceReadingPerByte=false);
ErrCode const & Read( char& );
@@ -82,7 +82,7 @@ public:
class SbiIoSystem
{
SbiStream* pChan[ CHANNELS ];
- OString aPrompt;
+ OUString aPrompt;
OString aIn;
OUString aOut;
short nChan;
@@ -94,11 +94,11 @@ public:
~SbiIoSystem() COVERITY_NOEXCEPT_FALSE;
ErrCode GetError();
void Shutdown();
- void SetPrompt(const OString& r) { aPrompt = r; }
+ void SetPrompt(const OUString& r) { aPrompt = r; }
void SetChannel( short n ) { nChan = n; }
short GetChannel() const { return nChan;}
void ResetChannel() { nChan = 0; }
- void Open( short, std::string_view, StreamMode, SbiStreamFlags, short );
+ void Open( short, const OUString&, StreamMode, SbiStreamFlags, short );
void Close();
void Read(OString&);
char Read();
diff --git a/basic/source/inc/namecont.hxx b/basic/source/inc/namecont.hxx
index 6a3b020d00a4..45246c8447f3 100644
--- a/basic/source/inc/namecont.hxx
+++ b/basic/source/inc/namecont.hxx
@@ -37,146 +37,124 @@
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/deployment/XPackage.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/script/vba/XVBACompatibility.hpp>
#include <com/sun/star/script/vba/XVBAScriptListener.hpp>
#include <com/sun/star/util/XChangesNotifier.hpp>
#include <osl/mutex.hxx>
#include <unotools/eventlisteneradapter.hxx>
+#include <comphelper/compbase.hxx>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/compbase.hxx>
#include <cppuhelper/weakref.hxx>
-#include <cppuhelper/component.hxx>
#include <cppuhelper/basemutex.hxx>
#include <rtl/ref.hxx>
#include <comphelper/interfacecontainer3.hxx>
-#include <comphelper/listenernotification.hxx>
+#include <comphelper/interfacecontainer4.hxx>
#include <xmlscript/xmllib_imexp.hxx>
-#include <comphelper/interfacecontainer3.hxx>
class BasicManager;
namespace basic
{
-typedef ::cppu::WeakImplHelper<
- css::container::XNameContainer,
- css::container::XContainer,
- css::util::XChangesNotifier > NameContainer_BASE;
-
-
-class NameContainer final : public ::cppu::BaseMutex, public NameContainer_BASE
+class NameContainer final
{
- typedef std::unordered_map < OUString, sal_Int32 > NameContainerNameMap;
+ cppu::OWeakObject& rOwner;
- NameContainerNameMap mHashMap;
- std::vector< OUString > mNames;
- std::vector< css::uno::Any > mValues;
- sal_Int32 mnElementCount;
+ std::unordered_map<OUString, css::uno::Any> maMap;
css::uno::Type mType;
css::uno::XInterface* mpxEventSource;
- ::comphelper::OInterfaceContainerHelper3<css::container::XContainerListener> maContainerListeners;
- ::comphelper::OInterfaceContainerHelper3<css::util::XChangesListener> maChangesListeners;
+ ::comphelper::OInterfaceContainerHelper4<css::container::XContainerListener> maContainerListeners;
+ ::comphelper::OInterfaceContainerHelper4<css::util::XChangesListener> maChangesListeners;
public:
- NameContainer( const css::uno::Type& rType )
- : mnElementCount( 0 )
+ NameContainer(const css::uno::Type& rType, cppu::OWeakObject& owner)
+ : rOwner(owner)
, mType( rType )
, mpxEventSource( nullptr )
- , maContainerListeners( m_aMutex )
- , maChangesListeners( m_aMutex )
{}
void setEventSource( css::uno::XInterface* pxEventSource )
{ mpxEventSource = pxEventSource; }
/// @throws css::lang::IllegalArgumentException
- /// @throws css::container::ElementExistException
- /// @throws css::lang::WrappedTargetException
- /// @throws css::uno::RuntimeException
- void insertCheck(const OUString& aName, const css::uno::Any& aElement);
-
- /// @throws css::lang::IllegalArgumentException
/// @throws css::lang::WrappedTargetException
/// @throws css::uno::RuntimeException
- void insertNoCheck(const OUString& aName, const css::uno::Any& aElement);
+ void insertNoCheck(const OUString& aName, const css::uno::Any& aElement,
+ std::unique_lock<std::mutex>& guard);
// Methods XElementAccess
- virtual css::uno::Type SAL_CALL getElementType( ) override;
- virtual sal_Bool SAL_CALL hasElements( ) override;
+ css::uno::Type getElementType();
+ sal_Bool hasElements();
// Methods XNameAccess
- virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
- virtual css::uno::Sequence< OUString > SAL_CALL getElementNames( ) override;
- virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
+ css::uno::Any getByName(const OUString& aName);
+ css::uno::Sequence<OUString> getElementNames();
+ sal_Bool hasByName(const OUString& aName);
// Methods XNameReplace
- virtual void SAL_CALL replaceByName( const OUString& aName, const css::uno::Any& aElement ) override;
+ void replaceByName(const OUString& aName, const css::uno::Any& aElement,
+ std::unique_lock<std::mutex>& guard);
// Methods XNameContainer
- virtual void SAL_CALL insertByName( const OUString& aName, const css::uno::Any& aElement ) override;
- virtual void SAL_CALL removeByName( const OUString& Name ) override;
+ void insertByName(const OUString& aName, const css::uno::Any& aElement,
+ std::unique_lock<std::mutex>& guard);
+ void removeByName(const OUString& Name, std::unique_lock<std::mutex>& guard);
// Methods XContainer
- virtual void SAL_CALL addContainerListener( const css::uno::Reference<css::container::XContainerListener >& xListener ) override;
- virtual void SAL_CALL removeContainerListener( const css::uno::Reference<css::container::XContainerListener >& xListener ) override;
+ void addContainerListener(
+ const css::uno::Reference<css::container::XContainerListener>& xListener,
+ std::unique_lock<std::mutex>& guard);
+ void removeContainerListener(
+ const css::uno::Reference<css::container::XContainerListener>& xListener,
+ std::unique_lock<std::mutex>& guard);
// Methods XChangesNotifier
- virtual void SAL_CALL addChangesListener( const css::uno::Reference<css::util::XChangesListener >& xListener ) override;
- virtual void SAL_CALL removeChangesListener( const css::uno::Reference<css::util::XChangesListener >& xListener ) override;
+ void addChangesListener(const css::uno::Reference<css::util::XChangesListener>& xListener,
+ std::unique_lock<std::mutex>& guard);
+ void removeChangesListener(const css::uno::Reference<css::util::XChangesListener>& xListener,
+ std::unique_lock<std::mutex>& guard);
};
class ModifiableHelper
{
private:
- ::comphelper::OInterfaceContainerHelper3<css::util::XModifyListener> m_aModifyListeners;
+ comphelper::OInterfaceContainerHelper4<css::util::XModifyListener> m_aModifyListeners;
::cppu::OWeakObject& m_rEventSource;
bool mbModified;
public:
- ModifiableHelper( ::cppu::OWeakObject& _rEventSource, ::osl::Mutex& _rMutex )
- :m_aModifyListeners( _rMutex )
- ,m_rEventSource( _rEventSource )
+ ModifiableHelper( ::cppu::OWeakObject& _rEventSource )
+ :m_rEventSource( _rEventSource )
,mbModified( false )
{
}
bool isModified() const { return mbModified; }
- void setModified( bool _bModified );
+ void setModified( bool _bModified, std::unique_lock<std::mutex>& guard );
- void addModifyListener( const css::uno::Reference< css::util::XModifyListener >& _rxListener )
+ void addModifyListener( const css::uno::Reference< css::util::XModifyListener >& _rxListener, std::unique_lock<std::mutex>& guard )
{
- m_aModifyListeners.addInterface( _rxListener );
+ m_aModifyListeners.addInterface(guard, _rxListener);
}
- void removeModifyListener( const css::uno::Reference< css::util::XModifyListener >& _rxListener )
+ void removeModifyListener( const css::uno::Reference< css::util::XModifyListener >& _rxListener, std::unique_lock<std::mutex>& guard )
{
- m_aModifyListeners.removeInterface( _rxListener );
+ m_aModifyListeners.removeInterface(guard, _rxListener);
}
};
-typedef ::comphelper::OListenerContainerBase<
- css::script::vba::XVBAScriptListener,
- css::script::vba::VBAScriptEvent > VBAScriptListenerContainer_BASE;
-
-class VBAScriptListenerContainer final : public VBAScriptListenerContainer_BASE
-{
-public:
- explicit VBAScriptListenerContainer( ::osl::Mutex& rMutex );
-
-private:
- virtual bool implTypedNotify(
- const css::uno::Reference< css::script::vba::XVBAScriptListener >& rxListener,
- const css::script::vba::VBAScriptEvent& rEvent ) override;
-};
-
+typedef comphelper::OInterfaceContainerHelper4<
+ css::script::vba::XVBAScriptListener > VBAScriptListenerContainer;
class SfxLibrary;
-typedef ::cppu::WeakComponentImplHelper<
+typedef comphelper::WeakComponentImplHelper<
css::lang::XInitialization,
css::script::XStorageBasedLibraryContainer,
css::script::XLibraryContainerPassword,
@@ -185,16 +163,17 @@ typedef ::cppu::WeakComponentImplHelper<
css::container::XContainer,
css::script::XLibraryQueryExecutable,
css::script::vba::XVBACompatibility,
- css::lang::XServiceInfo > SfxLibraryContainer_BASE;
+ css::lang::XServiceInfo,
+ css::beans::XPropertySet> SfxLibraryContainer_BASE;
class SfxLibraryContainer
- : public ::cppu::BaseMutex
- , public SfxLibraryContainer_BASE
+ : public SfxLibraryContainer_BASE
, public ::utl::OEventListenerAdapter
{
VBAScriptListenerContainer maVBAScriptListeners;
sal_Int32 mnRunningVBAScripts;
bool mbVBACompat;
+ rtl_TextEncoding meVBATextEncoding;
OUString msProjectName;
protected:
css::uno::Reference< css::uno::XComponentContext > mxContext;
@@ -204,9 +183,7 @@ protected:
ModifiableHelper maModifiable;
- rtl::Reference<NameContainer> maNameContainer;
- bool mbOldInfoFormat;
- bool mbOasis2OOoFormat;
+ NameContainer maNameContainer;
OUString maInitialDocumentURL;
OUString maInfoFileName;
@@ -219,6 +196,9 @@ protected:
BasicManager* mpBasMgr;
bool mbOwnBasMgr;
+ bool mbOldInfoFormat;
+ bool mbOasis2OOoFormat;
+
enum InitMode
{
DEFAULT,
@@ -236,7 +216,7 @@ protected:
void implStoreLibrary( SfxLibrary* pLib,
std::u16string_view rName,
const css::uno::Reference< css::embed::XStorage >& rStorage,
- const OUString& rTargetURL,
+ std::u16string_view rTargetURL,
const css::uno::Reference< css::ucb::XSimpleFileAccess3 >& rToUseSFI,
const css::uno::Reference< css::task::XInteractionHandler >& rHandler );
@@ -246,15 +226,17 @@ protected:
// New variant for library export
void implStoreLibraryIndexFile( SfxLibrary* pLib, const ::xmlscript::LibDescriptor& rLib,
const css::uno::Reference< css::embed::XStorage >& xStorage,
- const OUString& aTargetURL,
+ std::u16string_view aTargetURL,
const css::uno::Reference< css::ucb::XSimpleFileAccess3 >& rToUseSFI );
bool implLoadLibraryIndexFile( SfxLibrary* pLib,
::xmlscript::LibDescriptor& rLib,
const css::uno::Reference< css::embed::XStorage >& xStorage,
- const OUString& aIndexFileName );
+ const OUString& aIndexFileName,
+ std::unique_lock<std::mutex>& guard );
- void implImportLibDescriptor( SfxLibrary* pLib, ::xmlscript::LibDescriptor const & rLib );
+ void implImportLibDescriptor(SfxLibrary* pLib, ::xmlscript::LibDescriptor const& rLib,
+ std::unique_lock<std::mutex>& guard);
// Methods to distinguish between different library types
virtual rtl::Reference<SfxLibrary> implCreateLibrary( const OUString& aName ) = 0;
@@ -292,7 +274,8 @@ protected:
/// @throws css::lang::WrappedTargetException
/// @throws css::uno::RuntimeException
virtual bool implLoadPasswordLibrary( SfxLibrary* pLib, const OUString& Name,
- bool bVerifyPasswordOnly=false );
+ bool bVerifyPasswordOnly,
+ std::unique_lock<std::mutex>& guard );
virtual void onNewRootStorage() = 0;
@@ -307,12 +290,13 @@ protected:
OUString createAppLibraryFolder( SfxLibrary* pLib, std::u16string_view aName );
void init( const OUString& rInitialDocumentURL,
- const css::uno::Reference< css::embed::XStorage >& _rxInitialStorage );
+ const css::uno::Reference< css::embed::XStorage >& _rxInitialStorage,
+ std::unique_lock<std::mutex>& guard );
- virtual const char* getInfoFileName() const = 0;
- virtual const char* getOldInfoFileName() const = 0;
- virtual const char* getLibElementFileExtension() const = 0;
- virtual const char* getLibrariesDir() const = 0;
+ virtual OUString getInfoFileName() const = 0;
+ virtual OUString getOldInfoFileName() const = 0;
+ virtual OUString getLibElementFileExtension() const = 0;
+ virtual OUString getLibrariesDir() const = 0;
// Handle maLibInfoFileURL and maStorageURL correctly
void checkStorageURL
@@ -329,20 +313,32 @@ protected:
void storeLibraries_Impl(
const css::uno::Reference< css::embed::XStorage >& xStorage,
- bool bComplete );
+ bool bComplete,
+ std::unique_lock<std::mutex>& guard );
+
+ void initializeFromDocument( const css::uno::Reference< css::document::XStorageBasedDocument >& _rxDocument,
+ std::unique_lock<std::mutex>& guard );
+
+ css::uno::Reference<css::container::XNameContainer>
+ createLibrary_Impl(const OUString& Name, std::unique_lock<std::mutex>& guard);
+ css::uno::Reference<css::container::XNameAccess>
+ createLibraryLink_Impl(const OUString& Name, const OUString& StorageURL, sal_Bool ReadOnly,
+ std::unique_lock<std::mutex>& guard);
+ void loadLibrary_Impl(const OUString& Name, std::unique_lock<std::mutex>& guard);
- void initializeFromDocument( const css::uno::Reference< css::document::XStorageBasedDocument >& _rxDocument );
// OEventListenerAdapter
virtual void _disposing( const css::lang::EventObject& _rSource ) override;
- // OComponentHelper
- virtual void SAL_CALL disposing() override;
+ // WeakComponentImplHelperBase
+ virtual void disposing(std::unique_lock<std::mutex>& guard) override;
private:
void init_Impl( const OUString& rInitialDocumentURL,
- const css::uno::Reference< css::embed::XStorage >& _rxInitialStorage );
- void implScanExtensions();
+ const css::uno::Reference< css::embed::XStorage >& _rxInitialStorage,
+ std::unique_lock<std::mutex>& guard );
+ void implScanExtensions(std::unique_lock<std::mutex>& guard);
+ static constexpr OUString sVBATextEncodingPropName = u"VBATextEncoding"_ustr;
public:
SfxLibraryContainer();
@@ -438,6 +434,26 @@ public:
virtual void SAL_CALL removeVBAScriptListener(
const css::uno::Reference< css::script::vba::XVBAScriptListener >& Listener ) override;
virtual void SAL_CALL broadcastVBAScriptEvent( sal_Int32 nIdentifier, const OUString& rModuleName ) override;
+
+ // css::beans::XPropertySet
+ virtual css::uno::Reference<css::beans::XPropertySetInfo>
+ SAL_CALL getPropertySetInfo() override;
+ virtual void SAL_CALL setPropertyValue(const OUString& aPropertyName,
+ const css::uno::Any& aValue) override;
+ virtual css::uno::Any SAL_CALL getPropertyValue(const OUString& PropertyName) override;
+ virtual void SAL_CALL addPropertyChangeListener(
+ const OUString& aPropertyName,
+ const css::uno::Reference<css::beans::XPropertyChangeListener>& xListener) override;
+ virtual void SAL_CALL removePropertyChangeListener(
+ const OUString& aPropertyName,
+ const css::uno::Reference<css::beans::XPropertyChangeListener>& aListener) override;
+ virtual void SAL_CALL addVetoableChangeListener(
+ const OUString& PropertyName,
+ const css::uno::Reference<css::beans::XVetoableChangeListener>& aListener) override;
+ virtual void SAL_CALL removeVetoableChangeListener(
+ const OUString& PropertyName,
+ const css::uno::Reference<css::beans::XVetoableChangeListener>& aListener) override;
+
};
@@ -457,11 +473,8 @@ public:
class SfxLibrary
- : public css::container::XNameContainer
- , public css::container::XContainer
- , public css::util::XChangesNotifier
- , public ::cppu::BaseMutex
- , public ::cppu::OComponentHelper
+ : public comphelper::WeakComponentImplHelper<
+ css::container::XNameContainer, css::container::XContainer, css::util::XChangesNotifier>
{
friend class SfxLibraryContainer;
friend class SfxDialogLibraryContainer;
@@ -470,35 +483,30 @@ class SfxLibrary
css::uno::Reference< css::ucb::XSimpleFileAccess3 > mxSFI;
ModifiableHelper& mrModifiable;
- rtl::Reference<NameContainer> maNameContainer;
+ NameContainer maNameContainer;
bool mbLoaded;
bool mbIsModified;
bool mbInitialised;
-
-private:
-
- OUString maLibElementFileExtension;
- OUString maLibInfoFileURL;
- OUString maStorageURL;
- OUString maUnexpandedStorageURL;
- OUString maOriginalStorageURL;
-
bool mbLink;
bool mbReadOnly;
bool mbReadOnlyLink;
bool mbPreload;
-
-protected:
bool mbPasswordProtected;
-private:
bool mbPasswordVerified;
bool mbDoc50Password;
- OUString maPassword;
-
bool mbSharedIndexFile;
bool mbExtension;
+private:
+
+ OUString maLibElementFileExtension;
+ OUString maLibInfoFileURL;
+ OUString maStorageURL;
+ OUString maUnexpandedStorageURL;
+ OUString maOriginalStorageURL;
+ OUString maPassword;
+
// Additional functionality for localisation
// Provide modify state including resources
virtual bool isModified() = 0;
@@ -510,7 +518,8 @@ private:
protected:
bool implIsModified() const { return mbIsModified; }
- void implSetModified( bool _bIsModified );
+ void implSetModified(bool _bIsModified, std::unique_lock<std::mutex>& guard);
+ bool isPasswordProtected() const { return mbPasswordProtected; }
private:
/** checks whether the lib is readonly, or a readonly link, throws an IllegalArgumentException if so
@@ -522,7 +531,8 @@ private:
void impl_checkLoaded();
private:
- void impl_removeWithoutChecks( const OUString& _rElementName );
+ void impl_removeWithoutChecks(const OUString& _rElementName,
+ std::unique_lock<std::mutex>& guard);
public:
SfxLibrary(
@@ -534,16 +544,11 @@ public:
ModifiableHelper& _rModifiable,
const css::uno::Type& aType,
const css::uno::Reference< css::ucb::XSimpleFileAccess3 >& xSFI,
- const OUString& aLibInfoFileURL,
- const OUString& aStorageURL,
+ OUString aLibInfoFileURL,
+ OUString aStorageURL,
bool ReadOnly
);
- // Methods XInterface
- virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& rType ) override;
- virtual void SAL_CALL acquire() noexcept override { OComponentHelper::acquire(); }
- virtual void SAL_CALL release() noexcept override { OComponentHelper::release(); }
-
// Methods XElementAccess
virtual css::uno::Type SAL_CALL getElementType( ) override;
virtual sal_Bool SAL_CALL hasElements( ) override;
@@ -560,10 +565,6 @@ public:
virtual void SAL_CALL insertByName( const OUString& aName, const css::uno::Any& aElement ) override;
virtual void SAL_CALL removeByName( const OUString& Name ) override;
- // XTypeProvider
- css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override;
- css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId( ) override;
-
// Methods XContainer
virtual void SAL_CALL addContainerListener( const css::uno::Reference<
css::container::XContainerListener >& xListener ) override;
@@ -576,13 +577,6 @@ public:
virtual void SAL_CALL removeChangesListener( const css::uno::Reference<
css::util::XChangesListener >& xListener ) override;
-public:
- struct LibraryContainerAccess { friend class SfxLibraryContainer; private: LibraryContainerAccess() { } };
- void removeElementWithoutChecks( const OUString& _rElementName, LibraryContainerAccess )
- {
- impl_removeWithoutChecks( _rElementName );
- }
-
protected:
virtual bool isLoadedStorable();
diff --git a/basic/source/inc/parser.hxx b/basic/source/inc/parser.hxx
index 4e03e6d39058..2cbfb7864f41 100644
--- a/basic/source/inc/parser.hxx
+++ b/basic/source/inc/parser.hxx
@@ -95,7 +95,6 @@ public:
void Symbol( const KeywordSymbolInfo* pKeywordSymbolInfo ); // let or call
void ErrorStmnt(); // ERROR n
- void BadBlock(); // LOOP/WEND/NEXT
void NoIf(); // ELSE/ELSE IF without IF
void Assign(); // LET
void Attribute();
diff --git a/basic/source/inc/propacc.hxx b/basic/source/inc/propacc.hxx
index 66dd26cefe63..bb2d13d50216 100644
--- a/basic/source/inc/propacc.hxx
+++ b/basic/source/inc/propacc.hxx
@@ -22,11 +22,13 @@
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/beans/XPropertySetInfo.hpp>
#include <com/sun/star/beans/XPropertyAccess.hpp>
+#include <comphelper/propertysetinfo.hxx>
#include <cppuhelper/implbase.hxx>
#include <vector>
typedef std::vector<css::beans::PropertyValue> SbPropertyValueArr_Impl;
+typedef std::vector<comphelper::PropertyMapEntry> SbPropertyInfoArr_Impl;
typedef ::cppu::WeakImplHelper< css::beans::XPropertySet,
css::beans::XPropertyAccess > SbPropertyValuesHelper;
@@ -35,6 +37,7 @@ typedef ::cppu::WeakImplHelper< css::beans::XPropertySet,
class SbPropertyValues final : public SbPropertyValuesHelper
{
SbPropertyValueArr_Impl m_aPropVals;
+ SbPropertyInfoArr_Impl m_aPropInfos;
css::uno::Reference< css::beans::XPropertySetInfo > m_xInfo;
private:
diff --git a/basic/source/inc/rtlproto.hxx b/basic/source/inc/rtlproto.hxx
index b20fa9afab45..ad341778c049 100644
--- a/basic/source/inc/rtlproto.hxx
+++ b/basic/source/inc/rtlproto.hxx
@@ -28,111 +28,12 @@ typedef void( *RtlCall ) ( StarBASIC* p, SbxArray& rArgs, bool bWrite );
extern void SbRtl_Date(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
extern void SbRtl_Err(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
extern void SbRtl_Erl(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_False(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
extern void SbRtl_Empty(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
extern void SbRtl_Nothing(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
extern void SbRtl_Null(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_True(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-
-extern void SbRtl_ATTR_NORMAL(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_ATTR_READONLY(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_ATTR_HIDDEN(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_ATTR_SYSTEM(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_ATTR_VOLUME(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_ATTR_DIRECTORY(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_ATTR_ARCHIVE(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-
-extern void SbRtl_V_EMPTY(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_V_NULL(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_V_INTEGER(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_V_LONG(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_V_SINGLE(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_V_DOUBLE(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_V_CURRENCY(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_V_DATE(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_V_STRING(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-
-extern void SbRtl_MB_OK(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_MB_OKCANCEL(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_MB_ABORTRETRYIGNORE(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_MB_YESNOCANCEL(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_MB_YESNO(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_MB_RETRYCANCEL(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_MB_ICONSTOP(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_MB_ICONQUESTION(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_MB_ICONEXCLAMATION(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_MB_ICONINFORMATION(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_MB_DEFBUTTON1(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_MB_DEFBUTTON2(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_MB_DEFBUTTON3(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_MB_APPLMODAL(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_MB_SYSTEMMODAL(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-
-extern void SbRtl_IDOK(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_IDCANCEL(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_IDABORT(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_IDRETRY(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_IDYES(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_IDNO(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-
-extern void SbRtl_CF_TEXT(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_CF_BITMAP(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_CF_METAFILEPICT(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
extern void SbRtl_PI(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_SET_OFF(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_SET_ON(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TOGGLE(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-
-extern void SbRtl_TYP_AUTHORFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_CHAPTERFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_CONDTXTFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_DATEFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_DBFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_DBNAMEFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_DBNEXTSETFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_DBNUMSETFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_DBSETNUMBERFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_DDEFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_DOCINFOFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_DOCSTATFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_EXTUSERFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_FILENAMEFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_FIXDATEFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_FIXTIMEFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_FORMELFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_GETFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_GETREFFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_HIDDENPARAFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_HIDDENTXTFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_INPUTFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_MACROFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_NEXTPAGEFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_PAGENUMBERFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_POSTITFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_PREVPAGEFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_SEQFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_SETFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_SETINPFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_SETREFFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_TEMPLNAMEFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_TIMEFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_USERFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_USRINPFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_SETREFPAGEFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_GETREFPAGEFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_INTERNETFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_TYP_JUMPEDITFLD(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-
-extern void SbRtl_FRAMEANCHORPAGE(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_FRAMEANCHORPARA(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_FRAMEANCHORCHAR(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-
-extern void SbRtl_CLEAR_ALLTABS(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_CLEAR_TAB(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_SET_TAB(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-
// Methods
extern void SbRtl_CreateObject(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
@@ -200,7 +101,6 @@ extern void SbRtl_Tan(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
extern void SbRtl_UCase(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
extern void SbRtl_Val(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
extern void SbRtl_Len(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
-extern void SbRtl_Spc(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
extern void SbRtl_DateSerial(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
extern void SbRtl_TimeSerial(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
extern void SbRtl_DateValue(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
@@ -232,6 +132,7 @@ extern void SbRtl_IsUnoStruct(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
extern void SbRtl_FileDateTime(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
extern void SbRtl_Format(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
extern void SbRtl_FormatNumber(StarBASIC* pBasic, SbxArray& rPar, bool bWrite);
+extern void SbRtl_FormatPercent(StarBASIC* pBasic, SbxArray& rPar, bool bWrite);
extern void SbRtl_GetAttr(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
extern void SbRtl_Randomize(StarBASIC * pBasic, SbxArray & rPar, bool bWrite); // JSM
extern void SbRtl_Round(StarBASIC * pBasic, SbxArray & rPar, bool bWrite);
diff --git a/basic/source/inc/runtime.hxx b/basic/source/inc/runtime.hxx
index d09db071a1a9..e2b1a4a331a0 100644
--- a/basic/source/inc/runtime.hxx
+++ b/basic/source/inc/runtime.hxx
@@ -32,14 +32,15 @@
#include <cmath>
#include <vector>
#include <memory>
+#include <optional>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/container/XEnumeration.hpp>
#include <com/sun/star/container/XIndexAccess.hpp>
#include <unotools/localedatawrapper.hxx>
#include <o3tl/deleter.hxx>
#include <o3tl/typed_flags_set.hxx>
+#include <tools/wldcrd.hxx>
-class SbiInstance; // active StarBASIC process
class SbiRuntime; // active StarBASIC procedure instance
struct SbiArgv; // Argv stack element
@@ -87,30 +88,104 @@ struct SbiForStack { // for/next stack:
#define MAXRECURSION 500 //to prevent dead-recursions
-enum class SbAttributes {
- NONE = 0x0000,
- READONLY = 0x0001,
- HIDDEN = 0x0002,
- DIRECTORY = 0x0010
-};
+// Related to: Dir, GetAttr, SetAttr
+namespace SbAttributes
+{
+constexpr sal_Int16 NORMAL = 0x0000;
+constexpr sal_Int16 READONLY = 0x0001;
+constexpr sal_Int16 HIDDEN = 0x0002;
+constexpr sal_Int16 SYSTEM = 0x0004;
+constexpr sal_Int16 VOLUME = 0x0008;
+constexpr sal_Int16 DIRECTORY = 0x0010;
+constexpr sal_Int16 ARCHIVE = 0x0020;
+}
-namespace o3tl
+// Related to: MsgBox (Buttons argument)
+namespace SbMB
+{
+constexpr sal_Int16 OK = 0;
+constexpr sal_Int16 OKCANCEL = 1;
+constexpr sal_Int16 ABORTRETRYIGNORE = 2;
+constexpr sal_Int16 YESNOCANCEL = 3;
+constexpr sal_Int16 YESNO = 4;
+constexpr sal_Int16 RETRYCANCEL = 5;
+constexpr sal_Int16 ICONSTOP = 16;
+constexpr sal_Int16 ICONQUESTION = 32;
+constexpr sal_Int16 ICONEXCLAMATION = 48;
+constexpr sal_Int16 ICONINFORMATION = 64;
+constexpr sal_Int16 DEFBUTTON1 = 0;
+constexpr sal_Int16 DEFBUTTON2 = 256;
+constexpr sal_Int16 DEFBUTTON3 = 512;
+constexpr sal_Int16 APPLMODAL = 0;
+constexpr sal_Int16 SYSTEMMODAL = 4096;
+
+// Related to: MsgBox (return value)
+namespace Response
{
- template<> struct typed_flags<SbAttributes> : is_typed_flags<SbAttributes, 0x13> {};
+constexpr sal_Int16 OK = 1;
+constexpr sal_Int16 CANCEL = 2;
+constexpr sal_Int16 ABORT = 3;
+constexpr sal_Int16 RETRY = 4;
+constexpr sal_Int16 IGNORE = 5;
+constexpr sal_Int16 YES = 6;
+constexpr sal_Int16 NO = 7;
+}
}
-class WildCard;
+// Related to: SwFieldTypesEnum in sw/inc/fldbas.hxx
+namespace SbTYP
+{
+constexpr sal_Int16 DATE = 0;
+constexpr sal_Int16 TIME = 1;
+constexpr sal_Int16 FILENAME = 2;
+constexpr sal_Int16 DATABASENAME = 3;
+constexpr sal_Int16 CHAPTER = 4;
+constexpr sal_Int16 PAGENUMBER = 5;
+constexpr sal_Int16 DOCUMENTSTATISTICS = 6;
+constexpr sal_Int16 AUTHOR = 7;
+constexpr sal_Int16 SET = 8;
+constexpr sal_Int16 GET = 9;
+constexpr sal_Int16 FORMEL = 10;
+constexpr sal_Int16 HIDDENTEXT = 11;
+constexpr sal_Int16 SETREF = 12;
+constexpr sal_Int16 GETREF = 13;
+constexpr sal_Int16 DDE = 14;
+constexpr sal_Int16 MACRO = 15;
+constexpr sal_Int16 INPUT = 16;
+constexpr sal_Int16 HIDDENPARAGRAPH = 17;
+constexpr sal_Int16 DOCUMENTINFO = 18;
+constexpr sal_Int16 DATABASE = 19;
+constexpr sal_Int16 USER = 20;
+constexpr sal_Int16 POSTIT = 21;
+constexpr sal_Int16 TEMPLATENAME = 22;
+constexpr sal_Int16 SEQUENCE = 23;
+constexpr sal_Int16 DATABASENEXTSET = 24;
+constexpr sal_Int16 DATABASENUMBERSET = 25;
+constexpr sal_Int16 DATABASESETNUMBER = 26;
+constexpr sal_Int16 CONDITIONALTEXT = 27;
+constexpr sal_Int16 NEXTPAGE = 28;
+constexpr sal_Int16 PREVIOUSPAGE = 29;
+constexpr sal_Int16 EXTENDEDUSER = 30;
+constexpr sal_Int16 FIXEDDATE = 31;
+constexpr sal_Int16 FIXEDTIME = 32;
+constexpr sal_Int16 SETINPUT = 33;
+constexpr sal_Int16 USERINPUT = 34;
+constexpr sal_Int16 SETREFPAGE = 35;
+constexpr sal_Int16 GETREFPAGE = 36;
+constexpr sal_Int16 INTERNET = 37;
+constexpr sal_Int16 JUMPEDIT = 38;
+}
class SbiRTLData
{
public:
std::unique_ptr<osl::Directory> pDir;
- SbAttributes nDirFlags;
+ sal_Int16 nDirFlags;
short nCurDirPos;
OUString sFullNameToBeChecked;
- std::unique_ptr<WildCard> pWildCard;
+ std::optional<WildCard> moWildCard;
css::uno::Sequence< OUString > aDirSeq;
@@ -188,7 +263,7 @@ public:
SbiDdeControl* GetDdeControl() { return pDdeCtrl.get(); }
StarBASIC* GetBasic() { return pBasic; }
SbiDllMgr* GetDllMgr();
- SbiRTLData& GetRTLData() const { return const_cast<SbiRTLData&>(aRTLData); }
+ SbiRTLData& GetRTLData() { return aRTLData; }
std::shared_ptr<SvNumberFormatter> const & GetNumberFormatter();
sal_uInt32 GetStdDateIdx() const { return nStdDateIdx; }
@@ -226,31 +301,30 @@ class SbiRuntime
SbxArrayRef refRedimpArray; // Array saved to use for REDIM PRESERVE
SbxVariableRef refRedim; // Array saved to use for REDIM
SbxVariableRef xDummyVar; // substitute for variables that weren't found
- SbxVariable* mpExtCaller; // Caller ( external - e.g. button name, shape, range object etc. - only in vba mode )
- SbiForStack* pForStk; // FOR/NEXT-Stack
- sal_uInt16 nExprLvl; // depth of the expr-stack
- sal_uInt16 nForLvl; // #118235: Maintain for level
+ SbxVariable* mpExtCaller = nullptr; // Caller ( external - e.g. button name, shape, range object etc. - only in vba mode )
+ SbiForStack* pForStk = nullptr; // FOR/NEXT-Stack
+ sal_uInt16 nExprLvl = 0; // depth of the expr-stack
+ sal_uInt16 nForLvl = 0; // #118235: Maintain for level
const sal_uInt8* pCode; // current Code-Pointer
const sal_uInt8* pStmnt; // beginning of the last statement
- const sal_uInt8* pError; // address of the current error handler
- const sal_uInt8* pRestart; // restart-address
- const sal_uInt8* pErrCode; // restart-address RESUME NEXT
- const sal_uInt8* pErrStmnt; // restart-address RESUME 0
+ const sal_uInt8* pError = nullptr; // address of the current error handler
+ const sal_uInt8* pRestart = nullptr; // restart-address
+ const sal_uInt8* pErrCode = nullptr; // restart-address RESUME NEXT
+ const sal_uInt8* pErrStmnt = nullptr; // restart-address RESUME 0
OUString aLibName; // Lib-name for declare-call
SbxArrayRef refParams; // current procedure parameters
SbxArrayRef refLocals; // local variable
SbxArrayRef refArgv;
// #74254, one refSaveObj is not enough! new: pRefSaveList (see above)
- short nArgc;
- bool bRun;
- bool bError; // true: handle errors
- bool bInError; // true: in an error handler
- bool bBlocked; // true: blocked by next call level, #i48868
+ short nArgc = 0;
+ bool bRun = true;
+ bool bError = true; // true: handle errors
+ bool bInError = false; // true: in an error handler
+ bool bBlocked = false; // true: blocked by next call level, #i48868
bool bVBAEnabled;
BasicDebugFlags nFlags; // Debugging-Flags
- ErrCode nError;
- sal_uInt16 nOps; // opcode counter
- sal_uInt32 m_nLastTime;
+ ErrCode nError = ERRCODE_NONE;
+ sal_uInt16 nOps = 0; // opcode counter
std::vector<SbxVariableRef> aRefSaved; // #74254 save temporary references
std::vector<SbiGosub> pGosubStk; // GOSUB stack
@@ -349,8 +423,8 @@ public:
void SetVBAEnabled( bool bEnabled );
bool IsImageFlag( SbiImageFlags n ) const;
sal_uInt16 GetBase() const;
- sal_Int32 nLine,nCol1,nCol2;
- SbiRuntime* pNext; // Stack-Chain
+ sal_Int32 nLine = 0, nCol1 = 0, nCol2 = 0;
+ SbiRuntime* pNext = nullptr; // Stack-Chain
// tdf#79426, tdf#125180 - adds the information about a missing parameter
static void SetIsMissing( SbxVariable* );
diff --git a/basic/source/inc/sbintern.hxx b/basic/source/inc/sbintern.hxx
index 0f1b4d3114b5..e3dcd492a4f6 100644
--- a/basic/source/inc/sbintern.hxx
+++ b/basic/source/inc/sbintern.hxx
@@ -21,18 +21,16 @@
#include <basic/sbstar.hxx>
#include <sbxfac.hxx>
+#include "sbunoobj.hxx"
#include <unotools/transliterationwrapper.hxx>
-#include <vcl/errcode.hxx>
+#include <comphelper/errcode.hxx>
#include <config_features.h>
+#include <optional>
namespace utl
{
class TransliterationWrapper;
}
-class SbUnoFactory;
-class SbTypeFactory;
-class SbOLEFactory;
-class SbFormFactory;
class SbiInstance;
class SbModule;
class BasicManager;
@@ -104,22 +102,25 @@ struct SbiGlobals
{
static SbiGlobals* pGlobals;
SbiInstance* pInst; // all active runtime instances
- std::unique_ptr<SbiFactory> pSbFac; // StarBASIC-Factory
- std::unique_ptr<SbUnoFactory> pUnoFac; // Factory for Uno-Structs at DIM AS NEW
- std::unique_ptr<SbTypeFactory>
+#if HAVE_FEATURE_SCRIPTING
+ std::optional<SbiFactory> pSbFac; // StarBASIC-Factory
+ std::optional<SbUnoFactory> pUnoFac; // Factory for Uno-Structs at DIM AS NEW
+ std::optional<SbTypeFactory>
pTypeFac; // Factory for user defined types
std::unique_ptr<SbClassFactory>
pClassFac; // Factory for user defined classes (based on class modules)
- std::unique_ptr<SbOLEFactory>
+ std::optional<SbOLEFactory>
pOLEFac; // Factory for OLE types
- std::unique_ptr<SbFormFactory>
+ std::optional<SbFormFactory>
pFormFac; // Factory for user forms
+ std::unique_ptr<BasicManager> pAppBasMgr;
+#endif
SbModule* pMod; // currently active module
SbModule* pCompMod; // currently compiled module
short nInst; // number of BASICs
Link<StarBASIC*,bool> aErrHdl; // global error handler
Link<StarBASIC*,BasicDebugFlags> aBreakHdl; // global break handler
- ErrCode nCode;
+ ErrCodeMsg nCode;
sal_Int32 nLine;
sal_Int32 nCol1,nCol2; // from... to...
bool bCompilerError; // flag for compiler error
@@ -128,9 +129,6 @@ struct SbiGlobals
OUString aErrMsg; // buffer for GetErrorText()
std::unique_ptr<::utl::TransliterationWrapper> pTransliterationWrapper; // For StrComp
bool bBlockCompilerError;
-#if HAVE_FEATURE_SCRIPTING
- std::unique_ptr<BasicManager> pAppBasMgr;
-#endif
StarBASIC* pMSOMacroRuntimLib; // Lib containing MSO Macro Runtime API entry symbols
SbiGlobals();
diff --git a/basic/source/inc/sbjsmod.hxx b/basic/source/inc/sbjsmod.hxx
index 128c0e243e95..4f8584ff08e5 100644
--- a/basic/source/inc/sbjsmod.hxx
+++ b/basic/source/inc/sbjsmod.hxx
@@ -28,7 +28,7 @@
class SbJScriptModule final : public SbModule
{
virtual bool LoadData(SvStream&, sal_uInt16) override;
- virtual bool StoreData(SvStream&) const override;
+ virtual std::pair<bool, sal_uInt32> StoreData(SvStream&) const override;
public:
SBX_DECL_PERSIST_NODATA(SBXID_JSCRIPTMOD, 1);
diff --git a/basic/source/inc/sbunoobj.hxx b/basic/source/inc/sbunoobj.hxx
index 1f3042951e51..16e32af5a87e 100644
--- a/basic/source/inc/sbunoobj.hxx
+++ b/basic/source/inc/sbunoobj.hxx
@@ -31,9 +31,11 @@
#include <com/sun/star/reflection/XIdlClass.hpp>
#include <com/sun/star/reflection/XServiceTypeDescription2.hpp>
#include <rtl/ustring.hxx>
+#include <o3tl/string_view.hxx>
#include <string_view>
#include <unordered_map>
+#include <utility>
#include <vector>
#include <map>
@@ -65,9 +67,9 @@ class SbUnoStructRefObject final : public SbxObject
{
struct caseLessComp
{
- bool operator() (const OUString& rProp, std::u16string_view rOtherProp ) const
+ bool operator() (std::u16string_view rProp, std::u16string_view rOtherProp ) const
{
- return rProp.compareToIgnoreAsciiCase( rOtherProp ) < 0;
+ return o3tl::compareToIgnoreAsciiCase( rProp, rOtherProp ) < 0;
}
};
typedef std::map< OUString, std::unique_ptr<StructRefInfo>, caseLessComp > StructFieldInfo;
@@ -82,7 +84,7 @@ class SbUnoStructRefObject final : public SbxObject
public:
StructRefInfo getStructMember( const OUString& rMember );
const StructRefInfo& getStructInfo() const { return maMemberInfo; }
- SbUnoStructRefObject( const OUString& aName_, const StructRefInfo& rMemberInfo );
+ SbUnoStructRefObject( const OUString& aName_, StructRefInfo aMemberInfo );
virtual ~SbUnoStructRefObject() override;
// override Find to support e. g. NameAccess
@@ -192,12 +194,13 @@ class SbUnoProperty final : public SbxProperty
public:
SbUnoProperty( const OUString& aName_, SbxDataType eSbxType, SbxDataType eRealSbxType,
- const css::beans::Property& aUnoProp_, sal_Int32 nId_, bool bInvocation, bool bUnoStruct );
+ css::beans::Property aUnoProp_, sal_Int32 nId_, bool bInvocation, bool bUnoStruct );
bool isUnoStruct() const { return mbUnoStruct; }
bool isInvocationBased() const
{ return mbInvocation; }
SbxDataType getRealType() const { return mRealType; }
+ const OUString& getUnoName() const { return aUnoProp.Name; }
};
// factory class to create uno-structs per DIM AS NEW
@@ -217,9 +220,9 @@ public:
SbUnoClass( const OUString& aName_ )
: SbxObject( aName_ )
{}
- SbUnoClass( const OUString& aName_, const css::uno::Reference< css::reflection::XIdlClass >& xClass_ )
+ SbUnoClass( const OUString& aName_, css::uno::Reference< css::reflection::XIdlClass > xClass_ )
: SbxObject( aName_ )
- , m_xClass( xClass_ )
+ , m_xClass(std::move( xClass_ ))
{}
@@ -244,9 +247,9 @@ class SbUnoService final : public SbxObject
public:
SbUnoService( const OUString& aName_,
- const css::uno::Reference< css::reflection::XServiceTypeDescription2 >& xServiceTypeDesc )
+ css::uno::Reference< css::reflection::XServiceTypeDescription2 > xServiceTypeDesc )
: SbxObject( aName_ )
- , m_xServiceTypeDesc( xServiceTypeDesc )
+ , m_xServiceTypeDesc(std::move( xServiceTypeDesc ))
, m_bNeedsInit( true )
{}
@@ -293,9 +296,9 @@ class SbUnoAnyObject final : public SbxObject
css::uno::Any mVal;
public:
- SbUnoAnyObject( const css::uno::Any& rVal )
+ SbUnoAnyObject( css::uno::Any rVal )
: SbxObject( OUString() )
- , mVal( rVal )
+ , mVal(std::move( rVal ))
{}
const css::uno::Any& getValue() const
@@ -350,7 +353,7 @@ class BasicCollection final : public SbxObject
virtual ~BasicCollection() override;
virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
sal_Int32 implGetIndex( SbxVariable const * pIndexVar );
- sal_Int32 implGetIndexForName(std::u16string_view rName);
+ sal_Int32 implGetIndexForName(const OUString& rName);
void CollAdd( SbxArray* pPar_ );
void CollItem( SbxArray* pPar_ );
void CollRemove( SbxArray* pPar_ );
@@ -372,7 +375,7 @@ private:
public:
static VBAConstantHelper& instance();
SbxVariable* getVBAConstant( const OUString& rName );
- bool isVBAConstantType( const OUString& rName );
+ bool isVBAConstantType( std::u16string_view rName );
};
SbxVariable* getDefaultProp( SbxVariable* pRef );
diff --git a/basic/source/inc/scanner.hxx b/basic/source/inc/scanner.hxx
index 39dda9fa391c..51e4ed7fa5d8 100644
--- a/basic/source/inc/scanner.hxx
+++ b/basic/source/inc/scanner.hxx
@@ -20,7 +20,7 @@
#pragma once
#include <basic/sbxdef.hxx>
-#include <vcl/errcode.hxx>
+#include <comphelper/errcode.hxx>
// The scanner is stand-alone, i. e. it can be used from everywhere.
// A BASIC-instance is necessary for error messages. Without BASIC
@@ -33,6 +33,7 @@ class SbiScanner
{
OUString aBuf; // input buffer
OUString aLine;
+ OUString aSaveLine;
sal_Int32 nLineIdx;
sal_Int32 nSaveLineIdx;
StarBASIC* pBasic; // instance for error callbacks
@@ -62,11 +63,12 @@ protected:
bool bVBASupportOn; // true: OPTION VBASupport 1 otherwise default False
bool bPrevLineExtentsComment; // true: Previous line is comment and ends on "... _"
bool bClosingUnderscore; // true: Closing underscore followed by end of line
+ bool bLineEndsWithWhitespace; // true: Line ends with whitespace (BasicCharClass::isWhitespace)
bool bInStatement;
void GenError( ErrCode );
public:
- SbiScanner( const OUString&, StarBASIC* = nullptr );
+ SbiScanner( OUString , StarBASIC* = nullptr );
void EnableErrors() { bError = false; }
bool IsHash() const { return bHash; }
@@ -79,8 +81,8 @@ public:
sal_Int32 GetCol1() const { return nCol1; }
void SetCol1( sal_Int32 n ) { nCol1 = n; }
StarBASIC* GetBasic() { return pBasic; }
- void SaveLine() { nSaveLineIdx = nLineIdx; }
- void RestoreLine() { nLineIdx = nSaveLineIdx; }
+ void SaveLine() { aSaveLine = aLine; nSaveLineIdx = nLineIdx; }
+ void RestoreLine() { nLineIdx = nSaveLineIdx; aLine = aSaveLine; }
void LockColumn();
void UnlockColumn();
bool DoesColonFollow();
diff --git a/basic/source/inc/scriptcont.hxx b/basic/source/inc/scriptcont.hxx
index 592c3ad9d31b..38e62b3bfedc 100644
--- a/basic/source/inc/scriptcont.hxx
+++ b/basic/source/inc/scriptcont.hxx
@@ -29,7 +29,7 @@ namespace basic
{
-class SfxScriptLibraryContainer final : public SfxLibraryContainer, public OldBasicPassword
+class SfxScriptLibraryContainer final : public SfxLibraryContainer
{
css::uno::Reference< css::container::XNameAccess > mxCodeNameAccess;
@@ -70,18 +70,16 @@ class SfxScriptLibraryContainer final : public SfxLibraryContainer, public OldBa
const css::uno::Reference< css::ucb::XSimpleFileAccess3 >& rToUseSFI, const css::uno::Reference< css::task::XInteractionHandler >& Handler ) override;
virtual bool implLoadPasswordLibrary( SfxLibrary* pLib, const OUString& Name,
- bool bVerifyPasswordOnly=false ) override;
+ bool bVerifyPasswordOnly,
+ std::unique_lock<std::mutex>& guard ) override;
virtual void onNewRootStorage() override;
- // OldBasicPassword interface
- virtual void setLibraryPassword( const OUString& rLibraryName, const OUString& rPassword ) override;
-
- virtual const char* getInfoFileName() const override;
- virtual const char* getOldInfoFileName() const override;
- virtual const char* getLibElementFileExtension() const override;
- virtual const char* getLibrariesDir() const override;
+ virtual OUString getInfoFileName() const override;
+ virtual OUString getOldInfoFileName() const override;
+ virtual OUString getLibElementFileExtension() const override;
+ virtual OUString getLibrariesDir() const override;
public:
SfxScriptLibraryContainer();
@@ -99,14 +97,17 @@ public:
// Methods XServiceInfo
virtual OUString SAL_CALL getImplementationName( ) override;
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
+
+ // Library password handling for 5.0 documents
+ void setLibraryPassword( const OUString& rLibraryName, const OUString& rPassword );
};
typedef std::unordered_map< OUString, css::script::ModuleInfo > ModuleInfoMap;
-typedef ::cppu::ImplHelper1< css::script::vba::XVBAModuleInfo > SfxScriptLibrary_BASE;
+typedef cppu::ImplInheritanceHelper< SfxLibrary, css::script::vba::XVBAModuleInfo > SfxScriptLibrary_BASE;
-class SfxScriptLibrary final : public SfxLibrary, public SfxScriptLibrary_BASE
+class SfxScriptLibrary final : public SfxScriptLibrary_BASE
{
friend class SfxScriptLibraryContainer;
@@ -139,9 +140,6 @@ public:
const OUString& aLibInfoFileURL, const OUString& aStorageURL, bool ReadOnly
);
- DECLARE_XINTERFACE()
- DECLARE_XTYPEPROVIDER()
-
// XVBAModuleInfo
virtual css::script::ModuleInfo SAL_CALL getModuleInfo( const OUString& ModuleName ) override;
virtual sal_Bool SAL_CALL hasModuleInfo( const OUString& ModuleName ) override;
diff --git a/basic/source/inc/stdobj.hxx b/basic/source/inc/stdobj.hxx
index 18df1fbbdda7..c62292351d06 100644
--- a/basic/source/inc/stdobj.hxx
+++ b/basic/source/inc/stdobj.hxx
@@ -20,17 +20,16 @@
#pragma once
#include <basic/sbxobj.hxx>
+#include <sbstdobj.hxx>
+#include <optional>
class StarBASIC;
-class SbStdFactory;
class SbiStdObject final : public SbxObject
{
- std::unique_ptr<SbStdFactory> pStdFactory;
+ std::optional<SbStdFactory> pStdFactory;
virtual ~SbiStdObject() override;
- using SbxVariable::GetInfo;
- static SbxInfo* GetInfo(short);
virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;
public:
diff --git a/basic/source/inc/symtbl.hxx b/basic/source/inc/symtbl.hxx
index b8a2f6ebbaad..fdb7ce736be2 100644
--- a/basic/source/inc/symtbl.hxx
+++ b/basic/source/inc/symtbl.hxx
@@ -26,7 +26,6 @@
class SbiConstDef;
class SbiParser;
class SbiProcDef;
-class SbiStringPool;
class SbiSymDef; // base class
enum SbiSymScope { SbLOCAL, SbPARAM, SbPUBLIC, SbGLOBAL, SbRTL };
@@ -42,7 +41,7 @@ public:
sal_uInt32 GetSize() const { return aData.size(); }
short Add( const OUString& );
short Add( double, SbxDataType );
- OUString Find( sal_uInt32 ) const;
+ const OUString & Find( sal_uInt32 ) const;
};
@@ -107,7 +106,7 @@ protected:
sal_uInt16 nDefaultId; // Symbol number of default value
short nFixedStringLength; // String length in: Dim foo As String*Length
public:
- SbiSymDef( const OUString& );
+ SbiSymDef( OUString );
virtual ~SbiSymDef();
virtual SbiProcDef* GetProcDef();
virtual SbiConstDef* GetConstDef();
diff --git a/basic/source/inc/token.hxx b/basic/source/inc/token.hxx
index 4230ff585b7a..9927e894e3b5 100644
--- a/basic/source/inc/token.hxx
+++ b/basic/source/inc/token.hxx
@@ -130,7 +130,7 @@ public:
{ return t >= FIRSTKWD && t <= LASTKWD; }
static bool IsExtra( SbiToken t )
{ return t >= FIRSTEXTRA; }
- static OUString GetKeywordCase( const OUString& sKeyword );
+ static OUString GetKeywordCase( std::u16string_view sKeyword );
};
diff --git a/basic/source/runtime/basrdll.cxx b/basic/source/runtime/basrdll.cxx
index ba94fd7b9d2b..853863b4fcfd 100644
--- a/basic/source/runtime/basrdll.cxx
+++ b/basic/source/runtime/basrdll.cxx
@@ -37,12 +37,11 @@ struct BasicDLLImpl : public SvRefBase
bool bDebugMode;
bool bBreakEnabled;
- std::unique_ptr<SbxAppData> xSbxAppData;
+ SbxAppData aSbxAppData;
BasicDLLImpl()
: bDebugMode(false)
, bBreakEnabled(true)
- , xSbxAppData(new SbxAppData)
{ }
static BasicDLLImpl* BASIC_DLL;
@@ -69,7 +68,7 @@ BasicDLL::~BasicDLL()
std::scoped_lock aGuard(BasicDLLImpl::getMutex());
const bool bLastRef = m_xImpl->GetRefCount() == 1;
if (bLastRef) {
- BasicDLLImpl::BASIC_DLL->xSbxAppData->m_aGlobErr.clear();
+ BasicDLLImpl::BASIC_DLL->aSbxAppData.m_aGlobErr.clear();
}
m_xImpl.clear();
// only reset BASIC_DLL after the object had been destroyed
@@ -122,12 +121,12 @@ void BasicDLL::BasicBreak()
SbxAppData& GetSbxData_Impl()
{
- return *BasicDLLImpl::BASIC_DLL->xSbxAppData;
+ return BasicDLLImpl::BASIC_DLL->aSbxAppData;
}
bool IsSbxData_Impl()
{
- return BasicDLLImpl::BASIC_DLL && BasicDLLImpl::BASIC_DLL->xSbxAppData;
+ return BasicDLLImpl::BASIC_DLL;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/runtime/comenumwrapper.cxx b/basic/source/runtime/comenumwrapper.cxx
index b7881a1b9ade..2434197d76d8 100644
--- a/basic/source/runtime/comenumwrapper.cxx
+++ b/basic/source/runtime/comenumwrapper.cxx
@@ -30,7 +30,7 @@ sal_Bool SAL_CALL ComEnumerationWrapper::hasMoreElements()
if ( m_xInvocation.is() )
{
sal_Int32 nLength = 0;
- bResult = ( ( m_xInvocation->getValue( "length" ) >>= nLength ) && nLength > m_nCurInd );
+ bResult = ( ( m_xInvocation->getValue( u"length"_ustr ) >>= nLength ) && nLength > m_nCurInd );
}
}
catch(const uno::Exception& )
@@ -49,7 +49,7 @@ uno::Any SAL_CALL ComEnumerationWrapper::nextElement()
uno::Sequence< uno::Any > aNamedParam;
uno::Sequence< uno::Any > aArgs{ uno::Any(m_nCurInd++) };
- return m_xInvocation->invoke( "item",
+ return m_xInvocation->invoke( u"item"_ustr,
aArgs,
aNamedParamIndex,
aNamedParam );
diff --git a/basic/source/runtime/comenumwrapper.hxx b/basic/source/runtime/comenumwrapper.hxx
index 560829b331bb..38dd57f274a6 100644
--- a/basic/source/runtime/comenumwrapper.hxx
+++ b/basic/source/runtime/comenumwrapper.hxx
@@ -23,6 +23,7 @@
#include <com/sun/star/script/XInvocation.hpp>
#include <cppuhelper/implbase.hxx>
+#include <utility>
class ComEnumerationWrapper : public ::cppu::WeakImplHelper<css::container::XEnumeration>
{
@@ -30,8 +31,8 @@ class ComEnumerationWrapper : public ::cppu::WeakImplHelper<css::container::XEnu
sal_Int32 m_nCurInd;
public:
- explicit ComEnumerationWrapper(const css::uno::Reference<css::script::XInvocation>& xInvocation)
- : m_xInvocation(xInvocation)
+ explicit ComEnumerationWrapper(css::uno::Reference<css::script::XInvocation> xInvocation)
+ : m_xInvocation(std::move(xInvocation))
, m_nCurInd(0)
{
}
diff --git a/basic/source/runtime/ddectrl.cxx b/basic/source/runtime/ddectrl.cxx
index bb2c4c5548f1..41e5c53d84de 100644
--- a/basic/source/runtime/ddectrl.cxx
+++ b/basic/source/runtime/ddectrl.cxx
@@ -17,7 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
-#include <vcl/errcode.hxx>
+#include <comphelper/errcode.hxx>
#include <svl/svdde.hxx>
#include "ddectrl.hxx"
#include <basic/sberrors.hxx>
diff --git a/basic/source/runtime/ddectrl.hxx b/basic/source/runtime/ddectrl.hxx
index 3b4f3d9bb122..d341bbcb8e72 100644
--- a/basic/source/runtime/ddectrl.hxx
+++ b/basic/source/runtime/ddectrl.hxx
@@ -20,7 +20,7 @@
#pragma once
#include <tools/link.hxx>
-#include <vcl/errcode.hxx>
+#include <comphelper/errcode.hxx>
#include <memory>
#include <vector>
diff --git a/basic/source/runtime/dllmgr-none.cxx b/basic/source/runtime/dllmgr-none.cxx
index 30070977d215..2a03e2ae7855 100644
--- a/basic/source/runtime/dllmgr-none.cxx
+++ b/basic/source/runtime/dllmgr-none.cxx
@@ -50,27 +50,26 @@ ErrCode returnInt64InOutArg(SbxArray *pArgs, SbxVariable &rRetVal,
pOut->PutCurrency(nValue);
return ERRCODE_NONE;
}
- if (pOut->IsObject())
- {
- // FIXME: should we clone this and use pOut->PutObject ?
- SbxObject* pObj = dynamic_cast<SbxObject*>( pOut->GetObject() );
- if (!pObj)
- return ERRCODE_BASIC_BAD_ARGUMENT;
-
- // We expect two Longs but other mappings could be possible too.
- SbxArray* pProps = pObj->GetProperties();
- if (pProps->Count() != 2)
- return ERRCODE_BASIC_BAD_ARGUMENT;
- SbxVariable* pLow = pProps->Get(0);
- SbxVariable* pHigh = pProps->Get(1);
- if (!pLow || !pLow->IsLong() ||
- !pHigh || !pHigh->IsLong())
- return ERRCODE_BASIC_BAD_ARGUMENT;
- pLow->PutLong(nValue & 0xffffffff);
- pHigh->PutLong(nValue >> 32);
- return ERRCODE_NONE;
- }
- return ERRCODE_BASIC_BAD_ARGUMENT;
+ if (!pOut->IsObject())
+ return ERRCODE_BASIC_BAD_ARGUMENT;
+
+ // FIXME: should we clone this and use pOut->PutObject ?
+ SbxObject* pObj = dynamic_cast<SbxObject*>( pOut->GetObject() );
+ if (!pObj)
+ return ERRCODE_BASIC_BAD_ARGUMENT;
+
+ // We expect two Longs but other mappings could be possible too.
+ SbxArray* pProps = pObj->GetProperties();
+ if (pProps->Count() != 2)
+ return ERRCODE_BASIC_BAD_ARGUMENT;
+ SbxVariable* pLow = pProps->Get(0);
+ SbxVariable* pHigh = pProps->Get(1);
+ if (!pLow || !pLow->IsLong() ||
+ !pHigh || !pHigh->IsLong())
+ return ERRCODE_BASIC_BAD_ARGUMENT;
+ pLow->PutLong(nValue & 0xffffffff);
+ pHigh->PutLong(nValue >> 32);
+ return ERRCODE_NONE;
}
ErrCode builtin_kernel32(std::u16string_view aFuncName, SbxArray *pArgs,
@@ -107,6 +106,8 @@ void SbiDllMgr::FreeDll(SAL_UNUSED_PARAMETER OUString const &) {}
SbiDllMgr::SbiDllMgr() = default;
+#if defined(_WIN32)
SbiDllMgr::~SbiDllMgr() = default;
+#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/runtime/dllmgr-x64.cxx b/basic/source/runtime/dllmgr-x64.cxx
index dad4bea8794a..ec5f79c4ab3e 100644
--- a/basic/source/runtime/dllmgr-x64.cxx
+++ b/basic/source/runtime/dllmgr-x64.cxx
@@ -27,10 +27,12 @@
#include <algorithm>
#include <cstddef>
#include <map>
+#include <string_view>
#include <vector>
#include <basic/sbx.hxx>
#include <basic/sbxvar.hxx>
+#include <comphelper/string.hxx>
#include <runtime.hxx>
#include <osl/thread.h>
#include <osl/diagnose.h>
@@ -40,6 +42,7 @@
#include <sal/log.hxx>
#include <salhelper/simplereferenceobject.hxx>
#include <o3tl/char16_t2wchar_t.hxx>
+#include <o3tl/string_view.hxx>
#undef max
@@ -481,7 +484,7 @@ struct ProcData {
};
ErrCode call(
- OUString const & dll, ProcData const & proc, SbxArray * arguments,
+ std::u16string_view dll, ProcData const & proc, SbxArray * arguments,
SbxVariable & result)
{
if (arguments && arguments->Count() > 20)
@@ -495,7 +498,7 @@ ErrCode call(
// requires special handling in unmarshalString; other functions might
// require similar treatment, too:
bool special =
- dll.equalsIgnoreAsciiCase("KERNEL32.DLL") &&
+ o3tl::equalsIgnoreAsciiCase(dll, u"KERNEL32.DLL") &&
(proc.name == "GetLogicalDriveStringsA");
for (sal_uInt32 i = 1; i < (arguments == nullptr ? 0 : arguments->Count()); ++i)
{
@@ -512,8 +515,6 @@ ErrCode call(
// We fake all calls as being to a varargs function,
// as this means any floating-point argument among the first four
// ones will end up in a XMM register where the callee expects it.
- sal_Int32 (*proc_i)(double d, ...) = reinterpret_cast<sal_Int32 (*)(double, ...)>(proc.proc);
- double (*proc_d)(double d, ...) = reinterpret_cast<double (*)(double, ...)>(proc.proc);
sal_Int64 iRetVal = 0;
double dRetVal = 0.0;
@@ -527,55 +528,21 @@ ErrCode call(
case SbxBOOL:
case SbxBYTE:
{
- auto const st = stack.data();
- iRetVal =
- proc_i(*reinterpret_cast<double *>(st + 0),
- *reinterpret_cast<double *>(st + 1*8),
- *reinterpret_cast<double *>(st + 2*8),
- *reinterpret_cast<double *>(st + 3*8),
- *reinterpret_cast<sal_uInt64 *>(st + 4*8),
- *reinterpret_cast<sal_uInt64 *>(st + 5*8),
- *reinterpret_cast<sal_uInt64 *>(st + 6*8),
- *reinterpret_cast<sal_uInt64 *>(st + 7*8),
- *reinterpret_cast<sal_uInt64 *>(st + 8*8),
- *reinterpret_cast<sal_uInt64 *>(st + 9*8),
- *reinterpret_cast<sal_uInt64 *>(st + 10*8),
- *reinterpret_cast<sal_uInt64 *>(st + 11*8),
- *reinterpret_cast<sal_uInt64 *>(st + 12*8),
- *reinterpret_cast<sal_uInt64 *>(st + 13*8),
- *reinterpret_cast<sal_uInt64 *>(st + 14*8),
- *reinterpret_cast<sal_uInt64 *>(st + 15*8),
- *reinterpret_cast<sal_uInt64 *>(st + 16*8),
- *reinterpret_cast<sal_uInt64 *>(st + 17*8),
- *reinterpret_cast<sal_uInt64 *>(st + 18*8),
- *reinterpret_cast<sal_uInt64 *>(st + 19*8));
+ auto p = reinterpret_cast<sal_Int64 (*)(...)>(proc.proc);
+ auto const st = reinterpret_cast<double *>(stack.data());
+ iRetVal
+ = p(st[0], st[1], st[2], st[3], st[4], st[5], st[6], st[7], st[8], st[9], st[10],
+ st[11], st[12], st[13], st[14], st[15], st[16], st[17], st[18], st[19]);
break;
}
case SbxSINGLE:
case SbxDOUBLE:
{
- auto const st = stack.data();
- dRetVal =
- proc_d(*reinterpret_cast<double *>(st + 0),
- *reinterpret_cast<double *>(st + 1*8),
- *reinterpret_cast<double *>(st + 2*8),
- *reinterpret_cast<double *>(st + 3*8),
- *reinterpret_cast<sal_uInt64 *>(st + 4*8),
- *reinterpret_cast<sal_uInt64 *>(st + 5*8),
- *reinterpret_cast<sal_uInt64 *>(st + 6*8),
- *reinterpret_cast<sal_uInt64 *>(st + 7*8),
- *reinterpret_cast<sal_uInt64 *>(st + 8*8),
- *reinterpret_cast<sal_uInt64 *>(st + 9*8),
- *reinterpret_cast<sal_uInt64 *>(st + 10*8),
- *reinterpret_cast<sal_uInt64 *>(st + 11*8),
- *reinterpret_cast<sal_uInt64 *>(st + 12*8),
- *reinterpret_cast<sal_uInt64 *>(st + 13*8),
- *reinterpret_cast<sal_uInt64 *>(st + 14*8),
- *reinterpret_cast<sal_uInt64 *>(st + 15*8),
- *reinterpret_cast<sal_uInt64 *>(st + 16*8),
- *reinterpret_cast<sal_uInt64 *>(st + 17*8),
- *reinterpret_cast<sal_uInt64 *>(st + 18*8),
- *reinterpret_cast<sal_uInt64 *>(st + 19*8));
+ auto p = reinterpret_cast<double (*)(...)>(proc.proc);
+ auto const st = reinterpret_cast<double*>(stack.data());
+ dRetVal
+ = p(st[0], st[1], st[2], st[3], st[4], st[5], st[6], st[7], st[8], st[9], st[10],
+ st[11], st[12], st[13], st[14], st[15], st[16], st[17], st[18], st[19]);
break;
}
default:
@@ -644,7 +611,7 @@ ErrCode getProcData(HMODULE handle, OUString const & name, ProcData * proc)
{
assert(proc != nullptr);
if (name.getLength() != 0 && name[0] == '@') { //TODO: "@" vs. "#"???
- sal_Int32 n = name.copy(1).toInt32(); //TODO: handle bad input
+ sal_IntPtr n = o3tl::toInt32(name.subView(1)); //TODO: handle bad input
if (n <= 0 || n > 0xFFFF) {
return ERRCODE_BASIC_BAD_ARGUMENT; //TODO: more specific errcode?
}
diff --git a/basic/source/runtime/dllmgr-x86.cxx b/basic/source/runtime/dllmgr-x86.cxx
index 93e5c2bf533f..7ab84d7f8b56 100644
--- a/basic/source/runtime/dllmgr-x86.cxx
+++ b/basic/source/runtime/dllmgr-x86.cxx
@@ -31,6 +31,7 @@
#include <basic/sbx.hxx>
#include <basic/sbxvar.hxx>
+#include <comphelper/string.hxx>
#include "runtime.hxx"
#include <osl/thread.h>
#include <rtl/ref.hxx>
@@ -39,6 +40,7 @@
#include <sal/log.hxx>
#include <salhelper/simplereferenceobject.hxx>
#include <o3tl/char16_t2wchar_t.hxx>
+#include <o3tl/string_view.hxx>
#undef max
@@ -584,7 +586,7 @@ ErrCode getProcData(HMODULE handle, OUString const & name, ProcData * proc)
{
assert(proc != 0);
if ( !name.isEmpty() && name[0] == '@' ) { //TODO: "@" vs. "#"???
- sal_Int32 n = name.copy(1).toInt32(); //TODO: handle bad input
+ sal_Int32 n = o3tl::toInt32(name.subView(1)); //TODO: handle bad input
if (n <= 0 || n > 0xFFFF) {
return ERRCODE_BASIC_BAD_ARGUMENT; //TODO: more specific errcode?
}
diff --git a/basic/source/runtime/dllmgr.hxx b/basic/source/runtime/dllmgr.hxx
index 3f984c95105c..fe76cfb681b6 100644
--- a/basic/source/runtime/dllmgr.hxx
+++ b/basic/source/runtime/dllmgr.hxx
@@ -20,7 +20,7 @@
#pragma once
#include <sal/config.h>
-#include <vcl/errcode.hxx>
+#include <comphelper/errcode.hxx>
#include <memory>
class SbxArray;
@@ -33,7 +33,9 @@ public:
SbiDllMgr();
+#if defined(_WIN32)
~SbiDllMgr();
+#endif
ErrCode Call(
std::u16string_view function, std::u16string_view library,
@@ -42,7 +44,7 @@ public:
void FreeDll(OUString const & library);
private:
-#if defined(_WIN32) && !defined(_ARM64_)
+#if defined(_WIN32)
struct Impl;
std::unique_ptr< Impl > impl_;
diff --git a/basic/source/runtime/inputbox.cxx b/basic/source/runtime/inputbox.cxx
index 36d604298bad..5f55aceb98b3 100644
--- a/basic/source/runtime/inputbox.cxx
+++ b/basic/source/runtime/inputbox.cxx
@@ -19,9 +19,9 @@
#include <basic/sberrors.hxx>
#include <tools/lineend.hxx>
+#include <vcl/outdev.hxx>
#include <vcl/svapp.hxx>
#include <vcl/weld.hxx>
-#include <vcl/window.hxx>
#include <rtlproto.hxx>
#include <memory>
@@ -52,11 +52,11 @@ public:
SvRTLInputBox::SvRTLInputBox(weld::Window* pParent, const OUString& rPrompt,
const OUString& rTitle, const OUString& rDefault,
tools::Long nXTwips, tools::Long nYTwips)
- : GenericDialogController(pParent, "svt/ui/inputbox.ui", "InputBox")
- , m_xEdit(m_xBuilder->weld_entry("entry"))
- , m_xOk(m_xBuilder->weld_button("ok"))
- , m_xCancel(m_xBuilder->weld_button("cancel"))
- , m_xPromptText(m_xBuilder->weld_label("prompt"))
+ : GenericDialogController(pParent, u"svt/ui/inputbox.ui"_ustr, u"InputBox"_ustr)
+ , m_xEdit(m_xBuilder->weld_entry(u"entry"_ustr))
+ , m_xOk(m_xBuilder->weld_button(u"ok"_ustr))
+ , m_xCancel(m_xBuilder->weld_button(u"cancel"_ustr))
+ , m_xPromptText(m_xBuilder->weld_label(u"prompt"_ustr))
{
PositionDialog( nXTwips, nYTwips );
InitButtons();
@@ -118,7 +118,7 @@ void SbRtl_InputBox(StarBASIC *, SbxArray & rPar, bool)
OUString aTitle;
OUString aDefault;
sal_Int32 nX = -1, nY = -1; // center
- const OUString& rPrompt = rPar.Get(1)->GetOUString();
+ const OUString aPrompt = rPar.Get(1)->GetOUString();
if (nArgCount > 2 && !rPar.Get(2)->IsErr())
aTitle = rPar.Get(2)->GetOUString();
if (nArgCount > 3 && !rPar.Get(3)->IsErr())
@@ -133,7 +133,7 @@ void SbRtl_InputBox(StarBASIC *, SbxArray & rPar, bool)
nX = rPar.Get(4)->GetLong();
nY = rPar.Get(5)->GetLong();
}
- SvRTLInputBox aDlg(Application::GetDefDialogParent(), rPrompt, aTitle, aDefault, nX, nY);
+ SvRTLInputBox aDlg(Application::GetDefDialogParent(), aPrompt, aTitle, aDefault, nX, nY);
aDlg.run();
rPar.Get(0)->PutString(aDlg.GetText());
}
diff --git a/basic/source/runtime/iosys.cxx b/basic/source/runtime/iosys.cxx
index 43ee1c4d6856..a30f8e763aff 100644
--- a/basic/source/runtime/iosys.cxx
+++ b/basic/source/runtime/iosys.cxx
@@ -20,7 +20,7 @@
#include <string.h>
#include <vcl/svapp.hxx>
#include <vcl/weld.hxx>
-#include <vcl/window.hxx>
+#include <osl/diagnose.h>
#include <osl/file.hxx>
#include <runtime.hxx>
@@ -38,14 +38,12 @@
#include <com/sun/star/io/XOutputStream.hpp>
#include <com/sun/star/io/XStream.hpp>
#include <com/sun/star/io/XSeekable.hpp>
+#include <iosys.hxx>
using namespace com::sun::star::uno;
-using namespace com::sun::star::lang;
using namespace com::sun::star::ucb;
using namespace com::sun::star::io;
-using namespace com::sun::star::bridge;
-#include <iosys.hxx>
namespace {
@@ -66,11 +64,11 @@ public:
}
SbiInputDialog::SbiInputDialog(weld::Window* pParent, const OUString& rPrompt)
- : GenericDialogController(pParent, "svt/ui/inputbox.ui", "InputBox")
- , m_xInput(m_xBuilder->weld_entry("entry"))
- , m_xOk(m_xBuilder->weld_button("ok"))
- , m_xCancel(m_xBuilder->weld_button("cancel"))
- , m_xPromptText(m_xBuilder->weld_label("prompt"))
+ : GenericDialogController(pParent, u"svt/ui/inputbox.ui"_ustr, u"InputBox"_ustr)
+ , m_xInput(m_xBuilder->weld_entry(u"entry"_ustr))
+ , m_xOk(m_xBuilder->weld_button(u"ok"_ustr))
+ , m_xCancel(m_xBuilder->weld_button(u"cancel"_ustr))
+ , m_xPromptText(m_xBuilder->weld_label(u"prompt"_ustr))
{
m_xDialog->set_title(rPrompt);
m_xPromptText->set_label(rPrompt);
@@ -134,7 +132,7 @@ void SbiStream::MapError()
bool hasUno()
{
static const bool bRetVal = [] {
- Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
+ const Reference< XComponentContext >& xContext = comphelper::getProcessComponentContext();
if( !xContext.is() )
{
// No service manager at all
@@ -144,7 +142,7 @@ bool hasUno()
{
Reference< XUniversalContentBroker > xManager = UniversalContentBroker::create(xContext);
- if ( !( xManager->queryContentProvider( "file:///" ).is() ) )
+ if ( !( xManager->queryContentProvider( u"file:///"_ustr ).is() ) )
{
// No UCB
return false;
@@ -417,7 +415,7 @@ void UCBStream::SetSize( sal_uInt64 )
ErrCode const & SbiStream::Open
-( std::string_view rName, StreamMode nStrmMode, SbiStreamFlags nFlags, short nL )
+( const OUString& rName, StreamMode nStrmMode, SbiStreamFlags nFlags, short nL )
{
nMode = nFlags;
nLen = nL;
@@ -427,8 +425,7 @@ ErrCode const & SbiStream::Open
{
nStrmMode |= StreamMode::NOCREATE;
}
- OUString aStr(OStringToOUString(rName, osl_getThreadTextEncoding()));
- OUString aNameStr = getFullPath( aStr );
+ OUString aNameStr = getFullPath(rName);
if( hasUno() )
{
@@ -563,7 +560,7 @@ namespace
void WriteLines(SvStream &rStream, const OString& rStr)
{
OString aStr(convertLineEnd(rStr, rStream.GetLineDelimiter()) );
- write_uInt8s_FromOString(rStream, aStr);
+ rStream.WriteBytes(aStr.getStr(), aStr.getLength());
endl( rStream );
}
}
@@ -627,7 +624,7 @@ ErrCode SbiIoSystem::GetError()
return n;
}
-void SbiIoSystem::Open(short nCh, std::string_view rName, StreamMode nMode, SbiStreamFlags nFlags, short nLen)
+void SbiIoSystem::Open(short nCh, const OUString& rName, StreamMode nMode, SbiStreamFlags nFlags, short nLen)
{
nError = ERRCODE_NONE;
if( nCh >= CHANNELS || !nCh )
@@ -786,8 +783,7 @@ void SbiIoSystem::CloseAll()
void SbiIoSystem::ReadCon(OString& rIn)
{
- OUString aPromptStr(OStringToOUString(aPrompt, osl_getThreadTextEncoding()));
- SbiInputDialog aDlg(nullptr, aPromptStr);
+ SbiInputDialog aDlg(nullptr, aPrompt);
if (aDlg.run() == RET_OK)
{
rIn = OUStringToOString(aDlg.GetInput(), osl_getThreadTextEncoding());
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index 7e9a1adcccd7..679414e10a14 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -24,11 +24,10 @@
#include <basic/sbuno.hxx>
#include <osl/process.h>
#include <vcl/dibtools.hxx>
-#include <vcl/window.hxx>
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
#include <vcl/sound.hxx>
-#include <tools/wintypes.hxx>
+#include <vcl/wintypes.hxx>
#include <vcl/stdtext.hxx>
#include <vcl/weld.hxx>
#include <basic/sbx.hxx>
@@ -45,6 +44,7 @@
#include <rtl/string.hxx>
#include <sal/log.hxx>
#include <comphelper/DirectoryHelper.hxx>
+#include <comphelper/lok.hxx>
#include <runtime.hxx>
#include <sbunoobj.hxx>
@@ -60,6 +60,7 @@
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/ucb/SimpleFileAccess.hpp>
#include <com/sun/star/script/XErrorQuery.hpp>
+#include <ooo/vba/VbStrConv.hpp>
#include <ooo/vba/VbTriState.hpp>
#include <com/sun/star/bridge/oleautomation/XAutomationObject.hpp>
#include <memory>
@@ -68,20 +69,12 @@
#include <o3tl/char16_t2wchar_t.hxx>
// include search util
-#include <com/sun/star/util/SearchFlags.hpp>
+#include <com/sun/star/i18n/Transliteration.hpp>
#include <com/sun/star/util/SearchAlgorithms2.hpp>
#include <i18nutil/searchopt.hxx>
#include <unotools/textsearch.hxx>
#include <svl/numformat.hxx>
-
-
-using namespace comphelper;
-using namespace osl;
-using namespace com::sun::star;
-using namespace com::sun::star::lang;
-using namespace com::sun::star::uno;
-
#include <date.hxx>
#include <sbstdobj.hxx>
#include <rtlproto.hxx>
@@ -109,12 +102,24 @@ using namespace com::sun::star::uno;
#include <unistd.h>
#endif
-#include <com/sun/star/i18n/XCharacterClassification.hpp>
-#include <vcl/unohelp.hxx>
#include <vcl/TypeSerializer.hxx>
+using namespace comphelper;
+using namespace osl;
+using namespace com::sun::star;
+using namespace com::sun::star::lang;
+using namespace com::sun::star::uno;
+
+static sal_Int32 GetDayDiff(const Date& rDate) { return rDate - Date(1899'12'30); }
+
#if HAVE_FEATURE_SCRIPTING
+static sal_Int32 nanoSecToMilliSec(sal_Int64 nNanoSeconds)
+{
+ // Rounding nanoseconds to milliseconds precision to avoid comparison inaccuracies
+ return o3tl::convert(nNanoSeconds, 1, tools::Time::nanoPerMilli);
+}
+
static void FilterWhiteSpace( OUString& rStr )
{
if (rStr.isEmpty())
@@ -136,8 +141,6 @@ static void FilterWhiteSpace( OUString& rStr )
rStr = aRet.makeStringAndClear();
}
-static tools::Long GetDayDiff( const Date& rDate );
-
static const CharClass& GetCharClass()
{
static CharClass aCharClass( Application::GetSettings().GetLanguageTag() );
@@ -185,16 +188,17 @@ static uno::Reference< ucb::XSimpleFileAccess3 > const & getFileAccess()
void SbRtl_CreateObject(StarBASIC * pBasic, SbxArray & rPar, bool)
{
+ if( rPar.Count() < 2 )
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
OUString aClass(rPar.Get(1)->GetOUString());
SbxObjectRef p = SbxBase::CreateObject( aClass );
if( !p.is() )
- StarBASIC::Error( ERRCODE_BASIC_CANNOT_LOAD );
- else
- {
- // Convenience: enter BASIC as parent
- p->SetParent( pBasic );
- rPar.Get(0)->PutObject(p.get());
- }
+ return StarBASIC::Error( ERRCODE_BASIC_CANNOT_LOAD );
+
+ // Convenience: enter BASIC as parent
+ p->SetParent( pBasic );
+ rPar.Get(0)->PutObject(p.get());
}
// Error( n )
@@ -202,54 +206,51 @@ void SbRtl_CreateObject(StarBASIC * pBasic, SbxArray & rPar, bool)
void SbRtl_Error(StarBASIC * pBasic, SbxArray & rPar, bool)
{
if( !pBasic )
- StarBASIC::Error( ERRCODE_BASIC_INTERNAL_ERROR );
+ return StarBASIC::Error( ERRCODE_BASIC_INTERNAL_ERROR );
+
+ OUString aErrorMsg;
+ ErrCode nErr = ERRCODE_NONE;
+ sal_Int32 nCode = 0;
+ if (rPar.Count() == 1)
+ {
+ nErr = StarBASIC::GetErrBasic();
+ aErrorMsg = StarBASIC::GetErrorMsg();
+ }
else
{
- OUString aErrorMsg;
- ErrCode nErr = ERRCODE_NONE;
- sal_Int32 nCode = 0;
- if (rPar.Count() == 1)
+ nCode = rPar.Get(1)->GetLong();
+ if( nCode > 65535 )
{
- nErr = StarBASIC::GetErrBasic();
- aErrorMsg = StarBASIC::GetErrorMsg();
- }
- else
- {
- nCode = rPar.Get(1)->GetLong();
- if( nCode > 65535 )
- {
- StarBASIC::Error( ERRCODE_BASIC_CONVERSION );
- }
- else
- {
- nErr = StarBASIC::GetSfxFromVBError( static_cast<sal_uInt16>(nCode) );
- }
- }
-
- bool bVBA = SbiRuntime::isVBAEnabled();
- OUString tmpErrMsg;
- if( bVBA && !aErrorMsg.isEmpty())
- {
- tmpErrMsg = aErrorMsg;
+ StarBASIC::Error( ERRCODE_BASIC_CONVERSION );
}
else
{
- StarBASIC::MakeErrorText( nErr, aErrorMsg );
- tmpErrMsg = StarBASIC::GetErrorText();
+ nErr = StarBASIC::GetSfxFromVBError( static_cast<sal_uInt16>(nCode) );
}
- // If this rtlfunc 'Error' passed an errcode the same as the active Err Objects's
- // current err then return the description for the error message if it is set
- // ( complicated isn't it ? )
- if (bVBA && rPar.Count() > 1)
+ }
+ bool bVBA = SbiRuntime::isVBAEnabled();
+ OUString tmpErrMsg;
+ if( bVBA && !aErrorMsg.isEmpty())
+ {
+ tmpErrMsg = aErrorMsg;
+ }
+ else
+ {
+ StarBASIC::MakeErrorText( nErr, aErrorMsg );
+ tmpErrMsg = StarBASIC::GetErrorText();
+ }
+ // If this rtlfunc 'Error' passed an errcode the same as the active Err Objects's
+ // current err then return the description for the error message if it is set
+ // ( complicated isn't it ? )
+ if (bVBA && rPar.Count() > 1)
+ {
+ uno::Reference< ooo::vba::XErrObject > xErrObj( SbxErrObject::getUnoErrObject() );
+ if ( xErrObj.is() && xErrObj->getNumber() == nCode && !xErrObj->getDescription().isEmpty() )
{
- uno::Reference< ooo::vba::XErrObject > xErrObj( SbxErrObject::getUnoErrObject() );
- if ( xErrObj.is() && xErrObj->getNumber() == nCode && !xErrObj->getDescription().isEmpty() )
- {
- tmpErrMsg = xErrObj->getDescription();
- }
+ tmpErrMsg = xErrObj->getDescription();
}
- rPar.Get(0)->PutString(tmpErrMsg);
}
+ rPar.Get(0)->PutString(tmpErrMsg);
}
// Sinus
@@ -257,106 +258,87 @@ void SbRtl_Error(StarBASIC * pBasic, SbxArray & rPar, bool)
void SbRtl_Sin(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- else
- {
- SbxVariableRef pArg = rPar.Get(1);
- rPar.Get(0)->PutDouble(sin(pArg->GetDouble()));
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ SbxVariableRef pArg = rPar.Get(1);
+ rPar.Get(0)->PutDouble(sin(pArg->GetDouble()));
}
void SbRtl_Cos(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- else
- {
- SbxVariableRef pArg = rPar.Get(1);
- rPar.Get(0)->PutDouble(cos(pArg->GetDouble()));
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ SbxVariableRef pArg = rPar.Get(1);
+ rPar.Get(0)->PutDouble(cos(pArg->GetDouble()));
}
void SbRtl_Atn(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- else
- {
- SbxVariableRef pArg = rPar.Get(1);
- rPar.Get(0)->PutDouble(atan(pArg->GetDouble()));
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ SbxVariableRef pArg = rPar.Get(1);
+ rPar.Get(0)->PutDouble(atan(pArg->GetDouble()));
}
void SbRtl_Abs(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- SbxVariableRef pArg = rPar.Get(1);
- rPar.Get(0)->PutDouble(fabs(pArg->GetDouble()));
- }
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ SbxVariableRef pArg = rPar.Get(1);
+ rPar.Get(0)->PutDouble(fabs(pArg->GetDouble()));
}
void SbRtl_Asc(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ SbxVariableRef pArg = rPar.Get(1);
+ OUString aStr( pArg->GetOUString() );
+ if ( aStr.isEmpty())
{
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ rPar.Get(0)->PutEmpty();
+ return;
}
- else
- {
- SbxVariableRef pArg = rPar.Get(1);
- OUString aStr( pArg->GetOUString() );
- if ( aStr.isEmpty())
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- rPar.Get(0)->PutEmpty();
- }
- else
- {
- sal_Unicode aCh = aStr[0];
- rPar.Get(0)->PutLong(aCh);
- }
- }
+ sal_Unicode aCh = aStr[0];
+ rPar.Get(0)->PutLong(aCh);
}
static void implChr( SbxArray& rPar, bool bChrW )
{
if (rPar.Count() < 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ SbxVariableRef pArg = rPar.Get(1);
+
+ OUString aStr;
+ if( !bChrW && SbiRuntime::isVBAEnabled() )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ char c = static_cast<char>(pArg->GetByte());
+ aStr = OUString(&c, 1, osl_getThreadTextEncoding());
}
else
{
- SbxVariableRef pArg = rPar.Get(1);
-
- OUString aStr;
- if( !bChrW && SbiRuntime::isVBAEnabled() )
- {
- char c = static_cast<char>(pArg->GetByte());
- aStr = OUString(&c, 1, osl_getThreadTextEncoding());
- }
- else
+ // Map negative 16-bit values to large positive ones, so that code like Chr(&H8000)
+ // still works after the fix for tdf#62326 changed those four-digit hex notations to
+ // produce negative values:
+ sal_Int32 aCh = pArg->GetLong();
+ if (aCh < -0x8000 || aCh > 0xFFFF)
{
- // Map negative 16-bit values to large positive ones, so that code like Chr(&H8000)
- // still works after the fix for tdf#62326 changed those four-digit hex notations to
- // produce negative values:
- sal_Int32 aCh = pArg->GetLong();
- if (aCh < -0x8000 || aCh > 0xFFFF) {
- StarBASIC::Error(ERRCODE_BASIC_MATH_OVERFLOW);
- aCh = 0;
- }
- aStr = OUString(static_cast<sal_Unicode>(aCh));
+ StarBASIC::Error(ERRCODE_BASIC_MATH_OVERFLOW);
+ aCh = 0;
}
- rPar.Get(0)->PutString(aStr);
+ aStr = OUString(static_cast<sal_Unicode>(aCh));
}
+ rPar.Get(0)->PutString(aStr);
}
void SbRtl_Chr(StarBASIC *, SbxArray & rPar, bool)
@@ -396,22 +378,21 @@ void SbRtl_CurDir(StarBASIC *, SbxArray & rPar, bool)
// there's no possibility to detect the current one in a way that a virtual URL
// could be delivered.
+ if (rPar.Count() > 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
#if defined(_WIN32)
int nCurDir = 0; // Current dir // JSM
if (rPar.Count() == 2)
{
OUString aDrive = rPar.Get(1)->GetOUString();
if ( aDrive.getLength() != 1 )
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
auto c = rtl::toAsciiUpperCase(aDrive[0]);
if ( !rtl::isAsciiUpperCase( c ) )
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
nCurDir = c - 'A' + 1;
}
wchar_t pBuffer[ _MAX_PATH ];
@@ -421,14 +402,10 @@ void SbRtl_CurDir(StarBASIC *, SbxArray & rPar, bool)
auto const handler = _set_thread_local_invalid_parameter_handler(&invalidParameterHandler);
auto const ok = _wgetdcwd( nCurDir, pBuffer, _MAX_PATH ) != nullptr;
_set_thread_local_invalid_parameter_handler(handler);
- if ( ok )
- {
- rPar.Get(0)->PutString(OUString(o3tl::toU(pBuffer)));
- }
- else
- {
- StarBASIC::Error( ERRCODE_BASIC_NO_DEVICE );
- }
+ if ( !ok )
+ return StarBASIC::Error( ERRCODE_BASIC_NO_DEVICE );
+
+ rPar.Get(0)->PutString(OUString(o3tl::toU(pBuffer)));
#else
@@ -440,20 +417,16 @@ void SbRtl_CurDir(StarBASIC *, SbxArray & rPar, bool)
{
pMem.reset(new char[nSize]);
if( !pMem )
- {
- StarBASIC::Error( ERRCODE_BASIC_NO_MEMORY );
- return;
- }
+ return StarBASIC::Error( ERRCODE_BASIC_NO_MEMORY );
+
if( getcwd( pMem.get(), nSize-1 ) != nullptr )
{
rPar.Get(0)->PutString(OUString::createFromAscii(pMem.get()));
return;
}
if( errno != ERANGE )
- {
- StarBASIC::Error( ERRCODE_BASIC_INTERNAL_ERROR );
- return;
- }
+ return StarBASIC::Error( ERRCODE_BASIC_INTERNAL_ERROR );
+
nSize += PATH_INCR;
};
@@ -463,18 +436,14 @@ void SbRtl_CurDir(StarBASIC *, SbxArray & rPar, bool)
void SbRtl_ChDir(StarBASIC * pBasic, SbxArray & rPar, bool)
{
rPar.Get(0)->PutEmpty();
- if (rPar.Count() == 2)
- {
- // VBA: track current directory per document type (separately for Writer, Calc, Impress, etc.)
- if( SbiRuntime::isVBAEnabled() )
- {
- ::basic::vba::registerCurrentDirectory(getDocumentModel(pBasic),
- rPar.Get(1)->GetOUString());
- }
- }
- else
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ // VBA: track current directory per document type (separately for Writer, Calc, Impress, etc.)
+ if( SbiRuntime::isVBAEnabled() )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ ::basic::vba::registerCurrentDirectory(getDocumentModel(pBasic),
+ rPar.Get(1)->GetOUString());
}
}
@@ -482,9 +451,7 @@ void SbRtl_ChDrive(StarBASIC *, SbxArray & rPar, bool)
{
rPar.Get(0)->PutEmpty();
if (rPar.Count() != 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
@@ -533,129 +500,119 @@ void implStepRenameOSL( const OUString& aSource, const OUString& aDest )
void SbRtl_FileCopy(StarBASIC *, SbxArray & rPar, bool)
{
rPar.Get(0)->PutEmpty();
- if (rPar.Count() == 3)
+ if (rPar.Count() != 3)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ OUString aSource = rPar.Get(1)->GetOUString();
+ OUString aDest = rPar.Get(2)->GetOUString();
+ if( hasUno() )
{
- OUString aSource = rPar.Get(1)->GetOUString();
- OUString aDest = rPar.Get(2)->GetOUString();
- if( hasUno() )
+ const uno::Reference< ucb::XSimpleFileAccess3 >& xSFI = getFileAccess();
+ if( xSFI.is() )
{
- const uno::Reference< ucb::XSimpleFileAccess3 >& xSFI = getFileAccess();
- if( xSFI.is() )
+ try
{
- try
- {
- xSFI->copy( getFullPath( aSource ), getFullPath( aDest ) );
- }
- catch(const Exception & )
- {
- StarBASIC::Error( ERRCODE_BASIC_PATH_NOT_FOUND );
- }
+ xSFI->copy( getFullPath( aSource ), getFullPath( aDest ) );
}
- }
- else
- {
- FileBase::RC nRet = File::copy( getFullPath( aSource ), getFullPath( aDest ) );
- if( nRet != FileBase::E_None )
+ catch(const Exception & )
{
StarBASIC::Error( ERRCODE_BASIC_PATH_NOT_FOUND );
}
}
}
else
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ {
+ FileBase::RC nRet = File::copy( getFullPath( aSource ), getFullPath( aDest ) );
+ if( nRet != FileBase::E_None )
+ {
+ StarBASIC::Error( ERRCODE_BASIC_PATH_NOT_FOUND );
+ }
+ }
}
void SbRtl_Kill(StarBASIC *, SbxArray & rPar, bool)
{
rPar.Get(0)->PutEmpty();
- if (rPar.Count() == 2)
- {
- OUString aFileSpec = rPar.Get(1)->GetOUString();
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- if( hasUno() )
+ OUString aFileSpec = rPar.Get(1)->GetOUString();
+
+ if( hasUno() )
+ {
+ const uno::Reference< ucb::XSimpleFileAccess3 >& xSFI = getFileAccess();
+ if( xSFI.is() )
{
- const uno::Reference< ucb::XSimpleFileAccess3 >& xSFI = getFileAccess();
- if( xSFI.is() )
+ OUString aFullPath = getFullPath( aFileSpec );
+ if( !xSFI->exists( aFullPath ) || xSFI->isFolder( aFullPath ) )
{
- OUString aFullPath = getFullPath( aFileSpec );
- if( !xSFI->exists( aFullPath ) || xSFI->isFolder( aFullPath ) )
- {
- StarBASIC::Error( ERRCODE_BASIC_FILE_NOT_FOUND );
- return;
- }
- try
- {
- xSFI->kill( aFullPath );
- }
- catch(const Exception & )
- {
- StarBASIC::Error( ERRCODE_IO_GENERAL );
- }
+ StarBASIC::Error( ERRCODE_BASIC_FILE_NOT_FOUND );
+ return;
+ }
+ try
+ {
+ xSFI->kill( aFullPath );
+ }
+ catch(const Exception & )
+ {
+ StarBASIC::Error( ERRCODE_IO_GENERAL );
}
- }
- else
- {
- File::remove( getFullPath( aFileSpec ) );
}
}
else
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ File::remove( getFullPath( aFileSpec ) );
}
}
void SbRtl_MkDir(StarBASIC * pBasic, SbxArray & rPar, bool bWrite)
{
rPar.Get(0)->PutEmpty();
- if (rPar.Count() == 2)
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ OUString aPath = rPar.Get(1)->GetOUString();
+ if ( SbiRuntime::isVBAEnabled() )
{
- OUString aPath = rPar.Get(1)->GetOUString();
- if ( SbiRuntime::isVBAEnabled() )
+ // In vba if the full path is not specified then
+ // folder is created relative to the curdir
+ INetURLObject aURLObj( getFullPath( aPath ) );
+ if ( aURLObj.GetProtocol() != INetProtocol::File )
{
- // In vba if the full path is not specified then
- // folder is created relative to the curdir
- INetURLObject aURLObj( getFullPath( aPath ) );
- if ( aURLObj.GetProtocol() != INetProtocol::File )
- {
- SbxArrayRef pPar = new SbxArray();
- SbxVariableRef pResult = new SbxVariable();
- SbxVariableRef pParam = new SbxVariable();
- pPar->Insert(pResult.get(), pPar->Count());
- pPar->Insert(pParam.get(), pPar->Count());
- SbRtl_CurDir( pBasic, *pPar, bWrite );
-
- OUString sCurPathURL;
- File::getFileURLFromSystemPath(pPar->Get(0)->GetOUString(), sCurPathURL);
-
- aURLObj.SetURL( sCurPathURL );
- aURLObj.Append( aPath );
- File::getSystemPathFromFileURL(aURLObj.GetMainURL( INetURLObject::DecodeMechanism::ToIUri ),aPath ) ;
- }
+ SbxArrayRef pPar = new SbxArray();
+ SbxVariableRef pResult = new SbxVariable();
+ SbxVariableRef pParam = new SbxVariable();
+ pPar->Insert(pResult.get(), pPar->Count());
+ pPar->Insert(pParam.get(), pPar->Count());
+ SbRtl_CurDir( pBasic, *pPar, bWrite );
+
+ OUString sCurPathURL;
+ File::getFileURLFromSystemPath(pPar->Get(0)->GetOUString(), sCurPathURL);
+
+ aURLObj.SetURL( sCurPathURL );
+ aURLObj.Append( aPath );
+ File::getSystemPathFromFileURL(aURLObj.GetMainURL( INetURLObject::DecodeMechanism::ToIUri ),aPath ) ;
}
+ }
- if( hasUno() )
+ if( hasUno() )
+ {
+ const uno::Reference< ucb::XSimpleFileAccess3 >& xSFI = getFileAccess();
+ if( xSFI.is() )
{
- const uno::Reference< ucb::XSimpleFileAccess3 >& xSFI = getFileAccess();
- if( xSFI.is() )
+ try
{
- try
- {
- xSFI->createFolder( getFullPath( aPath ) );
- }
- catch(const Exception & )
- {
- StarBASIC::Error( ERRCODE_IO_GENERAL );
- }
+ xSFI->createFolder( getFullPath( aPath ) );
+ }
+ catch(const Exception & )
+ {
+ StarBASIC::Error( ERRCODE_IO_GENERAL );
}
- }
- else
- {
- Directory::create( getFullPath( aPath ) );
}
}
else
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ Directory::create( getFullPath( aPath ) );
}
}
@@ -673,16 +630,14 @@ static void implRemoveDirRecursive( const OUString& aDirPath )
if( !bExists || !bFolder )
{
- StarBASIC::Error( ERRCODE_BASIC_PATH_NOT_FOUND );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_PATH_NOT_FOUND );
}
Directory aDir( aDirPath );
nRet = aDir.open();
if( nRet != FileBase::E_None )
{
- StarBASIC::Error( ERRCODE_BASIC_PATH_NOT_FOUND );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_PATH_NOT_FOUND );
}
aDir.close();
@@ -693,49 +648,43 @@ static void implRemoveDirRecursive( const OUString& aDirPath )
void SbRtl_RmDir(StarBASIC *, SbxArray & rPar, bool)
{
rPar.Get(0)->PutEmpty();
- if (rPar.Count() == 2)
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ OUString aPath = rPar.Get(1)->GetOUString();
+ if( hasUno() )
{
- OUString aPath = rPar.Get(1)->GetOUString();
- if( hasUno() )
+ const uno::Reference< ucb::XSimpleFileAccess3 >& xSFI = getFileAccess();
+ if( xSFI.is() )
{
- const uno::Reference< ucb::XSimpleFileAccess3 >& xSFI = getFileAccess();
- if( xSFI.is() )
+ try
{
- try
+ if( !xSFI->isFolder( aPath ) )
{
- if( !xSFI->isFolder( aPath ) )
- {
- StarBASIC::Error( ERRCODE_BASIC_PATH_NOT_FOUND );
- return;
- }
- SbiInstance* pInst = GetSbData()->pInst;
- bool bCompatibility = ( pInst && pInst->IsCompatibility() );
- if( bCompatibility )
- {
- Sequence< OUString > aContent = xSFI->getFolderContents( aPath, true );
- if( aContent.hasElements() )
- {
- StarBASIC::Error( ERRCODE_BASIC_ACCESS_ERROR );
- return;
- }
- }
-
- xSFI->kill( getFullPath( aPath ) );
+ return StarBASIC::Error( ERRCODE_BASIC_PATH_NOT_FOUND );
}
- catch(const Exception & )
+ SbiInstance* pInst = GetSbData()->pInst;
+ bool bCompatibility = ( pInst && pInst->IsCompatibility() );
+ if( bCompatibility )
{
- StarBASIC::Error( ERRCODE_IO_GENERAL );
+ Sequence< OUString > aContent = xSFI->getFolderContents( aPath, true );
+ if( aContent.hasElements() )
+ {
+ return StarBASIC::Error( ERRCODE_BASIC_ACCESS_ERROR );
+ }
}
+
+ xSFI->kill( getFullPath( aPath ) );
+ }
+ catch(const Exception & )
+ {
+ StarBASIC::Error( ERRCODE_IO_GENERAL );
}
- }
- else
- {
- implRemoveDirRecursive( getFullPath( aPath ) );
}
}
else
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ implRemoveDirRecursive( getFullPath( aPath ) );
}
}
@@ -748,91 +697,79 @@ void SbRtl_SendKeys(StarBASIC *, SbxArray & rPar, bool)
void SbRtl_Exp(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- else
- {
- double aDouble = rPar.Get(1)->GetDouble();
- aDouble = exp( aDouble );
- checkArithmeticOverflow( aDouble );
- rPar.Get(0)->PutDouble(aDouble);
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ double aDouble = rPar.Get(1)->GetDouble();
+ aDouble = exp( aDouble );
+ checkArithmeticOverflow( aDouble );
+ rPar.Get(0)->PutDouble(aDouble);
}
void SbRtl_FileLen(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
- else
+
+ SbxVariableRef pArg = rPar.Get(1);
+ OUString aStr( pArg->GetOUString() );
+ sal_Int32 nLen = 0;
+ if( hasUno() )
{
- SbxVariableRef pArg = rPar.Get(1);
- OUString aStr( pArg->GetOUString() );
- sal_Int32 nLen = 0;
- if( hasUno() )
+ const uno::Reference< ucb::XSimpleFileAccess3 >& xSFI = getFileAccess();
+ if( xSFI.is() )
{
- const uno::Reference< ucb::XSimpleFileAccess3 >& xSFI = getFileAccess();
- if( xSFI.is() )
+ try
{
- try
- {
- nLen = xSFI->getSize( getFullPath( aStr ) );
- }
- catch(const Exception & )
- {
- StarBASIC::Error( ERRCODE_IO_GENERAL );
- }
+ nLen = xSFI->getSize( getFullPath( aStr ) );
+ }
+ catch(const Exception & )
+ {
+ StarBASIC::Error( ERRCODE_IO_GENERAL );
}
}
- else
- {
- DirectoryItem aItem;
- (void)DirectoryItem::get( getFullPath( aStr ), aItem );
- FileStatus aFileStatus( osl_FileStatus_Mask_FileSize );
- (void)aItem.getFileStatus( aFileStatus );
- nLen = static_cast<sal_Int32>(aFileStatus.getFileSize());
- }
- rPar.Get(0)->PutLong(static_cast<tools::Long>(nLen));
}
+ else
+ {
+ DirectoryItem aItem;
+ (void)DirectoryItem::get( getFullPath( aStr ), aItem );
+ FileStatus aFileStatus( osl_FileStatus_Mask_FileSize );
+ (void)aItem.getFileStatus( aFileStatus );
+ nLen = static_cast<sal_Int32>(aFileStatus.getFileSize());
+ }
+ rPar.Get(0)->PutLong(nLen);
}
+
void SbRtl_Hex(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- SbxVariableRef pArg = rPar.Get(1);
- // converting value to unsigned and limit to 2 or 4 byte representation
- sal_uInt32 nVal = pArg->IsInteger() ?
- static_cast<sal_uInt16>(pArg->GetInteger()) :
- static_cast<sal_uInt32>(pArg->GetLong());
- OUString aStr(OUString::number( nVal, 16 ));
- aStr = aStr.toAsciiUpperCase();
- rPar.Get(0)->PutString(aStr);
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
+
+ SbxVariableRef pArg = rPar.Get(1);
+ // converting value to unsigned and limit to 2 or 4 byte representation
+ sal_uInt32 nVal = pArg->IsInteger() ?
+ static_cast<sal_uInt16>(pArg->GetInteger()) :
+ static_cast<sal_uInt32>(pArg->GetLong());
+ rPar.Get(0)->PutString(OUString::number(nVal, 16).toAsciiUpperCase());
}
void SbRtl_FuncCaller(StarBASIC *, SbxArray & rPar, bool)
{
- if ( SbiRuntime::isVBAEnabled() && GetSbData()->pInst && GetSbData()->pInst->pRun )
- {
- if ( GetSbData()->pInst->pRun->GetExternalCaller() )
- *rPar.Get(0) = *GetSbData()->pInst->pRun->GetExternalCaller();
- else
- {
- SbxVariableRef pVar = new SbxVariable(SbxVARIANT);
- *rPar.Get(0) = *pVar;
- }
- }
+ if (!SbiRuntime::isVBAEnabled() || GetSbData()->pInst == nullptr || GetSbData()->pInst->pRun == nullptr)
+ return StarBASIC::Error(ERRCODE_BASIC_NOT_IMPLEMENTED);
+
+ if ( GetSbData()->pInst->pRun->GetExternalCaller() )
+ *rPar.Get(0) = *GetSbData()->pInst->pRun->GetExternalCaller();
else
{
- StarBASIC::Error( ERRCODE_BASIC_NOT_IMPLEMENTED );
+ SbxVariableRef pVar = new SbxVariable(SbxVARIANT);
+ *rPar.Get(0) = *pVar;
}
-
}
// InStr( [start],string,string,[compare] )
@@ -840,79 +777,77 @@ void SbRtl_InStr(StarBASIC *, SbxArray & rPar, bool)
{
const sal_uInt32 nArgCount = rPar.Count() - 1;
if ( nArgCount < 2 )
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- else
- {
- sal_Int32 nStartPos = 1;
- sal_Int32 nFirstStringPos = 1;
+ return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
- if ( nArgCount >= 3 )
- {
- nStartPos = rPar.Get(1)->GetLong();
- if( nStartPos <= 0 )
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- nStartPos = 1;
- }
- nFirstStringPos++;
- }
+ sal_Int32 nStartPos = 1;
+ sal_Int32 nFirstStringPos = 1;
- SbiInstance* pInst = GetSbData()->pInst;
- bool bTextMode;
- bool bCompatibility = ( pInst && pInst->IsCompatibility() );
- if( bCompatibility )
- {
- SbiRuntime* pRT = pInst->pRun;
- bTextMode = pRT && pRT->IsImageFlag( SbiImageFlags::COMPARETEXT );
- }
- else
- {
- bTextMode = true;
- }
- if ( nArgCount == 4 )
+ if ( nArgCount >= 3 )
+ {
+ nStartPos = rPar.Get(1)->GetLong();
+ if( nStartPos <= 0 )
{
- bTextMode = rPar.Get(4)->GetInteger();
+ StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ nStartPos = 1;
}
- sal_Int32 nPos;
- const OUString& rToken = rPar.Get(nFirstStringPos + 1)->GetOUString();
+ nFirstStringPos++;
+ }
- // #97545 Always find empty string
- if( rToken.isEmpty() )
+ SbiInstance* pInst = GetSbData()->pInst;
+ bool bTextMode;
+ bool bCompatibility = ( pInst && pInst->IsCompatibility() );
+ if( bCompatibility )
+ {
+ SbiRuntime* pRT = pInst->pRun;
+ bTextMode = pRT && pRT->IsImageFlag( SbiImageFlags::COMPARETEXT );
+ }
+ else
+ {
+ bTextMode = true;
+ }
+ if ( nArgCount == 4 )
+ {
+ bTextMode = rPar.Get(4)->GetInteger();
+ }
+ sal_Int32 nPos;
+ const OUString aToken = rPar.Get(nFirstStringPos + 1)->GetOUString();
+
+ // #97545 Always find empty string
+ if( aToken.isEmpty() )
+ {
+ nPos = nStartPos;
+ }
+ else
+ {
+ const OUString aStr1 = rPar.Get(nFirstStringPos)->GetOUString();
+ const sal_Int32 nrStr1Len = aStr1.getLength();
+ if (nStartPos > nrStr1Len)
{
- nPos = nStartPos;
+ // Start position is greater than the string being searched
+ nPos = 0;
}
else
{
- const OUString& rStr1 = rPar.Get(nFirstStringPos)->GetOUString();
- const sal_Int32 nrStr1Len = rStr1.getLength();
- if (nStartPos > nrStr1Len)
+ if( !bTextMode )
{
- // Start position is greater than the string being searched
- nPos = 0;
+ nPos = aStr1.indexOf( aToken, nStartPos - 1 ) + 1;
}
else
{
- if( !bTextMode )
- {
- nPos = rStr1.indexOf( rToken, nStartPos - 1 ) + 1;
- }
- else
- {
- // tdf#139840 - case-insensitive operation for non-ASCII characters
- i18nutil::SearchOptions2 aSearchOptions;
- aSearchOptions.searchString = rToken;
- aSearchOptions.AlgorithmType2 = util::SearchAlgorithms2::ABSOLUTE;
- aSearchOptions.transliterateFlags |= TransliterationFlags::IGNORE_CASE;
- utl::TextSearch textSearch(aSearchOptions);
-
- sal_Int32 nStart = nStartPos - 1;
- sal_Int32 nEnd = nrStr1Len;
- nPos = textSearch.SearchForward(rStr1, &nStart, &nEnd) ? nStart + 1 : 0;
- }
+ // tdf#139840 - case-insensitive operation for non-ASCII characters
+ i18nutil::SearchOptions2 aSearchOptions;
+ aSearchOptions.searchString = aToken;
+ aSearchOptions.AlgorithmType2 = util::SearchAlgorithms2::ABSOLUTE;
+ aSearchOptions.transliterateFlags |= TransliterationFlags::IGNORE_CASE;
+ utl::TextSearch textSearch(aSearchOptions);
+
+ sal_Int32 nStart = nStartPos - 1;
+ sal_Int32 nEnd = nrStr1Len;
+ nPos = textSearch.SearchForward(aStr1, &nStart, &nEnd) ? nStart + 1 : 0;
}
}
- rPar.Get(0)->PutLong(nPos);
}
+ rPar.Get(0)->PutLong(nPos);
}
@@ -923,78 +858,76 @@ void SbRtl_InStrRev(StarBASIC *, SbxArray & rPar, bool)
const sal_uInt32 nArgCount = rPar.Count() - 1;
if ( nArgCount < 2 )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
- else
- {
- const OUString aStr1 = rPar.Get(1)->GetOUString();
- const OUString aToken = rPar.Get(2)->GetOUString();
- sal_Int32 nStartPos = -1;
- if ( nArgCount >= 3 )
- {
- nStartPos = rPar.Get(3)->GetLong();
- if( nStartPos <= 0 && nStartPos != -1 )
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- nStartPos = -1;
- }
- }
+ const OUString aStr1 = rPar.Get(1)->GetOUString();
+ const OUString aToken = rPar.Get(2)->GetOUString();
- SbiInstance* pInst = GetSbData()->pInst;
- bool bTextMode;
- bool bCompatibility = ( pInst && pInst->IsCompatibility() );
- if( bCompatibility )
- {
- SbiRuntime* pRT = pInst->pRun;
- bTextMode = pRT && pRT->IsImageFlag( SbiImageFlags::COMPARETEXT );
- }
- else
- {
- bTextMode = true;
- }
- if ( nArgCount == 4 )
+ sal_Int32 nStartPos = -1;
+ if ( nArgCount >= 3 )
+ {
+ nStartPos = rPar.Get(3)->GetLong();
+ if( nStartPos <= 0 && nStartPos != -1 )
{
- bTextMode = rPar.Get(4)->GetInteger();
+ StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ nStartPos = -1;
}
- const sal_Int32 nStrLen = aStr1.getLength();
- if( nStartPos == -1 )
+ }
+
+ SbiInstance* pInst = GetSbData()->pInst;
+ bool bTextMode;
+ bool bCompatibility = ( pInst && pInst->IsCompatibility() );
+ if( bCompatibility )
+ {
+ SbiRuntime* pRT = pInst->pRun;
+ bTextMode = pRT && pRT->IsImageFlag( SbiImageFlags::COMPARETEXT );
+ }
+ else
+ {
+ bTextMode = true;
+ }
+ if ( nArgCount == 4 )
+ {
+ bTextMode = rPar.Get(4)->GetInteger();
+ }
+ const sal_Int32 nStrLen = aStr1.getLength();
+ if( nStartPos == -1 )
+ {
+ nStartPos = nStrLen;
+ }
+
+ sal_Int32 nPos = 0;
+ if( nStartPos <= nStrLen )
+ {
+ sal_Int32 nTokenLen = aToken.getLength();
+ if( !nTokenLen )
{
- nStartPos = nStrLen;
+ // Always find empty string
+ nPos = nStartPos;
}
-
- sal_Int32 nPos = 0;
- if( nStartPos <= nStrLen )
+ else if( nStrLen > 0 )
{
- sal_Int32 nTokenLen = aToken.getLength();
- if( !nTokenLen )
+ if( !bTextMode )
{
- // Always find empty string
- nPos = nStartPos;
+ nPos = aStr1.lastIndexOf( aToken, nStartPos ) + 1;
}
- else if( nStrLen > 0 )
+ else
{
- if( !bTextMode )
- {
- nPos = aStr1.lastIndexOf( aToken, nStartPos ) + 1;
- }
- else
- {
- // tdf#143332 - case-insensitive operation for non-ASCII characters
- i18nutil::SearchOptions2 aSearchOptions;
- aSearchOptions.searchString = aToken;
- aSearchOptions.AlgorithmType2 = util::SearchAlgorithms2::ABSOLUTE;
- aSearchOptions.transliterateFlags |= TransliterationFlags::IGNORE_CASE;
- utl::TextSearch textSearch(aSearchOptions);
-
- sal_Int32 nStart = 0;
- sal_Int32 nEnd = nStartPos;
- nPos = textSearch.SearchBackward(aStr1, &nEnd, &nStart) ? nStart : 0;
- }
+ // tdf#143332 - case-insensitive operation for non-ASCII characters
+ i18nutil::SearchOptions2 aSearchOptions;
+ aSearchOptions.searchString = aToken;
+ aSearchOptions.AlgorithmType2 = util::SearchAlgorithms2::ABSOLUTE;
+ aSearchOptions.transliterateFlags |= TransliterationFlags::IGNORE_CASE;
+ utl::TextSearch textSearch(aSearchOptions);
+
+ sal_Int32 nStart = 0;
+ sal_Int32 nEnd = nStartPos;
+ nPos = textSearch.SearchBackward(aStr1, &nEnd, &nStart) ? nStart : 0;
}
}
- rPar.Get(0)->PutLong(nPos);
}
+ rPar.Get(0)->PutLong(nPos);
}
@@ -1008,110 +941,86 @@ void SbRtl_InStrRev(StarBASIC *, SbxArray & rPar, bool)
void SbRtl_Int(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- else
- {
- SbxVariableRef pArg = rPar.Get(1);
- double aDouble= pArg->GetDouble();
- /*
- floor( 2.8 ) = 2.0
- floor( -2.8 ) = -3.0
- */
- aDouble = floor( aDouble );
- rPar.Get(0)->PutDouble(aDouble);
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ SbxVariableRef pArg = rPar.Get(1);
+ double aDouble= pArg->GetDouble();
+ /*
+ floor( 2.8 ) = 2.0
+ floor( -2.8 ) = -3.0
+ */
+ aDouble = floor( aDouble );
+ rPar.Get(0)->PutDouble(aDouble);
}
void SbRtl_Fix(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ SbxVariableRef pArg = rPar.Get(1);
+ double aDouble = pArg->GetDouble();
+ if ( aDouble >= 0.0 )
+ aDouble = floor( aDouble );
else
- {
- SbxVariableRef pArg = rPar.Get(1);
- double aDouble = pArg->GetDouble();
- if ( aDouble >= 0.0 )
- aDouble = floor( aDouble );
- else
- aDouble = ceil( aDouble );
- rPar.Get(0)->PutDouble(aDouble);
- }
+ aDouble = ceil( aDouble );
+ rPar.Get(0)->PutDouble(aDouble);
}
void SbRtl_LCase(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- const CharClass& rCharClass = GetCharClass();
- OUString aStr(rPar.Get(1)->GetOUString());
- aStr = rCharClass.lowercase(aStr);
- rPar.Get(0)->PutString(aStr);
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ const CharClass& rCharClass = GetCharClass();
+ OUString aStr(rPar.Get(1)->GetOUString());
+ aStr = rCharClass.lowercase(aStr);
+ rPar.Get(0)->PutString(aStr);
}
void SbRtl_Left(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 3)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ OUString aStr(rPar.Get(1)->GetOUString());
+ sal_Int32 nResultLen = rPar.Get(2)->GetLong();
+ if( nResultLen < 0 )
{
+ nResultLen = 0;
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
- else
+ else if(nResultLen > aStr.getLength())
{
- OUString aStr(rPar.Get(1)->GetOUString());
- sal_Int32 nResultLen = rPar.Get(2)->GetLong();
- if( nResultLen < 0 )
- {
- nResultLen = 0;
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else if(nResultLen > aStr.getLength())
- {
- nResultLen = aStr.getLength();
- }
- aStr = aStr.copy(0, nResultLen );
- rPar.Get(0)->PutString(aStr);
+ nResultLen = aStr.getLength();
}
+ aStr = aStr.copy(0, nResultLen );
+ rPar.Get(0)->PutString(aStr);
}
void SbRtl_Log(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- double aArg = rPar.Get(1)->GetDouble();
- if ( aArg > 0 )
- {
- double d = log( aArg );
- checkArithmeticOverflow( d );
- rPar.Get(0)->PutDouble(d);
- }
- else
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ double aArg = rPar.Get(1)->GetDouble();
+ if ( aArg <= 0 )
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ double d = log( aArg );
+ checkArithmeticOverflow( d );
+ rPar.Get(0)->PutDouble(d);
}
void SbRtl_LTrim(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- OUString aStr(comphelper::string::stripStart(rPar.Get(1)->GetOUString(), ' '));
- rPar.Get(0)->PutString(aStr);
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ OUString aStr(comphelper::string::stripStart(rPar.Get(1)->GetOUString(), ' '));
+ rPar.Get(0)->PutString(aStr);
}
@@ -1122,137 +1031,119 @@ void SbRtl_Mid(StarBASIC *, SbxArray & rPar, bool bWrite)
int nArgCount = rPar.Count() - 1;
if ( nArgCount < 2 )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
}
- else
+ // #23178: replicate the functionality of Mid$ as a command
+ // by adding a replacement-string as a fourth parameter.
+ // In contrast to the original the third parameter (nLength)
+ // can't be left out here. That's considered in bWrite already.
+ if( nArgCount == 4 )
{
- // #23178: replicate the functionality of Mid$ as a command
- // by adding a replacement-string as a fourth parameter.
- // In contrast to the original the third parameter (nLength)
- // can't be left out here. That's considered in bWrite already.
- if( nArgCount == 4 )
- {
- bWrite = true;
- }
- OUString aArgStr = rPar.Get(1)->GetOUString();
- sal_Int32 nStartPos = rPar.Get(2)->GetLong();
- if ( nStartPos < 1 )
+ bWrite = true;
+ }
+ OUString aArgStr = rPar.Get(1)->GetOUString();
+ sal_Int32 nStartPos = rPar.Get(2)->GetLong();
+ if ( nStartPos < 1 )
+ {
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ }
+
+ nStartPos--;
+ sal_Int32 nLen = -1;
+ bool bWriteNoLenParam = false;
+ if ( nArgCount == 3 || bWrite )
+ {
+ sal_Int32 n = rPar.Get(3)->GetLong();
+ if( bWrite && n == -1 )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ bWriteNoLenParam = true;
}
- else
+ nLen = n;
+ }
+ if ( bWrite )
+ {
+ sal_Int32 nArgLen = aArgStr.getLength();
+ if( nStartPos > nArgLen )
{
- nStartPos--;
- sal_Int32 nLen = -1;
- bool bWriteNoLenParam = false;
- if ( nArgCount == 3 || bWrite )
+ SbiInstance* pInst = GetSbData()->pInst;
+ bool bCompatibility = ( pInst && pInst->IsCompatibility() );
+ if( bCompatibility )
{
- sal_Int32 n = rPar.Get(3)->GetLong();
- if( bWrite && n == -1 )
- {
- bWriteNoLenParam = true;
- }
- nLen = n;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
- if ( bWrite )
- {
- sal_Int32 nArgLen = aArgStr.getLength();
- if( nStartPos > nArgLen )
- {
- SbiInstance* pInst = GetSbData()->pInst;
- bool bCompatibility = ( pInst && pInst->IsCompatibility() );
- if( bCompatibility )
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
- }
- nStartPos = nArgLen;
- }
-
- OUString aReplaceStr = rPar.Get(4)->GetOUString();
- sal_Int32 nReplaceStrLen = aReplaceStr.getLength();
- sal_Int32 nReplaceLen;
- if( bWriteNoLenParam )
- {
- nReplaceLen = nArgLen - nStartPos;
- }
- else
- {
- nReplaceLen = nLen;
- if( nReplaceLen < 0 || nReplaceLen > nArgLen - nStartPos )
- {
- nReplaceLen = nArgLen - nStartPos;
- }
- }
-
- OUStringBuffer aResultStr(aArgStr);
- sal_Int32 nErase = nReplaceLen;
- aResultStr.remove( nStartPos, nErase );
- aResultStr.insert(
- nStartPos, aReplaceStr.getStr(), std::min(nReplaceLen, nReplaceStrLen));
+ nStartPos = nArgLen;
+ }
- rPar.Get(1)->PutString(aResultStr.makeStringAndClear());
- }
- else
+ OUString aReplaceStr = rPar.Get(4)->GetOUString();
+ sal_Int32 nReplaceStrLen = aReplaceStr.getLength();
+ sal_Int32 nReplaceLen;
+ if( bWriteNoLenParam )
+ {
+ nReplaceLen = nArgLen - nStartPos;
+ }
+ else
+ {
+ nReplaceLen = nLen;
+ if( nReplaceLen < 0 || nReplaceLen > nArgLen - nStartPos )
{
- OUString aResultStr;
- if (nStartPos > aArgStr.getLength())
- {
- // do nothing
- }
- else if(nArgCount == 2)
- {
- aResultStr = aArgStr.copy( nStartPos);
- }
- else
- {
- if (nLen < 0)
- nLen = 0;
- if(nStartPos + nLen > aArgStr.getLength())
- {
- nLen = aArgStr.getLength() - nStartPos;
- }
- if (nLen > 0)
- aResultStr = aArgStr.copy( nStartPos, nLen );
- }
- rPar.Get(0)->PutString(aResultStr);
+ nReplaceLen = nArgLen - nStartPos;
}
}
- }
-}
-void SbRtl_Oct(StarBASIC *, SbxArray & rPar, bool)
-{
- if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ OUStringBuffer aResultStr(aArgStr);
+ sal_Int32 nErase = nReplaceLen;
+ aResultStr.remove( nStartPos, nErase );
+ aResultStr.insert(
+ nStartPos, aReplaceStr.getStr(), std::min(nReplaceLen, nReplaceStrLen));
+
+ rPar.Get(1)->PutString(aResultStr.makeStringAndClear());
}
else
{
- char aBuffer[16];
- SbxVariableRef pArg = rPar.Get(1);
- if ( pArg->IsInteger() )
+ OUString aResultStr;
+ if (nStartPos > aArgStr.getLength())
+ {
+ // do nothing
+ }
+ else if(nArgCount == 2)
{
- snprintf( aBuffer, sizeof(aBuffer), "%o", pArg->GetInteger() );
+ aResultStr = aArgStr.copy( nStartPos);
}
else
{
- snprintf( aBuffer, sizeof(aBuffer), "%lo", static_cast<long unsigned int>(pArg->GetLong()) );
+ if (nLen < 0)
+ nLen = 0;
+ if(nStartPos + nLen > aArgStr.getLength())
+ {
+ nLen = aArgStr.getLength() - nStartPos;
+ }
+ if (nLen > 0)
+ aResultStr = aArgStr.copy( nStartPos, nLen );
}
- rPar.Get(0)->PutString(OUString::createFromAscii(aBuffer));
+ rPar.Get(0)->PutString(aResultStr);
}
}
+void SbRtl_Oct(StarBASIC *, SbxArray & rPar, bool)
+{
+ if (rPar.Count() < 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ SbxVariableRef pArg = rPar.Get(1);
+ // converting value to unsigned and limit to 2 or 4 byte representation
+ sal_uInt32 nVal = pArg->IsInteger() ?
+ static_cast<sal_uInt16>(pArg->GetInteger()) :
+ static_cast<sal_uInt32>(pArg->GetLong());
+ rPar.Get(0)->PutString(OUString::number(nVal, 8));
+}
+
// Replace(expression, find, replace[, start[, count[, compare]]])
void SbRtl_Replace(StarBASIC *, SbxArray & rPar, bool)
{
const sal_uInt32 nArgCount = rPar.Count() - 1;
if ( nArgCount < 3 || nArgCount > 6 )
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
sal_Int32 lStartPos = 1;
if (nArgCount >= 4)
@@ -1263,10 +1154,10 @@ void SbRtl_Replace(StarBASIC *, SbxArray & rPar, bool)
}
if (lStartPos < 1)
{
- StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
- return;
+ return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
}
}
+ --lStartPos; // Make it 0-based
sal_Int32 lCount = -1;
if (nArgCount >= 5)
@@ -1277,8 +1168,7 @@ void SbRtl_Replace(StarBASIC *, SbxArray & rPar, bool)
}
if (lCount < -1)
{
- StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
- return;
+ return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
}
}
@@ -1302,66 +1192,74 @@ void SbRtl_Replace(StarBASIC *, SbxArray & rPar, bool)
}
const OUString aExpStr = rPar.Get(1)->GetOUString();
- const OUString aFindStr = rPar.Get(2)->GetOUString();
+ OUString aFindStr = rPar.Get(2)->GetOUString();
const OUString aReplaceStr = rPar.Get(3)->GetOUString();
- const sal_Int32 nExpStrLen = aExpStr.getLength();
- const sal_Int32 nFindStrLen = aFindStr.getLength();
- // tdf#142487 - use utl::TextSearch in order to implement the replace algorithm
- i18nutil::SearchOptions2 aSearchOptions;
- aSearchOptions.searchString = aFindStr;
- aSearchOptions.AlgorithmType2 = util::SearchAlgorithms2::ABSOLUTE;
+ OUString aSrcStr(aExpStr);
+ sal_Int32 nPrevPos = std::min(lStartPos, aSrcStr.getLength());
+ css::uno::Sequence<sal_Int32> aOffset;
if (bCaseInsensitive)
- aSearchOptions.transliterateFlags |= TransliterationFlags::IGNORE_CASE;
- utl::TextSearch textSearch(aSearchOptions);
+ {
+ // tdf#132389: case-insensitive operation for non-ASCII characters
+ // tdf#142487: use css::i18n::Transliteration to correctly handle ß -> ss expansion
+ // tdf#132388: We can't use utl::TextSearch (css::i18n::XTextSearch), because each call to
+ // css::i18n::XTextSearch::SearchForward transliterates input string, making
+ // performance of repeated calls unacceptable
+ auto xTrans = css::i18n::Transliteration::create(comphelper::getProcessComponentContext());
+ xTrans->loadModule(css::i18n::TransliterationModules_IGNORE_CASE, {});
+ aFindStr = xTrans->transliterate(aFindStr, 0, aFindStr.getLength(), aOffset);
+ aSrcStr = xTrans->transliterate(aSrcStr, nPrevPos, aSrcStr.getLength() - nPrevPos, aOffset);
+ nPrevPos = std::distance(aOffset.begin(),
+ std::lower_bound(aOffset.begin(), aOffset.end(), nPrevPos));
+ }
+
+ auto getExpStrPos = [aOffset, nExpLen = aExpStr.getLength()](sal_Int32 nSrcStrPos) -> sal_Int32
+ {
+ assert(!aOffset.hasElements() || aOffset.getLength() >= nSrcStrPos);
+ if (!aOffset.hasElements())
+ return nSrcStrPos;
+ return aOffset.getLength() > nSrcStrPos ? aOffset[nSrcStrPos] : nExpLen;
+ };
// Note: the result starts from lStartPos, removing everything to the left. See i#94895.
- sal_Int32 nPrevPos = std::min(lStartPos - 1, nExpStrLen);
- OUStringBuffer sResult(nExpStrLen - nPrevPos);
+ OUStringBuffer sResult(aSrcStr.getLength() - nPrevPos);
sal_Int32 nCounts = 0;
while (lCount == -1 || lCount > nCounts)
{
- sal_Int32 nStartPos = nPrevPos;
- sal_Int32 aEndPos = aExpStr.getLength();
- if (textSearch.SearchForward(aExpStr, &nStartPos, &aEndPos))
- {
- sResult.append(aExpStr.getStr() + nPrevPos, nStartPos - nPrevPos);
- sResult.append(aReplaceStr);
- nPrevPos = nStartPos + nFindStrLen;
- nCounts++;
- }
- else
- {
+ sal_Int32 nPos = aSrcStr.indexOf(aFindStr, nPrevPos);
+ if (nPos < 0)
break;
- }
+
+ lStartPos = getExpStrPos(nPrevPos);
+ sResult.append(aExpStr.getStr() + lStartPos, getExpStrPos(nPos) - lStartPos);
+ sResult.append(aReplaceStr);
+ nPrevPos = nPos + aFindStr.getLength();
+ nCounts++;
}
- sResult.append(aExpStr.getStr() + nPrevPos, nExpStrLen - nPrevPos);
+ lStartPos = getExpStrPos(nPrevPos);
+ sResult.append(aExpStr.getStr() + lStartPos, aExpStr.getLength() - lStartPos);
rPar.Get(0)->PutString(sResult.makeStringAndClear());
}
void SbRtl_Right(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 3)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ const OUString aStr = rPar.Get(1)->GetOUString();
+ int nResultLen = rPar.Get(2)->GetLong();
+ if( nResultLen < 0 )
{
+ nResultLen = 0;
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
- else
+ int nStrLen = aStr.getLength();
+ if ( nResultLen > nStrLen )
{
- const OUString& rStr = rPar.Get(1)->GetOUString();
- int nResultLen = rPar.Get(2)->GetLong();
- if( nResultLen < 0 )
- {
- nResultLen = 0;
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- int nStrLen = rStr.getLength();
- if ( nResultLen > nStrLen )
- {
- nResultLen = nStrLen;
- }
- OUString aResultStr = rStr.copy( nStrLen - nResultLen );
- rPar.Get(0)->PutString(aResultStr);
+ nResultLen = nStrLen;
}
+ OUString aResultStr = aStr.copy( nStrLen - nResultLen );
+ rPar.Get(0)->PutString(aResultStr);
}
void SbRtl_RTL(StarBASIC * pBasic, SbxArray & rPar, bool)
@@ -1372,145 +1270,115 @@ void SbRtl_RTL(StarBASIC * pBasic, SbxArray & rPar, bool)
void SbRtl_RTrim(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- OUString aStr(comphelper::string::stripEnd(rPar.Get(1)->GetOUString(), ' '));
- rPar.Get(0)->PutString(aStr);
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ OUString aStr(comphelper::string::stripEnd(rPar.Get(1)->GetOUString(), ' '));
+ rPar.Get(0)->PutString(aStr);
}
void SbRtl_Sgn(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ double aDouble = rPar.Get(1)->GetDouble();
+ sal_Int16 nResult = 0;
+ if ( aDouble > 0 )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ nResult = 1;
}
- else
+ else if ( aDouble < 0 )
{
- double aDouble = rPar.Get(1)->GetDouble();
- sal_Int16 nResult = 0;
- if ( aDouble > 0 )
- {
- nResult = 1;
- }
- else if ( aDouble < 0 )
- {
- nResult = -1;
- }
- rPar.Get(0)->PutInteger(nResult);
+ nResult = -1;
}
+ rPar.Get(0)->PutInteger(nResult);
}
void SbRtl_Space(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- OUStringBuffer aBuf;
- string::padToLength(aBuf, rPar.Get(1)->GetLong(), ' ');
- rPar.Get(0)->PutString(aBuf.makeStringAndClear());
+ return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
}
-}
-void SbRtl_Spc(StarBASIC *, SbxArray & rPar, bool)
-{
- if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- OUStringBuffer aBuf;
- string::padToLength(aBuf, rPar.Get(1)->GetLong(), ' ');
- rPar.Get(0)->PutString(aBuf.makeStringAndClear());
- }
+ const sal_Int32 nCount = rPar.Get(1)->GetLong();
+ OUStringBuffer aBuf(nCount);
+ string::padToLength(aBuf, nCount, ' ');
+ rPar.Get(0)->PutString(aBuf.makeStringAndClear());
}
void SbRtl_Sqr(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
}
- else
+
+ double aDouble = rPar.Get(1)->GetDouble();
+ if ( aDouble < 0 )
{
- double aDouble = rPar.Get(1)->GetDouble();
- if ( aDouble >= 0 )
- {
- rPar.Get(0)->PutDouble(sqrt(aDouble));
- }
- else
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
+ rPar.Get(0)->PutDouble(sqrt(aDouble));
}
void SbRtl_Str(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
}
- else
+
+ OUString aStr;
+ OUString aStrNew(u""_ustr);
+ SbxVariableRef pArg = rPar.Get(1);
+ pArg->Format( aStr );
+
+ // Numbers start with a space
+ if (pArg->GetType() != SbxBOOL && pArg->IsNumericRTL())
{
- OUString aStr;
- OUString aStrNew("");
- SbxVariableRef pArg = rPar.Get(1);
- pArg->Format( aStr );
+ // replace commas by points so that it's symmetric to Val!
+ aStr = aStr.replaceFirst( ",", "." );
- // Numbers start with a space
- if( pArg->IsNumericRTL() )
+ SbiInstance* pInst = GetSbData()->pInst;
+ bool bCompatibility = ( pInst && pInst->IsCompatibility() );
+ if( bCompatibility )
{
- // replace commas by points so that it's symmetric to Val!
- aStr = aStr.replaceFirst( ",", "." );
-
- SbiInstance* pInst = GetSbData()->pInst;
- bool bCompatibility = ( pInst && pInst->IsCompatibility() );
- if( bCompatibility )
- {
- sal_Int32 nLen = aStr.getLength();
+ sal_Int32 nLen = aStr.getLength();
- const sal_Unicode* pBuf = aStr.getStr();
+ const sal_Unicode* pBuf = aStr.getStr();
- bool bNeg = ( pBuf[0] == '-' );
- sal_Int32 iZeroSearch = 0;
- if( bNeg )
- {
- aStrNew += "-";
- iZeroSearch++;
- }
- else
- {
- if( pBuf[0] != ' ' )
- {
- aStrNew += " ";
- }
- }
- sal_Int32 iNext = iZeroSearch + 1;
- if( pBuf[iZeroSearch] == '0' && nLen > iNext && pBuf[iNext] == '.' )
+ bool bNeg = ( pBuf[0] == '-' );
+ sal_Int32 iZeroSearch = 0;
+ if( bNeg )
+ {
+ aStrNew += "-";
+ iZeroSearch++;
+ }
+ else
+ {
+ if( pBuf[0] != ' ' )
{
- iZeroSearch += 1;
+ aStrNew += " ";
}
- aStrNew += aStr.subView(iZeroSearch);
}
- else
+ sal_Int32 iNext = iZeroSearch + 1;
+ if( pBuf[iZeroSearch] == '0' && nLen > iNext && pBuf[iNext] == '.' )
{
- aStrNew = " " + aStr;
+ iZeroSearch += 1;
}
+ aStrNew += aStr.subView(iZeroSearch);
}
else
{
- aStrNew = aStr;
+ aStrNew = " " + aStr;
}
- rPar.Get(0)->PutString(aStrNew);
}
+ else
+ {
+ aStrNew = aStr;
+ }
+ rPar.Get(0)->PutString(aStrNew);
}
void SbRtl_StrComp(StarBASIC *, SbxArray & rPar, bool)
@@ -1521,8 +1389,8 @@ void SbRtl_StrComp(StarBASIC *, SbxArray & rPar, bool)
rPar.Get(0)->PutEmpty();
return;
}
- const OUString& rStr1 = rPar.Get(1)->GetOUString();
- const OUString& rStr2 = rPar.Get(2)->GetOUString();
+ const OUString aStr1 = rPar.Get(1)->GetOUString();
+ const OUString aStr2 = rPar.Get(2)->GetOUString();
SbiInstance* pInst = GetSbData()->pInst;
bool bTextCompare;
@@ -1549,7 +1417,7 @@ void SbRtl_StrComp(StarBASIC *, SbxArray & rPar, bool)
::utl::TransliterationWrapper* pTransliterationWrapper = GetSbData()->pTransliterationWrapper.get();
if( !pTransliterationWrapper )
{
- uno::Reference< uno::XComponentContext > xContext = getProcessComponentContext();
+ const uno::Reference< uno::XComponentContext >& xContext = getProcessComponentContext();
GetSbData()->pTransliterationWrapper.reset(
new ::utl::TransliterationWrapper( xContext,
TransliterationFlags::IGNORE_CASE |
@@ -1560,12 +1428,12 @@ void SbRtl_StrComp(StarBASIC *, SbxArray & rPar, bool)
LanguageType eLangType = Application::GetSettings().GetLanguageTag().getLanguageType();
pTransliterationWrapper->loadModuleIfNeeded( eLangType );
- nRetValue = pTransliterationWrapper->compareString( rStr1, rStr2 );
+ nRetValue = pTransliterationWrapper->compareString( aStr1, aStr2 );
}
else
{
sal_Int32 aResult;
- aResult = rStr1.compareTo( rStr2 );
+ aResult = aStr1.compareTo( aStr2 );
if ( aResult < 0 )
{
nRetValue = -1;
@@ -1582,69 +1450,64 @@ void SbRtl_String(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
{
+ return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
+ }
+
+ sal_Unicode aFiller;
+ sal_Int32 lCount = rPar.Get(1)->GetLong();
+ if( lCount < 0 || lCount > 0xffff )
+ {
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
+ if (rPar.Get(2)->GetType() == SbxINTEGER)
+ {
+ aFiller = static_cast<sal_Unicode>(rPar.Get(2)->GetInteger());
+ }
else
{
- sal_Unicode aFiller;
- sal_Int32 lCount = rPar.Get(1)->GetLong();
- if( lCount < 0 || lCount > 0xffff )
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- if (rPar.Get(2)->GetType() == SbxINTEGER)
- {
- aFiller = static_cast<sal_Unicode>(rPar.Get(2)->GetInteger());
- }
- else
- {
- const OUString& rStr = rPar.Get(2)->GetOUString();
- aFiller = rStr[0];
- }
- OUStringBuffer aBuf(lCount);
- string::padToLength(aBuf, lCount, aFiller);
- rPar.Get(0)->PutString(aBuf.makeStringAndClear());
+ const OUString aStr = rPar.Get(2)->GetOUString();
+ aFiller = aStr[0];
}
+ OUStringBuffer aBuf(lCount);
+ string::padToLength(aBuf, lCount, aFiller);
+ rPar.Get(0)->PutString(aBuf.makeStringAndClear());
}
void SbRtl_Tab(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- else
{
- OUStringBuffer aStr;
- comphelper::string::padToLength(aStr, rPar.Get(1)->GetLong(), '\t');
- rPar.Get(0)->PutString(aStr.makeStringAndClear());
+ return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
}
+
+ const sal_Int32 nCount = std::max(rPar.Get(1)->GetLong(), sal_Int32(0));
+ OUStringBuffer aStr(nCount);
+ comphelper::string::padToLength(aStr, nCount, '\t');
+ rPar.Get(0)->PutString(aStr.makeStringAndClear());
}
void SbRtl_Tan(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- SbxVariableRef pArg = rPar.Get(1);
- rPar.Get(0)->PutDouble(tan(pArg->GetDouble()));
+ return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
}
+
+ SbxVariableRef pArg = rPar.Get(1);
+ rPar.Get(0)->PutDouble(tan(pArg->GetDouble()));
}
void SbRtl_UCase(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- const CharClass& rCharClass = GetCharClass();
- OUString aStr(rPar.Get(1)->GetOUString());
- aStr = rCharClass.uppercase( aStr );
- rPar.Get(0)->PutString(aStr);
+ return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
}
+
+ const CharClass& rCharClass = GetCharClass();
+ OUString aStr(rPar.Get(1)->GetOUString());
+ aStr = rCharClass.uppercase( aStr );
+ rPar.Get(0)->PutString(aStr);
}
@@ -1652,64 +1515,52 @@ void SbRtl_Val(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
}
- else
- {
- double nResult = 0.0;
- char* pEndPtr;
+ double nResult = 0.0;
- OUString aStr(rPar.Get(1)->GetOUString());
+ OUString aStr(rPar.Get(1)->GetOUString());
- FilterWhiteSpace( aStr );
- if ( aStr.getLength() > 1 && aStr[0] == '&' )
+ FilterWhiteSpace( aStr );
+ if ( aStr.getLength() > 1 && aStr[0] == '&' )
+ {
+ sal_Unicode aChar = aStr[1];
+ if ( aChar == 'h' || aChar == 'H' )
{
- int nRadix = 10;
- char aChar = static_cast<char>(aStr[1]);
- if ( aChar == 'h' || aChar == 'H' )
- {
- nRadix = 16;
- }
- else if ( aChar == 'o' || aChar == 'O' )
- {
- nRadix = 8;
- }
- if ( nRadix != 10 )
- {
- OString aByteStr(OUStringToOString(aStr, osl_getThreadTextEncoding()));
- sal_Int16 nlResult = static_cast<sal_Int16>(strtol( aByteStr.getStr()+2, &pEndPtr, nRadix));
- nResult = static_cast<double>(nlResult);
- }
+ nResult = static_cast<sal_Int16>(o3tl::toInt64(aStr.subView(2), 16));
}
- else
+ else if ( aChar == 'o' || aChar == 'O' )
{
- rtl_math_ConversionStatus eStatus = rtl_math_ConversionStatus_Ok;
- sal_Int32 nParseEnd = 0;
- nResult = ::rtl::math::stringToDouble( aStr, '.', ',', &eStatus, &nParseEnd );
- if ( eStatus != rtl_math_ConversionStatus_Ok )
- StarBASIC::Error( ERRCODE_BASIC_MATH_OVERFLOW );
- /* TODO: we should check whether all characters were parsed here,
- * but earlier code silently ignored trailing nonsense such as "1x"
- * resulting in 1 with the side effect that any alpha-only-string
- * like "x" resulted in 0. Not changing that now (2013-03-22) as
- * user macros may rely on it. */
+ nResult = static_cast<sal_Int16>(o3tl::toInt64(aStr.subView(2), 8));
+ }
+ }
+ else
+ {
+ rtl_math_ConversionStatus eStatus = rtl_math_ConversionStatus_Ok;
+ sal_Int32 nParseEnd = 0;
+ nResult = ::rtl::math::stringToDouble( aStr, '.', ',', &eStatus, &nParseEnd );
+ if ( eStatus != rtl_math_ConversionStatus_Ok )
+ StarBASIC::Error( ERRCODE_BASIC_MATH_OVERFLOW );
+ /* TODO: we should check whether all characters were parsed here,
+ * but earlier code silently ignored trailing nonsense such as "1x"
+ * resulting in 1 with the side effect that any alpha-only-string
+ * like "x" resulted in 0. Not changing that now (2013-03-22) as
+ * user macros may rely on it. */
#if 0
- else if ( nParseEnd != aStr.getLength() )
- StarBASIC::Error( ERRCODE_BASIC_CONVERSION );
+ else if ( nParseEnd != aStr.getLength() )
+ StarBASIC::Error( ERRCODE_BASIC_CONVERSION );
#endif
- }
-
- rPar.Get(0)->PutDouble(nResult);
}
+
+ rPar.Get(0)->PutDouble(nResult);
}
// Helper functions for date conversion
sal_Int16 implGetDateDay( double aDate )
{
- aDate -= 2.0; // standardize: 1.1.1900 => 0.0
aDate = floor( aDate );
- Date aRefDate( 1, 1, 1900 );
+ Date aRefDate(1899'12'30);
aRefDate.AddDays( aDate );
sal_Int16 nRet = static_cast<sal_Int16>( aRefDate.GetDay() );
@@ -1718,9 +1569,8 @@ sal_Int16 implGetDateDay( double aDate )
sal_Int16 implGetDateMonth( double aDate )
{
- Date aRefDate( 1,1,1900 );
+ Date aRefDate(1899'12'30);
sal_Int32 nDays = static_cast<sal_Int32>(aDate);
- nDays -= 2; // standardize: 1.1.1900 => 0.0
aRefDate.AddDays( nDays );
sal_Int16 nRet = static_cast<sal_Int16>( aRefDate.GetMonth() );
return nRet;
@@ -1752,8 +1602,7 @@ void SbRtl_CDateToUnoDate(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 2)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
unoToSbxValue(rPar.Get(0), Any(SbxDateToUNODate(rPar.Get(1))));
@@ -1764,8 +1613,7 @@ void SbRtl_CDateFromUnoDate(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 2 || rPar.Get(1)->GetType() != SbxOBJECT)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
Any aAny(sbxToUnoValue(rPar.Get(1), cppu::UnoType<css::util::Date>::get()));
@@ -1784,14 +1632,15 @@ css::util::Time SbxDateToUNOTime( const SbxValue* const pVal )
aUnoTime.Hours = implGetHour ( aDate );
aUnoTime.Minutes = implGetMinute ( aDate );
aUnoTime.Seconds = implGetSecond ( aDate );
- aUnoTime.NanoSeconds = 0;
+ aUnoTime.NanoSeconds = implGetNanoSecond( aDate );
return aUnoTime;
}
void SbxDateFromUNOTime( SbxValue *pVal, const css::util::Time& aUnoTime)
{
- pVal->PutDate( implTimeSerial(aUnoTime.Hours, aUnoTime.Minutes, aUnoTime.Seconds) );
+ pVal->PutDate(implTimeSerial(aUnoTime.Hours, aUnoTime.Minutes, aUnoTime.Seconds,
+ nanoSecToMilliSec(aUnoTime.NanoSeconds)));
}
// Function to convert date to UNO time (com.sun.star.util.Time)
@@ -1799,8 +1648,7 @@ void SbRtl_CDateToUnoTime(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 2)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
unoToSbxValue(rPar.Get(0), Any(SbxDateToUNOTime(rPar.Get(1))));
@@ -1811,8 +1659,7 @@ void SbRtl_CDateFromUnoTime(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 2 || rPar.Get(1)->GetType() != SbxOBJECT)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
Any aAny(sbxToUnoValue(rPar.Get(1), cppu::UnoType<css::util::Time>::get()));
@@ -1834,7 +1681,7 @@ css::util::DateTime SbxDateToUNODateTime( const SbxValue* const pVal )
aUnoDT.Hours = implGetHour ( aDate );
aUnoDT.Minutes = implGetMinute ( aDate );
aUnoDT.Seconds = implGetSecond ( aDate );
- aUnoDT.NanoSeconds = 0;
+ aUnoDT.NanoSeconds = implGetNanoSecond( aDate );
return aUnoDT;
}
@@ -1842,9 +1689,8 @@ css::util::DateTime SbxDateToUNODateTime( const SbxValue* const pVal )
void SbxDateFromUNODateTime( SbxValue *pVal, const css::util::DateTime& aUnoDT)
{
double dDate(0.0);
- if( implDateTimeSerial( aUnoDT.Year, aUnoDT.Month, aUnoDT.Day,
- aUnoDT.Hours, aUnoDT.Minutes, aUnoDT.Seconds,
- dDate ) )
+ if (implDateTimeSerial(aUnoDT.Year, aUnoDT.Month, aUnoDT.Day, aUnoDT.Hours, aUnoDT.Minutes,
+ aUnoDT.Seconds, nanoSecToMilliSec(aUnoDT.NanoSeconds), dDate))
{
pVal->PutDate( dDate );
}
@@ -1855,8 +1701,7 @@ void SbRtl_CDateToUnoDateTime(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 2)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
unoToSbxValue(rPar.Get(0), Any(SbxDateToUNODateTime(rPar.Get(1))));
@@ -1867,8 +1712,7 @@ void SbRtl_CDateFromUnoDateTime(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 2 || rPar.Get(1)->GetType() != SbxOBJECT)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
Any aAny(sbxToUnoValue(rPar.Get(1), cppu::UnoType<css::util::DateTime>::get()));
@@ -1882,24 +1726,19 @@ void SbRtl_CDateFromUnoDateTime(StarBASIC *, SbxArray & rPar, bool)
// Function to convert date to ISO 8601 date format YYYYMMDD
void SbRtl_CDateToIso(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() == 2)
- {
- double aDate = rPar.Get(1)->GetDate();
+ if (rPar.Count() != 2)
+ return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
- // Date may actually even be -YYYYYMMDD
- char Buffer[11];
- sal_Int16 nYear = implGetDateYear( aDate );
- snprintf( Buffer, sizeof( Buffer ), (nYear < 0 ? "%05d%02d%02d" : "%04d%02d%02d"),
- static_cast<int>(nYear),
- static_cast<int>(implGetDateMonth( aDate )),
- static_cast<int>(implGetDateDay( aDate )) );
- OUString aRetStr = OUString::createFromAscii( Buffer );
- rPar.Get(0)->PutString(aRetStr);
- }
- else
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
+ double aDate = rPar.Get(1)->GetDate();
+
+ // Date may actually even be -YYYYYMMDD
+ char Buffer[11];
+ sal_Int16 nYear = implGetDateYear(aDate);
+ snprintf(Buffer, sizeof(Buffer), (nYear < 0 ? "%05d%02d%02d" : "%04d%02d%02d"),
+ static_cast<int>(nYear), static_cast<int>(implGetDateMonth(aDate)),
+ static_cast<int>(implGetDateDay(aDate)));
+ OUString aRetStr = OUString::createFromAscii(Buffer);
+ rPar.Get(0)->PutString(aRetStr);
}
// Function to convert date from ISO 8601 date format YYYYMMDD or YYYY-MM-DD
@@ -1937,7 +1776,7 @@ void SbRtl_CDateFromIso(StarBASIC *, SbxArray & rPar, bool)
break;
bool bUseTwoDigitYear = false;
- OUString aYearStr, aMonthStr, aDayStr;
+ std::u16string_view aYearStr, aMonthStr, aDayStr;
if (nLen == 6 || nLen == 8 || nLen == 9)
{
// ((Y)YY)YYMMDD
@@ -1947,9 +1786,9 @@ void SbRtl_CDateFromIso(StarBASIC *, SbxArray & rPar, bool)
const sal_Int32 nMonthPos = (nLen == 8 ? 4 : (nLen == 6 ? 2 : 5));
if (nMonthPos == 2)
bUseTwoDigitYear = true;
- aYearStr = aStr.copy( 0, nMonthPos );
- aMonthStr = aStr.copy( nMonthPos, 2 );
- aDayStr = aStr.copy( nMonthPos + 2, 2 );
+ aYearStr = aStr.subView( 0, nMonthPos );
+ aMonthStr = aStr.subView( nMonthPos, 2 );
+ aDayStr = aStr.subView( nMonthPos + 2, 2 );
}
else
{
@@ -1960,9 +1799,9 @@ void SbRtl_CDateFromIso(StarBASIC *, SbxArray & rPar, bool)
if (aStr.indexOf('-', nMonthSep + 1) != nMonthSep + 3)
break;
- aYearStr = aStr.copy( 0, nMonthSep );
- aMonthStr = aStr.copy( nMonthSep + 1, 2 );
- aDayStr = aStr.copy( nMonthSep + 4, 2 );
+ aYearStr = aStr.subView( 0, nMonthSep );
+ aMonthStr = aStr.subView( nMonthSep + 1, 2 );
+ aDayStr = aStr.subView( nMonthSep + 4, 2 );
if ( !comphelper::string::isdigitAsciiString(aYearStr) ||
!comphelper::string::isdigitAsciiString(aMonthStr) ||
!comphelper::string::isdigitAsciiString(aDayStr))
@@ -1970,8 +1809,8 @@ void SbRtl_CDateFromIso(StarBASIC *, SbxArray & rPar, bool)
}
double dDate;
- if (!implDateSerial( static_cast<sal_Int16>(nSign * aYearStr.toInt32()),
- static_cast<sal_Int16>(aMonthStr.toInt32()), static_cast<sal_Int16>(aDayStr.toInt32()),
+ if (!implDateSerial( static_cast<sal_Int16>(nSign * o3tl::toInt32(aYearStr)),
+ static_cast<sal_Int16>(o3tl::toInt32(aMonthStr)), static_cast<sal_Int16>(o3tl::toInt32(aDayStr)),
bUseTwoDigitYear, SbDateCorrection::None, dDate ))
break;
@@ -1993,8 +1832,7 @@ void SbRtl_DateSerial(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 4)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
sal_Int16 nYear = rPar.Get(1)->GetInteger();
sal_Int16 nMonth = rPar.Get(2)->GetInteger();
@@ -2011,8 +1849,7 @@ void SbRtl_TimeSerial(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 4)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
sal_Int16 nHour = rPar.Get(1)->GetInteger();
if ( nHour == 24 )
@@ -2025,11 +1862,10 @@ void SbRtl_TimeSerial(StarBASIC *, SbxArray & rPar, bool)
(nMinute < 0 || nMinute > 59 ) ||
(nSecond < 0 || nSecond > 59 ))
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
- rPar.Get(0)->PutDate(implTimeSerial(nHour, nMinute, nSecond)); // JSM
+ rPar.Get(0)->PutDate(implTimeSerial(nHour, nMinute, nSecond, 0)); // JSM
}
void SbRtl_DateValue(StarBASIC *, SbxArray & rPar, bool)
@@ -2133,127 +1969,101 @@ void SbRtl_TimeValue(StarBASIC *, SbxArray & rPar, bool)
void SbRtl_Day(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- SbxVariableRef pArg = rPar.Get(1);
- double aDate = pArg->GetDate();
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ SbxVariableRef pArg = rPar.Get(1);
+ double aDate = pArg->GetDate();
- sal_Int16 nDay = implGetDateDay( aDate );
- rPar.Get(0)->PutInteger(nDay);
- }
+ sal_Int16 nDay = implGetDateDay( aDate );
+ rPar.Get(0)->PutInteger(nDay);
}
void SbRtl_Year(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- sal_Int16 nYear = implGetDateYear(rPar.Get(1)->GetDate());
- rPar.Get(0)->PutInteger(nYear);
- }
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ sal_Int16 nYear = implGetDateYear(rPar.Get(1)->GetDate());
+ rPar.Get(0)->PutInteger(nYear);
}
sal_Int16 implGetHour( double dDate )
{
- double nFrac = dDate - floor( dDate );
- nFrac *= 86400.0;
- sal_Int32 nSeconds = static_cast<sal_Int32>(nFrac + 0.5);
- sal_Int16 nHour = static_cast<sal_Int16>(nSeconds / 3600);
- return nHour;
+ double nFrac = (dDate - floor(dDate)) * ::tools::Time::milliSecPerDay;
+ sal_uInt64 nMilliSeconds = static_cast<sal_uInt64>(nFrac + 0.5);
+ return static_cast<sal_Int16>((nMilliSeconds / ::tools::Time::milliSecPerHour)
+ % ::tools::Time::hourPerDay);
}
void SbRtl_Hour(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- double nArg = rPar.Get(1)->GetDate();
- sal_Int16 nHour = implGetHour( nArg );
- rPar.Get(0)->PutInteger(nHour);
- }
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ double nArg = rPar.Get(1)->GetDate();
+ sal_Int16 nHour = implGetHour( nArg );
+ rPar.Get(0)->PutInteger(nHour);
}
void SbRtl_Minute(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- double nArg = rPar.Get(1)->GetDate();
- sal_Int16 nMin = implGetMinute( nArg );
- rPar.Get(0)->PutInteger(nMin);
- }
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ double nArg = rPar.Get(1)->GetDate();
+ sal_Int16 nMin = implGetMinute( nArg );
+ rPar.Get(0)->PutInteger(nMin);
}
void SbRtl_Month(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- sal_Int16 nMonth = implGetDateMonth(rPar.Get(1)->GetDate());
- rPar.Get(0)->PutInteger(nMonth);
- }
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ sal_Int16 nMonth = implGetDateMonth(rPar.Get(1)->GetDate());
+ rPar.Get(0)->PutInteger(nMonth);
}
sal_Int16 implGetSecond( double dDate )
{
- double nFrac = dDate - floor( dDate );
- nFrac *= 86400.0;
- sal_Int32 nSeconds = static_cast<sal_Int32>(nFrac + 0.5);
- sal_Int16 nTemp = static_cast<sal_Int16>(nSeconds / 3600);
- nSeconds -= nTemp * 3600;
- nTemp = static_cast<sal_Int16>(nSeconds / 60);
- nSeconds -= nTemp * 60;
+ double nFrac = (dDate - floor(dDate)) * ::tools::Time::milliSecPerDay;
+ sal_uInt64 nMilliSeconds = static_cast<sal_uInt64>(nFrac + 0.5);
+ return static_cast<sal_Int16>((nMilliSeconds / ::tools::Time::milliSecPerSec)
+ % ::tools::Time::secondPerMinute);
+}
- sal_Int16 nRet = static_cast<sal_Int16>(nSeconds);
- return nRet;
+sal_Int32 implGetNanoSecond(double dDate)
+{
+ double nFrac = (dDate - floor(dDate)) * ::tools::Time::milliSecPerDay;
+ sal_uInt64 nMilliSeconds = static_cast<sal_uInt64>(nFrac + 0.5);
+ nMilliSeconds %= ::tools::Time::milliSecPerSec;
+
+ return static_cast<sal_Int32>(nMilliSeconds * ::tools::Time ::nanoPerMilli);
}
void SbRtl_Second(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- double nArg = rPar.Get(1)->GetDate();
- sal_Int16 nSecond = implGetSecond( nArg );
- rPar.Get(0)->PutInteger(nSecond);
- }
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ double nArg = rPar.Get(1)->GetDate();
+ sal_Int16 nSecond = implGetSecond( nArg );
+ rPar.Get(0)->PutInteger(nSecond);
}
double Now_Impl()
{
- DateTime aDateTime( DateTime::SYSTEM );
- double aSerial = static_cast<double>(GetDayDiff( aDateTime ));
- tools::Long nSeconds = aDateTime.GetHour();
- nSeconds *= 3600;
- nSeconds += aDateTime.GetMin() * 60;
- nSeconds += aDateTime.GetSec();
- double nDays = static_cast<double>(nSeconds) / (24.0*3600.0);
- aSerial += nDays;
- return aSerial;
+ // tdf#161469 - align implementation with the now function in calc, i.e., include subseconds
+ DateTime aActTime(DateTime::SYSTEM);
+ return static_cast<double>(GetDayDiff(aActTime))
+ + implTimeSerial(aActTime.GetHour(), aActTime.GetMin(), aActTime.GetSec(),
+ nanoSecToMilliSec(aActTime.GetNanoSec()));
}
// Date Now()
-void SbRtl_Now(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutDate(Now_Impl()); }
+void SbRtl_Now(StarBASIC*, SbxArray& rPar, bool)
+{
+ if (rPar.Count() != 1)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ rPar.Get(0)->PutDate(Now_Impl());
+}
// Date Time()
@@ -2263,6 +2073,11 @@ void SbRtl_Time(StarBASIC *, SbxArray & rPar, bool bWrite)
{
tools::Time aTime( tools::Time::SYSTEM );
SbxVariable* pMeth = rPar.Get(0);
+ if (!pMeth->IsString())
+ {
+ pMeth->PutDate(aTime.GetTimeInDays());
+ return;
+ }
OUString aRes;
if( pMeth->IsFixed() )
{
@@ -2357,176 +2172,144 @@ void SbRtl_Date(StarBASIC *, SbxArray & rPar, bool bWrite)
void SbRtl_IsArray(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- rPar.Get(0)->PutBool((rPar.Get(1)->GetType() & SbxARRAY) != 0);
- }
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ rPar.Get(0)->PutBool((rPar.Get(1)->GetType() & SbxARRAY) != 0);
}
void SbRtl_IsObject(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- SbxVariable* pVar = rPar.Get(1);
- bool bObject = pVar->IsObject();
- SbxBase* pObj = (bObject ? pVar->GetObject() : nullptr);
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- if( auto pUnoClass = dynamic_cast<SbUnoClass*>( pObj) )
- {
- bObject = pUnoClass->getUnoClass().is();
- }
- rPar.Get(0)->PutBool(bObject);
+ SbxVariable* pVar = rPar.Get(1);
+ bool bObject = pVar->IsObject();
+ SbxBase* pObj = (bObject ? pVar->GetObject() : nullptr);
+
+ if( auto pUnoClass = dynamic_cast<SbUnoClass*>( pObj) )
+ {
+ bObject = pUnoClass->getUnoClass().is();
}
+ rPar.Get(0)->PutBool(bObject);
}
void SbRtl_IsDate(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() < 2)
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ // #46134 only string is converted, all other types result in sal_False
+ SbxVariableRef xArg = rPar.Get(1);
+ SbxDataType eType = xArg->GetType();
+ bool bDate = false;
+
+ if( eType == SbxDATE )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ bDate = true;
}
- else
+ else if( eType == SbxSTRING )
{
- // #46134 only string is converted, all other types result in sal_False
- SbxVariableRef xArg = rPar.Get(1);
- SbxDataType eType = xArg->GetType();
- bool bDate = false;
-
- if( eType == SbxDATE )
- {
- bDate = true;
- }
- else if( eType == SbxSTRING )
- {
- ErrCode nPrevError = SbxBase::GetError();
- SbxBase::ResetError();
+ ErrCode nPrevError = SbxBase::GetError();
+ SbxBase::ResetError();
- // force conversion of the parameter to SbxDATE
- xArg->SbxValue::GetDate();
+ // force conversion of the parameter to SbxDATE
+ xArg->SbxValue::GetDate();
- bDate = !SbxBase::IsError();
+ bDate = !SbxBase::IsError();
- SbxBase::ResetError();
- SbxBase::SetError( nPrevError );
- }
- rPar.Get(0)->PutBool(bDate);
+ SbxBase::ResetError();
+ SbxBase::SetError( nPrevError );
}
+ rPar.Get(0)->PutBool(bDate);
}
void SbRtl_IsEmpty(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() < 2)
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ SbxVariable* pVar = nullptr;
+ if( SbiRuntime::isVBAEnabled() )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ pVar = getDefaultProp(rPar.Get(1));
+ }
+ if ( pVar )
+ {
+ pVar->Broadcast( SfxHintId::BasicDataWanted );
+ rPar.Get(0)->PutBool(pVar->IsEmpty());
}
else
{
- SbxVariable* pVar = nullptr;
- if( SbiRuntime::isVBAEnabled() )
- {
- pVar = getDefaultProp(rPar.Get(1));
- }
- if ( pVar )
- {
- pVar->Broadcast( SfxHintId::BasicDataWanted );
- rPar.Get(0)->PutBool(pVar->IsEmpty());
- }
- else
- {
- rPar.Get(0)->PutBool(rPar.Get(1)->IsEmpty());
- }
+ rPar.Get(0)->PutBool(rPar.Get(1)->IsEmpty());
}
}
void SbRtl_IsError(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() < 2)
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ SbxVariable* pVar = rPar.Get(1);
+ SbUnoObject* pObj = dynamic_cast<SbUnoObject*>( pVar );
+ if ( !pObj )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ if ( SbxBase* pBaseObj = (pVar->IsObject() ? pVar->GetObject() : nullptr) )
+ {
+ pObj = dynamic_cast<SbUnoObject*>( pBaseObj );
+ }
+ }
+ uno::Reference< script::XErrorQuery > xError;
+ if ( pObj )
+ {
+ xError.set( pObj->getUnoAny(), uno::UNO_QUERY );
+ }
+ if ( xError.is() )
+ {
+ rPar.Get(0)->PutBool(xError->hasError());
}
else
{
- SbxVariable* pVar = rPar.Get(1);
- SbUnoObject* pObj = dynamic_cast<SbUnoObject*>( pVar );
- if ( !pObj )
- {
- if ( SbxBase* pBaseObj = (pVar->IsObject() ? pVar->GetObject() : nullptr) )
- {
- pObj = dynamic_cast<SbUnoObject*>( pBaseObj );
- }
- }
- uno::Reference< script::XErrorQuery > xError;
- if ( pObj )
- {
- xError.set( pObj->getUnoAny(), uno::UNO_QUERY );
- }
- if ( xError.is() )
- {
- rPar.Get(0)->PutBool(xError->hasError());
- }
- else
- {
- rPar.Get(0)->PutBool(rPar.Get(1)->IsErr());
- }
+ rPar.Get(0)->PutBool(rPar.Get(1)->IsErr());
}
}
void SbRtl_IsNull(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ // #51475 because of Uno-objects return true
+ // even if the pObj value is NULL
+ SbxVariableRef pArg = rPar.Get(1);
+ bool bNull = rPar.Get(1)->IsNull();
+ if( !bNull && pArg->GetType() == SbxOBJECT )
{
- // #51475 because of Uno-objects return true
- // even if the pObj value is NULL
- SbxVariableRef pArg = rPar.Get(1);
- bool bNull = rPar.Get(1)->IsNull();
- if( !bNull && pArg->GetType() == SbxOBJECT )
+ SbxBase* pObj = pArg->GetObject();
+ if( !pObj )
{
- SbxBase* pObj = pArg->GetObject();
- if( !pObj )
- {
- bNull = true;
- }
+ bNull = true;
}
- rPar.Get(0)->PutBool(bNull);
}
+ rPar.Get(0)->PutBool(bNull);
}
void SbRtl_IsNumeric(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- rPar.Get(0)->PutBool(rPar.Get(1)->IsNumericRTL());
- }
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ rPar.Get(0)->PutBool(rPar.Get(1)->IsNumericRTL());
}
void SbRtl_IsMissing(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- // #57915 Missing is reported by an error
- rPar.Get(0)->PutBool(rPar.Get(1)->IsErr());
- }
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ // #57915 Missing is reported by an error
+ rPar.Get(0)->PutBool(rPar.Get(1)->IsErr());
}
// Function looks for wildcards, removes them and always returns the pure path
@@ -2537,7 +2320,7 @@ static OUString implSetupWildcard(const OUString& rFileParam, SbiRTLData& rRTLDa
static const char cWild1 = '*';
static const char cWild2 = '?';
- rRTLData.pWildCard.reset();
+ rRTLData.moWildCard.reset();
rRTLData.sFullNameToBeChecked.clear();
OUString aFileParam = rFileParam;
@@ -2591,7 +2374,7 @@ static OUString implSetupWildcard(const OUString& rFileParam, SbiRTLData& rRTLDa
// invalid anyway because it was not accepted by OSL before
if (aPureFileName != "*")
{
- rRTLData.pWildCard = std::make_unique<WildCard>(aPureFileName);
+ rRTLData.moWildCard.emplace(aPureFileName);
}
return aPathStr;
}
@@ -2600,15 +2383,15 @@ static bool implCheckWildcard(std::u16string_view rName, SbiRTLData const& rRTLD
{
bool bMatch = true;
- if (rRTLData.pWildCard)
+ if (rRTLData.moWildCard)
{
- bMatch = rRTLData.pWildCard->Matches(rName);
+ bMatch = rRTLData.moWildCard->Matches(rName);
}
return bMatch;
}
-static bool isRootDir( const OUString& aDirURLStr )
+static bool isRootDir( std::u16string_view aDirURLStr )
{
INetURLObject aDirURLObj( aDirURLStr );
bool bRoot = false;
@@ -2690,18 +2473,17 @@ void SbRtl_Dir(StarBASIC *, SbxArray & rPar, bool)
}
else
{
- rPar.Get(0)->PutString("");
+ rPar.Get(0)->PutString(u""_ustr);
}
- SbAttributes nFlags = SbAttributes::NONE;
+ sal_Int16 nFlags = SbAttributes::NORMAL;
if ( nParCount > 2 )
{
- rRTLData.nDirFlags = nFlags
- = static_cast<SbAttributes>(rPar.Get(2)->GetInteger());
+ rRTLData.nDirFlags = nFlags = rPar.Get(2)->GetInteger();
}
else
{
- rRTLData.nDirFlags = SbAttributes::NONE;
+ rRTLData.nDirFlags = SbAttributes::NORMAL;
}
// Read directory
bool bIncludeFolders = bool(nFlags & SbAttributes::DIRECTORY);
@@ -2809,15 +2591,14 @@ void SbRtl_Dir(StarBASIC *, SbxArray & rPar, bool)
OUString aDirURL = implSetupWildcard(aFileParam, rRTLData);
- SbAttributes nFlags = SbAttributes::NONE;
+ sal_Int16 nFlags = SbAttributes::NORMAL;
if ( nParCount > 2 )
{
- rRTLData.nDirFlags = nFlags
- = static_cast<SbAttributes>(rPar.Get(2)->GetInteger());
+ rRTLData.nDirFlags = nFlags = rPar.Get(2)->GetInteger();
}
else
{
- rRTLData.nDirFlags = SbAttributes::NONE;
+ rRTLData.nDirFlags = SbAttributes::NORMAL;
}
// Read directory
@@ -2918,7 +2699,7 @@ void SbRtl_GetAttr(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() == 2)
{
- sal_Int16 nFlags = 0;
+ sal_Int16 nFlags = SbAttributes::NORMAL;
// In Windows, we want to use Windows API to get the file attributes
// for VBA interoperability.
@@ -2960,8 +2741,7 @@ void SbRtl_GetAttr(StarBASIC *, SbxArray & rPar, bool)
catch(const Exception & ) {}
if( !bExists )
{
- StarBASIC::Error( ERRCODE_BASIC_FILE_NOT_FOUND );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_FILE_NOT_FOUND );
}
bool bReadOnly = xSFI->isReadOnly( aPath );
@@ -2969,15 +2749,15 @@ void SbRtl_GetAttr(StarBASIC *, SbxArray & rPar, bool)
bool bDirectory = xSFI->isFolder( aPath );
if( bReadOnly )
{
- nFlags |= sal_uInt16(SbAttributes::READONLY);
+ nFlags |= SbAttributes::READONLY;
}
if( bHidden )
{
- nFlags |= sal_uInt16(SbAttributes::HIDDEN);
+ nFlags |= SbAttributes::HIDDEN;
}
if( bDirectory )
{
- nFlags |= sal_uInt16(SbAttributes::DIRECTORY);
+ nFlags |= SbAttributes::DIRECTORY;
}
}
catch(const Exception & )
@@ -2999,11 +2779,11 @@ void SbRtl_GetAttr(StarBASIC *, SbxArray & rPar, bool)
bool bDirectory = isFolder( aType );
if( bReadOnly )
{
- nFlags |= sal_uInt16(SbAttributes::READONLY);
+ nFlags |= SbAttributes::READONLY;
}
if( bDirectory )
{
- nFlags |= sal_uInt16(SbAttributes::DIRECTORY);
+ nFlags |= SbAttributes::DIRECTORY;
}
}
rPar.Get(0)->PutInteger(nFlags);
@@ -3128,8 +2908,7 @@ void SbRtl_EOF(StarBASIC *, SbxArray & rPar, bool)
SbiStream* pSbStrm = pIO->GetStream( nChannel );
if ( !pSbStrm )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_CHANNEL );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_CHANNEL );
}
bool beof;
SvStream* pSvStrm = pSbStrm->GetStrm();
@@ -3169,8 +2948,7 @@ void SbRtl_FileAttr(StarBASIC *, SbxArray & rPar, bool)
SbiStream* pSbStrm = pIO->GetStream( nChannel );
if ( !pSbStrm )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_CHANNEL );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_CHANNEL );
}
sal_Int16 nRet;
if (rPar.Get(2)->GetInteger() == 1)
@@ -3198,8 +2976,7 @@ void SbRtl_Loc(StarBASIC *, SbxArray & rPar, bool)
SbiStream* pSbStrm = pIO->GetStream( nChannel );
if ( !pSbStrm )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_CHANNEL );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_CHANNEL );
}
SvStream* pSvStrm = pSbStrm->GetStrm();
std::size_t nPos;
@@ -3243,8 +3020,7 @@ void SbRtl_Lof(StarBASIC *, SbxArray & rPar, bool)
SbiStream* pSbStrm = pIO->GetStream( nChannel );
if ( !pSbStrm )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_CHANNEL );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_CHANNEL );
}
SvStream* pSvStrm = pSbStrm->GetStrm();
sal_uInt64 const nLen = pSvStrm->TellEnd();
@@ -3259,16 +3035,14 @@ void SbRtl_Seek(StarBASIC *, SbxArray & rPar, bool)
int nArgs = static_cast<int>(rPar.Count());
if ( nArgs < 2 || nArgs > 3 )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
sal_Int16 nChannel = rPar.Get(1)->GetInteger();
SbiIoSystem* pIO = GetSbData()->pInst->GetIoSystem();
SbiStream* pSbStrm = pIO->GetStream( nChannel );
if ( !pSbStrm )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_CHANNEL );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_CHANNEL );
}
SvStream* pStrm = pSbStrm->GetStrm();
@@ -3287,8 +3061,7 @@ void SbRtl_Seek(StarBASIC *, SbxArray & rPar, bool)
sal_Int32 nPos = rPar.Get(2)->GetLong();
if ( nPos < 1 )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
nPos--; // Basic counts from 1, SvStreams count from 0
pSbStrm->SetExpandOnWriteTo( 0 );
@@ -3324,14 +3097,34 @@ void SbRtl_Format(StarBASIC *, SbxArray & rPar, bool)
}
}
-// https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/formatnumber-function
-void SbRtl_FormatNumber(StarBASIC*, SbxArray& rPar, bool)
+static bool IsMissing(SbxArray& rPar, const sal_uInt32 i)
+{
+ const sal_uInt32 nArgCount = rPar.Count();
+ if (nArgCount <= i)
+ return true;
+
+ SbxVariable* aPar = rPar.Get(i);
+ return (aPar->GetType() == SbxERROR && SbiRuntime::IsMissing(aPar, 1));
+}
+
+static sal_Int16 GetOptionalIntegerParamOrDefault(SbxArray& rPar, const sal_uInt32 i,
+ const sal_Int16 defaultValue)
+{
+ return IsMissing(rPar, i) ? defaultValue : rPar.Get(i)->GetInteger();
+}
+
+static OUString GetOptionalOUStringParamOrDefault(SbxArray& rPar, const sal_uInt32 i,
+ const OUString& defaultValue)
+{
+ return IsMissing(rPar, i) ? defaultValue : rPar.Get(i)->GetOUString();
+}
+
+static void lcl_FormatNumberPercent(SbxArray& rPar, bool isPercent)
{
const sal_uInt32 nArgCount = rPar.Count();
if (nArgCount < 2 || nArgCount > 6)
{
- StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
- return;
+ return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
}
// The UI locale never changes -> we can use static value here
@@ -3342,8 +3135,7 @@ void SbRtl_FormatNumber(StarBASIC*, SbxArray& rPar, bool)
nNumDigitsAfterDecimal = rPar.Get(2)->GetInteger();
if (nNumDigitsAfterDecimal < -1)
{
- StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
- return;
+ return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
}
else if (nNumDigitsAfterDecimal > 255)
nNumDigitsAfterDecimal %= 256;
@@ -3366,8 +3158,7 @@ void SbRtl_FormatNumber(StarBASIC*, SbxArray& rPar, bool)
// do nothing;
break;
default:
- StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
- return;
+ return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
}
}
@@ -3384,8 +3175,7 @@ void SbRtl_FormatNumber(StarBASIC*, SbxArray& rPar, bool)
bUseParensForNegativeNumbers = true;
break;
default:
- StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
- return;
+ return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
}
}
@@ -3402,53 +3192,59 @@ void SbRtl_FormatNumber(StarBASIC*, SbxArray& rPar, bool)
bGroupDigits = true;
break;
default:
- StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
- return;
+ return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
}
}
double fVal = rPar.Get(1)->GetDouble();
+ if (isPercent)
+ fVal *= 100;
const bool bNegative = fVal < 0;
if (bNegative)
fVal = fabs(fVal); // Always work with non-negatives, to easily handle leading zero
static const sal_Unicode decSep = localeData.getNumDecimalSep().toChar();
- OUString aResult = rtl::math::doubleToUString(
+ OUStringBuffer aResult;
+ rtl::math::doubleToUStringBuffer(aResult,
fVal, rtl_math_StringFormat_F, nNumDigitsAfterDecimal, decSep,
bGroupDigits ? localeData.getDigitGrouping().getConstArray() : nullptr,
localeData.getNumThousandSep().toChar());
- if (!bIncludeLeadingDigit && aResult.getLength() > 1 && aResult.startsWith("0"))
- aResult = aResult.copy(1);
+ if (!bIncludeLeadingDigit && aResult.getLength() > 1)
+ aResult.stripStart('0');
if (nNumDigitsAfterDecimal > 0)
{
- sal_Int32 nActualDigits;
const sal_Int32 nSepPos = aResult.indexOf(decSep);
- if (nSepPos == -1)
- nActualDigits = 0;
- else
- nActualDigits = aResult.getLength() - nSepPos - 1;
// VBA allows up to 255 digits; rtl::math::doubleToUString outputs up to 15 digits
// for ~small numbers, so pad them as appropriate.
- if (nActualDigits < nNumDigitsAfterDecimal)
- {
- OUStringBuffer sBuf;
- comphelper::string::padToLength(sBuf, nNumDigitsAfterDecimal - nActualDigits, '0');
- aResult += sBuf;
- }
+ if (nSepPos >= 0)
+ comphelper::string::padToLength(aResult, nSepPos + nNumDigitsAfterDecimal + 1, '0');
}
if (bNegative)
{
if (bUseParensForNegativeNumbers)
- aResult = "(" + aResult + ")";
+ aResult.insert(0, '(').append(')');
else
- aResult = "-" + aResult;
+ aResult.insert(0, '-');
}
+ if (isPercent)
+ aResult.append('%');
+ rPar.Get(0)->PutString(aResult.makeStringAndClear());
+}
- rPar.Get(0)->PutString(aResult);
+// https://docs.microsoft.com/en-us/office/vba/Language/Reference/User-Interface-Help/formatnumber-function
+void SbRtl_FormatNumber(StarBASIC*, SbxArray& rPar, bool)
+{
+ return lcl_FormatNumberPercent(rPar, false);
+}
+
+// https://docs.microsoft.com/en-us/office/vba/Language/Reference/User-Interface-Help/formatpercent-function
+void SbRtl_FormatPercent(StarBASIC*, SbxArray& rPar, bool)
+{
+ return lcl_FormatNumberPercent(rPar, true);
}
namespace {
@@ -3479,7 +3275,11 @@ struct RandomNumberGenerator
}
};
-class theRandomNumberGenerator : public rtl::Static<RandomNumberGenerator, theRandomNumberGenerator> {};
+RandomNumberGenerator& theRandomNumberGenerator()
+{
+ static RandomNumberGenerator theGenerator;
+ return theGenerator;
+}
}
@@ -3492,7 +3292,7 @@ void SbRtl_Randomize(StarBASIC *, SbxArray & rPar, bool)
if (rPar.Count() == 2)
{
int nSeed = static_cast<int>(rPar.Get(1)->GetInteger());
- theRandomNumberGenerator::get().global_rng.seed(nSeed);
+ theRandomNumberGenerator().global_rng.seed(nSeed);
}
// without parameter, no need to do anything - RNG is seeded at first use
}
@@ -3506,7 +3306,7 @@ void SbRtl_Rnd(StarBASIC *, SbxArray & rPar, bool)
else
{
std::uniform_real_distribution<double> dist(0.0, 1.0);
- double const tmp(dist(theRandomNumberGenerator::get().global_rng));
+ double const tmp(dist(theRandomNumberGenerator().global_rng));
rPar.Get(0)->PutDouble(tmp);
}
}
@@ -3531,6 +3331,13 @@ void SbRtl_Shell(StarBASIC *, SbxArray & rPar, bool)
}
else
{
+ // Just go straight to error in this case
+ if (comphelper::LibreOfficeKit::isActive())
+ {
+ StarBASIC::Error(ERRCODE_BASIC_FILE_NOT_FOUND);
+ return;
+ }
+
oslProcessOption nOptions = osl_Process_SEARCHPATH | osl_Process_DETACHED;
OUString aCmdLine = rPar.Get(1)->GetOUString();
@@ -3543,30 +3350,21 @@ void SbRtl_Shell(StarBASIC *, SbxArray & rPar, bool)
aCmdLine += " " + tmp;
}
}
- else if( aCmdLine.isEmpty() )
- {
- // avoid special treatment (empty list)
- aCmdLine += " ";
- }
sal_Int32 nLen = aCmdLine.getLength();
// #55735 if there are parameters, they have to be separated
// #72471 also separate the single parameters
std::vector<OUString> aTokenVector;
- OUString aToken;
- sal_Int32 i = 0;
- sal_Unicode c;
- while( i < nLen )
+ for (sal_Int32 i = 0; i < nLen;)
{
- for ( ;; ++i )
+ sal_Unicode c = aCmdLine[i];
+ if (c == ' ' || c == '\t')
{
- c = aCmdLine[ i ];
- if ( c != ' ' && c != '\t' )
- {
- break;
- }
+ ++i;
+ continue;
}
+ OUString aToken;
if( c == '\"' || c == '\'' )
{
sal_Int32 iFoundPos = aCmdLine.indexOf( c, i + 1 );
@@ -3605,6 +3403,9 @@ void SbRtl_Shell(StarBASIC *, SbxArray & rPar, bool)
}
// #55735 / #72471 end
+ if (aTokenVector.empty())
+ return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
+
sal_Int16 nWinStyle = 0;
if( nArgCount >= 3 )
{
@@ -3699,62 +3500,62 @@ void SbRtl_VarType(StarBASIC *, SbxArray & rPar, bool)
}
// Exported function
-OUString getBasicTypeName( SbxDataType eType )
-{
- static const char* pTypeNames[] =
- {
- "Empty", // SbxEMPTY
- "Null", // SbxNULL
- "Integer", // SbxINTEGER
- "Long", // SbxLONG
- "Single", // SbxSINGLE
- "Double", // SbxDOUBLE
- "Currency", // SbxCURRENCY
- "Date", // SbxDATE
- "String", // SbxSTRING
- "Object", // SbxOBJECT
- "Error", // SbxERROR
- "Boolean", // SbxBOOL
- "Variant", // SbxVARIANT
- "DataObject", // SbxDATAOBJECT
- "Unknown Type",
- "Unknown Type",
- "Char", // SbxCHAR
- "Byte", // SbxBYTE
- "UShort", // SbxUSHORT
- "ULong", // SbxULONG
- "Long64", // SbxLONG64
- "ULong64", // SbxULONG64
- "Int", // SbxINT
- "UInt", // SbxUINT
- "Void", // SbxVOID
- "HResult", // SbxHRESULT
- "Pointer", // SbxPOINTER
- "DimArray", // SbxDIMARRAY
- "CArray", // SbxCARRAY
- "Userdef", // SbxUSERDEF
- "Lpstr", // SbxLPSTR
- "Lpwstr", // SbxLPWSTR
- "Unknown Type", // SbxCoreSTRING
- "WString", // SbxWSTRING
- "WChar", // SbxWCHAR
- "Int64", // SbxSALINT64
- "UInt64", // SbxSALUINT64
- "Decimal", // SbxDECIMAL
+const OUString & getBasicTypeName( SbxDataType eType )
+{
+ static constexpr OUString pTypeNames[] =
+ {
+ u"Empty"_ustr, // SbxEMPTY
+ u"Null"_ustr, // SbxNULL
+ u"Integer"_ustr, // SbxINTEGER
+ u"Long"_ustr, // SbxLONG
+ u"Single"_ustr, // SbxSINGLE
+ u"Double"_ustr, // SbxDOUBLE
+ u"Currency"_ustr, // SbxCURRENCY
+ u"Date"_ustr, // SbxDATE
+ u"String"_ustr, // SbxSTRING
+ u"Object"_ustr, // SbxOBJECT
+ u"Error"_ustr, // SbxERROR
+ u"Boolean"_ustr, // SbxBOOL
+ u"Variant"_ustr, // SbxVARIANT
+ u"DataObject"_ustr, // SbxDATAOBJECT
+ u"Unknown Type"_ustr,
+ u"Unknown Type"_ustr,
+ u"Char"_ustr, // SbxCHAR
+ u"Byte"_ustr, // SbxBYTE
+ u"UShort"_ustr, // SbxUSHORT
+ u"ULong"_ustr, // SbxULONG
+ u"Long64"_ustr, // SbxLONG64
+ u"ULong64"_ustr, // SbxULONG64
+ u"Int"_ustr, // SbxINT
+ u"UInt"_ustr, // SbxUINT
+ u"Void"_ustr, // SbxVOID
+ u"HResult"_ustr, // SbxHRESULT
+ u"Pointer"_ustr, // SbxPOINTER
+ u"DimArray"_ustr, // SbxDIMARRAY
+ u"CArray"_ustr, // SbxCARRAY
+ u"Userdef"_ustr, // SbxUSERDEF
+ u"Lpstr"_ustr, // SbxLPSTR
+ u"Lpwstr"_ustr, // SbxLPWSTR
+ u"Unknown Type"_ustr, // SbxCoreSTRING
+ u"WString"_ustr, // SbxWSTRING
+ u"WChar"_ustr, // SbxWCHAR
+ u"Int64"_ustr, // SbxSALINT64
+ u"UInt64"_ustr, // SbxSALUINT64
+ u"Decimal"_ustr, // SbxDECIMAL
};
size_t nPos = static_cast<size_t>(eType) & 0x0FFF;
- const size_t nTypeNameCount = SAL_N_ELEMENTS( pTypeNames );
+ const size_t nTypeNameCount = std::size( pTypeNames );
if ( nPos >= nTypeNameCount )
{
nPos = nTypeNameCount - 1;
}
- return OUString::createFromAscii(pTypeNames[nPos]);
+ return pTypeNames[nPos];
}
static OUString getObjectTypeName( SbxVariable* pVar )
{
- OUString sRet( "Object" );
+ OUString sRet( u"Object"_ustr );
if ( pVar )
{
SbxBase* pBaseObj = pVar->GetObject();
@@ -3796,7 +3597,7 @@ static OUString getObjectTypeName( SbxVariable* pVar )
{
try
{
- xInv->getValue( "$GetTypeName" ) >>= sRet;
+ xInv->getValue( u"$GetTypeName"_ustr ) >>= sRet;
}
catch(const Exception& )
{
@@ -3846,14 +3647,9 @@ void SbRtl_TypeName(StarBASIC *, SbxArray & rPar, bool)
void SbRtl_Len(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- const OUString& rStr = rPar.Get(1)->GetOUString();
- rPar.Get(0)->PutLong(rStr.getLength());
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ const OUString aStr = rPar.Get(1)->GetOUString();
+ rPar.Get(0)->PutLong(aStr.getLength());
}
void SbRtl_DDEInitiate(StarBASIC *, SbxArray & rPar, bool)
@@ -3861,15 +3657,14 @@ void SbRtl_DDEInitiate(StarBASIC *, SbxArray & rPar, bool)
int nArgs = static_cast<int>(rPar.Count());
if ( nArgs != 3 )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
- const OUString& rApp = rPar.Get(1)->GetOUString();
- const OUString& rTopic = rPar.Get(2)->GetOUString();
+ const OUString aApp = rPar.Get(1)->GetOUString();
+ const OUString aTopic = rPar.Get(2)->GetOUString();
SbiDdeControl* pDDE = GetSbData()->pInst->GetDdeControl();
size_t nChannel;
- ErrCode nDdeErr = pDDE->Initiate( rApp, rTopic, nChannel );
+ ErrCode nDdeErr = pDDE->Initiate( aApp, aTopic, nChannel );
if( nDdeErr )
{
StarBASIC::Error( nDdeErr );
@@ -3904,8 +3699,7 @@ void SbRtl_DDETerminateAll(StarBASIC *, SbxArray & rPar, bool)
int nArgs = static_cast<int>(rPar.Count());
if ( nArgs != 1 )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
SbiDdeControl* pDDE = GetSbData()->pInst->GetDdeControl();
@@ -3921,14 +3715,13 @@ void SbRtl_DDERequest(StarBASIC *, SbxArray & rPar, bool)
int nArgs = static_cast<int>(rPar.Count());
if ( nArgs != 3 )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
size_t nChannel = rPar.Get(1)->GetInteger();
- const OUString& rItem = rPar.Get(2)->GetOUString();
+ const OUString aItem = rPar.Get(2)->GetOUString();
SbiDdeControl* pDDE = GetSbData()->pInst->GetDdeControl();
OUString aResult;
- ErrCode nDdeErr = pDDE->Request( nChannel, rItem, aResult );
+ ErrCode nDdeErr = pDDE->Request( nChannel, aItem, aResult );
if( nDdeErr )
{
StarBASIC::Error( nDdeErr );
@@ -3945,13 +3738,12 @@ void SbRtl_DDEExecute(StarBASIC *, SbxArray & rPar, bool)
int nArgs = static_cast<int>(rPar.Count());
if ( nArgs != 3 )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
size_t nChannel = rPar.Get(1)->GetInteger();
- const OUString& rCommand = rPar.Get(2)->GetOUString();
+ const OUString aCommand = rPar.Get(2)->GetOUString();
SbiDdeControl* pDDE = GetSbData()->pInst->GetDdeControl();
- ErrCode nDdeErr = pDDE->Execute( nChannel, rCommand );
+ ErrCode nDdeErr = pDDE->Execute( nChannel, aCommand );
if( nDdeErr )
{
StarBASIC::Error( nDdeErr );
@@ -3964,14 +3756,13 @@ void SbRtl_DDEPoke(StarBASIC *, SbxArray & rPar, bool)
int nArgs = static_cast<int>(rPar.Count());
if ( nArgs != 4 )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
size_t nChannel = rPar.Get(1)->GetInteger();
- const OUString& rItem = rPar.Get(2)->GetOUString();
- const OUString& rData = rPar.Get(3)->GetOUString();
+ const OUString aItem = rPar.Get(2)->GetOUString();
+ const OUString aData = rPar.Get(3)->GetOUString();
SbiDdeControl* pDDE = GetSbData()->pInst->GetDdeControl();
- ErrCode nDdeErr = pDDE->Poke( nChannel, rItem, rData );
+ ErrCode nDdeErr = pDDE->Poke( nChannel, aItem, aData );
if( nDdeErr )
{
StarBASIC::Error( nDdeErr );
@@ -3983,8 +3774,7 @@ void SbRtl_FreeFile(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 1)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
SbiIoSystem* pIO = GetSbData()->pInst->GetIoSystem();
short nChannel = 1;
@@ -4005,56 +3795,42 @@ void SbRtl_LBound(StarBASIC *, SbxArray & rPar, bool)
{
const sal_uInt32 nParCount = rPar.Count();
if ( nParCount != 3 && nParCount != 2 )
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
SbxBase* pParObj = rPar.Get(1)->GetObject();
SbxDimArray* pArr = dynamic_cast<SbxDimArray*>( pParObj );
- if( pArr )
- {
- sal_Int32 nLower, nUpper;
- short nDim = (nParCount == 3) ? static_cast<short>(rPar.Get(2)->GetInteger()) : 1;
- if (!pArr->GetDim(nDim, nLower, nUpper))
- StarBASIC::Error( ERRCODE_BASIC_OUT_OF_RANGE );
- else
- rPar.Get(0)->PutLong(nLower);
- }
- else
- StarBASIC::Error( ERRCODE_BASIC_MUST_HAVE_DIMS );
+ if( !pArr )
+ return StarBASIC::Error( ERRCODE_BASIC_MUST_HAVE_DIMS );
+
+ sal_Int32 nLower, nUpper;
+ short nDim = (nParCount == 3) ? static_cast<short>(rPar.Get(2)->GetInteger()) : 1;
+ if (!pArr->GetDim(nDim, nLower, nUpper))
+ return StarBASIC::Error( ERRCODE_BASIC_OUT_OF_RANGE );
+ rPar.Get(0)->PutLong(nLower);
}
void SbRtl_UBound(StarBASIC *, SbxArray & rPar, bool)
{
const sal_uInt32 nParCount = rPar.Count();
if ( nParCount != 3 && nParCount != 2 )
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
SbxBase* pParObj = rPar.Get(1)->GetObject();
SbxDimArray* pArr = dynamic_cast<SbxDimArray*>( pParObj );
- if( pArr )
- {
- sal_Int32 nLower, nUpper;
- short nDim = (nParCount == 3) ? static_cast<short>(rPar.Get(2)->GetInteger()) : 1;
- if (!pArr->GetDim(nDim, nLower, nUpper))
- StarBASIC::Error( ERRCODE_BASIC_OUT_OF_RANGE );
- else
- rPar.Get(0)->PutLong(nUpper);
- }
- else
- StarBASIC::Error( ERRCODE_BASIC_MUST_HAVE_DIMS );
+ if( !pArr )
+ return StarBASIC::Error( ERRCODE_BASIC_MUST_HAVE_DIMS );
+
+ sal_Int32 nLower, nUpper;
+ short nDim = (nParCount == 3) ? static_cast<short>(rPar.Get(2)->GetInteger()) : 1;
+ if (!pArr->GetDim(nDim, nLower, nUpper))
+ return StarBASIC::Error( ERRCODE_BASIC_OUT_OF_RANGE );
+ rPar.Get(0)->PutLong(nUpper);
}
void SbRtl_RGB(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 4)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
sal_Int32 nRed = rPar.Get(1)->GetInteger() & 0xFF;
sal_Int32 nGreen = rPar.Get(2)->GetInteger() & 0xFF;
@@ -4103,31 +3879,61 @@ void SbRtl_QBColor(StarBASIC *, SbxArray & rPar, bool)
if (rPar.Count() != 2)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
sal_Int16 nCol = rPar.Get(1)->GetInteger();
if( nCol < 0 || nCol > 15 )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
sal_Int32 nRGB = pRGB[ nCol ];
rPar.Get(0)->PutLong(nRGB);
}
+static std::vector<sal_uInt8> byteArray2Vec(SbxArray* pArr)
+{
+ std::vector<sal_uInt8> result;
+ if (pArr)
+ {
+ const sal_uInt32 nCount = pArr->Count();
+ result.reserve(nCount + 1); // to avoid reallocation when padding in vbFromUnicode
+ for (sal_uInt32 i = 0; i < nCount; i++)
+ result.push_back(pArr->Get(i)->GetByte());
+ }
+ return result;
+}
+
+// Makes sure to get the byte array if passed, or the string converted to the bytes using
+// StringToByteArray in basic/source/sbx/sbxstr.cxx
+static std::vector<sal_uInt8> getByteArray(const SbxValue& val)
+{
+ if (val.GetFullType() == SbxOBJECT)
+ if (auto pObj = val.GetObject())
+ if (pObj->GetType() == (SbxARRAY | SbxBYTE))
+ if (auto pArr = dynamic_cast<SbxArray*>(pObj))
+ return byteArray2Vec(pArr);
+
+ // Convert to string
+ tools::SvRef<SbxValue> pStringValue(new SbxValue(SbxSTRING));
+ *pStringValue = val;
+
+ // Convert string to byte array
+ tools::SvRef<SbxValue> pValue(new SbxValue(SbxOBJECT));
+ pValue->PutObject(new SbxArray(SbxBYTE));
+ *pValue = *pStringValue; // Does the magic of conversion of strings to byte arrays
+ return byteArray2Vec(dynamic_cast<SbxArray*>(pValue->GetObject()));
+}
+
// StrConv(string, conversion, LCID)
void SbRtl_StrConv(StarBASIC *, SbxArray & rPar, bool)
{
const sal_uInt32 nArgCount = rPar.Count() - 1;
if( nArgCount < 2 || nArgCount > 3 )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
- OUString aOldStr = rPar.Get(1)->GetOUString();
sal_Int32 nConversion = rPar.Get(2)->GetLong();
LanguageType nLanguage = LANGUAGE_SYSTEM;
if (nArgCount == 3)
@@ -4135,127 +3941,101 @@ void SbRtl_StrConv(StarBASIC *, SbxArray & rPar, bool)
sal_Int32 lcid = rPar.Get(3)->GetLong();
nLanguage = LanguageType(lcid);
}
- OUString sLanguage = LanguageTag(nLanguage).getLanguage();
- rtl_TextEncoding encodingVal = utl_getWinTextEncodingFromLangStr(sLanguage);
- sal_Int32 nOldLen = aOldStr.getLength();
- if( nOldLen == 0 )
+ if (nConversion == ooo::vba::VbStrConv::vbUnicode) // This mode does not combine
{
- // null string,return
- rPar.Get(0)->PutString(aOldStr);
+ // Assume that the passed byte array is encoded in the defined encoding, convert to
+ // UTF-16 and store as string. Passed strings are converted to byte array first.
+ auto inArray = getByteArray(*rPar.Get(1));
+ std::string_view s(reinterpret_cast<char*>(inArray.data()), inArray.size() / sizeof(char));
+ const auto encoding = utl_getWinTextEncodingFromLangStr(LanguageTag(nLanguage).getBcp47());
+ OUString aOUStr = OStringToOUString(s, encoding);
+ rPar.Get(0)->PutString(aOUStr);
return;
}
- TransliterationFlags nType = TransliterationFlags::NONE;
- if ( (nConversion & 0x03) == 3 ) // vbProperCase
- {
- const CharClass& rCharClass = GetCharClass();
- aOldStr = rCharClass.titlecase( aOldStr.toAsciiLowerCase(), 0, nOldLen );
- }
- else if ( (nConversion & 0x01) == 1 ) // vbUpperCase
- {
- nType |= TransliterationFlags::LOWERCASE_UPPERCASE;
- }
- else if ( (nConversion & 0x02) == 2 ) // vbLowerCase
- {
- nType |= TransliterationFlags::UPPERCASE_LOWERCASE;
- }
- if ( (nConversion & 0x04) == 4 ) // vbWide
- {
- nType |= TransliterationFlags::HALFWIDTH_FULLWIDTH;
- }
- else if ( (nConversion & 0x08) == 8 ) // vbNarrow
- {
- nType |= TransliterationFlags::FULLWIDTH_HALFWIDTH;
- }
- if ( (nConversion & 0x10) == 16) // vbKatakana
- {
- nType |= TransliterationFlags::HIRAGANA_KATAKANA;
- }
- else if ( (nConversion & 0x20) == 32 ) // vbHiragana
- {
- nType |= TransliterationFlags::KATAKANA_HIRAGANA;
- }
- OUString aNewStr( aOldStr );
- if( nType != TransliterationFlags::NONE )
+ if (nConversion == ooo::vba::VbStrConv::vbFromUnicode) // This mode does not combine
{
- uno::Reference< uno::XComponentContext > xContext = getProcessComponentContext();
- ::utl::TransliterationWrapper aTransliterationWrapper( xContext, nType );
- uno::Sequence<sal_Int32> aOffsets;
- aTransliterationWrapper.loadModuleIfNeeded( nLanguage );
- aNewStr = aTransliterationWrapper.transliterate( aOldStr, nLanguage, 0, nOldLen, &aOffsets );
- }
+ // Assume that the passed byte array is UTF-16-encoded (system-endian), convert to specified
+ // encoding and store as byte array. Passed strings are converted to byte array first.
+ auto inArray = getByteArray(*rPar.Get(1));
+ while (inArray.size() % sizeof(sal_Unicode))
+ inArray.push_back('\0');
+ std::u16string_view s(reinterpret_cast<sal_Unicode*>(inArray.data()),
+ inArray.size() / sizeof(sal_Unicode));
+ const auto encoding = utl_getWinTextEncodingFromLangStr(LanguageTag(nLanguage).getBcp47());
+ OString aOStr = OUStringToOString(s, encoding);
+ const sal_Int32 lb = IsBaseIndexOne() ? 1 : 0;
+ const sal_Int32 ub = lb + aOStr.getLength() - 1;
+ SbxDimArray* pArray = new SbxDimArray(SbxBYTE);
+ pArray->unoAddDim(lb, ub);
- if ( (nConversion & 0x40) == 64 ) // vbUnicode
- {
- // convert the string to byte string, preserving unicode (2 bytes per character)
- sal_Int32 nSize = aNewStr.getLength()*2;
- const sal_Unicode* pSrc = aNewStr.getStr();
- std::unique_ptr<char[]> pChar(new char[nSize+1]);
- for( sal_Int32 i=0; i < nSize; i++ )
+ for (sal_Int32 i = 0; i < aOStr.getLength(); ++i)
{
- pChar[i] = static_cast< char >( (i%2) ? ((*pSrc) >> 8) & 0xff : (*pSrc) & 0xff );
- if( i%2 )
- {
- pSrc++;
- }
+ SbxVariable* pNew = new SbxVariable(SbxBYTE);
+ pNew->PutByte(aOStr[i]);
+ pArray->Put(pNew, i);
}
- pChar[nSize] = '\0';
- OString aOStr(pChar.get());
- // there is no concept about default codepage in unix. so it is incorrectly in unix
- OUString aOUStr = OStringToOUString(aOStr, encodingVal);
- rPar.Get(0)->PutString(aOUStr);
+ SbxVariable* retVar = rPar.Get(0);
+ SbxFlagBits nFlags = retVar->GetFlags();
+ retVar->ResetFlag(SbxFlagBits::Fixed);
+ retVar->PutObject(pArray);
+ retVar->SetFlags(nFlags);
+ retVar->SetParameters(nullptr);
return;
}
- else if ( (nConversion & 0x80) == 128 ) // vbFromUnicode
+
+ std::vector<TransliterationFlags> aTranslitSet;
+ auto check = [&nConversion, &aTranslitSet](sal_Int32 conv, TransliterationFlags flag)
{
- // there is no concept about default codepage in unix. so it is incorrectly in unix
- OString aOStr = OUStringToOString(aNewStr, encodingVal);
- const char* pChar = aOStr.getStr();
- sal_Int32 nArraySize = aOStr.getLength();
- SbxDimArray* pArray = new SbxDimArray(SbxBYTE);
- bool bIncIndex = IsBaseIndexOne();
- if(nArraySize)
+ if ((nConversion & conv) != conv)
+ return false;
+
+ aTranslitSet.push_back(flag);
+ nConversion &= ~conv;
+ return true;
+ };
+
+ // Check mutually exclusive bits together
+
+ if (!check(ooo::vba::VbStrConv::vbProperCase, TransliterationFlags::TITLE_CASE))
+ if (!check(ooo::vba::VbStrConv::vbUpperCase, TransliterationFlags::LOWERCASE_UPPERCASE))
+ check(ooo::vba::VbStrConv::vbLowerCase, TransliterationFlags::UPPERCASE_LOWERCASE);
+
+ if (!check(ooo::vba::VbStrConv::vbWide, TransliterationFlags::HALFWIDTH_FULLWIDTH))
+ check(ooo::vba::VbStrConv::vbNarrow, TransliterationFlags::FULLWIDTH_HALFWIDTH);
+
+ if (!check(ooo::vba::VbStrConv::vbKatakana, TransliterationFlags::HIRAGANA_KATAKANA))
+ check(ooo::vba::VbStrConv::vbHiragana, TransliterationFlags::KATAKANA_HIRAGANA);
+
+ if (nConversion) // unknown / incorrectly combined bits
+ return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
+
+ OUString aStr = rPar.Get(1)->GetOUString();
+ if (!aStr.isEmpty() && !aTranslitSet.empty())
+ {
+ const uno::Reference< uno::XComponentContext >& xContext = getProcessComponentContext();
+
+ for (auto transliterationFlag : aTranslitSet)
{
- if( bIncIndex )
+ if (transliterationFlag == TransliterationFlags::TITLE_CASE)
{
- pArray->AddDim(1, nArraySize);
+ // TransliterationWrapper only handles the first character of the passed string
+ // when handling TITLE_CASE; see Transliteration_titlecase::transliterateImpl in
+ // i18npool/source/transliteration/transliteration_body.cxx
+ CharClass aCharClass{ xContext, LanguageTag(nLanguage) };
+ aStr = aCharClass.titlecase(aCharClass.lowercase(aStr));
}
else
{
- pArray->AddDim(0, nArraySize - 1);
- }
- }
- else
- {
- pArray->unoAddDim(0, -1);
- }
-
- for( sal_Int32 i=0; i< nArraySize; i++)
- {
- SbxVariable* pNew = new SbxVariable( SbxBYTE );
- pNew->PutByte(*pChar);
- pChar++;
- pNew->SetFlag( SbxFlagBits::Write );
- sal_Int32 aIdx[1];
- aIdx[0] = i;
- if( bIncIndex )
- {
- ++aIdx[0];
+ utl::TransliterationWrapper aWrapper(xContext, transliterationFlag);
+ aStr = aWrapper.transliterate(aStr, nLanguage, 0, aStr.getLength(), nullptr);
}
- pArray->Put(pNew, aIdx);
}
-
- SbxVariableRef refVar = rPar.Get(0);
- SbxFlagBits nFlags = refVar->GetFlags();
- refVar->ResetFlag( SbxFlagBits::Fixed );
- refVar->PutObject( pArray );
- refVar->SetFlags( nFlags );
- refVar->SetParameters( nullptr );
- return;
}
- rPar.Get(0)->PutString(aNewStr);
+
+ rPar.Get(0)->PutString(aStr);
}
@@ -4263,8 +4043,7 @@ void SbRtl_Beep(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 1)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
Sound::Beep();
}
@@ -4273,8 +4052,7 @@ void SbRtl_Load(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 2)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
@@ -4288,7 +4066,7 @@ void SbRtl_Load(StarBASIC *, SbxArray & rPar, bool)
}
else if (SbxObject* pSbxObj = dynamic_cast<SbxObject*>(pObj))
{
- SbxVariable* pVar = pSbxObj->Find("Load", SbxClassType::Method);
+ SbxVariable* pVar = pSbxObj->Find(u"Load"_ustr, SbxClassType::Method);
if( pVar )
{
pVar->GetInteger();
@@ -4301,8 +4079,7 @@ void SbRtl_Unload(StarBASIC *, SbxArray & rPar, bool)
rPar.Get(0)->PutEmpty();
if (rPar.Count() != 2)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
@@ -4316,7 +4093,7 @@ void SbRtl_Unload(StarBASIC *, SbxArray & rPar, bool)
}
else if (SbxObject *pSbxObj = dynamic_cast<SbxObject*>(pObj))
{
- SbxVariable* pVar = pSbxObj->Find("Unload", SbxClassType::Method);
+ SbxVariable* pVar = pSbxObj->Find(u"Unload"_ustr, SbxClassType::Method);
if( pVar )
{
pVar->GetInteger();
@@ -4328,8 +4105,7 @@ void SbRtl_LoadPicture(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 2)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
OUString aFileURL = getFullPath(rPar.Get(1)->GetOUString());
@@ -4352,8 +4128,7 @@ void SbRtl_SavePicture(StarBASIC *, SbxArray & rPar, bool)
rPar.Get(0)->PutEmpty();
if (rPar.Count() != 3)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
SbxBase* pObj = rPar.Get(1)->GetObject();
@@ -4371,40 +4146,23 @@ void SbRtl_MsgBox(StarBASIC *, SbxArray & rPar, bool)
const sal_uInt32 nArgCount = rPar.Count();
if( nArgCount < 2 || nArgCount > 6 )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
- WinBits nType = 0; // MB_OK
- if( nArgCount >= 3 )
- nType = static_cast<WinBits>(rPar.Get(2)->GetInteger());
- WinBits nStyle = nType;
- nStyle &= 15; // delete bits 4-16
- if (nStyle > 5)
- nStyle = 0;
-
- enum BasicResponse
- {
- Ok = 1,
- Cancel = 2,
- Abort = 3,
- Retry = 4,
- Ignore = 5,
- Yes = 6,
- No = 7
- };
- OUString aMsg = rPar.Get(1)->GetOUString();
- OUString aTitle;
- if( nArgCount >= 4 )
+ // tdf#147529 - check for missing parameters
+ if (IsMissing(rPar, 1))
{
- aTitle = rPar.Get(3)->GetOUString();
- }
- else
- {
- aTitle = Application::GetDisplayName();
+ return StarBASIC::Error(ERRCODE_BASIC_NOT_OPTIONAL);
}
- WinBits nDialogType = nType & (16+32+64);
+ // tdf#151012 - initialize optional parameters with their default values (number of buttons)
+ sal_Int16 nType = GetOptionalIntegerParamOrDefault(rPar, 2, SbMB::OK);
+
+ OUString aMsg = rPar.Get(1)->GetOUString();
+ // tdf#151012 - initialize optional parameters with their default values (title of dialog box)
+ OUString aTitle = GetOptionalOUStringParamOrDefault(rPar, 3, Application::GetDisplayName());
+
+ sal_Int16 nDialogType = nType & (SbMB::ICONSTOP | SbMB::ICONQUESTION | SbMB::ICONINFORMATION);
SolarMutexGuard aSolarGuard;
weld::Widget* pParent = Application::GetDefDialogParent();
@@ -4413,85 +4171,64 @@ void SbRtl_MsgBox(StarBASIC *, SbxArray & rPar, bool)
switch (nDialogType)
{
- case 16:
+ case SbMB::ICONSTOP:
eType = VclMessageType::Error;
break;
- case 32:
+ case SbMB::ICONQUESTION:
eType = VclMessageType::Question;
break;
- case 48:
+ case SbMB::ICONEXCLAMATION:
eType = VclMessageType::Warning;
break;
- case 64:
+ case SbMB::ICONINFORMATION:
eType = VclMessageType::Info;
break;
}
std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pParent,
- eType, VclButtonsType::NONE, aMsg));
+ eType, VclButtonsType::NONE, aMsg, GetpApp()));
- switch (nStyle)
+ std::vector<std::pair<StandardButtonType, sal_Int16>> buttons;
+ switch (nType & 0x0F) // delete bits 4-16
{
- case 0: // MB_OK
+ case SbMB::OK:
default:
- xBox->add_button(GetStandardText(StandardButtonType::OK), BasicResponse::Ok);
+ buttons.emplace_back(StandardButtonType::OK, SbMB::Response::OK);
break;
- case 1: // MB_OKCANCEL
- xBox->add_button(GetStandardText(StandardButtonType::OK), BasicResponse::Ok);
- xBox->add_button(GetStandardText(StandardButtonType::Cancel), BasicResponse::Cancel);
-
- if (nType & 256 || nType & 512)
- xBox->set_default_response(BasicResponse::Cancel);
- else
- xBox->set_default_response(BasicResponse::Ok);
-
+ case SbMB::OKCANCEL:
+ buttons.emplace_back(StandardButtonType::OK, SbMB::Response::OK);
+ buttons.emplace_back(StandardButtonType::Cancel, SbMB::Response::CANCEL);
break;
- case 2: // MB_ABORTRETRYIGNORE
- xBox->add_button(GetStandardText(StandardButtonType::Abort), BasicResponse::Abort);
- xBox->add_button(GetStandardText(StandardButtonType::Retry), BasicResponse::Retry);
- xBox->add_button(GetStandardText(StandardButtonType::Ignore), BasicResponse::Ignore);
-
- if (nType & 256)
- xBox->set_default_response(BasicResponse::Retry);
- else if (nType & 512)
- xBox->set_default_response(BasicResponse::Ignore);
- else
- xBox->set_default_response(BasicResponse::Cancel);
-
+ case SbMB::ABORTRETRYIGNORE:
+ buttons.emplace_back(StandardButtonType::Abort, SbMB::Response::ABORT);
+ buttons.emplace_back(StandardButtonType::Retry, SbMB::Response::RETRY);
+ buttons.emplace_back(StandardButtonType::Ignore, SbMB::Response::IGNORE);
break;
- case 3: // MB_YESNOCANCEL
- xBox->add_button(GetStandardText(StandardButtonType::Yes), BasicResponse::Yes);
- xBox->add_button(GetStandardText(StandardButtonType::No), BasicResponse::No);
- xBox->add_button(GetStandardText(StandardButtonType::Cancel), BasicResponse::Cancel);
-
- if (nType & 256 || nType & 512)
- xBox->set_default_response(BasicResponse::Cancel);
- else
- xBox->set_default_response(BasicResponse::Yes);
-
+ case SbMB::YESNOCANCEL:
+ buttons.emplace_back(StandardButtonType::Yes, SbMB::Response::YES);
+ buttons.emplace_back(StandardButtonType::No, SbMB::Response::NO);
+ buttons.emplace_back(StandardButtonType::Cancel, SbMB::Response::CANCEL);
break;
- case 4: // MB_YESNO
- xBox->add_button(GetStandardText(StandardButtonType::Yes), BasicResponse::Yes);
- xBox->add_button(GetStandardText(StandardButtonType::No), BasicResponse::No);
-
- if (nType & 256 || nType & 512)
- xBox->set_default_response(BasicResponse::No);
- else
- xBox->set_default_response(BasicResponse::Yes);
-
+ case SbMB::YESNO:
+ buttons.emplace_back(StandardButtonType::Yes, SbMB::Response::YES);
+ buttons.emplace_back(StandardButtonType::No, SbMB::Response::NO);
break;
- case 5: // MB_RETRYCANCEL
- xBox->add_button(GetStandardText(StandardButtonType::Retry), BasicResponse::Retry);
- xBox->add_button(GetStandardText(StandardButtonType::Cancel), BasicResponse::Cancel);
-
- if (nType & 256 || nType & 512)
- xBox->set_default_response(BasicResponse::Cancel);
- else
- xBox->set_default_response(BasicResponse::Retry);
-
+ case SbMB::RETRYCANCEL:
+ buttons.emplace_back(StandardButtonType::Retry, SbMB::Response::RETRY);
+ buttons.emplace_back(StandardButtonType::Cancel, SbMB::Response::CANCEL);
break;
}
+ for (auto [buttonType, buttonResponse] : buttons)
+ xBox->add_button(GetStandardText(buttonType), buttonResponse);
+
+ std::size_t default_button = 0;
+ if (nType & SbMB::DEFBUTTON2)
+ default_button = 1;
+ else if (nType & SbMB::DEFBUTTON3)
+ default_button = 2;
+ xBox->set_default_response(buttons[std::min(default_button, buttons.size() - 1)].second);
+
xBox->set_title(aTitle);
sal_Int16 nRet = xBox->run();
rPar.Get(0)->PutInteger(nRet);
@@ -4503,7 +4240,7 @@ void SbRtl_SetAttr(StarBASIC *, SbxArray & rPar, bool)
if (rPar.Count() == 3)
{
OUString aStr = rPar.Get(1)->GetOUString();
- SbAttributes nFlags = static_cast<SbAttributes>(rPar.Get(2)->GetInteger());
+ sal_Int16 nFlags = rPar.Get(2)->GetInteger();
if( hasUno() )
{
@@ -4514,7 +4251,7 @@ void SbRtl_SetAttr(StarBASIC *, SbxArray & rPar, bool)
{
bool bReadOnly = bool(nFlags & SbAttributes::READONLY);
xSFI->setReadOnly( aStr, bReadOnly );
- bool bHidden = bool(nFlags & SbAttributes::HIDDEN);
+ bool bHidden = bool(nFlags & SbAttributes::HIDDEN);
xSFI->setHidden( aStr, bHidden );
}
catch(const Exception & )
@@ -4609,8 +4346,7 @@ void SbRtl_Partition(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 5)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
sal_Int32 nNumber = rPar.Get(1)->GetLong();
@@ -4620,8 +4356,7 @@ void SbRtl_Partition(StarBASIC *, SbxArray & rPar, bool)
if( nStart < 0 || nStop <= nStart || nInterval < 1 )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
// the Partition function inserts leading spaces before lowervalue and uppervalue
@@ -4687,28 +4422,10 @@ void SbRtl_Partition(StarBASIC *, SbxArray & rPar, bool)
#endif
-static tools::Long GetDayDiff( const Date& rDate )
-{
- Date aRefDate( 1,1,1900 );
- tools::Long nDiffDays;
- if ( aRefDate > rDate )
- {
- nDiffDays = aRefDate - rDate;
- nDiffDays *= -1;
- }
- else
- {
- nDiffDays = rDate - aRefDate;
- }
- nDiffDays += 2; // adjustment VisualBasic: 1.Jan.1900 == 2
- return nDiffDays;
-}
-
sal_Int16 implGetDateYear( double aDate )
{
- Date aRefDate( 1,1,1900 );
- tools::Long nDays = static_cast<tools::Long>(aDate);
- nDays -= 2; // standardize: 1.1.1900 => 0.0
+ Date aRefDate(1899'12'30);
+ sal_Int32 nDays = static_cast<sal_Int32>(aDate);
aRefDate.AddDays( nDays );
sal_Int16 nRet = aRefDate.GetYear();
return nRet;
@@ -4820,40 +4537,34 @@ bool implDateSerial( sal_Int16 nYear, sal_Int16 nMonth, sal_Int16 nDay,
}
}
- tools::Long nDiffDays = GetDayDiff( aCurDate );
- rdRet = static_cast<double>(nDiffDays);
+ rdRet = GetDayDiff(aCurDate);
return true;
}
-double implTimeSerial( sal_Int16 nHours, sal_Int16 nMinutes, sal_Int16 nSeconds )
+double implTimeSerial(sal_Int16 nHours, sal_Int16 nMinutes, sal_Int16 nSeconds,
+ sal_Int32 nMilliSeconds)
{
- return
- static_cast<double>( nHours * ::tools::Time::secondPerHour +
- nMinutes * ::tools::Time::secondPerMinute +
- nSeconds)
- /
- static_cast<double>( ::tools::Time::secondPerDay );
+ return (nHours * ::tools::Time::milliSecPerHour + nMinutes * ::tools::Time::milliSecPerMinute
+ + nSeconds * ::tools::Time::milliSecPerSec + nMilliSeconds)
+ / static_cast<double>(::tools::Time::milliSecPerDay);
}
-bool implDateTimeSerial( sal_Int16 nYear, sal_Int16 nMonth, sal_Int16 nDay,
- sal_Int16 nHour, sal_Int16 nMinute, sal_Int16 nSecond,
- double& rdRet )
+bool implDateTimeSerial(sal_Int16 nYear, sal_Int16 nMonth, sal_Int16 nDay, sal_Int16 nHour,
+ sal_Int16 nMinute, sal_Int16 nSecond, sal_Int32 nMilliSecond, double& rdRet)
{
double dDate;
if(!implDateSerial(nYear, nMonth, nDay, false/*bUseTwoDigitYear*/, SbDateCorrection::None, dDate))
return false;
- rdRet += dDate + implTimeSerial(nHour, nMinute, nSecond);
+ rdRet += dDate + implTimeSerial(nHour, nMinute, nSecond, nMilliSecond);
return true;
}
sal_Int16 implGetMinute( double dDate )
{
- double nFrac = dDate - floor( dDate );
- nFrac *= 86400.0;
- sal_Int32 nSeconds = static_cast<sal_Int32>(nFrac + 0.5);
- sal_Int16 nTemp = static_cast<sal_Int16>(nSeconds % 3600);
- sal_Int16 nMin = nTemp / 60;
- return nMin;
+ double nFrac = (dDate - floor(dDate)) * ::tools::Time::milliSecPerDay;
+ sal_uInt64 nMilliSeconds = static_cast<sal_uInt64>(nFrac + 0.5);
+ return static_cast<sal_Int16>((nMilliSeconds / ::tools::Time::milliSecPerMinute)
+ % ::tools::Time::minutePerHour);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/runtime/methods1.cxx b/basic/source/runtime/methods1.cxx
index 117e84d73000..e1fd37e45018 100644
--- a/basic/source/runtime/methods1.cxx
+++ b/basic/source/runtime/methods1.cxx
@@ -24,7 +24,6 @@
#include <cstddef>
-#include <stdlib.h>
#include <rtl/math.hxx>
#include <vcl/svapp.hxx>
#include <vcl/mapmod.hxx>
@@ -38,6 +37,7 @@
#include <tools/fract.hxx>
#include <o3tl/temporary.hxx>
#include <osl/file.hxx>
+#include <osl/process.h>
#include <sbobjmod.hxx>
#include <basic/sbuno.hxx>
@@ -61,6 +61,7 @@
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/i18n/LocaleCalendar2.hpp>
#include <com/sun/star/sheet/XFunctionAccess.hpp>
+
#include <memory>
using namespace comphelper;
@@ -120,7 +121,7 @@ void SbRtl_CallByName(StarBASIC *, SbxArray & rPar, bool)
return;
}
- // 2. parameter is ProcedureName
+ // 2. parameter is ProcName
OUString aNameStr = rPar.Get(2)->GetOUString();
// 3. parameter is CallType
@@ -277,15 +278,11 @@ void SbRtl_CDec(StarBASIC *, SbxArray & rPar, bool)
void SbRtl_CDate(StarBASIC *, SbxArray & rPar, bool) // JSM
{
double nVal = 0.0;
- if (rPar.Count() == 2)
- {
- SbxVariable* pSbxVariable = rPar.Get(1);
- nVal = pSbxVariable->GetDate();
- }
- else
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ SbxVariable* pSbxVariable = rPar.Get(1);
+ nVal = pSbxVariable->GetDate();
rPar.Get(0)->PutDate(nVal);
}
@@ -321,30 +318,22 @@ void SbRtl_CDbl(StarBASIC *, SbxArray & rPar, bool) // JSM
void SbRtl_CInt(StarBASIC *, SbxArray & rPar, bool) // JSM
{
sal_Int16 nVal = 0;
- if (rPar.Count() == 2)
- {
- SbxVariable* pSbxVariable = rPar.Get(1);
- nVal = pSbxVariable->GetInteger();
- }
- else
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ SbxVariable* pSbxVariable = rPar.Get(1);
+ nVal = pSbxVariable->GetInteger();
rPar.Get(0)->PutInteger(nVal);
}
void SbRtl_CLng(StarBASIC *, SbxArray & rPar, bool) // JSM
{
sal_Int32 nVal = 0;
- if (rPar.Count() == 2)
- {
- SbxVariable* pSbxVariable = rPar.Get(1);
- nVal = pSbxVariable->GetLong();
- }
- else
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ SbxVariable* pSbxVariable = rPar.Get(1);
+ nVal = pSbxVariable->GetLong();
rPar.Get(0)->PutLong(nVal);
}
@@ -380,16 +369,11 @@ void SbRtl_CSng(StarBASIC *, SbxArray & rPar, bool) // JSM
void SbRtl_CStr(StarBASIC *, SbxArray & rPar, bool) // JSM
{
- OUString aString;
- if (rPar.Count() == 2)
- {
- SbxVariable* pSbxVariable = rPar.Get(1);
- aString = pSbxVariable->GetOUString();
- }
- else
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ SbxVariable* pSbxVariable = rPar.Get(1);
+ OUString aString = pSbxVariable->GetOUString();
rPar.Get(0)->PutString(aString);
}
@@ -410,112 +394,86 @@ void SbRtl_CVar(StarBASIC *, SbxArray & rPar, bool) // JSM
void SbRtl_CVErr(StarBASIC *, SbxArray & rPar, bool)
{
- sal_Int16 nErrCode = 0;
- if (rPar.Count() == 2)
- {
- SbxVariable* pSbxVariable = rPar.Get(1);
- nErrCode = pSbxVariable->GetInteger();
- }
- else
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ SbxVariable* pSbxVariable = rPar.Get(1);
+ sal_Int16 nErrCode = pSbxVariable->GetInteger();
rPar.Get(0)->PutErr(nErrCode);
}
void SbRtl_Iif(StarBASIC *, SbxArray & rPar, bool) // JSM
{
- if (rPar.Count() == 4)
+ if (rPar.Count() != 4)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ if (rPar.Get(1)->GetBool())
{
- if (rPar.Get(1)->GetBool())
- {
- *rPar.Get(0) = *rPar.Get(2);
- }
- else
- {
- *rPar.Get(0) = *rPar.Get(3);
- }
+ *rPar.Get(0) = *rPar.Get(2);
}
else
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ *rPar.Get(0) = *rPar.Get(3);
}
+
}
void SbRtl_GetSystemType(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 1)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
// Removed for SRC595
- rPar.Get(0)->PutInteger(-1);
- }
+ rPar.Get(0)->PutInteger(-1);
}
void SbRtl_GetGUIType(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 1)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
// 17.7.2000 Make simple solution for testtool / fat office
#if defined(_WIN32)
- rPar.Get(0)->PutInteger(1);
+ rPar.Get(0)->PutInteger(1);
#elif defined(UNX)
- rPar.Get(0)->PutInteger(4);
+ rPar.Get(0)->PutInteger(4);
#else
- rPar.Get(0)->PutInteger(-1);
+ rPar.Get(0)->PutInteger(-1);
#endif
- }
}
void SbRtl_Red(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- sal_Int32 nRGB = rPar.Get(1)->GetLong();
- nRGB &= 0x00FF0000;
- nRGB >>= 16;
- rPar.Get(0)->PutInteger(static_cast<sal_Int16>(nRGB));
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ sal_Int32 nRGB = rPar.Get(1)->GetLong();
+ nRGB &= 0x00FF0000;
+ nRGB >>= 16;
+ rPar.Get(0)->PutInteger(static_cast<sal_Int16>(nRGB));
+
}
void SbRtl_Green(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- sal_Int32 nRGB = rPar.Get(1)->GetLong();
- nRGB &= 0x0000FF00;
- nRGB >>= 8;
- rPar.Get(0)->PutInteger(static_cast<sal_Int16>(nRGB));
- }
+
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ sal_Int32 nRGB = rPar.Get(1)->GetLong();
+ nRGB &= 0x0000FF00;
+ nRGB >>= 8;
+ rPar.Get(0)->PutInteger(static_cast<sal_Int16>(nRGB));
}
void SbRtl_Blue(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- sal_Int32 nRGB = rPar.Get(1)->GetLong();
- nRGB &= 0x000000FF;
- rPar.Get(0)->PutInteger(static_cast<sal_Int16>(nRGB));
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ sal_Int32 nRGB = rPar.Get(1)->GetLong();
+ nRGB &= 0x000000FF;
+ rPar.Get(0)->PutInteger(static_cast<sal_Int16>(nRGB));
}
@@ -525,7 +483,7 @@ void SbRtl_Switch(StarBASIC *, SbxArray & rPar, bool)
if( !(nCount & 0x0001 ))
{
// number of arguments must be odd
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
sal_uInt32 nCurExpr = 1;
while( nCurExpr < (nCount-1) )
@@ -545,10 +503,8 @@ void SbRtl_Switch(StarBASIC *, SbxArray & rPar, bool)
void Wait_Impl( bool bDurationBased, SbxArray& rPar )
{
if (rPar.Count() != 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
tools::Long nWait = 0;
if ( bDurationBased )
{
@@ -561,11 +517,9 @@ void Wait_Impl( bool bDurationBased, SbxArray& rPar )
{
nWait = rPar.Get(1)->GetLong();
}
+
if( nWait < 0 )
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
Timer aTimer("basic Wait_Impl");
aTimer.SetTimeout( nWait );
@@ -602,14 +556,10 @@ void SbRtl_DoEvents(StarBASIC *, SbxArray & rPar, bool)
void SbRtl_GetGUIVersion(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 1)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- // Removed for SRC595
- rPar.Get(0)->PutLong(-1);
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ // Removed for SRC595
+ rPar.Get(0)->PutLong(-1);
}
void SbRtl_Choose(StarBASIC *, SbxArray & rPar, bool)
@@ -634,13 +584,10 @@ void SbRtl_Trim(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- OUString aStr(comphelper::string::strip(rPar.Get(1)->GetOUString(), ' '));
- rPar.Get(0)->PutString(aStr);
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
+ OUString aStr(comphelper::string::strip(rPar.Get(1)->GetOUString(), ' '));
+ rPar.Get(0)->PutString(aStr);
}
void SbRtl_GetSolarVersion(StarBASIC *, SbxArray & rPar, bool)
@@ -808,11 +755,9 @@ void SbRtl_DimArray(StarBASIC *, SbxArray & rPar, bool)
// 1st parameter = the object's name as string
void SbRtl_FindObject(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
- }
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
OUString aNameStr = rPar.Get(1)->GetOUString();
@@ -831,11 +776,9 @@ void SbRtl_FindObject(StarBASIC *, SbxArray & rPar, bool)
// 2nd parameter = the property's name as string
void SbRtl_FindPropertyObject(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() < 3)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
- }
+ if (rPar.Count() != 3)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
SbxBase* pObjVar = rPar.Get(1)->GetObject();
SbxObject* pObj = nullptr;
@@ -936,20 +879,20 @@ static bool lcl_WriteSbxVariable( const SbxVariable& rVar, SvStream* pStrm,
case SbxSTRING:
case SbxLPSTR:
{
- const OUString& rStr = rVar.GetOUString();
+ const OUString aStr = rVar.GetOUString();
if( !bBinary || bIsArray )
{
if( bIsVariant )
{
pStrm->WriteUInt16( SbxSTRING );
}
- pStrm->WriteUniOrByteString( rStr, osl_getThreadTextEncoding() );
+ pStrm->WriteUniOrByteString( aStr, osl_getThreadTextEncoding() );
}
else
{
// without any length information! without end-identifier!
// What does that mean for Unicode?! Choosing conversion to ByteString...
- OString aByteStr(OUStringToOString(rStr, osl_getThreadTextEncoding()));
+ OString aByteStr(OUStringToOString(aStr, osl_getThreadTextEncoding()));
pStrm->WriteOString( aByteStr );
}
}
@@ -1107,10 +1050,8 @@ static bool lcl_WriteReadSbxArray( SbxDimArray& rArr, SvStream* pStrm,
static void PutGet( SbxArray& rPar, bool bPut )
{
if (rPar.Count() != 4)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
sal_Int16 nFileNo = rPar.Get(1)->GetInteger();
SbxVariable* pVar2 = rPar.Get(2);
SbxDataType eType2 = pVar2->GetType();
@@ -1126,10 +1067,7 @@ static void PutGet( SbxArray& rPar, bool bPut )
SbiStream* pSbStrm = pIO->GetStream( nFileNo );
if ( !pSbStrm || !(pSbStrm->GetMode() & (SbiStreamFlags::Binary | SbiStreamFlags::Random)) )
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_CHANNEL );
- return;
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_CHANNEL );
SvStream* pStrm = pSbStrm->GetStrm();
bool bRandom = pSbStrm->IsRandom();
@@ -1192,19 +1130,10 @@ void SbRtl_Get(StarBASIC *, SbxArray & rPar, bool)
void SbRtl_Environ(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
OUString aResult;
- // should be ANSI but that's not possible under Win16 in the DLL
- OString aByteStr(OUStringToOString(rPar.Get(1)->GetOUString(),
- osl_getThreadTextEncoding()));
- const char* pEnvStr = getenv(aByteStr.getStr());
- if ( pEnvStr )
- {
- aResult = OUString(pEnvStr, strlen(pEnvStr), osl_getThreadTextEncoding());
- }
+ osl_getEnvironment(rPar.Get(1)->GetOUString().pData, &aResult.pData);
rPar.Get(0)->PutString(aResult);
}
@@ -1241,20 +1170,15 @@ static double GetDialogZoomFactor( bool bX, tools::Long nValue )
void SbRtl_GetDialogZoomFactorX(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
rPar.Get(0)->PutDouble(GetDialogZoomFactor(true, rPar.Get(1)->GetLong()));
}
void SbRtl_GetDialogZoomFactorY(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
rPar.Get(0)->PutDouble(GetDialogZoomFactor(false, rPar.Get(1)->GetLong()));
}
@@ -1271,109 +1195,94 @@ void SbRtl_EnableReschedule(StarBASIC *, SbxArray & rPar, bool)
void SbRtl_GetSystemTicks(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 1)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
rPar.Get(0)->PutLong(tools::Time::GetSystemTicks());
}
void SbRtl_GetPathSeparator(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 1)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
rPar.Get(0)->PutString(OUString(SAL_PATHDELIMITER));
}
void SbRtl_ResolvePath(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() == 2)
- {
- OUString aStr = rPar.Get(1)->GetOUString();
- rPar.Get(0)->PutString(aStr);
- }
- else
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ OUString aStr = rPar.Get(1)->GetOUString();
+ rPar.Get(0)->PutString(aStr);
}
void SbRtl_TypeLen(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ SbxDataType eType = rPar.Get(1)->GetType();
+ sal_Int16 nLen = 0;
+ switch( eType )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- SbxDataType eType = rPar.Get(1)->GetType();
- sal_Int16 nLen = 0;
- switch( eType )
- {
- case SbxEMPTY:
- case SbxNULL:
- case SbxVECTOR:
- case SbxARRAY:
- case SbxBYREF:
- case SbxVOID:
- case SbxHRESULT:
- case SbxPOINTER:
- case SbxDIMARRAY:
- case SbxCARRAY:
- case SbxUSERDEF:
- nLen = 0;
- break;
+ case SbxEMPTY:
+ case SbxNULL:
+ case SbxVECTOR:
+ case SbxARRAY:
+ case SbxBYREF:
+ case SbxVOID:
+ case SbxHRESULT:
+ case SbxPOINTER:
+ case SbxDIMARRAY:
+ case SbxCARRAY:
+ case SbxUSERDEF:
+ case SbxOBJECT:
+ case SbxVARIANT:
+ case SbxDATAOBJECT:
+ nLen = 0;
+ break;
- case SbxINTEGER:
- case SbxERROR:
- case SbxUSHORT:
- case SbxINT:
- case SbxUINT:
- nLen = 2;
- break;
+ case SbxINTEGER:
+ case SbxERROR:
+ case SbxUSHORT:
+ case SbxINT:
+ case SbxUINT:
+ nLen = 2;
+ break;
- case SbxLONG:
- case SbxSINGLE:
- case SbxULONG:
- nLen = 4;
- break;
+ case SbxLONG:
+ case SbxSINGLE:
+ case SbxULONG:
+ nLen = 4;
+ break;
- case SbxDOUBLE:
- case SbxCURRENCY:
- case SbxDATE:
- case SbxSALINT64:
- case SbxSALUINT64:
- nLen = 8;
- break;
+ case SbxDOUBLE:
+ case SbxCURRENCY:
+ case SbxDATE:
+ case SbxSALINT64:
+ case SbxSALUINT64:
+ nLen = 8;
+ break;
- case SbxOBJECT:
- case SbxVARIANT:
- case SbxDATAOBJECT:
- nLen = 0;
+ case SbxCHAR:
+ case SbxBYTE:
+ case SbxBOOL:
+ nLen = 1;
break;
- case SbxCHAR:
- case SbxBYTE:
- case SbxBOOL:
- nLen = 1;
- break;
-
- case SbxLPSTR:
- case SbxLPWSTR:
- case SbxCoreSTRING:
- case SbxSTRING:
- nLen = static_cast<sal_Int16>(rPar.Get(1)->GetOUString().getLength());
- break;
+ case SbxLPSTR:
+ case SbxLPWSTR:
+ case SbxCoreSTRING:
+ case SbxSTRING:
+ nLen = static_cast<sal_Int16>(rPar.Get(1)->GetOUString().getLength());
+ break;
- default:
- nLen = 0;
- break;
- }
- rPar.Get(0)->PutInteger(nLen);
+ default:
+ nLen = 0;
+ break;
}
+ rPar.Get(0)->PutInteger(nLen);
}
@@ -1454,44 +1363,37 @@ void SbRtl_GlobalScope(StarBASIC * pBasic, SbxArray & rPar, bool)
// Helper functions to convert Url from/to system paths
void SbRtl_ConvertToUrl(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() == 2)
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ OUString aStr = rPar.Get(1)->GetOUString();
+ INetURLObject aURLObj( aStr, INetProtocol::File );
+ OUString aFileURL = aURLObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
+ if( aFileURL.isEmpty() )
{
- OUString aStr = rPar.Get(1)->GetOUString();
- INetURLObject aURLObj( aStr, INetProtocol::File );
- OUString aFileURL = aURLObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
- if( aFileURL.isEmpty() )
- {
- osl::File::getFileURLFromSystemPath(aStr, aFileURL);
- }
- if( aFileURL.isEmpty() )
- {
- aFileURL = aStr;
- }
- rPar.Get(0)->PutString(aFileURL);
+ osl::File::getFileURLFromSystemPath(aStr, aFileURL);
}
- else
+ if( aFileURL.isEmpty() )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ aFileURL = aStr;
}
+ rPar.Get(0)->PutString(aFileURL);
+
}
void SbRtl_ConvertFromUrl(StarBASIC *, SbxArray & rPar, bool)
{
- if (rPar.Count() == 2)
- {
- OUString aStr = rPar.Get(1)->GetOUString();
- OUString aSysPath;
- ::osl::File::getSystemPathFromFileURL( aStr, aSysPath );
- if( aSysPath.isEmpty() )
- {
- aSysPath = aStr;
- }
- rPar.Get(0)->PutString(aSysPath);
- }
- else
+ if (rPar.Count() != 2)
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
+ OUString aStr = rPar.Get(1)->GetOUString();
+ OUString aSysPath;
+ ::osl::File::getSystemPathFromFileURL( aStr, aSysPath );
+ if( aSysPath.isEmpty() )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+ aSysPath = aStr;
}
+ rPar.Get(0)->PutString(aSysPath);
}
@@ -1505,47 +1407,40 @@ void SbRtl_Join(StarBASIC *, SbxArray & rPar, bool)
{
sal_uInt32 nParCount = rPar.Count();
if ( nParCount != 3 && nParCount != 2 )
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
SbxBase* pParObj = rPar.Get(1)->GetObject();
SbxDimArray* pArr = dynamic_cast<SbxDimArray*>( pParObj );
- if( pArr )
+ if( !pArr )
+ return StarBASIC::Error( ERRCODE_BASIC_MUST_HAVE_DIMS );
+
+ if (pArr->GetDims() != 1)
+ return StarBASIC::Error( ERRCODE_BASIC_WRONG_DIMS ); // Syntax Error?!
+
+ OUString aDelim;
+ if( nParCount == 3 )
{
- if (pArr->GetDims() != 1)
- {
- StarBASIC::Error( ERRCODE_BASIC_WRONG_DIMS ); // Syntax Error?!
- return;
- }
- OUString aDelim;
- if( nParCount == 3 )
- {
- aDelim = rPar.Get(2)->GetOUString();
- }
- else
- {
- aDelim = " ";
- }
- OUStringBuffer aRetStr(32);
- sal_Int32 nLower, nUpper;
- pArr->GetDim(1, nLower, nUpper);
- sal_Int32 aIdx[1];
- for (aIdx[0] = nLower; aIdx[0] <= nUpper; ++aIdx[0])
- {
- OUString aStr = pArr->Get(aIdx)->GetOUString();
- aRetStr.append(aStr);
- if (aIdx[0] != nUpper)
- {
- aRetStr.append(aDelim);
- }
- }
- rPar.Get(0)->PutString(aRetStr.makeStringAndClear());
+ aDelim = rPar.Get(2)->GetOUString();
}
else
{
- StarBASIC::Error( ERRCODE_BASIC_MUST_HAVE_DIMS );
+ aDelim = " ";
}
+ OUStringBuffer aRetStr(32);
+ sal_Int32 nLower, nUpper;
+ pArr->GetDim(1, nLower, nUpper);
+ sal_Int32 aIdx[1];
+ for (aIdx[0] = nLower; aIdx[0] <= nUpper; ++aIdx[0])
+ {
+ OUString aStr = pArr->Get(aIdx)->GetOUString();
+ aRetStr.append(aStr);
+ if (aIdx[0] != nUpper)
+ {
+ aRetStr.append(aDelim);
+ }
+ }
+ rPar.Get(0)->PutString(aRetStr.makeStringAndClear());
+
}
@@ -1744,7 +1639,7 @@ void SbRtl_WeekdayName(StarBASIC *, SbxArray & rPar, bool)
void SbRtl_Weekday(StarBASIC *, SbxArray & rPar, bool)
{
sal_uInt32 nParCount = rPar.Count();
- if ( nParCount < 2 )
+ if ( nParCount < 2 || nParCount > 3 )
{
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
@@ -1805,13 +1700,13 @@ static IntervalInfo const * getIntervalInfo( const OUString& rStringCode )
{ INTERVAL_N, "n", 1.0 / 1440.0, true }, // Minute
{ INTERVAL_S, "s", 1.0 / 86400.0, true } // Second
};
- for( std::size_t i = 0; i != SAL_N_ELEMENTS(aIntervalTable); ++i )
- {
- if( rStringCode.equalsIgnoreAsciiCaseAscii(
- aIntervalTable[i].mStringCode ) )
- {
- return &aIntervalTable[i];
- }
+ auto const pred = [&rStringCode](const IntervalInfo &aInterval) {
+ return rStringCode.equalsIgnoreAsciiCaseAscii(aInterval.mStringCode);
+ };
+
+ auto intervalIter = std::find_if(std::begin(aIntervalTable), std::end(aIntervalTable), pred);
+ if(intervalIter != std::end(aIntervalTable)) {
+ return intervalIter;
}
return nullptr;
}
@@ -2416,7 +2311,7 @@ static void CallFunctionAccessFunction( const Sequence< Any >& aArgs, const OUSt
Reference< XMultiServiceFactory > xFactory( getProcessServiceFactory() );
if( xFactory.is() )
{
- xFunc.set( xFactory->createInstance("com.sun.star.sheet.FunctionAccess"), UNO_QUERY_THROW);
+ xFunc.set( xFactory->createInstance(u"com.sun.star.sheet.FunctionAccess"_ustr), UNO_QUERY_THROW);
}
}
Any aRet = xFunc->callFunction( sFuncName, aArgs );
@@ -2444,13 +2339,13 @@ void SbRtl_SYD(StarBASIC *, SbxArray & rPar, bool)
Sequence< Any > aParams
{
- makeAny(rPar.Get(1)->GetDouble()),
- makeAny(rPar.Get(2)->GetDouble()),
- makeAny(rPar.Get(3)->GetDouble()),
- makeAny(rPar.Get(4)->GetDouble())
+ Any(rPar.Get(1)->GetDouble()),
+ Any(rPar.Get(2)->GetDouble()),
+ Any(rPar.Get(3)->GetDouble()),
+ Any(rPar.Get(4)->GetDouble())
};
- CallFunctionAccessFunction(aParams, "SYD", rPar.Get(0));
+ CallFunctionAccessFunction(aParams, u"SYD"_ustr, rPar.Get(0));
}
void SbRtl_SLN(StarBASIC *, SbxArray & rPar, bool)
@@ -2467,12 +2362,12 @@ void SbRtl_SLN(StarBASIC *, SbxArray & rPar, bool)
Sequence< Any > aParams
{
- makeAny(rPar.Get(1)->GetDouble()),
- makeAny(rPar.Get(2)->GetDouble()),
- makeAny(rPar.Get(3)->GetDouble())
+ Any(rPar.Get(1)->GetDouble()),
+ Any(rPar.Get(2)->GetDouble()),
+ Any(rPar.Get(3)->GetDouble())
};
- CallFunctionAccessFunction(aParams, "SLN", rPar.Get(0));
+ CallFunctionAccessFunction(aParams, u"SLN"_ustr, rPar.Get(0));
}
void SbRtl_Pmt(StarBASIC *, SbxArray & rPar, bool)
@@ -2509,14 +2404,14 @@ void SbRtl_Pmt(StarBASIC *, SbxArray & rPar, bool)
Sequence< Any > aParams
{
- makeAny(rate),
- makeAny(nper),
- makeAny(pmt),
- makeAny(fv),
- makeAny(type)
+ Any(rate),
+ Any(nper),
+ Any(pmt),
+ Any(fv),
+ Any(type)
};
- CallFunctionAccessFunction(aParams, "Pmt", rPar.Get(0));
+ CallFunctionAccessFunction(aParams, u"Pmt"_ustr, rPar.Get(0));
}
void SbRtl_PPmt(StarBASIC *, SbxArray & rPar, bool)
@@ -2554,15 +2449,15 @@ void SbRtl_PPmt(StarBASIC *, SbxArray & rPar, bool)
Sequence< Any > aParams
{
- makeAny(rate),
- makeAny(per),
- makeAny(nper),
- makeAny(pv),
- makeAny(fv),
- makeAny(type)
+ Any(rate),
+ Any(per),
+ Any(nper),
+ Any(pv),
+ Any(fv),
+ Any(type)
};
- CallFunctionAccessFunction(aParams, "PPmt", rPar.Get(0));
+ CallFunctionAccessFunction(aParams, u"PPmt"_ustr, rPar.Get(0));
}
void SbRtl_PV(StarBASIC *, SbxArray & rPar, bool)
@@ -2599,14 +2494,14 @@ void SbRtl_PV(StarBASIC *, SbxArray & rPar, bool)
Sequence< Any > aParams
{
- makeAny(rate),
- makeAny(nper),
- makeAny(pmt),
- makeAny(fv),
- makeAny(type)
+ Any(rate),
+ Any(nper),
+ Any(pmt),
+ Any(fv),
+ Any(type)
};
- CallFunctionAccessFunction(aParams, "PV", rPar.Get(0));
+ CallFunctionAccessFunction(aParams, u"PV"_ustr, rPar.Get(0));
}
void SbRtl_NPV(StarBASIC *, SbxArray & rPar, bool)
@@ -2629,11 +2524,11 @@ void SbRtl_NPV(StarBASIC *, SbxArray & rPar, bool)
Sequence< Any > aParams
{
- makeAny(rPar.Get(1)->GetDouble()),
+ Any(rPar.Get(1)->GetDouble()),
aValues
};
- CallFunctionAccessFunction(aParams, "NPV", rPar.Get(0));
+ CallFunctionAccessFunction(aParams, u"NPV"_ustr, rPar.Get(0));
}
void SbRtl_NPer(StarBASIC *, SbxArray & rPar, bool)
@@ -2670,14 +2565,14 @@ void SbRtl_NPer(StarBASIC *, SbxArray & rPar, bool)
Sequence< Any > aParams
{
- makeAny(rate),
- makeAny(pmt),
- makeAny(pv),
- makeAny(fv),
- makeAny(type)
+ Any(rate),
+ Any(pmt),
+ Any(pv),
+ Any(fv),
+ Any(type)
};
- CallFunctionAccessFunction(aParams, "NPer", rPar.Get(0));
+ CallFunctionAccessFunction(aParams, u"NPer"_ustr, rPar.Get(0));
}
void SbRtl_MIRR(StarBASIC *, SbxArray & rPar, bool)
@@ -2703,11 +2598,11 @@ void SbRtl_MIRR(StarBASIC *, SbxArray & rPar, bool)
Sequence< Any > aParams
{
aValues,
- makeAny(rPar.Get(2)->GetDouble()),
- makeAny(rPar.Get(3)->GetDouble())
+ Any(rPar.Get(2)->GetDouble()),
+ Any(rPar.Get(3)->GetDouble())
};
- CallFunctionAccessFunction(aParams, "MIRR", rPar.Get(0));
+ CallFunctionAccessFunction(aParams, u"MIRR"_ustr, rPar.Get(0));
}
void SbRtl_IRR(StarBASIC *, SbxArray & rPar, bool)
@@ -2740,10 +2635,10 @@ void SbRtl_IRR(StarBASIC *, SbxArray & rPar, bool)
Sequence< Any > aParams
{
aValues,
- makeAny(guess)
+ Any(guess)
};
- CallFunctionAccessFunction(aParams, "IRR", rPar.Get(0));
+ CallFunctionAccessFunction(aParams, u"IRR"_ustr, rPar.Get(0));
}
void SbRtl_IPmt(StarBASIC *, SbxArray & rPar, bool)
@@ -2781,15 +2676,15 @@ void SbRtl_IPmt(StarBASIC *, SbxArray & rPar, bool)
Sequence< Any > aParams
{
- makeAny(rate),
- makeAny(per),
- makeAny(nper),
- makeAny(pv),
- makeAny(fv),
- makeAny(type)
+ Any(rate),
+ Any(per),
+ Any(nper),
+ Any(pv),
+ Any(fv),
+ Any(type)
};
- CallFunctionAccessFunction(aParams, "IPmt", rPar.Get(0));
+ CallFunctionAccessFunction(aParams, u"IPmt"_ustr, rPar.Get(0));
}
void SbRtl_FV(StarBASIC *, SbxArray & rPar, bool)
@@ -2826,14 +2721,14 @@ void SbRtl_FV(StarBASIC *, SbxArray & rPar, bool)
Sequence< Any > aParams
{
- makeAny(rate),
- makeAny(nper),
- makeAny(pmt),
- makeAny(pv),
- makeAny(type)
+ Any(rate),
+ Any(nper),
+ Any(pmt),
+ Any(pv),
+ Any(type)
};
- CallFunctionAccessFunction(aParams, "FV", rPar.Get(0));
+ CallFunctionAccessFunction(aParams, u"FV"_ustr, rPar.Get(0));
}
void SbRtl_DDB(StarBASIC *, SbxArray & rPar, bool)
@@ -2864,14 +2759,14 @@ void SbRtl_DDB(StarBASIC *, SbxArray & rPar, bool)
Sequence< Any > aParams
{
- makeAny(cost),
- makeAny(salvage),
- makeAny(life),
- makeAny(period),
- makeAny(factor)
+ Any(cost),
+ Any(salvage),
+ Any(life),
+ Any(period),
+ Any(factor)
};
- CallFunctionAccessFunction(aParams, "DDB", rPar.Get(0));
+ CallFunctionAccessFunction(aParams, u"DDB"_ustr, rPar.Get(0));
}
void SbRtl_Rate(StarBASIC *, SbxArray & rPar, bool)
@@ -2921,15 +2816,15 @@ void SbRtl_Rate(StarBASIC *, SbxArray & rPar, bool)
Sequence< Any > aParams
{
- makeAny(nper),
- makeAny(pmt),
- makeAny(pv),
- makeAny(fv),
- makeAny(type),
- makeAny(guess)
+ Any(nper),
+ Any(pmt),
+ Any(pv),
+ Any(fv),
+ Any(type),
+ Any(guess)
};
- CallFunctionAccessFunction(aParams, "Rate", rPar.Get(0));
+ CallFunctionAccessFunction(aParams, u"Rate"_ustr, rPar.Get(0));
}
void SbRtl_StrReverse(StarBASIC *, SbxArray & rPar, bool)
@@ -3024,9 +2919,8 @@ void SbRtl_Me(StarBASIC *, SbxArray & rPar, bool)
sal_Int16 implGetWeekDay( double aDate, bool bFirstDayParam, sal_Int16 nFirstDay )
{
- Date aRefDate( 1,1,1900 );
+ Date aRefDate(1899'12'30);
sal_Int32 nDays = static_cast<sal_Int32>(aDate);
- nDays -= 2; // normalize: 1.1.1900 => 0
aRefDate.AddDays( nDays);
DayOfWeek aDay = aRefDate.GetDayOfWeek();
sal_Int16 nDay;
diff --git a/basic/source/runtime/props.cxx b/basic/source/runtime/props.cxx
index f3d84a0127b5..3eccc378efee 100644
--- a/basic/source/runtime/props.cxx
+++ b/basic/source/runtime/props.cxx
@@ -21,7 +21,6 @@
#include <runtime.hxx>
#include <rtlproto.hxx>
#include <errobject.hxx>
-#include <basegfx/numeric/ftools.hxx>
// Properties and methods lay the return value down at Get (bWrite = sal_False)
@@ -49,8 +48,6 @@ void SbRtl_Err(StarBASIC *, SbxArray & rPar, bool bWrite)
}
}
-void SbRtl_False(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutBool(false); }
-
void SbRtl_Empty(StarBASIC *, SbxArray &, bool) {}
void SbRtl_Nothing(StarBASIC *, SbxArray & rPar, bool)
@@ -67,106 +64,4 @@ void SbRtl_Null(StarBASIC *, SbxArray & rPar, bool)
void SbRtl_PI(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutDouble(M_PI); }
-void SbRtl_True(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutBool(true); }
-
-void SbRtl_ATTR_NORMAL(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(0); }
-void SbRtl_ATTR_READONLY(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(1); }
-void SbRtl_ATTR_HIDDEN(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(2); }
-void SbRtl_ATTR_SYSTEM(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(4); }
-void SbRtl_ATTR_VOLUME(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(8); }
-void SbRtl_ATTR_DIRECTORY(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(16); }
-void SbRtl_ATTR_ARCHIVE(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(32); }
-
-void SbRtl_V_EMPTY(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(0); }
-void SbRtl_V_NULL(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(1); }
-void SbRtl_V_INTEGER(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(2); }
-void SbRtl_V_LONG(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(3); }
-void SbRtl_V_SINGLE(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(4); }
-void SbRtl_V_DOUBLE(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(5); }
-void SbRtl_V_CURRENCY(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(6); }
-void SbRtl_V_DATE(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(7); }
-void SbRtl_V_STRING(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(8); }
-
-void SbRtl_MB_OK(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(0); }
-void SbRtl_MB_OKCANCEL(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(1); }
-void SbRtl_MB_ABORTRETRYIGNORE(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(2); }
-void SbRtl_MB_YESNOCANCEL(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(3); }
-void SbRtl_MB_YESNO(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(4); }
-void SbRtl_MB_RETRYCANCEL(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(5); }
-void SbRtl_MB_ICONSTOP(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(16); }
-void SbRtl_MB_ICONQUESTION(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(32); }
-void SbRtl_MB_ICONEXCLAMATION(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(48); }
-void SbRtl_MB_ICONINFORMATION(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(64); }
-void SbRtl_MB_DEFBUTTON1(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(0); }
-void SbRtl_MB_DEFBUTTON2(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(256); }
-void SbRtl_MB_DEFBUTTON3(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(512); }
-void SbRtl_MB_APPLMODAL(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(0); }
-void SbRtl_MB_SYSTEMMODAL(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(4096); }
-
-void SbRtl_IDOK(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(1); }
-
-void SbRtl_IDCANCEL(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(2); }
-void SbRtl_IDABORT(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(3); }
-void SbRtl_IDRETRY(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(4); }
-void SbRtl_IDYES(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(6); }
-void SbRtl_IDNO(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(7); }
-
-void SbRtl_CF_TEXT(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(1); }
-void SbRtl_CF_BITMAP(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(2); }
-void SbRtl_CF_METAFILEPICT(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(3); }
-
-void SbRtl_TYP_AUTHORFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(7); }
-void SbRtl_TYP_CHAPTERFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(4); }
-void SbRtl_TYP_CONDTXTFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(27); }
-void SbRtl_TYP_DATEFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(0); }
-void SbRtl_TYP_DBFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(19); }
-void SbRtl_TYP_DBNAMEFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(3); }
-void SbRtl_TYP_DBNEXTSETFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(24); }
-void SbRtl_TYP_DBNUMSETFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(25); }
-void SbRtl_TYP_DBSETNUMBERFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(26); }
-void SbRtl_TYP_DDEFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(14); }
-void SbRtl_TYP_DOCINFOFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(18); }
-void SbRtl_TYP_DOCSTATFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(6); }
-void SbRtl_TYP_EXTUSERFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(30); }
-void SbRtl_TYP_FILENAMEFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(2); }
-void SbRtl_TYP_FIXDATEFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(31); }
-void SbRtl_TYP_FIXTIMEFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(32); }
-void SbRtl_TYP_FORMELFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(10); }
-void SbRtl_TYP_GETFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(9); }
-void SbRtl_TYP_GETREFFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(13); }
-void SbRtl_TYP_HIDDENPARAFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(17); }
-void SbRtl_TYP_HIDDENTXTFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(11); }
-void SbRtl_TYP_INPUTFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(16); }
-void SbRtl_TYP_MACROFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(15); }
-void SbRtl_TYP_NEXTPAGEFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(28); }
-void SbRtl_TYP_PAGENUMBERFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(5); }
-void SbRtl_TYP_POSTITFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(21); }
-void SbRtl_TYP_PREVPAGEFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(29); }
-void SbRtl_TYP_SEQFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(23); }
-void SbRtl_TYP_SETFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(8); }
-void SbRtl_TYP_SETINPFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(33); }
-void SbRtl_TYP_SETREFFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(12); }
-void SbRtl_TYP_TEMPLNAMEFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(22); }
-void SbRtl_TYP_TIMEFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(1); }
-void SbRtl_TYP_USERFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(20); }
-void SbRtl_TYP_USRINPFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(34); }
-void SbRtl_TYP_SETREFPAGEFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(35); }
-void SbRtl_TYP_GETREFPAGEFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(36); }
-void SbRtl_TYP_INTERNETFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(37); }
-
-void SbRtl_SET_ON(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(1); }
-void SbRtl_SET_OFF(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(0); }
-void SbRtl_TOGGLE(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(2); }
-
-void SbRtl_FRAMEANCHORPAGE(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(1); }
-void SbRtl_FRAMEANCHORPARA(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(14); }
-void SbRtl_FRAMEANCHORCHAR(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(15); }
-
-void SbRtl_CLEAR_ALLTABS(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(2); }
-void SbRtl_CLEAR_TAB(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(1); }
-void SbRtl_SET_TAB(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(0); }
-
-void SbRtl_TYP_JUMPEDITFLD(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(38); }
-
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx
index bad307f27dd6..92ebafec70da 100644
--- a/basic/source/runtime/runtime.cxx
+++ b/basic/source/runtime/runtime.cxx
@@ -36,8 +36,9 @@
#include <sal/log.hxx>
#include <tools/wldcrd.hxx>
-#include <tools/diagnose_ex.h>
+#include <comphelper/diagnose_ex.hxx>
+#include <utility>
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
@@ -48,9 +49,7 @@
#include <svl/numformat.hxx>
#include <svl/zforlist.hxx>
-#include <i18nutil/searchopt.hxx>
-#include <unotools/syslocale.hxx>
-#include <unotools/textsearch.hxx>
+#include <unicode/regex.h>
#include <basic/sbuno.hxx>
@@ -75,11 +74,12 @@ using com::sun::star::uno::Reference;
using namespace com::sun::star::uno;
using namespace com::sun::star::container;
using namespace com::sun::star::lang;
-using namespace com::sun::star::beans;
using namespace com::sun::star::script;
using namespace ::com::sun::star;
+#if HAVE_FEATURE_SCRIPTING
+
static void lcl_clearImpl( SbxVariableRef const & refVar, SbxDataType const & eType );
static void lcl_eraseImpl( SbxVariableRef const & refVar, bool bVBAEnabled );
@@ -89,17 +89,16 @@ class ScopedWritableGuard
{
public:
ScopedWritableGuard(const SbxVariableRef& rVar, bool bMakeWritable)
- : m_rVar(rVar)
- , m_bReset(bMakeWritable && !rVar->CanWrite())
+ : m_rVar(bMakeWritable && !rVar->CanWrite() ? rVar : SbxVariableRef())
{
- if (m_bReset)
+ if (m_rVar)
{
m_rVar->SetFlag(SbxFlagBits::Write);
}
}
~ScopedWritableGuard()
{
- if (m_bReset)
+ if (m_rVar)
{
m_rVar->ResetFlag(SbxFlagBits::Write);
}
@@ -107,17 +106,13 @@ public:
private:
SbxVariableRef m_rVar;
- bool m_bReset;
};
}
bool SbiRuntime::isVBAEnabled()
{
- bool bResult = false;
SbiInstance* pInst = GetSbData()->pInst;
- if ( pInst && GetSbData()->pInst->pRun )
- bResult = pInst->pRun->bVBAEnabled;
- return bResult;
+ return pInst && pInst->pRun && pInst->pRun->bVBAEnabled;
}
void StarBASIC::SetVBAEnabled( bool bEnabled )
@@ -130,21 +125,15 @@ void StarBASIC::SetVBAEnabled( bool bEnabled )
bool StarBASIC::isVBAEnabled() const
{
- if ( bDocBasic )
- {
- if( SbiRuntime::isVBAEnabled() )
- return true;
- return bVBAEnabled;
- }
- return false;
+ return bDocBasic && (bVBAEnabled || SbiRuntime::isVBAEnabled());
}
struct SbiArgv { // Argv stack:
SbxArrayRef refArgv; // Argv
short nArgc; // Argc
- SbiArgv(SbxArrayRef const & refArgv_, short nArgc_) :
- refArgv(refArgv_),
+ SbiArgv(SbxArrayRef refArgv_, short nArgc_) :
+ refArgv(std::move(refArgv_)),
nArgc(nArgc_) {}
};
@@ -289,7 +278,7 @@ const SbiRuntime::pStep2 SbiRuntime::aStep2[] = {// all opcodes with two operand
// SbiRTLData
SbiRTLData::SbiRTLData()
- : nDirFlags(SbAttributes::NONE)
+ : nDirFlags(SbAttributes::NORMAL)
, nCurDirPos(0)
{
}
@@ -384,6 +373,8 @@ SbiDllMgr* SbiInstance::GetDllMgr()
return pDllMgr.get();
}
+#endif
+
// #39629 create NumberFormatter with the help of a static method now
std::shared_ptr<SvNumberFormatter> const & SbiInstance::GetNumberFormatter()
{
@@ -476,6 +467,7 @@ std::shared_ptr<SvNumberFormatter> SbiInstance::PrepareNumberFormatter( sal_uInt
return pNumberFormatter;
}
+#if HAVE_FEATURE_SCRIPTING
// Let engine run. If Flags == BasicDebugFlags::Continue, take Flags over
@@ -598,32 +590,14 @@ SbMethod* SbiInstance::GetCaller( sal_uInt16 nLevel )
SbiRuntime::SbiRuntime( SbModule* pm, SbMethod* pe, sal_uInt32 nStart )
: rBasic( *static_cast<StarBASIC*>(pm->pParent) ), pInst( GetSbData()->pInst ),
- pMod( pm ), pMeth( pe ), pImg( pMod->pImage.get() ), mpExtCaller(nullptr), m_nLastTime(0)
+ pMod( pm ), pMeth( pe ), pImg( pMod->pImage.get() )
{
nFlags = pe ? pe->GetDebugFlags() : BasicDebugFlags::NONE;
pIosys = pInst->GetIoSystem();
- pForStk = nullptr;
- pError = nullptr;
- pErrCode =
- pErrStmnt =
- pRestart = nullptr;
- pNext = nullptr;
pCode =
pStmnt = pImg->GetCode() + nStart;
- bRun =
- bError = true;
- bInError = false;
- bBlocked = false;
- nLine = 0;
- nCol1 = 0;
- nCol2 = 0;
- nExprLvl = 0;
- nArgc = 0;
- nError = ERRCODE_NONE;
- nForLvl = 0;
- nOps = 0;
refExprStk = new SbxArray;
- SetVBAEnabled( pMod->IsVBACompat() );
+ SetVBAEnabled( pMod->IsVBASupport() );
SetParameters( pe ? pe->GetParameters() : nullptr );
}
@@ -706,6 +680,7 @@ void SbiRuntime::SetParameters( SbxArray* pParams )
}
SbxVariable* v = pParams->Get(i);
+ assert(v);
// methods are always byval!
bool bByVal = dynamic_cast<const SbxMethod *>(v) != nullptr;
SbxDataType t = v->GetType();
@@ -791,23 +766,26 @@ bool SbiRuntime::Step()
{
if( bRun )
{
+ static sal_uInt32 nLastTime = osl_getGlobalTimer();
+
// in any case check casually!
if( !( ++nOps & 0xF ) && pInst->IsReschedule() )
{
sal_uInt32 nTime = osl_getGlobalTimer();
- if (nTime - m_nLastTime > 5 ) // 20 ms
+ if (nTime - nLastTime > 5) // 20 ms
{
+ nLastTime = nTime;
Application::Reschedule();
- m_nLastTime = nTime;
}
}
// #i48868 blocked by next call level?
while( bBlocked )
{
- if( pInst->IsReschedule() )
+ if( pInst->IsReschedule() ) // And what if not? Busy loop?
{
Application::Reschedule();
+ nLastTime = osl_getGlobalTimer();
}
}
@@ -1151,6 +1129,17 @@ void SbiRuntime::PushFor()
p->refInc = PopVar();
p->refEnd = PopVar();
+ if (isVBAEnabled())
+ {
+ // tdf#150458: only calculate these once, coercing to double
+ // tdf#150460: shouldn't we do it in non-VBA / compat mode, too?
+ SbxVariableRef incCopy(new SbxVariable(SbxDOUBLE));
+ *incCopy = *p->refInc;
+ p->refInc = std::move(incCopy);
+ SbxVariableRef endCopy(new SbxVariable(SbxDOUBLE));
+ *endCopy = *p->refEnd;
+ p->refEnd = std::move(endCopy);
+ }
SbxVariableRef xBgn = PopVar();
p->refVar = PopVar();
// tdf#85371 - grant explicitly write access to the index variable
@@ -1169,7 +1158,15 @@ void SbiRuntime::PushForEach()
pForStk = p;
SbxVariableRef xObjVar = PopVar();
- SbxBase* pObj = xObjVar && xObjVar->GetFullType() == SbxOBJECT ? xObjVar->GetObject() : nullptr;
+ SbxBase* pObj(nullptr);
+ if (xObjVar)
+ {
+ SbxValues v(SbxVARIANT);
+ // Here it may retrieve the value, and change the type from SbxEMPTY to SbxOBJECT
+ xObjVar->Get(v);
+ if (v.eType == SbxOBJECT)
+ pObj = v.pObj;
+ }
if (SbxDimArray* pArray = dynamic_cast<SbxDimArray*>(pObj))
{
@@ -1208,7 +1205,7 @@ void SbiRuntime::PushForEach()
else if (aAny >>= xIndexAccess)
{
p->eForType = ForType::EachXIndexAccess;
- p->xIndexAccess = xIndexAccess;
+ p->xIndexAccess = std::move(xIndexAccess);
p->nCurCollectionIndex = 0;
}
else if ( isVBAEnabled() && pUnoObj->isNativeCOMObject() )
@@ -1279,8 +1276,6 @@ void SbiRuntime::DllCall
SbxDataType eResType, // return value
bool bCDecl ) // true: according to C-conventions
{
- // NOT YET IMPLEMENTED
-
SbxVariable* pRes = new SbxVariable( eResType );
SbiDllMgr* pDllMgr = pInst->GetDllMgr();
ErrCode nErr = pDllMgr->Call( aFuncName, aDLLName, pArgs, *pRes, bCDecl );
@@ -1451,101 +1446,68 @@ void SbiRuntime::StepGE() { StepCompare( SbxGE ); }
namespace
{
- bool NeedEsc(sal_Unicode cCode)
- {
- if(!rtl::isAscii(cCode))
- {
- return false;
- }
- switch(cCode)
- {
- case '.':
- case '^':
- case '$':
- case '+':
- case '\\':
- case '|':
- case '{':
- case '}':
- case '(':
- case ')':
- return true;
- default:
- return false;
- }
- }
-
- OUString VBALikeToRegexp(const OUString &rIn)
+ OUString VBALikeToRegexp(std::u16string_view sIn)
{
- OUStringBuffer sResult;
- const sal_Unicode *start = rIn.getStr();
- const sal_Unicode *end = start + rIn.getLength();
-
- int seenright = 0;
+ OUStringBuffer sResult("\\A"); // Match at the beginning of the input
- sResult.append('^');
-
- while (start < end)
+ for (auto start = sIn.begin(), end = sIn.end(); start < end;)
{
- switch (*start)
+ switch (auto ch = *start++)
{
case '?':
sResult.append('.');
- start++;
break;
case '*':
sResult.append(".*");
- start++;
break;
case '#':
sResult.append("[0-9]");
- start++;
- break;
- case ']':
- sResult.append('\\');
- sResult.append(*start++);
break;
case '[':
- sResult.append(*start++);
- seenright = 0;
- while (start < end && !seenright)
+ sResult.append(ch);
+ if (start < end)
+ {
+ if (*start == '!')
+ {
+ sResult.append('^');
+ ++start;
+ }
+ else if (*start == '^')
+ sResult.append('\\');
+ }
+ for (bool seenright = false; start < end && !seenright; ++start)
{
switch (*start)
{
case '[':
- case '?':
- case '*':
+ case '\\':
sResult.append('\\');
- sResult.append(*start);
break;
case ']':
- sResult.append(*start);
- seenright = 1;
- break;
- case '!':
- sResult.append('^');
- break;
- default:
- if (NeedEsc(*start))
- {
- sResult.append('\\');
- }
- sResult.append(*start);
+ seenright = true;
break;
}
- start++;
+ sResult.append(*start);
}
break;
+ case '.':
+ case '^':
+ case '$':
+ case '+':
+ case '\\':
+ case '|':
+ case '{':
+ case '}':
+ case '(':
+ case ')':
+ sResult.append('\\');
+ [[fallthrough]];
default:
- if (NeedEsc(*start))
- {
- sResult.append('\\');
- }
- sResult.append(*start++);
+ sResult.append(ch);
}
}
- sResult.append('$');
+ sResult.append("\\z"); // Match if the current position is at the end of input
return sResult.makeStringAndClear();
}
@@ -1556,15 +1518,8 @@ void SbiRuntime::StepLIKE()
SbxVariableRef refVar1 = PopVar();
SbxVariableRef refVar2 = PopVar();
- OUString pattern = VBALikeToRegexp(refVar1->GetOUString());
OUString value = refVar2->GetOUString();
-
- i18nutil::SearchOptions2 aSearchOpt;
-
- aSearchOpt.AlgorithmType2 = css::util::SearchAlgorithms2::REGEXP;
-
- aSearchOpt.Locale = Application::GetSettings().GetLanguageTag().getLocale();
- aSearchOpt.searchString = pattern;
+ OUString regex = VBALikeToRegexp(refVar1->GetOUString());
bool bTextMode(true);
bool bCompatibility = ( GetSbData()->pInst && GetSbData()->pInst->IsCompatibility() );
@@ -1572,14 +1527,35 @@ void SbiRuntime::StepLIKE()
{
bTextMode = IsImageFlag( SbiImageFlags::COMPARETEXT );
}
+ sal_uInt32 searchFlags = UREGEX_UWORD | UREGEX_DOTALL; // Dot matches newline
if( bTextMode )
{
- aSearchOpt.transliterateFlags |= TransliterationFlags::IGNORE_CASE;
+ searchFlags |= UREGEX_CASE_INSENSITIVE;
+ }
+
+ static sal_uInt32 cachedSearchFlags = 0;
+ static OUString cachedRegex;
+ static std::optional<icu::RegexMatcher> oRegexMatcher;
+ UErrorCode nIcuErr = U_ZERO_ERROR;
+ if (regex != cachedRegex || searchFlags != cachedSearchFlags || !oRegexMatcher)
+ {
+ cachedRegex = regex;
+ cachedSearchFlags = searchFlags;
+ icu::UnicodeString sRegex(false, reinterpret_cast<const UChar*>(cachedRegex.getStr()),
+ cachedRegex.getLength());
+ oRegexMatcher.emplace(sRegex, cachedSearchFlags, nIcuErr);
+ }
+
+ icu::UnicodeString sSource(false, reinterpret_cast<const UChar*>(value.getStr()),
+ value.getLength());
+ oRegexMatcher->reset(sSource);
+
+ bool bRes = oRegexMatcher->matches(nIcuErr);
+ if (nIcuErr)
+ {
+ Error(ERRCODE_BASIC_INTERNAL_ERROR);
}
SbxVariable* pRes = new SbxVariable;
- utl::TextSearch aSearch( aSearchOpt);
- sal_Int32 nStart=0, nEnd=value.getLength();
- bool bRes = aSearch.SearchForward(value, &nStart, &nEnd);
pRes->PutBool( bRes );
PushVar( pRes );
@@ -1666,40 +1642,39 @@ static bool checkUnoStructCopy( bool bVBA, SbxVariableRef const & refVal, SbxVar
aAny = pUnoVal ? pUnoVal->getUnoAny() : pUnoStructVal->getUnoAny();
else
return false;
- if ( aAny.getValueType().getTypeClass() == TypeClass_STRUCT )
- {
- refVar->SetType( SbxOBJECT );
- ErrCode eOldErr = SbxBase::GetError();
- // There are some circumstances when calling GetObject
- // will trigger an error, we need to squash those here.
- // Alternatively it is possible that the same scenario
- // could overwrite and existing error. Lets prevent that
- SbxObjectRef xVarObj = static_cast<SbxObject*>(refVar->GetObject());
- if ( eOldErr != ERRCODE_NONE )
- SbxBase::SetError( eOldErr );
- else
- SbxBase::ResetError();
+ if ( aAny.getValueTypeClass() != TypeClass_STRUCT )
+ return false;
- SbUnoStructRefObject* pUnoStructObj = dynamic_cast<SbUnoStructRefObject*>( xVarObj.get() );
+ refVar->SetType( SbxOBJECT );
+ ErrCode eOldErr = SbxBase::GetError();
+ // There are some circumstances when calling GetObject
+ // will trigger an error, we need to squash those here.
+ // Alternatively it is possible that the same scenario
+ // could overwrite and existing error. Let's prevent that
+ SbxObjectRef xVarObj = static_cast<SbxObject*>(refVar->GetObject());
+ if ( eOldErr != ERRCODE_NONE )
+ SbxBase::SetError( eOldErr );
+ else
+ SbxBase::ResetError();
- OUString sClassName = pUnoVal ? pUnoVal->GetClassName() : pUnoStructVal->GetClassName();
- OUString sName = pUnoVal ? pUnoVal->GetName() : pUnoStructVal->GetName();
+ SbUnoStructRefObject* pUnoStructObj = dynamic_cast<SbUnoStructRefObject*>( xVarObj.get() );
- if ( pUnoStructObj )
- {
- StructRefInfo aInfo = pUnoStructObj->getStructInfo();
- aInfo.setValue( aAny );
- }
- else
- {
- SbUnoObject* pNewUnoObj = new SbUnoObject( sName, aAny );
- // #70324: adopt ClassName
- pNewUnoObj->SetClassName( sClassName );
- refVar->PutObject( pNewUnoObj );
- }
- return true;
+ OUString sClassName = pUnoVal ? pUnoVal->GetClassName() : pUnoStructVal->GetClassName();
+ OUString sName = pUnoVal ? pUnoVal->GetName() : pUnoStructVal->GetName();
+
+ if ( pUnoStructObj )
+ {
+ StructRefInfo aInfo = pUnoStructObj->getStructInfo();
+ aInfo.setValue( aAny );
+ }
+ else
+ {
+ SbUnoObject* pNewUnoObj = new SbUnoObject( sName, aAny );
+ // #70324: adopt ClassName
+ pNewUnoObj->SetClassName( sClassName );
+ refVar->PutObject( pNewUnoObj );
}
- return false;
+ return true;
}
@@ -1775,10 +1750,10 @@ struct DimAsNewRecoverItem
, m_pClassModule( nullptr )
{}
- DimAsNewRecoverItem( const OUString& rObjClass, const OUString& rObjName,
+ DimAsNewRecoverItem( OUString aObjClass, OUString aObjName,
SbxObject* pObjParent, SbModule* pClassModule )
- : m_aObjClass( rObjClass )
- , m_aObjName( rObjName )
+ : m_aObjClass(std::move( aObjClass ))
+ , m_aObjName(std::move( aObjName ))
, m_pObjParent( pObjParent )
, m_pClassModule( pClassModule )
{}
@@ -1816,7 +1791,7 @@ void removeDimAsNewRecoverItem( SbxVariable* pVar )
// saving object variable
// not-object variables will cause errors
-constexpr OUStringLiteral pCollectionStr = u"Collection";
+constexpr OUString pCollectionStr = u"Collection"_ustr;
void SbiRuntime::StepSET_Impl( SbxVariableRef& refVal, SbxVariableRef& refVar, bool bHandleDefaultProp )
{
@@ -1850,7 +1825,7 @@ void SbiRuntime::StepSET_Impl( SbxVariableRef& refVal, SbxVariableRef& refVar, b
if( refObjVal.is() )
{
- refVal = refObjVal;
+ refVal = std::move(refObjVal);
}
else if( !(eValType & SbxARRAY) )
{
@@ -1985,7 +1960,7 @@ void SbiRuntime::StepSET_Impl( SbxVariableRef& refVal, SbxVariableRef& refVar, b
const DimAsNewRecoverItem& rItem = it->second;
if( rItem.m_pClassModule != nullptr )
{
- SbClassModuleObject* pNewObj = new SbClassModuleObject( rItem.m_pClassModule );
+ SbClassModuleObject* pNewObj = new SbClassModuleObject(*rItem.m_pClassModule);
pNewObj->SetName( rItem.m_aObjName );
pNewObj->SetParent( rItem.m_pObjParent );
refVar->PutObject( pNewObj );
@@ -2015,9 +1990,9 @@ void SbiRuntime::StepSET_Impl( SbxVariableRef& refVal, SbxVariableRef& refVar, b
SbClassModuleObject* pClassModuleObj = dynamic_cast<SbClassModuleObject*>( pValObjBase );
if( pClassModuleObj != nullptr )
{
- SbModule* pClassModule = pClassModuleObj->getClassModule();
+ SbModule& rClassModule = pClassModuleObj->getClassModule();
gaDimAsNewRecoverHash[refVar.get()] =
- DimAsNewRecoverItem( aObjClass, pValObj->GetName(), pValObj->GetParent(), pClassModule );
+ DimAsNewRecoverItem( aObjClass, pValObj->GetName(), pValObj->GetParent(), &rClassModule );
}
else if( aObjClass.equalsIgnoreAsciiCase( "Collection" ) )
{
@@ -2546,7 +2521,7 @@ void SbiRuntime::StepINPUT()
// then with a string value
if( !pVar->IsFixed() || pVar->IsNumeric() )
{
- sal_uInt16 nLen = 0;
+ sal_Int32 nLen = 0;
if( !pVar->Scan( s, &nLen ) )
{
err = SbxBase::GetError();
@@ -2745,7 +2720,7 @@ void SbiRuntime::StepPRINTF() // print TOS in field
}
s.append(s1);
comphelper::string::padToLength(s, 14, ' ');
- pIosys->Write( s.makeStringAndClear() );
+ pIosys->Write( s );
Error( pIosys->GetError() );
}
@@ -2798,8 +2773,7 @@ void SbiRuntime::StepRENAME() // Rename Tos+1 to Tos
void SbiRuntime::StepPROMPT()
{
SbxVariableRef p = PopVar();
- OString aStr(OUStringToOString(p->GetOUString(), osl_getThreadTextEncoding()));
- pIosys->SetPrompt( aStr );
+ pIosys->SetPrompt(p->GetOUString());
}
// Set Restart point
@@ -2848,7 +2822,7 @@ void SbiRuntime::StepLOADNC( sal_uInt32 nOp1 )
// tdf#143707 - check if the data type character was added after the string termination symbol
SbxDataType eTypeStr;
// #57844 use localized function
- OUString aStr = pImg->GetString(static_cast<short>(nOp1), &eTypeStr);
+ OUString aStr = pImg->GetString(nOp1, &eTypeStr);
// also allow , !!!
sal_Int32 iComma = aStr.indexOf(',');
if( iComma >= 0 )
@@ -2894,7 +2868,7 @@ void SbiRuntime::StepLOADNC( sal_uInt32 nOp1 )
void SbiRuntime::StepLOADSC( sal_uInt32 nOp1 )
{
SbxVariable* p = new SbxVariable;
- p->PutString( pImg->GetString( static_cast<short>( nOp1 ) ) );
+ p->PutString( pImg->GetString( nOp1 ) );
PushVar( p );
}
@@ -2916,7 +2890,7 @@ void SbiRuntime::StepARGN( sal_uInt32 nOp1 )
StarBASIC::FatalError( ERRCODE_BASIC_INTERNAL_ERROR );
else
{
- OUString aAlias( pImg->GetString( static_cast<short>( nOp1 ) ) );
+ OUString aAlias( pImg->GetString( nOp1 ) );
SbxVariableRef pVal = PopVar();
if( bVBAEnabled &&
( dynamic_cast<const SbxMethod*>( pVal.get()) != nullptr
@@ -3000,6 +2974,11 @@ void SbiRuntime::StepPAD( sal_uInt32 nOp1 )
comphelper::string::padToLength(aBuf, nLen, ' ');
}
s = aBuf.makeStringAndClear();
+ // Do not modify the original variable inadvertently
+ PopVar();
+ p = new SbxVariable;
+ p->PutString(s);
+ PushVar(p);
}
// jump (+target)
@@ -3024,6 +3003,14 @@ bool SbiRuntime::EvaluateTopOfStackAsBool()
{
return false;
}
+
+ // tdf#151503 - do not evaluate a missing optional variable to a boolean
+ if (tos->GetType() == SbxERROR && IsMissing(tos.get(), 1))
+ {
+ Error(ERRCODE_BASIC_NOT_OPTIONAL);
+ return false;
+ }
+
if ( tos->IsObject() )
{
//GetBool applied to an Object attempts to dereference and evaluate
@@ -3069,13 +3056,16 @@ void SbiRuntime::StepONJUMP( sal_uInt32 nOp1 )
{
SbxVariableRef p = PopVar();
sal_Int16 n = p->GetInteger();
- if( nOp1 & 0x8000 )
- {
+
+ if (nOp1 & 0x8000)
nOp1 &= 0x7FFF;
- PushGosub( pCode + 5 * nOp1 );
- }
- if( n < 1 || o3tl::make_unsigned(n) > nOp1 )
- n = static_cast<sal_Int16>( nOp1 + 1 );
+
+ // tdf#160321 - do not execute the jump statement if the expression is out of range
+ if (n < 1 || o3tl::make_unsigned(n) > nOp1)
+ n = static_cast<sal_Int16>(nOp1 + 1);
+ else if (nOp1 & 0x8000)
+ PushGosub(pCode + 5 * nOp1);
+
nOp1 = static_cast<sal_uInt32>(pCode - pImg->GetCode()) + 5 * --n;
StepJUMP( nOp1 );
}
@@ -3427,7 +3417,7 @@ void SbiRuntime::StepSETCLASS_impl( sal_uInt32 nOp1, bool bHandleDflt )
{
SbxVariableRef refVal = PopVar();
SbxVariableRef refVar = PopVar();
- OUString aClass( pImg->GetString( static_cast<short>( nOp1 ) ) );
+ OUString aClass( pImg->GetString( nOp1 ) );
bool bOk = checkClass_Impl( refVal, aClass, true, true );
if( bOk )
@@ -3449,7 +3439,7 @@ void SbiRuntime::StepSETCLASS( sal_uInt32 nOp1 )
void SbiRuntime::StepTESTCLASS( sal_uInt32 nOp1 )
{
SbxVariableRef xObjVal = PopVar();
- OUString aClass( pImg->GetString( static_cast<short>( nOp1 ) ) );
+ OUString aClass( pImg->GetString( nOp1 ) );
bool bDefault = !bVBAEnabled;
bool bOk = checkClass_Impl( xObjVal, aClass, false, bDefault );
@@ -3462,7 +3452,7 @@ void SbiRuntime::StepTESTCLASS( sal_uInt32 nOp1 )
void SbiRuntime::StepLIB( sal_uInt32 nOp1 )
{
- aLibName = pImg->GetString( static_cast<short>( nOp1 ) );
+ aLibName = pImg->GetString( nOp1 );
}
// TOS is incremented by BASE, BASE is pushed before (+BASE)
@@ -3516,7 +3506,7 @@ SbxVariable* SbiRuntime::FindElement( SbxObject* pObj, sal_uInt32 nOp1, sal_uInt
{
bool bFatalError = false;
SbxDataType t = static_cast<SbxDataType>(nOp2);
- OUString aName( pImg->GetString( static_cast<short>( nOp1 & 0x7FFF ) ) );
+ OUString aName( pImg->GetString( nOp1 & 0x7FFF ) );
// Hacky capture of Evaluate [] syntax
// this should be tackled I feel at the pcode level
if ( bIsVBAInterOp && aName.startsWith("[") )
@@ -3721,7 +3711,7 @@ SbxVariable* SbiRuntime::FindElement( SbxObject* pObj, sal_uInt32 nOp1, sal_uInt
}
// consider index-access for UnoObjects
// definitely we want this for VBA where properties are often
- // collections ( which need index access ), but lets only do
+ // collections ( which need index access ), but let's only do
// this if we actually have params following
else if( bVBAEnabled && dynamic_cast<const SbUnoProperty*>( pElem) != nullptr && pElem->GetParameters() )
{
@@ -3785,7 +3775,7 @@ SbxBase* SbiRuntime::FindElementExtern( const OUString& rName )
{
// Parameter is missing
pElem = new SbxVariable( SbxSTRING );
- pElem->PutString( "<missing parameter>");
+ pElem->PutString( u"<missing parameter>"_ustr);
}
else
{
@@ -3875,7 +3865,7 @@ void SbiRuntime::SetupArgs( SbxVariable* p, sal_uInt32 nOp1 )
{
Any aAny = pUnoObj->getUnoAny();
- if( aAny.getValueType().getTypeClass() == TypeClass_INTERFACE )
+ if( aAny.getValueTypeClass() == TypeClass_INTERFACE )
{
Reference< XDefaultMethod > xDfltMethod( aAny, UNO_QUERY );
@@ -3951,33 +3941,44 @@ void SbiRuntime::SetupArgs( SbxVariable* p, sal_uInt32 nOp1 )
SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem )
{
- SbxArray* pPar;
+ assert(pElem);
if( ( pElem->GetType() & SbxARRAY ) && refRedim.get() != pElem )
{
SbxBase* pElemObj = pElem->GetObject();
- SbxDimArray* pDimArray = dynamic_cast<SbxDimArray*>( pElemObj );
- pPar = pElem->GetParameters();
- if( pDimArray )
+ SbxArray* pPar = pElem->GetParameters();
+ if (SbxDimArray* pDimArray = dynamic_cast<SbxDimArray*>(pElemObj))
{
// parameters may be missing, if an array is
// passed as an argument
if( pPar )
- pElem = pDimArray->Get( pPar );
- }
- else
- {
- SbxArray* pArray = dynamic_cast<SbxArray*>( pElemObj );
- if( pArray )
{
- if( !pPar )
+ bool parIsArrayIndex = true;
+ if (dynamic_cast<const SbxMethod*>(pElem))
{
- Error( ERRCODE_BASIC_OUT_OF_RANGE );
- pElem = new SbxVariable;
- }
- else
- {
- pElem = pArray->Get(pPar->Get(1)->GetInteger());
+ // If this was a method, then there are two possibilities:
+ // 1. pPar is this method's parameters.
+ // 2. pPar is the indexes into the array returned from the method.
+ // To disambiguate, check the 0th element of pPar.
+ if (dynamic_cast<const SbxMethod*>(pPar->Get(0)))
+ {
+ // pPar was the parameters to the method, not indexes into the array
+ parIsArrayIndex = false;
+ }
}
+ if (parIsArrayIndex)
+ pElem = pDimArray->Get(pPar);
+ }
+ }
+ else if (SbxArray* pArray = dynamic_cast<SbxArray*>(pElemObj))
+ {
+ if( !pPar )
+ {
+ Error( ERRCODE_BASIC_OUT_OF_RANGE );
+ pElem = new SbxVariable;
+ }
+ else
+ {
+ pElem = pArray->Get(pPar->Get(1)->GetInteger());
}
}
@@ -3992,8 +3993,7 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem )
dynamic_cast<const SbxMethod*>( pElem) == nullptr &&
( !bVBAEnabled || dynamic_cast<const SbxProperty*>( pElem) == nullptr ) )
{
- pPar = pElem->GetParameters();
- if ( pPar )
+ if (SbxArray* pPar = pElem->GetParameters())
{
// is it a uno-object?
SbxBaseRef pObj = pElem->GetObject();
@@ -4003,7 +4003,7 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem )
{
Any aAny = pUnoObj->getUnoAny();
- if( aAny.getValueType().getTypeClass() == TypeClass_INTERFACE )
+ if( aAny.getValueTypeClass() == TypeClass_INTERFACE )
{
Reference< XIndexAccess > xIndexAccess( aAny, UNO_QUERY );
if ( !bVBAEnabled )
@@ -4069,8 +4069,8 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem )
pUnoObj = pSbObj;
Any aUnoAny = pUnoObj->getUnoAny();
- if( aUnoAny.getValueType().getTypeClass() == TypeClass_INTERFACE )
- x = aUnoAny;
+ if( aUnoAny.getValueTypeClass() == TypeClass_INTERFACE )
+ x = std::move(aUnoAny);
pElem = pDflt;
}
}
@@ -4308,7 +4308,7 @@ void SbiRuntime::StepCASEIS( sal_uInt32 nOp1, sal_uInt32 nOp2 )
void SbiRuntime::StepCALL( sal_uInt32 nOp1, sal_uInt32 nOp2 )
{
- OUString aName = pImg->GetString( static_cast<short>( nOp1 & 0x7FFF ) );
+ OUString aName = pImg->GetString( nOp1 & 0x7FFF );
SbxArray* pArgs = nullptr;
if( nOp1 & 0x8000 )
{
@@ -4326,7 +4326,7 @@ void SbiRuntime::StepCALL( sal_uInt32 nOp1, sal_uInt32 nOp2 )
void SbiRuntime::StepCALLC( sal_uInt32 nOp1, sal_uInt32 nOp2 )
{
- OUString aName = pImg->GetString( static_cast<short>( nOp1 & 0x7FFF ) );
+ OUString aName = pImg->GetString( nOp1 & 0x7FFF );
SbxArray* pArgs = nullptr;
if( nOp1 & 0x8000 )
{
@@ -4416,7 +4416,7 @@ void SbiRuntime::StepSTMNT( sal_uInt32 nOp1, sal_uInt32 nOp2 )
}
// 16.10.96: #31460 new concept for StepInto/Over/Out
- // see explanation at _ImplGetBreakCallLevel
+ // see explanation at SbiInstance::CalcBreakCallLevel
if( pInst->nCallLvl <= pInst->nBreakCallLvl )
{
StarBASIC* pStepBasic = GetCurrentBasic( &rBasic );
@@ -4449,7 +4449,7 @@ void SbiRuntime::StepOPEN( sal_uInt32 nOp1, sal_uInt32 nOp2 )
SbxVariableRef pLen = PopVar();
short nBlkLen = pLen->GetInteger();
short nChan = pChan->GetInteger();
- OString aName(OUStringToOString(pName->GetOUString(), osl_getThreadTextEncoding()));
+ OUString aName = pName->GetOUString();
pIosys->Open( nChan, aName, static_cast<StreamMode>( nOp1 ),
static_cast<SbiStreamFlags>( nOp2 ), nBlkLen );
Error( pIosys->GetError() );
@@ -4459,7 +4459,7 @@ void SbiRuntime::StepOPEN( sal_uInt32 nOp1, sal_uInt32 nOp2 )
void SbiRuntime::StepCREATE( sal_uInt32 nOp1, sal_uInt32 nOp2 )
{
- OUString aClass( pImg->GetString( static_cast<short>( nOp2 ) ) );
+ OUString aClass( pImg->GetString( nOp2 ) );
SbxObjectRef pObj = SbxBase::CreateObject( aClass );
if( !pObj )
{
@@ -4467,7 +4467,7 @@ void SbiRuntime::StepCREATE( sal_uInt32 nOp1, sal_uInt32 nOp2 )
}
else
{
- OUString aName( pImg->GetString( static_cast<short>( nOp1 ) ) );
+ OUString aName( pImg->GetString( nOp1 ) );
pObj->SetName( aName );
// the object must be able to call the BASIC
pObj->SetParent( &rBasic );
@@ -4529,7 +4529,7 @@ void SbiRuntime::StepDCREATE_IMPL( sal_uInt32 nOp1, sal_uInt32 nOp2 )
nTotalSize = 0; // on error, don't create objects
// create objects and insert them into the array
- OUString aClass( pImg->GetString( static_cast<short>( nOp2 ) ) );
+ OUString aClass( pImg->GetString( nOp2 ) );
OUString aName;
for( sal_Int32 i = 0 ; i < nTotalSize ; ++i )
{
@@ -4544,7 +4544,7 @@ void SbiRuntime::StepDCREATE_IMPL( sal_uInt32 nOp1, sal_uInt32 nOp2 )
else
{
if (aName.isEmpty())
- aName = pImg->GetString(static_cast<short>(nOp1));
+ aName = pImg->GetString(nOp1);
pClassObj->SetName(aName);
// the object must be able to call the basic
pClassObj->SetParent(&rBasic);
@@ -4556,8 +4556,8 @@ void SbiRuntime::StepDCREATE_IMPL( sal_uInt32 nOp1, sal_uInt32 nOp2 )
void SbiRuntime::StepTCREATE( sal_uInt32 nOp1, sal_uInt32 nOp2 )
{
- OUString aName( pImg->GetString( static_cast<short>( nOp1 ) ) );
- OUString aClass( pImg->GetString( static_cast<short>( nOp2 ) ) );
+ OUString aName( pImg->GetString( nOp1 ) );
+ OUString aClass( pImg->GetString( nOp2 ) );
SbxObjectRef pCopyObj = createUserTypeImpl( aClass );
if( pCopyObj )
@@ -4586,7 +4586,7 @@ void SbiRuntime::implHandleSbxFlags( SbxVariable* pVar, SbxDataType t, sal_uInt3
if( bFixedString )
{
sal_uInt16 nCount = static_cast<sal_uInt16>( nOp2 >> 17 ); // len = all bits above 0x10000
- OUStringBuffer aBuf;
+ OUStringBuffer aBuf(nCount);
comphelper::string::padToLength(aBuf, nCount);
pVar->PutString(aBuf.makeStringAndClear());
}
@@ -4606,7 +4606,7 @@ void SbiRuntime::StepLOCAL( sal_uInt32 nOp1, sal_uInt32 nOp2 )
{
refLocals = new SbxArray;
}
- OUString aName( pImg->GetString( static_cast<short>( nOp1 ) ) );
+ OUString aName( pImg->GetString( nOp1 ) );
if( refLocals->Find( aName, SbxClassType::DontCare ) == nullptr )
{
SbxDataType t = static_cast<SbxDataType>(nOp2 & 0xffff);
@@ -4621,7 +4621,7 @@ void SbiRuntime::StepLOCAL( sal_uInt32 nOp1, sal_uInt32 nOp2 )
void SbiRuntime::StepPUBLIC_Impl( sal_uInt32 nOp1, sal_uInt32 nOp2, bool bUsedForClassModule )
{
- OUString aName( pImg->GetString( static_cast<short>( nOp1 ) ) );
+ OUString aName( pImg->GetString( nOp1 ) );
SbxDataType t = static_cast<SbxDataType>(nOp2 & 0xffff);
bool bFlag = pMod->IsSet( SbxFlagBits::NoModify );
pMod->SetFlag( SbxFlagBits::NoModify );
@@ -4673,7 +4673,7 @@ void SbiRuntime::StepGLOBAL( sal_uInt32 nOp1, sal_uInt32 nOp2 )
{
StepPUBLIC_Impl( nOp1, nOp2, true );
}
- OUString aName( pImg->GetString( static_cast<short>( nOp1 ) ) );
+ OUString aName( pImg->GetString( nOp1 ) );
SbxDataType t = static_cast<SbxDataType>(nOp2 & 0xffff);
// Store module scope variables at module scope
@@ -4733,7 +4733,7 @@ void SbiRuntime::StepFIND_G( sal_uInt32 nOp1, sal_uInt32 nOp2 )
{
// Return dummy variable
SbxDataType t = static_cast<SbxDataType>(nOp2);
- OUString aName( pImg->GetString( static_cast<short>( nOp1 & 0x7FFF ) ) );
+ OUString aName( pImg->GetString( nOp1 & 0x7FFF ) );
SbxVariable* pDummyVar = new SbxVariable( t );
pDummyVar->SetName( aName );
@@ -4766,9 +4766,11 @@ SbxVariable* SbiRuntime::StepSTATIC_Impl(
// establishing a static variable (+StringID+type)
void SbiRuntime::StepSTATIC( sal_uInt32 nOp1, sal_uInt32 nOp2 )
{
- OUString aName( pImg->GetString( static_cast<short>( nOp1 ) ) );
+ OUString aName( pImg->GetString( nOp1 ) );
SbxDataType t = static_cast<SbxDataType>(nOp2 & 0xffff);
StepSTATIC_Impl( aName, t, nOp2 );
}
+#endif
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/runtime/stdobj.cxx b/basic/source/runtime/stdobj.cxx
index 1a2499cde2da..f30a633dccfb 100644
--- a/basic/source/runtime/stdobj.cxx
+++ b/basic/source/runtime/stdobj.cxx
@@ -34,29 +34,38 @@
// does NOT impose a limit on User defined procedures ). This changes is to
// allow us space for a flag to denylist some functions in vba mode
-#define ARGSMASK_ 0x003F // 63 Arguments
-#define COMPTMASK_ 0x00C0 // COMPATIBILITY mask
-#define COMPATONLY_ 0x0080 // procedure is visible in vba mode only
-#define NORMONLY_ 0x0040 // procedure is visible in normal mode only
-
-#define RWMASK_ 0x0F00 // mask for R/W-bits
-#define TYPEMASK_ 0xF000 // mask for the entry's type
-
-#define OPT_ 0x0400 // parameter is optional
-#define CONST_ 0x0800 // property is const
-#define METHOD_ 0x3000
-#define PROPERTY_ 0x4000
-#define OBJECT_ 0x8000
- // combination of bits above:
-#define FUNCTION_ 0x1100
-#define LFUNCTION_ 0x1300 // mask for function which also works as Lvalue
-#define SUB_ 0x2100
-#define ROPROP_ 0x4100 // mask Read Only-Property
-#define RWPROP_ 0x4300 // mask Read/Write-Property
-#define CPROP_ 0x4900 // mask for constant
-
namespace {
+enum Flags
+{
+ ARGSMASK_ = 0x003F, // 63 Arguments
+
+ NORMONLY_ = 0x0040, // procedure is visible in normal mode only
+ COMPATONLY_ = 0x0080, // procedure is visible in vba mode only
+ COMPTMASK_ = (COMPATONLY_ | NORMONLY_), // COMPATIBILITY mask
+
+ READ_ = 0x0100, // parameter allows read
+ WRITE_ = 0x0200, // parameter allows write
+ OPT_ = 0x0400, // parameter is optional
+ CONST_ = 0x0800, // property is const
+ RWMASK_ = (READ_ | WRITE_ | OPT_ | CONST_), // mask for R/W-bits
+
+ FUNC_TYPE_ = 0x1000, // functional type
+ SUB_TYPE_ = 0x2000, // sub type
+ METHOD_ = (FUNC_TYPE_ | SUB_TYPE_),
+ PROPERTY_ = 0x4000,
+ OBJECT_ = 0x8000,
+ TYPEMASK_ = (METHOD_ | PROPERTY_ | OBJECT_), // mask for the entry's type
+
+ // combination of bits above
+ FUNCTION_ = (FUNC_TYPE_ | READ_),
+ LFUNCTION_ = (FUNC_TYPE_ | READ_ | WRITE_), // mask for function which also works as Lvalue (statement)
+ SUB_ = SUB_TYPE_,
+ ROPROP_ = (PROPERTY_ | READ_), // mask Read Only-Property
+ RWPROP_ = (PROPERTY_ | READ_ | WRITE_), // mask Read/Write-Property
+ CPROP_ = (PROPERTY_ | READ_ | CONST_) // mask for constant
+};
+
struct Method {
RtlCall pFunc;
std::u16string_view sName;
@@ -82,20 +91,9 @@ template <int N> constexpr bool MethodsTableValid(const Method (&rMethods)[N])
{
int nCurMethArgs = 0;
int nArgsChecked = 0;
- bool bFinished = false;
for (const auto& m : rMethods)
{
- assert(!bFinished); // no entries after end-of-table entry
- if (bFinished)
- return false;
- if (m.nArgs == -1) // end-of-table entry
- {
- assert(nCurMethArgs == nArgsChecked); // last method had correct # of arguments
- if (nCurMethArgs != nArgsChecked)
- return false;
- bFinished = true;
- }
- else if (m.pFunc) // main (function/sub/etc) entry
+ if (m.pFunc) // main (function/sub/etc) entry
{
assert(nCurMethArgs == nArgsChecked); // previous method had correct # of arguments
if (nCurMethArgs != nArgsChecked)
@@ -106,11 +104,12 @@ template <int N> constexpr bool MethodsTableValid(const Method (&rMethods)[N])
else // subordinate (argument) entry
++nArgsChecked;
}
- assert(bFinished); // its last entry was end-of-table entry
- return bFinished;
+ assert(nCurMethArgs == nArgsChecked); // last method had correct # of arguments
+ return nCurMethArgs == nArgsChecked;
}
-}
+template <bool N> void ConstBool(StarBASIC*, SbxArray& par, bool) { par.Get(0)->PutBool(N); }
+template <sal_Int16 N> void ConstInt(StarBASIC*, SbxArray& par, bool) { par.Get(0)->PutInteger(N); }
constexpr Method aMethods[] = {
@@ -127,13 +126,14 @@ constexpr Method aMethods[] = {
{ u"Atn", SbxDOUBLE, 1 | FUNCTION_, SbRtl_Atn },
arg(u"number", SbxDOUBLE),
-{ u"ATTR_ARCHIVE", SbxINTEGER, CPROP_, SbRtl_ATTR_ARCHIVE },
-{ u"ATTR_DIRECTORY", SbxINTEGER, CPROP_, SbRtl_ATTR_DIRECTORY },
-{ u"ATTR_HIDDEN", SbxINTEGER, CPROP_, SbRtl_ATTR_HIDDEN },
-{ u"ATTR_NORMAL", SbxINTEGER, CPROP_, SbRtl_ATTR_NORMAL },
-{ u"ATTR_READONLY", SbxINTEGER, CPROP_, SbRtl_ATTR_READONLY },
-{ u"ATTR_SYSTEM", SbxINTEGER, CPROP_, SbRtl_ATTR_SYSTEM },
-{ u"ATTR_VOLUME", SbxINTEGER, CPROP_, SbRtl_ATTR_VOLUME },
+// Related to: Dir, GetAttr, SetAttr
+{ u"ATTR_ARCHIVE", SbxINTEGER, CPROP_, ConstInt<SbAttributes::ARCHIVE> },
+{ u"ATTR_DIRECTORY", SbxINTEGER, CPROP_, ConstInt<SbAttributes::DIRECTORY> },
+{ u"ATTR_HIDDEN", SbxINTEGER, CPROP_, ConstInt<SbAttributes::HIDDEN> },
+{ u"ATTR_NORMAL", SbxINTEGER, CPROP_, ConstInt<SbAttributes::NORMAL> },
+{ u"ATTR_READONLY", SbxINTEGER, CPROP_, ConstInt<SbAttributes::READONLY> },
+{ u"ATTR_SYSTEM", SbxINTEGER, CPROP_, ConstInt<SbAttributes::SYSTEM> },
+{ u"ATTR_VOLUME", SbxINTEGER, CPROP_, ConstInt<SbAttributes::VOLUME> },
{ u"Beep", SbxNULL, FUNCTION_, SbRtl_Beep },
{ u"Blue", SbxINTEGER, 1 | FUNCTION_ | NORMONLY_, SbRtl_Blue },
@@ -141,7 +141,7 @@ constexpr Method aMethods[] = {
{ u"CallByName", SbxVARIANT, 3 | FUNCTION_, SbRtl_CallByName },
arg(u"Object", SbxOBJECT),
- arg(u"ProcedureName", SbxSTRING),
+ arg(u"ProcName", SbxSTRING),
arg(u"CallType", SbxINTEGER),
{ u"CBool", SbxBOOL, 1 | FUNCTION_, SbRtl_CBool },
@@ -186,9 +186,11 @@ constexpr Method aMethods[] = {
{ u"CDbl", SbxDOUBLE, 1 | FUNCTION_, SbRtl_CDbl },
arg(u"expression", SbxVARIANT),
-{ u"CF_BITMAP", SbxINTEGER, CPROP_, SbRtl_CF_BITMAP },
-{ u"CF_METAFILEPICT", SbxINTEGER, CPROP_, SbRtl_CF_METAFILEPICT },
-{ u"CF_TEXT", SbxINTEGER, CPROP_, SbRtl_CF_TEXT },
+// FIXME: CF_* are for what??? They duplicate WinAPI clipboard constants, but why?
+{ u"CF_BITMAP", SbxINTEGER, CPROP_, ConstInt<1> },
+{ u"CF_METAFILEPICT", SbxINTEGER, CPROP_, ConstInt<2> },
+{ u"CF_TEXT", SbxINTEGER, CPROP_, ConstInt<3> },
+
{ u"ChDir", SbxNULL, 1 | FUNCTION_, SbRtl_ChDir },
arg(u"string", SbxSTRING),
@@ -200,16 +202,19 @@ constexpr Method aMethods[] = {
arg(u"Expression", SbxVARIANT),
{ u"Chr", SbxSTRING, 1 | FUNCTION_, SbRtl_Chr },
- arg(u"string", SbxINTEGER),
+ arg(u"charcode", SbxLONG),
{ u"ChrW", SbxSTRING, 1 | FUNCTION_ | COMPATONLY_, SbRtl_ChrW },
- arg(u"string", SbxINTEGER),
+ arg(u"charcode", SbxLONG),
{ u"CInt", SbxINTEGER, 1 | FUNCTION_, SbRtl_CInt },
arg(u"expression", SbxVARIANT),
-{ u"CLEAR_ALLTABS", SbxINTEGER, CPROP_, SbRtl_CLEAR_ALLTABS },
-{ u"CLEAR_TAB", SbxINTEGER, CPROP_, SbRtl_CLEAR_TAB },
+// FIXME: what for are these???
+{ u"SET_TAB", SbxINTEGER, CPROP_, ConstInt<0> },
+{ u"CLEAR_TAB", SbxINTEGER, CPROP_, ConstInt<1> },
+{ u"CLEAR_ALLTABS", SbxINTEGER, CPROP_, ConstInt<2> },
+
{ u"CLng", SbxLONG, 1 | FUNCTION_, SbRtl_CLng },
arg(u"expression", SbxVARIANT),
@@ -328,8 +333,8 @@ constexpr Method aMethods[] = {
{ u"Ddeterminateall", SbxNULL, FUNCTION_, SbRtl_DDETerminateAll },
{ u"DimArray", SbxOBJECT, FUNCTION_, SbRtl_DimArray },
{ u"Dir", SbxSTRING, 2 | FUNCTION_, SbRtl_Dir },
- arg(u"FileSpec", SbxSTRING, OPT_),
- arg(u"attrmask", SbxINTEGER, OPT_),
+ arg(u"Pathname", SbxSTRING, OPT_),
+ arg(u"Attributes", SbxINTEGER, OPT_),
{ u"DoEvents", SbxINTEGER, FUNCTION_, SbRtl_DoEvents },
{ u"DumpAllObjects", SbxEMPTY, 2 | SUB_, SbRtl_DumpAllObjects },
@@ -358,7 +363,9 @@ constexpr Method aMethods[] = {
{ u"Exp", SbxDOUBLE, 1 | FUNCTION_, SbRtl_Exp },
arg(u"number", SbxDOUBLE),
-{ u"False", SbxBOOL, CPROP_, SbRtl_False },
+{ u"False", SbxBOOL, CPROP_, ConstBool<false> },
+{ u"True", SbxBOOL, CPROP_, ConstBool<true> },
+
{ u"FileAttr", SbxINTEGER, 2 | FUNCTION_, SbRtl_FileAttr },
arg(u"Channel", SbxINTEGER),
arg(u"Attributes", SbxINTEGER),
@@ -401,12 +408,21 @@ constexpr Method aMethods[] = {
arg(u"useParensForNegativeNumbers", SbxINTEGER, OPT_), // vbTriState
arg(u"groupDigits", SbxINTEGER, OPT_), // vbTriState
+{ u"FormatPercent", SbxSTRING, 5 | FUNCTION_ | COMPATONLY_, SbRtl_FormatPercent },
+ arg(u"expression", SbxDOUBLE),
+ arg(u"numDigitsAfterDecimal", SbxINTEGER, OPT_),
+ arg(u"includeLeadingDigit", SbxINTEGER, OPT_), // vbTriState
+ arg(u"useParensForNegativeNumbers", SbxINTEGER, OPT_), // vbTriState
+ arg(u"groupDigits", SbxINTEGER, OPT_), // vbTriState
+
{ u"Frac", SbxDOUBLE, 1 | FUNCTION_, SbRtl_Frac },
arg(u"number", SbxDOUBLE),
-{ u"FRAMEANCHORCHAR", SbxINTEGER, CPROP_, SbRtl_FRAMEANCHORCHAR },
-{ u"FRAMEANCHORPAGE", SbxINTEGER, CPROP_, SbRtl_FRAMEANCHORPAGE },
-{ u"FRAMEANCHORPARA", SbxINTEGER, CPROP_, SbRtl_FRAMEANCHORPARA },
+// FIXME: what for are these???
+{ u"FRAMEANCHORPAGE", SbxINTEGER, CPROP_, ConstInt<1> },
+{ u"FRAMEANCHORCHAR", SbxINTEGER, CPROP_, ConstInt<15> },
+{ u"FRAMEANCHORPARA", SbxINTEGER, CPROP_, ConstInt<14> },
+
{ u"FreeFile", SbxINTEGER, FUNCTION_, SbRtl_FreeFile },
{ u"FreeLibrary", SbxNULL, 1 | FUNCTION_, SbRtl_FreeLibrary },
arg(u"Modulename", SbxSTRING),
@@ -449,12 +465,14 @@ constexpr Method aMethods[] = {
{ u"Hour", SbxINTEGER, 1 | FUNCTION_, SbRtl_Hour },
arg(u"Date", SbxDATE),
-{ u"IDABORT", SbxINTEGER, CPROP_, SbRtl_IDABORT },
-{ u"IDCANCEL", SbxINTEGER, CPROP_, SbRtl_IDCANCEL },
-{ u"IDNO", SbxINTEGER, CPROP_, SbRtl_IDNO },
-{ u"IDOK", SbxINTEGER, CPROP_, SbRtl_IDOK },
-{ u"IDRETRY", SbxINTEGER, CPROP_, SbRtl_IDRETRY },
-{ u"IDYES", SbxINTEGER, CPROP_, SbRtl_IDYES },
+// Related to: MsgBox (return value)
+{ u"IDABORT", SbxINTEGER, CPROP_, ConstInt<SbMB::Response::ABORT> },
+{ u"IDCANCEL", SbxINTEGER, CPROP_, ConstInt<SbMB::Response::CANCEL> },
+{ u"IDIGNORE", SbxINTEGER, CPROP_, ConstInt<SbMB::Response::IGNORE> },
+{ u"IDNO", SbxINTEGER, CPROP_, ConstInt<SbMB::Response::NO> },
+{ u"IDOK", SbxINTEGER, CPROP_, ConstInt<SbMB::Response::OK> },
+{ u"IDRETRY", SbxINTEGER, CPROP_, ConstInt<SbMB::Response::RETRY> },
+{ u"IDYES", SbxINTEGER, CPROP_, ConstInt<SbMB::Response::YES> },
{ u"Iif", SbxVARIANT, 3 | FUNCTION_, SbRtl_Iif },
arg(u"Bool", SbxBOOL),
@@ -479,10 +497,10 @@ constexpr Method aMethods[] = {
arg(u"Compare", SbxINTEGER, OPT_),
{ u"InStrRev", SbxLONG, 4 | FUNCTION_ | COMPATONLY_, SbRtl_InStrRev },
- arg(u"String1", SbxSTRING),
- arg(u"String2", SbxSTRING),
- arg(u"Start", SbxSTRING, OPT_),
- arg(u"Compare", SbxINTEGER, OPT_),
+ arg(u"StringCheck", SbxSTRING),
+ arg(u"StringMatch", SbxSTRING),
+ arg(u"Start", SbxSTRING, OPT_),
+ arg(u"Compare", SbxINTEGER, OPT_),
{ u"Int", SbxDOUBLE, 1 | FUNCTION_, SbRtl_Int },
arg(u"number", SbxDOUBLE),
@@ -527,8 +545,8 @@ constexpr Method aMethods[] = {
arg(u"Variant", SbxVARIANT),
{ u"Join", SbxSTRING, 2 | FUNCTION_, SbRtl_Join },
- arg(u"list", SbxOBJECT),
- arg(u"delimiter", SbxSTRING),
+ arg(u"SourceArray", SbxOBJECT),
+ arg(u"Delimiter", SbxSTRING),
{ u"Kill", SbxNULL, 1 | FUNCTION_, SbRtl_Kill },
arg(u"filespec", SbxSTRING),
@@ -541,7 +559,7 @@ constexpr Method aMethods[] = {
{ u"Left", SbxSTRING, 2 | FUNCTION_, SbRtl_Left },
arg(u"String", SbxSTRING),
- arg(u"Count", SbxLONG),
+ arg(u"Length", SbxLONG),
{ u"Len", SbxLONG, 1 | FUNCTION_, SbRtl_Len },
arg(u"StringOrVariant", SbxVARIANT),
@@ -567,27 +585,28 @@ constexpr Method aMethods[] = {
{ u"LTrim", SbxSTRING, 1 | FUNCTION_, SbRtl_LTrim },
arg(u"string", SbxSTRING),
-{ u"MB_ABORTRETRYIGNORE", SbxINTEGER, CPROP_, SbRtl_MB_ABORTRETRYIGNORE },
-{ u"MB_APPLMODAL", SbxINTEGER, CPROP_, SbRtl_MB_APPLMODAL },
-{ u"MB_DEFBUTTON1", SbxINTEGER, CPROP_, SbRtl_MB_DEFBUTTON1 },
-{ u"MB_DEFBUTTON2", SbxINTEGER, CPROP_, SbRtl_MB_DEFBUTTON2 },
-{ u"MB_DEFBUTTON3", SbxINTEGER, CPROP_, SbRtl_MB_DEFBUTTON3 },
-{ u"MB_ICONEXCLAMATION", SbxINTEGER, CPROP_, SbRtl_MB_ICONEXCLAMATION },
-{ u"MB_ICONINFORMATION", SbxINTEGER, CPROP_, SbRtl_MB_ICONINFORMATION },
-{ u"MB_ICONQUESTION", SbxINTEGER, CPROP_, SbRtl_MB_ICONQUESTION },
-{ u"MB_ICONSTOP", SbxINTEGER, CPROP_, SbRtl_MB_ICONSTOP },
-{ u"MB_OK", SbxINTEGER, CPROP_, SbRtl_MB_OK },
-{ u"MB_OKCANCEL", SbxINTEGER, CPROP_, SbRtl_MB_OKCANCEL },
-{ u"MB_RETRYCANCEL", SbxINTEGER, CPROP_, SbRtl_MB_RETRYCANCEL },
-{ u"MB_SYSTEMMODAL", SbxINTEGER, CPROP_, SbRtl_MB_SYSTEMMODAL },
-{ u"MB_YESNO", SbxINTEGER, CPROP_, SbRtl_MB_YESNO },
-{ u"MB_YESNOCANCEL", SbxINTEGER, CPROP_, SbRtl_MB_YESNOCANCEL },
+// Related to: MsgBox (Buttons argument)
+{ u"MB_ABORTRETRYIGNORE", SbxINTEGER, CPROP_, ConstInt<SbMB::ABORTRETRYIGNORE> },
+{ u"MB_APPLMODAL", SbxINTEGER, CPROP_, ConstInt<SbMB::APPLMODAL> },
+{ u"MB_DEFBUTTON1", SbxINTEGER, CPROP_, ConstInt<SbMB::DEFBUTTON1> },
+{ u"MB_DEFBUTTON2", SbxINTEGER, CPROP_, ConstInt<SbMB::DEFBUTTON2> },
+{ u"MB_DEFBUTTON3", SbxINTEGER, CPROP_, ConstInt<SbMB::DEFBUTTON3> },
+{ u"MB_ICONEXCLAMATION", SbxINTEGER, CPROP_, ConstInt<SbMB::ICONEXCLAMATION> },
+{ u"MB_ICONINFORMATION", SbxINTEGER, CPROP_, ConstInt<SbMB::ICONINFORMATION> },
+{ u"MB_ICONQUESTION", SbxINTEGER, CPROP_, ConstInt<SbMB::ICONQUESTION> },
+{ u"MB_ICONSTOP", SbxINTEGER, CPROP_, ConstInt<SbMB::ICONSTOP> },
+{ u"MB_OK", SbxINTEGER, CPROP_, ConstInt<SbMB::OK> },
+{ u"MB_OKCANCEL", SbxINTEGER, CPROP_, ConstInt<SbMB::OKCANCEL> },
+{ u"MB_RETRYCANCEL", SbxINTEGER, CPROP_, ConstInt<SbMB::RETRYCANCEL> },
+{ u"MB_SYSTEMMODAL", SbxINTEGER, CPROP_, ConstInt<SbMB::SYSTEMMODAL> },
+{ u"MB_YESNO", SbxINTEGER, CPROP_, ConstInt<SbMB::YESNO> },
+{ u"MB_YESNOCANCEL", SbxINTEGER, CPROP_, ConstInt<SbMB::YESNOCANCEL> },
{ u"Me", SbxOBJECT, 0 | FUNCTION_ | COMPATONLY_, SbRtl_Me },
{ u"Mid", SbxSTRING, 3 | LFUNCTION_, SbRtl_Mid },
- arg(u"String", SbxSTRING),
- arg(u"StartPos", SbxLONG),
- arg(u"Length", SbxLONG, OPT_),
+ arg(u"String", SbxSTRING),
+ arg(u"Start", SbxLONG),
+ arg(u"Length", SbxLONG, OPT_),
{ u"Minute", SbxINTEGER, 1 | FUNCTION_, SbRtl_Minute },
arg(u"Date", SbxDATE),
@@ -703,7 +722,7 @@ constexpr Method aMethods[] = {
{ u"Right", SbxSTRING, 2 | FUNCTION_, SbRtl_Right },
arg(u"String", SbxSTRING),
- arg(u"Count", SbxLONG),
+ arg(u"Length", SbxLONG),
{ u"RmDir", SbxNULL, 1 | FUNCTION_, SbRtl_RmDir },
arg(u"pathname", SbxSTRING),
@@ -734,18 +753,20 @@ constexpr Method aMethods[] = {
arg(u"Wait", SbxBOOL, OPT_),
{ u"SetAttr", SbxNULL, 2 | FUNCTION_, SbRtl_SetAttr },
- arg(u"File", SbxSTRING),
+ arg(u"PathName", SbxSTRING),
arg(u"Attributes", SbxINTEGER),
-{ u"SET_OFF", SbxINTEGER, CPROP_, SbRtl_SET_OFF },
-{ u"SET_ON", SbxINTEGER, CPROP_, SbRtl_SET_ON },
-{ u"SET_TAB", SbxINTEGER, CPROP_, SbRtl_SET_TAB },
+// FIXME: what for are these???
+{ u"SET_OFF", SbxINTEGER, CPROP_, ConstInt<0> },
+{ u"SET_ON", SbxINTEGER, CPROP_, ConstInt<1> },
+{ u"TOGGLE", SbxINTEGER, CPROP_, ConstInt<2> },
+
{ u"Sgn", SbxINTEGER, 1 | FUNCTION_, SbRtl_Sgn },
arg(u"number", SbxDOUBLE),
{ u"Shell", SbxLONG, 2 | FUNCTION_, SbRtl_Shell },
- arg(u"Commandstring", SbxSTRING),
- arg(u"WindowStyle", SbxINTEGER, OPT_),
+ arg(u"PathName", SbxSTRING),
+ arg(u"WindowStyle", SbxINTEGER, OPT_),
{ u"Sin", SbxDOUBLE, 1 | FUNCTION_, SbRtl_Sin },
arg(u"number", SbxDOUBLE),
@@ -762,15 +783,15 @@ constexpr Method aMethods[] = {
arg(u"Period", SbxDOUBLE),
{ u"Space", SbxSTRING, 1 | FUNCTION_, SbRtl_Space },
- arg(u"string", SbxLONG),
+ arg(u"Number", SbxLONG),
-{ u"Spc", SbxSTRING, 1 | FUNCTION_, SbRtl_Spc },
- arg(u"Count", SbxLONG),
+{ u"Spc", SbxSTRING, 1 | FUNCTION_, SbRtl_Space },
+ arg(u"Number", SbxLONG),
{ u"Split", SbxOBJECT, 3 | FUNCTION_, SbRtl_Split },
arg(u"expression", SbxSTRING),
arg(u"delimiter", SbxSTRING),
- arg(u"count", SbxLONG),
+ arg(u"Limit", SbxLONG),
{ u"Sqr", SbxDOUBLE, 1 | FUNCTION_, SbRtl_Sqr },
arg(u"number", SbxDOUBLE),
@@ -789,8 +810,8 @@ constexpr Method aMethods[] = {
arg(u"LCID", SbxINTEGER, OPT_),
{ u"String", SbxSTRING, 2 | FUNCTION_, SbRtl_String },
- arg(u"Count", SbxLONG),
- arg(u"Filler", SbxVARIANT),
+ arg(u"Number", SbxLONG),
+ arg(u"Character", SbxVARIANT),
{ u"StrReverse", SbxSTRING, 1 | FUNCTION_ | COMPATONLY_, SbRtl_StrReverse },
arg(u"String1", SbxSTRING),
@@ -815,59 +836,58 @@ constexpr Method aMethods[] = {
{ u"TimeValue", SbxDATE, 1 | FUNCTION_, SbRtl_TimeValue },
arg(u"String", SbxSTRING),
-{ u"TOGGLE", SbxINTEGER, CPROP_, SbRtl_TOGGLE },
{ u"Trim", SbxSTRING, 1 | FUNCTION_, SbRtl_Trim },
arg(u"String", SbxSTRING),
-{ u"True", SbxBOOL, CPROP_, SbRtl_True },
{ u"TwipsPerPixelX", SbxLONG, FUNCTION_, SbRtl_TwipsPerPixelX },
{ u"TwipsPerPixelY", SbxLONG, FUNCTION_, SbRtl_TwipsPerPixelY },
-{ u"TYP_AUTHORFLD", SbxINTEGER, CPROP_, SbRtl_TYP_AUTHORFLD },
-{ u"TYP_CHAPTERFLD", SbxINTEGER, CPROP_, SbRtl_TYP_CHAPTERFLD },
-{ u"TYP_CONDTXTFLD", SbxINTEGER, CPROP_, SbRtl_TYP_CONDTXTFLD },
-{ u"TYP_DATEFLD", SbxINTEGER, CPROP_, SbRtl_TYP_DATEFLD },
-{ u"TYP_DBFLD", SbxINTEGER, CPROP_, SbRtl_TYP_DBFLD },
-{ u"TYP_DBNAMEFLD", SbxINTEGER, CPROP_, SbRtl_TYP_DBNAMEFLD },
-{ u"TYP_DBNEXTSETFLD", SbxINTEGER, CPROP_, SbRtl_TYP_DBNEXTSETFLD },
-{ u"TYP_DBNUMSETFLD", SbxINTEGER, CPROP_, SbRtl_TYP_DBNUMSETFLD },
-{ u"TYP_DBSETNUMBERFLD", SbxINTEGER, CPROP_, SbRtl_TYP_DBSETNUMBERFLD },
-{ u"TYP_DDEFLD", SbxINTEGER, CPROP_, SbRtl_TYP_DDEFLD },
-{ u"TYP_DOCINFOFLD", SbxINTEGER, CPROP_, SbRtl_TYP_DOCINFOFLD },
-{ u"TYP_DOCSTATFLD", SbxINTEGER, CPROP_, SbRtl_TYP_DOCSTATFLD },
-{ u"TYP_EXTUSERFLD", SbxINTEGER, CPROP_, SbRtl_TYP_EXTUSERFLD },
-{ u"TYP_FILENAMEFLD", SbxINTEGER, CPROP_, SbRtl_TYP_FILENAMEFLD },
-{ u"TYP_FIXDATEFLD", SbxINTEGER, CPROP_, SbRtl_TYP_FIXDATEFLD },
-{ u"TYP_FIXTIMEFLD", SbxINTEGER, CPROP_, SbRtl_TYP_FIXTIMEFLD },
-{ u"TYP_FORMELFLD", SbxINTEGER, CPROP_, SbRtl_TYP_FORMELFLD },
-{ u"TYP_GETFLD", SbxINTEGER, CPROP_, SbRtl_TYP_GETFLD },
-{ u"TYP_GETREFFLD", SbxINTEGER, CPROP_, SbRtl_TYP_GETREFFLD },
-{ u"TYP_GETREFPAGEFLD", SbxINTEGER, CPROP_, SbRtl_TYP_GETREFPAGEFLD },
-{ u"TYP_HIDDENPARAFLD", SbxINTEGER, CPROP_, SbRtl_TYP_HIDDENPARAFLD },
-{ u"TYP_HIDDENTXTFLD", SbxINTEGER, CPROP_, SbRtl_TYP_HIDDENTXTFLD },
-{ u"TYP_INPUTFLD", SbxINTEGER, CPROP_, SbRtl_TYP_INPUTFLD },
-{ u"TYP_INTERNETFLD", SbxINTEGER, CPROP_, SbRtl_TYP_INTERNETFLD },
-{ u"TYP_JUMPEDITFLD", SbxINTEGER, CPROP_, SbRtl_TYP_JUMPEDITFLD },
-{ u"TYP_MACROFLD", SbxINTEGER, CPROP_, SbRtl_TYP_MACROFLD },
-{ u"TYP_NEXTPAGEFLD", SbxINTEGER, CPROP_, SbRtl_TYP_NEXTPAGEFLD },
-{ u"TYP_PAGENUMBERFLD", SbxINTEGER, CPROP_, SbRtl_TYP_PAGENUMBERFLD },
-{ u"TYP_POSTITFLD", SbxINTEGER, CPROP_, SbRtl_TYP_POSTITFLD },
-{ u"TYP_PREVPAGEFLD", SbxINTEGER, CPROP_, SbRtl_TYP_PREVPAGEFLD },
-{ u"TYP_SEQFLD", SbxINTEGER, CPROP_, SbRtl_TYP_SEQFLD },
-{ u"TYP_SETFLD", SbxINTEGER, CPROP_, SbRtl_TYP_SETFLD },
-{ u"TYP_SETINPFLD", SbxINTEGER, CPROP_, SbRtl_TYP_SETINPFLD },
-{ u"TYP_SETREFFLD", SbxINTEGER, CPROP_, SbRtl_TYP_SETREFFLD },
-{ u"TYP_SETREFPAGEFLD", SbxINTEGER, CPROP_, SbRtl_TYP_SETREFPAGEFLD },
-{ u"TYP_TEMPLNAMEFLD", SbxINTEGER, CPROP_, SbRtl_TYP_TEMPLNAMEFLD },
-{ u"TYP_TIMEFLD", SbxINTEGER, CPROP_, SbRtl_TYP_TIMEFLD },
-{ u"TYP_USERFLD", SbxINTEGER, CPROP_, SbRtl_TYP_USERFLD },
-{ u"TYP_USRINPFLD", SbxINTEGER, CPROP_, SbRtl_TYP_USRINPFLD },
+// Related to: SwFieldTypesEnum in sw/inc/fldbas.hxx, .uno:InsertField (Type param), .uno:InsertDBField (Type param)
+{ u"TYP_AUTHORFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::AUTHOR> },
+{ u"TYP_CHAPTERFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::CHAPTER> },
+{ u"TYP_CONDTXTFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::CONDITIONALTEXT> },
+{ u"TYP_DATEFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::DATE> },
+{ u"TYP_DBFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::DATABASE> },
+{ u"TYP_DBNAMEFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::DATABASENAME> },
+{ u"TYP_DBNEXTSETFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::DATABASENEXTSET> },
+{ u"TYP_DBNUMSETFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::DATABASENUMBERSET> },
+{ u"TYP_DBSETNUMBERFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::DATABASESETNUMBER> },
+{ u"TYP_DDEFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::DDE> },
+{ u"TYP_DOCINFOFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::DOCUMENTINFO> },
+{ u"TYP_DOCSTATFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::DOCUMENTSTATISTICS> },
+{ u"TYP_EXTUSERFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::EXTENDEDUSER> },
+{ u"TYP_FILENAMEFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::FILENAME> },
+{ u"TYP_FIXDATEFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::FIXEDDATE> },
+{ u"TYP_FIXTIMEFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::FIXEDTIME> },
+{ u"TYP_FORMELFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::FORMEL> },
+{ u"TYP_GETFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::GET> },
+{ u"TYP_GETREFFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::GETREF> },
+{ u"TYP_GETREFPAGEFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::GETREFPAGE> },
+{ u"TYP_HIDDENPARAFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::HIDDENPARAGRAPH> },
+{ u"TYP_HIDDENTXTFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::HIDDENTEXT> },
+{ u"TYP_INPUTFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::INPUT> },
+{ u"TYP_INTERNETFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::INTERNET> },
+{ u"TYP_JUMPEDITFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::JUMPEDIT> },
+{ u"TYP_MACROFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::MACRO> },
+{ u"TYP_NEXTPAGEFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::NEXTPAGE> },
+{ u"TYP_PAGENUMBERFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::PAGENUMBER> },
+{ u"TYP_POSTITFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::POSTIT> },
+{ u"TYP_PREVPAGEFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::PREVIOUSPAGE> },
+{ u"TYP_SEQFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::SEQUENCE> },
+{ u"TYP_SETFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::SET> },
+{ u"TYP_SETINPFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::SETINPUT> },
+{ u"TYP_SETREFFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::SETREF> },
+{ u"TYP_SETREFPAGEFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::SETREFPAGE> },
+{ u"TYP_TEMPLNAMEFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::TEMPLATENAME> },
+{ u"TYP_TIMEFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::TIME> },
+{ u"TYP_USERFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::USER> },
+{ u"TYP_USRINPFLD", SbxINTEGER, CPROP_, ConstInt<SbTYP::USERINPUT> },
{ u"TypeLen", SbxINTEGER, 1 | FUNCTION_, SbRtl_TypeLen },
arg(u"Var", SbxVARIANT),
{ u"TypeName", SbxSTRING, 1 | FUNCTION_, SbRtl_TypeName },
- arg(u"Var", SbxVARIANT),
+ arg(u"Varname", SbxVARIANT),
{ u"UBound", SbxLONG, 1 | FUNCTION_, SbRtl_UBound },
arg(u"Var", SbxVARIANT),
@@ -882,17 +902,18 @@ constexpr Method aMethods[] = {
arg(u"String", SbxSTRING),
{ u"VarType", SbxINTEGER, 1 | FUNCTION_, SbRtl_VarType },
- arg(u"Var", SbxVARIANT),
-
-{ u"V_EMPTY", SbxINTEGER, CPROP_, SbRtl_V_EMPTY },
-{ u"V_NULL", SbxINTEGER, CPROP_, SbRtl_V_NULL },
-{ u"V_INTEGER", SbxINTEGER, CPROP_, SbRtl_V_INTEGER },
-{ u"V_LONG", SbxINTEGER, CPROP_, SbRtl_V_LONG },
-{ u"V_SINGLE", SbxINTEGER, CPROP_, SbRtl_V_SINGLE },
-{ u"V_DOUBLE", SbxINTEGER, CPROP_, SbRtl_V_DOUBLE },
-{ u"V_CURRENCY", SbxINTEGER, CPROP_, SbRtl_V_CURRENCY },
-{ u"V_DATE", SbxINTEGER, CPROP_, SbRtl_V_DATE },
-{ u"V_STRING", SbxINTEGER, CPROP_, SbRtl_V_STRING },
+ arg(u"Varname", SbxVARIANT),
+
+// Related to: VarType
+{ u"V_EMPTY", SbxINTEGER, CPROP_, ConstInt<SbxEMPTY> },
+{ u"V_NULL", SbxINTEGER, CPROP_, ConstInt<SbxNULL> },
+{ u"V_INTEGER", SbxINTEGER, CPROP_, ConstInt<SbxINTEGER> },
+{ u"V_LONG", SbxINTEGER, CPROP_, ConstInt<SbxLONG> },
+{ u"V_SINGLE", SbxINTEGER, CPROP_, ConstInt<SbxSINGLE> },
+{ u"V_DOUBLE", SbxINTEGER, CPROP_, ConstInt<SbxDOUBLE> },
+{ u"V_CURRENCY", SbxINTEGER, CPROP_, ConstInt<SbxCURRENCY> },
+{ u"V_DATE", SbxINTEGER, CPROP_, ConstInt<SbxDATE> },
+{ u"V_STRING", SbxINTEGER, CPROP_, ConstInt<SbxSTRING> },
{ u"Wait", SbxNULL, 1 | FUNCTION_, SbRtl_Wait },
arg(u"Milliseconds", SbxLONG),
@@ -913,28 +934,50 @@ constexpr Method aMethods[] = {
{ u"Year", SbxINTEGER, 1 | FUNCTION_, SbRtl_Year },
arg(u"Date", SbxDATE),
-
-{ {}, SbxNULL, -1, nullptr }}; // end of the table
+}; // end of the table
static_assert(MethodsTableValid(aMethods));
+// building the info-structure for single elements
+// if nIdx = 0, don't create anything (Std-Props!)
+
+SbxInfo* GetMethodInfo(std::size_t nIdx)
+{
+ if (!nIdx)
+ return nullptr;
+ assert(nIdx <= std::size(aMethods));
+ const Method* p = &aMethods[nIdx - 1];
+ SbxInfo* pInfo_ = new SbxInfo;
+ short nPar = p->nArgs & ARGSMASK_;
+ for (short i = 0; i < nPar; i++)
+ {
+ p++;
+ SbxFlagBits nFlags_ = static_cast<SbxFlagBits>((p->nArgs >> 8) & 0x03);
+ if (p->nArgs & OPT_)
+ nFlags_ |= SbxFlagBits::Optional;
+ pInfo_->AddParam(OUString(p->sName), p->eType, nFlags_);
+ }
+ return pInfo_;
+}
+}
+
SbiStdObject::SbiStdObject( const OUString& r, StarBASIC* pb ) : SbxObject( r )
{
// #i92642: Remove default properties
- Remove( "Name", SbxClassType::DontCare );
- Remove( "Parent", SbxClassType::DontCare );
+ Remove( u"Name"_ustr, SbxClassType::DontCare );
+ Remove( u"Parent"_ustr, SbxClassType::DontCare );
SetParent( pb );
- pStdFactory.reset( new SbStdFactory );
- SbxBase::AddFactory( pStdFactory.get() );
+ pStdFactory.emplace();
+ SbxBase::AddFactory( &*pStdFactory );
Insert( new SbStdClipboard );
}
SbiStdObject::~SbiStdObject()
{
- SbxBase::RemoveFactory( pStdFactory.get() );
+ SbxBase::RemoveFactory( &*pStdFactory );
pStdFactory.reset();
}
@@ -954,7 +997,7 @@ SbxVariable* SbiStdObject::Find( const OUString& rName, SbxClassType t )
{
// else search one
sal_uInt16 nHash_ = SbxVariable::MakeHashCode( rName );
- const Method* p = aMethods;
+ auto p = std::begin(aMethods);
bool bFound = false;
short nIndex = 0;
sal_uInt16 nSrchMask = TYPEMASK_;
@@ -965,8 +1008,9 @@ SbxVariable* SbiStdObject::Find( const OUString& rName, SbxClassType t )
case SbxClassType::Object: nSrchMask = OBJECT_; break;
default: break;
}
- while( p->nArgs != -1 )
+ while (p != std::end(aMethods))
{
+ assert(p < std::end(aMethods));
if( ( p->nArgs & nSrchMask )
&& ( p->nHash == nHash_ )
&& (rName.equalsIgnoreAsciiCase(p->sName)))
@@ -985,7 +1029,7 @@ SbxVariable* SbiStdObject::Find( const OUString& rName, SbxClassType t )
// No instance running => compiling a source on module level.
const SbModule* pModule = GetSbData()->pCompMod;
if (pModule)
- bCompatibility = pModule->IsVBACompat();
+ bCompatibility = pModule->IsVBASupport();
}
if ((bCompatibility && (NORMONLY_ & p->nArgs)) || (!bCompatibility && (COMPATONLY_ & p->nArgs)))
bFound = false;
@@ -1035,14 +1079,15 @@ void SbiStdObject::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
SbxVariable* pVar = pHint->GetVar();
SbxArray* pPar_ = pVar->GetParameters();
- const sal_uInt16 nCallId = static_cast<sal_uInt16>(pVar->GetUserData());
+ const std::size_t nCallId = pVar->GetUserData();
if( nCallId )
{
const SfxHintId t = pHint->GetId();
if( t == SfxHintId::BasicInfoWanted )
- pVar->SetInfo( GetInfo( static_cast<short>(pVar->GetUserData()) ) );
+ pVar->SetInfo(GetMethodInfo(nCallId));
else
{
+ assert(nCallId <= std::size(aMethods));
bool bWrite = false;
if( t == SfxHintId::BasicDataChanged )
bWrite = true;
@@ -1063,27 +1108,4 @@ void SbiStdObject::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
SbxObject::Notify( rBC, rHint );
}
-// building the info-structure for single elements
-// if nIdx = 0, don't create anything (Std-Props!)
-
-SbxInfo* SbiStdObject::GetInfo( short nIdx )
-{
- if( !nIdx )
- return nullptr;
- const Method* p = &aMethods[ --nIdx ];
- SbxInfo* pInfo_ = new SbxInfo;
- short nPar = p->nArgs & ARGSMASK_;
- for( short i = 0; i < nPar; i++ )
- {
- p++;
- SbxFlagBits nFlags_ = static_cast<SbxFlagBits>(( p->nArgs >> 8 ) & 0x03);
- if( p->nArgs & OPT_ )
- {
- nFlags_ |= SbxFlagBits::Optional;
- }
- pInfo_->AddParam(OUString(p->sName), p->eType, nFlags_);
- }
- return pInfo_;
-}
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/runtime/stdobj1.cxx b/basic/source/runtime/stdobj1.cxx
index ee7df8d7a62d..533eb2f92f24 100644
--- a/basic/source/runtime/stdobj1.cxx
+++ b/basic/source/runtime/stdobj1.cxx
@@ -22,23 +22,26 @@
#include <vcl/outdev.hxx>
#include <sbstdobj.hxx>
-#define ATTR_IMP_TYPE 1
-#define ATTR_IMP_WIDTH 2
-#define ATTR_IMP_HEIGHT 3
-#define ATTR_IMP_BOLD 4
-#define ATTR_IMP_ITALIC 5
-#define ATTR_IMP_STRIKETHROUGH 6
-#define ATTR_IMP_UNDERLINE 7
-#define ATTR_IMP_SIZE 9
-#define ATTR_IMP_NAME 10
-
-#define METH_CLEAR 20
-#define METH_GETDATA 21
-#define METH_GETFORMAT 22
-#define METH_GETTEXT 23
-#define METH_SETDATA 24
-#define METH_SETTEXT 25
-
+namespace {
+ enum UserData
+ {
+ ATTR_IMP_TYPE = 1,
+ ATTR_IMP_WIDTH = 2,
+ ATTR_IMP_HEIGHT = 3,
+ ATTR_IMP_BOLD = 4,
+ ATTR_IMP_ITALIC = 5,
+ ATTR_IMP_STRIKETHROUGH = 6,
+ ATTR_IMP_UNDERLINE = 7,
+ ATTR_IMP_SIZE = 9,
+ ATTR_IMP_NAME = 10,
+ METH_CLEAR = 20,
+ METH_GETDATA = 21,
+ METH_GETFORMAT = 22,
+ METH_GETTEXT = 23,
+ METH_SETDATA = 24,
+ METH_SETTEXT = 25
+ };
+}
SbStdFactory::SbStdFactory()
{
@@ -101,16 +104,16 @@ void SbStdPicture::PropHeight( SbxVariable* pVar, bool bWrite )
SbStdPicture::SbStdPicture() :
- SbxObject( "Picture" )
+ SbxObject( u"Picture"_ustr )
{
// Properties
- SbxVariable* p = Make( "Type", SbxClassType::Property, SbxVARIANT );
+ SbxVariable* p = Make( u"Type"_ustr, SbxClassType::Property, SbxVARIANT );
p->SetFlags( SbxFlagBits::Read | SbxFlagBits::DontStore );
p->SetUserData( ATTR_IMP_TYPE );
- p = Make( "Width", SbxClassType::Property, SbxVARIANT );
+ p = Make( u"Width"_ustr, SbxClassType::Property, SbxVARIANT );
p->SetFlags( SbxFlagBits::Read | SbxFlagBits::DontStore );
p->SetUserData( ATTR_IMP_WIDTH );
- p = Make( "Height", SbxClassType::Property, SbxVARIANT );
+ p = Make( u"Height"_ustr, SbxClassType::Property, SbxVARIANT );
p->SetFlags( SbxFlagBits::Read | SbxFlagBits::DontStore );
p->SetUserData( ATTR_IMP_HEIGHT );
}
@@ -144,6 +147,7 @@ void SbStdPicture::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
case ATTR_IMP_TYPE: PropType( pVar, bWrite ); return;
case ATTR_IMP_WIDTH: PropWidth( pVar, bWrite ); return;
case ATTR_IMP_HEIGHT: PropHeight( pVar, bWrite ); return;
+ default: break;
}
SbxObject::Notify( rBC, rHint );
@@ -204,7 +208,7 @@ void SbStdFont::PropName( SbxVariable* pVar, bool bWrite )
SbStdFont::SbStdFont()
- : SbxObject( "Font" )
+ : SbxObject( u"Font"_ustr )
, bBold(false)
, bItalic(false)
, bStrikeThrough(false)
@@ -212,24 +216,24 @@ SbStdFont::SbStdFont()
, nSize(0)
{
// Properties
- SbxVariable* p = Make( "Bold", SbxClassType::Property, SbxVARIANT );
+ SbxVariable* p = Make( u"Bold"_ustr, SbxClassType::Property, SbxVARIANT );
p->SetFlags( SbxFlagBits::ReadWrite | SbxFlagBits::DontStore );
p->SetUserData( ATTR_IMP_BOLD );
- p = Make( "Italic", SbxClassType::Property, SbxVARIANT );
+ p = Make( u"Italic"_ustr, SbxClassType::Property, SbxVARIANT );
p->SetFlags( SbxFlagBits::ReadWrite | SbxFlagBits::DontStore );
p->SetUserData( ATTR_IMP_ITALIC );
- p = Make( "StrikeThrough", SbxClassType::Property, SbxVARIANT );
+ p = Make( u"StrikeThrough"_ustr, SbxClassType::Property, SbxVARIANT );
p->SetFlags( SbxFlagBits::ReadWrite | SbxFlagBits::DontStore );
p->SetUserData( ATTR_IMP_STRIKETHROUGH );
- p = Make( "Underline", SbxClassType::Property, SbxVARIANT );
+ p = Make( u"Underline"_ustr, SbxClassType::Property, SbxVARIANT );
p->SetFlags( SbxFlagBits::ReadWrite | SbxFlagBits::DontStore );
p->SetUserData( ATTR_IMP_UNDERLINE );
- p = Make( "Size", SbxClassType::Property, SbxVARIANT );
+ p = Make( u"Size"_ustr, SbxClassType::Property, SbxVARIANT );
p->SetFlags( SbxFlagBits::ReadWrite | SbxFlagBits::DontStore );
p->SetUserData( ATTR_IMP_SIZE );
// handle name property yourself
- p = Find( "Name", SbxClassType::Property );
+ p = Find( u"Name"_ustr, SbxClassType::Property );
assert(p && "No Name Property");
p->SetUserData( ATTR_IMP_NAME );
}
@@ -264,6 +268,7 @@ void SbStdFont::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
case ATTR_IMP_UNDERLINE: PropUnderline( pVar, bWrite ); return;
case ATTR_IMP_SIZE: PropSize( pVar, bWrite ); return;
case ATTR_IMP_NAME: PropName( pVar, bWrite ); return;
+ default: break;
}
SbxObject::Notify( rBC, rHint );
@@ -355,29 +360,29 @@ void SbStdClipboard::MethSetText( SbxArray const * pPar_ )
SbStdClipboard::SbStdClipboard() :
- SbxObject( "Clipboard" )
+ SbxObject( u"Clipboard"_ustr )
{
- SbxVariable* p = Find( "Name", SbxClassType::Property );
+ SbxVariable* p = Find( u"Name"_ustr, SbxClassType::Property );
assert(p && "No Name Property");
p->SetUserData( ATTR_IMP_NAME );
// register methods
- p = Make( "Clear", SbxClassType::Method, SbxEMPTY );
+ p = Make( u"Clear"_ustr, SbxClassType::Method, SbxEMPTY );
p->SetFlag( SbxFlagBits::DontStore );
p->SetUserData( METH_CLEAR );
- p = Make( "GetData", SbxClassType::Method, SbxEMPTY );
+ p = Make( u"GetData"_ustr, SbxClassType::Method, SbxEMPTY );
p->SetFlag( SbxFlagBits::DontStore );
p->SetUserData( METH_GETDATA );
- p = Make( "GetFormat", SbxClassType::Method, SbxEMPTY );
+ p = Make( u"GetFormat"_ustr, SbxClassType::Method, SbxEMPTY );
p->SetFlag( SbxFlagBits::DontStore );
p->SetUserData( METH_GETFORMAT );
- p = Make( "GetText", SbxClassType::Method, SbxEMPTY );
+ p = Make( u"GetText"_ustr, SbxClassType::Method, SbxEMPTY );
p->SetFlag( SbxFlagBits::DontStore );
p->SetUserData( METH_GETTEXT );
- p = Make( "SetData", SbxClassType::Method, SbxEMPTY );
+ p = Make( u"SetData"_ustr, SbxClassType::Method, SbxEMPTY );
p->SetFlag( SbxFlagBits::DontStore );
p->SetUserData( METH_SETDATA );
- p = Make( "SetText", SbxClassType::Method, SbxEMPTY );
+ p = Make( u"SetText"_ustr, SbxClassType::Method, SbxEMPTY );
p->SetFlag( SbxFlagBits::DontStore );
p->SetUserData( METH_SETTEXT );
}
@@ -412,6 +417,7 @@ void SbStdClipboard::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
case METH_GETTEXT: MethGetText( pVar, pPar_ ); return;
case METH_SETDATA: MethSetData( pPar_ ); return;
case METH_SETTEXT: MethSetText( pPar_ ); return;
+ default: break;
}
SbxObject::Notify( rBC, rHint );
diff --git a/basic/source/sbx/sbxarray.cxx b/basic/source/sbx/sbxarray.cxx
index d8f16f5891c1..5be00ebf010d 100644
--- a/basic/source/sbx/sbxarray.cxx
+++ b/basic/source/sbx/sbxarray.cxx
@@ -24,7 +24,9 @@
#include <basic/sbx.hxx>
#include <runtime.hxx>
+#include <cstddef>
#include <optional>
+#include <filefmt.hxx>
struct SbxVarEntry
{
@@ -142,17 +144,17 @@ void SbxArray::Put( SbxVariable* pVar, sal_uInt32 nIdx )
}
}
-OUString SbxArray::GetAlias( sal_uInt32 nIdx )
+const OUString & SbxArray::GetAlias( sal_uInt32 nIdx )
{
if( !CanRead() )
{
SetError( ERRCODE_BASIC_PROP_WRITEONLY );
- return OUString();
+ return EMPTY_OUSTRING;
}
SbxVarEntry& rRef = reinterpret_cast<SbxVarEntry&>(GetRef( nIdx ));
if (!rRef.maAlias)
- return OUString();
+ return EMPTY_OUSTRING;
return *rRef.maAlias;
}
@@ -277,6 +279,7 @@ SbxVariable* SbxArray::Find( const OUString& rName, SbxClassType t )
return nullptr;
bool bExtSearch = IsSet( SbxFlagBits::ExtSearch );
sal_uInt16 nHash = SbxVariable::MakeHashCode( rName );
+ const OUString aNameCI = SbxVariable::NameToCaseInsensitiveName(rName);
for (auto& rEntry : mVarEntries)
{
if (!rEntry.mpVar.is() || !rEntry.mpVar->IsVisible())
@@ -284,9 +287,10 @@ SbxVariable* SbxArray::Find( const OUString& rName, SbxClassType t )
// The very secure search works as well, if there is no hashcode!
sal_uInt16 nVarHash = rEntry.mpVar->GetHashCode();
+ // tdf#148358 - compare the names case-insensitive
if ( (!nVarHash || nVarHash == nHash)
&& (t == SbxClassType::DontCare || rEntry.mpVar->GetClass() == t)
- && (rEntry.mpVar->GetName().equalsIgnoreAsciiCase(rName)))
+ && (rEntry.mpVar->GetName(SbxNameType::CaseInsensitive) == aNameCI))
{
p = rEntry.mpVar.get();
p->ResetFlag(SbxFlagBits::ExtFound);
@@ -342,7 +346,7 @@ bool SbxArray::LoadData( SvStream& rStrm, sal_uInt16 /*nVer*/ )
if( pVar )
{
SbxVariableRef& rRef = GetRef( nIdx );
- rRef = pVar;
+ rRef = std::move(pVar);
}
else
{
@@ -354,7 +358,7 @@ bool SbxArray::LoadData( SvStream& rStrm, sal_uInt16 /*nVer*/ )
return bRes;
}
-bool SbxArray::StoreData( SvStream& rStrm ) const
+std::pair<bool, sal_uInt32> SbxArray::StoreData( SvStream& rStrm ) const
{
sal_uInt32 nElem = 0;
// Which elements are even defined?
@@ -364,17 +368,24 @@ bool SbxArray::StoreData( SvStream& rStrm ) const
nElem++;
}
rStrm.WriteUInt16( nElem );
+
+ sal_uInt32 nVersion = B_IMG_VERSION_12;
for( size_t n = 0; n < mVarEntries.size(); n++ )
{
const SbxVarEntry& rEntry = mVarEntries[n];
if (rEntry.mpVar.is() && !(rEntry.mpVar->GetFlags() & SbxFlagBits::DontStore))
{
rStrm.WriteUInt16( n );
- if (!rEntry.mpVar->Store(rStrm))
- return false;
+ const auto [bSuccess, nVersionModule] = rEntry.mpVar->Store(rStrm);
+ if (!bSuccess)
+ return { false, 0 };
+ else if (nVersionModule > nVersion)
+ {
+ nVersion = nVersionModule;
+ }
}
}
- return true;
+ return { true, nVersion };
}
// #100883 Method to set method directly to parameter array
@@ -446,7 +457,7 @@ void SbxDimArray::unoAddDim( sal_Int32 lb, sal_Int32 ub )
bool SbxDimArray::GetDim( sal_Int32 n, sal_Int32& rlb, sal_Int32& rub ) const
{
- if( n < 1 || n > static_cast<sal_Int32>(m_vDimensions.size()) )
+ if( n < 1 || o3tl::make_unsigned(n) > m_vDimensions.size() )
{
SetError( ERRCODE_BASIC_OUT_OF_RANGE );
rub = rlb = 0;
@@ -556,11 +567,11 @@ bool SbxDimArray::LoadData( SvStream& rStrm, sal_uInt16 nVer )
return SbxArray::LoadData( rStrm, nVer );
}
-bool SbxDimArray::StoreData( SvStream& rStrm ) const
+std::pair<bool, sal_uInt32> SbxDimArray::StoreData( SvStream& rStrm ) const
{
assert(m_vDimensions.size() <= sal::static_int_cast<size_t>(std::numeric_limits<sal_Int16>::max()));
rStrm.WriteInt16( m_vDimensions.size() );
- for( sal_Int32 i = 1; i <= static_cast<sal_Int32>(m_vDimensions.size()); i++ )
+ for( std::size_t i = 1; i <= m_vDimensions.size(); i++ )
{
sal_Int32 lb32, ub32;
GetDim(i, lb32, ub32);
diff --git a/basic/source/sbx/sbxbase.cxx b/basic/source/sbx/sbxbase.cxx
index 3b70307ec3e7..1d34683aea19 100644
--- a/basic/source/sbx/sbxbase.cxx
+++ b/basic/source/sbx/sbxbase.cxx
@@ -31,12 +31,14 @@
#include <rtl/ustring.hxx>
#include <sal/log.hxx>
+#include <filefmt.hxx>
// AppData-Structure for SBX:
SbxAppData::SbxAppData()
: eErrCode(ERRCODE_NONE)
+ , aErrorMsg(OUString())
, eBasicFormaterLangType(LANGUAGE_DONTKNOW)
{
}
@@ -55,11 +57,7 @@ SbxBase::SbxBase()
nFlags = SbxFlagBits::ReadWrite;
}
-SbxBase::SbxBase( const SbxBase& r )
- : SvRefBase( r )
-{
- nFlags = r.nFlags;
-}
+SbxBase::SbxBase(const SbxBase& r) = default;
SbxBase::~SbxBase()
{
@@ -96,6 +94,21 @@ ErrCode const & SbxBase::GetError()
return GetSbxData_Impl().eErrCode;
}
+OUString const & SbxBase::GetErrorMsg()
+{
+ return GetSbxData_Impl().aErrorMsg;
+}
+
+void SbxBase::SetError(ErrCode e, const OUString& rMsg)
+{
+ SbxAppData& r = GetSbxData_Impl();
+ if (e && r.eErrCode == ERRCODE_NONE)
+ {
+ r.eErrCode = e;
+ r.aErrorMsg = rMsg;
+ }
+}
+
void SbxBase::SetError( ErrCode e )
{
SbxAppData& r = GetSbxData_Impl();
@@ -111,6 +124,7 @@ bool SbxBase::IsError()
void SbxBase::ResetError()
{
GetSbxData_Impl().eErrCode = ERRCODE_NONE;
+ GetSbxData_Impl().aErrorMsg = OUString();
}
void SbxBase::AddFactory( SbxFactory* pFac )
@@ -144,12 +158,12 @@ SbxBaseRef SbxBase::Create( sal_uInt16 nSbxId, sal_uInt32 nCreator )
case SBXID_VARIABLE: return new SbxVariable;
case SBXID_ARRAY: return new SbxArray;
case SBXID_DIMARRAY: return new SbxDimArray;
- case SBXID_OBJECT: return new SbxObject( "" );
+ case SBXID_OBJECT: return new SbxObject( u""_ustr );
case SBXID_COLLECTION: return new SbxCollection;
case SBXID_FIXCOLLECTION:
return new SbxStdCollection;
- case SBXID_METHOD: return new SbxMethod( "", SbxEMPTY );
- case SBXID_PROPERTY: return new SbxProperty( "", SbxEMPTY );
+ case SBXID_METHOD: return new SbxMethod( u""_ustr, SbxEMPTY );
+ case SBXID_PROPERTY: return new SbxProperty( u""_ustr, SbxEMPTY );
}
// Unknown type: go over the factories!
SbxAppData& r = GetSbxData_Impl();
@@ -231,7 +245,7 @@ SbxBaseRef SbxBase::Load( SvStream& rStrm )
return p;
}
-bool SbxBase::Store( SvStream& rStrm )
+std::pair<bool, sal_uInt32> SbxBase::Store( SvStream& rStrm )
{
if( ( nFlags & SbxFlagBits::DontStore ) == SbxFlagBits::NONE )
{
@@ -241,7 +255,7 @@ bool SbxBase::Store( SvStream& rStrm )
.WriteUInt16( GetVersion() );
sal_uInt64 const nOldPos = rStrm.Tell();
rStrm.WriteUInt32( 0 );
- bool bRes = StoreData( rStrm );
+ auto [bRes, nVersion] = StoreData(rStrm);
sal_uInt64 const nNewPos = rStrm.Tell();
rStrm.Seek( nOldPos );
rStrm.WriteUInt32( nNewPos - nOldPos );
@@ -250,10 +264,10 @@ bool SbxBase::Store( SvStream& rStrm )
bRes = false;
if( bRes )
bRes = true;
- return bRes;
+ return { bRes, nVersion };
}
else
- return true;
+ return { true, B_IMG_VERSION_12 };
}
bool SbxBase::LoadCompleted()
diff --git a/basic/source/sbx/sbxbool.cxx b/basic/source/sbx/sbxbool.cxx
index 723939fb0c4a..6cdcb9ed464a 100644
--- a/basic/source/sbx/sbxbool.cxx
+++ b/basic/source/sbx/sbxbool.cxx
@@ -17,123 +17,107 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
-#include <vcl/errcode.hxx>
+#include <comphelper/errcode.hxx>
#include <basic/sberrors.hxx>
#include "sbxconv.hxx"
#include "sbxres.hxx"
enum SbxBOOL ImpGetBool( const SbxValues* p )
{
- enum SbxBOOL nRes;
+ auto SbxBoolFrom = [](auto val) { return val != 0 ? SbxTRUE : SbxFALSE; };
switch( +p->eType )
{
- case SbxNULL:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- [[fallthrough]];
case SbxEMPTY:
- nRes = SbxFALSE; break;
+ return SbxFALSE;
case SbxCHAR:
- nRes = p->nChar ? SbxTRUE : SbxFALSE; break;
+ return SbxBoolFrom(p->nChar);
+ case SbxBYREF | SbxCHAR:
+ return SbxBoolFrom(*p->pChar);
case SbxBYTE:
- nRes = p->nByte ? SbxTRUE : SbxFALSE; break;
+ return SbxBoolFrom(p->nByte);
+ case SbxBYREF | SbxBYTE:
+ return SbxBoolFrom(*p->pByte);
case SbxINTEGER:
case SbxBOOL:
- nRes = p->nInteger ? SbxTRUE : SbxFALSE; break;
+ return SbxBoolFrom(p->nInteger);
+ case SbxBYREF | SbxINTEGER:
+ case SbxBYREF | SbxBOOL:
+ return SbxBoolFrom(*p->pInteger);
case SbxERROR:
case SbxUSHORT:
- nRes = p->nUShort ? SbxTRUE : SbxFALSE; break;
+ return SbxBoolFrom(p->nUShort);
+ case SbxBYREF | SbxERROR:
+ case SbxBYREF | SbxUSHORT:
+ return SbxBoolFrom(*p->pUShort);
case SbxLONG:
- nRes = p->nLong ? SbxTRUE : SbxFALSE; break;
+ return SbxBoolFrom(p->nLong);
+ case SbxBYREF | SbxLONG:
+ return SbxBoolFrom(*p->pLong);
case SbxULONG:
- nRes = p->nULong ? SbxTRUE : SbxFALSE; break;
+ return SbxBoolFrom(p->nULong);
+ case SbxBYREF | SbxULONG:
+ return SbxBoolFrom(*p->pULong);
case SbxSINGLE:
- nRes = p->nSingle ? SbxTRUE : SbxFALSE; break;
+ return SbxBoolFrom(p->nSingle);
+ case SbxBYREF | SbxSINGLE:
+ return SbxBoolFrom(*p->pSingle);
case SbxDATE:
case SbxDOUBLE:
- nRes = p->nDouble ? SbxTRUE : SbxFALSE; break;
+ return SbxBoolFrom(p->nDouble);
+ case SbxBYREF | SbxDATE:
+ case SbxBYREF | SbxDOUBLE:
+ return SbxBoolFrom(*p->pDouble);
case SbxDECIMAL:
case SbxBYREF | SbxDECIMAL:
- {
- double dVal = 0.0;
if( p->pDecimal )
- p->pDecimal->getDouble( dVal );
- nRes = dVal ? SbxTRUE : SbxFALSE;
- }
- break;
+ return SbxBoolFrom(p->pDecimal->getWithOverflow<double>());
+ return SbxFALSE;
case SbxSALINT64:
case SbxCURRENCY:
- nRes = p->nInt64 ? SbxTRUE : SbxFALSE; break;
+ return SbxBoolFrom(p->nInt64);
+ case SbxBYREF | SbxSALINT64:
+ case SbxBYREF | SbxCURRENCY:
+ return SbxBoolFrom(*p->pnInt64);
case SbxSALUINT64:
- nRes = p->uInt64 ? SbxTRUE : SbxFALSE; break;
+ return SbxBoolFrom(p->uInt64);
+ case SbxBYREF | SbxSALUINT64:
+ return SbxBoolFrom(*p->puInt64);
+
case SbxBYREF | SbxSTRING:
case SbxSTRING:
case SbxLPSTR:
- nRes = SbxFALSE;
if ( p->pOUString )
{
if( p->pOUString->equalsIgnoreAsciiCase( GetSbxRes( StringId::True ) ) )
- nRes = SbxTRUE;
- else if( !p->pOUString->equalsIgnoreAsciiCase( GetSbxRes( StringId::False ) ) )
+ return SbxTRUE;
+ if( p->pOUString->equalsIgnoreAsciiCase( GetSbxRes( StringId::False ) ) )
+ return SbxFALSE;
+
+ // it can be convertible to a number
+ double n;
+ SbxDataType t;
+ sal_Int32 nLen = 0;
+ if( ImpScan( *p->pOUString, n, t, &nLen ) == ERRCODE_NONE )
{
- // it can be convertible to a number
- bool bError = true;
- double n;
- SbxDataType t;
- sal_uInt16 nLen = 0;
- if( ImpScan( *p->pOUString, n, t, &nLen, true ) == ERRCODE_NONE )
+ if( nLen == p->pOUString->getLength() )
{
- if( nLen == p->pOUString->getLength() )
- {
- bError = false;
- if( n != 0.0 )
- nRes = SbxTRUE;
- }
+ return SbxBoolFrom(n);
}
- if( bError )
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
}
+ SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
}
- break;
+ return SbxFALSE;
+
case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
- nRes = pVal->GetBool() ? SbxTRUE : SbxFALSE;
- else
- {
- SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT ); nRes = SbxFALSE;
- }
- break;
- }
+ if (SbxValue* pVal = dynamic_cast<SbxValue*>(p->pObj))
+ return SbxBoolFrom(pVal->GetBool());
+ SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT );
+ return SbxFALSE;
- case SbxBYREF | SbxCHAR:
- nRes = *p->pChar ? SbxTRUE : SbxFALSE; break;
- case SbxBYREF | SbxBYTE:
- nRes = *p->pByte ? SbxTRUE : SbxFALSE; break;
- case SbxBYREF | SbxINTEGER:
- case SbxBYREF | SbxBOOL:
- nRes = *p->pInteger ? SbxTRUE : SbxFALSE; break;
- case SbxBYREF | SbxLONG:
- nRes = *p->pLong ? SbxTRUE : SbxFALSE; break;
- case SbxBYREF | SbxULONG:
- nRes = *p->pULong ? SbxTRUE : SbxFALSE; break;
- case SbxBYREF | SbxERROR:
- case SbxBYREF | SbxUSHORT:
- nRes = *p->pUShort ? SbxTRUE : SbxFALSE; break;
- case SbxBYREF | SbxSINGLE:
- nRes = ( *p->pSingle != 0 ) ? SbxTRUE : SbxFALSE; break;
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- nRes = ( *p->pDouble != 0 ) ? SbxTRUE : SbxFALSE; break;
- case SbxBYREF | SbxCURRENCY:
- case SbxBYREF | SbxSALINT64:
- nRes = ( *p->pnInt64 ) ? SbxTRUE : SbxFALSE; break;
- case SbxBYREF | SbxSALUINT64:
- nRes = ( *p->puInt64 ) ? SbxTRUE : SbxFALSE; break;
default:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION ); nRes = SbxFALSE;
+ SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
+ return SbxFALSE;
}
- return nRes;
}
void ImpPutBool( SbxValues* p, sal_Int16 n )
@@ -144,28 +128,53 @@ void ImpPutBool( SbxValues* p, sal_Int16 n )
{
case SbxCHAR:
p->nChar = static_cast<sal_Unicode>(n); break;
- case SbxUINT:
+ case SbxBYREF | SbxCHAR:
+ *p->pChar = static_cast<sal_Unicode>(n); break;
+ case SbxBYTE:
p->nByte = static_cast<sal_uInt8>(n); break;
+ case SbxBYREF | SbxBYTE:
+ *p->pByte = static_cast<sal_uInt8>(n); break;
case SbxINTEGER:
case SbxBOOL:
p->nInteger = n; break;
+ case SbxBYREF | SbxINTEGER:
+ case SbxBYREF | SbxBOOL:
+ *p->pInteger = n; break;
+ case SbxERROR:
+ case SbxUSHORT:
+ p->nUShort = static_cast<sal_uInt16>(n); break;
+ case SbxBYREF | SbxERROR:
+ case SbxBYREF | SbxUSHORT:
+ *p->pUShort = static_cast<sal_uInt16>(n); break;
case SbxLONG:
p->nLong = n; break;
+ case SbxBYREF | SbxLONG:
+ *p->pLong = n; break;
case SbxULONG:
p->nULong = static_cast<sal_uInt32>(n); break;
- case SbxERROR:
- case SbxUSHORT:
- p->nUShort = static_cast<sal_uInt16>(n); break;
+ case SbxBYREF | SbxULONG:
+ *p->pULong = static_cast<sal_uInt32>(n); break;
case SbxSINGLE:
p->nSingle = n; break;
+ case SbxBYREF | SbxSINGLE:
+ *p->pSingle = n; break;
case SbxDATE:
case SbxDOUBLE:
p->nDouble = n; break;
+ case SbxBYREF | SbxDATE:
+ case SbxBYREF | SbxDOUBLE:
+ *p->pDouble = n; break;
case SbxCURRENCY:
case SbxSALINT64:
- p->nInt64 = static_cast<sal_Int64>(n); break;
+ p->nInt64 = n; break;
+ case SbxBYREF | SbxCURRENCY:
+ case SbxBYREF | SbxSALINT64:
+ *p->pnInt64 = n; break;
case SbxSALUINT64:
p->uInt64 = static_cast<sal_uInt64>(n); break;
+ case SbxBYREF | SbxSALUINT64:
+ *p->puInt64 = static_cast<sal_uInt64>(n); break;
+
case SbxDECIMAL:
case SbxBYREF | SbxDECIMAL:
ImpCreateDecimal( p )->setInt( n );
@@ -181,38 +190,12 @@ void ImpPutBool( SbxValues* p, sal_Int16 n )
break;
case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
+ if (SbxValue* pVal = dynamic_cast<SbxValue*>(p->pObj))
pVal->PutBool( n != 0 );
else
SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT );
break;
- }
- case SbxBYREF | SbxCHAR:
- *p->pChar = static_cast<sal_Unicode>(n); break;
- case SbxBYREF | SbxBYTE:
- *p->pByte = static_cast<sal_uInt8>(n); break;
- case SbxBYREF | SbxINTEGER:
- case SbxBYREF | SbxBOOL:
- *p->pInteger = n; break;
- case SbxBYREF | SbxERROR:
- case SbxBYREF | SbxUSHORT:
- *p->pUShort = static_cast<sal_uInt16>(n); break;
- case SbxBYREF | SbxLONG:
- *p->pLong = n; break;
- case SbxBYREF | SbxULONG:
- *p->pULong = static_cast<sal_uInt32>(n); break;
- case SbxBYREF | SbxSINGLE:
- *p->pSingle = n; break;
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- *p->pDouble = n; break;
- case SbxBYREF | SbxCURRENCY:
- case SbxBYREF | SbxSALINT64:
- *p->pnInt64 = static_cast<sal_Int64>(n); break;
- case SbxBYREF | SbxSALUINT64:
- *p->puInt64 = static_cast<sal_uInt64>(n); break;
+
default:
SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
}
diff --git a/basic/source/sbx/sbxbyte.cxx b/basic/source/sbx/sbxbyte.cxx
deleted file mode 100644
index 4974213dc7a1..000000000000
--- a/basic/source/sbx/sbxbyte.cxx
+++ /dev/null
@@ -1,312 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include <sal/config.h>
-
-#include <o3tl/safeint.hxx>
-#include <vcl/errcode.hxx>
-//#include <basic/sbx.hxx>
-#include <basic/sberrors.hxx>
-#include "sbxconv.hxx"
-
-#include <rtl/math.hxx>
-
-sal_uInt8 ImpGetByte( const SbxValues* p )
-{
- SbxValues aTmp;
- sal_uInt8 nRes;
-start:
- switch( +p->eType )
- {
- case SbxNULL:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- [[fallthrough]];
- case SbxEMPTY:
- nRes = 0; break;
- case SbxCHAR:
- if( p->nChar > SbxMAXBYTE )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = 0;
- }
- else
- nRes = static_cast<sal_uInt8>(p->nChar);
- break;
- case SbxBYTE:
- nRes = p->nByte; break;
- case SbxINTEGER:
- case SbxBOOL:
- if( p->nInteger > SbxMAXBYTE )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXBYTE;
- }
- else if( p->nInteger < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = 0;
- }
- else
- nRes = static_cast<sal_uInt8>(p->nInteger);
- break;
- case SbxERROR:
- case SbxUSHORT:
- if( p->nUShort > o3tl::make_unsigned(SbxMAXBYTE) )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXBYTE;
- }
- else
- nRes = static_cast<sal_uInt8>(p->nUShort);
- break;
- case SbxLONG:
- if( p->nLong > SbxMAXBYTE )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXBYTE;
- }
- else if( p->nLong < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = 0;
- }
- else
- nRes = static_cast<sal_uInt8>(p->nLong);
- break;
- case SbxULONG:
- if( p->nULong > SbxMAXBYTE )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXBYTE;
- }
- else
- nRes = static_cast<sal_uInt8>(p->nULong);
- break;
- case SbxCURRENCY:
- case SbxSALINT64:
- {
- sal_Int64 val = p->nInt64;
- if ( p->eType == SbxCURRENCY )
- val = val / CURRENCY_FACTOR;
- if( val > SbxMAXBYTE )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXBYTE;
- }
- else if( p->nInt64 < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = 0;
- }
- else
- nRes = static_cast<sal_uInt8>(val);
- break;
- }
- case SbxSALUINT64:
- if( p->uInt64 > SbxMAXBYTE )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXBYTE;
- }
- else
- nRes = static_cast<sal_uInt8>(p->uInt64);
- break;
- case SbxSINGLE:
- if( p->nSingle > SbxMAXBYTE )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXBYTE;
- }
- else if( p->nSingle < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = 0;
- }
- else
- nRes = static_cast<sal_uInt8>(rtl::math::round( p->nSingle ));
- break;
- case SbxDATE:
- case SbxDOUBLE:
- case SbxDECIMAL:
- case SbxBYREF | SbxDECIMAL:
- {
- double dVal;
- if( p->eType == SbxDECIMAL )
- {
- dVal = 0.0;
- if( p->pDecimal )
- p->pDecimal->getDouble( dVal );
- }
- else
- dVal = p->nDouble;
-
- if( dVal > SbxMAXBYTE )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXBYTE;
- }
- else if( dVal < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = 0;
- }
- else
- nRes = static_cast<sal_uInt8>(rtl::math::round( dVal ));
- break;
- }
- case SbxBYREF | SbxSTRING:
- case SbxSTRING:
- case SbxLPSTR:
- if( !p->pOUString )
- nRes = 0;
- else
- {
- double d;
- SbxDataType t;
- if( ImpScan( *p->pOUString, d, t, nullptr, true ) != ERRCODE_NONE )
- nRes = 0;
- else if( d > SbxMAXBYTE )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXBYTE;
- }
- else if( d < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = 0;
- }
- else
- nRes = static_cast<sal_uInt8>( d + 0.5 );
- }
- break;
- case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
- nRes = pVal->GetByte();
- else
- {
- SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT ); nRes = 0;
- }
- break;
- }
-
- case SbxBYREF | SbxBYTE:
- nRes = p->nByte; break;
-
- // from here on will be tested
- case SbxBYREF | SbxCHAR:
- aTmp.nChar = *p->pChar; goto ref;
- case SbxBYREF | SbxINTEGER:
- case SbxBYREF | SbxBOOL:
- aTmp.nInteger = *p->pInteger; goto ref;
- case SbxBYREF | SbxLONG:
- aTmp.nLong = *p->pLong; goto ref;
- case SbxBYREF | SbxULONG:
- aTmp.nULong = *p->pULong; goto ref;
- case SbxBYREF | SbxERROR:
- case SbxBYREF | SbxUSHORT:
- aTmp.nUShort = *p->pUShort; goto ref;
- case SbxBYREF | SbxSINGLE:
- aTmp.nSingle = *p->pSingle; goto ref;
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- aTmp.nDouble = *p->pDouble; goto ref;
- case SbxBYREF | SbxCURRENCY:
- case SbxBYREF | SbxSALINT64:
- aTmp.nInt64 = *p->pnInt64; goto ref;
- case SbxBYREF | SbxSALUINT64:
- aTmp.uInt64 = *p->puInt64; goto ref;
- ref:
- aTmp.eType = SbxDataType( p->eType & 0x0FFF );
- p = &aTmp; goto start;
-
- default:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION ); nRes = 0;
- }
- return nRes;
-}
-
-void ImpPutByte( SbxValues* p, sal_uInt8 n )
-{
- switch( +p->eType )
- {
- case SbxBYTE:
- p->nByte = n; break;
- case SbxINTEGER:
- case SbxBOOL:
- p->nInteger = n; break;
- case SbxERROR:
- case SbxUSHORT:
- p->nUShort = n; break;
- case SbxLONG:
- p->nLong = n; break;
- case SbxULONG:
- p->nULong = n; break;
- case SbxSINGLE:
- p->nSingle = n; break;
- case SbxDATE:
- case SbxDOUBLE:
- p->nDouble = n; break;
- case SbxCURRENCY:
- p->nInt64 = n * CURRENCY_FACTOR; break;
- case SbxSALINT64:
- p->nInt64 = n; break;
- case SbxSALUINT64:
- p->uInt64 = n; break;
- case SbxDECIMAL:
- case SbxBYREF | SbxDECIMAL:
- ImpCreateDecimal( p )->setByte( n );
- break;
-
- case SbxCHAR:
- p->nChar = static_cast<sal_Unicode>(n); break;
-
- case SbxBYREF | SbxSTRING:
- case SbxSTRING:
- case SbxLPSTR:
- if( !p->pOUString )
- p->pOUString = new OUString;
- ImpCvtNum( static_cast<double>(n), 0, *p->pOUString );
- break;
- case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
- pVal->PutByte( n );
- else
- SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT );
- break;
- }
- case SbxBYREF | SbxCHAR:
- *p->pChar = static_cast<sal_Unicode>(n); break;
- case SbxBYREF | SbxBYTE:
- *p->pByte = n; break;
- case SbxBYREF | SbxINTEGER:
- case SbxBYREF | SbxBOOL:
- *p->pInteger = n; break;
- case SbxBYREF | SbxERROR:
- case SbxBYREF | SbxUSHORT:
- *p->pUShort = n; break;
- case SbxBYREF | SbxLONG:
- *p->pLong = n; break;
- case SbxBYREF | SbxULONG:
- *p->pULong = n; break;
- case SbxBYREF | SbxSINGLE:
- *p->pSingle = n; break;
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- *p->pDouble = n; break;
- case SbxBYREF | SbxCURRENCY:
- p->nInt64 = n * CURRENCY_FACTOR; break;
- case SbxBYREF | SbxSALINT64:
- *p->pnInt64 = n; break;
- case SbxBYREF | SbxSALUINT64:
- *p->puInt64 = n; break;
-
- default:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- }
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/sbx/sbxchar.cxx b/basic/source/sbx/sbxchar.cxx
deleted file mode 100644
index d25ccc083d7c..000000000000
--- a/basic/source/sbx/sbxchar.cxx
+++ /dev/null
@@ -1,300 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include <vcl/errcode.hxx>
-#include <basic/sberrors.hxx>
-#include "sbxconv.hxx"
-
-#include <rtl/math.hxx>
-
-sal_Unicode ImpGetChar( const SbxValues* p )
-{
- SbxValues aTmp;
- sal_Unicode nRes = 0;
-start:
- switch( +p->eType )
- {
- case SbxNULL:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- [[fallthrough]];
- case SbxEMPTY:
- nRes = 0; break;
- case SbxCHAR:
- nRes = p->nChar; break;
- case SbxBYTE:
- nRes = static_cast<sal_Unicode>(p->nByte);
- break;
- case SbxINTEGER:
- case SbxBOOL:
- if( p->nInteger < SbxMINCHAR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMINCHAR;
- }
- else
- nRes = static_cast<sal_Unicode>(p->nInteger);
- break;
- case SbxERROR:
- case SbxUSHORT:
- nRes = static_cast<sal_Unicode>(p->nUShort);
- break;
- case SbxLONG:
- if( p->nLong > SbxMAXCHAR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXCHAR;
- }
- else if( p->nLong < SbxMINCHAR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMINCHAR;
- }
- else
- nRes = static_cast<sal_Unicode>(p->nLong);
- break;
- case SbxULONG:
- if( p->nULong > SbxMAXCHAR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXCHAR;
- }
- else
- nRes = static_cast<sal_Unicode>(p->nULong);
- break;
- case SbxCURRENCY:
- case SbxSALINT64:
- {
- sal_Int64 val = p->nInt64;
-
- if ( p->eType == SbxCURRENCY )
- val = val / CURRENCY_FACTOR;
-
- if( val > SbxMAXCHAR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXCHAR;
- }
- else if( p->nInt64 < SbxMINCHAR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMINCHAR;
- }
- else
- nRes = static_cast<sal_Unicode>(val);
- break;
- }
- case SbxSALUINT64:
- if( p->uInt64 > SbxMAXCHAR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXCHAR;
- }
- else
- nRes = static_cast<sal_Unicode>(p->uInt64);
- break;
- case SbxSINGLE:
- if( p->nSingle > SbxMAXCHAR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXCHAR;
- }
- else if( p->nSingle < SbxMINCHAR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMINCHAR;
- }
- else
- nRes = static_cast<sal_Unicode>(rtl::math::round( p->nSingle ));
- break;
- case SbxDATE:
- case SbxDOUBLE:
- case SbxDECIMAL:
- case SbxBYREF | SbxDECIMAL:
- {
- double dVal;
- if( p->eType == SbxDECIMAL )
- {
- dVal = 0.0;
- if( p->pDecimal )
- p->pDecimal->getDouble( dVal );
- }
- else
- dVal = p->nDouble;
-
- if( dVal > SbxMAXCHAR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXCHAR;
- }
- else if( dVal < SbxMINCHAR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMINCHAR;
- }
- else
- nRes = static_cast<sal_uInt8>(rtl::math::round( dVal ));
- break;
- }
- case SbxBYREF | SbxSTRING:
- case SbxSTRING:
- case SbxLPSTR:
- if ( p->pOUString )
- {
- double d;
- SbxDataType t;
- if( ImpScan( *p->pOUString, d, t, nullptr, true ) != ERRCODE_NONE )
- nRes = 0;
- else if( d > SbxMAXCHAR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXCHAR;
- }
- else if( d < SbxMINCHAR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMINCHAR;
- }
- else
- nRes = static_cast<sal_Unicode>(rtl::math::round( d ));
- }
- break;
- case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
- nRes = pVal->GetChar();
- else
- {
- SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT ); nRes = 0;
- }
- break;
- }
-
- case SbxBYREF | SbxCHAR:
- nRes = *p->pChar; break;
- // from here on will be tested
- case SbxBYREF | SbxBYTE:
- aTmp.nByte = *p->pByte; goto ref;
- case SbxBYREF | SbxINTEGER:
- case SbxBYREF | SbxBOOL:
- aTmp.nInteger = *p->pInteger; goto ref;
- case SbxBYREF | SbxLONG:
- aTmp.nLong = *p->pLong; goto ref;
- case SbxBYREF | SbxULONG:
- aTmp.nULong = *p->pULong; goto ref;
- case SbxBYREF | SbxERROR:
- case SbxBYREF | SbxUSHORT:
- aTmp.nUShort = *p->pUShort; goto ref;
- case SbxBYREF | SbxSINGLE:
- aTmp.nSingle = *p->pSingle; goto ref;
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- aTmp.nDouble = *p->pDouble; goto ref;
- case SbxBYREF | SbxCURRENCY:
- case SbxBYREF | SbxSALINT64:
- aTmp.nInt64 = *p->pnInt64; goto ref;
- case SbxBYREF | SbxSALUINT64:
- aTmp.uInt64 = *p->puInt64; goto ref;
- ref:
- aTmp.eType = SbxDataType( p->eType & 0x0FFF );
- p = &aTmp; goto start;
-
- default:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION ); nRes = 0;
- }
- return nRes;
-}
-
-void ImpPutChar( SbxValues* p, sal_Unicode n )
-{
- SbxValues aTmp;
-start:
- switch( +p->eType )
- {
- case SbxCHAR:
- p->nChar = n; break;
- case SbxINTEGER:
- case SbxBOOL:
- p->nInteger = n; break;
- case SbxLONG:
- p->nLong = n; break;
- case SbxSINGLE:
- p->nSingle = n; break;
- case SbxDATE:
- case SbxDOUBLE:
- p->nDouble = n; break;
- case SbxCURRENCY:
- p->nInt64 = n * CURRENCY_FACTOR; break;
- case SbxSALINT64:
- p->nInt64 = n; break;
- case SbxSALUINT64:
- p->uInt64 = n; break;
- case SbxBYREF | SbxDECIMAL:
- ImpCreateDecimal( p )->setChar( n );
- break;
-
- // from here on will be tested
- case SbxBYTE:
- aTmp.pByte = &p->nByte; goto direct;
- case SbxULONG:
- aTmp.pULong = &p->nULong; goto direct;
- case SbxERROR:
- case SbxUSHORT:
- aTmp.pUShort = &p->nUShort; goto direct;
- direct:
- aTmp.eType = SbxDataType( p->eType | SbxBYREF );
- p = &aTmp; goto start;
-
- case SbxBYREF | SbxSTRING:
- case SbxSTRING:
- case SbxLPSTR:
- if ( !p->pOUString )
- p->pOUString = new OUString( n );
- else
- *p->pOUString = OUString( n );
- break;
- case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
- pVal->PutChar( n );
- else
- SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT );
- break;
- }
- case SbxBYREF | SbxCHAR:
- *p->pChar = n; break;
- case SbxBYREF | SbxBYTE:
- *p->pByte = static_cast<sal_uInt8>(n); break;
- case SbxBYREF | SbxINTEGER:
- case SbxBYREF | SbxBOOL:
- *p->pInteger = n; break;
- case SbxBYREF | SbxERROR:
- case SbxBYREF | SbxUSHORT:
- *p->pUShort = static_cast<sal_uInt16>(n); break;
- case SbxBYREF | SbxLONG:
- *p->pLong = static_cast<sal_Int32>(n); break;
- case SbxBYREF | SbxULONG:
- *p->pULong = static_cast<sal_uInt32>(n); break;
- case SbxBYREF | SbxSINGLE:
- *p->pSingle = static_cast<float>(n); break;
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- *p->pDouble = static_cast<double>(n); break;
- case SbxBYREF | SbxCURRENCY:
- p->nInt64 = n * CURRENCY_FACTOR; break;
- case SbxBYREF | SbxSALINT64:
- *p->pnInt64 = n; break;
- case SbxBYREF | SbxSALUINT64:
- *p->puInt64 = n; break;
-
- default:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- }
-}
-
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/sbx/sbxcoll.cxx b/basic/source/sbx/sbxcoll.cxx
index ea4eb4cdea14..8b74d79bc194 100644
--- a/basic/source/sbx/sbxcoll.cxx
+++ b/basic/source/sbx/sbxcoll.cxx
@@ -17,6 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <o3tl/safeint.hxx>
#include <tools/stream.hxx>
#include <basic/sbx.hxx>
@@ -32,7 +33,7 @@ static sal_uInt16 nCountHash = 0, nAddHash, nItemHash, nRemoveHash;
SbxCollection::SbxCollection()
- : SbxObject( "" )
+ : SbxObject( u""_ustr )
{
if( !nCountHash )
{
@@ -102,47 +103,42 @@ SbxVariable* SbxCollection::Find( const OUString& rName, SbxClassType t )
void SbxCollection::Notify( SfxBroadcaster& rCst, const SfxHint& rHint )
{
- const SbxHint* p = dynamic_cast<const SbxHint*>(&rHint);
- if( p )
+ const SfxHintId nId = rHint.GetId();
+ if( nId == SfxHintId::BasicDataWanted || nId == SfxHintId::BasicDataChanged )
{
- const SfxHintId nId = p->GetId();
- bool bRead = ( nId == SfxHintId::BasicDataWanted );
- bool bWrite = ( nId == SfxHintId::BasicDataChanged );
+ const SbxHint* p = static_cast<const SbxHint*>(&rHint);
SbxVariable* pVar = p->GetVar();
SbxArray* pArg = pVar->GetParameters();
- if( bRead || bWrite )
+ OUString aVarName( pVar->GetName() );
+ if( pVar == this )
{
- OUString aVarName( pVar->GetName() );
- if( pVar == this )
- {
- CollItem( pArg );
- }
- else if( pVar->GetHashCode() == nCountHash
- && aVarName.equalsIgnoreAsciiCase( pCount ) )
- {
- pVar->PutLong(sal::static_int_cast<sal_Int32>(pObjs->Count()));
- }
- else if( pVar->GetHashCode() == nAddHash
- && aVarName.equalsIgnoreAsciiCase( pAdd ) )
- {
- CollAdd( pArg );
- }
- else if( pVar->GetHashCode() == nItemHash
- && aVarName.equalsIgnoreAsciiCase( pItem ) )
- {
- CollItem( pArg );
- }
- else if( pVar->GetHashCode() == nRemoveHash
- && aVarName.equalsIgnoreAsciiCase( pRemove ) )
- {
- CollRemove( pArg );
- }
- else
- {
- SbxObject::Notify( rCst, rHint );
- }
- return;
+ CollItem( pArg );
}
+ else if( pVar->GetHashCode() == nCountHash
+ && aVarName.equalsIgnoreAsciiCase( pCount ) )
+ {
+ pVar->PutLong(sal::static_int_cast<sal_Int32>(pObjs->Count()));
+ }
+ else if( pVar->GetHashCode() == nAddHash
+ && aVarName.equalsIgnoreAsciiCase( pAdd ) )
+ {
+ CollAdd( pArg );
+ }
+ else if( pVar->GetHashCode() == nItemHash
+ && aVarName.equalsIgnoreAsciiCase( pItem ) )
+ {
+ CollItem( pArg );
+ }
+ else if( pVar->GetHashCode() == nRemoveHash
+ && aVarName.equalsIgnoreAsciiCase( pRemove ) )
+ {
+ CollRemove( pArg );
+ }
+ else
+ {
+ SbxObject::Notify( rCst, rHint );
+ }
+ return;
}
SbxObject::Notify( rCst, rHint );
}
@@ -188,7 +184,7 @@ void SbxCollection::CollItem( SbxArray* pPar_ )
else
{
short n = p->GetInteger();
- if (n >= 1 && n <= static_cast<sal_Int32>(pObjs->Count()))
+ if (n >= 1 && o3tl::make_unsigned(n) <= pObjs->Count())
{
pRes = pObjs->Get(static_cast<sal_uInt32>(n) - 1);
}
@@ -210,7 +206,7 @@ void SbxCollection::CollRemove( SbxArray* pPar_ )
else
{
short n = pPar_->Get(1)->GetInteger();
- if (n < 1 || n > static_cast<sal_Int32>(pObjs->Count()))
+ if (n < 1 || o3tl::make_unsigned(n) > pObjs->Count())
SetError( ERRCODE_BASIC_BAD_INDEX );
else
Remove(pObjs->Get(static_cast<sal_uInt32>(n) - 1));
@@ -292,16 +288,16 @@ bool SbxStdCollection::LoadData( SvStream& rStrm, sal_uInt16 nVer )
return bRes;
}
-bool SbxStdCollection::StoreData( SvStream& rStrm ) const
+std::pair<bool, sal_uInt32> SbxStdCollection::StoreData( SvStream& rStrm ) const
{
- bool bRes = SbxCollection::StoreData( rStrm );
+ const auto [bRes, nVersion] = SbxCollection::StoreData(rStrm);
if( bRes )
{
write_uInt16_lenPrefixed_uInt8s_FromOUString(rStrm, aElemClass,
RTL_TEXTENCODING_ASCII_US);
rStrm.WriteBool( bAddRemoveOk );
}
- return bRes;
+ return { bRes, nVersion };
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/sbx/sbxconv.hxx b/basic/source/sbx/sbxconv.hxx
index a3837d9a3dbf..b04d534f42a2 100644
--- a/basic/source/sbx/sbxconv.hxx
+++ b/basic/source/sbx/sbxconv.hxx
@@ -26,93 +26,194 @@
#include <basic/sbxdef.hxx>
#include <o3tl/float_int_conversion.hxx>
+#include <o3tl/safeint.hxx>
#include <rtl/math.hxx>
#include <sal/types.h>
class SbxArray;
-template <typename I> inline I DoubleTo(double f, I min, I max)
+template <std::integral I> I ConvertWithOverflowTo(double f)
{
f = rtl::math::round(f);
- if (!o3tl::convertsToAtMost(f, max))
+ if (!o3tl::convertsToAtMost(f, std::numeric_limits<I>::max()))
{
SbxBase::SetError(ERRCODE_BASIC_MATH_OVERFLOW);
- return max;
+ return std::numeric_limits<I>::max();
}
- if (!o3tl::convertsToAtLeast(f, min))
+ if (!o3tl::convertsToAtLeast(f, std::numeric_limits<I>::min()))
{
SbxBase::SetError(ERRCODE_BASIC_MATH_OVERFLOW);
- return min;
+ return std::numeric_limits<I>::min();
}
return f;
}
-inline auto ImpDoubleToChar(double f) { return DoubleTo<sal_Unicode>(f, SbxMINCHAR, SbxMAXCHAR); }
-inline auto ImpDoubleToByte(double f) { return DoubleTo<sal_uInt8>(f, 0, SbxMAXBYTE); }
-inline auto ImpDoubleToUShort(double f) { return DoubleTo<sal_uInt16>(f, 0, SbxMAXUINT); }
-inline auto ImpDoubleToInteger(double f) { return DoubleTo<sal_Int16>(f, SbxMININT, SbxMAXINT); }
-inline auto ImpDoubleToULong(double f) { return DoubleTo<sal_uInt32>(f, 0, SbxMAXULNG); }
-inline auto ImpDoubleToLong(double f) { return DoubleTo<sal_Int32>(f, SbxMINLNG, SbxMAXLNG); }
-inline auto ImpDoubleToSalUInt64(double d) { return DoubleTo<sal_uInt64>(d, 0, SAL_MAX_UINT64); }
-inline auto ImpDoubleToSalInt64(double d)
+template <std::integral To, std::integral From> To ConvertWithOverflowTo(From n)
{
- return DoubleTo<sal_Int64>(d, SAL_MIN_INT64, SAL_MAX_INT64);
+ using ValidRange = o3tl::ValidRange<To>;
+ if (ValidRange::isAbove(n))
+ {
+ SbxBase::SetError(ERRCODE_BASIC_MATH_OVERFLOW);
+ return std::numeric_limits<To>::max();
+ }
+ if (ValidRange::isBelow(n))
+ {
+ SbxBase::SetError(ERRCODE_BASIC_MATH_OVERFLOW);
+ return std::numeric_limits<To>::min();
+ }
+ return n;
+}
+
+template <std::floating_point To, std::floating_point From> inline To ConvertWithOverflowTo(From n)
+{
+ if constexpr (std::numeric_limits<From>::max() > std::numeric_limits<To>::max())
+ {
+ if (n > std::numeric_limits<To>::max())
+ {
+ SbxBase::SetError(ERRCODE_BASIC_MATH_OVERFLOW);
+ return std::numeric_limits<To>::max();
+ }
+ }
+ if constexpr (std::numeric_limits<From>::lowest() < std::numeric_limits<To>::lowest())
+ {
+ if (n < std::numeric_limits<To>::lowest())
+ {
+ SbxBase::SetError(ERRCODE_BASIC_MATH_OVERFLOW);
+ return std::numeric_limits<To>::lowest();
+ }
+ }
+ // tests for underflow - storing value too small for precision of single
+ if constexpr (std::numeric_limits<From>::min() < std::numeric_limits<To>::min())
+ {
+ if (n > 0 && n < std::numeric_limits<To>::min())
+ {
+ SbxBase::SetError(ERRCODE_BASIC_MATH_OVERFLOW);
+ return std::numeric_limits<To>::min();
+ }
+ if (n < 0 && n > -std::numeric_limits<To>::min())
+ {
+ SbxBase::SetError(ERRCODE_BASIC_MATH_OVERFLOW);
+ return -std::numeric_limits<To>::min();
+ }
+ }
+ return n;
+}
+
+template <std::floating_point To, std::integral From> inline To ConvertWithOverflowTo(From n)
+{
+ // No integral types overflow floats
+ return static_cast<To>(n);
+}
+
+template <typename T1, typename T2> void assignWithOverflowTo(T1& dest, T2 src)
+{
+ dest = ConvertWithOverflowTo<T1>(src);
+}
+
+template <typename T> void assignWithOverflowTo(T& dest, SbxDecimal& dec)
+{
+ dest = dec.getWithOverflow<T>();
}
// SBXSCAN.CXX
extern void ImpCvtNum( double nNum, short nPrec, OUString& rRes, bool bCoreString=false );
extern ErrCode ImpScan
- ( const OUString& rSrc, double& nVal, SbxDataType& rType, sal_uInt16* pLen,
- bool bOnlyIntntl );
-
-// with advanced evaluation (International, "TRUE"/"FALSE")
-extern bool ImpConvStringExt( OUString& rSrc, SbxDataType eTargetType );
+ ( std::u16string_view rSrc, double& nVal, SbxDataType& rType, sal_Int32* pLen,
+ bool* pHasNumber, bool bOnlyIntntl );
+// A version that uses defaults / compatibility settings for bOnlyIntntl
+extern ErrCode ImpScan
+ ( std::u16string_view rSrc, double& nVal, SbxDataType& rType, sal_Int32* pLen );
void ImpGetIntntlSep( sal_Unicode& rcDecimalSep, sal_Unicode& rcThousandSep, sal_Unicode& rcDecimalSepAlt );
// SBXINT.CXX
+sal_Unicode ImpGetChar( const SbxValues* );
+void ImpPutChar( SbxValues*, sal_Unicode );
+sal_uInt8 ImpGetByte( const SbxValues* );
+void ImpPutByte( SbxValues*, sal_uInt8 );
sal_Int16 ImpGetInteger( const SbxValues* );
void ImpPutInteger( SbxValues*, sal_Int16 );
-
+sal_uInt16 ImpGetUShort( const SbxValues* );
+void ImpPutUShort( SbxValues*, sal_uInt16 );
+sal_Int32 ImpGetLong( const SbxValues* );
+void ImpPutLong( SbxValues*, sal_Int32 );
+sal_uInt32 ImpGetULong( const SbxValues* );
+void ImpPutULong( SbxValues*, sal_uInt32 );
sal_Int64 ImpGetInt64( const SbxValues* );
void ImpPutInt64( SbxValues*, sal_Int64 );
sal_uInt64 ImpGetUInt64( const SbxValues* );
void ImpPutUInt64( SbxValues*, sal_uInt64 );
-
-double ImpSalUInt64ToDouble( sal_uInt64 n );
-
-// SBXLNG.CXX
-
-sal_Int32 ImpGetLong( const SbxValues* );
-void ImpPutLong( SbxValues*, sal_Int32 );
-
-// SBXSNG.CXX
-
-float ImpGetSingle( const SbxValues* );
-void ImpPutSingle( SbxValues*, float );
-
-// SBXDBL.CXX
-
-double ImpGetDouble( const SbxValues* );
-void ImpPutDouble( SbxValues*, double, bool bCoreString=false );
+double ImpGetDouble( const SbxValues* );
+void ImpPutDouble( SbxValues*, double, bool bCoreString=false );
+float ImpGetSingle( const SbxValues* );
+void ImpPutSingle( SbxValues*, float );
// SBXCURR.CXX
sal_Int64 ImpGetCurrency( const SbxValues* );
void ImpPutCurrency( SbxValues*, const sal_Int64 );
-inline sal_Int64 ImpDoubleToCurrency( double d )
+inline sal_Int64 CurFrom(double d)
+{
+ double result = d > 0 ? (d * CURRENCY_FACTOR + 0.5) : (d * CURRENCY_FACTOR - 0.5);
+ if (result >= double(SAL_MAX_INT64)) // double(SAL_MAX_INT64) is greater than SAL_MAX_INT64
+ {
+ SbxBase::SetError(ERRCODE_BASIC_MATH_OVERFLOW);
+ return SAL_MAX_INT64;
+ }
+ if (result < double(SAL_MIN_INT64))
+ {
+ SbxBase::SetError(ERRCODE_BASIC_MATH_OVERFLOW);
+ return SAL_MIN_INT64;
+ }
+ return result;
+}
+
+template <std::integral I> sal_Int64 CurFrom(I n)
+{
+ using ValidRange = o3tl::ValidRange<sal_Int64, SAL_MIN_INT64 / CURRENCY_FACTOR, SAL_MAX_INT64 / CURRENCY_FACTOR>;
+ if (ValidRange::isAbove(n))
+ {
+ SbxBase::SetError(ERRCODE_BASIC_MATH_OVERFLOW);
+ return SAL_MAX_INT64;
+ }
+ if (ValidRange::isBelow(n))
+ {
+ SbxBase::SetError(ERRCODE_BASIC_MATH_OVERFLOW);
+ return SAL_MIN_INT64;
+ }
+ return n * CURRENCY_FACTOR;
+}
+
+template <std::integral I> I CurTo(sal_Int64 cur_val)
{
- if (d > 0)
- return static_cast<sal_Int64>( d * CURRENCY_FACTOR + 0.5);
- else
- return static_cast<sal_Int64>( d * CURRENCY_FACTOR - 0.5);
+ return ConvertWithOverflowTo<I>(CurTo<sal_Int64>(cur_val));
}
-inline double ImpCurrencyToDouble( const sal_Int64 r )
- { return static_cast<double>(r) / double(CURRENCY_FACTOR); }
+template <> inline sal_Int64 CurTo<sal_Int64>(sal_Int64 cur_val)
+{
+ sal_Int64 i = cur_val / CURRENCY_FACTOR;
+ // Rounding (half-to-even)
+ int f = cur_val % CURRENCY_FACTOR;
+ if (i % 2 == 1)
+ {
+ if (f < 0)
+ --f;
+ else
+ ++f;
+ }
+ if (f > CURRENCY_FACTOR / 2)
+ ++i;
+ else if (f < -CURRENCY_FACTOR / 2)
+ --i;
+ return i;
+}
+template <std::floating_point F> F CurTo(sal_Int64 r)
+{
+ return ConvertWithOverflowTo<F>(static_cast<double>(r) / CURRENCY_FACTOR);
+}
// SBXDEC.CXX
@@ -131,25 +232,6 @@ OUString ImpGetString( const SbxValues* );
OUString ImpGetCoreString( const SbxValues* );
void ImpPutString( SbxValues*, const OUString* );
-// SBXCHAR.CXX
-
-sal_Unicode ImpGetChar( const SbxValues* );
-void ImpPutChar( SbxValues*, sal_Unicode );
-
-// SBXBYTE.CXX
-sal_uInt8 ImpGetByte( const SbxValues* );
-void ImpPutByte( SbxValues*, sal_uInt8 );
-
-// SBXUINT.CXX
-
-sal_uInt16 ImpGetUShort( const SbxValues* );
-void ImpPutUShort( SbxValues*, sal_uInt16 );
-
-// SBXULNG.CXX
-
-sal_uInt32 ImpGetULong( const SbxValues* );
-void ImpPutULong( SbxValues*, sal_uInt32 );
-
// SBXBOOL.CXX
enum SbxBOOL ImpGetBool( const SbxValues* );
diff --git a/basic/source/sbx/sbxcurr.cxx b/basic/source/sbx/sbxcurr.cxx
index 416229afbc95..5b452686de24 100644
--- a/basic/source/sbx/sbxcurr.cxx
+++ b/basic/source/sbx/sbxcurr.cxx
@@ -21,355 +21,203 @@
#include <basic/sberrors.hxx>
#include <basic/sbxvar.hxx>
+#include <o3tl/string_view.hxx>
+#include <svl/numformat.hxx>
+#include <vcl/svapp.hxx>
+#include <vcl/settings.hxx>
+#include <sbintern.hxx>
+#include <runtime.hxx>
#include "sbxconv.hxx"
static OUString ImpCurrencyToString( sal_Int64 rVal )
{
- bool isNeg = ( rVal < 0 );
- sal_Int64 absVal = isNeg ? -rVal : rVal;
+ sal_Unicode cDecimalSep, cThousandSepDummy, cDecimalSepAltDummy;
+ ImpGetIntntlSep(cDecimalSep, cThousandSepDummy, cDecimalSepAltDummy);
- sal_Unicode const cDecimalSep = '.';
-
- OUString aAbsStr = OUString::number( absVal );
-
- sal_Int32 initialLen = aAbsStr.getLength();
-
- bool bLessThanOne = false;
- if ( initialLen <= 4 ) // if less the 1
- bLessThanOne = true;
-
- sal_Int32 nCapacity = 6; // minimum e.g. 0.0000
-
- if ( !bLessThanOne )
+ auto strNum = OUString::number(rVal);
+ std::u16string_view aAbsStr(strNum);
+ OUStringBuffer aBuf(22);
+ if (rVal < 0)
{
- nCapacity = initialLen + 1;
+ aBuf.append('-');
+ assert(aAbsStr[0] == '-');
+ aAbsStr = aAbsStr.substr(1); // skip the minus
}
-
- if ( isNeg )
- ++nCapacity;
-
- OUStringBuffer aBuf( nCapacity );
- aBuf.setLength( nCapacity );
-
-
- sal_Int32 nDigitCount = 0;
- sal_Int32 nInsertIndex = nCapacity - 1;
- sal_Int32 nEndIndex = isNeg ? 1 : 0;
-
- for ( sal_Int32 charCpyIndex = aAbsStr.getLength() - 1; nInsertIndex >= nEndIndex; ++nDigitCount )
- {
- if ( nDigitCount == 4 )
- aBuf[nInsertIndex--] = cDecimalSep;
- if ( nDigitCount < initialLen )
- aBuf[nInsertIndex--] = aAbsStr[ charCpyIndex-- ];
- else
- // Handle leading 0's to right of decimal point
- // Note: in VBA the stringification is a little more complex
- // but more natural as only the necessary digits
- // to the right of the decimal places are displayed
- // It would be great to conditionally be able to display like that too
-
- // Val OOo (Cur) VBA (Cur)
- // --- --------- ---------
- // 0 0.0000 0
- // 0.1 0.1000 0.1
-
- aBuf[nInsertIndex--] = '0';
- }
- if ( isNeg )
- aBuf[nInsertIndex] = '-';
-
- aAbsStr = aBuf.makeStringAndClear();
- return aAbsStr;
+ size_t hasFractDigits = std::min(aAbsStr.length(), size_t(4));
+ size_t hasWholeDigits = aAbsStr.length() - hasFractDigits;
+
+ if (hasWholeDigits > 0)
+ aBuf.append(aAbsStr.substr(0, hasWholeDigits));
+ else
+ aBuf.append('0');
+ aBuf.append(cDecimalSep);
+ // Handle leading 0's to right of decimal separator
+ // Note: in VBA the stringification is a little more complex
+ // but more natural as only the necessary digits
+ // to the right of the decimal places are displayed
+ // It would be great to conditionally be able to display like that too
+
+ // Val OOo (Cur) VBA (Cur)
+ // --- --------- ---------
+ // 0 0.0000 0
+ // 0.1 0.1000 0.1
+ for (size_t i = 4; i > hasFractDigits; --i)
+ aBuf.append('0');
+ aBuf.append(aAbsStr.substr(aAbsStr.length() - hasFractDigits, hasFractDigits));
+
+ return aBuf.makeStringAndClear();
}
-
-static sal_Int64 ImpStringToCurrency( const OUString &rStr )
+static sal_Int64 ImpStringToCurrency(const rtl::OUString& rStr)
{
-
- sal_Int32 nFractDigit = 4;
-
- sal_Unicode const cDeciPnt = '.';
- sal_Unicode const c1000Sep = ',';
-
- // lets use the existing string number conversions
- // there is a performance impact here ( multiple string copies )
- // but better I think than a home brewed string parser, if we need a parser
- // we should share some existing ( possibly from calc is there a currency
- // conversion there ? #TODO check )
-
- OUString sTmp( rStr.trim() );
- const sal_Unicode* p = sTmp.getStr();
-
- // normalise string number by removing thousand & decimal point separators
- OUStringBuffer sNormalisedNumString( sTmp.getLength() + nFractDigit );
-
- if ( *p == '-' || *p == '+' )
- sNormalisedNumString.append( *p++ );
-
- while ( *p >= '0' && *p <= '9' )
+ LanguageType eLangType = Application::GetSettings().GetLanguageTag().getLanguageType();
+ std::shared_ptr<SvNumberFormatter> pFormatter;
+ if (GetSbData()->pInst)
+ {
+ pFormatter = GetSbData()->pInst->GetNumberFormatter();
+ }
+ else
{
- sNormalisedNumString.append( *p++ );
- // #TODO in vba mode set runtime error when a space ( or other )
- // illegal character is found
- if( *p == c1000Sep )
- p++;
+ sal_uInt32 n; // Dummy
+ pFormatter = SbiInstance::PrepareNumberFormatter(/*date index*/ n, /*time index*/ n,
+ /*date time index*/ n);
}
- bool bRoundUp = false;
+ // Passing a locale index switches IsNumberFormat() to use that locale,
+ // in case the formatter wasn't default-created with it.
+ sal_uInt32 nIndex = pFormatter->GetStandardIndex(eLangType);
- if( *p == cDeciPnt )
+ double fResult = 0.0;
+ bool bSuccess = pFormatter->IsNumberFormat(rStr, nIndex, fResult);
+ if (bSuccess)
{
- p++;
- while( nFractDigit && *p >= '0' && *p <= '9' )
+ SvNumFormatType nType = pFormatter->GetType(nIndex);
+ if (!(nType & (SvNumFormatType::CURRENCY | SvNumFormatType::NUMBER)))
{
- sNormalisedNumString.append( *p++ );
- nFractDigit--;
+ bSuccess = false;
}
- // Consume trailing content
- if ( p != nullptr )
- {
- // Round up if necessary
- if( *p >= '5' && *p <= '9' )
- bRoundUp = true;
- while( *p >= '0' && *p <= '9' )
- p++;
- }
-
}
- // can we raise error here ? ( previous behaviour was more forgiving )
- // so... not sure that could break existing code, let's see if anyone
- // complains.
- if ( p != sTmp.getStr() + sTmp.getLength() )
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- while( nFractDigit )
+ if (!bSuccess)
{
- sNormalisedNumString.append( '0' );
- nFractDigit--;
+ SbxBase::SetError(ERRCODE_BASIC_CONVERSION);
}
- sal_Int64 result = sNormalisedNumString.makeStringAndClear().toInt64();
-
- if ( bRoundUp )
- ++result;
- return result;
+ return CurFrom(fResult);
}
-
sal_Int64 ImpGetCurrency( const SbxValues* p )
{
- SbxValues aTmp;
- sal_Int64 nRes;
-start:
switch( +p->eType )
{
case SbxERROR:
case SbxNULL:
SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- nRes = 0; break;
+ return 0;
case SbxEMPTY:
- nRes = 0; break;
+ return 0;
case SbxCURRENCY:
- nRes = p->nInt64; break;
+ return p->nInt64;
case SbxBYTE:
- nRes = sal_Int64(CURRENCY_FACTOR) * static_cast<sal_Int64>(p->nByte);
- break;
+ return CurFrom(p->nByte);
case SbxCHAR:
- nRes = sal_Int64(CURRENCY_FACTOR) * reinterpret_cast<sal_Int64>(p->pChar);
- break;
+ return CurFrom(p->nChar);
case SbxBOOL:
case SbxINTEGER:
- nRes = sal_Int64(CURRENCY_FACTOR) * static_cast<sal_Int64>(p->nInteger);
- break;
+ return CurFrom(p->nInteger);
case SbxUSHORT:
- nRes = sal_Int64(CURRENCY_FACTOR) * static_cast<sal_Int64>(p->nUShort);
- break;
+ return CurFrom(p->nUShort);
case SbxLONG:
- nRes = sal_Int64(CURRENCY_FACTOR) * static_cast<sal_Int64>(p->nLong);
- break;
+ return CurFrom(p->nLong);
case SbxULONG:
- nRes = sal_Int64(CURRENCY_FACTOR) * static_cast<sal_Int64>(p->nULong);
- break;
-
+ return CurFrom(p->nULong);
case SbxSALINT64:
- {
- nRes = p->nInt64 * CURRENCY_FACTOR; break;
-#if 0
- // Huh, is the 'break' above intentional? That means this
- // is unreachable, obviously. Avoid warning by ifdeffing
- // this out for now. Do not delete this #if 0 block unless
- // you know for sure the 'break' above is intentional.
- if ( nRes > SAL_MAX_INT64 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SAL_MAX_INT64;
- }
-#endif
- }
+ return CurFrom(p->nInt64);
case SbxSALUINT64:
- nRes = p->nInt64 * CURRENCY_FACTOR; break;
-#if 0
- // As above
- if ( nRes > SAL_MAX_INT64 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SAL_MAX_INT64;
- }
- else if ( nRes < SAL_MIN_INT64 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SAL_MIN_INT64;
- }
- break;
-#endif
-//TODO: bring back SbxINT64 types here for limits -1 with flag value at SAL_MAX/MIN
+ return CurFrom(p->uInt64);
case SbxSINGLE:
- if( p->nSingle * CURRENCY_FACTOR + 0.5 > float(SAL_MAX_INT64)
- || p->nSingle * CURRENCY_FACTOR - 0.5 < float(SAL_MIN_INT64) )
- {
- nRes = SAL_MAX_INT64;
- if( p->nSingle * CURRENCY_FACTOR - 0.5 < float(SAL_MIN_INT64) )
- nRes = SAL_MIN_INT64;
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- break;
- }
- nRes = ImpDoubleToCurrency( static_cast<double>(p->nSingle) );
- break;
+ return CurFrom(p->nSingle);
case SbxDATE:
case SbxDOUBLE:
- if( p->nDouble * CURRENCY_FACTOR + 0.5 > double(SAL_MAX_INT64)
- || p->nDouble * CURRENCY_FACTOR - 0.5 < double(SAL_MIN_INT64) )
- {
- nRes = SAL_MAX_INT64;
- if( p->nDouble * CURRENCY_FACTOR - 0.5 < double(SAL_MIN_INT64) )
- nRes = SAL_MIN_INT64;
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- break;
- }
- nRes = ImpDoubleToCurrency( p->nDouble );
- break;
+ return CurFrom(p->nDouble);
case SbxDECIMAL:
case SbxBYREF | SbxDECIMAL:
- {
- double d = 0.0;
if( p->pDecimal )
+ {
+ double d = 0.0;
p->pDecimal->getDouble( d );
- nRes = ImpDoubleToCurrency( d );
- break;
+ return CurFrom(d);
}
-
+ return 0;
case SbxBYREF | SbxSTRING:
case SbxSTRING:
case SbxLPSTR:
- if( !p->pOUString )
- nRes=0;
- else
- nRes = ImpStringToCurrency( *p->pOUString );
- break;
+ if (p->pOUString)
+ return ImpStringToCurrency( *p->pOUString );
+ return 0;
case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
- nRes = pVal->GetCurrency();
- else
- {
- SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT );
- nRes=0;
- }
- break;
- }
+ if (SbxValue* pVal = dynamic_cast<SbxValue*>(p->pObj))
+ return pVal->GetCurrency();
+ SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT );
+ return 0;
case SbxBYREF | SbxCHAR:
- nRes = sal_Int64(CURRENCY_FACTOR) * static_cast<sal_Int64>(*p->pChar);
- break;
+ return CurFrom(*p->pChar);
case SbxBYREF | SbxBYTE:
- nRes = sal_Int64(CURRENCY_FACTOR) * static_cast<sal_Int64>(*p->pByte);
- break;
+ return CurFrom(*p->pByte);
case SbxBYREF | SbxBOOL:
case SbxBYREF | SbxINTEGER:
- nRes = sal_Int64(CURRENCY_FACTOR) * static_cast<sal_Int64>(*p->pInteger);
- break;
+ return CurFrom(*p->pInteger);
case SbxBYREF | SbxERROR:
case SbxBYREF | SbxUSHORT:
- nRes = sal_Int64(CURRENCY_FACTOR) * static_cast<sal_Int64>(*p->pUShort);
- break;
+ return CurFrom(*p->pUShort);
- // from here on had to be tested
case SbxBYREF | SbxLONG:
- aTmp.nLong = *p->pLong; goto ref;
+ return CurFrom(*p->pLong);
case SbxBYREF | SbxULONG:
- aTmp.nULong = *p->pULong; goto ref;
+ return CurFrom(*p->pULong);
case SbxBYREF | SbxSINGLE:
- aTmp.nSingle = *p->pSingle; goto ref;
+ return CurFrom(*p->pSingle);
case SbxBYREF | SbxDATE:
case SbxBYREF | SbxDOUBLE:
- aTmp.nDouble = *p->pDouble; goto ref;
+ return CurFrom(*p->pDouble);
case SbxBYREF | SbxCURRENCY:
+ return *p->pnInt64;
case SbxBYREF | SbxSALINT64:
- aTmp.nInt64 = *p->pnInt64; goto ref;
+ return CurFrom(*p->pnInt64);
case SbxBYREF | SbxSALUINT64:
- aTmp.uInt64 = *p->puInt64; goto ref;
- ref:
- aTmp.eType = SbxDataType( p->eType & ~SbxBYREF );
- p = &aTmp; goto start;
+ return CurFrom(*p->puInt64);
default:
SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- nRes=0;
+ return 0;
}
- return nRes;
}
-
void ImpPutCurrency( SbxValues* p, const sal_Int64 r )
{
- SbxValues aTmp;
-start:
switch( +p->eType )
{
- // Here are tests necessary
- case SbxCHAR:
- aTmp.pChar = &p->nChar; goto direct;
- case SbxBYTE:
- aTmp.pByte = &p->nByte; goto direct;
- case SbxINTEGER:
- case SbxBOOL:
- aTmp.pInteger = &p->nInteger; goto direct;
- case SbxLONG:
- aTmp.pLong = &p->nLong; goto direct;
- case SbxULONG:
- aTmp.pULong = &p->nULong; goto direct;
- case SbxERROR:
- case SbxUSHORT:
- aTmp.pUShort = &p->nUShort; goto direct;
- direct:
- aTmp.eType = SbxDataType( p->eType | SbxBYREF );
- p = &aTmp; goto start;
-
- // from here no longer
- case SbxSINGLE:
- p->nSingle = static_cast<float>( r / CURRENCY_FACTOR ); break;
case SbxDATE:
case SbxDOUBLE:
- p->nDouble = ImpCurrencyToDouble( r ); break;
+ p->nDouble = CurTo<double>( r ); break;
case SbxSALUINT64:
- p->uInt64 = r / CURRENCY_FACTOR; break;
+ p->uInt64 = CurTo<sal_uInt64>(r); break;
case SbxSALINT64:
- p->nInt64 = r / CURRENCY_FACTOR; break;
+ p->nInt64 = CurTo<sal_Int64>(r); break;
case SbxCURRENCY:
p->nInt64 = r; break;
case SbxDECIMAL:
case SbxBYREF | SbxDECIMAL:
- {
- SbxDecimal* pDec = ImpCreateDecimal( p );
- if( !pDec->setDouble( ImpCurrencyToDouble( r ) / CURRENCY_FACTOR ) )
+ if (!ImpCreateDecimal(p)->setDouble(CurTo<double>(r)))
SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
break;
- }
case SbxBYREF | SbxSTRING:
case SbxSTRING:
case SbxLPSTR:
@@ -379,105 +227,52 @@ start:
*p->pOUString = ImpCurrencyToString( r );
break;
case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
+ if (SbxValue* pVal = dynamic_cast<SbxValue*>(p->pObj))
pVal->PutCurrency( r );
else
SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT );
break;
- }
+ case SbxCHAR:
+ p->nChar = CurTo<sal_Unicode>(r); break;
case SbxBYREF | SbxCHAR:
- {
- sal_Int64 val = r / CURRENCY_FACTOR;
- if( val > SbxMAXCHAR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); val = SbxMAXCHAR;
- }
- else if( val < SbxMINCHAR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); val = SbxMINCHAR;
- }
- *p->pChar = static_cast<sal_Unicode>(val); break;
- }
+ *p->pChar = CurTo<sal_Unicode>(r); break;
+ case SbxBYTE:
+ p->nByte = CurTo<sal_uInt8>(r); break;
case SbxBYREF | SbxBYTE:
- {
- sal_Int64 val = r / CURRENCY_FACTOR;
- if( val > SbxMAXBYTE )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); val = SbxMAXBYTE;
- }
- else if( val < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); val = 0;
- }
- *p->pByte = static_cast<sal_uInt8>(val); break;
- }
+ *p->pByte = CurTo<sal_uInt8>(r); break;
+ case SbxINTEGER:
+ case SbxBOOL:
+ p->nInteger = CurTo<sal_Int16>(r); break;
case SbxBYREF | SbxINTEGER:
case SbxBYREF | SbxBOOL:
- {
- sal_Int64 val = r / CURRENCY_FACTOR;
- if( r > SbxMAXINT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); val = SbxMAXINT;
- }
- else if( r < SbxMININT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); val = SbxMININT;
- }
- *p->pInteger = static_cast<sal_uInt16>(val); break;
- }
+ *p->pInteger = CurTo<sal_Int16>(r); break;
+ case SbxERROR:
+ case SbxUSHORT:
+ p->nUShort = CurTo<sal_uInt16>(r); break;
case SbxBYREF | SbxERROR:
case SbxBYREF | SbxUSHORT:
- {
- sal_Int64 val = r / CURRENCY_FACTOR;
- if( val > SbxMAXUINT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); val = SbxMAXUINT;
- }
- else if( val < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); val = 0;
- }
- *p->pUShort = static_cast<sal_uInt16>(val); break;
- }
+ *p->pUShort = CurTo<sal_uInt16>(r); break;
+ case SbxLONG:
+ p->nLong = CurTo<sal_Int32>(r); break;
case SbxBYREF | SbxLONG:
- {
- sal_Int64 val = r / CURRENCY_FACTOR;
- if( val > SbxMAXLNG )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); val = SbxMAXLNG;
- }
- else if( val < SbxMINLNG )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); val = SbxMINLNG;
- }
- *p->pLong = static_cast<sal_Int32>(val); break;
- }
+ *p->pLong = CurTo<sal_Int32>(r); break;
+ case SbxULONG:
+ p->nULong = CurTo<sal_uInt32>(r); break;
case SbxBYREF | SbxULONG:
- {
- sal_Int64 val = r / CURRENCY_FACTOR;
- if( val > SbxMAXULNG )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); val = SbxMAXULNG;
- }
- else if( val < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); val = 0;
- }
- *p->pULong = static_cast<sal_uInt32>(val); break;
- }
+ *p->pULong = CurTo<sal_uInt32>(r); break;
case SbxBYREF | SbxCURRENCY:
*p->pnInt64 = r; break;
case SbxBYREF | SbxSALINT64:
- *p->pnInt64 = r / CURRENCY_FACTOR; break;
+ *p->pnInt64 = CurTo<sal_Int64>(r); break;
case SbxBYREF | SbxSALUINT64:
- *p->puInt64 = static_cast<sal_uInt64>(r) / CURRENCY_FACTOR; break;
+ *p->puInt64 = CurTo<sal_uInt64>(r); break;
+ case SbxSINGLE:
+ p->nSingle = CurTo<float>( r ); break;
case SbxBYREF | SbxSINGLE:
- p->nSingle = static_cast<float>( r / CURRENCY_FACTOR ); break;
+ *p->pSingle = CurTo<float>( r ); break;
case SbxBYREF | SbxDATE:
case SbxBYREF | SbxDOUBLE:
- *p->pDouble = ImpCurrencyToDouble( r ); break;
+ *p->pDouble = CurTo<double>( r ); break;
default:
SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
}
diff --git a/basic/source/sbx/sbxdate.cxx b/basic/source/sbx/sbxdate.cxx
index 6b695a9c40c7..c3d3a4d2a4f2 100644
--- a/basic/source/sbx/sbxdate.cxx
+++ b/basic/source/sbx/sbxdate.cxx
@@ -35,73 +35,46 @@
double ImpGetDate( const SbxValues* p )
{
- double nRes;
- SbxValue* pVal;
-
switch( +p->eType )
{
- case SbxNULL:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- [[fallthrough]];
case SbxEMPTY:
- nRes = 0;
- break;
+ return 0;
case SbxCHAR:
- nRes = p->nChar;
- break;
+ return p->nChar;
case SbxBYTE:
- nRes = p->nByte;
- break;
+ return p->nByte;
case SbxINTEGER:
case SbxBOOL:
- nRes = p->nInteger;
- break;
+ return p->nInteger;
case SbxERROR:
case SbxUSHORT:
- nRes = p->nUShort;
- break;
+ return p->nUShort;
case SbxLONG:
- nRes = static_cast<double>(p->nLong);
- break;
+ return p->nLong;
case SbxULONG:
- nRes = static_cast<double>(p->nULong);
- break;
+ return p->nULong;
case SbxSINGLE:
- nRes = p->nSingle;
- break;
+ return p->nSingle;
case SbxDATE:
case SbxDOUBLE:
- nRes = p->nDouble;
- break;
+ return p->nDouble;
case SbxCURRENCY:
- nRes = ImpCurrencyToDouble( p->nInt64 );
- break;
+ return CurTo<double>(p->nInt64);
case SbxSALINT64:
- nRes = static_cast< double >(p->nInt64);
- break;
+ return static_cast<double>(p->nInt64);
case SbxSALUINT64:
- nRes = ImpSalUInt64ToDouble( p->uInt64 );
- break;
+ return static_cast<double>(p->uInt64);
case SbxDECIMAL:
case SbxBYREF | SbxDECIMAL:
- if( p->pDecimal )
- {
- p->pDecimal->getDouble( nRes );
- }
- else
- {
- nRes = 0.0;
- }
- break;
+ if (p->pDecimal)
+ if (double d; p->pDecimal->getDouble(d))
+ return d;
+ return 0;
case SbxBYREF | SbxSTRING:
case SbxSTRING:
case SbxLPSTR:
#if HAVE_FEATURE_SCRIPTING
- if( !p->pOUString )
- {
- nRes = 0;
- }
- else
+ if (p->pOUString)
{
LanguageType eLangType = Application::GetSettings().GetLanguageTag().getLanguageType();
std::shared_ptr<SvNumberFormatter> pFormatter;
@@ -143,135 +116,137 @@ double ImpGetDate( const SbxValues* p )
pFormatter->PutandConvertEntry( aStr, nCheckPos, nType,
nIndex, LANGUAGE_ENGLISH_US, eLangType, true);
- bool bSuccess = pFormatter->IsNumberFormat( *p->pOUString, nIndex, nRes );
- if ( bSuccess )
+ if (double d; pFormatter->IsNumberFormat(*p->pOUString, nIndex, d))
{
SvNumFormatType nType_ = pFormatter->GetType( nIndex );
- if(!(nType_ & ( SvNumFormatType::DATETIME | SvNumFormatType::DATE |
- SvNumFormatType::TIME | SvNumFormatType::DEFINED )))
+ if(nType_ & ( SvNumFormatType::DATETIME | SvNumFormatType::DATE |
+ SvNumFormatType::TIME | SvNumFormatType::DEFINED ))
{
- bSuccess = false;
+ return d;
}
}
- if ( !bSuccess )
- {
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION ); nRes = 0;
- }
+ SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
}
-#else
- nRes = 0;
#endif
- break;
+ return 0;
case SbxOBJECT:
- pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
- {
- nRes = pVal->GetDate();
- }
- else
- {
- SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT ); nRes = 0;
- }
- break;
+ if (SbxValue* pVal = dynamic_cast<SbxValue*>(p->pObj))
+ return pVal->GetDate();
+ SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT );
+ return 0;
case SbxBYREF | SbxCHAR:
- nRes = *p->pChar;
- break;
+ return *p->pChar;
case SbxBYREF | SbxBYTE:
- nRes = *p->pByte;
- break;
+ return *p->pByte;
case SbxBYREF | SbxINTEGER:
case SbxBYREF | SbxBOOL:
- nRes = *p->pInteger;
- break;
+ return *p->pInteger;
case SbxBYREF | SbxLONG:
- nRes = *p->pLong;
- break;
+ return *p->pLong;
case SbxBYREF | SbxULONG:
- nRes = *p->pULong;
- break;
+ return *p->pULong;
case SbxBYREF | SbxERROR:
case SbxBYREF | SbxUSHORT:
- nRes = *p->pUShort;
- break;
+ return *p->pUShort;
case SbxBYREF | SbxSINGLE:
- nRes = *p->pSingle;
- break;
+ return *p->pSingle;
case SbxBYREF | SbxDATE:
case SbxBYREF | SbxDOUBLE:
- nRes = *p->pDouble;
- break;
+ return *p->pDouble;
case SbxBYREF | SbxCURRENCY:
- nRes = ImpCurrencyToDouble( *p->pnInt64 );
- break;
+ return CurTo<double>(*p->pnInt64);
case SbxBYREF | SbxSALINT64:
- nRes = static_cast< double >(*p->pnInt64);
- break;
+ return static_cast<double>(*p->pnInt64);
case SbxBYREF | SbxSALUINT64:
- nRes = ImpSalUInt64ToDouble( *p->puInt64 );
- break;
+ return static_cast<double>(*p->puInt64);
default:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION ); nRes = 0;
- break;
+ SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
+ return 0;
}
- return nRes;
}
void ImpPutDate( SbxValues* p, double n )
{
- SbxValues aTmp;
- SbxDecimal* pDec;
- SbxValue* pVal;
-
-start:
switch( +p->eType )
{
case SbxDATE:
case SbxDOUBLE:
p->nDouble = n;
break;
- // from here will be tested
+ case SbxBYREF | SbxDATE:
+ case SbxBYREF | SbxDOUBLE:
+ *p->pDouble = n;
+ break;
case SbxCHAR:
- aTmp.pChar = &p->nChar;
- goto direct;
+ assignWithOverflowTo(p->nChar, n);
+ break;
+ case SbxBYREF | SbxCHAR:
+ assignWithOverflowTo(*p->pChar, n);
+ break;
case SbxBYTE:
- aTmp.pByte = &p->nByte;
- goto direct;
+ assignWithOverflowTo(p->nByte, n);
+ break;
+ case SbxBYREF | SbxBYTE:
+ assignWithOverflowTo(*p->pByte, n);
+ break;
case SbxINTEGER:
case SbxBOOL:
- aTmp.pInteger = &p->nInteger;
- goto direct;
- case SbxLONG:
- aTmp.pLong = &p->nLong;
- goto direct;
- case SbxULONG:
- aTmp.pULong = &p->nULong;
- goto direct;
+ assignWithOverflowTo(p->nInteger, n);
+ break;
+ case SbxBYREF | SbxINTEGER:
+ case SbxBYREF | SbxBOOL:
+ assignWithOverflowTo(*p->pInteger, n);
+ break;
case SbxERROR:
case SbxUSHORT:
- aTmp.pUShort = &p->nUShort;
- goto direct;
- case SbxSINGLE:
- aTmp.pSingle = &p->nSingle;
- goto direct;
+ assignWithOverflowTo(p->nUShort, n);
+ break;
+ case SbxBYREF | SbxERROR:
+ case SbxBYREF | SbxUSHORT:
+ assignWithOverflowTo(*p->pUShort, n);
+ break;
+ case SbxLONG:
+ assignWithOverflowTo(p->nLong, n);
+ break;
+ case SbxBYREF | SbxLONG:
+ assignWithOverflowTo(*p->pLong, n);
+ break;
+ case SbxULONG:
+ assignWithOverflowTo(p->nULong, n);
+ break;
+ case SbxBYREF | SbxULONG:
+ assignWithOverflowTo(*p->pULong, n);
+ break;
case SbxCURRENCY:
+ assignWithOverflowTo(p->nInt64, CurFrom(n));
+ break;
+ case SbxBYREF | SbxCURRENCY:
+ assignWithOverflowTo(*p->pnInt64, CurFrom(n));
+ break;
case SbxSALINT64:
- aTmp.pnInt64 = &p->nInt64;
- goto direct;
+ assignWithOverflowTo(p->nInt64, n);
+ break;
+ case SbxBYREF | SbxSALINT64:
+ assignWithOverflowTo(*p->pnInt64, n);
+ break;
case SbxSALUINT64:
- aTmp.puInt64 = &p->uInt64;
- goto direct;
+ assignWithOverflowTo(p->uInt64, n);
+ break;
+ case SbxBYREF | SbxSALUINT64:
+ assignWithOverflowTo(*p->puInt64, n);
+ break;
+ case SbxSINGLE:
+ assignWithOverflowTo(p->nSingle, n);
+ break;
+ case SbxBYREF | SbxSINGLE:
+ assignWithOverflowTo(*p->pSingle, n);
+ break;
+
case SbxDECIMAL:
case SbxBYREF | SbxDECIMAL:
- pDec = ImpCreateDecimal( p );
- if( !pDec->setDouble( n ) )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- }
+ ImpCreateDecimal(p)->setWithOverflow(n);
break;
- direct:
- aTmp.eType = SbxDataType( p->eType | SbxBYREF );
- p = &aTmp; goto start;
case SbxBYREF | SbxSTRING:
case SbxSTRING:
@@ -342,9 +317,9 @@ start:
#endif
break;
}
+
case SbxOBJECT:
- pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
+ if (auto pVal = dynamic_cast<SbxValue*>(p->pObj))
{
pVal->PutDate( n );
}
@@ -353,58 +328,7 @@ start:
SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT );
}
break;
- case SbxBYREF | SbxCHAR:
- *p->pChar = ImpDoubleToChar(n);
- break;
- case SbxBYREF | SbxBYTE:
- *p->pByte = ImpDoubleToByte(n);
- break;
- case SbxBYREF | SbxINTEGER:
- case SbxBYREF | SbxBOOL:
- *p->pInteger = ImpDoubleToInteger(n);
- break;
- case SbxBYREF | SbxERROR:
- case SbxBYREF | SbxUSHORT:
- *p->pUShort = ImpDoubleToUShort(n);
- break;
- case SbxBYREF | SbxLONG:
- *p->pLong = ImpDoubleToLong(n);
- break;
- case SbxBYREF | SbxULONG:
- *p->pULong = ImpDoubleToULong(n);
- break;
- case SbxBYREF | SbxSINGLE:
- if( n > SbxMAXSNG )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXSNG;
- }
- else if( n < SbxMINSNG )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMINSNG;
- }
- *p->pSingle = static_cast<float>(n);
- break;
- case SbxBYREF | SbxSALINT64:
- *p->pnInt64 = ImpDoubleToSalInt64( n );
- break;
- case SbxBYREF | SbxSALUINT64:
- *p->puInt64 = ImpDoubleToSalUInt64( n );
- break;
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- *p->pDouble = n;
- break;
- case SbxBYREF | SbxCURRENCY:
- if( n > SbxMAXCURR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXCURR;
- }
- else if( n < SbxMINCURR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMINCURR;
- }
- *p->pnInt64 = ImpDoubleToCurrency( n );
- break;
+
default:
SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
break;
diff --git a/basic/source/sbx/sbxdbl.cxx b/basic/source/sbx/sbxdbl.cxx
deleted file mode 100644
index 9718c1dfd7b7..000000000000
--- a/basic/source/sbx/sbxdbl.cxx
+++ /dev/null
@@ -1,268 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include <config_features.h>
-
-#include <o3tl/float_int_conversion.hxx>
-#include <vcl/errcode.hxx>
-#include "sbxconv.hxx"
-#include <runtime.hxx>
-
-double ImpGetDouble( const SbxValues* p )
-{
- double nRes;
- switch( +p->eType )
- {
- case SbxNULL:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- [[fallthrough]];
- case SbxEMPTY:
- nRes = 0; break;
- case SbxCHAR:
- nRes = p->nChar; break;
- case SbxBYTE:
- nRes = p->nByte; break;
- case SbxINTEGER:
- case SbxBOOL:
- nRes = p->nInteger; break;
- case SbxERROR:
- case SbxUSHORT:
- nRes = p->nUShort; break;
- case SbxLONG:
- nRes = p->nLong; break;
- case SbxULONG:
- nRes = p->nULong; break;
- case SbxSINGLE:
- nRes = p->nSingle; break;
- case SbxDATE:
- case SbxDOUBLE:
- nRes = p->nDouble; break;
- case SbxCURRENCY:
- nRes = ImpCurrencyToDouble( p->nInt64 ); break;
- case SbxSALINT64:
- nRes = static_cast< double >(p->nInt64); break;
- case SbxSALUINT64:
- nRes = ImpSalUInt64ToDouble( p->uInt64 ); break;
- case SbxDECIMAL:
- case SbxBYREF | SbxDECIMAL:
- if( p->pDecimal )
- p->pDecimal->getDouble( nRes );
- else
- nRes = 0.0;
- break;
- case SbxBYREF | SbxSTRING:
- case SbxSTRING:
- case SbxLPSTR:
- if( !p->pOUString )
- {
- nRes = 0;
-#if HAVE_FEATURE_SCRIPTING
- if ( SbiRuntime::isVBAEnabled() )// VBA only behaviour
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
-#endif
- }
- else
- {
- double d;
- SbxDataType t;
- if( ImpScan( *p->pOUString, d, t, nullptr, true ) != ERRCODE_NONE )
- {
- nRes = 0;
-#if HAVE_FEATURE_SCRIPTING
- if ( SbiRuntime::isVBAEnabled() )// VBA only behaviour
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
-#endif
- }
- else
- nRes = d;
- }
- break;
- case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
- nRes = pVal->GetDouble();
- else
- {
- SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT ); nRes = 0;
- }
- break;
- }
-
- case SbxBYREF | SbxCHAR:
- nRes = *p->pChar; break;
- case SbxBYREF | SbxBYTE:
- nRes = *p->pByte; break;
- case SbxBYREF | SbxINTEGER:
- case SbxBYREF | SbxBOOL:
- nRes = *p->pInteger; break;
- case SbxBYREF | SbxLONG:
- nRes = *p->pLong; break;
- case SbxBYREF | SbxULONG:
- nRes = *p->pULong; break;
- case SbxBYREF | SbxERROR:
- case SbxBYREF | SbxUSHORT:
- nRes = *p->pUShort; break;
- case SbxBYREF | SbxSINGLE:
- nRes = *p->pSingle; break;
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- nRes = *p->pDouble; break;
- case SbxBYREF | SbxCURRENCY:
- nRes = ImpCurrencyToDouble( *p->pnInt64 ); break;
- case SbxBYREF | SbxSALINT64:
- nRes = static_cast< double >(*p->pnInt64); break;
- case SbxBYREF | SbxSALUINT64:
- nRes = ImpSalUInt64ToDouble( *p->puInt64 ); break;
-
- default:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION ); nRes = 0;
- }
- return nRes;
-}
-
-void ImpPutDouble( SbxValues* p, double n, bool bCoreString )
-{
- SbxValues aTmp;
-start:
- switch( +p->eType )
- {
- // Here are tests necessary
- case SbxCHAR:
- aTmp.pChar = &p->nChar; goto direct;
- case SbxBYTE:
- aTmp.pByte = &p->nByte; goto direct;
- case SbxINTEGER:
- case SbxBOOL:
- aTmp.pInteger = &p->nInteger; goto direct;
- case SbxLONG:
- aTmp.pLong = &p->nLong; goto direct;
- case SbxULONG:
- aTmp.pULong = &p->nULong; goto direct;
- case SbxERROR:
- case SbxUSHORT:
- aTmp.pUShort = &p->nUShort; goto direct;
- case SbxSINGLE:
- aTmp.pSingle = &p->nSingle; goto direct;
- case SbxDECIMAL:
- case SbxBYREF | SbxDECIMAL:
- {
- SbxDecimal* pDec = ImpCreateDecimal( p );
- if( !pDec->setDouble( n ) )
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- break;
- }
- direct:
- aTmp.eType = SbxDataType( p->eType | SbxBYREF );
- p = &aTmp; goto start;
-
- case SbxCURRENCY:
- if( n > SbxMAXCURR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXCURR;
- }
- else if( n < SbxMINCURR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMINCURR;
- }
- p->nInt64 = ImpDoubleToCurrency( n );
- break;
-
- // from here on no longer
- case SbxSALINT64:
- p->nInt64 = ImpDoubleToSalInt64( n ); break;
- case SbxSALUINT64:
- p->uInt64 = ImpDoubleToSalUInt64( n ); break;
- case SbxDATE:
- case SbxDOUBLE:
- p->nDouble = n; break;
-
- case SbxBYREF | SbxSTRING:
- case SbxSTRING:
- case SbxLPSTR:
- if( !p->pOUString )
- p->pOUString = new OUString;
- // tdf#107953 - show 17 significant digits
- ImpCvtNum( n, 17, *p->pOUString, bCoreString );
- break;
- case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
- pVal->PutDouble( n );
- else
- SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT );
- break;
- }
- case SbxBYREF | SbxCHAR:
- *p->pChar = ImpDoubleToChar(n); break;
- case SbxBYREF | SbxBYTE:
- *p->pByte = ImpDoubleToByte(n); break;
- case SbxBYREF | SbxINTEGER:
- case SbxBYREF | SbxBOOL:
- *p->pInteger = ImpDoubleToInteger(n); break;
- case SbxBYREF | SbxERROR:
- case SbxBYREF | SbxUSHORT:
- *p->pUShort = ImpDoubleToUShort(n); break;
- case SbxBYREF | SbxLONG:
- *p->pLong = ImpDoubleToLong(n); break;
- case SbxBYREF | SbxULONG:
- *p->pULong = ImpDoubleToULong(n); break;
- case SbxBYREF | SbxSINGLE:
- if( n > SbxMAXSNG )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXSNG;
- }
- else if( n < SbxMINSNG )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMINSNG;
- }
- else if( n > 0 && n < SbxMAXSNG2 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXSNG2;
- }
- else if( n < 0 && n > SbxMINSNG2 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMINSNG2;
- }
- *p->pSingle = static_cast<float>(n); break;
- case SbxBYREF | SbxSALINT64:
- *p->pnInt64 = ImpDoubleToSalInt64( n ); break;
- case SbxBYREF | SbxSALUINT64:
- *p->puInt64 = ImpDoubleToSalUInt64( n ); break;
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- *p->pDouble = n; break;
- case SbxBYREF | SbxCURRENCY:
- if( n > SbxMAXCURR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXCURR;
- }
- else if( n < SbxMINCURR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMINCURR;
- }
- *p->pnInt64 = ImpDoubleToCurrency( n ); break;
-
- default:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- }
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/sbx/sbxdec.cxx b/basic/source/sbx/sbxdec.cxx
index e47713445cf7..e6a8837fe7ee 100644
--- a/basic/source/sbx/sbxdec.cxx
+++ b/basic/source/sbx/sbxdec.cxx
@@ -17,7 +17,11 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+#ifdef _WIN32
#include <o3tl/char16_t2wchar_t.hxx>
+#include <systools/win32/oleauto.hxx>
+#endif
#include <basic/sberrors.hxx>
#include "sbxconv.hxx"
@@ -70,20 +74,14 @@ void SbxDecimal::fillAutomationDecimal
#endif
}
-SbxDecimal::~SbxDecimal()
-{
-}
-
void releaseDecimalPtr( SbxDecimal*& rpDecimal )
{
if( rpDecimal )
{
rpDecimal->mnRefCount--;
if( rpDecimal->mnRefCount == 0 )
- {
delete rpDecimal;
- rpDecimal = nullptr;
- }
+ rpDecimal = nullptr;
}
}
@@ -159,6 +157,11 @@ void SbxDecimal::setLong( sal_Int32 val )
VarDecFromI4(static_cast<LONG>(val), &maDec);
}
+bool SbxDecimal::setHyper( sal_Int64 val )
+{
+ return SUCCEEDED(VarDecFromI8(static_cast<LONG64>(val), &maDec));
+}
+
void SbxDecimal::setUShort( sal_uInt16 val )
{
VarDecFromUI2( val, &maDec );
@@ -169,6 +172,11 @@ void SbxDecimal::setULong( sal_uInt32 val )
VarDecFromUI4( static_cast<ULONG>(val), &maDec );
}
+bool SbxDecimal::setUHyper( sal_uInt64 val )
+{
+ return SUCCEEDED(VarDecFromUI8( static_cast<ULONG64>(val), &maDec ));
+}
+
bool SbxDecimal::setSingle( float val )
{
bool bRet = ( VarDecFromR4( val, &maDec ) == S_OK );
@@ -243,6 +251,12 @@ bool SbxDecimal::getChar( sal_Unicode& rVal )
return bRet;
}
+bool SbxDecimal::getByte( sal_uInt8& rVal )
+{
+ bool bRet = ( VarUI1FromDec( &maDec, &rVal ) == S_OK );
+ return bRet;
+}
+
bool SbxDecimal::getShort( sal_Int16& rVal )
{
bool bRet = ( VarI2FromDec( &maDec, &rVal ) == S_OK );
@@ -255,6 +269,12 @@ bool SbxDecimal::getLong( sal_Int32& rVal )
return bRet;
}
+bool SbxDecimal::getHyper( sal_Int64& rVal )
+{
+ bool bRet = ( VarI8FromDec( &maDec, &rVal ) == S_OK );
+ return bRet;
+}
+
bool SbxDecimal::getUShort( sal_uInt16& rVal )
{
bool bRet = ( VarUI2FromDec( &maDec, &rVal ) == S_OK );
@@ -267,6 +287,12 @@ bool SbxDecimal::getULong( sal_uInt32& rVal )
return bRet;
}
+bool SbxDecimal::getUHyper( sal_uInt64& rVal )
+{
+ bool bRet = ( VarUI8FromDec( &maDec, &rVal ) == S_OK );
+ return bRet;
+}
+
bool SbxDecimal::getSingle( float& rVal )
{
bool bRet = ( VarR4FromDec( &maDec, &rVal ) == S_OK );
@@ -321,8 +347,10 @@ void SbxDecimal::setChar( SAL_UNUSED_PARAMETER sal_Unicode ) {}
void SbxDecimal::setByte( SAL_UNUSED_PARAMETER sal_uInt8 ) {}
void SbxDecimal::setShort( SAL_UNUSED_PARAMETER sal_Int16 ) {}
void SbxDecimal::setLong( SAL_UNUSED_PARAMETER sal_Int32 ) {}
+bool SbxDecimal::setHyper( SAL_UNUSED_PARAMETER sal_Int64 ) { return false; }
void SbxDecimal::setUShort( SAL_UNUSED_PARAMETER sal_uInt16 ) {}
void SbxDecimal::setULong( SAL_UNUSED_PARAMETER sal_uInt32 ) {}
+bool SbxDecimal::setUHyper( SAL_UNUSED_PARAMETER sal_uInt64 ) { return false; }
bool SbxDecimal::setSingle( SAL_UNUSED_PARAMETER float ) { return false; }
bool SbxDecimal::setDouble( SAL_UNUSED_PARAMETER double ) { return false; }
void SbxDecimal::setInt( SAL_UNUSED_PARAMETER int ) {}
@@ -330,10 +358,13 @@ void SbxDecimal::setUInt( SAL_UNUSED_PARAMETER unsigned int ) {}
bool SbxDecimal::setString( SAL_UNUSED_PARAMETER OUString* ) { return false; }
bool SbxDecimal::getChar( SAL_UNUSED_PARAMETER sal_Unicode& ) { return false; }
+bool SbxDecimal::getByte( SAL_UNUSED_PARAMETER sal_uInt8& ) { return false; }
bool SbxDecimal::getShort( SAL_UNUSED_PARAMETER sal_Int16& ) { return false; }
bool SbxDecimal::getLong( SAL_UNUSED_PARAMETER sal_Int32& ) { return false; }
+bool SbxDecimal::getHyper( SAL_UNUSED_PARAMETER sal_Int64& ) { return false; }
bool SbxDecimal::getUShort( SAL_UNUSED_PARAMETER sal_uInt16& ) { return false; }
bool SbxDecimal::getULong( SAL_UNUSED_PARAMETER sal_uInt32& ) { return false; }
+bool SbxDecimal::getUHyper( SAL_UNUSED_PARAMETER sal_uInt64& ) { return false; }
bool SbxDecimal::getSingle( SAL_UNUSED_PARAMETER float& ) { return false; }
bool SbxDecimal::getDouble( SAL_UNUSED_PARAMETER double& ) { return false; }
@@ -344,7 +375,7 @@ void SbxDecimal::getString( OUString& rString )
#ifdef _WIN32
static LCID nLANGID = MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US );
- BSTR pBStr = nullptr;
+ sal::systools::BStr pBStr;
// VarBstrFromDec allocates new BSTR that needs to be released with SysFreeString
HRESULT hResult = VarBstrFromDec( &maDec, nLANGID, 0, &pBStr );
if( hResult == S_OK )
@@ -368,14 +399,19 @@ void SbxDecimal::getString( OUString& rString )
i++;
}
}
- rString = o3tl::toU( pBStr );
- SysFreeString( pBStr );
+ rString = pBStr;
}
#else
(void)rString;
#endif
}
+void SbxDecimal::HandleFailure(bool isSuccess)
+{
+ if (!isSuccess)
+ SbxBase::SetError(ERRCODE_BASIC_MATH_OVERFLOW);
+}
+
SbxDecimal* ImpCreateDecimal( SbxValues* p )
{
if( !p )
@@ -392,25 +428,18 @@ SbxDecimal* ImpCreateDecimal( SbxValues* p )
SbxDecimal* ImpGetDecimal( const SbxValues* p )
{
- SbxValues aTmp;
- SbxDecimal* pnDecRes;
-
SbxDataType eType = p->eType;
if( eType == SbxDECIMAL && p->pDecimal )
{
- pnDecRes = new SbxDecimal( *p->pDecimal );
+ SbxDecimal* pnDecRes = new SbxDecimal( *p->pDecimal );
pnDecRes->addRef();
return pnDecRes;
}
- pnDecRes = new SbxDecimal();
+ SbxDecimal* pnDecRes = new SbxDecimal();
pnDecRes->addRef();
-start:
switch( +eType )
{
- case SbxNULL:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- [[fallthrough]];
case SbxEMPTY:
pnDecRes->setShort( 0 ); break;
case SbxCHAR:
@@ -428,35 +457,37 @@ start:
case SbxULONG:
pnDecRes->setULong( p->nULong ); break;
case SbxSINGLE:
- if( !pnDecRes->setSingle( p->nSingle ) )
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
+ pnDecRes->setWithOverflow(p->nSingle);
+ break;
+ case SbxBYREF | SbxSINGLE:
+ pnDecRes->setWithOverflow(*p->pSingle);
break;
case SbxCURRENCY:
- {
- if( !pnDecRes->setDouble( ImpCurrencyToDouble( p->nInt64 ) ) )
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- break;
- }
+ pnDecRes->setWithOverflow(CurTo<double>(p->nInt64));
+ break;
+ case SbxBYREF | SbxCURRENCY:
+ pnDecRes->setWithOverflow(CurTo<double>(*p->pnInt64));
+ break;
case SbxSALINT64:
- {
- if( !pnDecRes->setDouble( static_cast<double>(p->nInt64) ) )
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- break;
- }
+ pnDecRes->setWithOverflow(p->nInt64);
+ break;
+ case SbxBYREF | SbxSALINT64:
+ pnDecRes->setWithOverflow(*p->pnInt64);
+ break;
case SbxSALUINT64:
- {
- if( !pnDecRes->setDouble( static_cast<double>(p->uInt64) ) )
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- break;
- }
+ pnDecRes->setWithOverflow(p->uInt64);
+ break;
+ case SbxBYREF | SbxSALUINT64:
+ pnDecRes->setWithOverflow(*p->puInt64);
+ break;
case SbxDATE:
case SbxDOUBLE:
- {
- double dVal = p->nDouble;
- if( !pnDecRes->setDouble( dVal ) )
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
+ pnDecRes->setWithOverflow(p->nDouble);
+ break;
+ case SbxBYREF | SbxDATE:
+ case SbxBYREF | SbxDOUBLE:
+ pnDecRes->setWithOverflow(*p->pDouble);
break;
- }
case SbxLPSTR:
case SbxSTRING:
case SbxBYREF | SbxSTRING:
@@ -464,9 +495,7 @@ start:
pnDecRes->setString( p->pOUString );
break;
case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
+ if (SbxValue* pVal = dynamic_cast<SbxValue*>(p->pObj))
pnDecRes->setDecimal( pVal->GetDecimal() );
else
{
@@ -474,7 +503,6 @@ start:
pnDecRes->setShort( 0 );
}
break;
- }
case SbxBYREF | SbxCHAR:
pnDecRes->setChar( *p->pChar ); break;
@@ -491,21 +519,6 @@ start:
case SbxBYREF | SbxUSHORT:
pnDecRes->setUShort( *p->pUShort ); break;
- // from here on had to be tested
- case SbxBYREF | SbxSINGLE:
- aTmp.nSingle = *p->pSingle; goto ref;
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- aTmp.nDouble = *p->pDouble; goto ref;
- case SbxBYREF | SbxCURRENCY:
- case SbxBYREF | SbxSALINT64:
- aTmp.nInt64 = *p->pnInt64; goto ref;
- case SbxBYREF | SbxSALUINT64:
- aTmp.uInt64 = *p->puInt64; goto ref;
- ref:
- aTmp.eType = SbxDataType( p->eType & 0x0FFF );
- p = &aTmp; goto start;
-
default:
SbxBase::SetError( ERRCODE_BASIC_CONVERSION ); pnDecRes->setShort( 0 );
}
@@ -517,39 +530,69 @@ void ImpPutDecimal( SbxValues* p, SbxDecimal* pDec )
if( !pDec )
return;
- SbxValues aTmp;
-start:
switch( +p->eType )
{
- // here had to be tested
case SbxCHAR:
- aTmp.pChar = &p->nChar; goto direct;
+ assignWithOverflowTo(p->nChar, *pDec);
+ break;
+ case SbxBYREF | SbxCHAR:
+ assignWithOverflowTo(*p->pChar, *pDec);
+ break;
case SbxBYTE:
- aTmp.pByte = &p->nByte; goto direct;
- case SbxULONG:
- aTmp.pULong = &p->nULong; goto direct;
- case SbxERROR:
- case SbxUSHORT:
- aTmp.pUShort = &p->nUShort; goto direct;
+ assignWithOverflowTo(p->nByte, *pDec);
+ break;
+ case SbxBYREF | SbxBYTE:
+ assignWithOverflowTo(*p->pByte, *pDec);
+ break;
case SbxINTEGER:
case SbxBOOL:
- aTmp.pInteger = &p->nInteger; goto direct;
+ assignWithOverflowTo(p->nInteger, *pDec);
+ break;
+ case SbxBYREF | SbxINTEGER:
+ case SbxBYREF | SbxBOOL:
+ assignWithOverflowTo(*p->pInteger, *pDec);
+ break;
+ case SbxERROR:
+ case SbxUSHORT:
+ assignWithOverflowTo(p->nUShort, *pDec);
+ break;
+ case SbxBYREF | SbxERROR:
+ case SbxBYREF | SbxUSHORT:
+ assignWithOverflowTo(*p->pUShort, *pDec);
+ break;
case SbxLONG:
- aTmp.pLong = &p->nLong; goto direct;
+ assignWithOverflowTo(p->nLong, *pDec);
+ break;
+ case SbxBYREF | SbxLONG:
+ assignWithOverflowTo(*p->pLong, *pDec);
+ break;
+ case SbxULONG:
+ assignWithOverflowTo(p->nULong, *pDec);
+ break;
+ case SbxBYREF | SbxULONG:
+ assignWithOverflowTo(*p->pULong, *pDec);
+ break;
case SbxCURRENCY:
+ p->nInt64 = CurFrom(pDec->getWithOverflow<double>());
+ break;
+ case SbxBYREF | SbxCURRENCY:
+ *p->pnInt64 = CurFrom(pDec->getWithOverflow<double>());
+ break;
case SbxSALINT64:
- aTmp.pnInt64 = &p->nInt64; goto direct;
+ assignWithOverflowTo(p->nInt64, *pDec);
+ break;
+ case SbxBYREF | SbxSALINT64:
+ assignWithOverflowTo(*p->pnInt64, *pDec);
+ break;
case SbxSALUINT64:
- aTmp.puInt64 = &p->uInt64; goto direct;
-
- direct:
- aTmp.eType = SbxDataType( p->eType | SbxBYREF );
- p = &aTmp; goto start;
+ assignWithOverflowTo(p->uInt64, *pDec);
+ break;
+ case SbxBYREF | SbxSALUINT64:
+ assignWithOverflowTo(*p->puInt64, *pDec);
+ break;
- // from here on no longer
case SbxDECIMAL:
case SbxBYREF | SbxDECIMAL:
- {
if( pDec != p->pDecimal )
{
releaseDecimalPtr( p->pDecimal );
@@ -558,22 +601,20 @@ start:
pDec->addRef();
}
break;
- }
case SbxSINGLE:
- {
- float f(0.0);
- pDec->getSingle( f );
- p->nSingle = f;
+ assignWithOverflowTo(p->nSingle, *pDec);
+ break;
+ case SbxBYREF | SbxSINGLE:
+ assignWithOverflowTo(*p->pSingle, *pDec);
break;
- }
case SbxDATE:
case SbxDOUBLE:
- {
- double d(0.0);
- pDec->getDouble( d );
- p->nDouble = d;
+ assignWithOverflowTo(p->nDouble, *pDec);
+ break;
+ case SbxBYREF | SbxDATE:
+ case SbxBYREF | SbxDOUBLE:
+ assignWithOverflowTo(*p->pDouble, *pDec);
break;
- }
case SbxLPSTR:
case SbxSTRING:
@@ -583,100 +624,12 @@ start:
pDec->getString( *p->pOUString );
break;
case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
+ if (SbxValue* pVal = dynamic_cast<SbxValue*>(p->pObj))
pVal->PutDecimal( pDec );
else
SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT );
break;
- }
- case SbxBYREF | SbxCHAR:
- if( !pDec->getChar( *p->pChar ) )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- *p->pChar = 0;
- }
- break;
- case SbxBYREF | SbxBYTE:
- if( !pDec->getChar( *p->pChar ) )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- *p->pByte = 0;
- }
- break;
- case SbxBYREF | SbxINTEGER:
- case SbxBYREF | SbxBOOL:
- if( !pDec->getShort( *p->pInteger ) )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- *p->pInteger = 0;
- }
- break;
- case SbxBYREF | SbxERROR:
- case SbxBYREF | SbxUSHORT:
- if( !pDec->getUShort( *p->pUShort ) )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- *p->pUShort = 0;
- }
- break;
- case SbxBYREF | SbxLONG:
- if( !pDec->getLong( *p->pLong ) )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- *p->pLong = 0;
- }
- break;
- case SbxBYREF | SbxULONG:
- if( !pDec->getULong( *p->pULong ) )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- *p->pULong = 0;
- }
- break;
- case SbxBYREF | SbxCURRENCY:
- {
- double d(0.0);
- if( !pDec->getDouble( d ) )
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- *p->pnInt64 = ImpDoubleToCurrency( d );
- }
- break;
- case SbxBYREF | SbxSALINT64:
- {
- double d(0.0);
- if( !pDec->getDouble( d ) )
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- else
- *p->pnInt64 = ImpDoubleToSalInt64( d );
- }
- break;
- case SbxBYREF | SbxSALUINT64:
- {
- double d(0.0);
- if( !pDec->getDouble( d ) )
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- else
- *p->puInt64 = ImpDoubleToSalUInt64( d );
- }
- break;
- case SbxBYREF | SbxSINGLE:
- if( !pDec->getSingle( *p->pSingle ) )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- *p->pSingle = 0;
- }
- break;
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- if( !pDec->getDouble( *p->pDouble ) )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- *p->pDouble = 0;
- }
- break;
default:
SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
}
diff --git a/basic/source/sbx/sbxdec.hxx b/basic/source/sbx/sbxdec.hxx
index 3db396ea6cb4..a7af21fa4f28 100644
--- a/basic/source/sbx/sbxdec.hxx
+++ b/basic/source/sbx/sbxdec.hxx
@@ -46,8 +46,6 @@ public:
SbxDecimal( const SbxDecimal& rDec );
explicit SbxDecimal( const css::bridge::oleautomation::Decimal& rAutomationDec );
- ~SbxDecimal();
-
void addRef()
{ mnRefCount++; }
@@ -57,8 +55,10 @@ public:
void setByte( sal_uInt8 val );
void setShort( sal_Int16 val );
void setLong( sal_Int32 val );
+ bool setHyper( sal_Int64 val );
void setUShort( sal_uInt16 val );
void setULong( sal_uInt32 val );
+ bool setUHyper( sal_uInt64 val );
bool setSingle( float val );
bool setDouble( double val );
void setInt( int val );
@@ -74,15 +74,31 @@ public:
#endif
}
+ void setWithOverflow(float val) { HandleFailure(setSingle(val)); }
+ void setWithOverflow(double val) { HandleFailure(setDouble(val)); }
+ void setWithOverflow(sal_Int64 val) { HandleFailure(setHyper(val)); }
+ void setWithOverflow(sal_uInt64 val) { HandleFailure(setUHyper(val)); }
+
bool getChar( sal_Unicode& rVal );
+ bool getByte( sal_uInt8& rVal );
bool getShort( sal_Int16& rVal );
bool getLong( sal_Int32& rVal );
+ bool getHyper( sal_Int64& rVal );
bool getUShort( sal_uInt16& rVal );
bool getULong( sal_uInt32& rVal );
+ bool getUHyper( sal_uInt64& rVal );
bool getSingle( float& rVal );
bool getDouble( double& rVal );
void getString( OUString& rString );
+ // Only handles types, which have corresponding getWithOverflow_impl
+ template <typename T> T getWithOverflow()
+ {
+ T n = 0;
+ HandleFailure(getWithOverflow_impl(n));
+ return n;
+ }
+
bool operator -= ( const SbxDecimal &r );
bool operator += ( const SbxDecimal &r );
bool operator /= ( const SbxDecimal &r );
@@ -94,6 +110,20 @@ public:
// must match the return values of the Microsoft VarDecCmp Automation function
enum class CmpResult { LT, EQ, GT };
friend CmpResult compare( const SbxDecimal &rLeft, const SbxDecimal &rRight );
+
+private:
+ bool getWithOverflow_impl(sal_Unicode& n) { return getChar(n); }
+ bool getWithOverflow_impl(sal_uInt8& n) { return getByte(n); }
+ bool getWithOverflow_impl(sal_Int16& n) { return getShort(n); }
+ bool getWithOverflow_impl(sal_uInt16& n) { return getUShort(n); }
+ bool getWithOverflow_impl(sal_Int32& n) { return getLong(n); }
+ bool getWithOverflow_impl(sal_uInt32& n) { return getULong(n); }
+ bool getWithOverflow_impl(sal_Int64& n) { return getHyper(n); }
+ bool getWithOverflow_impl(sal_uInt64& n) { return getUHyper(n); }
+ bool getWithOverflow_impl(float& n) { return getSingle(n); }
+ bool getWithOverflow_impl(double& n) { return getDouble(n); }
+
+ void HandleFailure(bool isSuccess);
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/sbx/sbxexec.cxx b/basic/source/sbx/sbxexec.cxx
index d830061f071d..9d9b339ef715 100644
--- a/basic/source/sbx/sbxexec.cxx
+++ b/basic/source/sbx/sbxexec.cxx
@@ -17,19 +17,22 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
#include <basic/sbx.hxx>
#include <basic/sberrors.hxx>
#include <rtl/character.hxx>
#include <rtl/ustrbuf.hxx>
+#include <basiccharclass.hxx>
static SbxVariableRef Element
( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode** ppBuf,
- SbxClassType );
+ SbxClassType, bool bCompatible );
static const sal_Unicode* SkipWhitespace( const sal_Unicode* p )
{
- while( *p && ( *p == ' ' || *p == '\t' ) )
+ while( BasicCharClass::isWhitespace(*p) )
p++;
return p;
}
@@ -37,7 +40,7 @@ static const sal_Unicode* SkipWhitespace( const sal_Unicode* p )
// Scanning of a symbol. The symbol were inserted in rSym, the return value
// is the new scan position. The symbol is at errors empty.
-static const sal_Unicode* Symbol( const sal_Unicode* p, OUString& rSym )
+static const sal_Unicode* Symbol( const sal_Unicode* p, OUString& rSym, bool bCompatible )
{
sal_uInt16 nLen = 0;
// Did we have a nonstandard symbol?
@@ -54,7 +57,7 @@ static const sal_Unicode* Symbol( const sal_Unicode* p, OUString& rSym )
else
{
// A symbol had to begin with an alphabetic character or an underline
- if( !rtl::isAsciiAlpha( *p ) && *p != '_' )
+ if( !BasicCharClass::isAlpha( *p, bCompatible ) && *p != '_' )
{
SbxBase::SetError( ERRCODE_BASIC_SYNTAX );
}
@@ -62,7 +65,7 @@ static const sal_Unicode* Symbol( const sal_Unicode* p, OUString& rSym )
{
rSym = p;
// The it can contain alphabetic characters, numbers or underlines
- while( *p && (rtl::isAsciiAlphanumeric( *p ) || *p == '_') )
+ while( *p && (BasicCharClass::isAlphaNumeric( *p, bCompatible ) || *p == '_') )
{
p++;
nLen++;
@@ -81,15 +84,15 @@ static const sal_Unicode* Symbol( const sal_Unicode* p, OUString& rSym )
// Qualified name. Element.Element...
static SbxVariableRef QualifiedName
- ( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode** ppBuf, SbxClassType t )
+ ( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode** ppBuf, SbxClassType t, bool bCompatible )
{
SbxVariableRef refVar;
const sal_Unicode* p = SkipWhitespace( *ppBuf );
- if( rtl::isAsciiAlpha( *p ) || *p == '_' || *p == '[' )
+ if( BasicCharClass::isAlpha( *p, bCompatible ) || *p == '_' || *p == '[' )
{
// Read in the element
- refVar = Element( pObj, pGbl, &p, t );
+ refVar = Element( pObj, pGbl, &p, t, bCompatible );
while( refVar.is() && (*p == '.' || *p == '!') )
{
// It follows still an objectelement. The current element
@@ -103,7 +106,7 @@ static SbxVariableRef QualifiedName
break;
p++;
// And the next element please
- refVar = Element( pObj, pGbl, &p, t );
+ refVar = Element( pObj, pGbl, &p, t, bCompatible );
}
}
else
@@ -116,7 +119,7 @@ static SbxVariableRef QualifiedName
// a function (with optional parameters).
static SbxVariableRef Operand
- ( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode** ppBuf, bool bVar )
+ ( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode** ppBuf, bool bVar, bool bCompatible )
{
SbxVariableRef refVar( new SbxVariable );
const sal_Unicode* p = SkipWhitespace( *ppBuf );
@@ -126,8 +129,8 @@ static SbxVariableRef Operand
|| *p == '&' ) )
{
// A number could be scanned in directly!
- sal_uInt16 nLen;
- if( !refVar->Scan( OUString( p ), &nLen ) )
+ sal_Int32 nLen;
+ if (!refVar->Scan(p, &nLen))
{
refVar.clear();
}
@@ -159,7 +162,7 @@ static SbxVariableRef Operand
}
else
{
- refVar = QualifiedName( pObj, pGbl, &p, SbxClassType::DontCare );
+ refVar = QualifiedName( pObj, pGbl, &p, SbxClassType::DontCare, bCompatible );
}
*ppBuf = p;
return refVar;
@@ -168,15 +171,15 @@ static SbxVariableRef Operand
// Read in of a simple term. The operands +, -, * and /
// are supported.
-static SbxVariableRef MulDiv( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode** ppBuf )
+static SbxVariableRef MulDiv( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode** ppBuf, bool bCompatible )
{
const sal_Unicode* p = *ppBuf;
- SbxVariableRef refVar( Operand( pObj, pGbl, &p, false ) );
+ SbxVariableRef refVar( Operand( pObj, pGbl, &p, false, bCompatible ) );
p = SkipWhitespace( p );
while( refVar.is() && ( *p == '*' || *p == '/' ) )
{
sal_Unicode cOp = *p++;
- SbxVariableRef refVar2( Operand( pObj, pGbl, &p, false ) );
+ SbxVariableRef refVar2( Operand( pObj, pGbl, &p, false, bCompatible ) );
if( refVar2.is() )
{
// temporary variable!
@@ -198,15 +201,15 @@ static SbxVariableRef MulDiv( SbxObject* pObj, SbxObject* pGbl, const sal_Unicod
return refVar;
}
-static SbxVariableRef PlusMinus( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode** ppBuf )
+static SbxVariableRef PlusMinus( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode** ppBuf, bool bCompatible )
{
const sal_Unicode* p = *ppBuf;
- SbxVariableRef refVar( MulDiv( pObj, pGbl, &p ) );
+ SbxVariableRef refVar( MulDiv( pObj, pGbl, &p, bCompatible ) );
p = SkipWhitespace( p );
while( refVar.is() && ( *p == '+' || *p == '-' ) )
{
sal_Unicode cOp = *p++;
- SbxVariableRef refVar2( MulDiv( pObj, pGbl, &p ) );
+ SbxVariableRef refVar2( MulDiv( pObj, pGbl, &p, bCompatible ) );
if( refVar2.is() )
{
// temporary Variable!
@@ -228,10 +231,10 @@ static SbxVariableRef PlusMinus( SbxObject* pObj, SbxObject* pGbl, const sal_Uni
return refVar;
}
-static SbxVariableRef Assign( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode** ppBuf )
+static SbxVariableRef Assign( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode** ppBuf, bool bCompatible )
{
const sal_Unicode* p = *ppBuf;
- SbxVariableRef refVar( Operand( pObj, pGbl, &p, true ) );
+ SbxVariableRef refVar( Operand( pObj, pGbl, &p, true, bCompatible ) );
p = SkipWhitespace( p );
if( refVar.is() )
{
@@ -246,7 +249,7 @@ static SbxVariableRef Assign( SbxObject* pObj, SbxObject* pGbl, const sal_Unicod
else
{
p++;
- SbxVariableRef refVar2( PlusMinus( pObj, pGbl, &p ) );
+ SbxVariableRef refVar2( PlusMinus( pObj, pGbl, &p, bCompatible ) );
if( refVar2.is() )
{
SbxVariable* pVar = refVar.get();
@@ -270,10 +273,10 @@ static SbxVariableRef Assign( SbxObject* pObj, SbxObject* pGbl, const sal_Unicod
static SbxVariableRef Element
( SbxObject* pObj, SbxObject* pGbl, const sal_Unicode** ppBuf,
- SbxClassType t )
+ SbxClassType t, bool bCompatible )
{
OUString aSym;
- const sal_Unicode* p = Symbol( *ppBuf, aSym );
+ const sal_Unicode* p = Symbol( *ppBuf, aSym, bCompatible );
SbxVariableRef refVar;
if( !aSym.isEmpty() )
{
@@ -299,7 +302,7 @@ static SbxVariableRef Element
// Search parameter always global!
while( *p && *p != ')' && *p != ']' )
{
- SbxVariableRef refArg = PlusMinus( pGbl, pGbl, &p );
+ SbxVariableRef refArg = PlusMinus( pGbl, pGbl, &p, bCompatible );
if( !refArg.is() )
{
// Error during the parsing
@@ -323,7 +326,7 @@ static SbxVariableRef Element
}
}
else
- SbxBase::SetError( ERRCODE_BASIC_NO_METHOD );
+ SbxBase::SetError( ERRCODE_BASIC_NO_METHOD, aSym );
}
*ppBuf = p;
return refVar;
@@ -346,7 +349,7 @@ SbxVariable* SbxObject::Execute( const OUString& rTxt )
{
SetError( ERRCODE_BASIC_SYNTAX ); break;
}
- pVar = Assign( this, this, &p );
+ pVar = Assign( this, this, &p, IsOptionCompatible() );
if( !pVar.is() )
{
break;
@@ -369,7 +372,7 @@ SbxVariable* SbxObject::FindQualified( const OUString& rName, SbxClassType t )
{
return nullptr;
}
- pVar = QualifiedName( this, this, &p, t );
+ pVar = QualifiedName( this, this, &p, t, IsOptionCompatible() );
p = SkipWhitespace( p );
if( *p )
{
@@ -378,4 +381,11 @@ SbxVariable* SbxObject::FindQualified( const OUString& rName, SbxClassType t )
return pVar.get();
}
+bool SbxObject::IsOptionCompatible() const
+{
+ if (const SbxObject* pObj = GetParent())
+ return pObj->IsOptionCompatible();
+ return false;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/sbx/sbxform.cxx b/basic/source/sbx/sbxform.cxx
index 0123dd076d02..d0640e71a7d6 100644
--- a/basic/source/sbx/sbxform.cxx
+++ b/basic/source/sbx/sbxform.cxx
@@ -24,6 +24,10 @@
#include <rtl/ustrbuf.hxx>
#include <rtl/character.hxx>
+#include <o3tl/sprintf.hxx>
+#include <o3tl/string_view.hxx>
+#include <string_view>
+#include <utility>
/*
TODO: are there any Star-Basic characteristics unconsidered?
@@ -58,24 +62,24 @@ COMMENT: Visual-Basic treats the following (invalid) format-strings
#define FORMAT_SEPARATOR ';'
// predefined formats for the Format$()-command:
-constexpr OUStringLiteral BASICFORMAT_GENERALNUMBER = u"General Number";
-constexpr OUStringLiteral BASICFORMAT_CURRENCY = u"Currency";
-constexpr OUStringLiteral BASICFORMAT_FIXED = u"Fixed";
-constexpr OUStringLiteral BASICFORMAT_STANDARD = u"Standard";
-constexpr OUStringLiteral BASICFORMAT_PERCENT = u"Percent";
-constexpr OUStringLiteral BASICFORMAT_SCIENTIFIC = u"Scientific";
-constexpr OUStringLiteral BASICFORMAT_YESNO = u"Yes/No";
-constexpr OUStringLiteral BASICFORMAT_TRUEFALSE = u"True/False";
-constexpr OUStringLiteral BASICFORMAT_ONOFF = u"On/Off";
+constexpr std::u16string_view BASICFORMAT_GENERALNUMBER = u"General Number";
+constexpr std::u16string_view BASICFORMAT_CURRENCY = u"Currency";
+constexpr std::u16string_view BASICFORMAT_FIXED = u"Fixed";
+constexpr std::u16string_view BASICFORMAT_STANDARD = u"Standard";
+constexpr std::u16string_view BASICFORMAT_PERCENT = u"Percent";
+constexpr std::u16string_view BASICFORMAT_SCIENTIFIC = u"Scientific";
+constexpr std::u16string_view BASICFORMAT_YESNO = u"Yes/No";
+constexpr std::u16string_view BASICFORMAT_TRUEFALSE = u"True/False";
+constexpr std::u16string_view BASICFORMAT_ONOFF = u"On/Off";
// Comment: Visual-Basic has a maximum of 12 positions after the
// decimal point for floating-point-numbers.
// all format-strings are compatible to Visual-Basic:
-constexpr OUStringLiteral GENERALNUMBER_FORMAT = u"0.############";
-constexpr OUStringLiteral FIXED_FORMAT = u"0.00";
-constexpr OUStringLiteral STANDARD_FORMAT = u"@0.00";
-constexpr OUStringLiteral PERCENT_FORMAT = u"0.00%";
-constexpr OUStringLiteral SCIENTIFIC_FORMAT = u"#.00E+00";
+constexpr OUString GENERALNUMBER_FORMAT = u"0.############"_ustr;
+constexpr OUString FIXED_FORMAT = u"0.00"_ustr;
+constexpr OUString STANDARD_FORMAT = u"@0.00"_ustr;
+constexpr OUString PERCENT_FORMAT = u"0.00%"_ustr;
+constexpr OUString SCIENTIFIC_FORMAT = u"#.00E+00"_ustr;
// Comment: the character @ means that thousand-separators shall
// be generated. That's a StarBasic 'extension'.
@@ -91,24 +95,24 @@ static double get_number_of_digits( double dNumber )
SbxBasicFormater::SbxBasicFormater( sal_Unicode _cDecPoint, sal_Unicode _cThousandSep,
- const OUString& _sOnStrg,
- const OUString& _sOffStrg,
- const OUString& _sYesStrg,
- const OUString& _sNoStrg,
- const OUString& _sTrueStrg,
- const OUString& _sFalseStrg,
- const OUString& _sCurrencyStrg,
- const OUString& _sCurrencyFormatStrg )
+ OUString _sOnStrg,
+ OUString _sOffStrg,
+ OUString _sYesStrg,
+ OUString _sNoStrg,
+ OUString _sTrueStrg,
+ OUString _sFalseStrg,
+ OUString _sCurrencyStrg,
+ OUString _sCurrencyFormatStrg )
: cDecPoint(_cDecPoint)
, cThousandSep(_cThousandSep)
- , sOnStrg(_sOnStrg)
- , sOffStrg(_sOffStrg)
- , sYesStrg(_sYesStrg)
- , sNoStrg(_sNoStrg)
- , sTrueStrg(_sTrueStrg)
- , sFalseStrg(_sFalseStrg)
- , sCurrencyStrg(_sCurrencyStrg)
- , sCurrencyFormatStrg(_sCurrencyFormatStrg)
+ , sOnStrg(std::move(_sOnStrg))
+ , sOffStrg(std::move(_sOffStrg))
+ , sYesStrg(std::move(_sYesStrg))
+ , sNoStrg(std::move(_sNoStrg))
+ , sTrueStrg(std::move(_sTrueStrg))
+ , sFalseStrg(std::move(_sFalseStrg))
+ , sCurrencyStrg(std::move(_sCurrencyStrg))
+ , sCurrencyFormatStrg(std::move(_sCurrencyFormatStrg))
, dNum(0.0)
, nNumExp(0)
, nExpExp(0)
@@ -232,17 +236,16 @@ void SbxBasicFormater::InitScan( double _dNum )
dNum = _dNum;
InitExp( get_number_of_digits( dNum ) );
// maximum of 15 positions behind the decimal point, example: -1.234000000000000E-001
- /*int nCount =*/ sprintf( sBuffer,"%+22.15lE",dNum );
+ /*int nCount =*/ o3tl::sprintf( sBuffer,"%+22.15lE",dNum );
sSciNumStrg = OUString::createFromAscii( sBuffer );
}
void SbxBasicFormater::InitExp( double _dNewExp )
{
- char sBuffer[ MAX_DOUBLE_BUFFER_LENGTH ];
nNumExp = static_cast<short>(_dNewExp);
- /*int nCount =*/ sprintf( sBuffer,"%+i",nNumExp );
- sNumExpStrg = OUString::createFromAscii( sBuffer );
+ sNumExpStrg = (nNumExp >= 0 ? std::u16string_view(u"+") : std::u16string_view(u""))
+ + OUString::number(nNumExp);
nExpExp = static_cast<short>(get_number_of_digits( static_cast<double>(nNumExp) ));
}
@@ -295,71 +298,71 @@ short SbxBasicFormater::GetDigitAtPosExpScan( double dNewExponent, short nPos,
// Copies the respective part of the format-string, if existing, and returns it.
// So a new string is created, which has to be freed by the caller later.
-OUString SbxBasicFormater::GetPosFormatString( const OUString& sFormatStrg, bool & bFound )
+OUString SbxBasicFormater::GetPosFormatString( std::u16string_view sFormatStrg, bool & bFound )
{
bFound = false; // default...
- sal_Int32 nPos = sFormatStrg.indexOf( FORMAT_SEPARATOR );
+ size_t nPos = sFormatStrg.find( FORMAT_SEPARATOR );
- if( nPos >= 0 )
+ if( nPos != std::u16string_view::npos )
{
bFound = true;
// the format-string for positive numbers is
// everything before the first ';'
- return sFormatStrg.copy( 0,nPos );
+ return OUString(sFormatStrg.substr( 0,nPos ));
}
return OUString();
}
// see also GetPosFormatString()
-OUString SbxBasicFormater::GetNegFormatString( const OUString& sFormatStrg, bool & bFound )
+OUString SbxBasicFormater::GetNegFormatString( std::u16string_view sFormatStrg, bool & bFound )
{
bFound = false; // default...
- sal_Int32 nPos = sFormatStrg.indexOf( FORMAT_SEPARATOR );
+ size_t nPos = sFormatStrg.find( FORMAT_SEPARATOR );
- if( nPos >= 0)
+ if( nPos != std::u16string_view::npos)
{
// the format-string for negative numbers is
// everything between the first and the second ';'
- OUString sTempStrg = sFormatStrg.copy( nPos+1 );
- nPos = sTempStrg.indexOf( FORMAT_SEPARATOR );
+ std::u16string_view sTempStrg = sFormatStrg.substr( nPos+1 );
+ nPos = sTempStrg.find( FORMAT_SEPARATOR );
bFound = true;
- if( nPos < 0 )
+ if( nPos == std::u16string_view::npos )
{
- return sTempStrg;
+ return OUString(sTempStrg);
}
else
{
- return sTempStrg.copy( 0,nPos );
+ return OUString(sTempStrg.substr( 0,nPos ));
}
}
return OUString();
}
// see also GetPosFormatString()
-OUString SbxBasicFormater::Get0FormatString( const OUString& sFormatStrg, bool & bFound )
+OUString SbxBasicFormater::Get0FormatString( std::u16string_view sFormatStrg, bool & bFound )
{
bFound = false; // default...
- sal_Int32 nPos = sFormatStrg.indexOf( FORMAT_SEPARATOR );
+ size_t nPos = sFormatStrg.find( FORMAT_SEPARATOR );
- if( nPos >= 0 )
+ if( nPos != std::u16string_view::npos )
{
// the format string for the zero is
// everything after the second ';'
- OUString sTempStrg = sFormatStrg.copy( nPos+1 );
- nPos = sTempStrg.indexOf( FORMAT_SEPARATOR );
- if( nPos >= 0 )
+ std::u16string_view sTempStrg = sFormatStrg.substr( nPos+1 );
+ nPos = sTempStrg.find( FORMAT_SEPARATOR );
+ if( nPos != std::u16string_view::npos )
{
bFound = true;
- sTempStrg = sTempStrg.copy( nPos+1 );
- nPos = sTempStrg.indexOf( FORMAT_SEPARATOR );
- if( nPos < 0 )
+ sTempStrg = sTempStrg.substr( nPos+1 );
+ nPos = sTempStrg.find( FORMAT_SEPARATOR );
+ if( nPos == std::u16string_view::npos )
{
- return sTempStrg;
+ return OUString(sTempStrg);
}
else
{
- return sTempStrg.copy( 0,nPos );
+ return OUString(sTempStrg.substr( 0,nPos ));
}
}
}
@@ -368,25 +371,25 @@ OUString SbxBasicFormater::Get0FormatString( const OUString& sFormatStrg, bool &
}
// see also GetPosFormatString()
-OUString SbxBasicFormater::GetNullFormatString( const OUString& sFormatStrg, bool & bFound )
+OUString SbxBasicFormater::GetNullFormatString( std::u16string_view sFormatStrg, bool & bFound )
{
bFound = false; // default...
- sal_Int32 nPos = sFormatStrg.indexOf( FORMAT_SEPARATOR );
+ size_t nPos = sFormatStrg.find( FORMAT_SEPARATOR );
- if( nPos >= 0 )
+ if( nPos != std::u16string_view::npos )
{
// the format-string for the Null is
// everything after the third ';'
- OUString sTempStrg = sFormatStrg.copy( nPos+1 );
- nPos = sTempStrg.indexOf( FORMAT_SEPARATOR );
- if( nPos >= 0 )
+ std::u16string_view sTempStrg = sFormatStrg.substr( nPos+1 );
+ nPos = sTempStrg.find( FORMAT_SEPARATOR );
+ if( nPos != std::u16string_view::npos )
{
- sTempStrg = sTempStrg.copy( nPos+1 );
- nPos = sTempStrg.indexOf( FORMAT_SEPARATOR );
- if( nPos >= 0 )
+ sTempStrg = sTempStrg.substr( nPos+1 );
+ nPos = sTempStrg.find( FORMAT_SEPARATOR );
+ if( nPos != std::u16string_view::npos )
{
bFound = true;
- return sTempStrg.copy( nPos+1 );
+ return OUString(sTempStrg.substr( nPos+1 ));
}
}
}
@@ -395,7 +398,7 @@ OUString SbxBasicFormater::GetNullFormatString( const OUString& sFormatStrg, boo
}
// returns value <> 0 in case of an error
-void SbxBasicFormater::AnalyseFormatString( const OUString& sFormatStrg,
+void SbxBasicFormater::AnalyseFormatString( std::u16string_view sFormatStrg,
short& nNoOfDigitsLeft, short& nNoOfDigitsRight,
short& nNoOfOptionalDigitsLeft,
short& nNoOfExponentDigits, short& nNoOfOptionalExponentDigits,
@@ -406,7 +409,7 @@ void SbxBasicFormater::AnalyseFormatString( const OUString& sFormatStrg,
sal_Int32 nLen;
short nState = 0;
- nLen = sFormatStrg.getLength();
+ nLen = sFormatStrg.size();
nNoOfDigitsLeft = 0;
nNoOfDigitsRight = 0;
nNoOfOptionalDigitsLeft = 0;
@@ -417,7 +420,7 @@ void SbxBasicFormater::AnalyseFormatString( const OUString& sFormatStrg,
bScientific = false;
// from 11.7.97: as soon as a comma (point?) is found in the format string,
// all three decimal powers are marked (i. e. thousand, million, ...)
- bGenerateThousandSeparator = sFormatStrg.indexOf( ',' ) >= 0;
+ bGenerateThousandSeparator = sFormatStrg.find( ',' ) != std::u16string_view::npos;
nMultipleThousandSeparators = 0;
for( sal_Int32 i = 0; i < nLen; i++ )
@@ -511,7 +514,7 @@ void SbxBasicFormater::AnalyseFormatString( const OUString& sFormatStrg,
// the flag bCreateSign says that at the mantissa a leading sign
// shall be created
void SbxBasicFormater::ScanFormatString( double dNumber,
- const OUString& sFormatStrg, OUString& sReturnStrgFinal,
+ std::u16string_view sFormatStrg, OUString& sReturnStrgFinal,
bool bCreateSign )
{
short /*nErr,*/nNoOfDigitsLeft,nNoOfDigitsRight,nNoOfOptionalDigitsLeft,
@@ -563,7 +566,7 @@ void SbxBasicFormater::ScanFormatString( double dNumber,
bSignHappend = false;
bFoundFirstDigit = false;
bIsNegative = dNumber < 0.0;
- nLen = sFormatStrg.getLength();
+ nLen = sFormatStrg.size();
dExponent = get_number_of_digits( dNumber );
nExponentPos = 0;
nMaxExponentDigit = 0;
@@ -631,8 +634,7 @@ void SbxBasicFormater::ScanFormatString( double dNumber,
{
bFirstDigit = false;
}
- // coverity[copy_paste_error : FALSE] - this is correct and nDigitPos should not be j
- if( bGenerateThousandSeparator && ( c=='0' || nMaxDigit >= nDigitPos ) && j > 0 && (j % 3 == 0) )
+ if( bGenerateThousandSeparator && c=='0' && j > 0 && (j % 3 == 0) )
{
sReturnStrg.append(cThousandSep );
}
@@ -835,12 +837,12 @@ void SbxBasicFormater::ScanFormatString( double dNumber,
if( nNoOfDigitsRight>0 )
{
- ParseBack( sReturnStrg, sFormatStrg, sFormatStrg.getLength()-1 );
+ ParseBack( sReturnStrg, sFormatStrg, sFormatStrg.size()-1 );
}
sReturnStrgFinal = sReturnStrg.makeStringAndClear();
}
-OUString SbxBasicFormater::BasicFormatNull( const OUString& sFormatStrg )
+OUString SbxBasicFormater::BasicFormatNull( std::u16string_view sFormatStrg )
{
bool bNullFormatFound;
OUString sNullFormatStrg = GetNullFormatString( sFormatStrg, bNullFormatFound );
@@ -849,7 +851,7 @@ OUString SbxBasicFormater::BasicFormatNull( const OUString& sFormatStrg )
{
return sNullFormatStrg;
}
- return "null";
+ return u"null"_ustr;
}
OUString SbxBasicFormater::BasicFormat( double dNumber, const OUString& _sFormatStrg )
@@ -957,41 +959,41 @@ OUString SbxBasicFormater::BasicFormat( double dNumber, const OUString& _sFormat
return sReturnStrg;
}
-bool SbxBasicFormater::isBasicFormat( const OUString& sFormatStrg )
+bool SbxBasicFormater::isBasicFormat( std::u16string_view sFormatStrg )
{
- if( sFormatStrg.equalsIgnoreAsciiCase( BASICFORMAT_GENERALNUMBER ) )
+ if( o3tl::equalsIgnoreAsciiCase( sFormatStrg, BASICFORMAT_GENERALNUMBER ) )
{
return true;
}
- if( sFormatStrg.equalsIgnoreAsciiCase( BASICFORMAT_CURRENCY ) )
+ if( o3tl::equalsIgnoreAsciiCase( sFormatStrg, BASICFORMAT_CURRENCY ) )
{
return true;
}
- if( sFormatStrg.equalsIgnoreAsciiCase( BASICFORMAT_FIXED ) )
+ if( o3tl::equalsIgnoreAsciiCase( sFormatStrg, BASICFORMAT_FIXED ) )
{
return true;
}
- if( sFormatStrg.equalsIgnoreAsciiCase( BASICFORMAT_STANDARD ) )
+ if( o3tl::equalsIgnoreAsciiCase( sFormatStrg, BASICFORMAT_STANDARD ) )
{
return true;
}
- if( sFormatStrg.equalsIgnoreAsciiCase( BASICFORMAT_PERCENT ) )
+ if( o3tl::equalsIgnoreAsciiCase( sFormatStrg, BASICFORMAT_PERCENT ) )
{
return true;
}
- if( sFormatStrg.equalsIgnoreAsciiCase( BASICFORMAT_SCIENTIFIC ) )
+ if( o3tl::equalsIgnoreAsciiCase( sFormatStrg, BASICFORMAT_SCIENTIFIC ) )
{
return true;
}
- if( sFormatStrg.equalsIgnoreAsciiCase( BASICFORMAT_YESNO ) )
+ if( o3tl::equalsIgnoreAsciiCase( sFormatStrg, BASICFORMAT_YESNO ) )
{
return true;
}
- if( sFormatStrg.equalsIgnoreAsciiCase( BASICFORMAT_TRUEFALSE ) )
+ if( o3tl::equalsIgnoreAsciiCase( sFormatStrg, BASICFORMAT_TRUEFALSE ) )
{
return true;
}
- if( sFormatStrg.equalsIgnoreAsciiCase( BASICFORMAT_ONOFF ) )
+ if( o3tl::equalsIgnoreAsciiCase( sFormatStrg, BASICFORMAT_ONOFF ) )
{
return true;
}
diff --git a/basic/source/sbx/sbxint.cxx b/basic/source/sbx/sbxint.cxx
index 85febcd802c2..a0693635a302 100644
--- a/basic/source/sbx/sbxint.cxx
+++ b/basic/source/sbx/sbxint.cxx
@@ -19,806 +19,266 @@
#include <sal/config.h>
-#include <o3tl/float_int_conversion.hxx>
+#include <config_features.h>
+
#include <o3tl/safeint.hxx>
-#include <vcl/errcode.hxx>
+#include <comphelper/errcode.hxx>
#include <basic/sberrors.hxx>
#include "sbxconv.hxx"
+#include <runtime.hxx>
#include <rtl/math.hxx>
-sal_Int16 ImpGetInteger( const SbxValues* p )
+namespace
+{
+template <class T>
+concept number = std::is_arithmetic_v<T>;
+
+template <SbxDataType MySbxType, number N> N ImpGet(const SbxValues* p)
{
- SbxValues aTmp;
- sal_Int16 nRes;
-start:
- switch( +p->eType )
+ switch (+p->eType)
{
- case SbxNULL:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- [[fallthrough]];
case SbxEMPTY:
- nRes = 0; break;
+ return 0;
case SbxCHAR:
- nRes = p->nChar; break;
+ return ConvertWithOverflowTo<N>(p->nChar);
+ case SbxBYREF | SbxCHAR:
+ return ConvertWithOverflowTo<N>(*p->pChar);
case SbxBYTE:
- nRes = p->nByte; break;
+ return ConvertWithOverflowTo<N>(p->nByte);
+ case SbxBYREF | SbxBYTE:
+ return ConvertWithOverflowTo<N>(*p->pByte);
case SbxINTEGER:
case SbxBOOL:
- nRes = p->nInteger; break;
+ return ConvertWithOverflowTo<N>(p->nInteger);
+ case SbxBYREF | SbxINTEGER:
+ case SbxBYREF | SbxBOOL:
+ return ConvertWithOverflowTo<N>(*p->pInteger);
case SbxERROR:
case SbxUSHORT:
- if( p->nUShort > o3tl::make_unsigned(SbxMAXINT) )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXINT;
- }
- else
- nRes = static_cast<sal_Int16>(p->nUShort);
- break;
+ return ConvertWithOverflowTo<N>(p->nUShort);
+ case SbxBYREF | SbxERROR:
+ case SbxBYREF | SbxUSHORT:
+ return ConvertWithOverflowTo<N>(*p->pUShort);
case SbxLONG:
- if( p->nLong > SbxMAXINT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXINT;
- }
- else if( p->nLong < SbxMININT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMININT;
- }
- else
- nRes = static_cast<sal_Int16>(p->nLong);
- break;
+ return ConvertWithOverflowTo<N>(p->nLong);
+ case SbxBYREF | SbxLONG:
+ return ConvertWithOverflowTo<N>(*p->pLong);
case SbxULONG:
- if( p->nULong > SbxMAXINT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXINT;
- }
- else
- nRes = static_cast<sal_Int16>(p->nULong);
- break;
- case SbxSINGLE:
- nRes = ImpDoubleToInteger(p->nSingle);
- break;
+ return ConvertWithOverflowTo<N>(p->nULong);
+ case SbxBYREF | SbxULONG:
+ return ConvertWithOverflowTo<N>(*p->pULong);
case SbxCURRENCY:
- {
- sal_Int64 tstVal = p->nInt64 / sal_Int64(CURRENCY_FACTOR);
-
- if( tstVal > SbxMAXINT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXINT;
- }
- else if( tstVal < SbxMININT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMININT;
- }
- else
- nRes = static_cast<sal_Int16>(tstVal);
- break;
- }
+ return CurTo<N>(p->nInt64);
+ case SbxBYREF | SbxCURRENCY:
+ return CurTo<N>(*p->pnInt64);
case SbxSALINT64:
- if( p->nInt64 > SbxMAXINT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXINT;
- }
- else if( p->nInt64 < SbxMININT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMININT;
- }
- else
- nRes = static_cast<sal_Int16>(p->nInt64);
- break;
+ return ConvertWithOverflowTo<N>(p->nInt64);
+ case SbxBYREF | SbxSALINT64:
+ return ConvertWithOverflowTo<N>(*p->pnInt64);
case SbxSALUINT64:
- if( p->uInt64 > SbxMAXINT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXINT;
- }
- else
- nRes = static_cast<sal_Int16>(p->uInt64);
- break;
+ return ConvertWithOverflowTo<N>(p->uInt64);
+ case SbxBYREF | SbxSALUINT64:
+ return ConvertWithOverflowTo<N>(*p->puInt64);
+ case SbxSINGLE:
+ return ConvertWithOverflowTo<N>(p->nSingle);
+ case SbxBYREF | SbxSINGLE:
+ return ConvertWithOverflowTo<N>(*p->pSingle);
case SbxDATE:
case SbxDOUBLE:
+ return ConvertWithOverflowTo<N>(p->nDouble);
+ case SbxBYREF | SbxDATE:
+ case SbxBYREF | SbxDOUBLE:
+ return ConvertWithOverflowTo<N>(*p->pDouble);
case SbxDECIMAL:
case SbxBYREF | SbxDECIMAL:
- {
- double dVal = 0.0;
- if( p->eType == SbxDECIMAL )
- {
- if( p->pDecimal )
- p->pDecimal->getDouble( dVal );
- }
- else
- dVal = p->nDouble;
-
- nRes = ImpDoubleToInteger(dVal);
- break;
- }
- case SbxLPSTR:
- case SbxSTRING:
+ if (p->pDecimal)
+ return p->pDecimal->getWithOverflow<N>();
+ return 0;
case SbxBYREF | SbxSTRING:
- if( !p->pOUString )
- nRes = 0;
- else
+ case SbxSTRING:
+ case SbxLPSTR:
+ if (p->pOUString)
{
double d;
SbxDataType t;
- if( ImpScan( *p->pOUString, d, t, nullptr, true ) != ERRCODE_NONE )
- nRes = 0;
- else
- nRes = ImpDoubleToInteger(d);
- }
- break;
+ if (ImpScan(*p->pOUString, d, t, nullptr) == ERRCODE_NONE)
+ return ConvertWithOverflowTo<N>(d);
+ }
+#if HAVE_FEATURE_SCRIPTING
+ if (SbiRuntime::isVBAEnabled()) // VBA only behaviour
+ SbxBase::SetError(ERRCODE_BASIC_CONVERSION);
+#endif
+ return 0;
case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
- nRes = pVal->GetInteger();
- else
+ if (SbxValue* pVal = dynamic_cast<SbxValue*>(p->pObj))
{
- SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT ); nRes = 0;
+ SbxValues aObjVal(MySbxType);
+ pVal->Get(aObjVal);
+ return ImpGet<MySbxType, N>(&aObjVal);
}
- break;
- }
-
- case SbxBYREF | SbxCHAR:
- nRes = *p->pChar; break;
- case SbxBYREF | SbxBYTE:
- nRes = *p->pByte; break;
- case SbxBYREF | SbxINTEGER:
- case SbxBYREF | SbxBOOL:
- nRes = *p->pInteger; break;
-
- // from here had to be tested
- case SbxBYREF | SbxLONG:
- aTmp.nLong = *p->pLong; goto ref;
- case SbxBYREF | SbxULONG:
- aTmp.nULong = *p->pULong; goto ref;
- case SbxBYREF | SbxERROR:
- case SbxBYREF | SbxUSHORT:
- aTmp.nUShort = *p->pUShort; goto ref;
- case SbxBYREF | SbxSINGLE:
- aTmp.nSingle = *p->pSingle; goto ref;
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- aTmp.nDouble = *p->pDouble; goto ref;
- case SbxBYREF | SbxCURRENCY:
- case SbxBYREF | SbxSALINT64:
- aTmp.nInt64 = *p->pnInt64; goto ref;
- case SbxBYREF | SbxSALUINT64:
- aTmp.uInt64 = *p->puInt64; goto ref;
- ref:
- aTmp.eType = SbxDataType( p->eType & 0x0FFF );
- p = &aTmp; goto start;
+ SbxBase::SetError(ERRCODE_BASIC_NO_OBJECT);
+ return 0;
default:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION ); nRes = 0;
+ SbxBase::SetError(ERRCODE_BASIC_CONVERSION);
+ return 0;
}
- return nRes;
}
-void ImpPutInteger( SbxValues* p, sal_Int16 n )
+template <typename T> void assignTo(SbxDecimal& dest, T n); // not defined
+template <> void assignTo<sal_uInt8>(SbxDecimal& dest, sal_uInt8 n) { dest.setByte(n); }
+template <> void assignTo<sal_Unicode>(SbxDecimal& dest, sal_Unicode n) { dest.setChar(n); }
+template <> void assignTo<sal_Int16>(SbxDecimal& dest, sal_Int16 n) { dest.setShort(n); }
+template <> void assignTo<sal_uInt16>(SbxDecimal& dest, sal_uInt16 n) { dest.setUShort(n); }
+template <> void assignTo<sal_Int32>(SbxDecimal& dest, sal_Int32 n) { dest.setLong(n); }
+template <> void assignTo<sal_uInt32>(SbxDecimal& dest, sal_uInt32 n) { dest.setULong(n); }
+template <> void assignTo<sal_Int64>(SbxDecimal& dest, sal_Int64 n) { dest.setWithOverflow(n); }
+template <> void assignTo<sal_uInt64>(SbxDecimal& dest, sal_uInt64 n) { dest.setWithOverflow(n); }
+template <> void assignTo<double>(SbxDecimal& dest, double n) { dest.setWithOverflow(n); }
+template <> void assignTo<float>(SbxDecimal& dest, float n) { dest.setWithOverflow(n); }
+
+template <std::integral I> void assignTo(OUString& dest, I n, bool) { dest = OUString::number(n); }
+void assignTo(OUString& dest, double n, bool bCoreString)
{
- SbxValues aTmp;
-start:
- switch( +p->eType )
- {
- // here had to be tested
- case SbxCHAR:
- aTmp.pChar = &p->nChar; goto direct;
- case SbxBYTE:
- aTmp.pByte = &p->nByte; goto direct;
- case SbxULONG:
- aTmp.pULong = &p->nULong; goto direct;
- case SbxERROR:
- case SbxUSHORT:
- aTmp.pUShort = &p->nUShort; goto direct;
- case SbxSALUINT64:
- aTmp.puInt64 = &p->uInt64; goto direct;
- direct:
- aTmp.eType = SbxDataType( p->eType | SbxBYREF );
- p = &aTmp; goto start;
-
- // from here no tests needed
- case SbxINTEGER:
- case SbxBOOL:
- p->nInteger = n; break;
- case SbxLONG:
- p->nLong = n; break;
- case SbxSINGLE:
- p->nSingle = n; break;
- case SbxDATE:
- case SbxDOUBLE:
- p->nDouble = n; break;
- case SbxCURRENCY:
- p->nInt64 = n * CURRENCY_FACTOR; break;
- case SbxSALINT64:
- p->nInt64 = n; break;
- case SbxDECIMAL:
- case SbxBYREF | SbxDECIMAL:
- ImpCreateDecimal( p )->setInt( n );
- break;
-
- case SbxLPSTR:
- case SbxSTRING:
- case SbxBYREF | SbxSTRING:
- if( !p->pOUString )
- p->pOUString = new OUString;
- ImpCvtNum( static_cast<double>(n), 0, *p->pOUString );
- break;
- case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
- pVal->PutInteger( n );
- else
- SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT );
- break;
- }
- case SbxBYREF | SbxCHAR:
- if( n < SbxMINCHAR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMINCHAR;
- }
- *p->pChar = static_cast<char>(n); break;
- case SbxBYREF | SbxBYTE:
- if( n > SbxMAXBYTE )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXBYTE;
- }
- else if( n < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = 0;
- }
- *p->pByte = static_cast<sal_uInt8>(n); break;
- case SbxBYREF | SbxINTEGER:
- case SbxBYREF | SbxBOOL:
- *p->pInteger = n; break;
- case SbxBYREF | SbxERROR:
- case SbxBYREF | SbxUSHORT:
- if( n < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = 0;
- }
- *p->pUShort = static_cast<sal_uInt16>(n); break;
- case SbxBYREF | SbxLONG:
- *p->pLong = static_cast<sal_Int32>(n); break;
- case SbxBYREF | SbxULONG:
- if( n < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = 0;
- }
- *p->pULong = static_cast<sal_uInt32>(n); break;
- case SbxBYREF | SbxCURRENCY:
- *p->pnInt64 = n * CURRENCY_FACTOR; break;
- case SbxBYREF | SbxSALINT64:
- *p->pnInt64 = n; break;
- case SbxBYREF | SbxSALUINT64:
- if( n < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- *p->puInt64 = 0;
- }
- else
- *p->puInt64 = n;
- break;
- case SbxBYREF | SbxSINGLE:
- *p->pSingle = static_cast<float>(n); break;
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- *p->pDouble = static_cast<double>(n); break;
-
- default:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- }
+ // tdf#107953 - show 17 significant digits
+ ImpCvtNum(n, 17, dest, bCoreString);
}
-
-
-// sal_Int64 / hyper
-
-double ImpSalUInt64ToDouble( sal_uInt64 n )
+void assignTo(OUString& dest, float n, bool)
{
- double d = 0.0;
- if( n > SAL_MAX_INT64 )
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- else
- d = static_cast<double>(static_cast<sal_Int64>(n));
- return d;
+ // tdf#107953 - show 9 significant digits
+ ImpCvtNum(n, 9, dest);
}
-
-sal_Int64 ImpGetInt64( const SbxValues* p )
+template <SbxDataType MySbxType, number N> void ImpPut(SbxValues* p, N n, bool bCoreString)
{
- SbxValues aTmp;
- sal_Int64 nRes;
-start:
- switch( +p->eType )
+ switch (+p->eType)
{
- case SbxNULL:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- [[fallthrough]];
- case SbxEMPTY:
- nRes = 0; break;
case SbxCHAR:
- nRes = p->nChar; break;
- case SbxBYTE:
- nRes = p->nByte; break;
- case SbxINTEGER:
- case SbxBOOL:
- nRes = p->nInteger; break;
- case SbxERROR:
- case SbxUSHORT:
- nRes = static_cast<sal_Int64>(p->nUShort); break;
- case SbxLONG:
- nRes = static_cast<sal_Int64>(p->nLong); break;
- case SbxULONG:
- nRes = static_cast<sal_Int64>(p->nULong); break;
- case SbxSINGLE:
- nRes = ImpDoubleToSalInt64(p->nSingle);
+ assignWithOverflowTo(p->nChar, n);
break;
- case SbxDATE:
- case SbxDOUBLE:
- nRes = ImpDoubleToSalInt64(p->nDouble);
+ case SbxBYREF | SbxCHAR:
+ assignWithOverflowTo(*p->pChar, n);
break;
- case SbxCURRENCY:
- nRes = p->nInt64 / CURRENCY_FACTOR; break;
- case SbxSALINT64:
- nRes = p->nInt64; break;
- case SbxSALUINT64:
- if( p->uInt64 > SAL_MAX_INT64 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SAL_MAX_INT64;
- }
- else
- nRes = static_cast<sal_Int64>(p->uInt64);
+ case SbxBYTE:
+ assignWithOverflowTo(p->nByte, n);
break;
-
- case SbxBYREF | SbxSTRING:
- case SbxSTRING:
- case SbxLPSTR:
- if( !p->pOUString )
- nRes = 0;
- else
- {
- nRes = p->pOUString->toInt64();
- if( nRes == 0 )
- {
- // Check if really 0 or invalid conversion
- double d;
- SbxDataType t;
- if( ImpScan( *p->pOUString, d, t, nullptr, true ) != ERRCODE_NONE )
- nRes = 0;
- else
- nRes = ImpDoubleToSalInt64(d);
- }
- }
+ case SbxBYREF | SbxBYTE:
+ assignWithOverflowTo(*p->pByte, n);
break;
- case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
- nRes = pVal->GetInt64();
- else
- {
- SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT ); nRes = 0;
- }
+ case SbxINTEGER:
+ case SbxBOOL:
+ assignWithOverflowTo(p->nInteger, n);
break;
- }
-
- case SbxBYREF | SbxCHAR:
- nRes = *p->pChar; break;
- case SbxBYREF | SbxBYTE:
- nRes = *p->pByte; break;
case SbxBYREF | SbxINTEGER:
case SbxBYREF | SbxBOOL:
- nRes = *p->pInteger; break;
- case SbxBYREF | SbxLONG:
- nRes = *p->pLong; break;
- case SbxBYREF | SbxULONG:
- nRes = *p->pULong; break;
- case SbxBYREF | SbxCURRENCY:
- nRes = p->nInt64 / CURRENCY_FACTOR; break;
- case SbxBYREF | SbxSALINT64:
- nRes = *p->pnInt64; break;
-
- // from here the values has to be checked
- case SbxBYREF | SbxSALUINT64:
- aTmp.uInt64 = *p->puInt64; goto ref;
-
- case SbxBYREF | SbxERROR:
- case SbxBYREF | SbxUSHORT:
- aTmp.nUShort = *p->pUShort; goto ref;
- case SbxBYREF | SbxSINGLE:
- aTmp.nSingle = *p->pSingle; goto ref;
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- aTmp.nDouble = *p->pDouble; goto ref;
- ref:
- aTmp.eType = SbxDataType( p->eType & 0x0FFF );
- p = &aTmp; goto start;
-
- default:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION ); nRes = 0;
- }
- return nRes;
-}
-
-void ImpPutInt64( SbxValues* p, sal_Int64 n )
-{
- SbxValues aTmp;
-
-start:
- switch( +p->eType )
- {
- // Check necessary
- case SbxCHAR:
- aTmp.pChar = &p->nChar; goto direct;
- case SbxBYTE:
- aTmp.pByte = &p->nByte; goto direct;
- case SbxINTEGER:
- case SbxBOOL:
- aTmp.pInteger = &p->nInteger; goto direct;
- case SbxULONG:
- aTmp.pULong = &p->nULong; goto direct;
+ assignWithOverflowTo(*p->pInteger, n);
+ break;
case SbxERROR:
case SbxUSHORT:
- aTmp.pUShort = &p->nUShort; goto direct;
- case SbxLONG:
- aTmp.pnInt64 = &p->nInt64; goto direct;
- case SbxCURRENCY:
- case SbxSALINT64:
- aTmp.pnInt64 = &p->nInt64; goto direct;
- case SbxSALUINT64:
- aTmp.puInt64 = &p->uInt64; goto direct;
-
- direct:
- aTmp.eType = SbxDataType( p->eType | SbxBYREF );
- p = &aTmp; goto start;
-
- case SbxSINGLE:
- p->nSingle = static_cast<float>(n); break;
- case SbxDATE:
- case SbxDOUBLE:
- p->nDouble = static_cast<double>(n); break;
-
- case SbxBYREF | SbxSTRING:
- case SbxSTRING:
- case SbxLPSTR:
- {
- if( !p->pOUString )
- p->pOUString = new OUString;
-
- ::OString aOStr = OString::number( n );
- (*p->pOUString) = ::OStringToOUString( aOStr, RTL_TEXTENCODING_ASCII_US );
- break;
- }
- case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
- pVal->PutInt64( n );
- else
- SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT );
+ assignWithOverflowTo(p->nUShort, n);
break;
- }
- case SbxBYREF | SbxCHAR:
- if( n > SbxMAXCHAR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXCHAR;
- }
- else if( n < SbxMINCHAR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMINCHAR;
- }
- *p->pChar = static_cast<sal_Unicode>(n); break;
- case SbxBYREF | SbxBYTE:
- if( n > SbxMAXBYTE )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXBYTE;
- }
- else if( n < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = 0;
- }
- *p->pByte = static_cast<sal_uInt8>(n); break;
- case SbxBYREF | SbxINTEGER:
- case SbxBYREF | SbxBOOL:
- if( n > SbxMAXINT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXINT;
- }
- else if( n < SbxMININT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMININT;
- }
- *p->pInteger = static_cast<sal_Int16>(n); break;
case SbxBYREF | SbxERROR:
case SbxBYREF | SbxUSHORT:
- if( n > SbxMAXUINT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXUINT;
- }
- else if( n < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = 0;
- }
- *p->pUShort = static_cast<sal_uInt16>(n); break;
- case SbxBYREF | SbxLONG:
- if( n > SbxMAXLNG )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXLNG;
- }
- else if( n < SbxMINLNG )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMINLNG;
- }
- *p->pLong = static_cast<sal_Int32>(n); break;
- case SbxBYREF | SbxULONG:
- if( n > SbxMAXULNG )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXULNG;
- }
- else if( n < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = 0;
- }
- *p->pULong = static_cast<sal_uInt32>(n); break;
- case SbxBYREF | SbxSINGLE:
- *p->pSingle = static_cast<float>(n); break;
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- *p->pDouble = static_cast<double>(n); break;
- case SbxBYREF | SbxCURRENCY:
- *p->pnInt64 = n * CURRENCY_FACTOR; break;
- case SbxBYREF | SbxSALINT64:
- *p->pnInt64 = n; break;
- case SbxBYREF | SbxSALUINT64:
- if( n < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = 0;
- }
- *p->puInt64 = n; break;
-
- default:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- }
-}
-
-sal_uInt64 ImpGetUInt64( const SbxValues* p )
-{
- SbxValues aTmp;
- sal_uInt64 nRes;
-start:
- switch( +p->eType )
- {
- case SbxNULL:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- [[fallthrough]];
- case SbxEMPTY:
- nRes = 0; break;
- case SbxCHAR:
- nRes = p->nChar; break;
- case SbxBYTE:
- nRes = p->nByte; break;
- case SbxINTEGER:
- case SbxBOOL:
- nRes = p->nInteger; break;
- case SbxERROR:
- case SbxUSHORT:
- nRes = p->nUShort; break;
+ assignWithOverflowTo(*p->pUShort, n);
+ break;
case SbxLONG:
- nRes = p->nLong; break;
+ assignWithOverflowTo(p->nLong, n);
+ break;
+ case SbxBYREF | SbxLONG:
+ assignWithOverflowTo(*p->pLong, n);
+ break;
case SbxULONG:
- nRes = static_cast<sal_uInt64>(p->nULong); break;
- case SbxSINGLE:
- nRes = ImpDoubleToSalUInt64(p->nSingle); break;
- case SbxDATE:
- case SbxDOUBLE:
- nRes = ImpDoubleToSalUInt64(p->nDouble);
+ assignWithOverflowTo(p->nULong, n);
+ break;
+ case SbxBYREF | SbxULONG:
+ assignWithOverflowTo(*p->pULong, n);
break;
case SbxCURRENCY:
- nRes = p->nInt64 * CURRENCY_FACTOR; break;
+ assignWithOverflowTo(p->nInt64, CurFrom(n));
+ break;
+ case SbxBYREF | SbxCURRENCY:
+ assignWithOverflowTo(*p->pnInt64, CurFrom(n));
+ break;
case SbxSALINT64:
- if( p->nInt64 < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = 0;
- }
- else
- nRes = static_cast<sal_uInt64>(p->nInt64);
+ assignWithOverflowTo(p->nInt64, n);
+ break;
+ case SbxBYREF | SbxSALINT64:
+ assignWithOverflowTo(*p->pnInt64, n);
break;
case SbxSALUINT64:
- nRes = p->uInt64; break;
-
- case SbxBYREF | SbxSTRING:
- case SbxSTRING:
- case SbxLPSTR:
- if( !p->pOUString )
- nRes = 0;
- else
- {
- nRes = p->pOUString->toUInt64();
- if( nRes == 0 )
- {
- // Check if really 0 or invalid conversion
- double d;
- SbxDataType t;
- if( ImpScan( *p->pOUString, d, t, nullptr, true ) != ERRCODE_NONE )
- nRes = 0;
- else
- nRes = ImpDoubleToSalUInt64(d);
- }
- }
+ assignWithOverflowTo(p->uInt64, n);
break;
- case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
- nRes = pVal->GetUInt64();
- else
- {
- SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT ); nRes = 0;
- }
+ case SbxBYREF | SbxSALUINT64:
+ assignWithOverflowTo(*p->puInt64, n);
break;
- }
- case SbxBYREF | SbxCHAR:
- nRes = *p->pChar; break;
- case SbxBYREF | SbxBYTE:
- nRes = *p->pByte; break;
- case SbxBYREF | SbxINTEGER:
- case SbxBYREF | SbxBOOL:
- nRes = *p->pInteger; break;
- case SbxBYREF | SbxLONG:
- nRes = *p->pLong; break;
- case SbxBYREF | SbxULONG:
- nRes = *p->pULong; break;
- case SbxBYREF | SbxSALUINT64:
- nRes = *p->puInt64; break;
+ case SbxDECIMAL:
+ case SbxBYREF | SbxDECIMAL:
+ assignTo(*ImpCreateDecimal(p), n);
+ break;
- // from here on the value has to be checked
- case SbxBYREF | SbxERROR:
- case SbxBYREF | SbxUSHORT:
- aTmp.nUShort = *p->pUShort; goto ref;
+ case SbxSINGLE:
+ assignWithOverflowTo(p->nSingle, n);
+ break;
case SbxBYREF | SbxSINGLE:
- aTmp.nSingle = *p->pSingle; goto ref;
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- aTmp.nDouble = *p->pDouble; goto ref;
- case SbxBYREF | SbxCURRENCY:
- case SbxBYREF | SbxSALINT64:
- aTmp.nInt64 = *p->pnInt64; goto ref;
- ref:
- aTmp.eType = SbxDataType( p->eType & 0x0FFF );
- p = &aTmp; goto start;
-
- default:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION ); nRes = 0;
- }
- return nRes;
-}
-
-void ImpPutUInt64( SbxValues* p, sal_uInt64 n )
-{
- SbxValues aTmp;
+ assignWithOverflowTo(*p->pSingle, n);
+ break;
-start:
- switch( +p->eType )
- {
- // Check necessary
- case SbxCHAR:
- aTmp.pChar = &p->nChar; goto direct;
- case SbxBYTE:
- aTmp.pByte = &p->nByte; goto direct;
- case SbxINTEGER:
- case SbxBOOL:
- aTmp.pInteger = &p->nInteger; goto direct;
- case SbxULONG:
- aTmp.pULong = &p->nULong; goto direct;
- case SbxERROR:
- case SbxUSHORT:
- aTmp.pUShort = &p->nUShort; goto direct;
- case SbxLONG:
- aTmp.pnInt64 = &p->nInt64; goto direct;
- case SbxCURRENCY:
- case SbxSALINT64:
- aTmp.pnInt64 = &p->nInt64; goto direct;
- case SbxSINGLE:
- aTmp.pSingle = &p->nSingle; goto direct;
case SbxDATE:
case SbxDOUBLE:
- aTmp.pDouble = &p->nDouble; goto direct;
-
- direct:
- aTmp.eType = SbxDataType( p->eType | SbxBYREF );
- p = &aTmp; goto start;
-
- // Check not necessary
- case SbxSALUINT64:
- p->uInt64 = n; break;
+ assignWithOverflowTo(p->nDouble, n);
+ break;
+ case SbxBYREF | SbxDATE:
+ case SbxBYREF | SbxDOUBLE:
+ assignWithOverflowTo(*p->pDouble, n);
+ break;
case SbxBYREF | SbxSTRING:
case SbxSTRING:
case SbxLPSTR:
- if( !p->pOUString )
+ if (!p->pOUString)
p->pOUString = new OUString;
- if( n > SAL_MAX_INT64 )
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- else
- {
- ::OString aOStr = OString::number( n );
- (*p->pOUString) = ::OStringToOUString( aOStr, RTL_TEXTENCODING_ASCII_US );
- }
- break;
- case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
- pVal->PutUInt64( n );
- else
- SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT );
+ assignTo(*p->pOUString, n, bCoreString);
break;
- }
- case SbxBYREF | SbxCHAR:
- if( n > SbxMAXCHAR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXCHAR;
- }
- *p->pChar = static_cast<sal_Unicode>(n); break;
- case SbxBYREF | SbxBYTE:
- if( n > SbxMAXBYTE )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXBYTE;
- }
- *p->pByte = static_cast<sal_uInt8>(n); break;
- case SbxBYREF | SbxINTEGER:
- case SbxBYREF | SbxBOOL:
- if( n > SbxMAXINT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXINT;
- }
- *p->pInteger = static_cast<sal_Int16>(n); break;
- case SbxBYREF | SbxERROR:
- case SbxBYREF | SbxUSHORT:
- if( n > SbxMAXUINT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXUINT;
- }
- *p->pUShort = static_cast<sal_uInt16>(n); break;
- case SbxBYREF | SbxLONG:
- if( n > SbxMAXLNG )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXLNG;
- }
- *p->pLong = static_cast<sal_Int32>(n); break;
- case SbxBYREF | SbxULONG:
- if( n > SbxMAXULNG )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXULNG;
- }
- *p->pULong = static_cast<sal_uInt32>(n); break;
- case SbxBYREF | SbxSINGLE:
- *p->pDouble = static_cast<float>(ImpSalUInt64ToDouble( n )); break;
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- *p->pDouble = ImpSalUInt64ToDouble( n ); break;
- case SbxBYREF | SbxCURRENCY:
- if ( n > ( SAL_MAX_INT64 / CURRENCY_FACTOR ) )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- n = SAL_MAX_INT64;
- }
- *p->pnInt64 = static_cast<sal_Int64>( n * CURRENCY_FACTOR ); break;
- case SbxBYREF | SbxSALUINT64:
- *p->puInt64 = n; break;
- case SbxBYREF | SbxSALINT64:
- if( n > SAL_MAX_INT64 )
+ case SbxOBJECT:
+ if (SbxValue* pVal = dynamic_cast<SbxValue*>(p->pObj))
{
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = 0;
+ SbxValues newVal(MySbxType);
+ ImpPut<MySbxType, N>(&newVal, n, bCoreString);
+ pVal->Put(newVal);
}
- *p->pnInt64 = static_cast<sal_Int64>(n); break;
+ else
+ SbxBase::SetError(ERRCODE_BASIC_NO_OBJECT);
+ break;
default:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
+ SbxBase::SetError(ERRCODE_BASIC_CONVERSION);
}
}
+}
+sal_Unicode ImpGetChar(const SbxValues* p) { return ImpGet<SbxCHAR, sal_Unicode>(p); }
+sal_uInt8 ImpGetByte(const SbxValues* p) { return ImpGet<SbxBYTE, sal_uInt8>(p); }
+sal_Int16 ImpGetInteger(const SbxValues* p) { return ImpGet<SbxINTEGER, sal_Int16>(p); }
+sal_uInt16 ImpGetUShort(const SbxValues* p) { return ImpGet<SbxUSHORT, sal_uInt16>(p); }
+sal_Int32 ImpGetLong(const SbxValues* p) { return ImpGet<SbxLONG, sal_Int32>(p); }
+sal_uInt32 ImpGetULong(const SbxValues* p) { return ImpGet<SbxULONG, sal_uInt32>(p); }
+sal_Int64 ImpGetInt64(const SbxValues* p) { return ImpGet<SbxSALINT64, sal_Int64>(p); }
+sal_uInt64 ImpGetUInt64(const SbxValues* p) { return ImpGet<SbxSALUINT64, sal_uInt64>(p); }
+double ImpGetDouble(const SbxValues* p) { return ImpGet<SbxDOUBLE, double>(p); }
+float ImpGetSingle(const SbxValues* p) { return ImpGet<SbxSINGLE, float>(p); }
+
+void ImpPutChar(SbxValues* p, sal_Unicode n) { ImpPut<SbxCHAR>(p, n, false); }
+void ImpPutByte(SbxValues* p, sal_uInt8 n) { ImpPut<SbxBYTE>(p, n, false); }
+void ImpPutInteger(SbxValues* p, sal_Int16 n) { ImpPut<SbxINTEGER>(p, n, false); }
+void ImpPutUShort(SbxValues* p, sal_uInt16 n) { ImpPut<SbxUSHORT>(p, n, false); }
+void ImpPutLong(SbxValues* p, sal_Int32 n) { ImpPut<SbxLONG>(p, n, false); }
+void ImpPutULong(SbxValues* p, sal_uInt32 n) { ImpPut<SbxULONG>(p, n, false); }
+void ImpPutInt64(SbxValues* p, sal_Int64 n) { ImpPut<SbxSALINT64>(p, n, false); }
+void ImpPutUInt64(SbxValues* p, sal_uInt64 n) { ImpPut<SbxSALUINT64>(p, n, false); }
+void ImpPutDouble(SbxValues* p, double n, bool bCoreString) { ImpPut<SbxDOUBLE>(p, n, bCoreString); }
+void ImpPutSingle(SbxValues* p, float n) { ImpPut<SbxSINGLE>(p, n, false); }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/sbx/sbxlng.cxx b/basic/source/sbx/sbxlng.cxx
deleted file mode 100644
index 915cf861025f..000000000000
--- a/basic/source/sbx/sbxlng.cxx
+++ /dev/null
@@ -1,292 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include <sal/config.h>
-
-#include <o3tl/float_int_conversion.hxx>
-#include <vcl/errcode.hxx>
-#include <basic/sberrors.hxx>
-#include "sbxconv.hxx"
-
-#include <rtl/math.hxx>
-
-sal_Int32 ImpGetLong( const SbxValues* p )
-{
- SbxValues aTmp;
- sal_Int32 nRes;
-start:
- switch( +p->eType )
- {
- case SbxNULL:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- [[fallthrough]];
- case SbxEMPTY:
- nRes = 0; break;
- case SbxCHAR:
- nRes = p->nChar; break;
- case SbxBYTE:
- nRes = p->nByte; break;
- case SbxINTEGER:
- case SbxBOOL:
- nRes = p->nInteger; break;
- case SbxERROR:
- case SbxUSHORT:
- nRes = p->nUShort; break;
- case SbxLONG:
- nRes = p->nLong; break;
- case SbxULONG:
- if( p->nULong > SbxMAXLNG )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXLNG;
- }
- else
- nRes = static_cast<sal_Int32>(p->nULong);
- break;
- case SbxSINGLE:
- nRes = ImpDoubleToLong(p->nSingle);
- break;
- case SbxSALINT64:
- nRes = p->nInt64;
- break;
- case SbxSALUINT64:
- nRes = p->uInt64;
- break;
- case SbxCURRENCY:
- {
- sal_Int64 tstVal = p->nInt64 / CURRENCY_FACTOR;
- nRes = static_cast<sal_Int32>(tstVal);
- if( tstVal < SbxMINLNG || SbxMAXLNG < tstVal ) SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- if( SbxMAXLNG < tstVal ) nRes = SbxMAXLNG;
- if( tstVal < SbxMINLNG ) nRes = SbxMINLNG;
- break;
- }
- case SbxDATE:
- case SbxDOUBLE:
- case SbxDECIMAL:
- case SbxBYREF | SbxDECIMAL:
- {
- double dVal;
- if( p->eType == SbxDECIMAL )
- {
- dVal = 0.0;
- if( p->pDecimal )
- p->pDecimal->getDouble( dVal );
- }
- else
- dVal = p->nDouble;
-
- nRes = ImpDoubleToLong(dVal);
- break;
- }
- case SbxBYREF | SbxSTRING:
- case SbxSTRING:
- case SbxLPSTR:
- if( !p->pOUString )
- nRes = 0;
- else
- {
- double d;
- SbxDataType t;
- if( ImpScan( *p->pOUString, d, t, nullptr, true ) != ERRCODE_NONE )
- nRes = 0;
- else
- nRes = ImpDoubleToLong(d);
- }
- break;
- case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
- nRes = pVal->GetLong();
- else
- {
- SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT ); nRes = 0;
- }
- break;
- }
-
- case SbxBYREF | SbxCHAR:
- nRes = *p->pChar; break;
- case SbxBYREF | SbxBYTE:
- nRes = *p->pByte; break;
- case SbxBYREF | SbxINTEGER:
- case SbxBYREF | SbxBOOL:
- nRes = *p->pInteger; break;
- case SbxBYREF | SbxLONG:
- nRes = *p->pLong; break;
-
- // from here had to be tested
- case SbxBYREF | SbxULONG:
- aTmp.nULong = *p->pULong; goto ref;
- case SbxBYREF | SbxERROR:
- case SbxBYREF | SbxUSHORT:
- aTmp.nUShort = *p->pUShort; goto ref;
- case SbxBYREF | SbxSINGLE:
- aTmp.nSingle = *p->pSingle; goto ref;
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- aTmp.nDouble = *p->pDouble; goto ref;
- case SbxBYREF | SbxCURRENCY:
- case SbxBYREF | SbxSALINT64:
- aTmp.nInt64 = *p->pnInt64; goto ref;
- case SbxBYREF | SbxSALUINT64:
- aTmp.uInt64 = *p->puInt64; goto ref;
-
- ref:
- aTmp.eType = SbxDataType( p->eType & 0x0FFF );
- p = &aTmp; goto start;
-
- default:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION ); nRes = 0;
- }
- return nRes;
-}
-
-void ImpPutLong( SbxValues* p, sal_Int32 n )
-{
- SbxValues aTmp;
-
-start:
- switch( +p->eType )
- {
- // From here had to be tested
- case SbxCHAR:
- aTmp.pChar = &p->nChar; goto direct;
- case SbxBYTE:
- aTmp.pByte = &p->nByte; goto direct;
- case SbxINTEGER:
- case SbxBOOL:
- aTmp.pInteger = &p->nInteger; goto direct;
- case SbxULONG:
- aTmp.pULong = &p->nULong; goto direct;
- case SbxSALUINT64:
- aTmp.puInt64 = &p->uInt64; goto direct;
- case SbxERROR:
- case SbxUSHORT:
- aTmp.pUShort = &p->nUShort;
- direct:
- aTmp.eType = SbxDataType( p->eType | SbxBYREF );
- p = &aTmp; goto start;
-
- // from here no longer
- case SbxLONG:
- p->nLong = n; break;
- case SbxSINGLE:
- p->nSingle = static_cast<float>(n); break;
- case SbxDATE:
- case SbxDOUBLE:
- p->nDouble = n; break;
- case SbxCURRENCY:
- p->nInt64 = n * CURRENCY_FACTOR; break;
- case SbxSALINT64:
- p->nInt64 = n; break;
- case SbxDECIMAL:
- case SbxBYREF | SbxDECIMAL:
- ImpCreateDecimal( p )->setLong( n );
- break;
-
- case SbxBYREF | SbxSTRING:
- case SbxSTRING:
- case SbxLPSTR:
- if( !p->pOUString )
- p->pOUString = new OUString;
- ImpCvtNum( static_cast<double>(n), 0, *p->pOUString );
- break;
- case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
- pVal->PutLong( n );
- else
- SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT );
- break;
- }
- case SbxBYREF | SbxCHAR:
- if( n > SbxMAXCHAR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXCHAR;
- }
- else if( n < SbxMINCHAR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMINCHAR;
- }
- *p->pChar = static_cast<sal_Unicode>(n); break;
- case SbxBYREF | SbxBYTE:
- if( n > SbxMAXBYTE )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXBYTE;
- }
- else if( n < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = 0;
- }
- *p->pByte = static_cast<sal_uInt8>(n); break;
- case SbxBYREF | SbxINTEGER:
- case SbxBYREF | SbxBOOL:
- if( n > SbxMAXINT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXINT;
- }
- else if( n < SbxMININT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMININT;
- }
- *p->pInteger = static_cast<sal_Int16>(n); break;
- case SbxBYREF | SbxERROR:
- case SbxBYREF | SbxUSHORT:
- if( n > SbxMAXUINT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXUINT;
- }
- else if( n < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = 0;
- }
- *p->pUShort = static_cast<sal_uInt16>(n); break;
- case SbxBYREF | SbxLONG:
- *p->pLong = n; break;
- case SbxBYREF | SbxULONG:
- if( n < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = 0;
- }
- *p->pULong = static_cast<sal_uInt32>(n); break;
- case SbxBYREF | SbxSALINT64:
- *p->pnInt64 = n; break;
- case SbxBYREF | SbxSALUINT64:
- if( n < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); *p->puInt64 = 0;
- }
- else
- *p->puInt64 = n;
- break;
- case SbxBYREF | SbxSINGLE:
- *p->pSingle = static_cast<float>(n); break;
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- *p->pDouble = static_cast<double>(n); break;
- case SbxBYREF | SbxCURRENCY:
- *p->pnInt64 = static_cast<sal_Int64>(n) * sal_Int64(CURRENCY_FACTOR); break;
- default:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- }
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/sbx/sbxobj.cxx b/basic/source/sbx/sbxobj.cxx
index 7f3560a62003..3fc56112e9e8 100644
--- a/basic/source/sbx/sbxobj.cxx
+++ b/basic/source/sbx/sbxobj.cxx
@@ -29,7 +29,9 @@
#include <basic/sbxmeth.hxx>
#include <sbxprop.hxx>
#include <svl/SfxBroadcaster.hxx>
+#include "sbxdec.hxx"
#include "sbxres.hxx"
+#include <filefmt.hxx>
static OUString pNameProp; // Name-Property
@@ -137,16 +139,14 @@ void SbxObject::Clear()
void SbxObject::Notify( SfxBroadcaster&, const SfxHint& rHint )
{
- const SbxHint* p = dynamic_cast<const SbxHint*>(&rHint);
- if( !p )
- return;
-
- const SfxHintId nId = p->GetId();
+ const SfxHintId nId = rHint.GetId();
bool bRead = ( nId == SfxHintId::BasicDataWanted );
bool bWrite = ( nId == SfxHintId::BasicDataChanged );
- SbxVariable* pVar = p->GetVar();
if( !(bRead || bWrite) )
return;
+ const SbxHint* p = static_cast<const SbxHint*>(&rHint);
+
+ SbxVariable* pVar = p->GetVar();
OUString aVarName( pVar->GetName() );
sal_uInt16 nHash_ = MakeHashCode( aVarName );
@@ -262,6 +262,9 @@ bool SbxObject::Call( const OUString& rName, SbxArray* pParam )
SbxVariable* pMeth = FindQualified( rName, SbxClassType::DontCare);
if( dynamic_cast<const SbxMethod*>( pMeth) )
{
+ // tdf#149622 - clear return value of the method before calling it
+ pMeth->Clear();
+
// FindQualified() might have struck already!
if( pParam )
{
@@ -271,7 +274,7 @@ bool SbxObject::Call( const OUString& rName, SbxArray* pParam )
pMeth->SetParameters( nullptr );
return true;
}
- SetError( ERRCODE_BASIC_NO_METHOD );
+ SetError( ERRCODE_BASIC_NO_METHOD, rName );
return false;
}
@@ -599,11 +602,11 @@ bool SbxObject::LoadData( SvStream& rStrm, sal_uInt16 nVer )
return true;
}
-bool SbxObject::StoreData( SvStream& rStrm ) const
+std::pair<bool, sal_uInt32> SbxObject::StoreData( SvStream& rStrm ) const
{
- if( !SbxVariable::StoreData( rStrm ) )
+ if( !SbxVariable::StoreData(rStrm).first )
{
- return false;
+ return { false, 0 };
}
OUString aDfltProp;
if( pDfltProp )
@@ -618,20 +621,21 @@ bool SbxObject::StoreData( SvStream& rStrm ) const
rStrm.Seek( nPos );
rStrm.WriteUInt32( nNew - nPos );
rStrm.Seek( nNew );
- if( !pMethods->Store( rStrm ) )
+ const auto [bSuccess, nVersion] = pMethods->Store( rStrm );
+ if( !bSuccess )
{
- return false;
+ return { false, 0 };
}
- if( !pProps->Store( rStrm ) )
+ if( !pProps->Store( rStrm ).first )
{
- return false;
+ return { false, 0 };
}
- if( !pObjs->Store( rStrm ) )
+ if( !pObjs->Store( rStrm ).first )
{
- return false;
+ return { false, 0 };
}
const_cast<SbxObject*>(this)->SetModified( false );
- return true;
+ return { true, nVersion };
}
static bool CollectAttrs( const SbxBase* p, OUString& rRes )
@@ -683,11 +687,11 @@ void SbxObject::Dump( SvStream& rStrm, bool bFill )
static sal_uInt16 nLevel = 0;
if ( nLevel > 10 )
{
- rStrm.WriteCharPtr( "<too deep>" ) << endl;
+ rStrm.WriteOString( "<too deep>" ) << endl;
return;
}
++nLevel;
- OUString aIndent("");
+ OUString aIndent(u""_ustr);
for ( sal_uInt16 n = 1; n < nLevel; ++n )
{
aIndent += " ";
@@ -695,38 +699,38 @@ void SbxObject::Dump( SvStream& rStrm, bool bFill )
// Output the data of the object itself
OString aNameStr(OUStringToOString(GetName(), RTL_TEXTENCODING_ASCII_US));
OString aClassNameStr(OUStringToOString(aClassName, RTL_TEXTENCODING_ASCII_US));
- rStrm.WriteCharPtr( "Object( " )
- .WriteOString( OString::number(reinterpret_cast<sal_Int64>(this)) ).WriteCharPtr( "=='" )
- .WriteCharPtr( aNameStr.isEmpty() ? "<unnamed>" : aNameStr.getStr() ).WriteCharPtr( "', " )
- .WriteCharPtr( "of class '" ).WriteOString( aClassNameStr ).WriteCharPtr( "', " )
- .WriteCharPtr( "counts " )
+ rStrm.WriteOString( "Object( " )
+ .WriteOString( OString::number(reinterpret_cast<sal_IntPtr>(this)) ).WriteOString( "=='" )
+ .WriteOString( aNameStr.isEmpty() ? "<unnamed>"_ostr : aNameStr ).WriteOString( "', " )
+ .WriteOString( "of class '" ).WriteOString( aClassNameStr ).WriteOString( "', " )
+ .WriteOString( "counts " )
.WriteOString( OString::number(GetRefCount()) )
- .WriteCharPtr( " refs, " );
+ .WriteOString( " refs, " );
if ( GetParent() )
{
OString aParentNameStr(OUStringToOString(GetName(), RTL_TEXTENCODING_ASCII_US));
- rStrm.WriteCharPtr( "in parent " )
- .WriteOString( OString::number(reinterpret_cast<sal_Int64>(GetParent())) )
- .WriteCharPtr( "=='" ).WriteCharPtr( aParentNameStr.isEmpty() ? "<unnamed>" : aParentNameStr.getStr() ).WriteCharPtr( "'" );
+ rStrm.WriteOString( "in parent " )
+ .WriteOString( OString::number(reinterpret_cast<sal_IntPtr>(GetParent())) )
+ .WriteOString( "=='" ).WriteOString( aParentNameStr.isEmpty() ? "<unnamed>"_ostr : aParentNameStr ).WriteOString( "'" );
}
else
{
- rStrm.WriteCharPtr( "no parent " );
+ rStrm.WriteOString( "no parent " );
}
- rStrm.WriteCharPtr( " )" ) << endl;
+ rStrm.WriteOString( " )" ) << endl;
OString aIndentNameStr(OUStringToOString(aIndent, RTL_TEXTENCODING_ASCII_US));
- rStrm.WriteOString( aIndentNameStr ).WriteCharPtr( "{" ) << endl;
+ rStrm.WriteOString( aIndentNameStr ).WriteOString( "{" ) << endl;
// Flags
OUString aAttrs;
if( CollectAttrs( this, aAttrs ) )
{
OString aAttrStr(OUStringToOString(aAttrs, RTL_TEXTENCODING_ASCII_US));
- rStrm.WriteOString( aIndentNameStr ).WriteCharPtr( "- Flags: " ).WriteOString( aAttrStr ) << endl;
+ rStrm.WriteOString( aIndentNameStr ).WriteOString( "- Flags: " ).WriteOString( aAttrStr ) << endl;
}
// Methods
- rStrm.WriteOString( aIndentNameStr ).WriteCharPtr( "- Methods:" ) << endl;
+ rStrm.WriteOString( aIndentNameStr ).WriteOString( "- Methods:" ) << endl;
for (sal_uInt32 i = 0; i < pMethods->Count(); i++)
{
SbxVariableRef& r = pMethods->GetRef(i);
@@ -751,7 +755,7 @@ void SbxObject::Dump( SvStream& rStrm, bool bFill )
pVar->GetValues_Impl().pObj != this &&
pVar->GetValues_Impl().pObj != GetParent() )
{
- rStrm.WriteCharPtr( " contains " );
+ rStrm.WriteOString( " contains " );
static_cast<SbxObject*>(pVar->GetValues_Impl().pObj)->Dump( rStrm, bFill );
}
else
@@ -762,7 +766,7 @@ void SbxObject::Dump( SvStream& rStrm, bool bFill )
}
// Properties
- rStrm.WriteOString( aIndentNameStr ).WriteCharPtr( "- Properties:" ) << endl;
+ rStrm.WriteOString( aIndentNameStr ).WriteOString( "- Properties:" ) << endl;
{
for (sal_uInt32 i = 0; i < pProps->Count(); i++)
{
@@ -788,7 +792,7 @@ void SbxObject::Dump( SvStream& rStrm, bool bFill )
pVar->GetValues_Impl().pObj != this &&
pVar->GetValues_Impl().pObj != GetParent() )
{
- rStrm.WriteCharPtr( " contains " );
+ rStrm.WriteOString( " contains " );
static_cast<SbxObject*>(pVar->GetValues_Impl().pObj)->Dump( rStrm, bFill );
}
else
@@ -800,7 +804,7 @@ void SbxObject::Dump( SvStream& rStrm, bool bFill )
}
// Objects
- rStrm.WriteOString( aIndentNameStr ).WriteCharPtr( "- Objects:" ) << endl;
+ rStrm.WriteOString( aIndentNameStr ).WriteOString( "- Objects:" ) << endl;
{
for (sal_uInt32 i = 0; i < pObjs->Count(); i++)
{
@@ -808,7 +812,7 @@ void SbxObject::Dump( SvStream& rStrm, bool bFill )
SbxVariable* pVar = r.get();
if ( pVar )
{
- rStrm.WriteOString( aIndentNameStr ).WriteCharPtr( " - Sub" );
+ rStrm.WriteOString( aIndentNameStr ).WriteOString( " - Sub" );
if (SbxObject *pSbxObj = dynamic_cast<SbxObject*>(pVar))
{
pSbxObj->Dump(rStrm, bFill);
@@ -821,7 +825,7 @@ void SbxObject::Dump( SvStream& rStrm, bool bFill )
}
}
- rStrm.WriteOString( aIndentNameStr ).WriteCharPtr( "}" ) << endl << endl;
+ rStrm.WriteOString( aIndentNameStr ).WriteOString( "}" ) << endl << endl;
--nLevel;
}
@@ -850,6 +854,36 @@ SbxClassType SbxMethod::GetClass() const
return SbxClassType::Method;
}
+void SbxMethod::Clear()
+{
+ // Release referenced data, and reset data type to the function return type
+ // Implementation similar to SbxValue::SetType
+ // tdf#143582: Don't take "read-only" flag into account, allow clearing method return value
+ switch (aData.eType)
+ {
+ case SbxSTRING:
+ delete aData.pOUString;
+ break;
+ case SbxOBJECT:
+ if (aData.pObj)
+ {
+ if (aData.pObj != this)
+ {
+ bool bParentProp = (GetUserData() & 0xFFFF) == 5345; // See sbxvalue.cxx
+ if (!bParentProp)
+ aData.pObj->ReleaseRef();
+ }
+ }
+ break;
+ case SbxDECIMAL:
+ releaseDecimalPtr(aData.pDecimal);
+ break;
+ default:
+ break;
+ }
+ aData.clear(IsFixed() ? aData.eType : SbxEMPTY);
+}
+
SbxProperty::SbxProperty( const OUString& r, SbxDataType t )
: SbxVariable( t )
{
diff --git a/basic/source/sbx/sbxres.cxx b/basic/source/sbx/sbxres.cxx
index 125969e3efd9..d29383cf076c 100644
--- a/basic/source/sbx/sbxres.cxx
+++ b/basic/source/sbx/sbxres.cxx
@@ -22,59 +22,59 @@
#include <rtl/ustring.hxx>
-static const char* pSbxRes[] = {
- "Empty",
- "Null",
- "Integer",
- "Long",
- "Single",
- "Double",
- "Currency",
- "Date",
- "String",
- "Object",
- "Error",
- "Boolean",
- "Variant",
- "Any",
- "Type14",
- "Type15",
- "Char",
- "Byte",
- "UShort",
- "ULong",
- "Long64",
- "ULong64",
- "Int",
- "UInt",
- "Void",
- "HResult",
- "Pointer",
- "DimArray",
- "CArray",
- "Any",
- "LpStr",
- "LpWStr",
- " As ",
- "Optional ",
- "Byref ",
+constexpr OUString pSbxRes[] = {
+ u"Empty"_ustr,
+ u"Null"_ustr,
+ u"Integer"_ustr,
+ u"Long"_ustr,
+ u"Single"_ustr,
+ u"Double"_ustr,
+ u"Currency"_ustr,
+ u"Date"_ustr,
+ u"String"_ustr,
+ u"Object"_ustr,
+ u"Error"_ustr,
+ u"Boolean"_ustr,
+ u"Variant"_ustr,
+ u"Any"_ustr,
+ u"Type14"_ustr,
+ u"Type15"_ustr,
+ u"Char"_ustr,
+ u"Byte"_ustr,
+ u"UShort"_ustr,
+ u"ULong"_ustr,
+ u"Long64"_ustr,
+ u"ULong64"_ustr,
+ u"Int"_ustr,
+ u"UInt"_ustr,
+ u"Void"_ustr,
+ u"HResult"_ustr,
+ u"Pointer"_ustr,
+ u"DimArray"_ustr,
+ u"CArray"_ustr,
+ u"Any"_ustr,
+ u"LpStr"_ustr,
+ u"LpWStr"_ustr,
+ u" As "_ustr,
+ u"Optional "_ustr,
+ u"Byref "_ustr,
- "Name",
- "Parent",
- "Application",
- "Count",
- "Add",
- "Item",
- "Remove",
+ u"Name"_ustr,
+ u"Parent"_ustr,
+ u"Application"_ustr,
+ u"Count"_ustr,
+ u"Add"_ustr,
+ u"Item"_ustr,
+ u"Remove"_ustr,
- "Error ", // with blank!
- "False",
- "True"
+ u"Error "_ustr, // with blank!
+ u"False"_ustr,
+ u"True"_ustr
};
OUString GetSbxRes( StringId nId )
{
- return OUString::createFromAscii( ( nId > StringId::LastValue ) ? "???" : pSbxRes[ static_cast<int>( nId ) ] );
+ return ( nId > StringId::LastValue ) ? u"???"_ustr : pSbxRes[ static_cast<int>( nId ) ];
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/sbx/sbxscan.cxx b/basic/source/sbx/sbxscan.cxx
index e6037d05cbcd..546366af5698 100644
--- a/basic/source/sbx/sbxscan.cxx
+++ b/basic/source/sbx/sbxscan.cxx
@@ -19,11 +19,13 @@
#include <sal/config.h>
+#include <cstdlib>
+#include <optional>
#include <string_view>
#include <config_features.h>
-#include <vcl/errcode.hxx>
+#include <comphelper/errcode.hxx>
#include <unotools/resmgr.hxx>
#include "sbxconv.hxx"
@@ -47,6 +49,9 @@
#include <rtl/math.hxx>
#include <svl/numformat.hxx>
#include <svl/zforlist.hxx>
+#include <o3tl/temporary.hxx>
+#include <o3tl/string_view.hxx>
+#include <officecfg/Office/Scripting.hxx>
void ImpGetIntntlSep( sal_Unicode& rcDecimalSep, sal_Unicode& rcThousandSep, sal_Unicode& rcDecimalSepAlt )
@@ -59,123 +64,120 @@ void ImpGetIntntlSep( sal_Unicode& rcDecimalSep, sal_Unicode& rcThousandSep, sal
}
-static bool ImpStrChr( const OUString& str, sal_Unicode c ) { return str.indexOf(c) >= 0; }
+static bool ImpStrChr( std::u16string_view str, sal_Unicode c ) { return str.find(c) != std::u16string_view::npos; }
// scanning a string according to BASIC-conventions
// but exponent may also be a D, so data type is SbxDOUBLE
// conversion error if data type is fixed and it doesn't fit
-ErrCode ImpScan( const OUString& rWSrc, double& nVal, SbxDataType& rType,
- sal_uInt16* pLen, bool bOnlyIntntl )
+ErrCode ImpScan( std::u16string_view rWSrc, double& nVal, SbxDataType& rType,
+ sal_Int32* pLen, bool* pHasNumber, bool bOnlyIntntl )
{
- sal_Unicode cIntntlDecSep, cIntntlGrpSep, cIntntlDecSepAlt;
- sal_Unicode cNonIntntlDecSep = '.';
+ sal_Unicode cDecSep, cGrpSep, cDecSepAlt;
if( bOnlyIntntl )
{
- ImpGetIntntlSep( cIntntlDecSep, cIntntlGrpSep, cIntntlDecSepAlt );
- cNonIntntlDecSep = cIntntlDecSep;
+ ImpGetIntntlSep(cDecSep, cGrpSep, cDecSepAlt);
// Ensure that the decimal separator alternative is really one.
- if (cIntntlDecSepAlt && cIntntlDecSepAlt == cNonIntntlDecSep)
- cIntntlDecSepAlt = 0;
+ if (cDecSepAlt == cDecSep)
+ cDecSepAlt = 0;
}
else
{
- cIntntlDecSep = cNonIntntlDecSep;
- cIntntlGrpSep = 0; // no group separator accepted in non-i18n
- cIntntlDecSepAlt = 0;
+ cDecSep = '.';
+ cGrpSep = 0; // no group separator accepted in non-i18n
+ cDecSepAlt = 0;
}
- const sal_Unicode* const pStart = rWSrc.getStr();
- const sal_Unicode* p = pStart;
- OUStringBuffer aBuf( rWSrc.getLength());
- bool bRes = true;
+ auto const pStart = rWSrc.begin();
+ auto p = pStart;
bool bMinus = false;
nVal = 0;
SbxDataType eScanType = SbxSINGLE;
- while( *p == ' ' || *p == '\t' )
+ while (p != rWSrc.end() && (*p == ' ' || *p == '\t'))
p++;
- if (*p == '+')
+ if (p != rWSrc.end() && *p == '+')
p++;
- else if( *p == '-' )
+ else if (p != rWSrc.end() && *p == '-')
{
p++;
bMinus = true;
}
- if( rtl::isAsciiDigit( *p ) || ((*p == cNonIntntlDecSep || *p == cIntntlDecSep ||
- (cIntntlDecSep && *p == cIntntlGrpSep) || (cIntntlDecSepAlt && *p == cIntntlDecSepAlt)) &&
- rtl::isAsciiDigit( *(p+1) )))
+#if HAVE_FEATURE_SCRIPTING
+ if (SbiRuntime::isVBAEnabled())
+ {
+ while (p != rWSrc.end() && (*p == ' ' || *p == '\t'))
+ p++;
+ }
+#endif
+ const auto pNumberStart = p;
+ if (p != rWSrc.end()
+ && (rtl::isAsciiDigit(*p)
+ || ((*p == cDecSep || (cGrpSep && *p == cGrpSep) || (cDecSepAlt && *p == cDecSepAlt))
+ && p + 1 != rWSrc.end() && rtl::isAsciiDigit(*(p + 1)))))
{
- // tdf#118442: Whitespace and minus are skipped; store the position to calculate index
- const sal_Unicode* const pDigitsStart = p;
- short exp = 0;
- short decsep = 0;
+ bool exp = false;
+ bool decsep = false;
short ndig = 0;
short ncdig = 0; // number of digits after decimal point
- OUStringBuffer aSearchStr("0123456789DEde");
- aSearchStr.append(cNonIntntlDecSep);
- if( cIntntlDecSep != cNonIntntlDecSep )
- aSearchStr.append(cIntntlDecSep);
- if( cIntntlDecSepAlt && cIntntlDecSepAlt != cNonIntntlDecSep )
- aSearchStr.append(cIntntlDecSepAlt);
- if( bOnlyIntntl )
- aSearchStr.append(cIntntlGrpSep);
- const OUString pSearchStr = aSearchStr.makeStringAndClear();
- static const OUStringLiteral pDdEe = u"DdEe";
- while( ImpStrChr( pSearchStr, *p ) )
+ OUStringBuffer aSearchStr("0123456789DEde" + OUStringChar(cDecSep));
+ if (cDecSepAlt)
+ aSearchStr.append(cDecSepAlt);
+ if (cGrpSep)
+ aSearchStr.append(cGrpSep);
+ OUStringBuffer aBuf(rWSrc.end() - p);
+ for (; p != rWSrc.end() && ImpStrChr(aSearchStr, *p); ++p)
{
- aBuf.append( *p );
- if( bOnlyIntntl && *p == cIntntlGrpSep )
+ if (rtl::isAsciiDigit(*p))
+ {
+ aBuf.append(*p);
+ if (!exp)
+ {
+ ndig++;
+ if (decsep)
+ ncdig++;
+ }
+ }
+ else if (cGrpSep && *p == cGrpSep)
{
- p++;
- continue;
+ aBuf.append(*p);
}
- if( *p == cNonIntntlDecSep || *p == cIntntlDecSep || (cIntntlDecSepAlt && *p == cIntntlDecSepAlt) )
+ else if (*p == cDecSep || (cDecSepAlt && *p == cDecSepAlt))
{
+ if (decsep)
+ return ERRCODE_BASIC_CONVERSION;
+ decsep = true;
+
// Use the separator that is passed to stringToDouble()
- aBuf[p - pDigitsStart] = cIntntlDecSep;
- p++;
- if( ++decsep > 1 )
- continue;
+ aBuf.append(cDecSep);
}
- else if( ImpStrChr( pDdEe, *p ) )
+ else // DdEe
{
- if( ++exp > 1 )
- {
- p++;
- continue;
- }
+ if (exp)
+ return ERRCODE_BASIC_CONVERSION;
+ exp = true;
+
if( *p == 'D' || *p == 'd' )
eScanType = SbxDOUBLE;
- aBuf[p - pDigitsStart] = 'E';
- p++;
- if (*p == '+')
- ++p;
- else if (*p == '-')
+ aBuf.append('E');
+ if (auto pNext = p + 1; pNext != rWSrc.end())
{
- aBuf.append('-');
- ++p;
+ if (*pNext == '+')
+ ++p;
+ else if (*pNext == '-')
+ {
+ aBuf.append('-');
+ ++p;
+ }
}
}
- else
- {
- p++;
- if( decsep && !exp )
- ncdig++;
- }
- if( !exp )
- ndig++;
}
- if( decsep > 1 || exp > 1 )
- bRes = false;
-
- OUString aBufStr( aBuf.makeStringAndClear());
rtl_math_ConversionStatus eStatus = rtl_math_ConversionStatus_Ok;
sal_Int32 nParseEnd = 0;
- nVal = rtl::math::stringToDouble( aBufStr, cIntntlDecSep, cIntntlGrpSep, &eStatus, &nParseEnd );
- if( eStatus != rtl_math_ConversionStatus_Ok || nParseEnd != aBufStr.getLength() )
- bRes = false;
+ nVal = rtl::math::stringToDouble(aBuf, cDecSep, cGrpSep, &eStatus, &nParseEnd);
+ if( eStatus != rtl_math_ConversionStatus_Ok || nParseEnd != aBuf.getLength() )
+ return ERRCODE_BASIC_CONVERSION;
if( !decsep && !exp )
{
@@ -185,29 +187,29 @@ ErrCode ImpScan( const OUString& rWSrc, double& nVal, SbxDataType& rType,
eScanType = SbxLONG;
}
- ndig = ndig - decsep;
// too many numbers for SINGLE?
if( ndig > 15 || ncdig > 6 )
eScanType = SbxDOUBLE;
// type detection?
- static const OUStringLiteral pTypes = u"%!&#";
- if( ImpStrChr( pTypes, *p ) )
+ static constexpr std::u16string_view pTypes = u"%!&#";
+ if (p != rWSrc.end() && ImpStrChr(pTypes, *p))
p++;
}
// hex/octal number? read in and convert:
- else if( *p == '&' )
+ else if (p != rWSrc.end() && *p == '&')
{
- p++;
+ if (++p == rWSrc.end())
+ return ERRCODE_BASIC_CONVERSION;
eScanType = SbxLONG;
- OUString aCmp( "0123456789ABCDEF" );
+ auto isValidDigit = rtl::isAsciiHexDigit<sal_Unicode>;
char base = 16;
char ndig = 8;
switch( *p++ )
{
case 'O':
case 'o':
- aCmp = "01234567";
+ isValidDigit = rtl::isAsciiOctalDigit<sal_Unicode>;
base = 8;
ndig = 11;
break;
@@ -215,29 +217,18 @@ ErrCode ImpScan( const OUString& rWSrc, double& nVal, SbxDataType& rType,
case 'h':
break;
default :
- bRes = false;
+ return ERRCODE_BASIC_CONVERSION;
}
- while( rtl::isAsciiAlphanumeric( *p ) ) /* XXX: really munge all alnum also when error? */
+ const auto pDigitsStart = p;
+ for (; p != rWSrc.end() && rtl::isAsciiAlphanumeric(*p); ++p)
{
- sal_Unicode ch = rtl::toAsciiUpperCase(*p);
- if( ImpStrChr( aCmp, ch ) )
- aBuf.append( ch );
- else
- bRes = false;
- p++;
+ if (!isValidDigit(*p))
+ return ERRCODE_BASIC_CONVERSION;
}
- OUString aBufStr( aBuf.makeStringAndClear());
- sal_Int32 l = 0;
- for( const sal_Unicode* q = aBufStr.getStr(); bRes && *q; q++ )
- {
- int i = *q - '0';
- if( i > 9 )
- i -= 7; // 'A'-'0' = 17 => 10, ...
- l = ( l * base ) + i;
- if( !ndig-- )
- bRes = false;
- }
- if( *p == '&' )
+ if (p - pDigitsStart > ndig)
+ return ERRCODE_BASIC_CONVERSION;
+ sal_Int32 l = o3tl::toInt32(rWSrc.substr(pDigitsStart - pStart, p - pDigitsStart), base);
+ if (p != rWSrc.end() && *p == '&')
p++;
nVal = static_cast<double>(l);
if( l >= SbxMININT && l <= SbxMAXINT )
@@ -249,22 +240,34 @@ ErrCode ImpScan( const OUString& rWSrc, double& nVal, SbxDataType& rType,
return ERRCODE_BASIC_CONVERSION;
}
#endif
+ const auto pNumberEnd = p;
+ // tdf#146672 - skip whitespaces and tabs at the end of the scanned string
+ while (p != rWSrc.end() && (*p == ' ' || *p == '\t'))
+ p++;
if( pLen )
- *pLen = static_cast<sal_uInt16>( p - pStart );
- if( !bRes )
- return ERRCODE_BASIC_CONVERSION;
+ *pLen = p - pStart;
+ if (pHasNumber)
+ *pHasNumber = pNumberEnd > pNumberStart;
if( bMinus )
nVal = -nVal;
rType = eScanType;
return ERRCODE_NONE;
}
+ErrCode ImpScan(std::u16string_view rSrc, double& nVal, SbxDataType& rType, sal_Int32* pLen)
+{
+ using namespace officecfg::Office::Scripting;
+ static const bool bEnv = std::getenv("LIBREOFFICE6FLOATINGPOINTMODE") != nullptr;
+ bool bMode = bEnv || Basic::Compatibility::UseLibreOffice6FloatingPointConversion::get();
+
+ return ImpScan(rSrc, nVal, rType, pLen, nullptr, !bMode);
+}
+
// port for CDbl in the Basic
ErrCode SbxValue::ScanNumIntnl( const OUString& rSrc, double& nVal, bool bSingle )
{
- SbxDataType t;
- sal_uInt16 nLen = 0;
- ErrCode nRetError = ImpScan( rSrc, nVal, t, &nLen,
+ sal_Int32 nLen = 0;
+ ErrCode nRetError = ImpScan( rSrc, nVal, o3tl::temporary(SbxDataType()), &nLen, nullptr,
/*bOnlyIntntl*/true );
// read completely?
if( nRetError == ERRCODE_NONE && nLen != rSrc.getLength() )
@@ -286,110 +289,50 @@ ErrCode SbxValue::ScanNumIntnl( const OUString& rSrc, double& nVal, bool bSingle
void ImpCvtNum( double nNum, short nPrec, OUString& rRes, bool bCoreString )
{
- sal_Unicode cDecimalSep, cThousandSep, cDecimalSepAlt;
- ImpGetIntntlSep( cDecimalSep, cThousandSep, cDecimalSepAlt );
+ sal_Unicode cDecimalSep;
if( bCoreString )
cDecimalSep = '.';
+ else
+ ImpGetIntntlSep(cDecimalSep, o3tl::temporary(sal_Unicode()), o3tl::temporary(sal_Unicode()));
// tdf#143575 - use rtl::math::doubleToUString to convert numbers to strings in basic
rRes = rtl::math::doubleToUString(nNum, rtl_math_StringFormat_Automatic, nPrec, cDecimalSep, true);
}
-bool ImpConvStringExt( OUString& rSrc, SbxDataType eTargetType )
-{
- bool bChanged = false;
- OUString aNewString;
-
- // only special cases are handled, nothing on default
- switch( eTargetType )
- {
- // consider international for floating point
- case SbxSINGLE:
- case SbxDOUBLE:
- case SbxCURRENCY:
- {
- sal_Unicode cDecimalSep, cThousandSep, cDecimalSepAlt;
- ImpGetIntntlSep( cDecimalSep, cThousandSep, cDecimalSepAlt );
- aNewString = rSrc;
-
- if( cDecimalSep != '.' || (cDecimalSepAlt && cDecimalSepAlt != '.') )
- {
- sal_Int32 nPos = aNewString.indexOf( cDecimalSep );
- if( nPos == -1 && cDecimalSepAlt )
- nPos = aNewString.indexOf( cDecimalSepAlt );
- if( nPos != -1 )
- {
- sal_Unicode* pStr = const_cast<sal_Unicode*>(aNewString.getStr());
- pStr[nPos] = '.';
- bChanged = true;
- }
- }
- break;
- }
-
- // check as string in case of sal_Bool sal_True and sal_False
- case SbxBOOL:
- {
- if( rSrc.equalsIgnoreAsciiCase("true") )
- {
- aNewString = OUString::number( SbxTRUE );
- bChanged = true;
- }
- else if( rSrc.equalsIgnoreAsciiCase("false") )
- {
- aNewString = OUString::number( SbxFALSE );
- bChanged = true;
- }
- break;
- }
- default: break;
- }
-
- if( bChanged )
- rSrc = aNewString;
- return bChanged;
-}
-
-
// formatted number output
-// the return value is the number of characters used
-// from the format
-static sal_uInt16 printfmtstr( const OUString& rStr, OUString& rRes, const OUString& rFmt )
+static void printfmtstr(std::u16string_view rStr, OUString& rRes, std::u16string_view rFmt)
{
+ if (rFmt.empty())
+ rFmt = u"&";
+
OUStringBuffer aTemp;
- const sal_Unicode* pStr = rStr.getStr();
- const sal_Unicode* pFmtStart = rFmt.getStr();
- const sal_Unicode* pFmt = pFmtStart;
+ auto pStr = rStr.begin();
+ auto pFmt = rFmt.begin();
switch( *pFmt )
{
case '!':
- aTemp.append(*pStr++);
- pFmt++;
+ if (pStr != rStr.end())
+ aTemp.append(*pStr);
break;
case '\\':
do
{
- aTemp.append( *pStr ? *pStr++ : u' ');
- pFmt++;
- }
- while( *pFmt && *pFmt != '\\' );
- aTemp.append(*pStr ? *pStr++ : u' ');
- pFmt++; break;
+ aTemp.append(pStr != rStr.end() ? *pStr++ : u' ');
+ } while (++pFmt != rFmt.end() && *pFmt != '\\');
+ aTemp.append(pStr != rStr.end() ? *pStr : u' ');
+ break;
case '&':
- aTemp = rStr;
- pFmt++; break;
default:
aTemp = rStr;
break;
}
rRes = aTemp.makeStringAndClear();
- return static_cast<sal_uInt16>( pFmt - pFmtStart );
}
-bool SbxValue::Scan( const OUString& rSrc, sal_uInt16* pLen )
+bool SbxValue::Scan(std::u16string_view rSrc, sal_Int32* pLen)
{
ErrCode eRes = ERRCODE_NONE;
if( !CanWrite() )
@@ -400,7 +343,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 );
if( eRes == ERRCODE_NONE )
{
if( !IsFixed() )
@@ -438,7 +381,6 @@ enum class VbaFormatType
{
Offset, // standard number format
UserDefined, // user defined number format
- Null
};
#if HAVE_FEATURE_SCRIPTING
@@ -448,294 +390,277 @@ struct VbaFormatInfo
VbaFormatType meType;
std::u16string_view mpVbaFormat; // Format string in vba
NfIndexTableOffset meOffset; // SvNumberFormatter format index, if meType = VbaFormatType::Offset
- const char* mpOOoFormat; // if meType = VbaFormatType::UserDefined
+ OUString mpOOoFormat; // if meType = VbaFormatType::UserDefined
};
-const VbaFormatInfo pFormatInfoTable[] =
+const VbaFormatInfo* getFormatInfo( std::u16string_view rFmt )
{
- { VbaFormatType::Offset, std::u16string_view(u"Long Date"), NF_DATE_SYSTEM_LONG, nullptr },
- { VbaFormatType::UserDefined, std::u16string_view(u"Medium Date"), NF_NUMBER_STANDARD, "DD-MMM-YY" },
- { VbaFormatType::Offset, std::u16string_view(u"Short Date"), NF_DATE_SYSTEM_SHORT, nullptr },
- { VbaFormatType::UserDefined, std::u16string_view(u"Long Time"), NF_NUMBER_STANDARD, "H:MM:SS AM/PM" },
- { VbaFormatType::Offset, std::u16string_view(u"Medium Time"), NF_TIME_HHMMAMPM, nullptr },
- { VbaFormatType::Offset, std::u16string_view(u"Short Time"), NF_TIME_HHMM, nullptr },
- { VbaFormatType::Offset, std::u16string_view(u"ddddd"), NF_DATE_SYSTEM_SHORT, nullptr },
- { VbaFormatType::Offset, std::u16string_view(u"dddddd"), NF_DATE_SYSTEM_LONG, nullptr },
- { VbaFormatType::UserDefined, std::u16string_view(u"ttttt"), NF_NUMBER_STANDARD, "H:MM:SS AM/PM" },
- { VbaFormatType::Offset, std::u16string_view(u"ww"), NF_DATE_WW, nullptr },
- { VbaFormatType::Null, std::u16string_view(u""), NF_INDEX_TABLE_ENTRIES, nullptr }
-};
+ static constexpr const VbaFormatInfo formatInfoTable[] =
+ {
+ { VbaFormatType::Offset, u"Long Date", NF_DATE_SYSTEM_LONG, u""_ustr },
+ { VbaFormatType::UserDefined, u"Medium Date", NF_NUMBER_STANDARD, u"DD-MMM-YY"_ustr },
+ { VbaFormatType::Offset, u"Short Date", NF_DATE_SYSTEM_SHORT, u""_ustr },
+ { VbaFormatType::UserDefined, u"Long Time", NF_NUMBER_STANDARD, u"H:MM:SS AM/PM"_ustr },
+ { VbaFormatType::Offset, u"Medium Time", NF_TIME_HHMMAMPM, u""_ustr },
+ { VbaFormatType::Offset, u"Short Time", NF_TIME_HHMM, u""_ustr },
+ { VbaFormatType::Offset, u"ddddd", NF_DATE_SYSTEM_SHORT, u""_ustr },
+ { VbaFormatType::Offset, u"dddddd", NF_DATE_SYSTEM_LONG, u""_ustr },
+ { VbaFormatType::UserDefined, u"ttttt", NF_NUMBER_STANDARD, u"H:MM:SS AM/PM"_ustr },
+ { VbaFormatType::Offset, u"ww", NF_DATE_WW, u""_ustr },
+ };
+
+ for (auto& info : formatInfoTable)
+ if (o3tl::equalsIgnoreAsciiCase(rFmt, info.mpVbaFormat))
+ return &info;
+ return nullptr;
+}
+#endif
-const VbaFormatInfo* getFormatInfo( const OUString& rFmt )
+void BasicFormatNum(double d, const OUString& rFmt, OUString& rRes)
{
- const VbaFormatInfo* pInfo = pFormatInfoTable;
- while( pInfo->meType != VbaFormatType::Null )
+ SbxAppData& rAppData = GetSbxData_Impl();
+
+ LanguageType eLangType = Application::GetSettings().GetLanguageTag().getLanguageType();
+ if (rAppData.pBasicFormater)
+ if (rAppData.eBasicFormaterLangType != eLangType)
+ rAppData.pBasicFormater.reset();
+ rAppData.eBasicFormaterLangType = eLangType;
+
+ if (!rAppData.pBasicFormater)
{
- if( rFmt.equalsIgnoreAsciiCase( pInfo->mpVbaFormat ) )
- break;
- ++pInfo;
+ SvtSysLocale aSysLocale;
+ const LocaleDataWrapper& rData = aSysLocale.GetLocaleData();
+ sal_Unicode cComma = rData.getNumDecimalSep()[0];
+ sal_Unicode c1000 = rData.getNumThousandSep()[0];
+ const OUString& aCurrencyStrg = rData.getCurrSymbol();
+
+ // initialize the Basic-formater help object:
+ // get resources for predefined output
+ // of the Format()-command, e. g. for "On/Off"
+ OUString aOnStrg = BasResId(STR_BASICKEY_FORMAT_ON);
+ OUString aOffStrg = BasResId(STR_BASICKEY_FORMAT_OFF);
+ OUString aYesStrg = BasResId(STR_BASICKEY_FORMAT_YES);
+ OUString aNoStrg = BasResId(STR_BASICKEY_FORMAT_NO);
+ OUString aTrueStrg = BasResId(STR_BASICKEY_FORMAT_TRUE);
+ OUString aFalseStrg = BasResId(STR_BASICKEY_FORMAT_FALSE);
+ OUString aCurrencyFormatStrg = BasResId(STR_BASICKEY_FORMAT_CURRENCY);
+
+ rAppData.pBasicFormater = std::make_unique<SbxBasicFormater>(
+ cComma, c1000, aOnStrg, aOffStrg, aYesStrg, aNoStrg, aTrueStrg, aFalseStrg,
+ aCurrencyStrg, aCurrencyFormatStrg);
}
- return pInfo;
+ // 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 continuous string-creation
+ // operations, too.
+ // BUT: therefore this code is NOT multithreading capable!
+ rRes = rAppData.pBasicFormater->BasicFormat(d, rFmt);
}
-#endif
-} // namespace
-
-#if HAVE_FEATURE_SCRIPTING
-constexpr OUStringLiteral VBAFORMAT_GENERALDATE = u"General Date";
-constexpr OUStringLiteral VBAFORMAT_C = u"c";
-constexpr OUStringLiteral VBAFORMAT_N = u"n";
-constexpr OUStringLiteral VBAFORMAT_NN = u"nn";
-constexpr OUStringLiteral VBAFORMAT_W = u"w";
-constexpr OUStringLiteral VBAFORMAT_Y = u"y";
-constexpr OUStringLiteral VBAFORMAT_LOWERCASE = u"<";
-constexpr OUStringLiteral VBAFORMAT_UPPERCASE = u">";
-#endif
+std::shared_ptr<SvNumberFormatter> GetFormatter()
+{
+ if (auto pInst = GetSbData()->pInst)
+ {
+ return pInst->GetNumberFormatter();
+ }
+ else
+ {
+ return SbiInstance::PrepareNumberFormatter(o3tl::temporary(sal_uInt32()),
+ o3tl::temporary(sal_uInt32()),
+ o3tl::temporary(sal_uInt32()));
+ }
+}
-void SbxValue::Format( OUString& rRes, const OUString* pFmt ) const
+std::optional<double> StrToNumberIntl(const OUString& s,
+ std::shared_ptr<SvNumberFormatter>& rpFormatter)
{
- short nComma = 0;
- double d = 0;
+ double ret;
+ if (SbxValue::ScanNumIntnl(s, ret) == ERRCODE_NONE)
+ return ret;
- // 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
-#if HAVE_FEATURE_SCRIPTING
- if( pFmt && !SbxBasicFormater::isBasicFormat( *pFmt ) )
- {
- OUString aStr = GetOUString();
+ // We couldn't detect a Basic-formatted number (including type characters & specific exponents).
+ // Try generic number detection (works also for dates/times).
- SvtSysLocale aSysLocale;
- const CharClass& rCharClass = aSysLocale.GetCharClass();
+ rpFormatter = GetFormatter();
+ assert(rpFormatter);
+ LanguageType eLangType = Application::GetSettings().GetLanguageTag().getLanguageType();
+
+ // Passing an index of a locale switches IsNumberFormat() to use that
+ // locale in case the formatter wasn't default created with it.
+ sal_uInt32 nIndex = rpFormatter->GetStandardIndex(eLangType);
+
+ if (rpFormatter->IsNumberFormat(s, nIndex, ret))
+ return ret;
+
+ return {};
+}
+
+// For numeric types, takes the number directly; otherwise, tries to take string and convert it
+std::optional<double> GetNumberIntl(const SbxValue& val, OUString& rStrVal,
+ std::shared_ptr<SvNumberFormatter>& rpFormatter,
+ bool extendedNumberDetection)
+{
+ switch (SbxDataType type = val.GetType())
+ {
+ case SbxCHAR:
+ case SbxBYTE:
+ case SbxINTEGER:
+ case SbxUSHORT:
+ case SbxLONG:
+ case SbxULONG:
+ case SbxINT:
+ case SbxUINT:
+ case SbxSINGLE:
+ case SbxDOUBLE:
+ case SbxDATE:
+ return val.GetDouble();
+ case SbxBOOL:
+ if (extendedNumberDetection)
+ return val.GetDouble();
+ [[fallthrough]];
+ case SbxSTRING:
+ default:
+ rStrVal = val.GetOUString();
+ return extendedNumberDetection || type == SbxSTRING
+ ? StrToNumberIntl(rStrVal, rpFormatter)
+ : std::nullopt;
+ }
+}
+} // namespace
- if( pFmt->equalsIgnoreAsciiCase( VBAFORMAT_LOWERCASE ) )
+void SbxValue::Format( OUString& rRes, const OUString* pFmt ) const
+{
+ if (pFmt)
+ {
+ if (*pFmt == "<") // VBA lowercase
{
- rRes = rCharClass.lowercase( aStr );
+ rRes = SvtSysLocale().GetCharClass().lowercase(GetOUString());
return;
}
- if( pFmt->equalsIgnoreAsciiCase( VBAFORMAT_UPPERCASE ) )
+ if (*pFmt == ">") // VBA uppercase
{
- rRes = rCharClass.uppercase( aStr );
+ rRes = SvtSysLocale().GetCharClass().uppercase(GetOUString());
return;
}
+ }
- LanguageType eLangType = Application::GetSettings().GetLanguageTag().getLanguageType();
- std::shared_ptr<SvNumberFormatter> pFormatter;
- if (GetSbData()->pInst)
- {
- pFormatter = GetSbData()->pInst->GetNumberFormatter();
- }
- else
- {
- sal_uInt32 n; // Dummy
- pFormatter = SbiInstance::PrepareNumberFormatter( n, n, n );
- }
-
- // Passing an index of a locale switches IsNumberFormat() to use that
- // locale in case the formatter wasn't default created with it.
- sal_uInt32 nIndex = pFormatter->GetStandardIndex( eLangType);
- double nNumber;
- const Color* pCol;
+ const SbxDataType eType = GetType();
+ if (eType == SbxNULL)
+ {
+ rRes = SbxBasicFormater::BasicFormatNull(pFmt ? *pFmt : std::u16string_view{});
+ return;
+ }
- bool bSuccess = pFormatter->IsNumberFormat( aStr, nIndex, nNumber );
+ std::shared_ptr<SvNumberFormatter> pFormatter;
+ std::optional<double> number = GetNumberIntl(*this, rRes, pFormatter, pFmt != nullptr);
- // number format, use SvNumberFormatter to handle it.
- if( bSuccess )
- {
- sal_Int32 nCheckPos = 0;
- SvNumFormatType nType;
- OUString aFmtStr = *pFmt;
- const VbaFormatInfo* pInfo = getFormatInfo( aFmtStr );
- if( pInfo->meType != VbaFormatType::Null )
- {
- if( pInfo->meType == VbaFormatType::Offset )
- {
- nIndex = pFormatter->GetFormatIndex( pInfo->meOffset, eLangType );
- }
- else
- {
- aFmtStr = OUString::createFromAscii(pInfo->mpOOoFormat);
- pFormatter->PutandConvertEntry( aFmtStr, nCheckPos, nType, nIndex, LANGUAGE_ENGLISH_US, eLangType, true);
- }
- pFormatter->GetOutputString( nNumber, nIndex, rRes, &pCol );
- }
- else if( aFmtStr.equalsIgnoreAsciiCase( VBAFORMAT_GENERALDATE )
- || aFmtStr.equalsIgnoreAsciiCase( VBAFORMAT_C ))
- {
- if( nNumber <=-1.0 || nNumber >= 1.0 )
- {
- // short date
- nIndex = pFormatter->GetFormatIndex( NF_DATE_SYSTEM_SHORT, eLangType );
- pFormatter->GetOutputString( nNumber, nIndex, rRes, &pCol );
+ if (!number)
+ {
+ if (eType == SbxSTRING && pFmt)
+ printfmtstr(rRes, rRes, *pFmt);
+ return;
+ }
- // long time
- if( floor( nNumber ) != nNumber )
- {
- aFmtStr = "H:MM:SS AM/PM";
- pFormatter->PutandConvertEntry( aFmtStr, nCheckPos, nType, nIndex, LANGUAGE_ENGLISH_US, eLangType, true);
- OUString aTime;
- pFormatter->GetOutputString( nNumber, nIndex, aTime, &pCol );
- rRes += " " + aTime;
- }
- }
- else
- {
- // long time only
- aFmtStr = "H:MM:SS AM/PM";
- pFormatter->PutandConvertEntry( aFmtStr, nCheckPos, nType, nIndex, LANGUAGE_ENGLISH_US, eLangType, true);
- pFormatter->GetOutputString( nNumber, nIndex, rRes, &pCol );
- }
- }
- else if( aFmtStr.equalsIgnoreAsciiCase( VBAFORMAT_N ) ||
- aFmtStr.equalsIgnoreAsciiCase( VBAFORMAT_NN ))
- {
- sal_Int32 nMin = implGetMinute( nNumber );
- if( nMin < 10 && aFmtStr.equalsIgnoreAsciiCase( VBAFORMAT_NN ))
- {
- // Minute in two digits
- sal_Unicode aBuf[2];
- aBuf[0] = '0';
- aBuf[1] = '0' + nMin;
- rRes = OUString(aBuf, SAL_N_ELEMENTS(aBuf));
- }
- else
- {
- rRes = OUString::number(nMin);
- }
- }
- else if( aFmtStr.equalsIgnoreAsciiCase( VBAFORMAT_W ))
- {
- sal_Int32 nWeekDay = implGetWeekDay( nNumber );
- rRes = OUString::number(nWeekDay);
- }
- else if( aFmtStr.equalsIgnoreAsciiCase( VBAFORMAT_Y ))
- {
- sal_Int16 nYear = implGetDateYear( nNumber );
- double dBaseDate;
- implDateSerial( nYear, 1, 1, true, SbDateCorrection::None, dBaseDate );
- sal_Int32 nYear32 = 1 + sal_Int32( nNumber - dBaseDate );
- rRes = OUString::number(nYear32);
- }
- else
- {
- pFormatter->PutandConvertEntry( aFmtStr, nCheckPos, nType, nIndex, LANGUAGE_ENGLISH_US, eLangType, true);
- pFormatter->GetOutputString( nNumber, nIndex, rRes, &pCol );
- }
+ if (!pFmt)
+ {
+ ImpCvtNum(*number, eType == SbxSINGLE ? 6 : eType == SbxDOUBLE ? 14 : 0, rRes);
+ return;
+ }
- return;
- }
+ if (SbxBasicFormater::isBasicFormat(*pFmt))
+ {
+ BasicFormatNum(*number, *pFmt, rRes);
+ return;
}
-#endif
- SbxDataType eType = GetType();
- switch( eType )
+ // 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
+#if HAVE_FEATURE_SCRIPTING
+ // number format, use SvNumberFormatter to handle it.
+ if (!pFormatter)
+ pFormatter = GetFormatter();
+
+ LanguageType eLangType = Application::GetSettings().GetLanguageTag().getLanguageType();
+
+ sal_uInt32 nIndex;
+ const Color* pCol;
+ sal_Int32 nCheckPos = 0;
+ SvNumFormatType nType;
+ OUString aFmtStr = *pFmt;
+ if (const VbaFormatInfo* pInfo = getFormatInfo(aFmtStr))
{
- case SbxCHAR:
- case SbxBYTE:
- case SbxINTEGER:
- case SbxUSHORT:
- case SbxLONG:
- case SbxULONG:
- case SbxINT:
- case SbxUINT:
- case SbxNULL: // #45929 NULL with a little cheating
- nComma = 0; goto cvt;
- case SbxSINGLE:
- nComma = 6; goto cvt;
- case SbxDOUBLE:
- nComma = 14;
-
- cvt:
- if( eType != SbxNULL )
+ if( pInfo->meType == VbaFormatType::Offset )
{
- d = GetDouble();
+ nIndex = pFormatter->GetFormatIndex( pInfo->meOffset, eLangType );
}
- // #45355 another point to jump in for isnumeric-String
- cvt2:
- if( pFmt )
+ else
{
- SbxAppData& rAppData = GetSbxData_Impl();
-
- LanguageType eLangType = Application::GetSettings().GetLanguageTag().getLanguageType();
- if( rAppData.pBasicFormater )
- {
- if( rAppData.eBasicFormaterLangType != eLangType )
- {
- rAppData.pBasicFormater.reset();
- }
- }
- rAppData.eBasicFormaterLangType = eLangType;
-
+ aFmtStr = pInfo->mpOOoFormat;
+ pFormatter->PutandConvertEntry( aFmtStr, nCheckPos, nType, nIndex, LANGUAGE_ENGLISH_US, eLangType, true);
+ }
+ pFormatter->GetOutputString(*number, nIndex, rRes, &pCol);
+ }
+ else if (aFmtStr.equalsIgnoreAsciiCase("General Date") // VBA general date variants
+ || aFmtStr.equalsIgnoreAsciiCase("c"))
+ {
+ OUString dateStr;
+ if (*number <= -1.0 || *number >= 1.0)
+ {
+ // short date
+ nIndex = pFormatter->GetFormatIndex( NF_DATE_SYSTEM_SHORT, eLangType );
+ pFormatter->GetOutputString(*number, nIndex, dateStr, &pCol);
- if( !rAppData.pBasicFormater )
+ if (floor(*number) == *number)
{
- SvtSysLocale aSysLocale;
- const LocaleDataWrapper& rData = aSysLocale.GetLocaleData();
- sal_Unicode cComma = rData.getNumDecimalSep()[0];
- sal_Unicode c1000 = rData.getNumThousandSep()[0];
- const OUString& aCurrencyStrg = rData.getCurrSymbol();
-
- // initialize the Basic-formater help object:
- // get resources for predefined output
- // of the Format()-command, e. g. for "On/Off"
- OUString aOnStrg = BasResId(STR_BASICKEY_FORMAT_ON);
- OUString aOffStrg = BasResId(STR_BASICKEY_FORMAT_OFF);
- OUString aYesStrg = BasResId(STR_BASICKEY_FORMAT_YES);
- OUString aNoStrg = BasResId(STR_BASICKEY_FORMAT_NO);
- OUString aTrueStrg = BasResId(STR_BASICKEY_FORMAT_TRUE);
- OUString aFalseStrg = BasResId(STR_BASICKEY_FORMAT_FALSE);
- OUString aCurrencyFormatStrg = BasResId(STR_BASICKEY_FORMAT_CURRENCY);
-
- rAppData.pBasicFormater = std::make_unique<SbxBasicFormater>(
- cComma,c1000,aOnStrg,aOffStrg,
- aYesStrg,aNoStrg,aTrueStrg,aFalseStrg,
- aCurrencyStrg,aCurrencyFormatStrg );
+ rRes = dateStr;
+ return;
}
- // 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 continuous 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!!!
- // in addition rAppData.pBasicFormater->BasicFormatNull( *pFmt ); could be called!
- if( eType != SbxNULL )
- {
- rRes = rAppData.pBasicFormater->BasicFormat( d ,*pFmt );
- }
- else
- {
- rRes = SbxBasicFormater::BasicFormatNull( *pFmt );
- }
-
}
- else
- ImpCvtNum( GetDouble(), nComma, rRes );
- break;
- case SbxSTRING:
- if( pFmt )
+ // long time
+ aFmtStr = u"H:MM:SS AM/PM"_ustr;
+ pFormatter->PutandConvertEntry(aFmtStr, nCheckPos, nType, nIndex,
+ LANGUAGE_ENGLISH_US, eLangType, true);
+ pFormatter->GetOutputString(*number, nIndex, rRes, &pCol);
+ if (!dateStr.isEmpty())
+ rRes = dateStr + " " + rRes;
+ }
+ else if (aFmtStr.equalsIgnoreAsciiCase("n") // VBA minute variants
+ || aFmtStr.equalsIgnoreAsciiCase("nn"))
+ {
+ sal_Int32 nMin = implGetMinute(*number);
+ if (nMin < 10 && aFmtStr.equalsIgnoreAsciiCase("nn"))
{
- // #45355 converting if numeric
- if( IsNumericRTL() )
- {
- ScanNumIntnl( GetOUString(), d );
- goto cvt2;
- }
- else
- {
- printfmtstr( GetOUString(), rRes, *pFmt );
- }
+ // Minute in two digits
+ sal_Unicode aBuf[2];
+ aBuf[0] = '0';
+ aBuf[1] = '0' + nMin;
+ rRes = OUString(aBuf, std::size(aBuf));
}
else
{
- rRes = GetOUString();
+ rRes = OUString::number(nMin);
}
- break;
- default:
- rRes = GetOUString();
}
+ else if (aFmtStr.equalsIgnoreAsciiCase("w")) // VBA weekday number
+ {
+ rRes = OUString::number(implGetWeekDay(*number));
+ }
+ else if (aFmtStr.equalsIgnoreAsciiCase("y")) // VBA year day number
+ {
+ sal_Int16 nYear = implGetDateYear(*number);
+ double dBaseDate;
+ implDateSerial( nYear, 1, 1, true, SbDateCorrection::None, dBaseDate );
+ sal_Int32 nYear32 = 1 + sal_Int32(*number - dBaseDate);
+ rRes = OUString::number(nYear32);
+ }
+ else
+ {
+ pFormatter->PutandConvertEntry( aFmtStr, nCheckPos, nType, nIndex, LANGUAGE_ENGLISH_US, eLangType, true);
+ pFormatter->GetOutputString(*number, nIndex, rRes, &pCol);
+ }
+#endif
}
diff --git a/basic/source/sbx/sbxsng.cxx b/basic/source/sbx/sbxsng.cxx
deleted file mode 100644
index f97c6815d18a..000000000000
--- a/basic/source/sbx/sbxsng.cxx
+++ /dev/null
@@ -1,282 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include <sal/config.h>
-
-#include <o3tl/float_int_conversion.hxx>
-#include <vcl/errcode.hxx>
-#include <basic/sberrors.hxx>
-#include "sbxconv.hxx"
-
-float ImpGetSingle( const SbxValues* p )
-{
- SbxValues aTmp;
- float nRes;
-start:
- switch( +p->eType )
- {
- case SbxNULL:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- [[fallthrough]];
- case SbxEMPTY:
- nRes = 0; break;
- case SbxCHAR:
- nRes = p->nChar; break;
- case SbxBYTE:
- nRes = p->nByte; break;
- case SbxINTEGER:
- case SbxBOOL:
- nRes = p->nInteger; break;
- case SbxERROR:
- case SbxUSHORT:
- nRes = p->nUShort; break;
- case SbxLONG:
- nRes = static_cast<float>(p->nLong); break;
- case SbxULONG:
- nRes = static_cast<float>(p->nULong); break;
- case SbxSINGLE:
- nRes = p->nSingle; break;
- case SbxDECIMAL:
- case SbxBYREF | SbxDECIMAL:
- if( p->pDecimal )
- p->pDecimal->getSingle( nRes );
- else
- nRes = 0.0;
- break;
- case SbxDATE:
- case SbxDOUBLE:
- case SbxCURRENCY:
- case SbxSALINT64:
- case SbxSALUINT64:
- {
- double dVal;
- if( p->eType == SbxCURRENCY )
- dVal = ImpCurrencyToDouble( p->nInt64 );
- else if( p->eType == SbxSALINT64 )
- dVal = static_cast<float>(p->nInt64);
- else if( p->eType == SbxSALUINT64 )
- dVal = static_cast<float>(p->uInt64);
- else
- dVal = p->nDouble;
-
- if( dVal > SbxMAXSNG )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- nRes = static_cast< float >(SbxMAXSNG);
- }
- else if( dVal < SbxMINSNG )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- nRes = static_cast< float >(SbxMINSNG);
- }
- // tests for underflow - storing value too small for precision of single
- else if( dVal > 0 && dVal < SbxMAXSNG2 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- nRes = static_cast< float >(SbxMAXSNG2);
- }
- else if( dVal < 0 && dVal > SbxMINSNG2 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- nRes = static_cast< float >(SbxMINSNG2);
- }
- else
- nRes = static_cast<float>(dVal);
- break;
- }
- case SbxBYREF | SbxSTRING:
- case SbxSTRING:
- case SbxLPSTR:
- if( !p->pOUString )
- nRes = 0;
- else
- {
- double d;
- SbxDataType t;
- if( ImpScan( *p->pOUString, d, t, nullptr, true ) != ERRCODE_NONE )
- nRes = 0;
- else if( d > SbxMAXSNG )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- nRes = static_cast< float >(SbxMAXSNG);
- }
- else if( d < SbxMINSNG )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- nRes = static_cast< float >(SbxMINSNG);
- }
- else
- nRes = static_cast<float>(d);
- }
- break;
- case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
- nRes = pVal->GetSingle();
- else
- {
- SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT ); nRes = 0;
- }
- break;
- }
-
- case SbxBYREF | SbxCHAR:
- nRes = *p->pChar; break;
- case SbxBYREF | SbxBYTE:
- nRes = *p->pByte; break;
- case SbxBYREF | SbxINTEGER:
- case SbxBYREF | SbxBOOL:
- nRes = *p->pInteger; break;
- case SbxBYREF | SbxLONG:
- nRes = static_cast<float>(*p->pLong); break;
- case SbxBYREF | SbxULONG:
- nRes = static_cast<float>(*p->pULong); break;
- case SbxBYREF | SbxERROR:
- case SbxBYREF | SbxUSHORT:
- nRes = *p->pUShort; break;
- case SbxBYREF | SbxSINGLE:
- nRes = *p->pSingle; break;
- // from here had to be tested
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- aTmp.nDouble = *p->pDouble; goto ref;
- case SbxBYREF | SbxSALINT64:
- case SbxBYREF | SbxCURRENCY:
- aTmp.nInt64 = *p->pnInt64; goto ref;
- case SbxBYREF | SbxSALUINT64:
- aTmp.uInt64 = *p->puInt64; goto ref;
- ref:
- aTmp.eType = SbxDataType( p->eType & 0x0FFF );
- p = &aTmp; goto start;
-
- default:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION ); nRes = 0;
- }
- return nRes;
-}
-
-void ImpPutSingle( SbxValues* p, float n )
-{
- SbxValues aTmp;
-start:
- switch( +p->eType )
- {
- case SbxCHAR:
- aTmp.pChar = &p->nChar; goto direct;
- case SbxBYTE:
- aTmp.pByte = &p->nByte; goto direct;
- case SbxINTEGER:
- case SbxBOOL:
- aTmp.pInteger = &p->nInteger; goto direct;
- case SbxLONG:
- aTmp.pLong = &p->nLong; goto direct;
- case SbxULONG:
- aTmp.pULong = &p->nULong; goto direct;
- case SbxERROR:
- case SbxUSHORT:
- aTmp.pUShort = &p->nUShort; goto direct;
- case SbxCURRENCY:
- case SbxSALINT64:
- aTmp.pnInt64 = &p->nInt64; goto direct;
- case SbxSALUINT64:
- aTmp.puInt64 = &p->uInt64; goto direct;
- case SbxDECIMAL:
- case SbxBYREF | SbxDECIMAL:
- {
- SbxDecimal* pDec = ImpCreateDecimal( p );
- if( !pDec->setSingle( n ) )
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- break;
- }
- direct:
- aTmp.eType = SbxDataType( p->eType | SbxBYREF );
- p = &aTmp; goto start;
-
- // from here no tests
- case SbxSINGLE:
- p->nSingle = n; break;
- case SbxDATE:
- case SbxDOUBLE:
- p->nDouble = n; break;
-
- case SbxBYREF | SbxSTRING:
- case SbxSTRING:
- case SbxLPSTR:
- {
- if( !p->pOUString )
- p->pOUString = new OUString;
- // tdf#107953 - show 9 significant digits
- ImpCvtNum( static_cast<double>(n), 9, *p->pOUString );
- break;
- }
- case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
- pVal->PutSingle( n );
- else
- SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT );
- break;
- }
- case SbxBYREF | SbxCHAR:
- *p->pChar = ImpDoubleToChar(n); break;
- case SbxBYREF | SbxBYTE:
- *p->pByte = ImpDoubleToByte(n); break;
- case SbxBYREF | SbxINTEGER:
- case SbxBYREF | SbxBOOL:
- *p->pInteger = ImpDoubleToInteger(n); break;
- case SbxBYREF | SbxERROR:
- case SbxBYREF | SbxUSHORT:
- *p->pUShort = ImpDoubleToUShort(n); break;
- case SbxBYREF | SbxLONG:
- *p->pLong = ImpDoubleToLong(n); break;
- case SbxBYREF | SbxULONG:
- *p->pULong = ImpDoubleToULong(n); break;
- case SbxBYREF | SbxSINGLE:
- *p->pSingle = n; break;
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- *p->pDouble = static_cast<double>(n); break;
- case SbxBYREF | SbxSALINT64:
- *p->pnInt64 = ImpDoubleToSalInt64(n); break;
- case SbxBYREF | SbxSALUINT64:
- *p->puInt64 = ImpDoubleToSalUInt64(n); break;
- case SbxBYREF | SbxCURRENCY:
- double d;
- if( n > SbxMAXCURR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); d = SbxMAXCURR;
- }
- else if( n < SbxMINCURR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); d = SbxMINCURR;
- }
- else
- {
- d = n;
- }
- *p->pnInt64 = ImpDoubleToCurrency( d ); break;
-
- default:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- }
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/sbx/sbxstr.cxx b/basic/source/sbx/sbxstr.cxx
index 0c6fc19d514b..4e447bb600bb 100644
--- a/basic/source/sbx/sbxstr.cxx
+++ b/basic/source/sbx/sbxstr.cxx
@@ -302,7 +302,7 @@ SbxArray* StringToByteArray(const OUString& rStr)
OUString ByteArrayToString(SbxArray* pArr)
{
sal_uInt32 nCount = pArr->Count();
- OUStringBuffer aStrBuf;
+ OUStringBuffer aStrBuf((nCount + 1) / 2);
sal_Unicode aChar = 0;
for( sal_uInt32 i = 0 ; i < nCount ; i++ )
{
diff --git a/basic/source/sbx/sbxuint.cxx b/basic/source/sbx/sbxuint.cxx
deleted file mode 100644
index d8eeec4bc94d..000000000000
--- a/basic/source/sbx/sbxuint.cxx
+++ /dev/null
@@ -1,291 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include <sal/config.h>
-
-#include <o3tl/float_int_conversion.hxx>
-#include <vcl/errcode.hxx>
-#include <basic/sberrors.hxx>
-#include "sbxconv.hxx"
-
-sal_uInt16 ImpGetUShort( const SbxValues* p )
-{
- SbxValues aTmp;
- sal_uInt16 nRes;
-start:
- switch( +p->eType )
- {
- case SbxNULL:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- [[fallthrough]];
- case SbxEMPTY:
- nRes = 0; break;
- case SbxCHAR:
- nRes = p->nChar;
- break;
- case SbxBYTE:
- nRes = p->nByte; break;
- case SbxINTEGER:
- case SbxBOOL:
- if( p->nInteger < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = 0;
- }
- else
- nRes = p->nInteger;
- break;
- case SbxERROR:
- case SbxUSHORT:
- nRes = p->nUShort;
- break;
- case SbxLONG:
- if( p->nLong > SbxMAXUINT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXUINT;
- }
- else if( p->nLong < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = 0;
- }
- else
- nRes = static_cast<sal_uInt16>(p->nLong);
- break;
- case SbxULONG:
- if( p->nULong > SbxMAXUINT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXUINT;
- }
- else
- nRes = static_cast<sal_uInt16>(p->nULong);
- break;
- case SbxCURRENCY:
- if( p->nInt64 / CURRENCY_FACTOR > SbxMAXUINT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXUINT;
- }
- else if( p->nInt64 < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = 0;
- }
- else
- nRes = static_cast<sal_uInt16>(p->nInt64 / CURRENCY_FACTOR);
- break;
- case SbxSALINT64:
- if( p->nInt64 > SbxMAXUINT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXUINT;
- }
- else if( p->nInt64 < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = 0;
- }
- else
- nRes = static_cast<sal_uInt16>(p->nInt64);
- break;
- case SbxSALUINT64:
- if( p->uInt64 > SbxMAXUINT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXUINT;
- }
- else
- nRes = static_cast<sal_uInt16>(p->uInt64);
- break;
- case SbxSINGLE:
- nRes = ImpDoubleToUShort(p->nSingle);
- break;
- case SbxDATE:
- case SbxDOUBLE:
- case SbxDECIMAL:
- case SbxBYREF | SbxDECIMAL:
- {
- double dVal;
- if( p->eType == SbxDECIMAL )
- {
- dVal = 0.0;
- if( p->pDecimal )
- p->pDecimal->getDouble( dVal );
- }
- else
- dVal = p->nDouble;
-
- nRes = ImpDoubleToUShort(dVal);
- break;
- }
- case SbxBYREF | SbxSTRING:
- case SbxSTRING:
- case SbxLPSTR:
- if( !p->pOUString )
- nRes = 0;
- else
- {
- double d;
- SbxDataType t;
- if( ImpScan( *p->pOUString, d, t, nullptr, true ) != ERRCODE_NONE )
- nRes = 0;
- else
- nRes = ImpDoubleToUShort(d);
- }
- break;
- case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
- nRes = pVal->GetUShort();
- else
- {
- SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT ); nRes = 0;
- }
- break;
- }
-
- case SbxBYREF | SbxBYTE:
- nRes = *p->pByte; break;
- case SbxBYREF | SbxERROR:
- case SbxBYREF | SbxUSHORT:
- nRes = *p->pUShort; break;
-
- // from here on will be tested
- case SbxBYREF | SbxCHAR:
- aTmp.nChar = *p->pChar; goto ref;
- case SbxBYREF | SbxINTEGER:
- case SbxBYREF | SbxBOOL:
- aTmp.nInteger = *p->pInteger; goto ref;
- case SbxBYREF | SbxLONG:
- aTmp.nLong = *p->pLong; goto ref;
- case SbxBYREF | SbxULONG:
- aTmp.nULong = *p->pULong; goto ref;
- case SbxBYREF | SbxSINGLE:
- aTmp.nSingle = *p->pSingle; goto ref;
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- aTmp.nDouble = *p->pDouble; goto ref;
- case SbxBYREF | SbxCURRENCY:
- case SbxBYREF | SbxSALINT64:
- aTmp.nInt64 = *p->pnInt64; goto ref;
- case SbxBYREF | SbxSALUINT64:
- aTmp.uInt64 = *p->puInt64; goto ref;
- ref:
- aTmp.eType = SbxDataType( p->eType & 0x0FFF );
- p = &aTmp; goto start;
-
- default:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION ); nRes = 0;
- }
- return nRes;
-}
-
-void ImpPutUShort( SbxValues* p, sal_uInt16 n )
-{
- SbxValues aTmp;
-
-start:
- switch( +p->eType )
- {
- case SbxERROR:
- case SbxUSHORT:
- p->nUShort = n; break;
- case SbxLONG:
- p->nLong = n; break;
- case SbxULONG:
- p->nULong = n; break;
- case SbxSINGLE:
- p->nSingle = n; break;
- case SbxDATE:
- case SbxDOUBLE:
- p->nDouble = n; break;
- case SbxCURRENCY:
- p->nInt64 = n * CURRENCY_FACTOR; break;
- case SbxSALINT64:
- p->nInt64 = n; break;
- case SbxSALUINT64:
- p->uInt64 = n; break;
- case SbxDECIMAL:
- case SbxBYREF | SbxDECIMAL:
- ImpCreateDecimal( p )->setUInt( n );
- break;
-
- // from here on tests
- case SbxCHAR:
- aTmp.pChar = &p->nChar; goto direct;
- case SbxBYTE:
- aTmp.pByte = &p->nByte; goto direct;
- case SbxINTEGER:
- case SbxBOOL:
- aTmp.pInteger = &p->nInteger;
- direct:
- aTmp.eType = SbxDataType( p->eType | SbxBYREF );
- p = &aTmp; goto start;
-
- case SbxBYREF | SbxSTRING:
- case SbxSTRING:
- case SbxLPSTR:
- if( !p->pOUString )
- p->pOUString = new OUString;
- ImpCvtNum( static_cast<double>(n), 0, *p->pOUString );
- break;
- case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
- pVal->PutUShort( n );
- else
- SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT );
- break;
- }
-
- case SbxBYREF | SbxCHAR:
- *p->pChar = static_cast<sal_Unicode>(n); break;
- case SbxBYREF | SbxBYTE:
- if( n > SbxMAXBYTE )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXBYTE;
- }
- *p->pByte = static_cast<sal_uInt8>(n); break;
- case SbxBYREF | SbxINTEGER:
- case SbxBYREF | SbxBOOL:
- if( n > SbxMAXINT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXINT;
- }
- *p->pInteger = static_cast<sal_Int16>(n); break;
- case SbxBYREF | SbxERROR:
- case SbxBYREF | SbxUSHORT:
- *p->pUShort = n; break;
- case SbxBYREF | SbxLONG:
- *p->pLong = n; break;
- case SbxBYREF | SbxULONG:
- *p->pULong = n; break;
- case SbxBYREF | SbxSINGLE:
- *p->pSingle = n; break;
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- *p->pDouble = n; break;
- case SbxBYREF | SbxCURRENCY:
- *p->pnInt64 = n * CURRENCY_FACTOR; break;
- case SbxBYREF | SbxSALINT64:
- *p->pnInt64 = n; break;
- case SbxBYREF | SbxSALUINT64:
- *p->puInt64 = n; break;
-
- default:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- }
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/sbx/sbxulng.cxx b/basic/source/sbx/sbxulng.cxx
deleted file mode 100644
index fa872b8b0bb5..000000000000
--- a/basic/source/sbx/sbxulng.cxx
+++ /dev/null
@@ -1,267 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include <sal/config.h>
-
-#include <o3tl/float_int_conversion.hxx>
-#include <vcl/errcode.hxx>
-#include <basic/sberrors.hxx>
-#include "sbxconv.hxx"
-
-sal_uInt32 ImpGetULong( const SbxValues* p )
-{
- SbxValues aTmp;
- sal_uInt32 nRes;
-start:
- switch( +p->eType )
- {
- case SbxNULL:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- [[fallthrough]];
- case SbxEMPTY:
- nRes = 0; break;
- case SbxCHAR:
- nRes = p->nChar;
- break;
- case SbxBYTE:
- nRes = p->nByte; break;
- case SbxINTEGER:
- case SbxBOOL:
- if( p->nInteger < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = 0;
- }
- else
- nRes = p->nInteger;
- break;
- case SbxERROR:
- case SbxUSHORT:
- nRes = p->nUShort;
- break;
- case SbxLONG:
- if( p->nLong < 0 )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = 0;
- }
- else
- nRes = p->nLong;
- break;
- case SbxULONG:
- nRes = p->nULong; break;
- case SbxSINGLE:
- nRes = ImpDoubleToULong(p->nSingle);
- break;
- case SbxDATE:
- case SbxDOUBLE:
- case SbxSALINT64:
- case SbxSALUINT64:
- case SbxCURRENCY:
- case SbxDECIMAL:
- case SbxBYREF | SbxDECIMAL:
- {
- double dVal;
- if( p->eType == SbxCURRENCY )
- dVal = ImpCurrencyToDouble( p->nInt64 );
- else if( p->eType == SbxSALINT64 )
- dVal = static_cast< double >(p->nInt64);
- else if( p->eType == SbxSALUINT64 )
- dVal = ImpSalUInt64ToDouble( p->uInt64 );
- else if( p->eType == SbxDECIMAL )
- {
- dVal = 0.0;
- if( p->pDecimal )
- p->pDecimal->getDouble( dVal );
- }
- else
- dVal = p->nDouble;
-
- nRes = ImpDoubleToULong(dVal);
- break;
- }
- case SbxBYREF | SbxSTRING:
- case SbxSTRING:
- case SbxLPSTR:
- if( !p->pOUString )
- nRes = 0;
- else
- {
- double d;
- SbxDataType t;
- if( ImpScan( *p->pOUString, d, t, nullptr, true ) != ERRCODE_NONE )
- nRes = 0;
- else
- nRes = ImpDoubleToULong(d);
- }
- break;
- case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
- nRes = pVal->GetULong();
- else
- {
- SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT ); nRes = 0;
- }
- break;
- }
-
- case SbxBYREF | SbxBYTE:
- nRes = *p->pByte; break;
- case SbxBYREF | SbxERROR:
- case SbxBYREF | SbxUSHORT:
- nRes = *p->pUShort; break;
- case SbxBYREF | SbxULONG:
- nRes = *p->pULong; break;
-
- // from here on tests
- case SbxBYREF | SbxCHAR:
- aTmp.nChar = *p->pChar; goto ref;
- case SbxBYREF | SbxINTEGER:
- case SbxBYREF | SbxBOOL:
- aTmp.nInteger = *p->pInteger; goto ref;
- case SbxBYREF | SbxLONG:
- aTmp.nLong = *p->pLong; goto ref;
- case SbxBYREF | SbxSINGLE:
- aTmp.nSingle = *p->pSingle; goto ref;
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- aTmp.nDouble = *p->pDouble; goto ref;
- case SbxBYREF | SbxCURRENCY:
- case SbxBYREF | SbxSALINT64:
- aTmp.nInt64 = *p->pnInt64; goto ref;
- case SbxBYREF | SbxSALUINT64:
- aTmp.uInt64 = *p->puInt64; goto ref;
- ref:
- aTmp.eType = SbxDataType( p->eType & 0x0FFF );
- p = &aTmp; goto start;
-
- default:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION ); nRes = 0;
- }
- return nRes;
-}
-
-void ImpPutULong( SbxValues* p, sal_uInt32 n )
-{
- SbxValues aTmp;
-start:
- switch( +p->eType )
- {
- case SbxULONG:
- p->nULong = n; break;
- case SbxSINGLE:
- p->nSingle = static_cast<float>(n); break;
- case SbxDATE:
- case SbxDOUBLE:
- p->nDouble = n; break;
- case SbxCURRENCY:
- case SbxSALINT64:
- aTmp.pnInt64 = &p->nInt64; goto direct;
- case SbxSALUINT64:
- p->uInt64 = n; break;
- case SbxDECIMAL:
- case SbxBYREF | SbxDECIMAL:
- ImpCreateDecimal( p )->setULong( n );
- break;
-
- // from here on tests
- case SbxCHAR:
- aTmp.pChar = &p->nChar; goto direct;
- case SbxUINT:
- aTmp.pByte = &p->nByte; goto direct;
- case SbxINTEGER:
- case SbxBOOL:
- aTmp.pInteger = &p->nInteger; goto direct;
- case SbxLONG:
- aTmp.pLong = &p->nLong; goto direct;
- case SbxERROR:
- case SbxUSHORT:
- aTmp.pUShort = &p->nUShort; goto direct;
- direct:
- aTmp.eType = SbxDataType( p->eType | SbxBYREF );
- p = &aTmp; goto start;
-
- case SbxBYREF | SbxSTRING:
- case SbxSTRING:
- case SbxLPSTR:
- if( !p->pOUString )
- p->pOUString = new OUString;
- ImpCvtNum( static_cast<double>(n), 0, *p->pOUString );
- break;
- case SbxOBJECT:
- {
- SbxValue* pVal = dynamic_cast<SbxValue*>( p->pObj );
- if( pVal )
- pVal->PutULong( n );
- else
- SbxBase::SetError( ERRCODE_BASIC_NO_OBJECT );
- break;
- }
- case SbxBYREF | SbxCHAR:
- if( n > SbxMAXCHAR )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXCHAR;
- }
- *p->pChar = static_cast<sal_Unicode>(n); break;
- case SbxBYREF | SbxBYTE:
- if( n > SbxMAXBYTE )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXBYTE;
- }
- *p->pByte = static_cast<sal_uInt8>(n); break;
- case SbxBYREF | SbxINTEGER:
- case SbxBYREF | SbxBOOL:
- if( n > SbxMAXINT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXINT;
- }
- *p->pInteger = static_cast<sal_Int16>(n); break;
- case SbxBYREF | SbxERROR:
- case SbxBYREF | SbxUSHORT:
- if( n > SbxMAXUINT )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXUINT;
- }
- *p->pUShort = static_cast<sal_uInt16>(n); break;
- case SbxBYREF | SbxLONG:
- if( n > SbxMAXLNG )
- {
- SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXLNG;
- }
- *p->pLong = static_cast<sal_Int32>(n); break;
- case SbxBYREF | SbxULONG:
- *p->pULong = n; break;
- case SbxBYREF | SbxSINGLE:
- *p->pSingle = static_cast<float>(n); break;
- case SbxBYREF | SbxDATE:
- case SbxBYREF | SbxDOUBLE:
- *p->pDouble = n; break;
- case SbxBYREF | SbxCURRENCY:
- *p->pnInt64 = n * CURRENCY_FACTOR; break;
- case SbxBYREF | SbxSALINT64:
- *p->pnInt64 = n; break;
- case SbxBYREF | SbxSALUINT64:
- *p->puInt64 = n; break;
-
- default:
- SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
- }
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/sbx/sbxvalue.cxx b/basic/source/sbx/sbxvalue.cxx
index 7530f88dc6c6..8fac8fd867ef 100644
--- a/basic/source/sbx/sbxvalue.cxx
+++ b/basic/source/sbx/sbxvalue.cxx
@@ -22,7 +22,9 @@
#include <math.h>
#include <string_view>
+#include <osl/diagnose.h>
#include <o3tl/float_int_conversion.hxx>
+#include <o3tl/safeint.hxx>
#include <tools/debug.hxx>
#include <tools/stream.hxx>
#include <sal/log.hxx>
@@ -31,6 +33,7 @@
#include <sbunoobj.hxx>
#include "sbxconv.hxx"
#include <runtime.hxx>
+#include <filefmt.hxx>
///////////////////////////// constructors
@@ -489,31 +492,69 @@ bool SbxValue::Put( const SbxValues& rVal )
return bRes;
}
+// with advanced evaluation (International, "TRUE"/"FALSE")
+static OUString ImpConvStringExt(const OUString& rSrc, SbxDataType eTargetType)
+{
+ // only special cases are handled, nothing on default
+ switch (eTargetType)
+ {
+ // Consider international for floating point. Following default conversion (SbxValue::Put)
+ // assumes internationalized strings, but the input may use standard decimal dot.
+ case SbxSINGLE:
+ case SbxDOUBLE:
+ case SbxCURRENCY:
+ {
+ sal_Unicode cDecimalSep, cThousandSep, cDecimalSepAlt;
+ ImpGetIntntlSep(cDecimalSep, cThousandSep, cDecimalSepAlt);
+
+ // 1. If any of the returned decimal separators is dot, do nothing
+ if (cDecimalSep == '.' || cDecimalSepAlt == '.')
+ break;
+
+ // 2. If there are internationalized separators already, do nothing
+ if (rSrc.indexOf(cDecimalSep) >= 0 || rSrc.indexOf(cDecimalSepAlt) >= 0)
+ break;
+
+ // 3. Replace all dots with the primary separator. This resolves possible ambiguity with
+ // dot as thousand separator, in favor of decimal dot; unlike "only change one dot"
+ // approach, this prevents inconsistency like converting "234.567" to a number with
+ // floating point 234.567, while "1.234.567" to a whole number 1234567. The latter will
+ // be rejected now.
+ return rSrc.replaceAll(".", OUStringChar(cDecimalSep));
+ }
+
+ // check as string in case of sal_Bool sal_True and sal_False
+ case SbxBOOL:
+ if (rSrc.equalsIgnoreAsciiCase("true"))
+ return OUString::number(SbxTRUE);
+ if (rSrc.equalsIgnoreAsciiCase("false"))
+ return OUString::number(SbxFALSE);
+ break;
+
+ default:
+ break;
+ }
+
+ return rSrc;
+}
+
// From 1996-03-28:
// Method to execute a pretreatment of the strings at special types.
// In particular necessary for BASIC-IDE, so that
// the output in the Watch-Window can be written back with PutStringExt,
-// if Float were declared with ',' as the decimal separator or BOOl
-// explicit with "TRUE" or "FALSE".
-// Implementation in ImpConvStringExt (SBXSCAN.CXX)
+// if Float were declared with either '.' or locale-specific decimal
+// separator, or BOOl explicit with "TRUE" or "FALSE".
+// Implementation in ImpConvStringExt
void SbxValue::PutStringExt( const OUString& r )
{
- // Copy; if it is Unicode convert it immediately
- OUString aStr( r );
-
// Identify the own type (not as in Put() with TheRealValue(),
// Objects are not handled anyway)
SbxDataType eTargetType = SbxDataType( aData.eType & 0x0FFF );
+ OUString aStr(ImpConvStringExt(r, eTargetType));
// tinker a Source-Value
SbxValues aRes(SbxSTRING);
-
- // Only if really something was converted, take the copy,
- // otherwise take the original (Unicode remains)
- if( ImpConvStringExt( aStr, eTargetType ) )
- aRes.pOUString = &aStr;
- else
- aRes.pOUString = const_cast<OUString*>(&r);
+ aRes.pOUString = &aStr;
// #34939: For Strings which contain a number, and if this has a Num-Type,
// set a Fixed flag so that the type will not be changed
@@ -651,12 +692,17 @@ bool SbxValue::ImpIsNumeric( bool bOnlyIntntl ) const
OUString s( *aData.pOUString );
double n;
SbxDataType t2;
- sal_uInt16 nLen = 0;
- if( ImpScan( s, n, t2, &nLen, bOnlyIntntl ) == ERRCODE_NONE )
- return nLen == s.getLength();
+ sal_Int32 nLen = 0;
+ bool bHasNumber = false;
+ if( ImpScan( s, n, t2, &nLen, &bHasNumber, bOnlyIntntl ) == ERRCODE_NONE )
+ return nLen == s.getLength() && bHasNumber;
}
return false;
}
+#if HAVE_FEATURE_SCRIPTING
+ else if (t == SbxBOOL && bOnlyIntntl && SbiRuntime::isVBAEnabled())
+ return true;
+#endif
else
return t == SbxEMPTY
|| ( t >= SbxINTEGER && t <= SbxCURRENCY )
@@ -686,40 +732,40 @@ bool SbxValue::SetType( SbxDataType t )
}
t = SbxEMPTY;
}
- if( ( t & 0x0FFF ) != ( aData.eType & 0x0FFF ) )
+ if( ( t & 0x0FFF ) == ( aData.eType & 0x0FFF ) )
+ return true;
+
+ if( !CanWrite() || IsFixed() )
{
- if( !CanWrite() || IsFixed() )
- {
- SetError( ERRCODE_BASIC_CONVERSION );
- return false;
- }
- else
+ SetError( ERRCODE_BASIC_CONVERSION );
+ return false;
+ }
+ else
+ {
+ // De-allocate potential objects
+ switch( aData.eType )
{
- // De-allocate potential objects
- switch( aData.eType )
- {
- case SbxSTRING:
- delete aData.pOUString;
- break;
- case SbxOBJECT:
- if( aData.pObj && aData.pObj != this )
- {
- SAL_WARN("basic.sbx", "Not at Parent-Prop - otherwise CyclicRef");
- SbxVariable *pThisVar = dynamic_cast<SbxVariable*>( this );
- sal_uInt32 nSlotId = pThisVar
- ? pThisVar->GetUserData() & 0xFFFF
- : 0;
- DBG_ASSERT( nSlotId != 5345 || pThisVar->GetName() == "Parent",
- "SID_PARENTOBJECT is not named 'Parent'" );
- bool bParentProp = nSlotId == 5345;
- if ( !bParentProp )
- aData.pObj->ReleaseRef();
- }
- break;
- default: break;
- }
- aData.clear(t);
+ case SbxSTRING:
+ delete aData.pOUString;
+ break;
+ case SbxOBJECT:
+ if( aData.pObj && aData.pObj != this )
+ {
+ SAL_WARN("basic.sbx", "Not at Parent-Prop - otherwise CyclicRef");
+ SbxVariable *pThisVar = dynamic_cast<SbxVariable*>( this );
+ sal_uInt32 nSlotId = pThisVar
+ ? pThisVar->GetUserData() & 0xFFFF
+ : 0;
+ DBG_ASSERT( nSlotId != 5345 || pThisVar->GetName() == "Parent",
+ "SID_PARENTOBJECT is not named 'Parent'" );
+ bool bParentProp = nSlotId == 5345;
+ if ( !bParentProp )
+ aData.pObj->ReleaseRef();
+ }
+ break;
+ default: break;
}
+ aData.clear(t);
}
return true;
}
@@ -769,6 +815,40 @@ bool SbxValue::Convert( SbxDataType eTo )
}
////////////////////////////////// Calculating
+static sal_Int64 MulAndDiv(sal_Int64 n, sal_Int64 mul, sal_Int64 div)
+{
+ if (div == 0)
+ {
+ SbxBase::SetError(ERRCODE_BASIC_ZERODIV);
+ return n;
+ }
+ auto errorValue = [](sal_Int64 x, sal_Int64 y, sal_Int64 z)
+ {
+ const int i = (x < 0 ? -1 : 1) * (y < 0 ? -1 : 1) * (z < 0 ? -1 : 1);
+ return i == 1 ? SAL_MAX_INT64 : SAL_MIN_INT64;
+ };
+ sal_Int64 result;
+ // If x * integral part of (mul/div) overflows -> product does not fit
+ if (o3tl::checked_multiply(n, mul / div, result))
+ {
+ SbxBase::SetError(ERRCODE_BASIC_MATH_OVERFLOW);
+ return errorValue(n, mul, div);
+ }
+ if (sal_Int64 mul_frac = mul % div)
+ {
+ // can't overflow: mul_frac < div
+ sal_Int64 result_frac = n / div * mul_frac;
+ if (sal_Int64 x_frac = n % div)
+ result_frac += x_frac * mul_frac / div;
+ if (o3tl::checked_add(result, result_frac, result))
+ {
+ SbxBase::SetError(ERRCODE_BASIC_MATH_OVERFLOW);
+ return errorValue(n, mul, div);
+ }
+ }
+ return result;
+}
+
bool SbxValue::Compute( SbxOperator eOp, const SbxValue& rOp )
{
#if !HAVE_FEATURE_SCRIPTING
@@ -839,10 +919,12 @@ bool SbxValue::Compute( SbxOperator eOp, const SbxValue& rOp )
{
if( GetType() == eOpType )
{
- if( GetType() == SbxSALUINT64 || GetType() == SbxSALINT64
- || GetType() == SbxCURRENCY || GetType() == SbxULONG )
+ if (GetType() == SbxSALUINT64 || GetType() == SbxSALINT64 || GetType() == SbxULONG)
aL.eType = aR.eType = GetType();
- else if ( bVBAInterop && eOpType == SbxBOOL )
+ else if (GetType() == SbxCURRENCY)
+ aL.eType = aR.eType = SbxSALINT64; // Convert to integer value before operation
+ // tdf#145960 - return type of boolean operators should be of type boolean
+ else if ( eOpType == SbxBOOL && eOp != SbxMOD && eOp != SbxIDIV )
aL.eType = aR.eType = SbxBOOL;
else
aL.eType = aR.eType = SbxLONG;
@@ -850,9 +932,9 @@ bool SbxValue::Compute( SbxOperator eOp, const SbxValue& rOp )
else
aL.eType = aR.eType = SbxLONG;
- if( rOp.Get( aR ) ) // re-do Get after type assigns above
+ if (rOp.Get(aR) && Get(aL)) // re-do Get after type assigns above
{
- if( Get( aL ) ) switch( eOp )
+ switch( eOp )
{
/* TODO: For SbxEMPTY operands with boolean operators use
* the VBA Nothing definition of Comparing Nullable Types?
@@ -865,16 +947,10 @@ bool SbxValue::Compute( SbxOperator eOp, const SbxValue& rOp )
* string.
*/
case SbxIDIV:
- if( aL.eType == SbxCURRENCY )
- if( !aR.nInt64 ) SetError( ERRCODE_BASIC_ZERODIV );
- else {
- aL.nInt64 /= aR.nInt64;
- aL.nInt64 *= CURRENCY_FACTOR;
- }
- else if( aL.eType == SbxSALUINT64 )
+ if( aL.eType == SbxSALUINT64 )
if( !aR.uInt64 ) SetError( ERRCODE_BASIC_ZERODIV );
else aL.uInt64 /= aR.uInt64;
- else if( aL.eType == SbxSALINT64 )
+ else if( aL.eType == SbxCURRENCY || aL.eType == SbxSALINT64 )
if( !aR.nInt64 ) SetError( ERRCODE_BASIC_ZERODIV );
else aL.nInt64 /= aR.nInt64;
else if( aL.eType == SbxLONG )
@@ -987,92 +1063,34 @@ bool SbxValue::Compute( SbxOperator eOp, const SbxValue& rOp )
}
else if( GetType() == SbxCURRENCY || rOp.GetType() == SbxCURRENCY )
{
- aL.eType = SbxCURRENCY;
- aR.eType = SbxCURRENCY;
+ aL.eType = aR.eType = SbxCURRENCY;
- if( rOp.Get( aR ) )
+ if (rOp.Get(aR) && Get(aL))
{
- if( Get( aL ) ) switch( eOp )
+ switch (eOp)
{
case SbxMUL:
- {
- // first overflow check: see if product will fit - test real value of product (hence 2 curr factors)
- double dTest = static_cast<double>(aL.nInt64) * static_cast<double>(aR.nInt64) / double(CURRENCY_FACTOR_SQUARE);
- if( dTest < SbxMINCURR || SbxMAXCURR < dTest)
- {
- aL.nInt64 = SAL_MAX_INT64;
- if( dTest < SbxMINCURR ) aL.nInt64 = SAL_MIN_INT64;
- SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- break;
- }
- // second overflow check: see if unscaled product overflows - if so use doubles
- dTest = static_cast<double>(aL.nInt64) * static_cast<double>(aR.nInt64);
- if( !(o3tl::convertsToAtLeast(dTest, SAL_MIN_INT64)
- && o3tl::convertsToAtMost(dTest, SAL_MAX_INT64)))
- {
- aL.nInt64 = static_cast<sal_Int64>( dTest / double(CURRENCY_FACTOR) );
- break;
- }
- // precise calc: multiply then scale back (move decimal pt)
- aL.nInt64 *= aR.nInt64;
- aL.nInt64 /= CURRENCY_FACTOR;
- break;
- }
+ aL.nInt64 = MulAndDiv(aL.nInt64, aR.nInt64, CURRENCY_FACTOR);
+ break;
case SbxDIV:
- {
- if( !aR.nInt64 )
- {
- SetError( ERRCODE_BASIC_ZERODIV );
- break;
- }
- // first overflow check: see if quotient will fit - calc real value of quotient (curr factors cancel)
- double dTest = static_cast<double>(aL.nInt64) / static_cast<double>(aR.nInt64);
- if( dTest < SbxMINCURR || SbxMAXCURR < dTest)
- {
- SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- break;
- }
- // second overflow check: see if scaled dividend overflows - if so use doubles
- dTest = static_cast<double>(aL.nInt64) * double(CURRENCY_FACTOR);
- if( !(o3tl::convertsToAtLeast(dTest, SAL_MIN_INT64)
- && o3tl::convertsToAtMost(dTest, SAL_MAX_INT64)))
- {
- aL.nInt64 = static_cast<sal_Int64>(dTest / static_cast<double>(aR.nInt64));
- break;
- }
- // precise calc: scale (move decimal pt) then divide
- aL.nInt64 *= CURRENCY_FACTOR;
- aL.nInt64 /= aR.nInt64;
- break;
- }
+ aL.nInt64 = MulAndDiv(aL.nInt64, CURRENCY_FACTOR, aR.nInt64);
+ break;
case SbxPLUS:
- {
- double dTest = ( static_cast<double>(aL.nInt64) + static_cast<double>(aR.nInt64) ) / double(CURRENCY_FACTOR);
- if( dTest < SbxMINCURR || SbxMAXCURR < dTest)
- {
- SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- break;
- }
- aL.nInt64 += aR.nInt64;
- break;
- }
+ if (o3tl::checked_add(aL.nInt64, aR.nInt64, aL.nInt64))
+ SetError(ERRCODE_BASIC_MATH_OVERFLOW);
+ break;
- case SbxMINUS:
- {
- double dTest = ( static_cast<double>(aL.nInt64) - static_cast<double>(aR.nInt64) ) / double(CURRENCY_FACTOR);
- if( dTest < SbxMINCURR || SbxMAXCURR < dTest)
- {
- SetError( ERRCODE_BASIC_MATH_OVERFLOW );
- break;
- }
- aL.nInt64 -= aR.nInt64;
- break;
- }
case SbxNEG:
- aL.nInt64 = -aL.nInt64;
+ // Use subtraction; allows to detect negation of SAL_MIN_INT64
+ aR.nInt64 = std::exchange(aL.nInt64, 0);
+ [[fallthrough]];
+ case SbxMINUS:
+ if (o3tl::checked_sub(aL.nInt64, aR.nInt64, aL.nInt64))
+ SetError(ERRCODE_BASIC_MATH_OVERFLOW);
break;
+
default:
SetError( ERRCODE_BASIC_BAD_ARGUMENT );
}
@@ -1139,6 +1157,29 @@ Lbl_OpIsEmpty:
// The comparison routine deliver TRUE or FALSE.
+template <typename T> static bool CompareNormal(const T& l, const T& r, SbxOperator eOp)
+{
+ switch (eOp)
+ {
+ case SbxEQ:
+ return l == r;
+ case SbxNE:
+ return l != r;
+ case SbxLT:
+ return l < r;
+ case SbxGT:
+ return l > r;
+ case SbxLE:
+ return l <= r;
+ case SbxGE:
+ return l >= r;
+ default:
+ assert(false);
+ }
+ SbxBase::SetError(ERRCODE_BASIC_BAD_ARGUMENT);
+ return false;
+}
+
bool SbxValue::Compare( SbxOperator eOp, const SbxValue& rOp ) const
{
#if !HAVE_FEATURE_SCRIPTING
@@ -1181,23 +1222,8 @@ bool SbxValue::Compare( SbxOperator eOp, const SbxValue& rOp ) const
if( GetType() == SbxSTRING || rOp.GetType() == SbxSTRING )
{
aL.eType = aR.eType = SbxSTRING;
- if( Get( aL ) && rOp.Get( aR ) ) switch( eOp )
- {
- case SbxEQ:
- bRes = ( *aL.pOUString == *aR.pOUString ); break;
- case SbxNE:
- bRes = ( *aL.pOUString != *aR.pOUString ); break;
- case SbxLT:
- bRes = ( *aL.pOUString < *aR.pOUString ); break;
- case SbxGT:
- bRes = ( *aL.pOUString > *aR.pOUString ); break;
- case SbxLE:
- bRes = ( *aL.pOUString <= *aR.pOUString ); break;
- case SbxGE:
- bRes = ( *aL.pOUString >= *aR.pOUString ); break;
- default:
- SetError( ERRCODE_BASIC_BAD_ARGUMENT );
- }
+ if (Get(aL) && rOp.Get(aR))
+ bRes = CompareNormal(*aL.pOUString, *aR.pOUString, eOp);
}
// From 1995-12-19: If SbxSINGLE participate, then convert to SINGLE,
// otherwise it shows a numeric error
@@ -1205,23 +1231,7 @@ bool SbxValue::Compare( SbxOperator eOp, const SbxValue& rOp ) const
{
aL.eType = aR.eType = SbxSINGLE;
if( Get( aL ) && rOp.Get( aR ) )
- switch( eOp )
- {
- case SbxEQ:
- bRes = ( aL.nSingle == aR.nSingle ); break;
- case SbxNE:
- bRes = ( aL.nSingle != aR.nSingle ); break;
- case SbxLT:
- bRes = ( aL.nSingle < aR.nSingle ); break;
- case SbxGT:
- bRes = ( aL.nSingle > aR.nSingle ); break;
- case SbxLE:
- bRes = ( aL.nSingle <= aR.nSingle ); break;
- case SbxGE:
- bRes = ( aL.nSingle >= aR.nSingle ); break;
- default:
- SetError( ERRCODE_BASIC_BAD_ARGUMENT );
- }
+ bRes = CompareNormal(aL.nSingle, aR.nSingle, eOp);
}
else if( GetType() == SbxDECIMAL && rOp.GetType() == SbxDECIMAL )
{
@@ -1256,6 +1266,12 @@ bool SbxValue::Compare( SbxOperator eOp, const SbxValue& rOp ) const
releaseDecimalPtr( aL.pDecimal );
releaseDecimalPtr( aR.pDecimal );
}
+ else if (GetType() == SbxCURRENCY && rOp.GetType() == SbxCURRENCY)
+ {
+ aL.eType = aR.eType = GetType();
+ if (Get(aL) && rOp.Get(aR))
+ bRes = CompareNormal(aL.nInt64, aR.nInt64, eOp);
+ }
// Everything else comparing on a SbxDOUBLE-Basis
else
{
@@ -1263,23 +1279,7 @@ bool SbxValue::Compare( SbxOperator eOp, const SbxValue& rOp ) const
bool bGetL = Get( aL );
bool bGetR = rOp.Get( aR );
if( bGetL && bGetR )
- switch( eOp )
- {
- case SbxEQ:
- bRes = ( aL.nDouble == aR.nDouble ); break;
- case SbxNE:
- bRes = ( aL.nDouble != aR.nDouble ); break;
- case SbxLT:
- bRes = ( aL.nDouble < aR.nDouble ); break;
- case SbxGT:
- bRes = ( aL.nDouble > aR.nDouble ); break;
- case SbxLE:
- bRes = ( aL.nDouble <= aR.nDouble ); break;
- case SbxGE:
- bRes = ( aL.nDouble >= aR.nDouble ); break;
- default:
- SetError( ERRCODE_BASIC_BAD_ARGUMENT );
- }
+ bRes = CompareNormal(aL.nDouble, aR.nDouble, eOp);
// at least one value was got
// if this is VBA then a conversion error for one
// side will yield a false result of an equality test
@@ -1316,7 +1316,9 @@ bool SbxValue::LoadData( SvStream& r, sal_uInt16 )
case SbxINTEGER:
r.ReadInt16( aData.nInteger ); break;
case SbxLONG:
- r.ReadInt32( aData.nLong ); break;
+ case SbxDATAOBJECT:
+ r.ReadInt32( aData.nLong );
+ break;
case SbxSINGLE:
{
// Floats as ASCII
@@ -1324,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 ) != ERRCODE_NONE || t == SbxDOUBLE )
{
aData.nSingle = 0.0F;
return false;
@@ -1339,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 ) != ERRCODE_NONE )
{
aData.nDouble = 0.0;
return false;
@@ -1447,9 +1449,6 @@ bool SbxValue::LoadData( SvStream& r, sal_uInt16 )
case SbxNULL:
case SbxVOID:
break;
- case SbxDATAOBJECT:
- r.ReadInt32( aData.nLong );
- break;
// #78919 For backwards compatibility
case SbxWSTRING:
case SbxWCHAR:
@@ -1464,7 +1463,7 @@ bool SbxValue::LoadData( SvStream& r, sal_uInt16 )
return true;
}
- bool SbxValue::StoreData( SvStream& r ) const
+ std::pair<bool, sal_uInt32> SbxValue::StoreData( SvStream& r ) const
{
sal_uInt16 nType = sal::static_int_cast< sal_uInt16 >(aData.eType);
r.WriteUInt16( nType );
@@ -1474,7 +1473,9 @@ bool SbxValue::LoadData( SvStream& r, sal_uInt16 )
case SbxINTEGER:
r.WriteInt16( aData.nInteger ); break;
case SbxLONG:
- r.WriteInt32( aData.nLong ); break;
+ case SbxDATAOBJECT:
+ r.WriteInt32( aData.nLong );
+ break;
case SbxDATE:
// #49935: Save as double, otherwise an error during the read in
const_cast<SbxValue*>(this)->aData.eType = static_cast<SbxDataType>( ( nType & 0xF000 ) | SbxDOUBLE );
@@ -1549,18 +1550,15 @@ bool SbxValue::LoadData( SvStream& r, sal_uInt16 )
case SbxNULL:
case SbxVOID:
break;
- case SbxDATAOBJECT:
- r.WriteInt32( aData.nLong );
- break;
// #78919 For backwards compatibility
case SbxWSTRING:
case SbxWCHAR:
break;
default:
SAL_WARN( "basic.sbx", "Saving a non-supported data type" );
- return false;
+ return { false, 0 };
}
- return true;
+ return { true, B_IMG_VERSION_12 };
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/sbx/sbxvar.cxx b/basic/source/sbx/sbxvar.cxx
index b8be36ec2735..97f7c0347ad9 100644
--- a/basic/source/sbx/sbxvar.cxx
+++ b/basic/source/sbx/sbxvar.cxx
@@ -27,11 +27,14 @@
#include "sbxres.hxx"
#include "sbxconv.hxx"
#include <sbunoobj.hxx>
-#include <rtl/character.hxx>
#include <rtl/ustrbuf.hxx>
#include <sal/log.hxx>
+#include <global.hxx>
+#include <unotools/transliterationwrapper.hxx>
#include <com/sun/star/uno/XInterface.hpp>
+#include <utility>
+#include <filefmt.hxx>
using namespace com::sun::star::uno;
// SbxVariable
@@ -179,10 +182,17 @@ void SbxVariable::SetParameters( SbxArray* p )
// Name of the variables
+// static
+OUString SbxVariable::NameToCaseInsensitiveName(const OUString& rName)
+{
+ return SbGlobal::GetTransliteration().transliterate(rName, 0, rName.getLength());
+}
+
void SbxVariable::SetName( const OUString& rName )
{
maName = rName;
nHash = MakeHashCode( rName );
+ maNameCI.clear();
}
const OUString& SbxVariable::GetName( SbxNameType t ) const
@@ -192,6 +202,12 @@ const OUString& SbxVariable::GetName( SbxNameType t ) const
{
return maName;
}
+ if (t == SbxNameType::CaseInsensitive)
+ {
+ if (maNameCI.isEmpty() && !maName.isEmpty())
+ maNameCI = NameToCaseInsensitiveName(maName);
+ return maNameCI;
+ }
// Request parameter-information (not for objects)
const_cast<SbxVariable*>(this)->GetInfo();
// Append nothing, if it is a simple property (no empty brackets)
@@ -199,14 +215,15 @@ const OUString& SbxVariable::GetName( SbxNameType t ) const
{
return maName;
}
- sal_Unicode cType = ' ';
OUStringBuffer aTmp( maName );
- // short type? Then fetch it, possible this is 0.
- SbxDataType et = GetType();
if( t == SbxNameType::ShortTypes )
{
+ sal_Unicode cType = ' ';
+ // short type? Then fetch it, possible this is 0.
+ SbxDataType et = GetType();
if( et <= SbxSTRING )
{
+ assert(et >= 0 && size_t(et) < std::size(cSuffixes) - 1);
cType = cSuffixes[ et ];
}
if( cType != ' ' )
@@ -233,7 +250,7 @@ const OUString& SbxVariable::GetName( SbxNameType t ) const
aTmp.append( GetSbxRes( StringId::ByRef ) );
}
aTmp.append( i->aName );
- cType = ' ';
+ sal_Unicode cType = ' ';
// short type? Then fetch it, possible this is 0.
if( t == SbxNameType::ShortTypes )
{
@@ -281,7 +298,10 @@ SbxVariable& SbxVariable::operator=( const SbxVariable& r )
{
SbxValue::operator=( r );
// tdf#144353 - copy information about a missing parameter. See SbiRuntime::SetIsMissing.
- if (r.pInfo && !dynamic_cast<const SbxMethod*>(&r))
+ // We cannot unconditionally assign the data about a variable because we would overwrite
+ // the information about parameters (name, type, flags, and ids). For instance, in the case
+ // where a method will be initialized with a literal.
+ if (!pInfo)
pInfo = r.pInfo;
m_aDeclareClassName = r.m_aDeclareClassName;
m_xComListener = r.m_xComListener;
@@ -437,7 +457,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 ) != ERRCODE_NONE || t == SbxDOUBLE )
{
aTmp.nSingle = 0;
return false;
@@ -452,7 +472,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 ) != ERRCODE_NONE )
{
aTmp.nDouble = 0;
return false;
@@ -496,7 +516,7 @@ bool SbxVariable::LoadData( SvStream& rStrm, sal_uInt16 nVer )
return true;
}
-bool SbxVariable::StoreData( SvStream& rStrm ) const
+std::pair<bool, sal_uInt32> SbxVariable::StoreData( SvStream& rStrm ) const
{
rStrm.WriteUChar( 0xFF ); // Marker
bool bValStore;
@@ -513,16 +533,16 @@ bool SbxVariable::StoreData( SvStream& rStrm ) const
// So that the method will not be executed in any case!
// CAST, to avoid const!
pThis->SetFlag( SbxFlagBits::NoBroadcast );
- bValStore = SbxValue::StoreData( rStrm );
+ bValStore = SbxValue::StoreData( rStrm ).first;
pThis->ResetFlag( SbxFlagBits::NoBroadcast );
}
else
{
- bValStore = SbxValue::StoreData( rStrm );
+ bValStore = SbxValue::StoreData( rStrm ).first;
}
if( !bValStore )
{
- return false;
+ return { false, 0 };
}
write_uInt16_lenPrefixed_uInt8s_FromOUString(rStrm, maName,
RTL_TEXTENCODING_ASCII_US);
@@ -536,7 +556,7 @@ bool SbxVariable::StoreData( SvStream& rStrm ) const
{
rStrm.WriteUChar( 0 );
}
- return true;
+ return { true, B_IMG_VERSION_12 };
}
// SbxInfo
@@ -545,26 +565,28 @@ SbxInfo::SbxInfo()
: nHelpId(0)
{}
-SbxInfo::SbxInfo( const OUString& r, sal_uInt32 n )
- : aHelpFile( r ), nHelpId( n )
+SbxInfo::SbxInfo( OUString a, sal_uInt32 n )
+ : aHelpFile(std::move( a )), nHelpId( n )
{}
+SbxHint::~SbxHint() = default;
+
void SbxVariable::Dump( SvStream& rStrm, bool bFill )
{
OString aBNameStr(OUStringToOString(GetName( SbxNameType::ShortTypes ), RTL_TEXTENCODING_ASCII_US));
- rStrm.WriteCharPtr( "Variable( " )
- .WriteOString( OString::number(reinterpret_cast<sal_Int64>(this)) ).WriteCharPtr( "==" )
+ rStrm.WriteOString( "Variable( " )
+ .WriteOString( OString::number(reinterpret_cast<sal_IntPtr>(this)) ).WriteOString( "==" )
.WriteOString( aBNameStr );
OString aBParentNameStr(OUStringToOString(GetParent()->GetName(), RTL_TEXTENCODING_ASCII_US));
if ( GetParent() )
{
- rStrm.WriteCharPtr( " in parent '" ).WriteOString( aBParentNameStr ).WriteCharPtr( "'" );
+ rStrm.WriteOString( " in parent '" ).WriteOString( aBParentNameStr ).WriteOString( "'" );
}
else
{
- rStrm.WriteCharPtr( " no parent" );
+ rStrm.WriteOString( " no parent" );
}
- rStrm.WriteCharPtr( " ) " );
+ rStrm.WriteOString( " ) " );
// output also the object at object-vars
if ( GetValues_Impl().eType == SbxOBJECT &&
@@ -572,7 +594,7 @@ void SbxVariable::Dump( SvStream& rStrm, bool bFill )
GetValues_Impl().pObj != this &&
GetValues_Impl().pObj != GetParent() )
{
- rStrm.WriteCharPtr( " contains " );
+ rStrm.WriteOString( " contains " );
static_cast<SbxObject*>(GetValues_Impl().pObj)->Dump( rStrm, bFill );
}
else
diff --git a/basic/source/uno/dlgcont.cxx b/basic/source/uno/dlgcont.cxx
index 31c64aef95f5..0402e9188ed0 100644
--- a/basic/source/uno/dlgcont.cxx
+++ b/basic/source/uno/dlgcont.cxx
@@ -33,7 +33,9 @@
#include <dlgcont.hxx>
#include <comphelper/fileformat.h>
#include <comphelper/processfactory.hxx>
-#include <tools/diagnose_ex.h>
+#include <comphelper/diagnose_ex.hxx>
+#include <o3tl/temporary.hxx>
+#include <utility>
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
#include <xmlscript/xmldlg_imexp.hxx>
@@ -52,7 +54,6 @@ using namespace com::sun::star::io;
using namespace com::sun::star::uno;
using namespace com::sun::star::ucb;
using namespace com::sun::star::lang;
-using namespace com::sun::star::script;
using namespace com::sun::star::xml::sax;
using namespace com::sun::star;
using namespace cppu;
@@ -62,10 +63,26 @@ using com::sun::star::uno::Reference;
// Implementation class SfxDialogLibraryContainer
-const char* SfxDialogLibraryContainer::getInfoFileName() const { return "dialog"; }
-const char* SfxDialogLibraryContainer::getOldInfoFileName() const { return "dialogs"; }
-const char* SfxDialogLibraryContainer::getLibElementFileExtension() const { return "xdl"; }
-const char* SfxDialogLibraryContainer::getLibrariesDir() const { return "Dialogs"; }
+OUString SfxDialogLibraryContainer::getInfoFileName() const
+{
+ static constexpr OUStringLiteral dialog = u"dialog";
+ return dialog;
+}
+OUString SfxDialogLibraryContainer::getOldInfoFileName() const
+{
+ static constexpr OUStringLiteral dialogs = u"dialogs";
+ return dialogs;
+}
+OUString SfxDialogLibraryContainer::getLibElementFileExtension() const
+{
+ static constexpr OUStringLiteral xdl = u"xdl";
+ return xdl;
+}
+OUString SfxDialogLibraryContainer::getLibrariesDir() const
+{
+ static constexpr OUStringLiteral Dialogs = u"Dialogs";
+ return Dialogs;
+}
// Ctor for service
SfxDialogLibraryContainer::SfxDialogLibraryContainer()
@@ -76,7 +93,7 @@ SfxDialogLibraryContainer::SfxDialogLibraryContainer()
SfxDialogLibraryContainer::SfxDialogLibraryContainer( const uno::Reference< embed::XStorage >& xStorage )
{
- init( OUString(), xStorage );
+ init(OUString(), xStorage, o3tl::temporary(std::unique_lock(m_aMutex)));
}
// Methods to get library instances of the correct type
@@ -109,7 +126,7 @@ bool SfxDialogLibraryContainer::isLibraryElementValid(const Any& rElement) const
static bool writeOasis2OOoLibraryElement(
const Reference< XInputStream >& xInput, const Reference< XOutputStream >& xOutput )
{
- Reference< XComponentContext > xContext(
+ const Reference< XComponentContext >& xContext(
comphelper::getProcessComponentContext() );
Reference< lang::XMultiComponentFactory > xSMgr(
@@ -124,7 +141,7 @@ static bool writeOasis2OOoLibraryElement(
Sequence<Any> aArgs{ Any(xWriter) };
Reference< xml::sax::XDocumentHandler > xHandler(
xSMgr->createInstanceWithArgumentsAndContext(
- "com.sun.star.comp.Oasis2OOoTransformer",
+ u"com.sun.star.comp.Oasis2OOoTransformer"_ustr,
aArgs, xContext ),
UNO_QUERY );
@@ -228,7 +245,7 @@ void SfxDialogLibraryContainer::storeLibrariesToStorage( const uno::Reference< e
{
Reference< io::XInputStream > xInput( xISP->createInputStream() );
Reference< XNameContainer > xDialogModel(
- mxContext->getServiceManager()->createInstanceWithContext("com.sun.star.awt.UnoControlDialogModel", mxContext),
+ mxContext->getServiceManager()->createInstanceWithContext(u"com.sun.star.awt.UnoControlDialogModel"_ustr, mxContext),
UNO_QUERY );
::xmlscript::importDialogModel( xInput, xDialogModel, mxContext, mxOwnerDocument );
std::vector<uno::Reference<graphic::XGraphic>> vxGraphicList;
@@ -275,7 +292,7 @@ Any SfxDialogLibraryContainer::importLibraryElement
Reference< XParser > xParser = xml::sax::Parser::create( mxContext );
Reference< XNameContainer > xDialogModel(
- mxContext->getServiceManager()->createInstanceWithContext("com.sun.star.awt.UnoControlDialogModel", mxContext),
+ mxContext->getServiceManager()->createInstanceWithContext(u"com.sun.star.awt.UnoControlDialogModel"_ustr, mxContext),
UNO_QUERY );
if( !xDialogModel.is() )
{
@@ -308,7 +325,7 @@ Any SfxDialogLibraryContainer::importLibraryElement
return aRetAny;
InputSource source;
- source.aInputStream = xInput;
+ source.aInputStream = std::move(xInput);
source.sSystemId = aFile;
try {
@@ -346,8 +363,8 @@ rtl::Reference<SfxLibraryContainer> SfxDialogLibraryContainer::createInstanceImp
return new SfxDialogLibraryContainer();
}
-constexpr OUStringLiteral aResourceFileNameBase = u"DialogStrings";
-constexpr OUStringLiteral aResourceFileCommentBase = u"# Strings for Dialog Library ";
+constexpr OUString aResourceFileNameBase = u"DialogStrings"_ustr;
+constexpr OUString aResourceFileCommentBase = u"# Strings for Dialog Library "_ustr;
// Resource handling
Reference< css::resource::XStringResourcePersistence >
@@ -371,19 +388,19 @@ Reference< css::resource::XStringResourcePersistence >
xLibrariesStor = mxStorage->openStorageElement( maLibrariesDir, embed::ElementModes::READ );
// TODO: Should be READWRITE with new storage concept using store() instead of storeTo()
if ( !xLibrariesStor.is() )
- throw uno::RuntimeException("null returned from openStorageElement",static_cast< cppu::OWeakObject * >(this));
+ throw uno::RuntimeException(u"null returned from openStorageElement"_ustr,getXWeak());
xLibraryStor = xLibrariesStor->openStorageElement( aLibName, embed::ElementModes::READ );
// TODO: Should be READWRITE with new storage concept using store() instead of storeTo()
if ( !xLibraryStor.is() )
- throw uno::RuntimeException("null returned from openStorageElement",static_cast< cppu::OWeakObject * >(this));
+ throw uno::RuntimeException(u"null returned from openStorageElement"_ustr,getXWeak());
}
catch(const uno::Exception& )
{
// Something went wrong while trying to get the storage library.
// Return an object that supports StringResourceWithStorage, give it a storage location later.
xRet = Reference< resource::XStringResourcePersistence >(
- mxContext->getServiceManager()->createInstanceWithContext("com.sun.star.resource.StringResourceWithStorage", mxContext),
+ mxContext->getServiceManager()->createInstanceWithContext(u"com.sun.star.resource.StringResourceWithStorage"_ustr, mxContext),
UNO_QUERY );
return xRet;
}
@@ -405,7 +422,7 @@ Reference< css::resource::XStringResourcePersistence >
void SfxDialogLibraryContainer::onNewRootStorage()
{
// the library container is not modified, go through the libraries and check whether they are modified
- Sequence< OUString > aNames = maNameContainer->getElementNames();
+ Sequence< OUString > aNames = maNameContainer.getElementNames();
const OUString* pNames = aNames.getConstArray();
sal_Int32 nNameCount = aNames.getLength();
@@ -424,12 +441,12 @@ void SfxDialogLibraryContainer::onNewRootStorage()
try {
xLibrariesStor = mxStorage->openStorageElement( maLibrariesDir, embed::ElementModes::READWRITE );
if ( !xLibrariesStor.is() )
- throw uno::RuntimeException("null returned from openStorageElement",static_cast< cppu::OWeakObject * >(this));
+ throw uno::RuntimeException(u"null returned from openStorageElement"_ustr,getXWeak());
OUString aLibName = pDialogLibrary->getName();
xLibraryStor = xLibrariesStor->openStorageElement( aLibName, embed::ElementModes::READWRITE );
if ( !xLibraryStor.is() )
- throw uno::RuntimeException("null returned from openStorageElement",static_cast< cppu::OWeakObject * >(this));
+ throw uno::RuntimeException(u"null returned from openStorageElement"_ustr,getXWeak());
Reference< resource::XStringResourceWithStorage >
xStringResourceWithStorage( xStringResourcePersistence, UNO_QUERY );
@@ -454,45 +471,42 @@ SfxDialogLibraryContainer:: HasExecutableCode( const OUString& /*Library*/ )
OUString SAL_CALL SfxDialogLibraryContainer::getImplementationName( )
{
- return "com.sun.star.comp.sfx2.DialogLibraryContainer";
+ return u"com.sun.star.comp.sfx2.DialogLibraryContainer"_ustr;
}
Sequence< OUString > SAL_CALL SfxDialogLibraryContainer::getSupportedServiceNames( )
{
- return {"com.sun.star.script.DocumentDialogLibraryContainer",
- "com.sun.star.script.DialogLibraryContainer"}; // for compatibility
+ return {u"com.sun.star.script.DocumentDialogLibraryContainer"_ustr,
+ u"com.sun.star.script.DialogLibraryContainer"_ustr}; // for compatibility
}
// Implementation class SfxDialogLibrary
// Ctor
SfxDialogLibrary::SfxDialogLibrary( ModifiableHelper& _rModifiable,
- const OUString& aName,
+ OUString aName,
const Reference< XSimpleFileAccess3 >& xSFI,
SfxDialogLibraryContainer* pParent )
- : SfxLibrary( _rModifiable, cppu::UnoType<XInputStreamProvider>::get(), xSFI )
+ : SfxDialogLibrary_BASE(_rModifiable, cppu::UnoType<XInputStreamProvider>::get(), xSFI)
, m_pParent( pParent )
- , m_aName( aName )
+ , m_aName(std::move( aName ))
{
}
SfxDialogLibrary::SfxDialogLibrary( ModifiableHelper& _rModifiable,
- const OUString& aName,
+ OUString aName,
const Reference< XSimpleFileAccess3 >& xSFI,
const OUString& aLibInfoFileURL,
const OUString& aStorageURL,
bool ReadOnly,
SfxDialogLibraryContainer* pParent )
- : SfxLibrary( _rModifiable, cppu::UnoType<XInputStreamProvider>::get(),
+ : SfxDialogLibrary_BASE(_rModifiable, cppu::UnoType<XInputStreamProvider>::get(),
xSFI, aLibInfoFileURL, aStorageURL, ReadOnly)
, m_pParent( pParent )
- , m_aName( aName )
+ , m_aName(std::move( aName ))
{
}
-IMPLEMENT_FORWARD_XINTERFACE2( SfxDialogLibrary, SfxLibrary, SfxDialogLibrary_BASE );
-IMPLEMENT_FORWARD_XTYPEPROVIDER2( SfxDialogLibrary, SfxLibrary, SfxDialogLibrary_BASE );
-
// Provide modify state including resources
bool SfxDialogLibrary::isModified()
{
diff --git a/basic/source/uno/modsizeexceeded.cxx b/basic/source/uno/modsizeexceeded.cxx
index 27c795934961..4210184b37d6 100644
--- a/basic/source/uno/modsizeexceeded.cxx
+++ b/basic/source/uno/modsizeexceeded.cxx
@@ -25,7 +25,6 @@
using namespace com::sun::star;
using namespace cppu;
-using namespace osl;
ModuleSizeExceeded::ModuleSizeExceeded(const std::vector<OUString>& sModules)
{
@@ -39,18 +38,8 @@ ModuleSizeExceeded::ModuleSizeExceeded(const std::vector<OUString>& sModules)
m_lContinuations = { m_xApprove, m_xAbort };
}
-bool ModuleSizeExceeded::isAbort() const
-{
- comphelper::OInteractionAbort* pBase
- = static_cast<comphelper::OInteractionAbort*>(m_xAbort.get());
- return pBase->wasSelected();
-}
+bool ModuleSizeExceeded::isAbort() const { return m_xAbort->wasSelected(); }
-bool ModuleSizeExceeded::isApprove() const
-{
- comphelper::OInteractionApprove* pBase
- = static_cast<comphelper::OInteractionApprove*>(m_xApprove.get());
- return pBase->wasSelected();
-}
+bool ModuleSizeExceeded::isApprove() const { return m_xApprove->wasSelected(); }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/source/uno/namecont.cxx b/basic/source/uno/namecont.cxx
index 87b33ea9be66..db97fe8794b3 100644
--- a/basic/source/uno/namecont.cxx
+++ b/basic/source/uno/namecont.cxx
@@ -25,11 +25,15 @@
#include <com/sun/star/embed/ElementModes.hpp>
#include <com/sun/star/embed/XTransactedObject.hpp>
#include <com/sun/star/io/IOException.hpp>
+#include <com/sun/star/lang/NoSupportException.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/ucb/ContentCreationException.hpp>
#include <com/sun/star/xml/sax/SAXException.hpp>
+#include <utility>
#include <vcl/svapp.hxx>
+#include <o3tl/string_view.hxx>
+#include <o3tl/temporary.hxx>
#include <osl/mutex.hxx>
#include <vcl/errinf.hxx>
#include <rtl/ustring.hxx>
@@ -41,7 +45,7 @@
#include <namecont.hxx>
#include <basic/basicmanagerrepository.hxx>
-#include <tools/diagnose_ex.h>
+#include <comphelper/diagnose_ex.hxx>
#include <tools/urlobj.hxx>
#include <unotools/pathoptions.hxx>
#include <svtools/sfxecode.hxx>
@@ -87,7 +91,6 @@ using namespace com::sun::star::frame;
using namespace com::sun::star::deployment;
using namespace com::sun::star;
using namespace cppu;
-using namespace osl;
using com::sun::star::uno::Reference;
@@ -105,169 +108,140 @@ Type NameContainer::getElementType()
sal_Bool NameContainer::hasElements()
{
- bool bRet = (mnElementCount > 0);
- return bRet;
+ return !maMap.empty();
}
// Methods XNameAccess
Any NameContainer::getByName( const OUString& aName )
{
- NameContainerNameMap::iterator aIt = mHashMap.find( aName );
- if( aIt == mHashMap.end() )
+ auto aIt = maMap.find(aName);
+ if (aIt == maMap.end())
{
- throw NoSuchElementException();
+ throw NoSuchElementException(aName);
}
- sal_Int32 iHashResult = (*aIt).second;
- Any aRetAny = mValues[ iHashResult ];
- return aRetAny;
+ return aIt->second;
}
Sequence< OUString > NameContainer::getElementNames()
{
- return comphelper::containerToSequence(mNames);
+ return comphelper::mapKeysToSequence(maMap);
}
sal_Bool NameContainer::hasByName( const OUString& aName )
{
- NameContainerNameMap::iterator aIt = mHashMap.find( aName );
- bool bRet = ( aIt != mHashMap.end() );
- return bRet;
+ return maMap.contains(aName);
}
// Methods XNameReplace
-void NameContainer::replaceByName( const OUString& aName, const Any& aElement )
+void NameContainer::replaceByName(const OUString& aName, const Any& aElement,
+ std::unique_lock<std::mutex>& guard)
{
const Type& aAnyType = aElement.getValueType();
if( mType != aAnyType )
{
- throw IllegalArgumentException("types do not match", static_cast<cppu::OWeakObject*>(this), 2);
+ throw IllegalArgumentException(u"types do not match"_ustr, rOwner, 2);
}
- NameContainerNameMap::iterator aIt = mHashMap.find( aName );
- if( aIt == mHashMap.end() )
+ auto aIt = maMap.find(aName);
+ if (aIt == maMap.end())
{
- throw NoSuchElementException();
+ throw NoSuchElementException(aName);
}
- sal_Int32 iHashResult = (*aIt).second;
- Any aOldElement = mValues[ iHashResult ];
- mValues[ iHashResult ] = aElement;
-
+ Any aOldElement = aIt->second;
+ aIt->second = aElement;
// Fire event
- if( maContainerListeners.getLength() > 0 )
+ if (maContainerListeners.getLength(guard) > 0)
{
ContainerEvent aEvent;
aEvent.Source = mpxEventSource;
aEvent.Accessor <<= aName;
aEvent.Element = aElement;
aEvent.ReplacedElement = aOldElement;
- maContainerListeners.notifyEach( &XContainerListener::elementReplaced, aEvent );
+ maContainerListeners.notifyEach(guard, &XContainerListener::elementReplaced, aEvent);
}
/* After the container event has been fired (one listener will update the
core Basic manager), fire change event. Listeners can rely on that the
Basic source code of the core Basic manager is up-to-date. */
- if( maChangesListeners.getLength() > 0 )
+ if (maChangesListeners.getLength(guard) > 0)
{
ChangesEvent aEvent;
aEvent.Source = mpxEventSource;
aEvent.Base <<= aEvent.Source;
aEvent.Changes = { { Any(aName), aElement, aOldElement } };
- maChangesListeners.notifyEach( &XChangesListener::changesOccurred, aEvent );
+ maChangesListeners.notifyEach(guard, &XChangesListener::changesOccurred, aEvent);
}
}
-void NameContainer::insertCheck(const OUString& aName, const Any& aElement)
-{
- NameContainerNameMap::iterator aIt = mHashMap.find(aName);
- if( aIt != mHashMap.end() )
- {
- throw ElementExistException();
- }
- insertNoCheck(aName, aElement);
-}
-
-void NameContainer::insertNoCheck(const OUString& aName, const Any& aElement)
+void NameContainer::insertNoCheck(const OUString& aName, const Any& aElement,
+ std::unique_lock<std::mutex>& guard)
{
const Type& aAnyType = aElement.getValueType();
if( mType != aAnyType )
{
- throw IllegalArgumentException("types do not match", static_cast<cppu::OWeakObject*>(this), 2);
+ throw IllegalArgumentException(u"types do not match"_ustr, rOwner, 2);
}
- sal_Int32 nCount = mNames.size();
- mNames.push_back( aName );
- mValues.push_back( aElement );
-
- mHashMap[ aName ] = nCount;
- mnElementCount++;
+ maMap[aName] = aElement;
// Fire event
- if( maContainerListeners.getLength() > 0 )
+ if (maContainerListeners.getLength(guard) > 0)
{
ContainerEvent aEvent;
aEvent.Source = mpxEventSource;
aEvent.Accessor <<= aName;
aEvent.Element = aElement;
- maContainerListeners.notifyEach( &XContainerListener::elementInserted, aEvent );
+ maContainerListeners.notifyEach(guard, &XContainerListener::elementInserted, aEvent);
}
/* After the container event has been fired (one listener will update the
core Basic manager), fire change event. Listeners can rely on that the
Basic source code of the core Basic manager is up-to-date. */
- if( maChangesListeners.getLength() > 0 )
+ if (maChangesListeners.getLength(guard) > 0)
{
ChangesEvent aEvent;
aEvent.Source = mpxEventSource;
aEvent.Base <<= aEvent.Source;
aEvent.Changes = { { Any(aName), aElement, {} } };
- maChangesListeners.notifyEach( &XChangesListener::changesOccurred, aEvent );
+ maChangesListeners.notifyEach(guard, &XChangesListener::changesOccurred, aEvent);
}
}
// Methods XNameContainer
-void NameContainer::insertByName( const OUString& aName, const Any& aElement )
+void NameContainer::insertByName(const OUString& aName, const Any& aElement,
+ std::unique_lock<std::mutex>& guard)
{
- insertCheck(aName, aElement);
+ if (hasByName(aName))
+ throw ElementExistException(aName);
+ insertNoCheck(aName, aElement, guard);
}
-void NameContainer::removeByName( const OUString& aName )
+void NameContainer::removeByName(const OUString& aName, std::unique_lock<std::mutex>& guard)
{
- NameContainerNameMap::iterator aIt = mHashMap.find( aName );
- if( aIt == mHashMap.end() )
+ auto aIt = maMap.find(aName);
+ if (aIt == maMap.end())
{
- OUString sMessage = "\"" + aName + "\" not found";
- throw NoSuchElementException(sMessage);
+ throw NoSuchElementException("\"" + aName + "\" not found");
}
- sal_Int32 iHashResult = (*aIt).second;
- Any aOldElement = mValues[ iHashResult ];
- mHashMap.erase( aIt );
- sal_Int32 iLast = mNames.size() - 1;
- if( iLast != iHashResult )
- {
- mNames[ iHashResult ] = mNames[ iLast ];
- mValues[ iHashResult ] = mValues[ iLast ];
- mHashMap[ mNames[ iHashResult ] ] = iHashResult;
- }
- mNames.resize( iLast );
- mValues.resize( iLast );
- mnElementCount--;
+ Any aOldElement = aIt->second;
+ maMap.erase(aIt);
// Fire event
- if( maContainerListeners.getLength() > 0 )
+ if (maContainerListeners.getLength(guard) > 0)
{
ContainerEvent aEvent;
aEvent.Source = mpxEventSource;
aEvent.Accessor <<= aName;
aEvent.Element = aOldElement;
- maContainerListeners.notifyEach( &XContainerListener::elementRemoved, aEvent );
+ maContainerListeners.notifyEach(guard, &XContainerListener::elementRemoved, aEvent);
}
/* After the container event has been fired (one listener will update the
core Basic manager), fire change event. Listeners can rely on that the
Basic source code of the core Basic manager is up-to-date. */
- if( maChangesListeners.getLength() > 0 )
+ if (maChangesListeners.getLength(guard) > 0)
{
ChangesEvent aEvent;
aEvent.Source = mpxEventSource;
@@ -275,53 +249,57 @@ void NameContainer::removeByName( const OUString& aName )
aEvent.Changes = { { Any(aName),
{}, // Element remains empty (meaning "replaced with nothing")
aOldElement } };
- maChangesListeners.notifyEach( &XChangesListener::changesOccurred, aEvent );
+ maChangesListeners.notifyEach(guard, &XChangesListener::changesOccurred, aEvent);
}
}
// Methods XContainer
-void SAL_CALL NameContainer::addContainerListener( const Reference< XContainerListener >& xListener )
+void NameContainer::addContainerListener(const Reference<XContainerListener>& xListener,
+ std::unique_lock<std::mutex>& guard)
{
if( !xListener.is() )
{
- throw RuntimeException("addContainerListener called with null xListener",static_cast< cppu::OWeakObject * >(this));
+ throw RuntimeException(u"addContainerListener called with null xListener"_ustr,rOwner);
}
- maContainerListeners.addInterface( xListener );
+ maContainerListeners.addInterface(guard, xListener);
}
-void SAL_CALL NameContainer::removeContainerListener( const Reference< XContainerListener >& xListener )
+void NameContainer::removeContainerListener(const Reference<XContainerListener>& xListener,
+ std::unique_lock<std::mutex>& guard)
{
if( !xListener.is() )
{
- throw RuntimeException("removeContainerListener called with null xListener",static_cast< cppu::OWeakObject * >(this));
+ throw RuntimeException(u"removeContainerListener called with null xListener"_ustr,rOwner);
}
- maContainerListeners.removeInterface( xListener );
+ maContainerListeners.removeInterface(guard, xListener);
}
// Methods XChangesNotifier
-void SAL_CALL NameContainer::addChangesListener( const Reference< XChangesListener >& xListener )
+void NameContainer::addChangesListener(const Reference<XChangesListener>& xListener,
+ std::unique_lock<std::mutex>& guard)
{
if( !xListener.is() )
{
- throw RuntimeException("addChangesListener called with null xListener",static_cast< cppu::OWeakObject * >(this));
+ throw RuntimeException(u"addChangesListener called with null xListener"_ustr,rOwner);
}
- maChangesListeners.addInterface( xListener );
+ maChangesListeners.addInterface(guard, xListener);
}
-void SAL_CALL NameContainer::removeChangesListener( const Reference< XChangesListener >& xListener )
+void NameContainer::removeChangesListener(const Reference<XChangesListener>& xListener,
+ std::unique_lock<std::mutex>& guard)
{
if( !xListener.is() )
{
- throw RuntimeException("removeChangesListener called with null xListener",static_cast< cppu::OWeakObject * >(this));
+ throw RuntimeException(u"removeChangesListener called with null xListener"_ustr,rOwner);
}
- maChangesListeners.removeInterface( xListener );
+ maChangesListeners.removeInterface(guard, xListener);
}
// ModifiableHelper
-void ModifiableHelper::setModified( bool _bModified )
+void ModifiableHelper::setModified(bool _bModified, std::unique_lock<std::mutex>& guard)
{
if ( _bModified == mbModified )
{
@@ -329,38 +307,26 @@ void ModifiableHelper::setModified( bool _bModified )
}
mbModified = _bModified;
- if ( m_aModifyListeners.getLength() == 0 )
+ if (m_aModifyListeners.getLength(guard) == 0)
{
return;
}
EventObject aModifyEvent( m_rEventSource );
- m_aModifyListeners.notifyEach( &XModifyListener::modified, aModifyEvent );
+ m_aModifyListeners.notifyEach(guard, &XModifyListener::modified, aModifyEvent);
}
-VBAScriptListenerContainer::VBAScriptListenerContainer( ::osl::Mutex& rMutex ) :
- VBAScriptListenerContainer_BASE( rMutex )
-{
-}
-
-bool VBAScriptListenerContainer::implTypedNotify( const Reference< vba::XVBAScriptListener >& rxListener, const vba::VBAScriptEvent& rEvent )
-{
- rxListener->notifyVBAScriptEvent( rEvent );
- return true; // notify all other listeners too
-}
-
// Ctor
SfxLibraryContainer::SfxLibraryContainer()
- : SfxLibraryContainer_BASE( m_aMutex )
- , maVBAScriptListeners( m_aMutex )
- , mnRunningVBAScripts( 0 )
+ : mnRunningVBAScripts( 0 )
, mbVBACompat( false )
- , maModifiable( *this, m_aMutex )
- , maNameContainer( new NameContainer(cppu::UnoType<XNameAccess>::get()) )
- , mbOldInfoFormat( false )
- , mbOasis2OOoFormat( false )
+ , meVBATextEncoding( RTL_TEXTENCODING_DONTKNOW )
+ , maModifiable( *this )
+ , maNameContainer( cppu::UnoType<XNameAccess>::get(), *this )
, mpBasMgr( nullptr )
, mbOwnBasMgr( false )
+ , mbOldInfoFormat( false )
+ , mbOasis2OOoFormat( false )
, meInitMode(DEFAULT)
{
mxContext = comphelper::getProcessComponentContext();
@@ -381,7 +347,7 @@ SfxLibraryContainer::~SfxLibraryContainer()
void SfxLibraryContainer::enterMethod()
{
Application::GetSolarMutex().acquire();
- if ( rBHelper.bInDispose || rBHelper.bDisposed )
+ if (m_bDisposed)
{
throw DisposedException( OUString(), *this );
}
@@ -429,7 +395,7 @@ void SAL_CALL SfxLibraryContainer::setRootStorage( const Reference< XStorage >&
LibraryContainerMethodGuard aGuard( *this );
if ( !_rxRootStorage.is() )
{
- throw IllegalArgumentException("no root storage", static_cast<cppu::OWeakObject*>(this), 1);
+ throw IllegalArgumentException(u"no root storage"_ustr, getXWeak(), 1);
}
mxStorage = _rxRootStorage;
onNewRootStorage();
@@ -440,11 +406,11 @@ void SAL_CALL SfxLibraryContainer::storeLibrariesToStorage( const Reference< XSt
LibraryContainerMethodGuard aGuard( *this );
if ( !_rxRootStorage.is() )
{
- throw IllegalArgumentException("no root storage", static_cast<cppu::OWeakObject*>(this), 1);
+ throw IllegalArgumentException(u"no root storage"_ustr, getXWeak(), 1);
}
try
{
- storeLibraries_Impl( _rxRootStorage, true );
+ storeLibraries_Impl(_rxRootStorage, true, o3tl::temporary(std::unique_lock(m_aMutex)));
}
catch( const Exception& )
{
@@ -463,13 +429,8 @@ sal_Bool SfxLibraryContainer::isModified()
return true;
}
// the library container is not modified, go through the libraries and check whether they are modified
- Sequence< OUString > aNames = maNameContainer->getElementNames();
- const OUString* pNames = aNames.getConstArray();
- sal_Int32 nNameCount = aNames.getLength();
-
- for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
+ for (auto& aName : maNameContainer.getElementNames())
{
- OUString aName = pNames[ i ];
try
{
SfxLibrary* pImplLib = getImplLib( aName );
@@ -500,19 +461,19 @@ sal_Bool SfxLibraryContainer::isModified()
void SAL_CALL SfxLibraryContainer::setModified( sal_Bool _bModified )
{
LibraryContainerMethodGuard aGuard( *this );
- maModifiable.setModified( _bModified );
+ maModifiable.setModified(_bModified, o3tl::temporary(std::unique_lock(m_aMutex)));
}
void SAL_CALL SfxLibraryContainer::addModifyListener( const Reference< XModifyListener >& _rxListener )
{
LibraryContainerMethodGuard aGuard( *this );
- maModifiable.addModifyListener( _rxListener );
+ maModifiable.addModifyListener(_rxListener, o3tl::temporary(std::unique_lock(m_aMutex)));
}
void SAL_CALL SfxLibraryContainer::removeModifyListener( const Reference< XModifyListener >& _rxListener )
{
LibraryContainerMethodGuard aGuard( *this );
- maModifiable.removeModifyListener( _rxListener );
+ maModifiable.removeModifyListener(_rxListener, o3tl::temporary(std::unique_lock(m_aMutex)));
}
// Methods XPersistentLibraryContainer
@@ -533,7 +494,7 @@ void SAL_CALL SfxLibraryContainer::storeLibraries( )
LibraryContainerMethodGuard aGuard( *this );
try
{
- storeLibraries_Impl( mxStorage, mxStorage.is() );
+ storeLibraries_Impl(mxStorage, mxStorage.is(), o3tl::temporary(std::unique_lock(m_aMutex)));
// we need to store *all* libraries if and only if we are based on a storage:
// in this case, storeLibraries_Impl will remove the source storage, after loading
// all libraries, so we need to force them to be stored, again
@@ -544,7 +505,9 @@ void SAL_CALL SfxLibraryContainer::storeLibraries( )
}
}
-static void checkAndCopyFileImpl( const INetURLObject& rSourceFolderInetObj,
+namespace
+{
+void checkAndCopyFileImpl( const INetURLObject& rSourceFolderInetObj,
const INetURLObject& rTargetFolderInetObj,
std::u16string_view rCheckFileName,
std::u16string_view rCheckExtension,
@@ -566,40 +529,47 @@ static void checkAndCopyFileImpl( const INetURLObject& rSourceFolderInetObj,
}
}
-static void createVariableURL( OUString& rStr, std::u16string_view rLibName,
+constexpr OUString sUserBasicVariablePrefix = u"$(USER)/basic/"_ustr;
+constexpr OUString sInstBasicVariablePrefix = u"$(INST)/" LIBO_SHARE_FOLDER "/basic/"_ustr;
+
+void createVariableURL( OUString& rStr, std::u16string_view rLibName,
std::u16string_view rInfoFileName, bool bUser )
{
if( bUser )
{
- rStr = "$(USER)/basic/";
+ rStr = sUserBasicVariablePrefix;
}
else
{
- rStr = "$(INST)/" LIBO_SHARE_FOLDER "/basic/";
+ rStr = sInstBasicVariablePrefix;
}
rStr += OUString::Concat(rLibName) + "/" + rInfoFileName + ".xlb/";
}
+}
-void SfxLibraryContainer::init( const OUString& rInitialDocumentURL, const uno::Reference< embed::XStorage >& rxInitialStorage )
+void SfxLibraryContainer::init(const OUString& rInitialDocumentURL,
+ const uno::Reference<embed::XStorage>& rxInitialStorage,
+ std::unique_lock<std::mutex>& guard)
{
// this might be called from within the ctor, and the impl_init might (indirectly) create
// a UNO reference to ourself.
// Ensure that we're not destroyed while we're in here
osl_atomic_increment( &m_refCount );
- init_Impl( rInitialDocumentURL, rxInitialStorage );
+ init_Impl(rInitialDocumentURL, rxInitialStorage, guard);
osl_atomic_decrement( &m_refCount );
}
void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
- const uno::Reference< embed::XStorage >& rxInitialStorage )
+ const uno::Reference< embed::XStorage >& rxInitialStorage,
+ std::unique_lock<std::mutex>& guard )
{
uno::Reference< embed::XStorage > xStorage = rxInitialStorage;
maInitialDocumentURL = rInitialDocumentURL;
- maInfoFileName = OUString::createFromAscii( getInfoFileName() );
- maOldInfoFileName = OUString::createFromAscii( getOldInfoFileName() );
- maLibElementFileExtension = OUString::createFromAscii( getLibElementFileExtension() );
- maLibrariesDir = OUString::createFromAscii( getLibrariesDir() );
+ maInfoFileName = getInfoFileName();
+ maOldInfoFileName = getOldInfoFileName();
+ maLibElementFileExtension = getLibElementFileExtension();
+ maLibrariesDir = getLibrariesDir();
meInitMode = DEFAULT;
INetURLObject aInitUrlInetObj( maInitialDocumentURL );
@@ -615,7 +585,7 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
if( aExtension == "xlc" )
{
meInitMode = CONTAINER_INIT_FILE;
- INetURLObject aLibPathInetObj( aInitUrlInetObj );
+ INetURLObject aLibPathInetObj( std::move(aInitUrlInetObj) );
aLibPathInetObj.removeSegment();
maLibraryPath = aLibPathInetObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
}
@@ -624,7 +594,7 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
meInitMode = LIBRARY_INIT_FILE;
uno::Reference< embed::XStorage > xDummyStor;
::xmlscript::LibDescriptor aLibDesc;
- implLoadLibraryIndexFile( nullptr, aLibDesc, xDummyStor, aInitFileName );
+ implLoadLibraryIndexFile(nullptr, aLibDesc, xDummyStor, aInitFileName, guard);
return;
}
else
@@ -657,8 +627,6 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
maLibraryPath = SvtPathOptions().GetBasicPath();
}
- Reference< XParser > xParser = xml::sax::Parser::create(mxContext);
-
uno::Reference< io::XInputStream > xInput;
mxStorage = xStorage;
@@ -742,11 +710,11 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
{
if( nPass == 1 )
{
- pLibInfoInetObj.reset(new INetURLObject( maLibraryPath.getToken(0, ';') ));
+ pLibInfoInetObj.reset(new INetURLObject( o3tl::getToken(maLibraryPath, 0, ';') ));
}
else
{
- pLibInfoInetObj.reset(new INetURLObject( maLibraryPath.getToken(1, ';') ));
+ pLibInfoInetObj.reset(new INetURLObject( o3tl::getToken(maLibraryPath, 1, ';') ));
}
pLibInfoInetObj->insertName( maInfoFileName, false, INetURLObject::LAST_SEGMENT, INetURLObject::EncodeMechanism::All );
pLibInfoInetObj->setExtension( u"xlc" );
@@ -766,7 +734,7 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
// Old variant?
if( !xInput.is() && nPass == 0 )
{
- INetURLObject aLibInfoInetObj( maLibraryPath.getToken(1, ';') );
+ INetURLObject aLibInfoInetObj( o3tl::getToken(maLibraryPath, 1, ';') );
aLibInfoInetObj.insertName( maOldInfoFileName, false, INetURLObject::LAST_SEGMENT, INetURLObject::EncodeMechanism::All );
aLibInfoInetObj.setExtension( u"xli" );
aFileName = aLibInfoInetObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
@@ -790,11 +758,12 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
source.sSystemId = aFileName;
// start parsing
- auto pLibArray = std::make_unique<::xmlscript::LibDescriptorArray> ( );
+ ::xmlscript::LibDescriptorArray aLibArray;
+ Reference< XParser > xParser = xml::sax::Parser::create(mxContext);
try
{
- xParser->setDocumentHandler( ::xmlscript::importLibraryContainer( pLibArray.get() ) );
+ xParser->setDocumentHandler( ::xmlscript::importLibraryContainer( &aLibArray ) );
xParser->parseStream( source );
}
catch ( const xml::sax::SAXException& )
@@ -808,10 +777,10 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
return;
}
- sal_Int32 nLibCount = pLibArray->mnLibCount;
+ sal_Int32 nLibCount = aLibArray.mnLibCount;
for( sal_Int32 i = 0 ; i < nLibCount ; i++ )
{
- ::xmlscript::LibDescriptor& rLib = pLibArray->mpLibs[i];
+ ::xmlscript::LibDescriptor& rLib = aLibArray.mpLibs[i];
// Check storage URL
OUString aStorageURL = rLib.aStorageURL;
@@ -834,19 +803,19 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
if( mxSFI->isFolder( aLibDirPath ) )
{
createVariableURL( rLib.aStorageURL, rLib.aName, maInfoFileName, true );
- maModifiable.setModified( true );
+ maModifiable.setModified(true, guard);
}
else if( rLib.bLink )
{
// Check "share" path
- INetURLObject aShareInetObj( maLibraryPath.getToken(0, ';') );
+ INetURLObject aShareInetObj( o3tl::getToken(maLibraryPath, 0, ';') );
aShareInetObj.insertName( rLib.aName, true, INetURLObject::LAST_SEGMENT,
INetURLObject::EncodeMechanism::All );
OUString aShareLibDirPath = aShareInetObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
if( mxSFI->isFolder( aShareLibDirPath ) )
{
createVariableURL( rLib.aStorageURL, rLib.aName, maInfoFileName, false );
- maModifiable.setModified( true );
+ maModifiable.setModified(true, guard);
}
else
{
@@ -868,12 +837,12 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
if( rLib.bLink )
{
Reference< XNameAccess > xLib =
- createLibraryLink( aLibName, rLib.aStorageURL, rLib.bReadOnly );
+ createLibraryLink_Impl(aLibName, rLib.aStorageURL, rLib.bReadOnly, guard);
pImplLib = static_cast< SfxLibrary* >( xLib.get() );
}
else
{
- Reference< XNameContainer > xLib = createLibrary( aLibName );
+ Reference<XNameContainer> xLib = createLibrary_Impl(aLibName, guard);
pImplLib = static_cast< SfxLibrary* >( xLib.get() );
pImplLib->mbLoaded = false;
pImplLib->mbReadOnly = rLib.bReadOnly;
@@ -883,7 +852,7 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
pImplLib->maStorageURL, pImplLib->maUnexpandedStorageURL );
}
}
- maModifiable.setModified( false );
+ maModifiable.setModified(false, guard);
// Read library info files
if( !mbOldInfoFormat )
@@ -906,10 +875,10 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
}
}
- // Link is already initialised in createLibraryLink()
+ // Link is already initialised in createLibraryLink_Impl()
if( !pImplLib->mbInitialised && (!bStorage || xLibraryStor.is()) )
{
- bool bLoaded = implLoadLibraryIndexFile( pImplLib, rLib, xLibraryStor, OUString() );
+ bool bLoaded = implLoadLibraryIndexFile( pImplLib, rLib, xLibraryStor, OUString(), guard );
SAL_WARN_IF(
bLoaded && aLibName != rLib.aName, "basic",
("Different library names in library container and"
@@ -929,7 +898,7 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
implStoreLibraryIndexFile( pImplLib, rLib, xTmpStorage );
}
- implImportLibDescriptor( pImplLib, rLib );
+ implImportLibDescriptor(pImplLib, rLib, guard);
if( nPass == 1 )
{
@@ -953,7 +922,7 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
{
try
{
- implScanExtensions();
+ implScanExtensions(guard);
}
catch(const uno::Exception& )
{
@@ -964,16 +933,12 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
// Preload?
{
- Sequence< OUString > aNames = maNameContainer->getElementNames();
- const OUString* pNames = aNames.getConstArray();
- sal_Int32 nNameCount = aNames.getLength();
- for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
+ for (auto& aName : maNameContainer.getElementNames())
{
- OUString aName = pNames[ i ];
SfxLibrary* pImplLib = getImplLib( aName );
if( pImplLib->mbPreload )
{
- loadLibrary( aName );
+ loadLibrary_Impl(aName, guard);
}
}
}
@@ -981,8 +946,12 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
if( meInitMode != DEFAULT )
return;
- INetURLObject aUserBasicInetObj( maLibraryPath.getToken(1, ';') );
- OUString aStandardStr("Standard");
+ // tdf#121740 speed up loading documents with lots of embedded documents by avoid the UCB work of updating non-existent VBA libraries
+ if (rInitialDocumentURL.isEmpty())
+ return;
+
+ INetURLObject aUserBasicInetObj( o3tl::getToken(maLibraryPath, 1, ';') );
+ OUString aStandardStr(u"Standard"_ustr);
INetURLObject aPrevUserBasicInetObj_1( aUserBasicInetObj );
aPrevUserBasicInetObj_1.removeSegment();
@@ -1008,7 +977,7 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
OUString aPrevStandardFolder = aPrevUserBasicStandardInetObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
if( mxSFI->isFolder( aPrevStandardFolder ) )
{
- OUString aXlbExtension( "xlb" );
+ OUString aXlbExtension( u"xlb"_ustr );
OUString aCheckFileName;
// Check if script.xlb exists
@@ -1087,13 +1056,8 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
mxSFI->move( aFolderUserBasic, aPrevFolder );
mxSFI->move( aFolderTmp, aFolderUserBasic );
- Sequence< OUString > aNames = pPrevCont->getElementNames();
- const OUString* pNames = aNames.getConstArray();
- sal_Int32 nNameCount = aNames.getLength();
-
- for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
+ for (auto& aLibName : pPrevCont->getElementNames())
{
- OUString aLibName = pNames[ i ];
if( hasByName( aLibName ) )
{
if( aLibName == aStandardStr )
@@ -1122,7 +1086,7 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
}
if( bCreateLink )
{
- createLibraryLink( aLibName, pImplLib->maStorageURL, pImplLib->mbReadOnly );
+ createLibraryLink_Impl( aLibName, pImplLib->maStorageURL, pImplLib->mbReadOnly, guard );
}
}
else
@@ -1143,21 +1107,21 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
if( aLibName == aStandardStr )
{
- maNameContainer->removeByName( aLibName );
+ maNameContainer.removeByName(aLibName, guard);
}
// Create library
- Reference< XNameContainer > xLib = createLibrary( aLibName );
+ Reference<XNameContainer> xLib = createLibrary_Impl(aLibName, guard);
SfxLibrary* pNewLib = static_cast< SfxLibrary* >( xLib.get() );
pNewLib->mbLoaded = false;
- pNewLib->implSetModified( false );
+ pNewLib->implSetModified(false, guard);
checkStorageURL( aLibFolder, pNewLib->maLibInfoFileURL,
pNewLib->maStorageURL, pNewLib->maUnexpandedStorageURL );
uno::Reference< embed::XStorage > xDummyStor;
::xmlscript::LibDescriptor aLibDesc;
- implLoadLibraryIndexFile( pNewLib, aLibDesc, xDummyStor, pNewLib->maLibInfoFileURL );
- implImportLibDescriptor( pNewLib, aLibDesc );
+ implLoadLibraryIndexFile( pNewLib, aLibDesc, xDummyStor, pNewLib->maLibInfoFileURL, guard );
+ implImportLibDescriptor(pNewLib, aLibDesc, guard);
}
}
mxSFI->kill( aPrevFolder );
@@ -1173,7 +1137,7 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
if( !bCleanUp )
return;
- INetURLObject aPrevUserBasicInetObj_Err( aUserBasicInetObj );
+ INetURLObject aPrevUserBasicInetObj_Err(std::move(aUserBasicInetObj));
aPrevUserBasicInetObj_Err.removeSegment();
aPrevUserBasicInetObj_Err.Append( u"__basic_80_err" );
OUString aPrevFolder_Err = aPrevUserBasicInetObj_Err.GetMainURL( INetURLObject::DecodeMechanism::NONE );
@@ -1206,7 +1170,7 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
{}
}
-void SfxLibraryContainer::implScanExtensions()
+void SfxLibraryContainer::implScanExtensions(std::unique_lock<std::mutex>& guard)
{
#if HAVE_FEATURE_EXTENSIONS
ScriptExtensionIterator aScriptIt;
@@ -1248,10 +1212,10 @@ void SfxLibraryContainer::implScanExtensions()
// Create link
const bool bReadOnly = false;
- createLibraryLink( aLibName, aIndexFileURL, bReadOnly );
+ createLibraryLink_Impl(aLibName, aIndexFileURL, bReadOnly, guard);
}
#else
- (void) this;
+ (void)guard;
#endif
}
@@ -1265,6 +1229,17 @@ void SfxLibraryContainer::checkStorageURL( const OUString& aSourceURL,
{
aUnexpandedStorageURL = aSourceURL;
}
+ else
+ {
+ // try to re-create the variable URL: helps moving the profile
+ if (std::u16string_view aRest; aSourceURL.startsWith(expand_url(sUserBasicVariablePrefix), &aRest))
+ aUnexpandedStorageURL = sUserBasicVariablePrefix + aRest;
+ else if (aSourceURL.startsWith(expand_url(sInstBasicVariablePrefix), &aRest))
+ aUnexpandedStorageURL = sInstBasicVariablePrefix + aRest;
+ else
+ aUnexpandedStorageURL.clear(); // This will use eventual value of aLibInfoFileURL
+ }
+
INetURLObject aInetObj( aExpandedSourceURL );
OUString aExtension = aInetObj.getExtension();
if( aExtension == "xlb" )
@@ -1286,11 +1261,8 @@ void SfxLibraryContainer::checkStorageURL( const OUString& aSourceURL,
SfxLibrary* SfxLibraryContainer::getImplLib( const OUString& rLibraryName )
{
- Any aLibAny = maNameContainer->getByName( rLibraryName ) ;
- Reference< XNameAccess > xNameAccess;
- aLibAny >>= xNameAccess;
- SfxLibrary* pImplLib = static_cast< SfxLibrary* >( xNameAccess.get() );
- return pImplLib;
+ auto xNameAccess = maNameContainer.getByName(rLibraryName).query<XNameAccess>();
+ return static_cast<SfxLibrary*>(xNameAccess.get());
}
@@ -1319,7 +1291,8 @@ bool SfxLibraryContainer::implStorePasswordLibrary(
bool SfxLibraryContainer::implLoadPasswordLibrary(
SfxLibrary* /*pLib*/,
const OUString& /*Name*/,
- bool /*bVerifyPasswordOnly*/ )
+ bool /*bVerifyPasswordOnly*/,
+ std::unique_lock<std::mutex>& /*guard*/ )
{
return true;
}
@@ -1329,7 +1302,7 @@ OUString SfxLibraryContainer::createAppLibraryFolder( SfxLibrary* pLib, std::u16
OUString aLibDirPath = pLib->maStorageURL;
if( aLibDirPath.isEmpty() )
{
- INetURLObject aInetObj( maLibraryPath.getToken(1, ';') );
+ INetURLObject aInetObj( o3tl::getToken(maLibraryPath, 1, ';') );
aInetObj.insertName( aName, true, INetURLObject::LAST_SEGMENT, INetURLObject::EncodeMechanism::All );
checkStorageURL( aInetObj.GetMainURL( INetURLObject::DecodeMechanism::NONE ), pLib->maLibInfoFileURL,
pLib->maStorageURL, pLib->maUnexpandedStorageURL );
@@ -1356,29 +1329,24 @@ void SfxLibraryContainer::implStoreLibrary( SfxLibrary* pLib,
{
Reference< XSimpleFileAccess3 > xDummySFA;
Reference< XInteractionHandler > xDummyHandler;
- implStoreLibrary( pLib, aName, xStorage, OUString(), xDummySFA, xDummyHandler );
+ implStoreLibrary( pLib, aName, xStorage, u"", xDummySFA, xDummyHandler );
}
// New variant for library export
void SfxLibraryContainer::implStoreLibrary( SfxLibrary* pLib,
std::u16string_view aName,
const uno::Reference< embed::XStorage >& xStorage,
- const OUString& aTargetURL,
+ std::u16string_view aTargetURL,
const Reference< XSimpleFileAccess3 >& rToUseSFI,
const Reference< XInteractionHandler >& xHandler )
{
bool bLink = pLib->mbLink;
bool bStorage = xStorage.is() && !bLink;
- Sequence< OUString > aElementNames = pLib->getElementNames();
- sal_Int32 nNameCount = aElementNames.getLength();
- const OUString* pNames = aElementNames.getConstArray();
-
if( bStorage )
{
- for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
+ for (auto& aElementName : pLib->getElementNames())
{
- OUString aElementName = pNames[ i ];
OUString aStreamName = aElementName + ".xml";
if( !isLibraryElementValid( pLib->getByName( aElementName ) ) )
@@ -1403,10 +1371,10 @@ void SfxLibraryContainer::implStoreLibrary( SfxLibrary* pLib,
if ( xProps.is() )
{
- xProps->setPropertyValue("MediaType", uno::Any( OUString( "text/xml" ) ) );
+ xProps->setPropertyValue(u"MediaType"_ustr, uno::Any( u"text/xml"_ustr ) );
// #87671 Allow encryption
- xProps->setPropertyValue("UseCommonStoragePasswordEncryption", uno::Any( true ) );
+ xProps->setPropertyValue(u"UseCommonStoragePasswordEncryption"_ustr, uno::Any( true ) );
Reference< XOutputStream > xOutput = xElementStream->getOutputStream();
Reference< XNameContainer > xLib( pLib );
@@ -1424,7 +1392,7 @@ void SfxLibraryContainer::implStoreLibrary( SfxLibrary* pLib,
else
{
// Export?
- bool bExport = !aTargetURL.isEmpty();
+ bool bExport = !aTargetURL.empty();
try
{
Reference< XSimpleFileAccess3 > xSFI = mxSFI;
@@ -1451,10 +1419,8 @@ void SfxLibraryContainer::implStoreLibrary( SfxLibrary* pLib,
pLib->storeResources();
}
- for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
+ for (auto& aElementName : pLib->getElementNames())
{
- OUString aElementName = pNames[ i ];
-
INetURLObject aElementInetObj( aLibDirPath );
aElementInetObj.insertName( aElementName, false,
INetURLObject::LAST_SEGMENT,
@@ -1508,14 +1474,14 @@ void SfxLibraryContainer::implStoreLibraryIndexFile( SfxLibrary* pLib,
const uno::Reference< embed::XStorage >& xStorage )
{
Reference< XSimpleFileAccess3 > xDummySFA;
- implStoreLibraryIndexFile( pLib, rLib, xStorage, OUString(), xDummySFA );
+ implStoreLibraryIndexFile( pLib, rLib, xStorage, u"", xDummySFA );
}
// New variant for library export
void SfxLibraryContainer::implStoreLibraryIndexFile( SfxLibrary* pLib,
const ::xmlscript::LibDescriptor& rLib,
const uno::Reference< embed::XStorage >& xStorage,
- const OUString& aTargetURL,
+ std::u16string_view aTargetURL,
const Reference< XSimpleFileAccess3 >& rToUseSFI )
{
// Create sax writer
@@ -1540,10 +1506,10 @@ void SfxLibraryContainer::implStoreLibraryIndexFile( SfxLibrary* pLib,
if ( xProps.is() )
{
- xProps->setPropertyValue("MediaType", uno::Any( OUString("text/xml") ) );
+ xProps->setPropertyValue(u"MediaType"_ustr, uno::Any( u"text/xml"_ustr ) );
// #87671 Allow encryption
- xProps->setPropertyValue("UseCommonStoragePasswordEncryption", uno::Any( true ) );
+ xProps->setPropertyValue(u"UseCommonStoragePasswordEncryption"_ustr, uno::Any( true ) );
xOut = xInfoStream->getOutputStream();
}
@@ -1557,7 +1523,7 @@ void SfxLibraryContainer::implStoreLibraryIndexFile( SfxLibrary* pLib,
else
{
// Export?
- bool bExport = !aTargetURL.isEmpty();
+ bool bExport = !aTargetURL.empty();
Reference< XSimpleFileAccess3 > xSFI = mxSFI;
if( rToUseSFI.is() )
{
@@ -1614,7 +1580,8 @@ void SfxLibraryContainer::implStoreLibraryIndexFile( SfxLibrary* pLib,
bool SfxLibraryContainer::implLoadLibraryIndexFile( SfxLibrary* pLib,
::xmlscript::LibDescriptor& rLib,
const uno::Reference< embed::XStorage >& xStorage,
- const OUString& aIndexFileName )
+ const OUString& aIndexFileName,
+ std::unique_lock<std::mutex>& guard )
{
Reference< XParser > xParser = xml::sax::Parser::create(mxContext);
@@ -1675,7 +1642,7 @@ bool SfxLibraryContainer::implLoadLibraryIndexFile( SfxLibrary* pLib,
}
InputSource source;
- source.aInputStream = xInput;
+ source.aInputStream = std::move(xInput);
source.sSystemId = aLibInfoPath;
// start parsing
@@ -1694,59 +1661,51 @@ bool SfxLibraryContainer::implLoadLibraryIndexFile( SfxLibrary* pLib,
if( !pLib )
{
- Reference< XNameContainer > xLib = createLibrary( rLib.aName );
+ Reference<XNameContainer> xLib = createLibrary_Impl(rLib.aName, guard);
pLib = static_cast< SfxLibrary* >( xLib.get() );
pLib->mbLoaded = false;
rLib.aStorageURL = aIndexFileName;
checkStorageURL( rLib.aStorageURL, pLib->maLibInfoFileURL, pLib->maStorageURL,
pLib->maUnexpandedStorageURL );
- implImportLibDescriptor( pLib, rLib );
+ implImportLibDescriptor(pLib, rLib, guard);
}
return true;
}
void SfxLibraryContainer::implImportLibDescriptor( SfxLibrary* pLib,
- ::xmlscript::LibDescriptor const & rLib )
+ ::xmlscript::LibDescriptor const& rLib,
+ std::unique_lock<std::mutex>& guard)
{
if( pLib->mbInitialised )
return;
-
- sal_Int32 nElementCount = rLib.aElementNames.getLength();
- const OUString* pElementNames = rLib.aElementNames.getConstArray();
Any aDummyElement = createEmptyLibraryElement();
- for( sal_Int32 i = 0 ; i < nElementCount ; i++ )
+ for (auto& name : rLib.aElementNames)
{
- pLib->maNameContainer->insertByName( pElementNames[i], aDummyElement );
+ pLib->maNameContainer.insertByName(name, aDummyElement, guard);
}
pLib->mbPasswordProtected = rLib.bPasswordProtected;
pLib->mbReadOnly = rLib.bReadOnly;
pLib->mbPreload = rLib.bPreload;
- pLib->implSetModified( false );
+ pLib->implSetModified(false, guard);
pLib->mbInitialised = true;
}
// Methods of new XLibraryStorage interface?
void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XStorage >& i_rStorage,
- bool bComplete )
+ bool bComplete, std::unique_lock<std::mutex>& guard )
{
- const Sequence< OUString > aNames = maNameContainer->getElementNames();
- const sal_Int32 nNameCount = aNames.getLength();
- const OUString* pName = aNames.getConstArray();
- const OUString* pNamesEnd = aNames.getConstArray() + nNameCount;
+ const Sequence< OUString > aNames = maNameContainer.getElementNames();
// Don't count libs from shared index file
- sal_Int32 nLibsToSave = nNameCount;
- for( ; pName != pNamesEnd; ++pName )
- {
- SfxLibrary* pImplLib = getImplLib( *pName );
- if( pImplLib->mbSharedIndexFile || pImplLib->mbExtension )
- {
- nLibsToSave--;
- }
- }
+ sal_Int32 nLibsToSave
+ = std::count_if(aNames.begin(), aNames.end(),
+ [this](const OUString& name) {
+ SfxLibrary* pImplLib = getImplLib(name);
+ return !pImplLib->mbSharedIndexFile && !pImplLib->mbExtension;
+ });
// Write to storage?
bool bStorage = i_rStorage.is();
uno::Reference< embed::XStorage > xSourceLibrariesStor;
@@ -1768,10 +1727,7 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
// Don't write if only empty standard lib exists
if ( ( nLibsToSave == 1 ) && ( aNames[0] == "Standard" ) )
{
- Any aLibAny = maNameContainer->getByName( aNames[0] );
- Reference< XNameAccess > xNameAccess;
- aLibAny >>= xNameAccess;
- if ( ! xNameAccess->hasElements() )
+ if (!getImplLib(aNames[0])->hasElements())
{
if ( bInplaceStorage && mxStorage->hasByName(maLibrariesDir) )
{
@@ -1788,14 +1744,11 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
if ( bInplaceStorage )
{
// create a temporary target storage
- const OUStringBuffer aTempTargetNameBase = maLibrariesDir + "_temp_";
+ const OUString aTempTargetNameBase = maLibrariesDir + "_temp_";
sal_Int32 index = 0;
do
{
- OUStringBuffer aTempTargetName( aTempTargetNameBase );
- aTempTargetName.append( index++ );
-
- sTargetLibrariesStoreName = aTempTargetName.makeStringAndClear();
+ sTargetLibrariesStoreName = aTempTargetNameBase + OUString::number( index++ );
if ( !i_rStorage->hasByName( sTargetLibrariesStoreName ) )
{
break;
@@ -1838,24 +1791,23 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
}
int iArray = 0;
- pName = aNames.getConstArray();
::xmlscript::LibDescriptor aLibDescriptorForExtensionLibs;
- auto pLibArray = std::make_unique< ::xmlscript::LibDescriptorArray > ( nLibsToSave );
- for( ; pName != pNamesEnd; ++pName )
+ ::xmlscript::LibDescriptorArray aLibArray( nLibsToSave );
+ for (auto& name : aNames)
{
- SfxLibrary* pImplLib = getImplLib( *pName );
+ SfxLibrary* pImplLib = getImplLib(name);
if( pImplLib->mbSharedIndexFile )
{
continue;
}
const bool bExtensionLib = pImplLib->mbExtension;
::xmlscript::LibDescriptor& rLib = bExtensionLib ?
- aLibDescriptorForExtensionLibs : pLibArray->mpLibs[iArray];
+ aLibDescriptorForExtensionLibs : aLibArray.mpLibs[iArray];
if( !bExtensionLib )
{
iArray++;
}
- rLib.aName = *pName;
+ rLib.aName = name;
rLib.bLink = pImplLib->mbLink;
if( !bStorage || pImplLib->mbLink )
@@ -1939,7 +1891,7 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
// Maybe lib is not loaded?!
if( bComplete )
{
- loadLibrary( rLib.aName );
+ loadLibrary_Impl(rLib.aName, guard);
}
if( pImplLib->mbPasswordProtected )
{
@@ -1966,8 +1918,8 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
}
}
}
- maModifiable.setModified( true );
- pImplLib->implSetModified( false );
+ maModifiable.setModified(true, guard);
+ pImplLib->implSetModified(false, guard);
}
// For container info ReadOnly refers to mbReadOnlyLink
@@ -2029,7 +1981,7 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
{
return;
}
- maModifiable.setModified( false );
+ maModifiable.setModified(false, guard);
mbOldInfoFormat = false;
// Write library container info
@@ -2047,10 +1999,10 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
{
xInfoStream = xTargetLibrariesStor->openStreamElement( aStreamName, embed::ElementModes::READWRITE );
uno::Reference< beans::XPropertySet > xProps( xInfoStream, uno::UNO_QUERY_THROW );
- xProps->setPropertyValue("MediaType", uno::Any( OUString( "text/xml" ) ) );
+ xProps->setPropertyValue(u"MediaType"_ustr, uno::Any( u"text/xml"_ustr ) );
// #87671 Allow encryption
- xProps->setPropertyValue("UseCommonStoragePasswordEncryption", uno::Any( true ) );
+ xProps->setPropertyValue(u"UseCommonStoragePasswordEncryption"_ustr, uno::Any( true ) );
xOut = xInfoStream->getOutputStream();
}
@@ -2062,7 +2014,7 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
else
{
// Create Output stream
- INetURLObject aLibInfoInetObj( maLibraryPath.getToken(1, ';') );
+ INetURLObject aLibInfoInetObj( o3tl::getToken(maLibraryPath, 1, ';') );
aLibInfoInetObj.insertName( maInfoFileName, false, INetURLObject::LAST_SEGMENT, INetURLObject::EncodeMechanism::All );
aLibInfoInetObj.setExtension( u"xlc" );
OUString aLibInfoPath( aLibInfoInetObj.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
@@ -2093,7 +2045,7 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
try
{
- xmlscript::exportLibraryContainer( xWriter, pLibArray.get() );
+ xmlscript::exportLibraryContainer( xWriter, &aLibArray );
if ( bStorage )
{
uno::Reference< embed::XTransactedObject > xTransact( xTargetLibrariesStor, uno::UNO_QUERY_THROW );
@@ -2112,58 +2064,70 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
Type SAL_CALL SfxLibraryContainer::getElementType()
{
LibraryContainerMethodGuard aGuard( *this );
- return maNameContainer->getElementType();
+ return maNameContainer.getElementType();
}
sal_Bool SfxLibraryContainer::hasElements()
{
LibraryContainerMethodGuard aGuard( *this );
- bool bRet = maNameContainer->hasElements();
- return bRet;
+ return maNameContainer.hasElements();
}
// Methods XNameAccess
Any SfxLibraryContainer::getByName( const OUString& aName )
{
LibraryContainerMethodGuard aGuard( *this );
- Any aRetAny = maNameContainer->getByName( aName ) ;
- return aRetAny;
+ return maNameContainer.getByName(aName);
}
Sequence< OUString > SfxLibraryContainer::getElementNames()
{
LibraryContainerMethodGuard aGuard( *this );
- return maNameContainer->getElementNames();
+ return maNameContainer.getElementNames();
}
sal_Bool SfxLibraryContainer::hasByName( const OUString& aName )
{
LibraryContainerMethodGuard aGuard( *this );
- return maNameContainer->hasByName( aName ) ;
+ return maNameContainer.hasByName( aName ) ;
}
// Methods XLibraryContainer
Reference< XNameContainer > SAL_CALL SfxLibraryContainer::createLibrary( const OUString& Name )
{
LibraryContainerMethodGuard aGuard( *this );
+ return createLibrary_Impl(Name, o3tl::temporary(std::unique_lock(m_aMutex)));
+}
+
+css::uno::Reference<css::container::XNameContainer>
+SfxLibraryContainer::createLibrary_Impl(const OUString& Name, std::unique_lock<std::mutex>& guard)
+{
rtl::Reference<SfxLibrary> pNewLib = implCreateLibrary( Name );
pNewLib->maLibElementFileExtension = maLibElementFileExtension;
createVariableURL( pNewLib->maUnexpandedStorageURL, Name, maInfoFileName, true );
+ // tdf#151741 - fill various storage URLs for the newly created library
+ checkStorageURL(pNewLib->maUnexpandedStorageURL, pNewLib->maLibInfoFileURL,
+ pNewLib->maStorageURL, pNewLib->maUnexpandedStorageURL);
- Reference< XNameAccess > xNameAccess( pNewLib );
Any aElement;
- aElement <<= xNameAccess;
- maNameContainer->insertByName( Name, aElement );
- maModifiable.setModified( true );
- Reference< XNameContainer > xRet( xNameAccess, UNO_QUERY );
- return xRet;
+ aElement <<= Reference< XNameAccess >( pNewLib );
+ maNameContainer.insertByName(Name, aElement, guard);
+ maModifiable.setModified(true, guard);
+ return pNewLib;
}
Reference< XNameAccess > SAL_CALL SfxLibraryContainer::createLibraryLink
( const OUString& Name, const OUString& StorageURL, sal_Bool ReadOnly )
{
LibraryContainerMethodGuard aGuard( *this );
+ return createLibraryLink_Impl(Name, StorageURL, ReadOnly, o3tl::temporary(std::unique_lock(m_aMutex)));
+}
+
+css::uno::Reference<css::container::XNameAccess>
+SfxLibraryContainer::createLibraryLink_Impl(const OUString& Name, const OUString& StorageURL,
+ sal_Bool ReadOnly, std::unique_lock<std::mutex>& guard)
+{
// TODO: Check other reasons to force ReadOnly status
//if( !ReadOnly )
//{
@@ -2182,14 +2146,13 @@ Reference< XNameAccess > SAL_CALL SfxLibraryContainer::createLibraryLink
uno::Reference< embed::XStorage > xDummyStor;
::xmlscript::LibDescriptor aLibDesc;
- implLoadLibraryIndexFile( pNewLib.get(), aLibDesc, xDummyStor, OUString() );
- implImportLibDescriptor( pNewLib.get(), aLibDesc );
+ implLoadLibraryIndexFile(pNewLib.get(), aLibDesc, xDummyStor, OUString(), guard);
+ implImportLibDescriptor(pNewLib.get(), aLibDesc, guard);
- Reference< XNameAccess > xRet( pNewLib );
Any aElement;
- aElement <<= xRet;
- maNameContainer->insertByName( Name, aElement );
- maModifiable.setModified( true );
+ aElement <<= Reference< XNameAccess >( pNewLib );
+ maNameContainer.insertByName(Name, aElement, guard);
+ maModifiable.setModified(true, guard);
if( StorageURL.indexOf( "vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE" ) != -1 )
{
@@ -2202,24 +2165,22 @@ Reference< XNameAccess > SAL_CALL SfxLibraryContainer::createLibraryLink
pNewLib->mbReadOnly = true;
}
- return xRet;
+ return pNewLib;
}
void SAL_CALL SfxLibraryContainer::removeLibrary( const OUString& Name )
{
LibraryContainerMethodGuard aGuard( *this );
+ std::unique_lock guard(m_aMutex);
// Get and hold library before removing
- Any aLibAny = maNameContainer->getByName( Name ) ;
- Reference< XNameAccess > xNameAccess;
- aLibAny >>= xNameAccess;
- SfxLibrary* pImplLib = static_cast< SfxLibrary* >( xNameAccess.get() );
+ rtl::Reference pImplLib(getImplLib(Name));
if( pImplLib->mbReadOnly && !pImplLib->mbLink )
{
- throw IllegalArgumentException("readonly && !link", static_cast<cppu::OWeakObject*>(this), 1);
+ throw IllegalArgumentException(u"readonly && !link"_ustr, getXWeak(), 1);
}
// Remove from container
- maNameContainer->removeByName( Name );
- maModifiable.setModified( true );
+ maNameContainer.removeByName(Name, guard);
+ maModifiable.setModified(true, guard);
// Delete library files, but not for linked libraries
if( pImplLib->mbLink )
@@ -2229,19 +2190,14 @@ void SAL_CALL SfxLibraryContainer::removeLibrary( const OUString& Name )
{
return;
}
- if( xNameAccess->hasElements() )
+ if (pImplLib->hasElements())
{
- Sequence< OUString > aNames = pImplLib->getElementNames();
- sal_Int32 nNameCount = aNames.getLength();
- const OUString* pNames = aNames.getConstArray();
- for( sal_Int32 i = 0 ; i < nNameCount ; ++i, ++pNames )
- {
- pImplLib->removeElementWithoutChecks( *pNames, SfxLibrary::LibraryContainerAccess() );
- }
+ for (auto& name : pImplLib->getElementNames())
+ pImplLib->impl_removeWithoutChecks(name, guard);
}
// Delete index file
- createAppLibraryFolder( pImplLib, Name );
+ createAppLibraryFolder(pImplLib.get(), Name);
OUString aLibInfoPath = pImplLib->maLibInfoFileURL;
try
{
@@ -2253,7 +2209,7 @@ void SAL_CALL SfxLibraryContainer::removeLibrary( const OUString& Name )
catch(const Exception& ) {}
// Delete folder if empty
- INetURLObject aInetObj( maLibraryPath.getToken(1, ';') );
+ INetURLObject aInetObj( o3tl::getToken(maLibraryPath, 1, ';') );
aInetObj.insertName( Name, true, INetURLObject::LAST_SEGMENT,
INetURLObject::EncodeMechanism::All );
OUString aLibDirPath = aInetObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
@@ -2287,19 +2243,22 @@ sal_Bool SAL_CALL SfxLibraryContainer::isLibraryLoaded( const OUString& Name )
void SAL_CALL SfxLibraryContainer::loadLibrary( const OUString& Name )
{
LibraryContainerMethodGuard aGuard( *this );
- Any aLibAny = maNameContainer->getByName( Name ) ;
- Reference< XNameAccess > xNameAccess;
- aLibAny >>= xNameAccess;
- SfxLibrary* pImplLib = static_cast< SfxLibrary* >( xNameAccess.get() );
+ return loadLibrary_Impl(Name, o3tl::temporary(std::unique_lock(m_aMutex)));
+}
+
+void SfxLibraryContainer::loadLibrary_Impl(const OUString& Name,
+ std::unique_lock<std::mutex>& guard)
+{
+ SfxLibrary* pImplLib = getImplLib(Name);
bool bLoaded = pImplLib->mbLoaded;
pImplLib->mbLoaded = true;
- if( bLoaded || !xNameAccess->hasElements() )
+ if (bLoaded || !pImplLib->hasElements())
return;
if( pImplLib->mbPasswordProtected )
{
- implLoadPasswordLibrary( pImplLib, Name );
+ implLoadPasswordLibrary(pImplLib, Name, false, guard);
return;
}
@@ -2321,7 +2280,7 @@ void SAL_CALL SfxLibraryContainer::loadLibrary( const OUString& Name )
" storage!"));
if ( !xLibrariesStor.is() )
{
- throw uno::RuntimeException("null returned from openStorageElement",static_cast< cppu::OWeakObject * >(this));
+ throw uno::RuntimeException(u"null returned from openStorageElement"_ustr,getXWeak());
}
xLibraryStor = xLibrariesStor->openStorageElement( Name, embed::ElementModes::READ );
@@ -2331,7 +2290,7 @@ void SAL_CALL SfxLibraryContainer::loadLibrary( const OUString& Name )
" storage!"));
if ( !xLibrariesStor.is() )
{
- throw uno::RuntimeException("null returned from openStorageElement",static_cast< cppu::OWeakObject * >(this));
+ throw uno::RuntimeException(u"null returned from openStorageElement"_ustr,getXWeak());
}
#if OSL_DEBUG_LEVEL > 0
}
@@ -2345,13 +2304,18 @@ void SAL_CALL SfxLibraryContainer::loadLibrary( const OUString& Name )
#endif
}
- Sequence< OUString > aNames = pImplLib->getElementNames();
- sal_Int32 nNameCount = aNames.getLength();
- const OUString* pNames = aNames.getConstArray();
- for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
+ // tdf#167255 workaround: sort library elements to establish at least some predictable order.
+ // FIXME: the order of modules must not affect their inner names visibility. Modules must load
+ // their content first (and so the names of e.g. global constants / variables must be known),
+ // and only then their elements' values must be resolved.
+ auto elements = pImplLib->getElementNames();
{
- OUString aElementName = pNames[ i ];
+ auto range = asNonConstRange(elements);
+ std::sort(range.begin(), range.end());
+ }
+ for (auto& aElementName : elements)
+ {
OUString aFile;
uno::Reference< io::XInputStream > xInStream;
@@ -2390,7 +2354,7 @@ void SAL_CALL SfxLibraryContainer::loadLibrary( const OUString& Name )
"basic",
"couldn't open library element stream - attempted to"
" open library \"" << Name << '"');
- throw RuntimeException("couldn't open library element stream", *this);
+ throw RuntimeException(u"couldn't open library element stream"_ustr, *this);
}
}
else
@@ -2411,15 +2375,15 @@ void SAL_CALL SfxLibraryContainer::loadLibrary( const OUString& Name )
{
if( aAny.hasValue() )
{
- pImplLib->maNameContainer->replaceByName( aElementName, aAny );
+ pImplLib->maNameContainer.replaceByName(aElementName, aAny, guard);
}
}
else
{
- pImplLib->maNameContainer->insertNoCheck(aElementName, aAny);
+ pImplLib->maNameContainer.insertNoCheck(aElementName, aAny, guard);
}
}
- pImplLib->implSetModified( false );
+ pImplLib->implSetModified(false, guard);
}
// Methods XLibraryContainer2
@@ -2438,7 +2402,7 @@ OUString SAL_CALL SfxLibraryContainer::getLibraryLinkURL( const OUString& Name )
bool bLink = pImplLib->mbLink;
if( !bLink )
{
- throw IllegalArgumentException("!link", static_cast<cppu::OWeakObject*>(this), 1);
+ throw IllegalArgumentException(u"!link"_ustr, getXWeak(), 1);
}
OUString aRetStr = pImplLib->maLibInfoFileURL;
return aRetStr;
@@ -2455,14 +2419,15 @@ sal_Bool SAL_CALL SfxLibraryContainer::isLibraryReadOnly( const OUString& Name )
void SAL_CALL SfxLibraryContainer::setLibraryReadOnly( const OUString& Name, sal_Bool bReadOnly )
{
LibraryContainerMethodGuard aGuard( *this );
+ std::unique_lock guard(m_aMutex);
SfxLibrary* pImplLib = getImplLib( Name );
if( pImplLib->mbLink )
{
if( pImplLib->mbReadOnlyLink != bool(bReadOnly) )
{
pImplLib->mbReadOnlyLink = bReadOnly;
- pImplLib->implSetModified( true );
- maModifiable.setModified( true );
+ pImplLib->implSetModified(true, guard);
+ maModifiable.setModified(true, guard);
}
}
else
@@ -2470,7 +2435,7 @@ void SAL_CALL SfxLibraryContainer::setLibraryReadOnly( const OUString& Name, sal
if( pImplLib->mbReadOnly != bool(bReadOnly) )
{
pImplLib->mbReadOnly = bReadOnly;
- pImplLib->implSetModified( true );
+ pImplLib->implSetModified(true, guard);
}
}
}
@@ -2478,26 +2443,20 @@ void SAL_CALL SfxLibraryContainer::setLibraryReadOnly( const OUString& Name, sal
void SAL_CALL SfxLibraryContainer::renameLibrary( const OUString& Name, const OUString& NewName )
{
LibraryContainerMethodGuard aGuard( *this );
- if( maNameContainer->hasByName( NewName ) )
+ std::unique_lock guard(m_aMutex);
+ if( maNameContainer.hasByName( NewName ) )
{
throw ElementExistException();
}
// Get and hold library before removing
- Any aLibAny = maNameContainer->getByName( Name ) ;
+ rtl::Reference pImplLib(getImplLib(Name));
// #i24094 Maybe lib is not loaded!
- Reference< XNameAccess > xNameAccess;
- aLibAny >>= xNameAccess;
- SfxLibrary* pImplLib = static_cast< SfxLibrary* >( xNameAccess.get() );
if( pImplLib->mbPasswordProtected && !pImplLib->mbPasswordVerified )
{
return; // Lib with unverified password cannot be renamed
}
- loadLibrary( Name );
-
- // Remove from container
- maNameContainer->removeByName( Name );
- maModifiable.setModified( true );
+ loadLibrary_Impl(Name, guard);
// Rename library folder, but not for linked libraries
bool bMovedSuccessful = true;
@@ -2509,15 +2468,23 @@ void SAL_CALL SfxLibraryContainer::renameLibrary( const OUString& Name, const OU
bMovedSuccessful = false;
OUString aLibDirPath = pImplLib->maStorageURL;
+ // tdf#151741 - fill various storage URLs for the library
+ // These URLs should not be empty for newly created libraries after
+ // the change in SfxLibraryContainer::createLibrary_Impl.
+ if (aLibDirPath.isEmpty())
+ {
+ checkStorageURL(pImplLib->maUnexpandedStorageURL, pImplLib->maLibInfoFileURL,
+ pImplLib->maStorageURL, pImplLib->maUnexpandedStorageURL);
+ }
- INetURLObject aDestInetObj( maLibraryPath.getToken(1, ';'));
+ INetURLObject aDestInetObj( o3tl::getToken(maLibraryPath, 1, ';'));
aDestInetObj.insertName( NewName, true, INetURLObject::LAST_SEGMENT,
INetURLObject::EncodeMechanism::All );
OUString aDestDirPath = aDestInetObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
// Store new URL
OUString aLibInfoFileURL = pImplLib->maLibInfoFileURL;
- checkStorageURL( aDestDirPath, pImplLib->maLibInfoFileURL, pImplLib->maStorageURL,
+ checkStorageURL(aDestDirPath, pImplLib->maLibInfoFileURL, pImplLib->maStorageURL,
pImplLib->maUnexpandedStorageURL );
try
@@ -2541,13 +2508,8 @@ void SAL_CALL SfxLibraryContainer::renameLibrary( const OUString& Name, const OU
{
}
- Sequence< OUString > aElementNames = xNameAccess->getElementNames();
- sal_Int32 nNameCount = aElementNames.getLength();
- const OUString* pNames = aElementNames.getConstArray();
- for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
+ for (auto& aElementName : pImplLib->getElementNames())
{
- OUString aElementName = pNames[ i ];
-
INetURLObject aElementInetObj( aLibDirPath );
aElementInetObj.insertName( aElementName, false,
INetURLObject::LAST_SEGMENT, INetURLObject::EncodeMechanism::All );
@@ -2584,23 +2546,24 @@ void SAL_CALL SfxLibraryContainer::renameLibrary( const OUString& Name, const OU
}
bMovedSuccessful = true;
- pImplLib->implSetModified( true );
+ pImplLib->implSetModified(true, guard);
}
}
catch(const Exception& )
{
- // Restore old library
- maNameContainer->insertByName( Name, aLibAny ) ;
}
}
if( bStorage && !pImplLib->mbLink )
{
- pImplLib->implSetModified( true );
+ pImplLib->implSetModified(true, guard);
}
if( bMovedSuccessful )
{
- maNameContainer->insertByName( NewName, aLibAny ) ;
+ // Remove the old library from the container and insert it back with the new name
+ maNameContainer.removeByName(Name, guard);
+ maNameContainer.insertByName(NewName, Any(Reference<XNameAccess>(pImplLib)), guard);
+ maModifiable.setModified(true, guard);
}
}
@@ -2609,35 +2572,37 @@ void SAL_CALL SfxLibraryContainer::renameLibrary( const OUString& Name, const OU
void SAL_CALL SfxLibraryContainer::initialize( const Sequence< Any >& _rArguments )
{
LibraryContainerMethodGuard aGuard( *this );
+ std::unique_lock guard(m_aMutex);
sal_Int32 nArgCount = _rArguments.getLength();
if ( nArgCount != 1 )
- throw IllegalArgumentException("too many args", static_cast<cppu::OWeakObject*>(this), -1);
+ throw IllegalArgumentException(u"too many args"_ustr, getXWeak(), -1);
OUString sInitialDocumentURL;
Reference< XStorageBasedDocument > xDocument;
if ( _rArguments[0] >>= sInitialDocumentURL )
{
- init( sInitialDocumentURL, nullptr );
+ init(sInitialDocumentURL, nullptr, guard);
return;
}
if ( _rArguments[0] >>= xDocument )
{
- initializeFromDocument( xDocument );
+ initializeFromDocument(xDocument, guard);
return;
}
- throw IllegalArgumentException("arg1 unknown type", static_cast<cppu::OWeakObject*>(this), 1);
+ throw IllegalArgumentException(u"arg1 unknown type"_ustr, getXWeak(), 1);
}
-void SfxLibraryContainer::initializeFromDocument( const Reference< XStorageBasedDocument >& _rxDocument )
+void SfxLibraryContainer::initializeFromDocument( const Reference< XStorageBasedDocument >& _rxDocument,
+ std::unique_lock<std::mutex>& guard )
{
// check whether this is a valid OfficeDocument, and obtain the document's root storage
Reference< XStorage > xDocStorage;
try
{
Reference< XServiceInfo > xSI( _rxDocument, UNO_QUERY_THROW );
- if ( xSI->supportsService("com.sun.star.document.OfficeDocument"))
+ if ( xSI->supportsService(u"com.sun.star.document.OfficeDocument"_ustr))
{
xDocStorage.set( _rxDocument->getDocumentStorage(), UNO_SET_THROW );
}
@@ -2651,9 +2616,9 @@ void SfxLibraryContainer::initializeFromDocument( const Reference< XStorageBased
if ( !xDocStorage.is() )
{
- throw IllegalArgumentException("no doc storage", static_cast<cppu::OWeakObject*>(this), 1);
+ throw IllegalArgumentException(u"no doc storage"_ustr, getXWeak(), 1);
}
- init( OUString(), xDocStorage );
+ init(OUString(), xDocStorage, guard);
}
// OEventListenerAdapter
@@ -2671,11 +2636,11 @@ void SfxLibraryContainer::_disposing( const EventObject& _rSource )
}
// OComponentHelper
-void SAL_CALL SfxLibraryContainer::disposing()
+void SfxLibraryContainer::disposing(std::unique_lock<std::mutex>& guard)
{
Reference< XModel > xModel = mxOwnerDocument;
EventObject aEvent( xModel );
- maVBAScriptListeners.disposing( aEvent );
+ maVBAScriptListeners.disposeAndClear(guard, aEvent);
stopAllComponentListening();
mxOwnerDocument.clear();
}
@@ -2705,14 +2670,16 @@ void SAL_CALL SfxLibraryContainer::changeLibraryPassword(const OUString&, const
void SAL_CALL SfxLibraryContainer::addContainerListener( const Reference< XContainerListener >& xListener )
{
LibraryContainerMethodGuard aGuard( *this );
- maNameContainer->setEventSource( static_cast< XInterface* >( static_cast<OWeakObject*>(this) ) );
- maNameContainer->addContainerListener( xListener );
+ std::unique_lock guard(m_aMutex);
+ maNameContainer.setEventSource( getXWeak() );
+ maNameContainer.addContainerListener(xListener, guard);
}
void SAL_CALL SfxLibraryContainer::removeContainerListener( const Reference< XContainerListener >& xListener )
{
LibraryContainerMethodGuard aGuard( *this );
- maNameContainer->removeContainerListener( xListener );
+ std::unique_lock guard(m_aMutex);
+ maNameContainer.removeContainerListener(xListener, guard);
}
// Methods XLibraryContainerExport
@@ -2720,6 +2687,7 @@ void SAL_CALL SfxLibraryContainer::exportLibrary( const OUString& Name, const OU
const Reference< XInteractionHandler >& Handler )
{
LibraryContainerMethodGuard aGuard( *this );
+ std::unique_lock guard(m_aMutex);
SfxLibrary* pImplLib = getImplLib( Name );
Reference< XSimpleFileAccess3 > xToUseSFI;
@@ -2730,7 +2698,7 @@ void SAL_CALL SfxLibraryContainer::exportLibrary( const OUString& Name, const OU
}
// Maybe lib is not loaded?!
- loadLibrary( Name );
+ loadLibrary_Impl(Name, guard);
uno::Reference< css::embed::XStorage > xDummyStor;
if( pImplLib->mbPasswordProtected )
@@ -2777,7 +2745,7 @@ OUString SAL_CALL SfxLibraryContainer::getOriginalLibraryLinkURL( const OUString
bool bLink = pImplLib->mbLink;
if( !bLink )
{
- throw IllegalArgumentException("!link", static_cast<cppu::OWeakObject*>(this), 1);
+ throw IllegalArgumentException(u"!link"_ustr, getXWeak(), 1);
}
OUString aRetStr = pImplLib->maOriginalStorageURL;
return aRetStr;
@@ -2821,7 +2789,7 @@ void SAL_CALL SfxLibraryContainer::setVBACompatibilityMode( sal_Bool _vbacompatm
{
Reference< XModel > xModel( mxOwnerDocument ); // weak-ref -> ref
Reference< XMultiServiceFactory > xFactory( xModel, UNO_QUERY_THROW );
- xFactory->createInstance("ooo.vba.VBAGlobals");
+ xFactory->createInstance(u"ooo.vba.VBAGlobals"_ustr);
}
catch(const Exception& )
{
@@ -2850,12 +2818,12 @@ sal_Int32 SAL_CALL SfxLibraryContainer::getRunningVBAScripts()
void SAL_CALL SfxLibraryContainer::addVBAScriptListener( const Reference< vba::XVBAScriptListener >& rxListener )
{
- maVBAScriptListeners.addTypedListener( rxListener );
+ maVBAScriptListeners.addInterface(o3tl::temporary(std::unique_lock(m_aMutex)), rxListener);
}
void SAL_CALL SfxLibraryContainer::removeVBAScriptListener( const Reference< vba::XVBAScriptListener >& rxListener )
{
- maVBAScriptListeners.removeTypedListener( rxListener );
+ maVBAScriptListeners.removeInterface(o3tl::temporary(std::unique_lock(m_aMutex)), rxListener);
}
void SAL_CALL SfxLibraryContainer::broadcastVBAScriptEvent( sal_Int32 nIdentifier, const OUString& rModuleName )
@@ -2875,7 +2843,54 @@ void SAL_CALL SfxLibraryContainer::broadcastVBAScriptEvent( sal_Int32 nIdentifie
Reference< XModel > xModel = mxOwnerDocument; // weak-ref -> ref
vba::VBAScriptEvent aEvent( Reference<XInterface>(xModel, UNO_QUERY), nIdentifier, rModuleName );
- maVBAScriptListeners.notify( aEvent );
+ maVBAScriptListeners.notifyEach(o3tl::temporary(std::unique_lock(m_aMutex)),
+ &css::script::vba::XVBAScriptListener::notifyVBAScriptEvent,
+ aEvent);
+}
+
+// Methods XPropertySet
+css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL SfxLibraryContainer::getPropertySetInfo()
+{
+ return uno::Reference<beans::XPropertySetInfo>();
+}
+
+void SAL_CALL SfxLibraryContainer::setPropertyValue(const OUString& aPropertyName,
+ const uno::Any& aValue)
+{
+ if (aPropertyName != sVBATextEncodingPropName)
+ throw UnknownPropertyException(aPropertyName, getXWeak());
+ aValue >>= meVBATextEncoding;
+}
+
+css::uno::Any SAL_CALL SfxLibraryContainer::getPropertyValue(const OUString& aPropertyName)
+{
+ if (aPropertyName == sVBATextEncodingPropName)
+ return uno::Any(meVBATextEncoding);
+ throw UnknownPropertyException(aPropertyName, getXWeak());
+}
+
+void SAL_CALL SfxLibraryContainer::addPropertyChangeListener(
+ const OUString& /* aPropertyName */, const Reference<XPropertyChangeListener>& /* xListener */)
+{
+ throw NoSupportException();
+}
+
+void SAL_CALL SfxLibraryContainer::removePropertyChangeListener(
+ const OUString& /* aPropertyName */, const Reference<XPropertyChangeListener>& /* aListener */)
+{
+ throw NoSupportException();
+}
+
+void SAL_CALL SfxLibraryContainer::addVetoableChangeListener(
+ const OUString& /* PropertyName */, const Reference<XVetoableChangeListener>& /* aListener */)
+{
+ throw NoSupportException();
+}
+
+void SAL_CALL SfxLibraryContainer::removeVetoableChangeListener(
+ const OUString& /* PropertyName */, const Reference<XVetoableChangeListener>& /* aListener */)
+{
+ throw NoSupportException();
}
// Methods XServiceInfo
@@ -2889,10 +2904,9 @@ sal_Bool SAL_CALL SfxLibraryContainer::supportsService( const OUString& _rServic
// Ctor
SfxLibrary::SfxLibrary( ModifiableHelper& _rModifiable, const Type& aType,
const Reference< XSimpleFileAccess3 >& xSFI )
- : OComponentHelper( m_aMutex )
- , mxSFI( xSFI )
+ : mxSFI( xSFI )
, mrModifiable( _rModifiable )
- , maNameContainer( new NameContainer(aType) )
+ , maNameContainer( aType, *this )
, mbLoaded( true )
, mbIsModified( true )
, mbInitialised( false )
@@ -2910,16 +2924,13 @@ SfxLibrary::SfxLibrary( ModifiableHelper& _rModifiable, const Type& aType,
SfxLibrary::SfxLibrary( ModifiableHelper& _rModifiable, const Type& aType,
const Reference< XSimpleFileAccess3 >& xSFI,
- const OUString& aLibInfoFileURL, const OUString& aStorageURL, bool ReadOnly )
- : OComponentHelper( m_aMutex )
- , mxSFI( xSFI )
+ OUString aLibInfoFileURL, OUString aStorageURL, bool ReadOnly )
+ : mxSFI( xSFI )
, mrModifiable( _rModifiable )
- , maNameContainer( new NameContainer(aType) )
+ , maNameContainer( aType, *this )
, mbLoaded( false )
, mbIsModified( true )
, mbInitialised( false )
- , maLibInfoFileURL( aLibInfoFileURL )
- , maStorageURL( aStorageURL )
, mbLink( true )
, mbReadOnly( false )
, mbReadOnlyLink( ReadOnly )
@@ -2929,6 +2940,8 @@ SfxLibrary::SfxLibrary( ModifiableHelper& _rModifiable, const Type& aType,
, mbDoc50Password( false )
, mbSharedIndexFile( false )
, mbExtension( false )
+ , maLibInfoFileURL(std::move( aLibInfoFileURL ))
+ , maStorageURL(std::move( aStorageURL ))
{
}
@@ -2937,7 +2950,7 @@ bool SfxLibrary::isLoadedStorable()
return mbLoaded && (!mbPasswordProtected || mbPasswordVerified);
}
-void SfxLibrary::implSetModified( bool _bIsModified )
+void SfxLibrary::implSetModified(bool _bIsModified, std::unique_lock<std::mutex>& guard)
{
if ( mbIsModified == _bIsModified )
{
@@ -2946,38 +2959,19 @@ void SfxLibrary::implSetModified( bool _bIsModified )
mbIsModified = _bIsModified;
if ( mbIsModified )
{
- mrModifiable.setModified( true );
- }
-}
-
-// Methods XInterface
-Any SAL_CALL SfxLibrary::queryInterface( const Type& rType )
-{
- Any aRet =
- ::cppu::queryInterface(
- rType,
- static_cast< XContainer * >( this ),
- static_cast< XNameContainer * >( this ),
- static_cast< XNameAccess * >( this ),
- static_cast< XElementAccess * >( this ),
- static_cast< XChangesNotifier * >( this ) );
- if( !aRet.hasValue() )
- {
- aRet = OComponentHelper::queryInterface( rType );
+ mrModifiable.setModified(true, guard);
}
- return aRet;
}
// Methods XElementAccess
Type SfxLibrary::getElementType()
{
- return maNameContainer->getElementType();
+ return maNameContainer.getElementType();
}
sal_Bool SfxLibrary::hasElements()
{
- bool bRet = maNameContainer->hasElements();
- return bRet;
+ return maNameContainer.hasElements();
}
// Methods XNameAccess
@@ -2985,18 +2979,17 @@ Any SfxLibrary::getByName( const OUString& aName )
{
impl_checkLoaded();
- Any aRetAny = maNameContainer->getByName( aName ) ;
- return aRetAny;
+ return maNameContainer.getByName(aName);
}
Sequence< OUString > SfxLibrary::getElementNames()
{
- return maNameContainer->getElementNames();
+ return maNameContainer.getElementNames();
}
sal_Bool SfxLibrary::hasByName( const OUString& aName )
{
- bool bRet = maNameContainer->hasByName( aName );
+ bool bRet = maNameContainer.hasByName( aName );
return bRet;
}
@@ -3005,7 +2998,7 @@ void SfxLibrary::impl_checkReadOnly()
if( mbReadOnly || (mbLink && mbReadOnlyLink) )
{
throw IllegalArgumentException(
- "Library is readonly.",
+ u"Library is readonly."_ustr,
// TODO: resource
*this, 0
);
@@ -3037,8 +3030,9 @@ void SfxLibrary::replaceByName( const OUString& aName, const Any& aElement )
!isLibraryElementValid(aElement), "basic",
"SfxLibrary::replaceByName: replacing element is invalid!");
- maNameContainer->replaceByName( aName, aElement );
- implSetModified( true );
+ std::unique_lock guard(m_aMutex);
+ maNameContainer.replaceByName(aName, aElement, guard);
+ implSetModified(true, guard);
}
@@ -3052,14 +3046,16 @@ void SfxLibrary::insertByName( const OUString& aName, const Any& aElement )
!isLibraryElementValid(aElement), "basic",
"SfxLibrary::insertByName: to-be-inserted element is invalid!");
- maNameContainer->insertByName( aName, aElement );
- implSetModified( true );
+ std::unique_lock guard(m_aMutex);
+ maNameContainer.insertByName(aName, aElement, guard);
+ implSetModified(true, guard);
}
-void SfxLibrary::impl_removeWithoutChecks( const OUString& _rElementName )
+void SfxLibrary::impl_removeWithoutChecks(const OUString& _rElementName,
+ std::unique_lock<std::mutex>& guard)
{
- maNameContainer->removeByName( _rElementName );
- implSetModified( true );
+ maNameContainer.removeByName(_rElementName, guard);
+ implSetModified(true, guard);
// Remove element file
if( maStorageURL.isEmpty() )
@@ -3089,49 +3085,31 @@ void SfxLibrary::removeByName( const OUString& Name )
{
impl_checkReadOnly();
impl_checkLoaded();
- impl_removeWithoutChecks( Name );
-}
-
-// XTypeProvider
-Sequence< Type > SfxLibrary::getTypes()
-{
- static OTypeCollection ourTypes_NameContainer(
- cppu::UnoType<XNameContainer>::get(),
- cppu::UnoType<XContainer>::get(),
- cppu::UnoType<XChangesNotifier>::get(),
- OComponentHelper::getTypes() );
-
- return ourTypes_NameContainer.getTypes();
-}
-
-
-Sequence< sal_Int8 > SfxLibrary::getImplementationId()
-{
- return css::uno::Sequence<sal_Int8>();
+ impl_removeWithoutChecks(Name, o3tl::temporary(std::unique_lock(m_aMutex)));
}
// Methods XContainer
void SAL_CALL SfxLibrary::addContainerListener( const Reference< XContainerListener >& xListener )
{
- maNameContainer->setEventSource( static_cast< XInterface* >( static_cast<OWeakObject*>(this) ) );
- maNameContainer->addContainerListener( xListener );
+ maNameContainer.setEventSource( getXWeak() );
+ maNameContainer.addContainerListener(xListener, o3tl::temporary(std::unique_lock(m_aMutex)));
}
void SAL_CALL SfxLibrary::removeContainerListener( const Reference< XContainerListener >& xListener )
{
- maNameContainer->removeContainerListener( xListener );
+ maNameContainer.removeContainerListener(xListener, o3tl::temporary(std::unique_lock(m_aMutex)));
}
// Methods XChangesNotifier
void SAL_CALL SfxLibrary::addChangesListener( const Reference< XChangesListener >& xListener )
{
- maNameContainer->setEventSource( static_cast< XInterface* >( static_cast<OWeakObject*>(this) ) );
- maNameContainer->addChangesListener( xListener );
+ maNameContainer.setEventSource( getXWeak() );
+ maNameContainer.addChangesListener(xListener, o3tl::temporary(std::unique_lock(m_aMutex)));
}
void SAL_CALL SfxLibrary::removeChangesListener( const Reference< XChangesListener >& xListener )
{
- maNameContainer->removeChangesListener( xListener );
+ maNameContainer.removeChangesListener(xListener, o3tl::temporary(std::unique_lock(m_aMutex)));
}
@@ -3253,11 +3231,10 @@ Reference< deployment::XPackage > ScriptSubPackageIterator::getNextScriptSubPack
}
if( m_bIsBundle )
{
- const Reference< deployment::XPackage >* pSeq = m_aSubPkgSeq.getConstArray();
sal_Int32 iPkg;
for( iPkg = m_iNextSubPkg ; iPkg < m_nSubPkgCount ; ++iPkg )
{
- const Reference< deployment::XPackage > xSubPkg = pSeq[ iPkg ];
+ const Reference<deployment::XPackage> xSubPkg = m_aSubPkgSeq[iPkg];
xScriptPackage = implDetectScriptPackage( xSubPkg, rbPureDialogLib );
if( xScriptPackage.is() )
{
@@ -3307,7 +3284,7 @@ Reference< deployment::XPackage > ScriptExtensionIterator::implGetNextUserScript
try
{
Reference< XExtensionManager > xManager = ExtensionManager::get( m_xContext );
- m_aUserPackagesSeq = xManager->getDeployedExtensions("user",
+ m_aUserPackagesSeq = xManager->getDeployedExtensions(u"user"_ustr,
Reference< task::XAbortChannel >(),
Reference< ucb::XCommandEnvironment >() );
}
@@ -3329,8 +3306,7 @@ Reference< deployment::XPackage > ScriptExtensionIterator::implGetNextUserScript
{
if( m_pScriptSubPackageIterator == nullptr )
{
- const Reference< deployment::XPackage >* pUserPackages = m_aUserPackagesSeq.getConstArray();
- Reference< deployment::XPackage > xPackage = pUserPackages[ m_iUserPackage ];
+ Reference<deployment::XPackage> xPackage = m_aUserPackagesSeq[m_iUserPackage];
SAL_WARN_IF(
!xPackage.is(), "basic",
("ScriptExtensionIterator::implGetNextUserScriptPackage():"
@@ -3359,7 +3335,7 @@ Reference< deployment::XPackage > ScriptExtensionIterator::implGetNextSharedScri
try
{
Reference< XExtensionManager > xSharedManager = ExtensionManager::get( m_xContext );
- m_aSharedPackagesSeq = xSharedManager->getDeployedExtensions("shared",
+ m_aSharedPackagesSeq = xSharedManager->getDeployedExtensions(u"shared"_ustr,
Reference< task::XAbortChannel >(),
Reference< ucb::XCommandEnvironment >() );
}
@@ -3380,8 +3356,7 @@ Reference< deployment::XPackage > ScriptExtensionIterator::implGetNextSharedScri
{
if( m_pScriptSubPackageIterator == nullptr )
{
- const Reference< deployment::XPackage >* pSharedPackages = m_aSharedPackagesSeq.getConstArray();
- Reference< deployment::XPackage > xPackage = pSharedPackages[ m_iSharedPackage ];
+ Reference<deployment::XPackage> xPackage = m_aSharedPackagesSeq[m_iSharedPackage];
SAL_WARN_IF(
!xPackage.is(), "basic",
("ScriptExtensionIterator::implGetNextSharedScriptPackage():"
@@ -3410,7 +3385,7 @@ Reference< deployment::XPackage > ScriptExtensionIterator::implGetNextBundledScr
try
{
Reference< XExtensionManager > xManager = ExtensionManager::get( m_xContext );
- m_aBundledPackagesSeq = xManager->getDeployedExtensions("bundled",
+ m_aBundledPackagesSeq = xManager->getDeployedExtensions(u"bundled"_ustr,
Reference< task::XAbortChannel >(),
Reference< ucb::XCommandEnvironment >() );
}
@@ -3431,8 +3406,7 @@ Reference< deployment::XPackage > ScriptExtensionIterator::implGetNextBundledScr
{
if( m_pScriptSubPackageIterator == nullptr )
{
- const Reference< deployment::XPackage >* pBundledPackages = m_aBundledPackagesSeq.getConstArray();
- Reference< deployment::XPackage > xPackage = pBundledPackages[ m_iBundledPackage ];
+ Reference<deployment::XPackage> xPackage = m_aBundledPackagesSeq[m_iBundledPackage];
SAL_WARN_IF(
!xPackage.is(), "basic",
("ScriptExtensionIterator::implGetNextBundledScriptPackage():"
diff --git a/basic/source/uno/scriptcont.cxx b/basic/source/uno/scriptcont.cxx
index 5ccf6cc0ddfb..2fbed6ae9253 100644
--- a/basic/source/uno/scriptcont.cxx
+++ b/basic/source/uno/scriptcont.cxx
@@ -38,7 +38,7 @@
// For password functionality
#include <tools/urlobj.hxx>
-
+#include <o3tl/temporary.hxx>
#include <svtools/sfxecode.hxx>
#include <svtools/ehdl.hxx>
#include <basic/basmgr.hxx>
@@ -51,7 +51,6 @@
namespace basic
{
-using namespace com::sun::star::document;
using namespace com::sun::star::container;
using namespace com::sun::star::io;
using namespace com::sun::star::uno;
@@ -61,17 +60,31 @@ using namespace com::sun::star::script;
using namespace com::sun::star::xml::sax;
using namespace com::sun::star;
using namespace cppu;
-using namespace osl;
// Implementation class SfxScriptLibraryContainer
-const char* SfxScriptLibraryContainer::getInfoFileName() const { return "script"; }
-const char* SfxScriptLibraryContainer::getOldInfoFileName() const { return "script"; }
-const char* SfxScriptLibraryContainer::getLibElementFileExtension() const { return "xba"; }
-const char* SfxScriptLibraryContainer::getLibrariesDir() const { return "Basic"; }
+OUString SfxScriptLibraryContainer::getInfoFileName() const
+{
+ static constexpr OUStringLiteral script = u"script";
+ return script;
+}
+OUString SfxScriptLibraryContainer::getOldInfoFileName() const
+{
+ static constexpr OUStringLiteral script = u"script";
+ return script;
+}
+OUString SfxScriptLibraryContainer::getLibElementFileExtension() const
+{
+ static constexpr OUStringLiteral xba = u"xba";
+ return xba;
+}
+OUString SfxScriptLibraryContainer::getLibrariesDir() const
+{
+ static constexpr OUStringLiteral sBasic = u"Basic";
+ return sBasic;
+}
-// OldBasicPassword interface
void SfxScriptLibraryContainer::setLibraryPassword( const OUString& rLibraryName, const OUString& rPassword )
{
try
@@ -101,7 +114,7 @@ SfxScriptLibraryContainer::SfxScriptLibraryContainer()
SfxScriptLibraryContainer::SfxScriptLibraryContainer( const uno::Reference< embed::XStorage >& xStorage )
{
- init( OUString(), xStorage );
+ init(OUString(), xStorage, o3tl::temporary(std::unique_lock(m_aMutex)));
}
// Methods to get library instances of the correct type
@@ -215,7 +228,7 @@ Any SfxScriptLibraryContainer::importLibraryElement
return aRetAny;
InputSource source;
- source.aInputStream = xInput;
+ source.aInputStream = std::move(xInput);
source.sSystemId = aFile;
// start parsing
@@ -250,7 +263,7 @@ Any SfxScriptLibraryContainer::importLibraryElement
{
Reference< frame::XModel > xModel( mxOwnerDocument ); // weak-ref -> ref
Reference< XMultiServiceFactory > xFactory( xModel, UNO_QUERY_THROW );
- xFactory->createInstance("ooo.vba.VBAGlobals");
+ xFactory->createInstance(u"ooo.vba.VBAGlobals"_ustr);
}
catch(const Exception& )
{
@@ -280,7 +293,7 @@ Any SfxScriptLibraryContainer::importLibraryElement
{
Reference<frame::XModel > xModel( mxOwnerDocument );
Reference< XMultiServiceFactory> xSF( xModel, UNO_QUERY_THROW );
- mxCodeNameAccess.set( xSF->createInstance("ooo.vba.VBAObjectModuleObjectProvider"), UNO_QUERY );
+ mxCodeNameAccess.set( xSF->createInstance(u"ooo.vba.VBAObjectModuleObjectProvider"_ustr), UNO_QUERY );
}
catch(const Exception& ) {}
@@ -319,14 +332,14 @@ rtl::Reference<SfxLibraryContainer> SfxScriptLibraryContainer::createInstanceImp
void SfxScriptLibraryContainer::importFromOldStorage( const OUString& aFile )
{
// TODO: move loading from old storage to binary filters?
- auto xStorage = tools::make_ref<SotStorage>( false, aFile );
+ rtl::Reference<SotStorage> xStorage(new SotStorage(false, aFile));
if( xStorage->GetError() == ERRCODE_NONE )
{
- auto pBasicManager = std::make_unique<BasicManager> ( *xStorage, aFile );
+ BasicManager aBasicManager( *xStorage, aFile );
// Set info
- LibraryContainerInfo aInfo( this, nullptr, static_cast< OldBasicPassword* >( this ) );
- pBasicManager->SetLibraryContainerInfo( aInfo );
+ LibraryContainerInfo aInfo( this, nullptr, this );
+ aBasicManager.SetLibraryContainerInfo( aInfo );
}
}
@@ -348,7 +361,7 @@ sal_Bool SAL_CALL SfxScriptLibraryContainer::isLibraryPasswordVerified( const OU
SfxLibrary* pImplLib = getImplLib( Name );
if( !pImplLib->mbPasswordProtected )
{
- throw IllegalArgumentException("!passwordProtected", static_cast<cppu::OWeakObject*>(this), 1);
+ throw IllegalArgumentException(u"!passwordProtected"_ustr, getXWeak(), 1);
}
bool bRet = pImplLib->mbPasswordVerified;
return bRet;
@@ -358,10 +371,11 @@ sal_Bool SAL_CALL SfxScriptLibraryContainer::verifyLibraryPassword
( const OUString& Name, const OUString& Password )
{
LibraryContainerMethodGuard aGuard( *this );
+ std::unique_lock guard(m_aMutex);
SfxLibrary* pImplLib = getImplLib( Name );
if( !pImplLib->mbPasswordProtected || pImplLib->mbPasswordVerified )
{
- throw IllegalArgumentException("!PasswordProtected || PasswordVerified", static_cast<cppu::OWeakObject*>(this), 1);
+ throw IllegalArgumentException(u"!PasswordProtected || PasswordVerified"_ustr, getXWeak(), 1);
}
// Test password
bool bSuccess = false;
@@ -376,19 +390,19 @@ sal_Bool SAL_CALL SfxScriptLibraryContainer::verifyLibraryPassword
else
{
pImplLib->maPassword = Password;
- bSuccess = implLoadPasswordLibrary( pImplLib, Name, true );
+ bSuccess = implLoadPasswordLibrary( pImplLib, Name, true, guard);
if( bSuccess )
{
// The library gets modified by verifying the password, because other-
// wise for saving the storage would be copied and that doesn't work
// with mtg's storages when the password is verified
- pImplLib->implSetModified( true );
+ pImplLib->implSetModified(true, guard);
pImplLib->mbPasswordVerified = true;
// Reload library to get source
if( pImplLib->mbLoaded )
{
- implLoadPasswordLibrary( pImplLib, Name );
+ implLoadPasswordLibrary( pImplLib, Name, false, guard);
}
}
}
@@ -445,14 +459,15 @@ void SAL_CALL SfxScriptLibraryContainer::changeLibraryPassword( const OUString&
pImplLib->mbPasswordVerified = false;
pImplLib->maPassword.clear();
- maModifiable.setModified( true );
- pImplLib->implSetModified( true );
+ std::unique_lock guard(m_aMutex);
+ maModifiable.setModified(true, guard);
+ pImplLib->implSetModified(true, guard);
if( !bStorage && !pImplLib->mbDoc50Password )
{
// Store application basic unencrypted
uno::Reference< embed::XStorage > xStorage;
- storeLibraries_Impl( xStorage, false );
+ storeLibraries_Impl(xStorage, false, guard);
bKillCryptedFiles = true;
}
}
@@ -470,14 +485,15 @@ void SAL_CALL SfxScriptLibraryContainer::changeLibraryPassword( const OUString&
pSL->mbLoadedSource = true; // must store source code now!
}
- maModifiable.setModified( true );
- pImplLib->implSetModified( true );
+ std::unique_lock guard(m_aMutex);
+ maModifiable.setModified(true, guard);
+ pImplLib->implSetModified(true, guard);
if( !bStorage && !pImplLib->mbDoc50Password )
{
// Store application basic crypted
uno::Reference< embed::XStorage > xStorage;
- storeLibraries_Impl( xStorage, false );
+ storeLibraries_Impl(xStorage, false, guard);
bKillUnencryptedFiles = true;
}
}
@@ -557,7 +573,7 @@ bool SfxScriptLibraryContainer::implStorePasswordLibrary( SfxLibrary* pLib, cons
// save/saveas etc are handled in sfxbasemodel::storeSelf &
// sfxbasemodel::impl_store
std::vector<OUString> aNames;
- if ( bExport && pBasicMgr->LegacyPsswdBinaryLimitExceeded(aNames) )
+ if ( bExport && pBasicMgr->ImgVersion12PsswdBinaryLimitExceeded(aNames) )
{
if ( xHandler.is() )
{
@@ -600,7 +616,7 @@ bool SfxScriptLibraryContainer::implStorePasswordLibrary( SfxLibrary* pLib, cons
if ( !xCodeStream.is() )
{
- throw uno::RuntimeException("null returned from openStreamElement");
+ throw uno::RuntimeException(u"null returned from openStreamElement"_ustr);
}
SvMemoryStream aMemStream;
/*sal_Bool bStore = */pMod->StoreBinaryData( aMemStream );
@@ -640,7 +656,7 @@ bool SfxScriptLibraryContainer::implStorePasswordLibrary( SfxLibrary* pLib, cons
aSourceStreamName,
embed::ElementModes::READWRITE );
uno::Reference< beans::XPropertySet > xProps( xSourceStream, uno::UNO_QUERY_THROW );
- xProps->setPropertyValue("MediaType", uno::Any( OUString( "text/xml" ) ) );
+ xProps->setPropertyValue(u"MediaType"_ustr, uno::Any( u"text/xml"_ustr ) );
// Set encryption key
setStreamKey( xSourceStream, pLib->maPassword );
@@ -717,14 +733,14 @@ bool SfxScriptLibraryContainer::implStorePasswordLibrary( SfxLibrary* pLib, cons
embed::ElementModes::READWRITE );
if ( !xElementRootStorage.is() )
{
- throw uno::RuntimeException("null returned from GetStorageFromURL");
+ throw uno::RuntimeException(u"null returned from GetStorageFromURL"_ustr);
}
// Write binary image stream
SbModule* pMod = pBasicLib->FindModule( aElementName );
if( pMod )
{
uno::Reference< io::XStream > xCodeStream = xElementRootStorage->openStreamElement(
- "code.bin",
+ u"code.bin"_ustr,
embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE );
SvMemoryStream aMemStream;
@@ -745,7 +761,7 @@ bool SfxScriptLibraryContainer::implStorePasswordLibrary( SfxLibrary* pLib, cons
}
// Write encrypted source stream
- OUString aSourceStreamName( "source.xml" );
+ OUString aSourceStreamName( u"source.xml"_ustr );
uno::Reference< io::XStream > xSourceStream;
try
@@ -767,7 +783,7 @@ bool SfxScriptLibraryContainer::implStorePasswordLibrary( SfxLibrary* pLib, cons
}
uno::Reference< beans::XPropertySet > xProps( xSourceStream, uno::UNO_QUERY_THROW );
- xProps->setPropertyValue("MediaType", uno::Any( OUString( "text/xml" ) ) );
+ xProps->setPropertyValue(u"MediaType"_ustr, uno::Any( u"text/xml"_ustr ) );
Reference< XOutputStream > xOut = xSourceStream->getOutputStream();
Reference< XNameContainer > xLib( pLib );
@@ -793,7 +809,7 @@ bool SfxScriptLibraryContainer::implStorePasswordLibrary( SfxLibrary* pLib, cons
}
bool SfxScriptLibraryContainer::implLoadPasswordLibrary
- ( SfxLibrary* pLib, const OUString& Name, bool bVerifyPasswordOnly )
+ ( SfxLibrary* pLib, const OUString& Name, bool bVerifyPasswordOnly, std::unique_lock<std::mutex>& guard )
{
bool bRet = true;
@@ -848,12 +864,12 @@ bool SfxScriptLibraryContainer::implLoadPasswordLibrary
xLibrariesStor = mxStorage->openStorageElement( maLibrariesDir, embed::ElementModes::READ );
if ( !xLibrariesStor.is() )
{
- throw uno::RuntimeException("null returned from openStorageElement");
+ throw uno::RuntimeException(u"null returned from openStorageElement"_ustr);
}
xLibraryStor = xLibrariesStor->openStorageElement( Name, embed::ElementModes::READ );
if ( !xLibraryStor.is() )
{
- throw uno::RuntimeException("null returned from openStorageElement");
+ throw uno::RuntimeException(u"null returned from openStorageElement"_ustr);
}
}
catch(const uno::Exception& )
@@ -884,7 +900,7 @@ bool SfxScriptLibraryContainer::implLoadPasswordLibrary
embed::ElementModes::READ );
if ( !xCodeStream.is() )
{
- throw uno::RuntimeException("null returned from openStreamElement");
+ throw uno::RuntimeException(u"null returned from openStreamElement"_ustr);
}
std::unique_ptr<SvStream> pStream(::utl::UcbStreamHelper::CreateStream( xCodeStream ));
if ( !pStream || pStream->GetError() )
@@ -919,7 +935,7 @@ bool SfxScriptLibraryContainer::implLoadPasswordLibrary
pLib->maPassword );
if ( !xSourceStream.is() )
{
- throw uno::RuntimeException("null returned from openEncryptedStreamElement");
+ throw uno::RuntimeException(u"null returned from openEncryptedStreamElement"_ustr);
}
// if this point is reached then the password is correct
if ( !bVerifyPasswordOnly )
@@ -937,12 +953,12 @@ bool SfxScriptLibraryContainer::implLoadPasswordLibrary
{
if( aAny.hasValue() )
{
- pLib->maNameContainer->replaceByName( aElementName, aAny );
+ pLib->maNameContainer.replaceByName(aElementName, aAny, guard);
}
}
else
{
- pLib->maNameContainer->insertByName( aElementName, aAny );
+ pLib->maNameContainer.insertByName(aElementName, aAny, guard);
}
}
}
@@ -995,7 +1011,7 @@ bool SfxScriptLibraryContainer::implLoadPasswordLibrary
try
{
uno::Reference< io::XStream > xCodeStream = xElementRootStorage->openStreamElement(
- "code.bin",
+ u"code.bin"_ustr,
embed::ElementModes::READ );
std::unique_ptr<SvStream> pStream(::utl::UcbStreamHelper::CreateStream( xCodeStream ));
@@ -1025,14 +1041,14 @@ bool SfxScriptLibraryContainer::implLoadPasswordLibrary
// Access encrypted source stream
try
{
- OUString aSourceStreamName( "source.xml" );
+ OUString aSourceStreamName( u"source.xml"_ustr );
uno::Reference< io::XStream > xSourceStream = xElementRootStorage->openEncryptedStreamElement(
aSourceStreamName,
embed::ElementModes::READ,
pLib->maPassword );
if ( !xSourceStream.is() )
{
- throw uno::RuntimeException("null returned from openEncryptedStreamElement");
+ throw uno::RuntimeException(u"null returned from openEncryptedStreamElement"_ustr);
}
if ( !bVerifyPasswordOnly )
{
@@ -1050,12 +1066,13 @@ bool SfxScriptLibraryContainer::implLoadPasswordLibrary
{
if( aAny.hasValue() )
{
- pLib->maNameContainer->replaceByName( aElementName, aAny );
+ pLib->maNameContainer.replaceByName(aElementName, aAny,
+ guard);
}
}
else
{
- pLib->maNameContainer->insertByName( aElementName, aAny );
+ pLib->maNameContainer.insertByName(aElementName, aAny, guard);
}
}
}
@@ -1098,13 +1115,13 @@ sal_Bool SAL_CALL SfxScriptLibraryContainer:: HasExecutableCode( const OUString&
// Service
OUString SAL_CALL SfxScriptLibraryContainer::getImplementationName( )
{
- return "com.sun.star.comp.sfx2.ScriptLibraryContainer";
+ return u"com.sun.star.comp.sfx2.ScriptLibraryContainer"_ustr;
}
Sequence< OUString > SAL_CALL SfxScriptLibraryContainer::getSupportedServiceNames( )
{
- return {"com.sun.star.script.DocumentScriptLibraryContainer",
- "com.sun.star.script.ScriptLibraryContainer"}; // for compatibility
+ return {u"com.sun.star.script.DocumentScriptLibraryContainer"_ustr,
+ u"com.sun.star.script.ScriptLibraryContainer"_ustr}; // for compatibility
}
// Implementation class SfxScriptLibrary
@@ -1112,7 +1129,7 @@ Sequence< OUString > SAL_CALL SfxScriptLibraryContainer::getSupportedServiceName
// Ctor
SfxScriptLibrary::SfxScriptLibrary( ModifiableHelper& _rModifiable,
const Reference< XSimpleFileAccess3 >& xSFI )
- : SfxLibrary( _rModifiable, cppu::UnoType<OUString>::get(), xSFI )
+ : SfxScriptLibrary_BASE(_rModifiable, cppu::UnoType<OUString>::get(), xSFI)
, mbLoadedSource( false )
, mbLoadedBinary( false )
{
@@ -1123,7 +1140,7 @@ SfxScriptLibrary::SfxScriptLibrary( ModifiableHelper& _rModifiable,
const OUString& aLibInfoFileURL,
const OUString& aStorageURL,
bool ReadOnly )
- : SfxLibrary( _rModifiable, cppu::UnoType<OUString>::get(), xSFI,
+ : SfxScriptLibrary_BASE(_rModifiable, cppu::UnoType<OUString>::get(), xSFI,
aLibInfoFileURL, aStorageURL, ReadOnly)
, mbLoadedSource( false )
, mbLoadedBinary( false )
@@ -1133,7 +1150,7 @@ SfxScriptLibrary::SfxScriptLibrary( ModifiableHelper& _rModifiable,
bool SfxScriptLibrary::isLoadedStorable()
{
// note: mbLoadedSource can only be true for password-protected lib!
- return SfxLibrary::isLoadedStorable() && (!mbPasswordProtected || mbLoadedSource);
+ return SfxLibrary::isLoadedStorable() && (!isPasswordProtected() || mbLoadedSource);
}
// Provide modify state including resources
@@ -1173,9 +1190,6 @@ bool SfxScriptLibrary::isLibraryElementValid(const css::uno::Any& rElement) cons
return SfxScriptLibrary::containsValidModule(rElement);
}
-IMPLEMENT_FORWARD_XINTERFACE2( SfxScriptLibrary, SfxLibrary, SfxScriptLibrary_BASE );
-IMPLEMENT_FORWARD_XTYPEPROVIDER2( SfxScriptLibrary, SfxLibrary, SfxScriptLibrary_BASE );
-
script::ModuleInfo SAL_CALL SfxScriptLibrary::getModuleInfo( const OUString& ModuleName )
{
if ( !hasModuleInfo( ModuleName ) )