summaryrefslogtreecommitdiff
path: root/basic/source/classes/sb.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'basic/source/classes/sb.cxx')
-rw-r--r--basic/source/classes/sb.cxx284
1 files changed, 154 insertions, 130 deletions
diff --git a/basic/source/classes/sb.cxx b/basic/source/classes/sb.cxx
index 4ebab52ee2c4..9b702e08d5a1 100644
--- a/basic/source/classes/sb.cxx
+++ b/basic/source/classes/sb.cxx
@@ -18,6 +18,7 @@
*/
#include <sb.hxx>
+#include <o3tl/safeint.hxx>
#include <rtl/ustrbuf.hxx>
#include <tools/stream.hxx>
#include <tools/debug.hxx>
@@ -50,9 +51,11 @@
#include <com/sun/star/script/ModuleType.hpp>
#include <com/sun/star/script/ModuleInfo.hpp>
+#include <strings.hrc>
+
using namespace ::com::sun::star::script;
-#define SB_RTLNAME "@SBRTL"
+constexpr OUString SB_RTLNAME = u"@SBRTL"_ustr;
// i#i68894#
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
@@ -177,31 +180,31 @@ namespace {
typedef ::rtl::Reference< DocBasicItem > DocBasicItemRef;
-class GaDocBasicItems : public rtl::Static<std::unordered_map< const StarBASIC *, DocBasicItemRef >,GaDocBasicItems> {};
+std::unordered_map< const StarBASIC *, DocBasicItemRef > gaDocBasicItems;
const DocBasicItem* lclFindDocBasicItem( const StarBASIC* pDocBasic )
{
- auto it = GaDocBasicItems::get().find( pDocBasic );
- auto end = GaDocBasicItems::get().end();
+ auto it = gaDocBasicItems.find( pDocBasic );
+ auto end = gaDocBasicItems.end();
return (it != end) ? it->second.get() : nullptr;
}
void lclInsertDocBasicItem( StarBASIC& rDocBasic )
{
- DocBasicItemRef& rxDocBasicItem = GaDocBasicItems::get()[ &rDocBasic ];
+ DocBasicItemRef& rxDocBasicItem = gaDocBasicItems[ &rDocBasic ];
rxDocBasicItem.set( new DocBasicItem( rDocBasic ) );
rxDocBasicItem->startListening();
}
void lclRemoveDocBasicItem( StarBASIC& rDocBasic )
{
- auto it = GaDocBasicItems::get().find( &rDocBasic );
- if( it != GaDocBasicItems::get().end() )
+ auto it = gaDocBasicItems.find( &rDocBasic );
+ if( it != gaDocBasicItems.end() )
{
it->second->stopListening();
- GaDocBasicItems::get().erase( it );
+ gaDocBasicItems.erase( it );
}
- for( auto& rEntry : GaDocBasicItems::get() )
+ for( auto& rEntry : gaDocBasicItems )
{
rEntry.second->clearDependingVarsOnDelete( rDocBasic );
}
@@ -410,7 +413,7 @@ const SFX_VB_ErrorItem SFX_VB_ErrorTab[] =
// the Module-relationship. But it works only when a module is loaded.
// Can cause troubles with separately loaded properties!
-SbxBase* SbiFactory::Create( sal_uInt16 nSbxId, sal_uInt32 nCreator )
+SbxBaseRef SbiFactory::Create( sal_uInt16 nSbxId, sal_uInt32 nCreator )
{
if( nCreator == SBXCR_SBX )
{
@@ -433,7 +436,7 @@ SbxBase* SbiFactory::Create( sal_uInt16 nSbxId, sal_uInt32 nCreator )
return nullptr;
}
-SbxObject* SbiFactory::CreateObject( const OUString& rClass )
+SbxObjectRef SbiFactory::CreateObject( const OUString& rClass )
{
if( rClass.equalsIgnoreAsciiCase( "StarBASIC" ) )
{
@@ -464,28 +467,28 @@ SbxObject* SbiFactory::CreateObject( const OUString& rClass )
}
-SbxBase* SbOLEFactory::Create( sal_uInt16, sal_uInt32 )
+SbxBaseRef SbOLEFactory::Create( sal_uInt16, sal_uInt32 )
{
// Not supported
return nullptr;
}
-SbxObject* SbOLEFactory::CreateObject( const OUString& rClassName )
+SbxObjectRef SbOLEFactory::CreateObject( const OUString& rClassName )
{
- SbxObject* pRet = createOLEObject_Impl( rClassName );
+ SbxObjectRef pRet = createOLEObject_Impl( rClassName );
return pRet;
}
// SbFormFactory, show user forms by: dim as new <user form name>
-SbxBase* SbFormFactory::Create( sal_uInt16, sal_uInt32 )
+SbxBaseRef SbFormFactory::Create( sal_uInt16, sal_uInt32 )
{
// Not supported
return nullptr;
}
-SbxObject* SbFormFactory::CreateObject( const OUString& rClassName )
+SbxObjectRef SbFormFactory::CreateObject( const OUString& rClassName )
{
if( SbModule* pMod = GetSbData()->pMod )
{
@@ -514,17 +517,17 @@ SbxObject* SbFormFactory::CreateObject( const OUString& rClassName )
// SbTypeFactory
-SbxObject* cloneTypeObjectImpl( const SbxObject& rTypeObj )
+SbxObjectRef cloneTypeObjectImpl( const SbxObject& rTypeObj )
{
- SbxObject* pRet = new SbxObject( rTypeObj );
- pRet->PutObject( pRet );
+ SbxObjectRef pRet = new SbxObject( rTypeObj );
+ pRet->PutObject( pRet.get() );
// Copy the properties, not only the reference to them
SbxArray* pProps = pRet->GetProperties();
- sal_uInt32 nCount = pProps->Count32();
+ sal_uInt32 nCount = pProps->Count();
for( sal_uInt32 i = 0 ; i < nCount ; i++ )
{
- SbxVariable* pVar = pProps->Get32( i );
+ SbxVariable* pVar = pProps->Get(i);
SbxProperty* pProp = dynamic_cast<SbxProperty*>( pVar );
if( pProp )
{
@@ -537,19 +540,19 @@ SbxObject* cloneTypeObjectImpl( const SbxObject& rTypeObj )
SbxDimArray* pDest = new SbxDimArray( pVar->GetType() );
pDest->setHasFixedSize( pSource && pSource->hasFixedSize() );
- if ( pSource && pSource->GetDims32() && pSource->hasFixedSize() )
+ if (pSource && pSource->GetDims() && pSource->hasFixedSize())
{
sal_Int32 lb = 0;
sal_Int32 ub = 0;
- for ( sal_Int32 j = 1 ; j <= pSource->GetDims32(); ++j )
+ for (sal_Int32 j = 1; j <= pSource->GetDims(); ++j)
{
- pSource->GetDim32( j, lb, ub );
- pDest->AddDim32( lb, ub );
+ pSource->GetDim(j, lb, ub);
+ pDest->AddDim(lb, ub);
}
}
else
{
- pDest->unoAddDim32( 0, -1 ); // variant array
+ pDest->unoAddDim(0, -1); // variant array
}
SbxFlagBits nSavFlags = pVar->GetFlags();
pNewProp->ResetFlag( SbxFlagBits::Fixed );
@@ -562,10 +565,10 @@ SbxObject* cloneTypeObjectImpl( const SbxObject& rTypeObj )
{
SbxBase* pObjBase = pVar->GetObject();
SbxObject* pSrcObj = dynamic_cast<SbxObject*>( pObjBase );
- SbxObject* pDestObj = nullptr;
+ SbxObjectRef pDestObj;
if( pSrcObj != nullptr )
pDestObj = cloneTypeObjectImpl( *pSrcObj );
- pNewProp->PutObject( pDestObj );
+ pNewProp->PutObject( pDestObj.get() );
}
pProps->PutDirect( pNewProp, i );
}
@@ -573,15 +576,15 @@ SbxObject* cloneTypeObjectImpl( const SbxObject& rTypeObj )
return pRet;
}
-SbxBase* SbTypeFactory::Create( sal_uInt16, sal_uInt32 )
+SbxBaseRef SbTypeFactory::Create( sal_uInt16, sal_uInt32 )
{
// Not supported
return nullptr;
}
-SbxObject* SbTypeFactory::CreateObject( const OUString& rClassName )
+SbxObjectRef SbTypeFactory::CreateObject( const OUString& rClassName )
{
- SbxObject* pRet = nullptr;
+ SbxObjectRef pRet;
SbModule* pMod = GetSbData()->pMod;
if( pMod )
{
@@ -594,9 +597,9 @@ SbxObject* SbTypeFactory::CreateObject( const OUString& rClassName )
return pRet;
}
-SbxObject* createUserTypeImpl( const OUString& rClassName )
+SbxObjectRef createUserTypeImpl( const OUString& rClassName )
{
- SbxObject* pRetObj = GetSbData()->pTypeFac->CreateObject( rClassName );
+ SbxObjectRef pRetObj = GetSbData()->pTypeFac->CreateObject( rClassName );
return pRetObj;
}
@@ -609,7 +612,7 @@ SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule )
aOUSource = pClassModule->aOUSource;
aComment = pClassModule->aComment;
// see comment in destructor about these two
- pImage = pClassModule->pImage;
+ pImage.reset(pClassModule->pImage.get());
pBreaks = pClassModule->pBreaks;
SetClassName( pClassModule->GetName() );
@@ -619,11 +622,11 @@ SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule )
// Copy the methods from original class module
SbxArray* pClassMethods = pClassModule->GetMethods().get();
- sal_uInt32 nMethodCount = pClassMethods->Count32();
+ sal_uInt32 nMethodCount = pClassMethods->Count();
sal_uInt32 i;
for( i = 0 ; i < nMethodCount ; i++ )
{
- SbxVariable* pVar = pClassMethods->Get32( i );
+ SbxVariable* pVar = pClassMethods->Get(i);
// Exclude SbIfaceMapperMethod to copy them in a second step
SbIfaceMapperMethod* pIfaceMethod = dynamic_cast<SbIfaceMapperMethod*>( pVar );
@@ -649,7 +652,7 @@ SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule )
// the corresponding base methods have already been copied
for( i = 0 ; i < nMethodCount ; i++ )
{
- SbxVariable* pVar = pClassMethods->Get32( i );
+ SbxVariable* pVar = pClassMethods->Get(i);
SbIfaceMapperMethod* pIfaceMethod = dynamic_cast<SbIfaceMapperMethod*>( pVar );
if( pIfaceMethod )
@@ -677,10 +680,10 @@ SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule )
// Copy the properties from original class module
SbxArray* pClassProps = pClassModule->GetProperties();
- sal_uInt32 nPropertyCount = pClassProps->Count32();
+ sal_uInt32 nPropertyCount = pClassProps->Count();
for( i = 0 ; i < nPropertyCount ; i++ )
{
- SbxVariable* pVar = pClassProps->Get32( i );
+ SbxVariable* pVar = pClassProps->Get(i);
SbProcedureProperty* pProcedureProp = dynamic_cast<SbProcedureProperty*>( pVar );
if( pProcedureProp )
{
@@ -741,7 +744,7 @@ SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule )
}
}
SetModuleType( ModuleType::CLASS );
- mbVBACompat = pClassModule->mbVBACompat;
+ mbVBASupport = pClassModule->mbVBASupport;
}
SbClassModuleObject::~SbClassModuleObject()
@@ -753,9 +756,9 @@ SbClassModuleObject::~SbClassModuleObject()
if( !pDocBasicItem->isDocClosed() )
triggerTerminateEvent();
- // prevent the base class destructor from deleting these because
- // we do not actually own them
- pImage = nullptr;
+ // prevent the base class destructor from deleting this because:
+ // coverity[leaked_storage] - we do not actually own it
+ pImage.release();
pBreaks = nullptr;
}
@@ -852,13 +855,13 @@ void SbClassFactory::RemoveClassModule( SbModule* pClassModule )
xClassModules->Remove( pClassModule );
}
-SbxBase* SbClassFactory::Create( sal_uInt16, sal_uInt32 )
+SbxBaseRef SbClassFactory::Create( sal_uInt16, sal_uInt32 )
{
// Not supported
return nullptr;
}
-SbxObject* SbClassFactory::CreateObject( const OUString& rClassName )
+SbxObjectRef SbClassFactory::CreateObject( const OUString& rClassName )
{
SbxObjectRef xToUseClassModules = xClassModules;
@@ -873,7 +876,7 @@ SbxObject* SbClassFactory::CreateObject( const OUString& rClassName )
}
}
SbxVariable* pVar = xToUseClassModules->Find( rClassName, SbxClassType::Object );
- SbxObject* pRet = nullptr;
+ SbxObjectRef pRet;
if( pVar )
{
SbModule* pVarMod = static_cast<SbModule*>(pVar);
@@ -898,18 +901,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
@@ -937,17 +940,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 )
@@ -972,10 +975,10 @@ StarBASIC::~StarBASIC()
// #100326 Set Parent NULL in registered listeners
if( xUnoListeners.is() )
{
- sal_uInt32 uCount = xUnoListeners->Count32();
+ sal_uInt32 uCount = xUnoListeners->Count();
for( sal_uInt32 i = 0 ; i < uCount ; i++ )
{
- SbxVariable* pListenerObj = xUnoListeners->Get32( i );
+ SbxVariable* pListenerObj = xUnoListeners->Get(i);
pListenerObj->SetParent( nullptr );
}
xUnoListeners = nullptr;
@@ -994,9 +997,9 @@ void StarBASIC::implClearDependingVarsOnDelete( StarBASIC* pDeletedBasic )
}
}
- for( sal_uInt32 nObj = 0; nObj < pObjs->Count32(); nObj++ )
+ for (sal_uInt32 nObj = 0; nObj < pObjs->Count(); nObj++)
{
- SbxVariable* pVar = pObjs->Get32( nObj );
+ SbxVariable* pVar = pObjs->Get(nObj);
StarBASIC* pBasic = dynamic_cast<StarBASIC*>( pVar );
if( pBasic && pBasic != pDeletedBasic )
{
@@ -1071,7 +1074,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() );
}
@@ -1201,9 +1204,9 @@ void StarBASIC::InitAllModules( StarBASIC const * pBasicNotToInit )
// Check all objects if they are BASIC,
// if yes initialize
- for ( sal_uInt32 nObj = 0; nObj < pObjs->Count32(); nObj++ )
+ for (sal_uInt32 nObj = 0; nObj < pObjs->Count(); nObj++)
{
- SbxVariable* pVar = pObjs->Get32( nObj );
+ SbxVariable* pVar = pObjs->Get(nObj);
StarBASIC* pBasic = dynamic_cast<StarBASIC*>( pVar );
if( pBasic && pBasic != pBasicNotToInit )
{
@@ -1225,9 +1228,9 @@ void StarBASIC::DeInitAllModules()
}
}
- for ( sal_uInt32 nObj = 0; nObj < pObjs->Count32(); nObj++ )
+ for (sal_uInt32 nObj = 0; nObj < pObjs->Count(); nObj++)
{
- SbxVariable* pVar = pObjs->Get32( nObj );
+ SbxVariable* pVar = pObjs->Get(nObj);
StarBASIC* pBasic = dynamic_cast<StarBASIC*>( pVar );
if( pBasic )
{
@@ -1241,7 +1244,7 @@ void StarBASIC::DeInitAllModules()
// a public var or an entrypoint. If it is not found and we look for a
// method and a module with the given name is found the search continues
// for entrypoint "Main".
-// If this fails again a conventional search over objects is performend.
+// If this fails again a conventional search over objects is performed.
SbxVariable* StarBASIC::Find( const OUString& rName, SbxClassType t )
{
SbxVariable* pRes = nullptr;
@@ -1303,7 +1306,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 ) )
{
@@ -1322,11 +1325,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;
}
@@ -1426,7 +1429,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:
@@ -1528,7 +1531,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();
@@ -1538,13 +1541,13 @@ void StarBASIC::SetErrorData( ErrCode nCode, sal_uInt16 nLine,
aGlobals.nCol2 = nCol2;
}
-void StarBASIC::MakeErrorText( ErrCode nId, const OUString& aMsg )
+void StarBASIC::MakeErrorText( ErrCode nId, std::u16string_view aMsg )
{
SolarMutexGuard aSolarGuard;
sal_uInt16 nOldID = GetVBErrorCode( nId );
- const char* pErrorMsg = nullptr;
- for (std::pair<const char *, ErrCode> const *pItem = RID_BASIC_START; pItem->second; ++pItem)
+ TranslateId pErrorMsg;
+ for (std::pair<TranslateId, ErrCode> const *pItem = RID_BASIC_START; pItem->second; ++pItem)
{
if (nId == pItem->second)
{
@@ -1567,13 +1570,24 @@ void StarBASIC::MakeErrorText( ErrCode nId, const OUString& aMsg )
aMsg1.remove(nResult, aSrgStr.getLength());
aMsg1.insert(nResult, aMsg);
}
+ else if (!aMsg.empty())
+ {
+ // tdf#123144 - create a meaningful error message
+ aMsg1 = BasResId(STR_ADDITIONAL_INFO)
+ .replaceFirst("$ERR", aMsg1)
+ .replaceFirst("$MSG", aMsg);
+ }
GetSbData()->aErrMsg = aMsg1.makeStringAndClear();
}
+ // tdf#123144 - don't use an artificial error message if there is a custom one
+ else if (!aMsg.empty())
+ {
+ GetSbData()->aErrMsg = 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
{
@@ -1605,11 +1619,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() )
@@ -1636,6 +1651,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
@@ -1646,15 +1662,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 );
@@ -1665,11 +1681,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 )
@@ -1769,13 +1780,13 @@ bool StarBASIC::LoadData( SvStream& r, sal_uInt16 nVer )
}
// #95459 Delete dialogs, otherwise endless recursion
// in SbxVariable::GetType() if dialogs are accessed
- sal_uInt32 nObjCount = pObjs->Count32();
+ sal_uInt32 nObjCount = pObjs->Count();
std::unique_ptr<SbxVariable*[]> ppDeleteTab(new SbxVariable*[ nObjCount ]);
sal_uInt32 nObj;
for( nObj = 0 ; nObj < nObjCount ; nObj++ )
{
- SbxVariable* pVar = pObjs->Get32( nObj );
+ SbxVariable* pVar = pObjs->Get(nObj);
StarBASIC* pBasic = dynamic_cast<StarBASIC*>( pVar );
ppDeleteTab[nObj] = pBasic ? nullptr : pVar;
}
@@ -1802,8 +1813,8 @@ bool StarBASIC::LoadData( SvStream& r, sal_uInt16 nVer )
}
for (sal_uInt16 i = 0; i < nMod; ++i)
{
- SbxBase* pBase = SbxBase::Load( r );
- SbModule* pMod = dynamic_cast<SbModule*>(pBase);
+ SbxBaseRef pBase = SbxBase::Load( r );
+ SbModule* pMod = dynamic_cast<SbModule*>(pBase.get());
if( !pMod )
{
return false;
@@ -1837,22 +1848,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 )
@@ -1877,7 +1894,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)
- const OUString sThisComponent( "ThisComponent");
+ static constexpr OUStringLiteral sThisComponent( u"ThisComponent");
SbxVariable* pThisComponent = nullptr;
SbxObject* pLookup = pBasic->GetParent();
@@ -1914,8 +1931,7 @@ Reference< frame::XModel > StarBASIC::GetModelFromBasic( SbxObject* pBasic )
void StarBASIC::DetachAllDocBasicItems()
{
- std::unordered_map< const StarBASIC *, DocBasicItemRef >& rItems = GaDocBasicItems::get();
- for (auto const& item : rItems)
+ for (auto const& item : gaDocBasicItems)
{
DocBasicItemRef xItem = item.second;
xItem->setDisposed(true);
@@ -1925,9 +1941,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);
@@ -2000,7 +2020,7 @@ void BasicCollection::Notify( SfxBroadcaster& rCst, const SfxHint& rHint )
if( pVar->GetHashCode() == nCountHash
&& aVarName.equalsIgnoreAsciiCase( pCountStr ) )
{
- pVar->PutLong( xItemArray->Count32() );
+ pVar->PutLong(xItemArray->Count());
}
else if( pVar->GetHashCode() == nAddHash
&& aVarName.equalsIgnoreAsciiCase( pAddStr ) )
@@ -2054,44 +2074,48 @@ 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->Count32();
+ sal_Int32 nCount = xItemArray->Count();
sal_Int32 nNameHash = MakeHashCode( rName );
+
+ // tdf#144245 - case-insensitive operation for non-ASCII characters
+ OUString aNameCI; // Only initialize when matching hash found
+
for( sal_Int32 i = 0 ; i < nCount ; i++ )
{
- SbxVariable* pVar = xItemArray->Get32( i );
- if( pVar->GetHashCode() == nNameHash &&
- pVar->GetName().equalsIgnoreAsciiCase( rName ) )
+ SbxVariable* pVar = xItemArray->Get(i);
+ 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_ )
{
- sal_uInt32 nCount = pPar_->Count32();
+ sal_uInt32 nCount = pPar_->Count();
if( nCount < 2 || nCount > 5 )
{
SetError( ERRCODE_BASIC_WRONG_ARGS );
return;
}
- SbxVariable* pItem = pPar_->Get32(1);
+ SbxVariable* pItem = pPar_->Get(1);
if( pItem )
{
sal_uInt32 nNextIndex;
if( nCount < 4 )
{
- nNextIndex = xItemArray->Count32();
+ nNextIndex = xItemArray->Count();
}
else
{
- SbxVariable* pBefore = pPar_->Get32(3);
+ SbxVariable* pBefore = pPar_->Get(3);
if( nCount == 5 )
{
if( !( pBefore->IsErr() || ( pBefore->GetType() == SbxEMPTY ) ) )
@@ -2099,7 +2123,7 @@ void BasicCollection::CollAdd( SbxArray* pPar_ )
SetError( ERRCODE_BASIC_BAD_ARGUMENT );
return;
}
- SbxVariable* pAfter = pPar_->Get32(4);
+ SbxVariable* pAfter = pPar_->Get(4);
sal_Int32 nAfterIndex = implGetIndex( pAfter );
if( nAfterIndex == -1 )
{
@@ -2123,7 +2147,7 @@ void BasicCollection::CollAdd( SbxArray* pPar_ )
auto pNewItem = tools::make_ref<SbxVariable>( *pItem );
if( nCount >= 3 )
{
- SbxVariable* pKey = pPar_->Get32(2);
+ SbxVariable* pKey = pPar_->Get(2);
if( !( pKey->IsErr() || ( pKey->GetType() == SbxEMPTY ) ) )
{
if( pKey->GetType() != SbxSTRING )
@@ -2141,7 +2165,7 @@ void BasicCollection::CollAdd( SbxArray* pPar_ )
}
}
pNewItem->SetFlag( SbxFlagBits::ReadWrite );
- xItemArray->Insert32( pNewItem.get(), nNextIndex );
+ xItemArray->Insert(pNewItem.get(), nNextIndex);
}
else
{
@@ -2152,17 +2176,17 @@ void BasicCollection::CollAdd( SbxArray* pPar_ )
void BasicCollection::CollItem( SbxArray* pPar_ )
{
- if( pPar_->Count32() != 2 )
+ if (pPar_->Count() != 2)
{
SetError( ERRCODE_BASIC_WRONG_ARGS );
return;
}
SbxVariable* pRes = nullptr;
- SbxVariable* p = pPar_->Get32( 1 );
+ SbxVariable* p = pPar_->Get(1);
sal_Int32 nIndex = implGetIndex( p );
- if( nIndex >= 0 && nIndex < static_cast<sal_Int32>(xItemArray->Count32()) )
+ if (nIndex >= 0 && o3tl::make_unsigned(nIndex) < xItemArray->Count())
{
- pRes = xItemArray->Get32( nIndex );
+ pRes = xItemArray->Get(nIndex);
}
if( !pRes )
{
@@ -2170,21 +2194,21 @@ void BasicCollection::CollItem( SbxArray* pPar_ )
}
else
{
- *(pPar_->Get32(0)) = *pRes;
+ *(pPar_->Get(0)) = *pRes;
}
}
void BasicCollection::CollRemove( SbxArray* pPar_ )
{
- if( pPar_ == nullptr || pPar_->Count32() != 2 )
+ if (pPar_ == nullptr || pPar_->Count() != 2)
{
SetError( ERRCODE_BASIC_WRONG_ARGS );
return;
}
- SbxVariable* p = pPar_->Get32( 1 );
+ SbxVariable* p = pPar_->Get(1);
sal_Int32 nIndex = implGetIndex( p );
- if( nIndex >= 0 && nIndex < static_cast<sal_Int32>(xItemArray->Count32()) )
+ if (nIndex >= 0 && o3tl::make_unsigned(nIndex) < xItemArray->Count())
{
xItemArray->Remove( nIndex );