summaryrefslogtreecommitdiff
path: root/basic
diff options
context:
space:
mode:
Diffstat (limited to 'basic')
-rw-r--r--basic/CppunitTest_basic_macros.mk16
-rw-r--r--basic/CppunitTest_basic_scanner.mk6
-rw-r--r--basic/Library_sb.mk18
-rw-r--r--basic/inc/basic.hrc4
-rw-r--r--basic/inc/pch/precompiled_sb.hxx53
-rw-r--r--basic/inc/sbxbase.hxx3
-rw-r--r--basic/inc/sbxfac.hxx1
-rw-r--r--basic/inc/sbxform.hxx32
-rw-r--r--basic/inc/strings.hrc2
-rw-r--r--basic/qa/basic_coverage/da-DK/test_ccur_da_DK_locale.bas27
-rw-r--r--basic/qa/basic_coverage/string_left_01.bas26
-rw-r--r--basic/qa/basic_coverage/string_right_01.bas26
-rw-r--r--basic/qa/basic_coverage/test_CallByName.bas43
-rw-r--r--basic/qa/basic_coverage/test_Collection_class.bas71
-rw-r--r--basic/qa/basic_coverage/test_ccur_method.bas69
-rw-r--r--basic/qa/basic_coverage/test_cdbl_method.bas42
-rw-r--r--basic/qa/basic_coverage/test_converttofromurl_methods.bas29
-rw-r--r--basic/qa/basic_coverage/test_cstr_method.bas1
-rw-r--r--basic/qa/basic_coverage/test_declare_from_dll.bas36
-rw-r--r--basic/qa/basic_coverage/test_ismissing_basic.bas7
-rw-r--r--basic/qa/basic_coverage/test_ismissing_cascade.bas7
-rw-r--r--basic/qa/basic_coverage/test_ismissing_compatible.bas7
-rw-r--r--basic/qa/basic_coverage/test_join_method.bas30
-rw-r--r--basic/qa/basic_coverage/test_left_method.bas28
-rw-r--r--basic/qa/basic_coverage/test_like.bas41
-rw-r--r--basic/qa/basic_coverage/test_mid_keyword_names.bas26
-rw-r--r--basic/qa/basic_coverage/test_non_ascii_names.bas37
-rw-r--r--basic/qa/basic_coverage/test_non_ascii_names_compatible.bas45
-rw-r--r--basic/qa/basic_coverage/test_option_base.bas7
-rw-r--r--basic/qa/basic_coverage/test_option_base_compatible.bas7
-rw-r--r--basic/qa/basic_coverage/test_optional_paramter_type.bas74
-rw-r--r--basic/qa/basic_coverage/test_optional_paramters_basic.bas22
-rw-r--r--basic/qa/basic_coverage/test_optional_paramters_compatible.bas22
-rw-r--r--basic/qa/basic_coverage/test_right_method.bas28
-rw-r--r--basic/qa/basic_coverage/test_split_method.bas6
-rw-r--r--basic/qa/basic_coverage/test_string_method.bas28
-rw-r--r--basic/qa/basic_coverage/test_string_overflow_safe.bas7
-rw-r--r--basic/qa/basic_coverage/test_string_replace.bas7
-rw-r--r--basic/qa/basic_coverage/test_tdf132388_ReplacePerformance.bas28
-rw-r--r--basic/qa/basic_coverage/test_tdf134692.bas7
-rw-r--r--basic/qa/basic_coverage/test_tdf147089_idiv.bas30
-rw-r--r--basic/qa/basic_coverage/test_tdf147529_optional_parameters_msgbox.bas36
-rw-r--r--basic/qa/basic_coverage/test_tdf149622.bas48
-rw-r--r--basic/qa/basic_coverage/test_tdf150137_parse_fail.bas37
-rw-r--r--basic/qa/basic_coverage/test_tdf98778.bas7
-rw-r--r--basic/qa/basic_coverage/test_transliteration.bas52
-rw-r--r--basic/qa/basic_coverage/test_typename_method.bas2
-rw-r--r--basic/qa/basic_coverage/test_unsigned_integers.bas46
-rw-r--r--basic/qa/basic_coverage/test_vartype_method.bas2
-rw-r--r--basic/qa/basic_coverage/zh-CN/test_ccur_zh_CN_locale.bas27
-rw-r--r--basic/qa/cppunit/_test_asserts.bas10
-rw-r--r--basic/qa/cppunit/_test_asserts.vb10
-rw-r--r--basic/qa/cppunit/basictest.cxx2
-rw-r--r--basic/qa/cppunit/basictest.hxx4
-rw-r--r--basic/qa/cppunit/data/tdf149714.pngbin0 -> 1652 bytes
-rw-r--r--basic/qa/cppunit/test_compiler_checks.cxx138
-rw-r--r--basic/qa/cppunit/test_global_array.cxx4
-rw-r--r--basic/qa/cppunit/test_global_as_new.cxx4
-rw-r--r--basic/qa/cppunit/test_scanner.cxx40
-rw-r--r--basic/qa/cppunit/test_tdf149714.cxx86
-rw-r--r--basic/qa/cppunit/test_vba.cxx22
-rw-r--r--basic/qa/vba_tests/Err.Raise.vb2
-rw-r--r--basic/qa/vba_tests/cdbl.vb5
-rw-r--r--basic/qa/vba_tests/chr.vb2
-rw-r--r--basic/qa/vba_tests/constants.vb9
-rw-r--r--basic/qa/vba_tests/cstr.vb1
-rw-r--r--basic/qa/vba_tests/format.vb5
-rw-r--r--basic/qa/vba_tests/formatpercent.vb31
-rw-r--r--basic/qa/vba_tests/instrrev.vb7
-rw-r--r--basic/qa/vba_tests/join.vb5
-rw-r--r--basic/qa/vba_tests/left.vb3
-rw-r--r--basic/qa/vba_tests/like.vb42
-rw-r--r--basic/qa/vba_tests/mid.vb4
-rw-r--r--basic/qa/vba_tests/ole_ObjAssignNoDflt.vb8
-rw-r--r--basic/qa/vba_tests/ole_ObjAssignToNothing.vb8
-rw-r--r--basic/qa/vba_tests/right.vb3
-rw-r--r--basic/qa/vba_tests/split.vb6
-rw-r--r--basic/qa/vba_tests/strconv.vb21
-rw-r--r--basic/qa/vba_tests/string.vb10
-rw-r--r--basic/qa/vba_tests/tdf147089_idiv.vb31
-rw-r--r--basic/qa/vba_tests/tdf147529_optional_parameters_msgbox.vb37
-rw-r--r--basic/qa/vba_tests/tdf148358_non_ascii_names.vb33
-rw-r--r--basic/qa/vba_tests/typename.vb2
-rw-r--r--basic/qa/vba_tests/vartype.vb2
-rw-r--r--basic/source/basmgr/basicmanagerrepository.cxx15
-rw-r--r--basic/source/basmgr/basmgr.cxx167
-rw-r--r--basic/source/classes/eventatt.cxx15
-rw-r--r--basic/source/classes/image.cxx57
-rw-r--r--basic/source/classes/propacc.cxx48
-rw-r--r--basic/source/classes/sb.cxx120
-rw-r--r--basic/source/classes/sbunoobj.cxx155
-rw-r--r--basic/source/classes/sbxmod.cxx143
-rw-r--r--basic/source/comp/buffer.cxx1
-rw-r--r--basic/source/comp/codegen.cxx15
-rw-r--r--basic/source/comp/exprnode.cxx13
-rw-r--r--basic/source/comp/exprtree.cxx2
-rw-r--r--basic/source/comp/loops.cxx5
-rw-r--r--basic/source/comp/parser.cxx15
-rw-r--r--basic/source/comp/scanner.cxx56
-rw-r--r--basic/source/comp/symtbl.cxx5
-rw-r--r--basic/source/comp/token.cxx7
-rw-r--r--basic/source/inc/buffer.hxx2
-rw-r--r--basic/source/inc/dlgcont.hxx12
-rw-r--r--basic/source/inc/expr.hxx40
-rw-r--r--basic/source/inc/filefmt.hxx5
-rw-r--r--basic/source/inc/image.hxx8
-rw-r--r--basic/source/inc/namecont.hxx62
-rw-r--r--basic/source/inc/propacc.hxx3
-rw-r--r--basic/source/inc/rtlproto.hxx3
-rw-r--r--basic/source/inc/runtime.hxx43
-rw-r--r--basic/source/inc/sbintern.hxx16
-rw-r--r--basic/source/inc/sbjsmod.hxx2
-rw-r--r--basic/source/inc/sbunoobj.hxx26
-rw-r--r--basic/source/inc/scanner.hxx10
-rw-r--r--basic/source/inc/scriptcont.hxx16
-rw-r--r--basic/source/inc/stdobj.hxx5
-rw-r--r--basic/source/inc/symtbl.hxx2
-rw-r--r--basic/source/inc/token.hxx2
-rw-r--r--basic/source/runtime/basrdll.cxx9
-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.cxx2
-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/iosys.cxx6
-rw-r--r--basic/source/runtime/methods.cxx1687
-rw-r--r--basic/source/runtime/methods1.cxx608
-rw-r--r--basic/source/runtime/props.cxx2
-rw-r--r--basic/source/runtime/runtime.cxx274
-rw-r--r--basic/source/runtime/stdobj.cxx66
-rw-r--r--basic/source/runtime/stdobj1.cxx40
-rw-r--r--basic/source/sbx/sbxarray.cxx27
-rw-r--r--basic/source/sbx/sbxbase.cxx32
-rw-r--r--basic/source/sbx/sbxbool.cxx2
-rw-r--r--basic/source/sbx/sbxbyte.cxx2
-rw-r--r--basic/source/sbx/sbxchar.cxx2
-rw-r--r--basic/source/sbx/sbxcoll.cxx11
-rw-r--r--basic/source/sbx/sbxcurr.cxx102
-rw-r--r--basic/source/sbx/sbxdate.cxx8
-rw-r--r--basic/source/sbx/sbxdbl.cxx6
-rw-r--r--basic/source/sbx/sbxdec.cxx13
-rw-r--r--basic/source/sbx/sbxdec.hxx2
-rw-r--r--basic/source/sbx/sbxexec.cxx62
-rw-r--r--basic/source/sbx/sbxform.cxx164
-rw-r--r--basic/source/sbx/sbxint.cxx8
-rw-r--r--basic/source/sbx/sbxlng.cxx2
-rw-r--r--basic/source/sbx/sbxobj.cxx100
-rw-r--r--basic/source/sbx/sbxscan.cxx28
-rw-r--r--basic/source/sbx/sbxsng.cxx6
-rw-r--r--basic/source/sbx/sbxstr.cxx2
-rw-r--r--basic/source/sbx/sbxuint.cxx2
-rw-r--r--basic/source/sbx/sbxulng.cxx2
-rw-r--r--basic/source/sbx/sbxvalue.cxx7
-rw-r--r--basic/source/sbx/sbxvar.cxx43
-rw-r--r--basic/source/uno/dlgcont.cxx54
-rw-r--r--basic/source/uno/modsizeexceeded.cxx15
-rw-r--r--basic/source/uno/namecont.cxx245
-rw-r--r--basic/source/uno/scriptcont.cxx43
160 files changed, 3976 insertions, 2748 deletions
diff --git a/basic/CppunitTest_basic_macros.mk b/basic/CppunitTest_basic_macros.mk
index 83a9221369f0..a67508f800a2 100644
--- a/basic/CppunitTest_basic_macros.mk
+++ b/basic/CppunitTest_basic_macros.mk
@@ -9,8 +9,6 @@
$(eval $(call gb_CppunitTest_CppunitTest,basic_macros))
-$(eval $(call gb_CppunitTest_use_external,basic_macros,boost_headers))
-
$(eval $(call gb_CppunitTest_add_exception_objects,basic_macros, \
basic/qa/cppunit/basictest \
basic/qa/cppunit/basic_coverage \
@@ -21,6 +19,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,basic_macros, \
basic/qa/cppunit/test_vba \
basic/qa/cppunit/test_global_as_new \
basic/qa/cppunit/test_global_array \
+ basic/qa/cppunit/test_tdf149714 \
))
$(eval $(call gb_CppunitTest_use_libraries,basic_macros, \
@@ -45,9 +44,7 @@ $(eval $(call gb_CppunitTest_use_libraries,basic_macros, \
ifeq ($(OS),WNT)
$(eval $(call gb_CppunitTest_use_system_win32_libs,basic_macros, \
oleaut32 \
- legacy_stdio_definitions \
odbc32 \
- odbccp32 \
))
endif
@@ -60,15 +57,8 @@ $(eval $(call gb_CppunitTest_use_api,basic_macros,\
$(eval $(call gb_CppunitTest_use_ure,basic_macros))
$(eval $(call gb_CppunitTest_use_vcl,basic_macros))
-$(eval $(call gb_CppunitTest_use_components,basic_macros,\
- configmgr/source/configmgr \
- i18npool/source/search/i18nsearch \
- i18npool/util/i18npool \
- ucb/source/core/ucb1 \
- ucb/source/ucp/file/ucpfile1 \
- $(if $(filter $(OS),WNT), \
- extensions/source/ole/oleautobridge) \
-))
+$(eval $(call gb_CppunitTest_use_rdb,basic_macros,services))
+
$(eval $(call gb_CppunitTest_use_configuration,basic_macros))
# vim: set noet sw=4 ts=4:
diff --git a/basic/CppunitTest_basic_scanner.mk b/basic/CppunitTest_basic_scanner.mk
index 55a6e0faf311..03701864f8f7 100644
--- a/basic/CppunitTest_basic_scanner.mk
+++ b/basic/CppunitTest_basic_scanner.mk
@@ -11,6 +11,12 @@ $(eval $(call gb_CppunitTest_CppunitTest,basic_scanner))
$(eval $(call gb_CppunitTest_use_ure,basic_scanner))
+$(eval $(call gb_CppunitTest_use_externals,basic_scanner,\
+ icu_headers \
+ icuuc \
+ icui18n \
+))
+
$(eval $(call gb_CppunitTest_add_exception_objects,basic_scanner, \
basic/qa/cppunit/test_scanner \
))
diff --git a/basic/Library_sb.mk b/basic/Library_sb.mk
index 17fbcbd1010e..dae083a34864 100644
--- a/basic/Library_sb.mk
+++ b/basic/Library_sb.mk
@@ -25,9 +25,13 @@ $(eval $(call gb_Library_set_include,sb,\
-I$(SRCDIR)/basic/source/inc \
))
-$(eval $(call gb_Library_set_precompiled_header,sb,basic/inc/pch/precompiled_sb))
+$(eval $(call gb_Library_use_externals,sb,\
+ icu_headers \
+ icuuc \
+ icui18n \
+))
-$(eval $(call gb_Library_use_external,sb,boost_headers))
+$(eval $(call gb_Library_set_precompiled_header,sb,basic/inc/pch/precompiled_sb))
$(eval $(call gb_Library_use_custom_headers,sb,\
officecfg/registry \
@@ -66,13 +70,11 @@ $(eval $(call gb_Library_add_exception_objects,sb,\
basic/source/basmgr/vbahelper \
basic/source/classes/codecompletecache \
basic/source/classes/eventatt \
- basic/source/classes/global \
basic/source/classes/image \
basic/source/classes/propacc \
basic/source/classes/sb \
basic/source/classes/sbunoobj \
basic/source/classes/sbxmod \
- basic/source/comp/basiccharclass \
basic/source/comp/buffer \
basic/source/comp/codegen \
basic/source/comp/dim \
@@ -97,16 +99,18 @@ $(eval $(call gb_Library_add_exception_objects,sb,\
basic/source/runtime/props \
basic/source/runtime/stdobj \
basic/source/runtime/stdobj1 \
- basic/source/runtime/runtime \
basic/source/classes/errobject \
))
endif
$(eval $(call gb_Library_add_exception_objects,sb,\
+ basic/source/classes/global \
+ basic/source/classes/sbintern \
+ basic/source/comp/basiccharclass \
basic/source/runtime/basrdll \
basic/source/runtime/methods \
basic/source/runtime/methods1 \
- basic/source/classes/sbintern \
+ basic/source/runtime/runtime \
basic/source/sbx/sbxarray \
basic/source/sbx/sbxbool \
basic/source/sbx/sbxbyte \
@@ -146,7 +150,7 @@ $(eval $(call gb_Library_add_asmobjects,sb,\
basic/source/runtime/wnt-x86 \
))
else
-ifeq ($(OS)$(CPUNAME),WNTX86_64)
+ifeq ($(OS)$(filter-out AARCH64 X86_64,$(CPUNAME)),WNT)
$(eval $(call gb_Library_add_exception_objects,sb,\
basic/source/runtime/dllmgr-x64 \
))
diff --git a/basic/inc/basic.hrc b/basic/inc/basic.hrc
index 79b940a38a1e..6245a5d76d30 100644
--- a/basic/inc/basic.hrc
+++ b/basic/inc/basic.hrc
@@ -21,11 +21,11 @@
#include <basic/sberrors.hxx>
#include <unotools/resmgr.hxx>
-#include <vcl/errcode.hxx>
+#include <comphelper/errcode.hxx>
#include <utility>
-#define NC_(Context, String) TranslateId(Context, reinterpret_cast<char const *>(u8##String))
+#define NC_(Context, String) TranslateId(Context, u8##String)
std::pair<TranslateId, ErrCode> const RID_BASIC_START[] =
{
diff --git a/basic/inc/pch/precompiled_sb.hxx b/basic/inc/pch/precompiled_sb.hxx
index d327c88c5f58..47e336d1cce0 100644
--- a/basic/inc/pch/precompiled_sb.hxx
+++ b/basic/inc/pch/precompiled_sb.hxx
@@ -13,7 +13,7 @@
manual changes will be rewritten by the next run of update_pch.sh (which presumably
also fixes all possible problems, so it's usually better to use it).
- Generated on 2021-09-12 11:49:52 using:
+ Generated on 2022-06-27 18:57:27 using:
./bin/update_pch basic sb --cutoff=2 --exclude:system --exclude:module --include:local
If after updating build fails, use the following command to locate conflicting headers:
@@ -24,6 +24,7 @@
#if PCH_LEVEL >= 1
#include <chrono>
#include <cstddef>
+#include <limits>
#include <math.h>
#include <memory>
#include <ostream>
@@ -31,13 +32,13 @@
#include <stdlib.h>
#include <string_view>
#include <type_traits>
+#include <utility>
#include <vector>
#endif // PCH_LEVEL >= 1
#if PCH_LEVEL >= 2
#include <osl/endian.h>
#include <osl/file.hxx>
#include <osl/process.h>
-#include <osl/thread.h>
#include <osl/time.h>
#include <rtl/character.hxx>
#include <rtl/math.h>
@@ -50,75 +51,45 @@
#include <sal/log.hxx>
#include <sal/saldllapi.h>
#include <sal/types.h>
-#include <vcl/bitmap.hxx>
-#include <vcl/cairo.hxx>
-#include <vcl/devicecoordinate.hxx>
#include <vcl/dllapi.h>
-#include <vcl/errcode.hxx>
-#include <vcl/font.hxx>
+#include <comphelper/errcode.hxx>
#include <vcl/graph.hxx>
#include <vcl/mapmod.hxx>
-#include <vcl/metaactiontypes.hxx>
-#include <vcl/outdev.hxx>
-#include <vcl/region.hxx>
-#include <vcl/rendercontext/AddFontSubstituteFlags.hxx>
-#include <vcl/rendercontext/AntialiasingFlags.hxx>
-#include <vcl/rendercontext/DrawGridFlags.hxx>
-#include <vcl/rendercontext/DrawImageFlags.hxx>
-#include <vcl/rendercontext/DrawModeFlags.hxx>
-#include <vcl/rendercontext/DrawTextFlags.hxx>
-#include <vcl/rendercontext/GetDefaultFontFlags.hxx>
-#include <vcl/rendercontext/ImplMapRes.hxx>
-#include <vcl/rendercontext/InvertFlags.hxx>
-#include <vcl/rendercontext/RasterOp.hxx>
-#include <vcl/rendercontext/SalLayoutFlags.hxx>
-#include <vcl/rendercontext/State.hxx>
-#include <vcl/rendercontext/SystemTextColorFlags.hxx>
-#include <vcl/salnativewidgets.hxx>
#include <vcl/settings.hxx>
#include <vcl/svapp.hxx>
-#include <vcl/vclreferencebase.hxx>
-#include <vcl/wall.hxx>
#include <vcl/weld.hxx>
+#include <vcl/wintypes.hxx>
#endif // PCH_LEVEL >= 2
#if PCH_LEVEL >= 3
#include <basegfx/color/bcolor.hxx>
-#include <basegfx/numeric/ftools.hxx>
-#include <basegfx/polygon/b2dpolypolygon.hxx>
-#include <basegfx/vector/b2enums.hxx>
-#include <com/sun/star/awt/DeviceInfo.hpp>
-#include <com/sun/star/drawing/LineCap.hpp>
+#include <com/sun/star/i18n/TransliterationModules.hpp>
+#include <com/sun/star/i18n/TransliterationModulesExtra.hpp>
#include <com/sun/star/lang/Locale.hpp>
#include <com/sun/star/uno/Any.hxx>
#include <com/sun/star/uno/Reference.h>
-#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/uno/Sequence.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/string.hxx>
-#include <cppuhelper/weakref.hxx>
#include <i18nlangtag/lang.h>
-#include <o3tl/char16_t2wchar_t.hxx>
+#include <i18nutil/transliteration.hxx>
#include <o3tl/cow_wrapper.hxx>
-#include <o3tl/float_int_conversion.hxx>
#include <o3tl/safeint.hxx>
+#include <o3tl/string_view.hxx>
+#include <o3tl/typed_flags_set.hxx>
#include <svl/SfxBroadcaster.hxx>
#include <svl/numformat.hxx>
#include <svl/zforlist.hxx>
#include <tools/color.hxx>
#include <tools/debug.hxx>
-#include <tools/gen.hxx>
#include <tools/link.hxx>
#include <tools/mapunit.hxx>
-#include <tools/poly.hxx>
#include <tools/ref.hxx>
-#include <tools/solar.h>
#include <tools/stream.hxx>
#include <tools/toolsdllapi.h>
#include <tools/urlobj.hxx>
-#include <tools/wintypes.hxx>
#include <unotools/charclass.hxx>
-#include <unotools/fontdefs.hxx>
#include <unotools/syslocale.hxx>
+#include <unotools/transliterationwrapper.hxx>
#include <unotools/unotoolsdllapi.h>
#endif // PCH_LEVEL >= 3
#if PCH_LEVEL >= 4
@@ -129,10 +100,12 @@
#include <basic/sbstar.hxx>
#include <basic/sbuno.hxx>
#include <basic/sbx.hxx>
+#include <basic/sbxcore.hxx>
#include <basic/sbxmeth.hxx>
#include <basic/sbxobj.hxx>
#include <basic/sbxvar.hxx>
#include <date.hxx>
+#include <global.hxx>
#include <iosys.hxx>
#include <rtlproto.hxx>
#include <runtime.hxx>
diff --git a/basic/inc/sbxbase.hxx b/basic/inc/sbxbase.hxx
index 80552c2fbf08..15a16a4ac113 100644
--- a/basic/inc/sbxbase.hxx
+++ b/basic/inc/sbxbase.hxx
@@ -23,7 +23,7 @@
#include <basic/sbxvar.hxx>
#include <i18nlangtag/lang.h>
-#include <vcl/errcode.hxx>
+#include <comphelper/errcode.hxx>
#include <memory>
#include <vector>
@@ -36,6 +36,7 @@ class SbxBasicFormater;
struct SbxAppData
{
ErrCode eErrCode; // Error code
+ OUString aErrorMsg; // Error message for $ARG
SbxVariableRef m_aGlobErr; // Global error object
std::vector<SbxFactory*> m_Factories; // these are owned by fields in SbiGlobals
tools::SvRef<SvRefBase> mrImplRepository;
diff --git a/basic/inc/sbxfac.hxx b/basic/inc/sbxfac.hxx
index bbdbcb018f0b..5493a6687e00 100644
--- a/basic/inc/sbxfac.hxx
+++ b/basic/inc/sbxfac.hxx
@@ -26,7 +26,6 @@ class SbxFactory
{
public:
virtual ~SbxFactory();
- SbxFactory() {}
virtual SbxBaseRef Create(sal_uInt16 nSbxId, sal_uInt32);
virtual SbxObjectRef CreateObject(const OUString&);
};
diff --git a/basic/inc/sbxform.hxx b/basic/inc/sbxform.hxx
index 8173c8ed87b7..49ef777866c0 100644
--- a/basic/inc/sbxform.hxx
+++ b/basic/inc/sbxform.hxx
@@ -74,14 +74,14 @@ class SbxBasicFormater {
// Constructor takes signs for decimal point, thousand separation sign
// and necessary resource strings.
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 );
/* Basic command: Format$( number,format-string )
@@ -93,9 +93,9 @@ class SbxBasicFormater {
String containing the formatted output
*/
OUString BasicFormat( double dNumber, const OUString& sFormatStrg );
- static OUString BasicFormatNull( const OUString& sFormatStrg );
+ static OUString BasicFormatNull( std::u16string_view sFormatStrg );
- static bool isBasicFormat( const OUString& sFormatStrg );
+ static bool isBasicFormat( std::u16string_view sFormatStrg );
private:
static inline void ShiftString( OUStringBuffer& sStrg, sal_uInt16 nStartPos );
@@ -112,11 +112,11 @@ class SbxBasicFormater {
short GetDigitAtPosExpScan( double dNewExponent, short nPos,
bool& bFoundFirstDigit );
short GetDigitAtPosExpScan( short nPos, bool& bFoundFirstDigit );
- static OUString GetPosFormatString( const OUString& sFormatStrg, bool & bFound );
- static OUString GetNegFormatString( const OUString& sFormatStrg, bool & bFound );
- static OUString Get0FormatString( const OUString& sFormatStrg, bool & bFound );
- static OUString GetNullFormatString( const OUString& sFormatStrg, bool & bFound );
- static void AnalyseFormatString( const OUString& sFormatStrg,
+ static OUString GetPosFormatString( std::u16string_view sFormatStrg, bool & bFound );
+ static OUString GetNegFormatString( std::u16string_view sFormatStrg, bool & bFound );
+ static OUString Get0FormatString( std::u16string_view sFormatStrg, bool & bFound );
+ static OUString GetNullFormatString( std::u16string_view sFormatStrg, bool & bFound );
+ static void AnalyseFormatString( std::u16string_view sFormatStrg,
short& nNoOfDigitsLeft, short& nNoOfDigitsRight,
short& nNoOfOptionalDigitsLeft,
short& nNoOfExponentDigits,
@@ -124,7 +124,7 @@ class SbxBasicFormater {
bool& bPercent, bool& bCurrency, bool& bScientific,
bool& bGenerateThousandSeparator,
short& nMultipleThousandSeparators );
- void ScanFormatString( double dNumber, const OUString& sFormatStrg,
+ void ScanFormatString( double dNumber, std::u16string_view sFormatStrg,
OUString& sReturnStrg, bool bCreateSign );
//*** Data ***
diff --git a/basic/inc/strings.hrc b/basic/inc/strings.hrc
index 64b65db342cc..53a8da5c40fd 100644
--- a/basic/inc/strings.hrc
+++ b/basic/inc/strings.hrc
@@ -19,7 +19,7 @@
#pragma once
-#define NC_(Context, String) TranslateId(Context, reinterpret_cast<char const *>(u8##String))
+#define NC_(Context, String) TranslateId(Context, u8##String)
#define STR_BASICKEY_FORMAT_ON NC_("STR_BASICKEY_FORMAT_ON", "On")
#define STR_BASICKEY_FORMAT_OFF NC_("STR_BASICKEY_FORMAT_OFF", "Off")
diff --git a/basic/qa/basic_coverage/da-DK/test_ccur_da_DK_locale.bas b/basic/qa/basic_coverage/da-DK/test_ccur_da_DK_locale.bas
new file mode 100644
index 000000000000..52b8d3b6f1aa
--- /dev/null
+++ b/basic/qa/basic_coverage/da-DK/test_ccur_da_DK_locale.bas
@@ -0,0 +1,27 @@
+'
+' 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/.
+'
+
+Option Explicit
+
+Function doUnitTest as String
+ TestUtil.TestInit
+ verify_testCCurDaDKLocale
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Sub verify_testCCurDaDKLocale
+ On Error GoTo errorHandler
+
+ ' tdf#141050 - characteristic test for CCur() with the da_DK locale
+ TestUtil.AssertEqual(CCur("75,50"), 75.5, "CCur(75,50)")
+ TestUtil.AssertEqual(CCur("75,50 kr."), 75.5, "CCur(75,50 kr.)")
+
+ Exit Sub
+errorHandler:
+ TestUtil.ReportErrorHandler("verify_testCCurDaDKLocale", Err, Error$, Erl)
+End Sub
diff --git a/basic/qa/basic_coverage/string_left_01.bas b/basic/qa/basic_coverage/string_left_01.bas
deleted file mode 100644
index d2ae7ae45ff8..000000000000
--- a/basic/qa/basic_coverage/string_left_01.bas
+++ /dev/null
@@ -1,26 +0,0 @@
-'
-' 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/.
-'
-
-Option Explicit
-
-Function doUnitTest as String
-
-Dim s1 As String
-Dim s2 As String
-
- s1 = "abc"
-
- s2 = Left(s1, 2)
-
- If s2 = "ab" Then
- doUnitTest = "OK"
- Else
- doUnitTest = "FAIL"
- End If
-
-End Function
diff --git a/basic/qa/basic_coverage/string_right_01.bas b/basic/qa/basic_coverage/string_right_01.bas
deleted file mode 100644
index a291d0704bf3..000000000000
--- a/basic/qa/basic_coverage/string_right_01.bas
+++ /dev/null
@@ -1,26 +0,0 @@
-'
-' 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/.
-'
-
-Option Explicit
-
-Function doUnitTest as String
-
-Dim s1 As String
-Dim s2 As String
-
- s1 = "abc"
-
- s2 = Right(s1, 2)
-
- If s2 = "bc" Then
- doUnitTest = "OK"
- Else
- doUnitTest = "FAIL"
- End If
-
-End Function
diff --git a/basic/qa/basic_coverage/test_CallByName.bas b/basic/qa/basic_coverage/test_CallByName.bas
new file mode 100644
index 000000000000..3eca805fb1a9
--- /dev/null
+++ b/basic/qa/basic_coverage/test_CallByName.bas
@@ -0,0 +1,43 @@
+' 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/.
+'
+
+Option Explicit
+
+Function doUnitTest() As String
+ TestUtil.TestInit
+ verify_CallByName
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Sub verify_CallByName()
+ Const _Get = 2, _Let = 4, _Method = 1, _Set = 8
+
+ On Error GoTo errorHandler
+
+ ' Basic modules are Objects
+ TestUtil.AssertEqual(CallByName(TestUtil, "failCount", _Get), 0, "CallByName(TestUtil, ""failCount"", _Get")
+ TestUtil.AssertEqual(CallByName(TestUtil, "passCount", _Get), 1, "CallByName(TestUtil, ""passCount"", _Get")
+ TestUtil.AssertEqual(CallByName(TestUtil, "GetResult", _Method), "OK", "CallByName(TestUtil, ""GetResult"", _Method")
+
+ ' Collection instances
+ Dim c As New Collection
+ c.Add(100, "1st") : c.Add(101)
+ TestUtil.AssertEqual(CallByName(c,"Count", _Get), 2, "CallByName(c,""Count"", _Get)")
+ c.Remove(2)
+ TestUtil.AssertEqual(CallByName(callType:=_Get, object:=c, procName:="Count"), 1, _
+ "CallByName(callType:=_Get, object:=c, procName:=""Count"")")
+
+ ' ClassModule instances or UNO services are 'CallByNamable' objects too!
+ ' see https://help.libreoffice.org/7.4/en-US/text/sbasic/shared/CallByName.html?DbPAR=BASIC#bm_id3150669
+ ' for more _Let and _Set examples
+
+ Exit Sub
+errorHandler:
+ TestUtil.ReportErrorHandler("verify_CallByName", Err, Error$, Erl)
+ Resume Next
+
+End Sub \ No newline at end of file
diff --git a/basic/qa/basic_coverage/test_Collection_class.bas b/basic/qa/basic_coverage/test_Collection_class.bas
new file mode 100644
index 000000000000..06ed6b66588d
--- /dev/null
+++ b/basic/qa/basic_coverage/test_Collection_class.bas
@@ -0,0 +1,71 @@
+'
+' 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/.
+'
+
+Option Explicit
+
+Function doUnitTest() As String
+ TestUtil.TestInit
+ Call verify_Collection
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Sub verify_Collection()
+try: On Error GoTo catch
+
+ Dim c As New Collection, planet as String, ndx As Integer
+
+ TestUtil.assertEqual(c.Count, 0,"c.Count")
+
+ ' Let's collect Solar system planets from closest to SUN,
+ ' ranking them alphabetically using before/after keywords,
+ ' in order to validate various Add() method syntax variations.
+ c.Add("Mercury")
+ c.Add("Venus", "♀")
+ c.Add("Earth", "♁", before:=1)
+ TestUtil.assertEqual(c.Count, 3,"c.Count")
+ TestUtil.assertEqual(c.Item(1), "Earth","c.Item(1)")
+ TestUtil.assertEqual(c.Item("♁"), "Earth","c.Item(""♁"")")
+ TestUtil.assertEqual(c.Item(3), "Venus","c.Item(3)")
+ TestUtil.assertEqual(c.Item("♀"), "Venus","c.Item(""♀"")")
+
+ c.Add("Mars", "♂", after:="♁")
+ c.Add("Jupiter", after:="♁")
+ c.Add("Saturn", before:=5)
+ TestUtil.assertEqual(c.Count, 6,"c.Count")
+ TestUtil.assertEqual(c.Item(2), "Jupiter","c.Item(2)")
+ TestUtil.assertEqual(c.Item(3), "Mars","c.Item(3)")
+ TestUtil.assertEqual(c.Item("♂"), "Mars","c.Item(""♂"")")
+ TestUtil.assertEqual(c.Item(5), "Saturn","c.Item(5)")
+ TestUtil.assertEqual(c.Item(6), "Venus","c.Item(6)")
+
+ c.Add("Uranus", before:="♀")
+ c.Add("Neptune", "♆", after:=4)
+ TestUtil.assertEqual(c.Count, 8,"c.Count")
+ TestUtil.assertEqual(c.Item(7), "Uranus","c.Item(7)")
+ TestUtil.assertEqual(c.Item(5), "Neptune","c.Item(5)")
+ TestUtil.assertEqual(c.Item("♆"), "Neptune","c.Item(""♆"")")
+ TestUtil.assertEqual(c.Item(6), "Saturn","c.Item(6)")
+
+ c.remove(4)
+ c.remove("♁")
+
+ TestUtil.assertEqual(c.Count, 6,"c.Count")
+
+ For ndx = c.Count to 1 Step -1
+ c.Remove(ndx)
+ Next ndx
+
+ TestUtil.assertEqual(c.Count, 0,"c.Count")
+
+finally:
+ Exit Sub
+
+catch:
+ TestUtil.ReportErrorHandler("verify_Collection", Err, Error$, Erl)
+ Resume Next
+End Sub
diff --git a/basic/qa/basic_coverage/test_ccur_method.bas b/basic/qa/basic_coverage/test_ccur_method.bas
index cd700cad3c8e..c42dcb938590 100644
--- a/basic/qa/basic_coverage/test_ccur_method.bas
+++ b/basic/qa/basic_coverage/test_ccur_method.bas
@@ -9,16 +9,73 @@
Option Explicit
Function doUnitTest as String
+ TestUtil.TestInit
+ verify_testCCur
+ doUnitTest = TestUtil.GetResult()
+End Function
- doUnitTest = "FAIL"
+Sub verify_testCCur
+ On Error GoTo errorHandler
' CCUR
- if (CCur("100") <> 100) Then Exit Function
+ TestUtil.AssertEqual(CCur("100"), 100, "CCur(100)")
+
' tdf#141050 - passing a number with + sign
- if (CCur("+100") <> 100) Then Exit Function
+ TestUtil.AssertEqual(CCur("+100"), 100, "CCur(100)")
' tdf#141050 - passing a number with - sign
- if (CCur("-100") <> -100) Then Exit Function
+ TestUtil.AssertEqual(CCur("-100"), -100, "CCur(-100)")
- doUnitTest = "OK"
+ ' tdf#128122 - verify en_US locale currency format behavior
+ TestUtil.AssertEqual(CCur("$100"), 100, "CCur($100)")
+ TestUtil.AssertEqual(CCur("$1.50"), 1.5, "CCur($1.50)")
-End Function
+ verify_testCCurUnderflow
+ verify_testCCurOverflow
+ verify_testCCurInvalidFormat
+
+ Exit Sub
+errorHandler:
+ TestUtil.ReportErrorHandler("verify_testCCur", Err, Error$, Erl)
+End Sub
+
+sub verify_testCCurUnderflow
+ On Error GoTo underflowHandler
+
+ ' tdf$128122 - test underflow condition
+ CCur("-9223372036854775809")
+ TestUtil.Assert(False, "verify_testCCur", "underflow error not raised")
+
+ Exit Sub
+underflowHandler:
+ If(Err <> 6) Then
+ TestUtil.Assert(False, "verify_testCCur", "underflow error incorrect type")
+ Endif
+End Sub
+
+sub verify_testCCurOverflow
+ On Error GoTo overflowHandler
+
+ ' tdf$128122 - test overflow condition
+ CCur("9223372036854775808")
+ TestUtil.Assert(False, "verify_testCCur", "overflow error not raised")
+
+ Exit Sub
+overflowHandler:
+ If(Err <> 6) Then
+ TestUtil.Assert(False, "verify_testCCur", "overflow error incorrect type")
+ Endif
+End Sub
+
+sub verify_testCCurInvalidFormat
+ On Error GoTo invalidFormatHandler
+
+ ' tdf$128122 - test invalid format in en_US locale
+ CCur("75,50 kr")
+ TestUtil.Assert(False, "verify_testCCur", "invalid format error not raised")
+
+ Exit Sub
+invalidFormatHandler:
+ If(Err <> 13) Then
+ TestUtil.Assert(False, "verify_testCCur", "invalid format error incorrect type")
+ Endif
+End Sub
diff --git a/basic/qa/basic_coverage/test_cdbl_method.bas b/basic/qa/basic_coverage/test_cdbl_method.bas
index 1c7837fcaa4b..e44c23456ff1 100644
--- a/basic/qa/basic_coverage/test_cdbl_method.bas
+++ b/basic/qa/basic_coverage/test_cdbl_method.bas
@@ -1,18 +1,30 @@
-'
-' 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 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/.
+'
+
+Option Explicit
-Option Explicit
+Function doUnitTest() As String
+ TestUtil.TestInit
+ verify_testCdbl
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Sub verify_testCdbl
+ On Error GoTo errorHandler
-Function doUnitTest as String
' CDBL
- If (CDbl("100") <> 100) Then
- doUnitTest = "FAIL"
- Else
- doUnitTest = "OK"
- End If
-End Function
+ TestUtil.AssertEqual(CDbl("100"), 100, "CDbl(""100"")")
+
+ ' tdf#146672 - skip spaces and tabs at the end of the scanned string
+ TestUtil.AssertEqual(CDbl("28.8 "), 28.8, "CDbl(""28.8 "")")
+ TestUtil.AssertEqual(CDbl("28.8 "), 28.8, "CDbl(""28.8 "")")
+
+ Exit Sub
+errorHandler:
+ TestUtil.ReportErrorHandler("verify_testCdbl", Err, Error$, Erl)
+End Sub
diff --git a/basic/qa/basic_coverage/test_converttofromurl_methods.bas b/basic/qa/basic_coverage/test_converttofromurl_methods.bas
index d1dbcfc5ff73..c17d17e631e3 100644
--- a/basic/qa/basic_coverage/test_converttofromurl_methods.bas
+++ b/basic/qa/basic_coverage/test_converttofromurl_methods.bas
@@ -7,11 +7,28 @@
Option Explicit
-Function doUnitTest as String
- ' ConvertFromUrl ConvertToUrl
- If ( ConvertToUrl( ConvertFromUrl("") ) <> "") Then
- doUnitTest = "FAIL"
+Function doUnitTest() As String
+ TestUtil.TestInit
+ verify_testConvertToFromUrl
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Sub verify_testConvertToFromUrl
+ On Error GoTo errorHandler
+
+ TestUtil.AssertEqual( ConvertToUrl( ConvertFromUrl("") ), "", "ConvertToUrl( ConvertFromUrl("") )")
+
+ ' tdf#152917: Without the fix in place, this test would have failed with
+ ' Failed: ConvertFromUrl("file:///foo/bar/test.txt") returned , expected /foo/bar/test.txt
+ If (GetGUIType() <> 1) Then
+ 'Linux
+ TestUtil.AssertEqual( ConvertFromUrl("file:///foo/bar/test.txt"), "/foo/bar/test.txt", "ConvertFromUrl(""file:///foo/bar/test.txt"")")
Else
- doUnitTest = "OK"
+ 'Windows
+ TestUtil.AssertEqual( ConvertFromUrl("file://foo/bar/test.txt"), "\\foo\bar\test.txt", "ConvertFromUrl(""file://foo/bar/test.txt"")")
End If
-End Function
+
+ Exit Sub
+errorHandler:
+ TestUtil.ReportErrorHandler("verify_testConvertToFromUrl", Err, Error$, Erl)
+End Sub
diff --git a/basic/qa/basic_coverage/test_cstr_method.bas b/basic/qa/basic_coverage/test_cstr_method.bas
index 48b27640c275..c2ac003e8c8c 100644
--- a/basic/qa/basic_coverage/test_cstr_method.bas
+++ b/basic/qa/basic_coverage/test_cstr_method.bas
@@ -21,6 +21,7 @@ Sub verify_testCStr
TestUtil.AssertEqual(CStr(100), "100", "CStr(100)")
' tdf#143575 - round string to their nearest double representation
+ ' N.B.: check also how current conversion rounds a close number
' Without the fix in place, this test would have failed with:
' - Expected: 691.2
' - Actual : 691.2000000000001
diff --git a/basic/qa/basic_coverage/test_declare_from_dll.bas b/basic/qa/basic_coverage/test_declare_from_dll.bas
new file mode 100644
index 000000000000..7bdd1b170492
--- /dev/null
+++ b/basic/qa/basic_coverage/test_declare_from_dll.bas
@@ -0,0 +1,36 @@
+'
+' 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/.
+'
+
+Option Explicit
+
+' We link to shlwapi in many places, so safe to rely on it here
+Declare Function PathFindExtensionA Lib "Shlwapi" (ByVal pszPath As String) As String
+
+Function doUnitTest() As String
+ TestUtil.TestInit
+ verify_testPathFindExtensionA
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Sub verify_testPathFindExtensionA()
+ On Error GoTo errorHandler
+
+ ' Only test on Windows
+ If (GetGUIType() <> 1) Then
+ TestUtil.Assert(True) ' The test passed
+ Exit Sub
+ End If
+
+ ' Without the fix for tdf#147364 in place, the next call would crash in 64-bit version with
+ ' *** Exception 0xc0000005 occurred ***
+ TestUtil.AssertEqual(PathFindExtensionA("filename.ext"), ".ext", "PathFindExtensionA(""filename.ext"")")
+
+ Exit Sub
+errorHandler:
+ TestUtil.ReportErrorHandler("verify_testPathFindExtensionA", Err, Error$, Erl)
+End Sub
diff --git a/basic/qa/basic_coverage/test_ismissing_basic.bas b/basic/qa/basic_coverage/test_ismissing_basic.bas
index ed43a3ad19ee..0996da0f82a4 100644
--- a/basic/qa/basic_coverage/test_ismissing_basic.bas
+++ b/basic/qa/basic_coverage/test_ismissing_basic.bas
@@ -1,3 +1,10 @@
+' 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/.
+'
+
Const IsMissingNone = -1
Const IsMissingA = 0
Const IsMissingB = 1
diff --git a/basic/qa/basic_coverage/test_ismissing_cascade.bas b/basic/qa/basic_coverage/test_ismissing_cascade.bas
index f2f3a8b20564..3c6d9a71c09a 100644
--- a/basic/qa/basic_coverage/test_ismissing_cascade.bas
+++ b/basic/qa/basic_coverage/test_ismissing_cascade.bas
@@ -1,3 +1,10 @@
+' 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/.
+'
+
Option Explicit
Function doUnitTest() As String
diff --git a/basic/qa/basic_coverage/test_ismissing_compatible.bas b/basic/qa/basic_coverage/test_ismissing_compatible.bas
index fb7e6981d74c..6d11ab0902be 100644
--- a/basic/qa/basic_coverage/test_ismissing_compatible.bas
+++ b/basic/qa/basic_coverage/test_ismissing_compatible.bas
@@ -1,3 +1,10 @@
+' 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/.
+'
+
Option Compatible
Option Explicit
Const IsMissingNone = -1
diff --git a/basic/qa/basic_coverage/test_join_method.bas b/basic/qa/basic_coverage/test_join_method.bas
index 9076a0f8d83e..a3769ae188ff 100644
--- a/basic/qa/basic_coverage/test_join_method.bas
+++ b/basic/qa/basic_coverage/test_join_method.bas
@@ -7,14 +7,28 @@
Option Explicit
-Function doUnitTest as String
- ' Join
+Function doUnitTest() As String
+ TestUtil.TestInit
+ verify_Join_method
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Sub verify_Join_method
+ On Error GoTo errorHandler
+
+ ' JOIN
Dim aStrings(2) as String
aStrings(0) = "Hello"
aStrings(1) = "world"
- If ( Join( aStrings, " " ) <> "Hello world " ) Then
- doUnitTest = "FAIL"
- Else
- doUnitTest = "OK"
- End If
-End Function
+ TestUtil.AssertEqual(Join( aStrings, " " ), "Hello world ", "Join(aStrings, "" "" is not ""Hello world """)
+
+ ' tdf#141474 keyword names need to match that of VBA
+ Dim aList(0 to 7) As String : aList = Array("(", "Star", "|", "Open", "|", "Libre", ")", "Office")
+ TestUtil.AssertEqual(Join(sourceArray:=aList), "( Star | Open | Libre ) Office", "Join() with 1 keyword name")
+ TestUtil.AssertEqual(Join(delimiter:="", sourceArray:=aList), "(Star|Open|Libre)Office", "Join() with 2 keyword names")
+
+ Exit Sub
+errorHandler:
+ TestUtil.ReportErrorHandler("verify_Join_method", Err, Error$, Erl)
+End Sub
+
diff --git a/basic/qa/basic_coverage/test_left_method.bas b/basic/qa/basic_coverage/test_left_method.bas
new file mode 100644
index 000000000000..1c33bc9a711c
--- /dev/null
+++ b/basic/qa/basic_coverage/test_left_method.bas
@@ -0,0 +1,28 @@
+' 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/.
+'
+
+Option Explicit
+
+Function doUnitTest() As String
+ TestUtil.TestInit
+ verify_Left_method
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Sub verify_Left_method
+ On Error GoTo errorHandler
+
+ ' LEFT
+ TestUtil.AssertEqual(Left("abc", 2), "ab", "Left(""abc"",2)")
+
+ ' tdf#141474 keyword names need to match that of VBA
+ TestUtil.AssertEqual(Left(Length:=4, String:="sometext"), "some", "Left(Length:=4, String:=""sometext"")")
+
+ Exit Sub
+errorHandler:
+ TestUtil.ReportErrorHandler("verify_Left_method", Err, Error$, Erl)
+End Sub
diff --git a/basic/qa/basic_coverage/test_like.bas b/basic/qa/basic_coverage/test_like.bas
new file mode 100644
index 000000000000..2d018bf64f01
--- /dev/null
+++ b/basic/qa/basic_coverage/test_like.bas
@@ -0,0 +1,41 @@
+'
+' 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/.
+'
+
+Option Explicit
+
+Function doUnitTest() As String
+ TestUtil.TestInit
+ verify_testLike
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Sub verify_testLike()
+ On Error GoTo errorHandler
+ ' Negation test
+ TestUtil.AssertEqual("!" Like "[.!?]", True, "Negation1")
+ TestUtil.AssertEqual("a" Like "[!abc]", False, "Negation2")
+ TestUtil.AssertEqual("!" Like "[!!?]", False, "Negation3")
+ TestUtil.AssertEqual("^" Like "[.!?]", False, "Negation4")
+ TestUtil.AssertEqual("^" Like "[.^?]", True, "Negation5")
+ ' Like test from microsoft vba
+ TestUtil.AssertEqual("aBBBa" Like "a*a", True, "Like1")
+ TestUtil.AssertEqual("F" Like "[A-Z]", True, "Like2")
+ TestUtil.AssertEqual("F" Like "[!A-Z]", False, "Like3")
+ TestUtil.AssertEqual("a2a" Like "a#a", True, "Like4")
+ TestUtil.AssertEqual("aM5b" Like "a[L-P]#[!c-e]", True, "Like5")
+ TestUtil.AssertEqual("BAT123khg" Like "B?T*", True, "Like6")
+ TestUtil.AssertEqual("CAT123khg" Like "B?T*", False, "Like7")
+ TestUtil.AssertEqual("ab" Like "a*b", True, "Like8")
+ TestUtil.AssertEqual("a*b" Like "a [*]b", False, "Like9")
+ TestUtil.AssertEqual("axxxxxb" Like "a [*]b", False, "Like10")
+ TestUtil.AssertEqual("a [xyz" Like "a [[]*", True, "Like11")
+
+ Exit Sub
+errorHandler:
+ TestUtil.ReportErrorHandler("verify_testLike", Err, Error$, Erl)
+End Sub
diff --git a/basic/qa/basic_coverage/test_mid_keyword_names.bas b/basic/qa/basic_coverage/test_mid_keyword_names.bas
new file mode 100644
index 000000000000..abe56043ad29
--- /dev/null
+++ b/basic/qa/basic_coverage/test_mid_keyword_names.bas
@@ -0,0 +1,26 @@
+' 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/.
+'
+
+Option Explicit
+
+Function doUnitTest() As String
+ TestUtil.TestInit
+ verify_Mid_method
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Sub verify_Mid_method
+ On Error GoTo errorHandler
+
+ ' tdf#141474 keyword names need to match that of VBA
+ TestUtil.AssertEqual(Mid(start:=6, string:="LibreOffice" ), "Office", "Mid() with 2 keyword names" )
+ TestUtil.AssertEqual(Mid(length:=5, start:=1, string:="LibreOffice" ), "Libre", "Mid() with 3 keyword names" )
+
+ Exit Sub
+errorHandler:
+ TestUtil.ReportErrorHandler("verify_Mid_method", Err, Error$, Erl)
+End Sub \ No newline at end of file
diff --git a/basic/qa/basic_coverage/test_non_ascii_names.bas b/basic/qa/basic_coverage/test_non_ascii_names.bas
new file mode 100644
index 000000000000..c85c9cae12cb
--- /dev/null
+++ b/basic/qa/basic_coverage/test_non_ascii_names.bas
@@ -0,0 +1,37 @@
+'
+' 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/.
+'
+
+Option Explicit
+
+Function doUnitTest as String
+ [Prüfung]
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Function [Функция]([😁])
+ [Функция] = [😁] & " and some text"
+End Function
+
+Function TestNonAsciiNative as Integer
+ Dim [Абв] as Integer
+ [Абв] = 5
+ TestNonAsciiNative = [абв]
+End Function
+
+Sub [Prüfung]
+ On Error GoTo errorHandler
+
+ TestUtil.AssertEqual([Функция]("Smiley"), "Smiley and some text", "[Функция](""Smiley"")")
+
+ ' tdf#148358 - compare Non-ASCII variable names case-insensitive
+ TestUtil.AssertEqual(TestNonAsciiNative(), 5, "TestNonAsciiNative()")
+
+ Exit Sub
+errorHandler:
+ TestUtil.ReportErrorHandler("Prüfung", Err, Error$, Erl)
+End Sub
diff --git a/basic/qa/basic_coverage/test_non_ascii_names_compatible.bas b/basic/qa/basic_coverage/test_non_ascii_names_compatible.bas
new file mode 100644
index 000000000000..1abc272443c5
--- /dev/null
+++ b/basic/qa/basic_coverage/test_non_ascii_names_compatible.bas
@@ -0,0 +1,45 @@
+'
+' 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/.
+'
+
+Option Compatible
+Option Explicit
+
+Function doUnitTest as String
+ [Prüfung]
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Function [Функция]([😁])
+ [Функция] = [😁] & " and some text"
+End Function
+
+Function TestNonAscii as Integer
+ Dim Абв as Integer
+ Абв = 10
+ TestNonAscii = абв
+End Function
+
+Function TestNonAsciiNative as Integer
+ Dim [Абв] as Integer
+ [Абв] = 5
+ TestNonAsciiNative = [абв]
+End Function
+
+Sub [Prüfung]
+ On Error GoTo errorHandler
+
+ TestUtil.AssertEqual([Функция]("Smiley"), "Smiley and some text", "[Функция](""Smiley"")")
+
+ ' tdf#148358 - compare Non-ASCII variable names case-insensitive
+ TestUtil.AssertEqual(TestNonAscii(), 10, "TestNonAscii()")
+ TestUtil.AssertEqual(TestNonAsciiNative(), 5, "TestNonAsciiNative()")
+
+ Exit Sub
+errorHandler:
+ TestUtil.ReportErrorHandler("Prüfung Compatible", Err, Error$, Erl)
+End Sub
diff --git a/basic/qa/basic_coverage/test_option_base.bas b/basic/qa/basic_coverage/test_option_base.bas
index 11afea50d75b..69282f80bec6 100644
--- a/basic/qa/basic_coverage/test_option_base.bas
+++ b/basic/qa/basic_coverage/test_option_base.bas
@@ -1,3 +1,10 @@
+' 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/.
+'
+
Option Base 1
Option Explicit
diff --git a/basic/qa/basic_coverage/test_option_base_compatible.bas b/basic/qa/basic_coverage/test_option_base_compatible.bas
index 8001106a7bfc..296b208f582b 100644
--- a/basic/qa/basic_coverage/test_option_base_compatible.bas
+++ b/basic/qa/basic_coverage/test_option_base_compatible.bas
@@ -1,3 +1,10 @@
+' 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/.
+'
+
Option Base 1
Option Compatible
Option Explicit
diff --git a/basic/qa/basic_coverage/test_optional_paramter_type.bas b/basic/qa/basic_coverage/test_optional_paramter_type.bas
index 2a616c24044d..a98e422cd004 100644
--- a/basic/qa/basic_coverage/test_optional_paramter_type.bas
+++ b/basic/qa/basic_coverage/test_optional_paramter_type.bas
@@ -1,34 +1,40 @@
-REM ***** BASIC *****
-Option Compatible
-Option Explicit
-
-Function doUnitTest() As String
- doUnitTest = "FAIL"
- If CheckType1(32) = 0 Then
- Exit Function
- End If
- If CheckType2(32) = 0 Then
- Exit Function
- End If
- If CheckType2() = 0 Then
- Exit Function
- End If
- doUnitTest = "OK"
-End Function
-
-Function CheckType1(x As Integer) As Integer
- If TypeName(x) = "Integer" Then
- CheckType1 = 1
- Else
- CheckType1 = 0
- End If
-End Function
-
-
-Function CheckType2(Optional y As Integer = 32 ) As Integer
- If TypeName(y) = "Integer" Then
- CheckType2 = 1
- Else
- CheckType2 = 0
- End If
-End Function \ No newline at end of file
+' 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/.
+'
+
+Option Compatible
+Option Explicit
+
+Function doUnitTest() As String
+ doUnitTest = "FAIL"
+ If CheckType1(32) = 0 Then
+ Exit Function
+ End If
+ If CheckType2(32) = 0 Then
+ Exit Function
+ End If
+ If CheckType2() = 0 Then
+ Exit Function
+ End If
+ doUnitTest = "OK"
+End Function
+
+Function CheckType1(x As Integer) As Integer
+ If TypeName(x) = "Integer" Then
+ CheckType1 = 1
+ Else
+ CheckType1 = 0
+ End If
+End Function
+
+
+Function CheckType2(Optional y As Integer = 32 ) As Integer
+ If TypeName(y) = "Integer" Then
+ CheckType2 = 1
+ Else
+ CheckType2 = 0
+ End If
+End Function
diff --git a/basic/qa/basic_coverage/test_optional_paramters_basic.bas b/basic/qa/basic_coverage/test_optional_paramters_basic.bas
index a684fc256054..82880e11bdde 100644
--- a/basic/qa/basic_coverage/test_optional_paramters_basic.bas
+++ b/basic/qa/basic_coverage/test_optional_paramters_basic.bas
@@ -1,3 +1,10 @@
+' 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/.
+'
+
Option Explicit
Type testObject
@@ -125,6 +132,12 @@ Sub verify_testOptionalsBasic()
' - Actual : 448 (Actual value of the variable)
TestUtil.AssertEqual(TestObjectError, 449, "TestObjectError")
+ ' tdf#151503 - error handling of missing optional parameters (boolean operations)
+ ' Without the fix in place, this test would have failed with:
+ ' - Expected: 449 (ERRCODE_BASIC_NOT_OPTIONAL - Argument not optional)
+ ' - Actual : 0 (No error code since a missing parameter evaluates to true)
+ TestUtil.AssertEqual(TestBooleanOperations, 449, "TestBooleanOperations")
+
Exit Sub
errorHandler:
TestUtil.ReportErrorHandler("verify_testOptionalsBasic", Err, Error$, Erl)
@@ -229,6 +242,15 @@ errorHandler:
TestObjectError = Err()
End Function
+Function TestBooleanOperations(Optional optBool As Boolean)
+On Error GoTo errorHandler
+ if optBool then
+ TestBooleanOperations = 0
+ end if
+errorHandler:
+ TestBooleanOperations = Err()
+End Function
+
Function CollectionSum(C)
Dim idx As Integer
CollectionSum = 0
diff --git a/basic/qa/basic_coverage/test_optional_paramters_compatible.bas b/basic/qa/basic_coverage/test_optional_paramters_compatible.bas
index 56b314288e7a..78d14eb152eb 100644
--- a/basic/qa/basic_coverage/test_optional_paramters_compatible.bas
+++ b/basic/qa/basic_coverage/test_optional_paramters_compatible.bas
@@ -1,3 +1,10 @@
+' 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/.
+'
+
Option Compatible
Option Explicit
@@ -127,6 +134,12 @@ Sub verify_testOptionalsCompatible()
' - Actual : 448 (Actual value of the variable)
TestUtil.AssertEqual(TestObjectError, 449, "TestObjectError")
+ ' tdf#151503 - error handling of missing optional parameters (boolean operations)
+ ' Without the fix in place, this test would have failed with:
+ ' - Expected: 449 (ERRCODE_BASIC_NOT_OPTIONAL - Argument not optional)
+ ' - Actual : 0 (No error code since a missing parameter evaluates to true)
+ TestUtil.AssertEqual(TestBooleanOperations, 449, "TestBooleanOperations")
+
Exit Sub
errorHandler:
TestUtil.ReportErrorHandler("verify_testOptionalsCompatible", Err, Error$, Erl)
@@ -231,6 +244,15 @@ errorHandler:
TestObjectError = Err()
End Function
+Function TestBooleanOperations(Optional optBool As Boolean)
+On Error GoTo errorHandler
+ if optBool then
+ TestBooleanOperations = 0
+ end if
+errorHandler:
+ TestBooleanOperations = Err()
+End Function
+
Function CollectionSum(C)
Dim idx As Integer
CollectionSum = 0
diff --git a/basic/qa/basic_coverage/test_right_method.bas b/basic/qa/basic_coverage/test_right_method.bas
new file mode 100644
index 000000000000..45801d5d8686
--- /dev/null
+++ b/basic/qa/basic_coverage/test_right_method.bas
@@ -0,0 +1,28 @@
+' 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/.
+'
+
+Option Explicit
+
+Function doUnitTest() As String
+ TestUtil.TestInit
+ verify_Right_method
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Sub verify_Right_method
+ On Error GoTo errorHandler
+
+ ' RIGHT
+ TestUtil.AssertEqual(Right("abc", 2), "bc", "Right(""abc"",2)")
+
+ ' tdf#141474 keyword names need to match that of VBA
+ TestUtil.AssertEqual(Right(Length:=4, String:="sometext"), "text", "Right(Length:=4, String:=""sometext"")")
+
+ Exit Sub
+errorHandler:
+ TestUtil.ReportErrorHandler("verify_Right_method", Err, Error$, Erl)
+End Sub
diff --git a/basic/qa/basic_coverage/test_split_method.bas b/basic/qa/basic_coverage/test_split_method.bas
index 52ba91fe3a65..e53dfd9705f1 100644
--- a/basic/qa/basic_coverage/test_split_method.bas
+++ b/basic/qa/basic_coverage/test_split_method.bas
@@ -53,6 +53,12 @@ Sub verify_testSplit
TestUtil.AssertEqual(VarType(splitArr(i)), 8200, "VarType(splitArr(i))")
Next
+ ' tdf#141474 keyword names need to match that of VBA
+ TestUtil.AssertEqual(Split(expression:="LibreOffice StarOffice")(1), "StarOffice", "Split with 1 keyword name" )
+ Dim txt As String : txt = "Libre_Office_Star_Office"
+ TestUtil.AssertEqual(Split(delimiter:="_", expression:=txt)(2), "Star", "Split with 2 keyword names" )
+ TestUtil.AssertEqual(Split(limit:=3, delimiter:="_", expression:=txt)(2), "Star_Office", "Split with 3 keyword names" )
+
Exit Sub
errorHandler:
TestUtil.ReportErrorHandler("verify_testSplit", Err, Error$, Erl)
diff --git a/basic/qa/basic_coverage/test_string_method.bas b/basic/qa/basic_coverage/test_string_method.bas
index b06726e6045f..39b567a7882f 100644
--- a/basic/qa/basic_coverage/test_string_method.bas
+++ b/basic/qa/basic_coverage/test_string_method.bas
@@ -7,11 +7,25 @@
Option Explicit
-Function doUnitTest as String
- ' STRING
- If ( String( 3, "H" ) <> "HHH" ) Then
- doUnitTest = "FAIL"
- Else
- doUnitTest = "OK"
- End If
+Dim failedAssertion As Boolean, messages As String
+
+Function doUnitTest ' String(Number As Long, Character As String)
+
+ assert(String(3, "H")= "HHH", "String(3, ""H"") is not ""HHH""")
+ assert(String(5.8, "à")= "àààààà", "String(5.8, ""à"") is not ""àààààà""")
+ assert(String(Number:=3.45, Character:="test")="ttt", "String(Number:=3.45, Character:=""test"") is not ""ttt""")
+ assert(String(Character:="☺😎", Number:=7)= "☺☺☺☺☺☺☺", "String(Character:=""☺😎"", Number:=7) is not ""☺☺☺☺☺☺☺""")
+
+ If FailedAssertion Then
+ doUnitTest = "test_string_method.vb failed" + messages
+ Exit Function
+ EndIf
+ doUnitTest = "OK" ' All checks passed
End Function
+
+Sub assert(expression As Boolean, errMessage As String)
+ if ( Not expression ) Then
+ messages = messages + Chr(10) + ErrMessage
+ failedAssertion = True
+ EndIf
+End Sub \ No newline at end of file
diff --git a/basic/qa/basic_coverage/test_string_overflow_safe.bas b/basic/qa/basic_coverage/test_string_overflow_safe.bas
index f245e14abc4e..0b4fec15f0bd 100644
--- a/basic/qa/basic_coverage/test_string_overflow_safe.bas
+++ b/basic/qa/basic_coverage/test_string_overflow_safe.bas
@@ -1,3 +1,10 @@
+' 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/.
+'
+
Option Explicit
Function doUnitTest As String
diff --git a/basic/qa/basic_coverage/test_string_replace.bas b/basic/qa/basic_coverage/test_string_replace.bas
index d68f36fbb662..2b0f6354cd04 100644
--- a/basic/qa/basic_coverage/test_string_replace.bas
+++ b/basic/qa/basic_coverage/test_string_replace.bas
@@ -1,3 +1,10 @@
+' 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/.
+'
+
Option VBASupport 0
Option Explicit
diff --git a/basic/qa/basic_coverage/test_tdf132388_ReplacePerformance.bas b/basic/qa/basic_coverage/test_tdf132388_ReplacePerformance.bas
new file mode 100644
index 000000000000..1bb3b3de21c9
--- /dev/null
+++ b/basic/qa/basic_coverage/test_tdf132388_ReplacePerformance.bas
@@ -0,0 +1,28 @@
+'
+' 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/.
+'
+
+Function doUnitTest as String
+ TestUtil.TestInit
+ TestReplacePerformance()
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Sub TestReplacePerformance()
+ On Error GoTo errorHandler
+ ' Assume the normal case to be much faster than 60 s even on slow boxes, and the test string
+ ' is long enough to cause serious performance regressions make it perform much longer
+ n = 10000000
+ s = Space(n)
+ t = Now
+ s = Replace(s, " ", "*", 1, -1, 1)
+ t = Now - t
+ TestUtil.Assert(t <= TimeSerial(0, 2, 0), "TestReplacePerformance", Format(t, """t = ""[s]"" s"""))
+ Exit Sub
+errorHandler:
+ TestUtil.ReportErrorHandler("TestReplacePerformance", Err, Error$, Erl)
+End Sub
diff --git a/basic/qa/basic_coverage/test_tdf134692.bas b/basic/qa/basic_coverage/test_tdf134692.bas
index c310280fecdb..1f389f06cc86 100644
--- a/basic/qa/basic_coverage/test_tdf134692.bas
+++ b/basic/qa/basic_coverage/test_tdf134692.bas
@@ -1,3 +1,10 @@
+' 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/.
+'
+
Option VBASupport 0
Option Explicit
diff --git a/basic/qa/basic_coverage/test_tdf147089_idiv.bas b/basic/qa/basic_coverage/test_tdf147089_idiv.bas
new file mode 100644
index 000000000000..3d5e2271140c
--- /dev/null
+++ b/basic/qa/basic_coverage/test_tdf147089_idiv.bas
@@ -0,0 +1,30 @@
+'
+' 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/.
+'
+
+Option Explicit
+
+Function doUnitTest() As String
+ TestUtil.TestInit
+ verify_testIDiv
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Sub verify_testIDiv
+ On Error GoTo errorHandler
+
+ ' tdf#147089 - IDIV operands are rounded to Integer values before the operation is performed
+ TestUtil.AssertEqual(8.4 \ 2, 4, "8.4 \ 2")
+ TestUtil.AssertEqual(9.9 \ 2, 5, "9.9 \ 2")
+ TestUtil.AssertEqual(20 \ 4.9, 4, "20 \ 4.9")
+ TestUtil.AssertEqual(20 \ 4.4, 5, "20 \ 4.4")
+ TestUtil.AssertEqual(16.4 \ 5.9, 2, "16.4 \ 5.9")
+
+ Exit Sub
+errorHandler:
+ TestUtil.ReportErrorHandler("verify_testIDiv", Err, Error$, Erl)
+End Sub
diff --git a/basic/qa/basic_coverage/test_tdf147529_optional_parameters_msgbox.bas b/basic/qa/basic_coverage/test_tdf147529_optional_parameters_msgbox.bas
new file mode 100644
index 000000000000..67378213e287
--- /dev/null
+++ b/basic/qa/basic_coverage/test_tdf147529_optional_parameters_msgbox.bas
@@ -0,0 +1,36 @@
+'
+' 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/.
+'
+
+Option Explicit
+
+Function doUnitTest() As String
+ TestUtil.TestInit
+ verify_testOptionalParametersMsgBox
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Sub verify_testOptionalParametersMsgBox
+ On Error GoTo errorHandler
+
+ ' tdf#147529 - check for missing optional parameters
+ TestUtil.AssertEqual(TestOptionalParametersMsgBox(), True, "TestOptionalParametersMsgBox()")
+
+ Exit Sub
+errorHandler:
+ TestUtil.ReportErrorHandler("verify_testOptionalParametersMsgBox", Err, Error$, Erl)
+End Sub
+
+Function TestOptionalParametersMsgBox(Optional text, Optional dialogType, Optional dialogTitle) As Boolean
+On Error GoTo errorHandler
+ MsgBox(text, dialogType, dialogTitle)
+ TestOptionalParametersMsgBox = False
+ Exit Function
+errorHandler:
+ TestUtil.AssertEqual(Err, 449, "Argument not optional (Error 449)")
+ TestOptionalParametersMsgBox = True
+End Function
diff --git a/basic/qa/basic_coverage/test_tdf149622.bas b/basic/qa/basic_coverage/test_tdf149622.bas
new file mode 100644
index 000000000000..5c4738c068b2
--- /dev/null
+++ b/basic/qa/basic_coverage/test_tdf149622.bas
@@ -0,0 +1,48 @@
+'
+' 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/.
+'
+
+Option Explicit
+
+Function doUnitTest() As String
+ TestUtil.TestInit
+ verify_tdf149622()
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Sub verify_tdf149622()
+ On Error GoTo errorHandler
+
+ ' Testing fixed-type return value (Handler_handleEvent(...) As Boolean)
+ Dim oHandler
+ oHandler = CreateUnoListener("Handler_", "com.sun.star.awt.XEventHandler")
+ TestUtil.AssertEqualStrict(oHandler.handleEvent(0), True, "oHandler.handleEvent(0)")
+ ' Before the fix for tdf#149622, this returned the previous return value
+ TestUtil.AssertEqualStrict(oHandler.handleEvent(1), False, "oHandler.handleEvent(1)")
+
+ ' Testing Variant return value (Transfer_getData)
+ Dim oTransferable, aId0(0) As Byte, aId1(1) As Byte
+ oTransferable = CreateUnoListener("Transfer_", "com.sun.star.datatransfer.XSystemTransferable")
+ TestUtil.AssertEqualStrict(oTransferable.getData(aId0), True, "oTransferable.getData(aId0)")
+ ' Before the fix for tdf#149622, this returned the previous return value
+ TestUtil.AssertEqualStrict(oTransferable.getData(aId1), Empty, "oTransferable.getData(aId1)")
+
+ Exit Sub
+
+errorHandler:
+ TestUtil.ReportErrorHandler("verify_tdf149622", Err, Error$, Erl)
+End Sub
+
+Function Handler_handleEvent(Event) As Boolean
+ If Event = 0 Then Handler_handleEvent = True
+ ' Do not define return value explicitly in Else case
+End Function
+
+Function Transfer_getData(aProcessId())
+ If UBound(aProcessId) - LBound(aProcessId) = 0 Then Transfer_getData = True ' only for 1-element array
+ ' Do not define return value explicitly in Else case
+End Function
diff --git a/basic/qa/basic_coverage/test_tdf150137_parse_fail.bas b/basic/qa/basic_coverage/test_tdf150137_parse_fail.bas
new file mode 100644
index 000000000000..fdf9f1e9948e
--- /dev/null
+++ b/basic/qa/basic_coverage/test_tdf150137_parse_fail.bas
@@ -0,0 +1,37 @@
+'
+' 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/.
+'
+
+Option Explicit
+
+Function doUnitTest() As String
+ On Error GoTo ErrorHandler ' Set up error handler
+
+ Dim Xml As String
+ Dim XmlLen As Long
+ ' Not namespace-well-formed XML, parse is expected to fail
+ Xml = "<a:xml/>"
+ XmlLen = Len(Xml)
+ Dim XmlByte(1 To XmlLen) As Byte
+ Dim Index As Integer
+ For Index = 1 To XmlLen
+ XmlByte(Index) = Asc(Mid(Xml, Index, 1))
+ Next
+ Dim source As Object
+ source = CreateUnoStruct("com.sun.star.xml.sax.InputSource")
+ source.aInputStream = com.sun.star.io.SequenceInputStream.createStreamFromSequence(XmlByte)
+ Dim parser As Object
+ parser = CreateUnoService("com.sun.star.xml.sax.FastParser")
+ ' Parse crashed before the fix
+ parser.ParseStream(source)
+
+ ' Shouldn't end up here
+ doUnitTest = "FAIL"
+ Exit Function
+ErrorHandler:
+ doUnitTest = "OK"
+End Function
diff --git a/basic/qa/basic_coverage/test_tdf98778.bas b/basic/qa/basic_coverage/test_tdf98778.bas
index 0228e5060ba8..451d4bde70bc 100644
--- a/basic/qa/basic_coverage/test_tdf98778.bas
+++ b/basic/qa/basic_coverage/test_tdf98778.bas
@@ -1,3 +1,10 @@
+' 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/.
+'
+
Option VBASupport 0
Option Explicit
diff --git a/basic/qa/basic_coverage/test_transliteration.bas b/basic/qa/basic_coverage/test_transliteration.bas
new file mode 100644
index 000000000000..dd5f24fb4dae
--- /dev/null
+++ b/basic/qa/basic_coverage/test_transliteration.bas
@@ -0,0 +1,52 @@
+' 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/.
+'
+
+Option Explicit
+
+Function doUnitTest() As String
+ TestUtil.TestInit
+ verify_testTransliteration
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Sub verify_testTransliteration
+ On Error GoTo errorHandler
+
+ Dim oTr As Object, s$, oLoc as new com.sun.star.lang.Locale
+
+ With oLoc
+ .Country="US"
+ .Language="en"
+ .Variant=""
+ End With
+
+ s="AB cd. eF. "
+ oTr = CreateUnoService("com.sun.star.i18n.Transliteration")
+
+ oTr.LoadModuleByImplName("LOWERCASE_UPPERCASE", oLoc)
+ TestUtil.AssertEqual(oTr.transliterateString2String(s, 0, Len(s)), "AB CD. EF. ", "LOWERCASE_UPPERCASE")
+
+ oTr.LoadModuleByImplName("UPPERCASE_LOWERCASE", oLoc)
+ TestUtil.AssertEqual(oTr.transliterateString2String(s, 0, Len(s)), "ab cd. ef. ", "UPPERCASE_LOWERCASE")
+
+ oTr.LoadModuleByImplName("TOGGLE_CASE", oLoc)
+ TestUtil.AssertEqual(oTr.transliterateString2String(s, 0, Len(s)), "ab CD. Ef. ", "TOGGLE_CASE")
+
+ oTr.LoadModuleByImplName("IGNORE_CASE", oLoc)
+ TestUtil.AssertEqual(oTr.transliterateString2String(s, 0, Len(s)), "ab cd. ef. ", "IGNORE_CASE")
+
+ ' tdf#152520: Without the fix in place, this test would have crashed here
+ oTr.LoadModuleByImplName("TITLE_CASE", oLoc)
+ TestUtil.AssertEqual(oTr.transliterateString2String(s, 0, Len(s)), "Ab cd. ef. ", "TITLE_CASE")
+
+ oTr.LoadModuleByImplName("SENTENCE_CASE", oLoc)
+ TestUtil.AssertEqual(oTr.transliterateString2String(s, 0, Len(s)), "Ab cd. ef. ", "SENTENCE_CASE")
+
+ Exit Sub
+errorHandler:
+ TestUtil.ReportErrorHandler("verify_testTransliteration", Err, Error$, Erl)
+End Sub
diff --git a/basic/qa/basic_coverage/test_typename_method.bas b/basic/qa/basic_coverage/test_typename_method.bas
index 80a9658d25a7..028f57f0e8db 100644
--- a/basic/qa/basic_coverage/test_typename_method.bas
+++ b/basic/qa/basic_coverage/test_typename_method.bas
@@ -27,6 +27,8 @@ Dim intArray() As Integer, lngArray(5) As Long, sngArray!() As Single, dblArra
Function doUnitTest ' TypeName()
myErr = CVErr(0.56E-41)
+ assert(TypeName(varName:=int16) = "Integer", "TypeName(varName:=int16) is not ""Integer""")
+
assert( TypeName(int16) = "Integer" , "TypeName(int16) is not ""Integer""")
assert( TypeName(int32) = "Long" , "TypeName(int32) is not ""Long""")
assert( TypeName(flt32) = "Single" , "TypeName(flt32) is not ""Single""" )
diff --git a/basic/qa/basic_coverage/test_unsigned_integers.bas b/basic/qa/basic_coverage/test_unsigned_integers.bas
new file mode 100644
index 000000000000..d7f2385ecff5
--- /dev/null
+++ b/basic/qa/basic_coverage/test_unsigned_integers.bas
@@ -0,0 +1,46 @@
+'
+' 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/.
+'
+
+Option Explicit
+
+Function doUnitTest() As String
+ TestUtil.TestInit
+ verify_testUnsignedIntegers
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Function convertToDouble(n)
+ Dim conv As Object
+ conv = CreateUnoService("com.sun.star.script.Converter")
+ convertToDouble = conv.convertToSimpleType(n, com.sun.star.uno.TypeClass.DOUBLE)
+End Function
+
+Sub verify_testUnsignedIntegers()
+ On Error GoTo errorHandler
+
+ Dim t As New com.sun.star.util.Time ' has both unsigned long and unsigned short
+ t.Seconds = 201
+ t.NanoSeconds = 202
+ Dim u8 As Byte, u16, u32
+ u8 = 200
+ u16 = t.Seconds ' UShort
+ u32 = t.NanoSeconds ' ULong
+
+ TestUtil.AssertEqual(TypeName(u8), "Byte", "TypeName(u8)")
+ TestUtil.AssertEqual(convertToDouble(u8), 200, "convertToDouble(u8)")
+
+ TestUtil.AssertEqual(TypeName(u16), "UShort", "TypeName(u16)")
+ TestUtil.AssertEqual(convertToDouble(u16), 201, "convertToDouble(u16)")
+
+ TestUtil.AssertEqual(TypeName(u32), "ULong", "TypeName(u32)")
+ TestUtil.AssertEqual(convertToDouble(u32), 202, "convertToDouble(u32)")
+
+ Exit Sub
+errorHandler:
+ TestUtil.ReportErrorHandler("verify_testUnsignedIntegers", Err, Error$, Erl)
+End Sub
diff --git a/basic/qa/basic_coverage/test_vartype_method.bas b/basic/qa/basic_coverage/test_vartype_method.bas
index 3ab6f1f44358..1b7372b27933 100644
--- a/basic/qa/basic_coverage/test_vartype_method.bas
+++ b/basic/qa/basic_coverage/test_vartype_method.bas
@@ -53,6 +53,8 @@ Sub verify_testvartype()
TestUtil.AssertEqual( VarType(Nothing), V_OBJECT, "Vartype(Empty) is not V_OBJECT")
myErr = CVErr("errMsg")
+ TestUtil.AssertEqual(VarType(varName:=int16), V_INTEGER, "VarType(varName:=int16) is not V_INTEGER")
+
TestUtil.AssertEqual( VarType(int16), V_INTEGER , "VarType(int16) is not V_INTEGER")
TestUtil.AssertEqual( VarType(int32), V_LONG , "VarType(int32) is not V_LONG")
TestUtil.AssertEqual( VarType(flt32), V_SINGLE , "VarType(flt32) is not V_SINGLE" )
diff --git a/basic/qa/basic_coverage/zh-CN/test_ccur_zh_CN_locale.bas b/basic/qa/basic_coverage/zh-CN/test_ccur_zh_CN_locale.bas
new file mode 100644
index 000000000000..38a084e36c7f
--- /dev/null
+++ b/basic/qa/basic_coverage/zh-CN/test_ccur_zh_CN_locale.bas
@@ -0,0 +1,27 @@
+'
+' 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/.
+'
+
+Option Explicit
+
+Function doUnitTest as String
+ TestUtil.TestInit
+ verify_testCCurZhCNLocale
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Sub verify_testCCurZhCNLocale
+ On Error GoTo errorHandler
+
+ ' tdf#141050 - characteristic test for CCur() with the zh_CN locale
+ TestUtil.AssertEqual(CCur("75.50"), 75.5, "CCur(75.50)")
+ TestUtil.AssertEqual(CCur("¥75.50"), 75.5, "CCur(¥75.50)")
+
+ Exit Sub
+errorHandler:
+ TestUtil.ReportErrorHandler("verify_testCCurZhCNLocale", Err, Error$, Erl)
+End Sub
diff --git a/basic/qa/cppunit/_test_asserts.bas b/basic/qa/cppunit/_test_asserts.bas
index 51442a0590a6..0c3e0b371f14 100644
--- a/basic/qa/cppunit/_test_asserts.bas
+++ b/basic/qa/cppunit/_test_asserts.bas
@@ -34,8 +34,8 @@ Sub Assert(Assertion As Boolean, Optional testId As String, Optional testComment
If Not IsMissing(testId) Then
testMsg = " " + testId
End If
- If Not IsMissing(testComment) And Not (testComment = "") Then
- testMsg = testMsg + " (" + testComment + ")"
+ If Not IsMissing(testComment) Then
+ If Not (testComment = "") Then testMsg = testMsg + " (" + testComment + ")"
End If
result = result & Chr$(10) & " Failed:" & testMsg
@@ -52,6 +52,12 @@ Sub AssertEqual(actual As Variant, expected As Variant, testName As String)
End If
End Sub
+' Same as AssertEqual, but also checks actual and expected types
+Sub AssertEqualStrict(actual As Variant, expected As Variant, testName As String)
+ AssertEqual actual, expected, testName
+ AssertEqual TypeName(actual), TypeName(expected), testName & " type mismatch:"
+End Sub
+
Sub AssertEqualApprox(actual, expected, epsilon, testName As String)
If Abs(expected - actual) <= epsilon Then
passCount = passCount + 1
diff --git a/basic/qa/cppunit/_test_asserts.vb b/basic/qa/cppunit/_test_asserts.vb
index 0f1d0d88610f..2130ce02f454 100644
--- a/basic/qa/cppunit/_test_asserts.vb
+++ b/basic/qa/cppunit/_test_asserts.vb
@@ -35,8 +35,8 @@ Sub Assert(Assertion As Boolean, Optional testId As String, Optional testComment
If Not IsMissing(testId) Then
testMsg = " " + testId
End If
- If Not IsMissing(testComment) And Not (testComment = "") Then
- testMsg = testMsg + " (" + testComment + ")"
+ If Not IsMissing(testComment) Then
+ If Not (testComment = "") Then testMsg = testMsg + " (" + testComment + ")"
End If
result = result & Chr$(10) & " Failed:" & testMsg
@@ -53,6 +53,12 @@ Sub AssertEqual(actual As Variant, expected As Variant, testName As String)
End If
End Sub
+' Same as AssertEqual, but also checks actual and expected types
+Sub AssertEqualStrict(actual As Variant, expected As Variant, testName As String)
+ AssertEqual actual, expected, testName
+ AssertEqual TypeName(actual), TypeName(expected), testName & " type mismatch:"
+End Sub
+
Sub AssertEqualApprox(actual, expected, epsilon, testName As String)
If Abs(expected - actual) <= epsilon Then
passCount = passCount + 1
diff --git a/basic/qa/cppunit/basictest.cxx b/basic/qa/cppunit/basictest.cxx
index 8cf9812d5212..13dc8c72e4cb 100644
--- a/basic/qa/cppunit/basictest.cxx
+++ b/basic/qa/cppunit/basictest.cxx
@@ -108,7 +108,7 @@ bool MacroSnippet::Compile()
bool MacroSnippet::HasError() const { return mbError; }
-const ErrCode& MacroSnippet::getError() const { return maErrCode; }
+const ErrCodeMsg& MacroSnippet::getError() const { return maErrCode; }
IMPL_LINK( MacroSnippet, BasicErrorHdl, StarBASIC *, /*pBasic*/, bool)
{
diff --git a/basic/qa/cppunit/basictest.hxx b/basic/qa/cppunit/basictest.hxx
index 1901492bcfab..46af3542b82b 100644
--- a/basic/qa/cppunit/basictest.hxx
+++ b/basic/qa/cppunit/basictest.hxx
@@ -23,7 +23,7 @@ class MacroSnippet
{
private:
bool mbError;
- ErrCode maErrCode;
+ ErrCodeMsg maErrCode;
BasicDLL maDll; // we need a dll instance for resource manager etc.
SbModuleRef mpMod;
StarBASICRef mpBasic;
@@ -46,7 +46,7 @@ public:
DECL_LINK(BasicErrorHdl, StarBASIC*, bool);
bool HasError() const;
- const ErrCode& getError() const;
+ const ErrCodeMsg& getError() const;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basic/qa/cppunit/data/tdf149714.png b/basic/qa/cppunit/data/tdf149714.png
new file mode 100644
index 000000000000..d22b8451864d
--- /dev/null
+++ b/basic/qa/cppunit/data/tdf149714.png
Binary files differ
diff --git a/basic/qa/cppunit/test_compiler_checks.cxx b/basic/qa/cppunit/test_compiler_checks.cxx
index 24b380ed2a9a..2b8e72997c64 100644
--- a/basic/qa/cppunit/test_compiler_checks.cxx
+++ b/basic/qa/cppunit/test_compiler_checks.cxx
@@ -21,7 +21,7 @@ CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testRedefineArgument)
"End Sub\n");
aMacro.Compile();
CPPUNIT_ASSERT(aMacro.HasError());
- CPPUNIT_ASSERT_EQUAL(ERRCODE_BASIC_VAR_DEFINED, aMacro.getError().StripDynamic());
+ CPPUNIT_ASSERT_EQUAL(ERRCODE_BASIC_VAR_DEFINED, aMacro.getError().GetCode());
}
CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testDoubleArgument)
@@ -30,7 +30,141 @@ CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testDoubleArgument)
"End Sub\n");
aMacro.Compile();
CPPUNIT_ASSERT(aMacro.HasError());
- CPPUNIT_ASSERT_EQUAL(ERRCODE_BASIC_VAR_DEFINED, aMacro.getError().StripDynamic());
+ CPPUNIT_ASSERT_EQUAL(ERRCODE_BASIC_VAR_DEFINED, aMacro.getError().GetCode());
}
+CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf149157)
+{
+ MacroSnippet aMacro("Function extentComment() As Integer\n"
+ " ' _\n"
+ " If Not extentComment Then\n"
+ " extentComment = 1\n"
+ " End If\n"
+ "End Function\n");
+ aMacro.Compile();
+ CPPUNIT_ASSERT(!aMacro.HasError());
+}
+
+CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf149157_compatible)
+{
+ MacroSnippet aMacro("Option Compatible\n"
+ "Function extentComment() As Integer\n"
+ " ' _\n"
+ "\n"
+ " If Not extentComment Then\n"
+ " extentComment = 1\n"
+ " End If\n"
+ "End Function\n");
+ aMacro.Compile();
+ CPPUNIT_ASSERT(!aMacro.HasError());
+}
+
+CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf149157_vba)
+{
+ MacroSnippet aMacro("Option VBASupport 1\n"
+ "Function extentComment() As Integer\n"
+ " ' _\n"
+ "\n"
+ " If Not extentComment Then\n"
+ " extentComment = 1\n"
+ " End If\n"
+ "End Function\n");
+ aMacro.Compile();
+ CPPUNIT_ASSERT(!aMacro.HasError());
+}
+
+CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf149402)
+{
+ MacroSnippet aMacro("Function extentComment() As Integer\n"
+ " ' _ \n"
+ " If Not extentComment Then\n"
+ " extentComment = 1\n"
+ " Else\n"
+ " End If\n"
+ "End Function\n");
+ aMacro.Compile();
+ CPPUNIT_ASSERT(!aMacro.HasError());
+}
+
+CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf149402_compatible)
+{
+ MacroSnippet aMacro("Option Compatible\n"
+ "Function extentComment() As Integer\n"
+ " ' _ \n"
+ " If Not extentComment Then\n"
+ " extentComment = 1\n"
+ " Else\n"
+ " End If\n"
+ "End Function\n");
+ aMacro.Compile();
+ CPPUNIT_ASSERT(!aMacro.HasError());
+}
+
+CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf149402_vba)
+{
+ MacroSnippet aMacro("Option VBASupport 1\n"
+ "Function extentComment() As Integer\n"
+ " ' _ \n"
+ " If Not extentComment Then\n"
+ " extentComment = 1\n"
+ " Else\n"
+ " End If\n"
+ "End Function\n");
+ aMacro.Compile();
+ CPPUNIT_ASSERT(!aMacro.HasError());
+}
+
+CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf93727_if)
+{
+ // #If and #End directive
+ MacroSnippet aMacro("Sub doUnitTest\n"
+ " #If 1 = 1 Then\n"
+ " Const a = 10\n"
+ " #End If\n"
+ "End Sub\n");
+ aMacro.Compile();
+ CPPUNIT_ASSERT_MESSAGE("#If directive causes compile error", !aMacro.HasError());
+}
+
+CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf93727_else)
+{
+ // #Else directive
+ MacroSnippet aMacro("Sub doUnitTest\n"
+ "a = 0\n"
+ "#If 1 = 0 Then\n"
+ " a = 10\n"
+ "#Else\n"
+ " a = 20\n"
+ "#End If\n"
+ "End Sub\n");
+ aMacro.Compile();
+ CPPUNIT_ASSERT_MESSAGE("#Else directive causes compile error", !aMacro.HasError());
+}
+
+CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf93727_elseif)
+{
+ // #ElseIf directive
+ MacroSnippet aMacro("Sub doUnitTest\n"
+ "a = 0\n"
+ " #If 1 = 0 Then\n"
+ " a = 10\n"
+ " #ElseIf 2 = 2 Then\n"
+ " a = 20\n"
+ " #End If\n"
+ "End Sub\n");
+ aMacro.Compile();
+ CPPUNIT_ASSERT_MESSAGE("#ElseIf directive causes compile error", !aMacro.HasError());
+}
+
+CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf93727_const)
+{
+ // #Const directive
+ MacroSnippet aMacro("#Const MaxValue = 1000\n"
+ "Sub doUnitTest\n"
+ " Dim value As Integer\n"
+ " value = MaxValue\n"
+ "End Sub\n");
+ aMacro.Compile();
+ CPPUNIT_ASSERT_MESSAGE("#Const directive causes compile error", !aMacro.HasError());
+}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/basic/qa/cppunit/test_global_array.cxx b/basic/qa/cppunit/test_global_array.cxx
index 5317e8701858..d2dafcfbda00 100644
--- a/basic/qa/cppunit/test_global_array.cxx
+++ b/basic/qa/cppunit/test_global_array.cxx
@@ -51,8 +51,8 @@ End Function
)BAS");
CPPUNIT_ASSERT(mod->Compile());
- CPPUNIT_ASSERT_EQUAL(StarBASIC::GetErrBasic(), ERRCODE_NONE);
- CPPUNIT_ASSERT_EQUAL(SbxBase::GetError(), ERRCODE_NONE);
+ CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, StarBASIC::GetErrBasic());
+ CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, SbxBase::GetError());
CPPUNIT_ASSERT(mod->IsCompiled());
return mod;
}
diff --git a/basic/qa/cppunit/test_global_as_new.cxx b/basic/qa/cppunit/test_global_as_new.cxx
index ea5b6fcc527c..868f62d3ec15 100644
--- a/basic/qa/cppunit/test_global_as_new.cxx
+++ b/basic/qa/cppunit/test_global_as_new.cxx
@@ -45,8 +45,8 @@ End Function
)BAS");
CPPUNIT_ASSERT(mod->Compile());
- CPPUNIT_ASSERT_EQUAL(StarBASIC::GetErrBasic(), ERRCODE_NONE);
- CPPUNIT_ASSERT_EQUAL(SbxBase::GetError(), ERRCODE_NONE);
+ CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, StarBASIC::GetErrBasic());
+ CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, SbxBase::GetError());
CPPUNIT_ASSERT(mod->IsCompiled());
return mod;
}
diff --git a/basic/qa/cppunit/test_scanner.cxx b/basic/qa/cppunit/test_scanner.cxx
index 6559b3e35d48..f17750c89a6e 100644
--- a/basic/qa/cppunit/test_scanner.cxx
+++ b/basic/qa/cppunit/test_scanner.cxx
@@ -69,12 +69,12 @@ private:
CPPUNIT_TEST_SUITE_END();
};
-const OUString cr = "\n";
-const OUString rem = "REM";
-const OUString asdf = "asdf";
-const OUString dot = ".";
-const OUString goto_ = "goto";
-const OUString excl = "!";
+constexpr OUString cr = u"\n"_ustr;
+constexpr OUString rem = u"REM"_ustr;
+constexpr OUString asdf = u"asdf"_ustr;
+constexpr OUString dot = u"."_ustr;
+constexpr OUString goto_ = u"goto"_ustr;
+constexpr OUString excl = u"!"_ustr;
std::vector<Symbol> getSymbols(const OUString& source, sal_Int32& errors, bool bCompatible = false)
{
@@ -160,14 +160,14 @@ void ScannerTest::testBlankLines()
void ScannerTest::testOperators()
{
- const OUString sourceE("=");
- const OUString sourceLT("<");
- const OUString sourceGT(">");
- const OUString sourceLTE("<=");
- const OUString sourceGTE(">=");
- const OUString sourceNE("<>");
- const OUString sourceA(":=");
- const OUString sourceNot("Not");
+ constexpr OUString sourceE(u"="_ustr);
+ constexpr OUString sourceLT(u"<"_ustr);
+ constexpr OUString sourceGT(u">"_ustr);
+ constexpr OUString sourceLTE(u"<="_ustr);
+ constexpr OUString sourceGTE(u">="_ustr);
+ constexpr OUString sourceNE(u"<>"_ustr);
+ constexpr OUString sourceA(u":="_ustr);
+ constexpr OUString sourceNot(u"Not"_ustr);
std::vector<Symbol> symbols;
@@ -239,12 +239,12 @@ void ScannerTest::testOperators()
void ScannerTest::testAlphanum()
{
- const OUString source1("asdfghefg");
- const OUString source3("AdfsaAUdsl10987");
- const OUString source4("asdfa_mnvcnm");
- const OUString source5("_asdf1");
- const OUString source6("_6");
- const OUString source7("joxclk_");
+ constexpr OUString source1(u"asdfghefg"_ustr);
+ constexpr OUString source3(u"AdfsaAUdsl10987"_ustr);
+ constexpr OUString source4(u"asdfa_mnvcnm"_ustr);
+ constexpr OUString source5(u"_asdf1"_ustr);
+ constexpr OUString source6(u"_6"_ustr);
+ constexpr OUString source7(u"joxclk_"_ustr);
std::vector<Symbol> symbols;
diff --git a/basic/qa/cppunit/test_tdf149714.cxx b/basic/qa/cppunit/test_tdf149714.cxx
new file mode 100644
index 000000000000..76713508560c
--- /dev/null
+++ b/basic/qa/cppunit/test_tdf149714.cxx
@@ -0,0 +1,86 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * 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/.
+ */
+
+#include <sal/config.h>
+#include <basic/sbstar.hxx>
+#include <basic/sbmeth.hxx>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <unotest/directories.hxx>
+
+namespace
+{
+class TestTdf149714 : public CppUnit::TestFixture
+{
+ void testBitsPerPixel();
+
+ CPPUNIT_TEST_SUITE(TestTdf149714);
+ CPPUNIT_TEST(testBitsPerPixel);
+ CPPUNIT_TEST_SUITE_END();
+
+ StarBASICRef interpreter;
+
+ SbModuleRef Module()
+ {
+ test::Directories aDirectories;
+ OUString aDataFileName
+ = aDirectories.getURLFromSrc(u"basic/qa/cppunit/data/") + u"tdf149714.png";
+ OUString sBasic = uR"BAS(
+
+Function GetBitsPerPixelAsString As String
+ DIM oProps(0) As New "com.sun.star.beans.PropertyValue"
+ DIM oProvider, oGraphic
+
+ oProps(0).Name = "URL"
+ oProps(0).Value = "$PNGFILENAME"
+
+ oProvider = createUnoService("com.sun.star.graphic.GraphicProvider")
+ oGraphic = oProvider.queryGraphic(oProps())
+
+ GetBitsPerPixelAsString = oGraphic.BitsPerPixel
+
+End Function
+
+)BAS"_ustr;
+
+ sBasic = sBasic.replaceFirst("$PNGFILENAME", aDataFileName);
+
+ interpreter = new StarBASIC();
+ auto mod = interpreter->MakeModule("BitsPerPixel", sBasic);
+
+ CPPUNIT_ASSERT(mod->Compile());
+ CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, StarBASIC::GetErrBasic());
+ CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, SbxBase::GetError());
+ CPPUNIT_ASSERT(mod->IsCompiled());
+ return mod;
+ }
+};
+
+void TestTdf149714::testBitsPerPixel()
+{
+ auto m = Module();
+ auto GetBitsPerPixelAsString = m->FindMethod("GetBitsPerPixelAsString", SbxClassType::Method);
+ CPPUNIT_ASSERT_MESSAGE("Could not Find GetBitsPerPixelAsString in module",
+ GetBitsPerPixelAsString != nullptr);
+
+ SbxVariableRef returned = new SbxMethod{ *GetBitsPerPixelAsString };
+ CPPUNIT_ASSERT(returned->IsString());
+
+ // Without the fix in place this would fail with:
+ // - Expected: 24
+ // - Actual: True
+ CPPUNIT_ASSERT_EQUAL(OUString{ "24" }, returned->GetOUString());
+}
+
+// Put the test suite in the registry
+CPPUNIT_TEST_SUITE_REGISTRATION(TestTdf149714);
+
+} // namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/basic/qa/cppunit/test_vba.cxx b/basic/qa/cppunit/test_vba.cxx
index 818ba1c5f4c0..8a15ba7234e8 100644
--- a/basic/qa/cppunit/test_vba.cxx
+++ b/basic/qa/cppunit/test_vba.cxx
@@ -14,11 +14,7 @@
#include <comphelper/processfactory.hxx>
#include <o3tl/char16_t2wchar_t.hxx>
-#if !defined WIN32_LEAN_AND_MEAN
-# define WIN32_LEAN_AND_MEAN
-#endif
-#include <windows.h>
-#include <odbcinst.h>
+#include <systools/win32/odbccp32.hxx>
#endif
using namespace ::com::sun::star;
@@ -94,6 +90,7 @@ void VBATest::testMiscVBAFunctions()
"hex.vb",
"hour.vb",
"formatnumber.vb",
+ "formatpercent.vb",
"iif.vb",
"instr.vb",
"instrrev.vb",
@@ -117,6 +114,7 @@ void VBATest::testMiscVBAFunctions()
"minute.vb",
"month.vb",
"monthname.vb",
+ "like.vb",
"oct.vb",
"optional_paramters.vb",
"qbcolor.vb",
@@ -134,6 +132,9 @@ void VBATest::testMiscVBAFunctions()
"string.vb",
"strreverse.vb",
"switch.vb",
+ "tdf147089_idiv.vb",
+ "tdf147529_optional_parameters_msgbox.vb",
+ "tdf148358_non_ascii_names.vb",
"timeserial.vb",
"timevalue.vb",
"trim.vb",
@@ -157,7 +158,7 @@ void VBATest::testMiscVBAFunctions()
SvtSysLocaleOptions aLocalOptions;
aLocalOptions.SetLocaleConfigString( aLocale.getBcp47() );
- for ( size_t i=0; i<SAL_N_ELEMENTS( macroSource ); ++i )
+ for ( size_t i=0; i<std::size( macroSource ); ++i )
{
OUString sMacroURL = sMacroPathURL
+ OUString::createFromAscii( macroSource[ i ] );
@@ -207,7 +208,8 @@ void VBATest::testMiscOLEStuff()
const int nBufSize = 1024 * 4;
wchar_t sBuf[nBufSize];
- SQLGetInstalledDriversW( sBuf, nBufSize, nullptr );
+ if (!sal::systools::odbccp32().SQLGetInstalledDrivers(sBuf, nBufSize))
+ return;
const wchar_t *pODBCDriverName = sBuf;
bool bFound = false;
@@ -234,11 +236,11 @@ void VBATest::testMiscOLEStuff()
uno::Sequence< uno::Any > aArgs
{
- uno::makeAny(sPath),
- uno::makeAny(OUString(o3tl::toU(pODBCDriverName)))
+ uno::Any(sPath),
+ uno::Any(OUString(o3tl::toU(pODBCDriverName)))
};
- for ( sal_uInt32 i=0; i<SAL_N_ELEMENTS( macroSource ); ++i )
+ for ( sal_uInt32 i=0; i<std::size( macroSource ); ++i )
{
OUString sMacroURL = sMacroPathURL
+ OUString::createFromAscii( macroSource[ i ] );
diff --git a/basic/qa/vba_tests/Err.Raise.vb b/basic/qa/vba_tests/Err.Raise.vb
index 914906c342c0..d7714facb3bb 100644
--- a/basic/qa/vba_tests/Err.Raise.vb
+++ b/basic/qa/vba_tests/Err.Raise.vb
@@ -45,7 +45,7 @@ catch:
TestUtil.Assert(Err.Source = CurErrSource, "Err.Source failure", "Err.Source = " & Err.Source)
TestUtil.Assert(Err.Description = CurErrDescription, "Err.Description failure", "Err.Description = " & Err.Description)
- TestUtil.Assert(Erl = 32, "line# failure", "Erl = " & Erl ' WATCH OUT for HARDCODED LINE # HERE !)
+ TestUtil.Assert(Erl = 32, "line# failure", "Erl = " & Erl ) ' WATCH OUT for HARDCODED LINE # HERE
TestUtil.Assert(Err = CurErrNo, "Err# failure", "Err = " & Err)
TestUtil.Assert(Error = CurErrDescription, "Error description failure", "Error$ = " & Error$)
diff --git a/basic/qa/vba_tests/cdbl.vb b/basic/qa/vba_tests/cdbl.vb
index f29271f082d6..8a7d09cd5a2e 100644
--- a/basic/qa/vba_tests/cdbl.vb
+++ b/basic/qa/vba_tests/cdbl.vb
@@ -23,6 +23,11 @@ Sub verify_testCdbl()
TestUtil.AssertEqual(CDbl(0.005 * 0.01), 0.00005, "CDbl(0.005 * 0.01)")
TestUtil.AssertEqual(CDbl("20"), 20, "CDbl(""20"")")
+
+ ' tdf#146672 - skip spaces and tabs at the end of the scanned string
+ TestUtil.AssertEqual(CDbl("28.8 "), 28.8, "CDbl(""28.8 "")")
+ TestUtil.AssertEqual(CDbl("28.8 "), 28.8, "CDbl(""28.8 "")")
+
Exit Sub
errorHandler:
TestUtil.ReportErrorHandler("verify_testCdbl", Err, Error$, Erl)
diff --git a/basic/qa/vba_tests/chr.vb b/basic/qa/vba_tests/chr.vb
index 5dc85a0c9157..f9bc7ea12aa5 100644
--- a/basic/qa/vba_tests/chr.vb
+++ b/basic/qa/vba_tests/chr.vb
@@ -21,7 +21,7 @@ Sub verify_testCHR()
TestUtil.AssertEqual(Chr(87), "W", "Chr(87)")
TestUtil.AssertEqual(Chr(105), "i", "Chr(105)")
TestUtil.AssertEqual(Chr(35), "#", "Chr(35)")
-
+
' tdf#145693 - argument name should be 'charcode' instead of 'string'
TestUtil.AssertEqual(Chr(charcode:=35), "#", "Chr(charcode:=35)")
diff --git a/basic/qa/vba_tests/constants.vb b/basic/qa/vba_tests/constants.vb
index be7add515e83..c31444889fae 100644
--- a/basic/qa/vba_tests/constants.vb
+++ b/basic/qa/vba_tests/constants.vb
@@ -25,6 +25,15 @@ Sub verify_testConstants()
TestUtil.AssertEqual(vbNewLine, vbLf, "vbNewline")
End If
+ ' tdf#153543 - check for vba shell constants
+ ' See https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/shell-constants
+ TestUtil.AssertEqual(vbHide, 0, "vbHide")
+ TestUtil.AssertEqual(vbNormalFocus, 1, "vbNormalFocus")
+ TestUtil.AssertEqual(vbMinimizedFocus, 2, "vbMinimizedFocus")
+ TestUtil.AssertEqual(vbMaximizedFocus, 3, "vbMaximizedFocus")
+ TestUtil.AssertEqual(vbNormalNoFocus, 4, "vbNormalNoFocus")
+ TestUtil.AssertEqual(vbMinimizedNoFocus, 6, "vbMinimizedNoFocus")
+
' tdf#131563 - check for vba color constants
' See https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/color-constants
TestUtil.AssertEqual(vbBlack, RGB(0, 0, 0), "vbBlack")
diff --git a/basic/qa/vba_tests/cstr.vb b/basic/qa/vba_tests/cstr.vb
index dfa77b7db1f0..5eb43738f10c 100644
--- a/basic/qa/vba_tests/cstr.vb
+++ b/basic/qa/vba_tests/cstr.vb
@@ -24,6 +24,7 @@ Sub verify_testCStr()
TestUtil.AssertEqual(CStr(500), "500", "CStr(500)")
' tdf#143575 - round string to their nearest double representation
+ ' N.B.: check also how current conversion rounds a close number
' Without the fix in place, this test would have failed with:
' - Expected: 691.2
' - Actual : 691.2000000000001
diff --git a/basic/qa/vba_tests/format.vb b/basic/qa/vba_tests/format.vb
index 0e997ca824db..67abc5ffe24a 100644
--- a/basic/qa/vba_tests/format.vb
+++ b/basic/qa/vba_tests/format.vb
@@ -135,7 +135,7 @@ Sub Custom_Number_Format_Sample()
TestUtil.AssertEqual(Format(12345.25, "#,###.##"), "12,345.25", "Format(12345.25, ""#,###.##"")")
TestUtil.AssertEqual(Format(0.25, "##.00%"), "25.00%", "Format(0.25, ""##.00%"")")
TestUtil.AssertEqual(Format(1000000, "#,###"), "1,000,000", "Format(1000000, ""#,###"")")
- TestUtil.AssertEqual(Format(1.09837555, "#.#####E+###"), "1.09838E+000", "Format(1.09837555, ""#.#####E+###"")")
+ TestUtil.AssertEqual(Format(1.09837555, "#.#####E+000"), "1.09838E+000", "Format(1.09837555, ""#.#####E+000"")")
TestUtil.AssertEqual(Format(1.09837555, "###.####E#"), "1.0984E0", "Format(1.09837555, ""###.####E#"")")
TestUtil.AssertEqual(Format(1098.37555, "###.####E#"), "1.0984E3", "Format(1098.37555, ""###.####E#"")")
TestUtil.AssertEqual(Format(1098375.55, "###.####E#"), "1.0984E6", "Format(1098375.55, ""###.####E#"")")
@@ -148,7 +148,8 @@ Sub Custom_Number_Format_Sample()
TestUtil.AssertEqual(Format(123456, "####E0"), "12E4", "Format(123456, ""####E0"")")
TestUtil.AssertEqual(Format(2345.25, "$#,###.##"), "$2,345.25", "Format(2345.25, ""$#,###.##"")")
TestUtil.AssertEqual(Format(0.25, "##.###\%"), ".25%", "Format(0.25, ""##.###\%"")")
- TestUtil.AssertEqual(Format(12.25, "0.???"), "12.25 ", "Format(12.25, ""0.???"")")
+ ' tdf#158890 blank replaced by figure blank
+ TestUtil.AssertEqual(Format(12.25, "0.???"), "12.25 ", "Format(12.25, ""0.???"")")
Exit Sub
errorHandler:
diff --git a/basic/qa/vba_tests/formatpercent.vb b/basic/qa/vba_tests/formatpercent.vb
new file mode 100644
index 000000000000..0a8c551c27f1
--- /dev/null
+++ b/basic/qa/vba_tests/formatpercent.vb
@@ -0,0 +1,31 @@
+'
+' 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/.
+'
+
+Option VBASupport 1
+Option Explicit
+
+Function doUnitTest() As String
+ TestUtil.TestInit
+ verify_testFormatPercent
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Sub verify_testFormatPercent()
+ On Error GoTo errorHandler
+
+ TestUtil.AssertEqual(FormatPercent("12.2", 2, vbFalse, vbFalse, vbFalse), "1220.00%", "FormatPercent(""12.2"", 2, vbFalse, vbFalse, vbFalse)")
+ TestUtil.AssertEqual(FormatPercent("-.2", 2, vbTrue, vbFalse, vbFalse), "-20.00%", "FormatPercent(""-.2"", 20, vbTrue, vbFalse, vbFalse)")
+ TestUtil.AssertEqual(FormatPercent("-0.2", 2, vbFalse, vbFalse, vbFalse), "-20.00%", "FormatPercent(""-0.2"", 20, vbFalse, vbFalse, vbFalse)")
+ TestUtil.AssertEqual(FormatPercent("-0.2", -1, vbFalse, vbTrue, vbFalse), "(20.00)%", "FormatPercent(""-0.2"", -1, vbFalse, vbTrue, vbFalse)")
+ TestUtil.AssertEqual(FormatPercent("-0.2", -1, vbUseDefault, vbTrue, vbFalse), "(20.00)%", "FormatPercent(""-0.2"", -1, vbUseDefault, vbTrue, vbFalse)")
+ TestUtil.AssertEqual(FormatPercent("-12345678", -1, vbUseDefault, vbUseDefault, vbTrue), "-1,234,567,800.00%", "FormatPercent(""-12345678"", -1, vbUseDefault, vbUseDefault, vbTrue)")
+
+ Exit Sub
+errorHandler:
+ TestUtil.ReportErrorHandler("verify_testFormatPercent", Err, Error$, Erl)
+End Sub
diff --git a/basic/qa/vba_tests/instrrev.vb b/basic/qa/vba_tests/instrrev.vb
index 7d047fc74aa6..3849d60c5f7e 100644
--- a/basic/qa/vba_tests/instrrev.vb
+++ b/basic/qa/vba_tests/instrrev.vb
@@ -37,6 +37,13 @@ Sub verify_testInStrRev()
' This test should fail after tdf#110003 has been fixed.
TestUtil.AssertEqual(InStrRev("Straße", "s", -1, 1), 5, "InStrRev(""Straße"", ""s"", -1, 1)")
+ ' tdf#141474 keyword names need to match that of VBA
+ Const vbBinaryCompare = 0, vbTextCompare = 1
+ TestUtil.AssertEqual(InStrRev(stringMatch:="Star", stringCheck:="LibreOffice"), 0, "InStrRev(stringMatch:=""Star"", stringCheck:=""LibreOffice"")")
+ TestUtil.AssertEqual(InStrRev(Start:=-1, stringMatch:="Libre", stringCheck:="LibreOfficeLibre"), 12, "InStrRev(Start:=-1, stringMatch:=""Libre"", stringCheck:=""LibreOfficeLibre"")")
+ TestUtil.AssertEqual(InStrRev(Start:=12, stringMatch:="Libre", stringCheck:="LibreOfficeLibre"), 1, "InStrRev(Start:=12, stringMatch:=""Libre"", stringCheck:=""LibreOfficeLibre"")")
+ TestUtil.AssertEqual(InStrRev(Compare:=vbBinaryCompare, Start:=12, stringMatch:="Libre", stringCheck:="LibreOfficeLibre"), 1, "InStrRev(Compare:=vbBinaryCompare, Start:=12, stringMatch:=""Libre"", stringCheck:=""LibreOfficeLibre"")")
+
Exit Sub
errorHandler:
TestUtil.ReportErrorHandler("verify_testInStrRev", Err, Error$, Erl)
diff --git a/basic/qa/vba_tests/join.vb b/basic/qa/vba_tests/join.vb
index c4f568f812e1..8d6dd46dcd65 100644
--- a/basic/qa/vba_tests/join.vb
+++ b/basic/qa/vba_tests/join.vb
@@ -27,6 +27,11 @@ Sub verify_testJoin()
TestUtil.AssertEqual(Join(vaArray, "<>"), "string1<>string2<>string3", "Join(vaArray, ""<>"")")
TestUtil.AssertEqual(Join(vaArray, ""), "string1string2string3", "Join(vaArray, """")")
+ ' tdf#141474 keyword names need to match that of VBA
+ Dim aList(0 to 7) As String : aList = Array("(", "Star", "|", "Open", "|", "Libre", ")", "Office")
+ TestUtil.AssertEqual(Join(sourceArray:=aList), "( Star | Open | Libre ) Office", "Join() with 1 keyword name")
+ TestUtil.AssertEqual(Join(delimiter:="", sourceArray:=aList), "(Star|Open|Libre)Office", "Join() with 2 keyword names")
+
Exit Sub
errorHandler:
TestUtil.ReportErrorHandler("verify_testJoin", Err, Error$, Erl)
diff --git a/basic/qa/vba_tests/left.vb b/basic/qa/vba_tests/left.vb
index 047497ef0333..21ce3cefc6e0 100644
--- a/basic/qa/vba_tests/left.vb
+++ b/basic/qa/vba_tests/left.vb
@@ -22,6 +22,9 @@ Sub verify_testLeft()
TestUtil.AssertEqual(Left("sometext", 48), "sometext", "Left(""sometext"", 48)")
TestUtil.AssertEqual(Left("", 4), "", "Left("""", 4)")
+ ' tdf#141474 keyword names need to match that of VBA
+ TestUtil.AssertEqual(Left(Length:=4, String:="sometext"), "some", "Left(Length:=4, String:=""sometext"")")
+
Exit Sub
errorHandler:
TestUtil.ReportErrorHandler("verify_testLeft", Err, Error$, Erl)
diff --git a/basic/qa/vba_tests/like.vb b/basic/qa/vba_tests/like.vb
new file mode 100644
index 000000000000..c3be1e081b16
--- /dev/null
+++ b/basic/qa/vba_tests/like.vb
@@ -0,0 +1,42 @@
+'
+' 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/.
+'
+
+Option VBASupport 1
+Option Explicit
+
+Function doUnitTest() As String
+ TestUtil.TestInit
+ verify_testLike
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Sub verify_testLike()
+ On Error GoTo errorHandler
+ ' Negation test
+ TestUtil.AssertEqual("!" Like "[.!?]", True, "Negation1")
+ TestUtil.AssertEqual("a" Like "[!abc]", False, "Negation2")
+ TestUtil.AssertEqual("!" Like "[!!?]", False, "Negation3")
+ TestUtil.AssertEqual("^" Like "[.!?]", False, "Negation4")
+ TestUtil.AssertEqual("^" Like "[.^?]", True, "Negation5")
+ ' Like test from microsoft vba
+ TestUtil.AssertEqual("aBBBa" Like "a*a", True, "Like1")
+ TestUtil.AssertEqual("F" Like "[A-Z]", True, "Like2")
+ TestUtil.AssertEqual("F" Like "[!A-Z]", False, "Like3")
+ TestUtil.AssertEqual("a2a" Like "a#a", True, "Like4")
+ TestUtil.AssertEqual("aM5b" Like "a[L-P]#[!c-e]", True, "Like5")
+ TestUtil.AssertEqual("BAT123khg" Like "B?T*", True, "Like6")
+ TestUtil.AssertEqual("CAT123khg" Like "B?T*", False, "Like7")
+ TestUtil.AssertEqual("ab" Like "a*b", True, "Like8")
+ TestUtil.AssertEqual("a*b" Like "a [*]b", False, "Like9")
+ TestUtil.AssertEqual("axxxxxb" Like "a [*]b", False, "Like10")
+ TestUtil.AssertEqual("a [xyz" Like "a [[]*", True, "Like11")
+
+ Exit Sub
+errorHandler:
+ TestUtil.ReportErrorHandler("verify_testLike", Err, Error$, Erl)
+End Sub
diff --git a/basic/qa/vba_tests/mid.vb b/basic/qa/vba_tests/mid.vb
index 863e24784512..ebd326109f5d 100644
--- a/basic/qa/vba_tests/mid.vb
+++ b/basic/qa/vba_tests/mid.vb
@@ -22,6 +22,10 @@ Sub verify_testMid()
TestUtil.AssertEqual(Mid("Mid Function Demo", 14, 4), "Demo", "Mid(""Mid Function Demo"", 14, 4)")
TestUtil.AssertEqual(Mid("Mid Function Demo", 5), "Function Demo", "Mid(""Mid Function Demo"", 5)")
+ ' tdf#141474 keyword names need to match that of VBA
+ TestUtil.AssertEqual(Mid(start:=6, string:="LibreOffice" ), "Office", "Mid() with 2 keyword names" )
+ TestUtil.AssertEqual(Mid(length:=5, start:=1, string:="LibreOffice" ), "Libre", "Mid() with 3 keyword names" )
+
Exit Sub
errorHandler:
TestUtil.ReportErrorHandler("verify_testMid", Err, Error$, Erl)
diff --git a/basic/qa/vba_tests/ole_ObjAssignNoDflt.vb b/basic/qa/vba_tests/ole_ObjAssignNoDflt.vb
index b1a591b0c94d..9817aa7437dc 100644
--- a/basic/qa/vba_tests/ole_ObjAssignNoDflt.vb
+++ b/basic/qa/vba_tests/ole_ObjAssignNoDflt.vb
@@ -1,3 +1,11 @@
+'
+' 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/.
+'
+
Option VBASupport 1
Function doUnitTest(TestData as String, Driver as String) as String
Rem Ensure object assignment is by reference
diff --git a/basic/qa/vba_tests/ole_ObjAssignToNothing.vb b/basic/qa/vba_tests/ole_ObjAssignToNothing.vb
index d68664b41b72..9a0a557cdf31 100644
--- a/basic/qa/vba_tests/ole_ObjAssignToNothing.vb
+++ b/basic/qa/vba_tests/ole_ObjAssignToNothing.vb
@@ -1,3 +1,11 @@
+'
+' 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/.
+'
+
Option VBASupport 1
Function doUnitTest(TestData as String, Driver as String) as String
Rem Ensure object assignment is by reference
diff --git a/basic/qa/vba_tests/right.vb b/basic/qa/vba_tests/right.vb
index c7cb583724d1..742fc43c3b79 100644
--- a/basic/qa/vba_tests/right.vb
+++ b/basic/qa/vba_tests/right.vb
@@ -22,6 +22,9 @@ Sub verify_testRight()
TestUtil.AssertEqual(Right("sometext", 48), "sometext", "Right(""sometext"", 48)")
TestUtil.AssertEqual(Right("", 4), "", "Right("""", 4)")
+ ' tdf#141474 keyword names need to match that of VBA
+ TestUtil.AssertEqual(Right(Length:=4, String:="sometext"), "text", "Right(Length:=4, String:=""sometext"")")
+
Exit Sub
errorHandler:
TestUtil.ReportErrorHandler("verify_testRight", Err, Error$, Erl)
diff --git a/basic/qa/vba_tests/split.vb b/basic/qa/vba_tests/split.vb
index 56d4522180b0..13f4d66a9539 100644
--- a/basic/qa/vba_tests/split.vb
+++ b/basic/qa/vba_tests/split.vb
@@ -51,6 +51,12 @@ Sub verify_testSplit
' - Actual : 8200 (8192 for Array and 8 for String)
TestUtil.AssertEqual(VarType(splitArr(0)), 8, "VarType(splitArr(0))")
+ ' tdf#141474 keyword names need to match that of VBA
+ TestUtil.AssertEqual(Split(expression:="LibreOffice StarOffice")(1), "StarOffice", "Split with 1 keyword name" )
+ Dim txt As String : txt = "Libre_Office_Star_Office"
+ TestUtil.AssertEqual(Split(delimiter:="_", expression:=txt)(2), "Star", "Split with 2 keyword names" )
+ TestUtil.AssertEqual(Split(limit:=3, delimiter:="_", expression:=txt)(2), "Star_Office", "Split with 3 keyword names" )
+
Exit Sub
errorHandler:
TestUtil.ReportErrorHandler("verify_testSplit", Err, Error$, Erl)
diff --git a/basic/qa/vba_tests/strconv.vb b/basic/qa/vba_tests/strconv.vb
index b0295df428b2..9b7dfaf21866 100644
--- a/basic/qa/vba_tests/strconv.vb
+++ b/basic/qa/vba_tests/strconv.vb
@@ -18,25 +18,30 @@ End Function
Sub verify_testStrConv()
On Error GoTo errorHandler
- TestUtil.AssertEqual(StrConv("abc EFG hij", vbUpperCase), "ABC EFG HIJ", "StrConv(""abc EFG hij"", vbUpperCase)")
- TestUtil.AssertEqual(StrConv("abc EFG hij", vbLowerCase), "abc efg hij", "StrConv(""abc EFG hij"", vbLowerCase)")
- TestUtil.AssertEqual(StrConv("abc EFG hij", vbProperCase), "Abc Efg Hij", "StrConv(""abc EFG hij"", vbProperCase)")
+ TestUtil.AssertEqual(StrConv("abc EFG hij αβγ ΔΕΖ ηθι", vbUpperCase), "ABC EFG HIJ ΑΒΓ ΔΕΖ ΗΘΙ", "StrConv(""abc EFG hij αβγ ΔΕΖ ηθι"", vbUpperCase)")
+ TestUtil.AssertEqual(StrConv("abc EFG hij αβγ ΔΕΖ ηθι", vbLowerCase), "abc efg hij αβγ δεζ ηθι", "StrConv(""abc EFG hij αβγ ΔΕΖ ηθι"", vbLowerCase)")
+ TestUtil.AssertEqual(StrConv("abc EFG hij αβγ ΔΕΖ ηθι", vbProperCase), "Abc Efg Hij Αβγ Δεζ Ηθι", "StrConv(""abc EFG hij αβγ ΔΕΖ ηθι"", vbProperCase)")
' Converts narrow (single-byte) characters in string to wide
TestUtil.AssertEqual(StrConv("ABCDEVB¥ì¥¹¥­¥å©", vbWide), "ABCDEVB¥ì¥¹¥­¥å©", "StrConv(""ABCDEVB¥ì¥¹¥­¥å©"", vbWide)")
+ TestUtil.AssertEqual(StrConv("ABCDEVB¥ì¥¹¥­¥å©", vbWide + vbLowerCase), "abcdevb¥ì¥¹¥­¥å©", "StrConv(""ABCDEVB¥ì¥¹¥­¥å©"", vbWide + vbLowerCase)")
' Converts wide (double-byte) characters in string to narrow (single-byte) characters
TestUtil.AssertEqual(StrConv("ABCD@$%23'?EG", vbNarrow), "ABCD@$%23'?EG", "StrConv(""ABCD@$%23'?EG"", vbNarrow)")
+ TestUtil.AssertEqual(StrConv("ABCD@$%23'?EG", vbNarrow + vbLowerCase), "abcd@$%23'?eg", "StrConv(""ABCD@$%23'?EG"", vbNarrow + vbLowerCase)")
' Converts Hiragana characters in string to Katakana characters
TestUtil.AssertEqual(StrConv("かたかな", vbKatakana), "カタカナ", "StrConv(""かたかな"", vbKatakana)")
+ TestUtil.AssertEqual(StrConv("かたかな abc", vbKatakana + vbUpperCase + vbWide), "カタカナ ABC", "StrConv(""かたかな abc"", vbKatakana + vbUpperCase + vbWide)")
' Converts Katakana characters in string to Hiragana characters
TestUtil.AssertEqual(StrConv("カタカナ", vbHiragana), "かたかな", "StrConv(""カタカナ"", vbHiragana)")
+ TestUtil.AssertEqual(StrConv("カタカナ ABC", vbLowerCase + vbNarrow), "カタカナ abc", "StrConv(""カタカナ ABC"", vbLowerCase + vbNarrow)")
- ' Assumes CP-1252 encoding associated with en-US locale used in unit tests.
Dim x() As Byte
- x = StrConv("ÉϺ£ÊÐABC", vbFromUnicode)
+ Const Cp1252TestString = "ÉϺ£ÊÐABC"
+
+ x = StrConv(Cp1252TestString, vbFromUnicode, &h0409)' CP-1252 encoding associated with en-US locale
TestUtil.AssertEqual(UBound(x), 8, "UBound(x)")
TestUtil.AssertEqual(x(0), 201, "x(0)")
TestUtil.AssertEqual(x(1), 207, "x(1)")
@@ -47,7 +52,11 @@ Sub verify_testStrConv()
TestUtil.AssertEqual(x(6), 65, "x(6)")
TestUtil.AssertEqual(x(7), 66, "x(7)")
TestUtil.AssertEqual(x(8), 67, "x(8)")
- TestUtil.AssertEqual(StrConv(x, vbUnicode), "ÉϺ£ÊÐABC", "StrConv(x, vbUnicode)")
+ TestUtil.AssertEqual(StrConv(x, vbUnicode, &h0409), Cp1252TestString, "StrConv(x, vbUnicode, &h0409)")
+
+ x = StrConv(Cp1252TestString, vbUnicode, &h0409)
+ TestUtil.AssertEqual(UBound(x), 35, "UBound(x)")
+ TestUtil.AssertEqual(StrConv(x, vbFromUnicode, &h0409), Cp1252TestString, "StrConv(x, vbFromUnicode, &h0409)")
Exit Sub
errorHandler:
diff --git a/basic/qa/vba_tests/string.vb b/basic/qa/vba_tests/string.vb
index eca3fce3baec..239141d8173f 100644
--- a/basic/qa/vba_tests/string.vb
+++ b/basic/qa/vba_tests/string.vb
@@ -11,18 +11,22 @@ Option Explicit
Function doUnitTest() As String
TestUtil.TestInit
- verify_testString
+ verify_String
doUnitTest = TestUtil.GetResult()
End Function
-Sub verify_testString()
+Sub verify_String()
On Error GoTo errorHandler
TestUtil.AssertEqual(String(5, "P"), "PPPPP", "String(5, ""P"")")
TestUtil.AssertEqual(String(5, "a"), "aaaaa", "String(5, ""a"")")
TestUtil.AssertEqual(String(0, "P"), "", "String(0, ""P"")")
+ TestUtil.AssertEqual(String(5.8, "à"), "àààààà", "String(5.8, ""à"")")
+ TestUtil.AssertEqual(String(Number:=3.45, Character:="test"), "ttt", "String(Number:=3.45, Character:=""test"")")
+ TestUtil.AssertEqual(String(Character:="☺😎", Number:=7), "☺☺☺☺☺☺☺", "String(Character:=""☺😎"", Number:=7)")
+
Exit Sub
errorHandler:
- TestUtil.ReportErrorHandler("verify_testString", Err, Error$, Erl)
+ TestUtil.ReportErrorHandler("verify_String", Err, Error$, Erl)
End Sub
diff --git a/basic/qa/vba_tests/tdf147089_idiv.vb b/basic/qa/vba_tests/tdf147089_idiv.vb
new file mode 100644
index 000000000000..515f1e00cf63
--- /dev/null
+++ b/basic/qa/vba_tests/tdf147089_idiv.vb
@@ -0,0 +1,31 @@
+'
+' 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/.
+'
+
+Option VBASupport 1
+Option Explicit
+
+Function doUnitTest() As String
+ TestUtil.TestInit
+ verify_testIDiv
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Sub verify_testIDiv
+ On Error GoTo errorHandler
+
+ ' tdf#147089 - IDIV operands are rounded to Integer values before the operation is performed
+ TestUtil.AssertEqual(8.4 \ 2, 4, "8.4 \ 2")
+ TestUtil.AssertEqual(9.9 \ 2, 5, "9.9 \ 2")
+ TestUtil.AssertEqual(20 \ 4.9, 4, "20 \ 4.9")
+ TestUtil.AssertEqual(20 \ 4.4, 5, "20 \ 4.4")
+ TestUtil.AssertEqual(16.4 \ 5.9, 2, "16.4 \ 5.9")
+
+ Exit Sub
+errorHandler:
+ TestUtil.ReportErrorHandler("verify_testIDiv", Err, Error$, Erl)
+End Sub
diff --git a/basic/qa/vba_tests/tdf147529_optional_parameters_msgbox.vb b/basic/qa/vba_tests/tdf147529_optional_parameters_msgbox.vb
new file mode 100644
index 000000000000..e599f46eedf1
--- /dev/null
+++ b/basic/qa/vba_tests/tdf147529_optional_parameters_msgbox.vb
@@ -0,0 +1,37 @@
+'
+' 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/.
+'
+
+Option VBASupport 1
+Option Explicit
+
+Function doUnitTest() As String
+ TestUtil.TestInit
+ verify_testOptionalParametersMsgBox
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Sub verify_testOptionalParametersMsgBox
+ On Error GoTo errorHandler
+
+ ' tdf#147529 - check for missing optional parameters
+ TestUtil.AssertEqual(TestOptionalParametersMsgBox(), True, "TestOptionalParametersMsgBox()")
+
+ Exit Sub
+errorHandler:
+ TestUtil.ReportErrorHandler("verify_testOptionalParametersMsgBox", Err, Error$, Erl)
+End Sub
+
+Function TestOptionalParametersMsgBox(Optional text, Optional dialogType, Optional dialogTitle) As Boolean
+On Error GoTo errorHandler
+ MsgBox text, dialogType, dialogTitle
+ TestOptionalParametersMsgBox = False
+ Exit Function
+errorHandler:
+ TestUtil.AssertEqual(Err, 449, "Argument not optional (Error 449)")
+ TestOptionalParametersMsgBox = True
+End Function
diff --git a/basic/qa/vba_tests/tdf148358_non_ascii_names.vb b/basic/qa/vba_tests/tdf148358_non_ascii_names.vb
new file mode 100644
index 000000000000..95e7105407f5
--- /dev/null
+++ b/basic/qa/vba_tests/tdf148358_non_ascii_names.vb
@@ -0,0 +1,33 @@
+'
+' 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/.
+'
+
+Option VBASupport 1
+Option Explicit
+
+Function doUnitTest as String
+ TestUtil.TestInit
+ verify_testNonAsciiNames
+ doUnitTest = TestUtil.GetResult()
+End Function
+
+Function TestNonAscii as Integer
+ Dim Абв as Integer
+ Абв = 10
+ TestNonAscii = абв
+End Function
+
+Sub verify_testNonAsciiNames
+ On Error GoTo errorHandler
+
+ ' tdf#148358 - compare Non-ASCII variable names case-insensitive
+ TestUtil.AssertEqual(TestNonAscii(), 10, "TestNonAscii()")
+
+ Exit Sub
+errorHandler:
+ TestUtil.ReportErrorHandler("verify_testNonAsciiNames", Err, Error$, Erl)
+End Sub
diff --git a/basic/qa/vba_tests/typename.vb b/basic/qa/vba_tests/typename.vb
index 98bfd58feda4..b21d34cc4e0e 100644
--- a/basic/qa/vba_tests/typename.vb
+++ b/basic/qa/vba_tests/typename.vb
@@ -32,6 +32,8 @@ Sub verify_testTypeName()
Dim TestCurrSign@
Dim TestStrSign$
+ TestUtil.AssertEqual(TypeName(varname:=s1), "String", "TypeName(varname:=s1")
+
TestUtil.AssertEqual(TypeName(s1), "String", "TypeName(s1)")
TestUtil.AssertEqual(TypeName(b1), "Boolean", "TypeName(b1)")
TestUtil.AssertEqual(TypeName(c1), "Byte", "TypeName(c1)")
diff --git a/basic/qa/vba_tests/vartype.vb b/basic/qa/vba_tests/vartype.vb
index 2d8345ed1d86..066255b2b7e3 100644
--- a/basic/qa/vba_tests/vartype.vb
+++ b/basic/qa/vba_tests/vartype.vb
@@ -42,6 +42,8 @@ Sub verify_testVarType()
TestUtil.AssertEqual(vbString, 8, "vbString")
TestUtil.AssertEqual(vbBoolean, 11, "vbBoolean")
+ TestUtil.AssertEqual(VarType(varname:=TestStr), vbString, "VarType(varname:=TestStr)")
+
TestUtil.AssertEqual(VarType(TestStr), vbString, "VarType(TestStr)")
TestUtil.AssertEqual(VarType(TestBoo), vbBoolean, "VarType(TestBoo)")
TestUtil.AssertEqual(VarType(TestDouble), vbDouble, "VarType(TestDouble)")
diff --git a/basic/source/basmgr/basicmanagerrepository.cxx b/basic/source/basmgr/basicmanagerrepository.cxx
index 3a0405f472d0..525482d8dbae 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>
@@ -284,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()) +
@@ -299,7 +300,7 @@ 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
@@ -381,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 );
@@ -429,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() )
@@ -461,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 );
diff --git a/basic/source/basmgr/basmgr.cxx b/basic/source/basmgr/basmgr.cxx
index 4dadf17d8f3f..72b6f0de5ddf 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,8 @@
#include <com/sun/star/script/XLibraryContainer.hpp>
#include <com/sun/star/script/XPersistentLibraryContainer.hpp>
+#include <scriptcont.hxx>
+
#include <memory>
#include <vector>
@@ -84,12 +88,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 +110,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 +300,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 +421,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 )
{
@@ -565,7 +566,7 @@ void BasicManager::SetLibraryContainerInfo( const LibraryContainerInfo& rInfo )
copyToLibraryContainer( pLib, maContainerInfo );
if (rpBasLibInfo->HasPassword())
{
- OldBasicPassword* pOldBasicPassword =
+ basic::SfxScriptLibraryContainer* pOldBasicPassword =
maContainerInfo.mpOldBasicPassword;
if( pOldBasicPassword )
{
@@ -605,8 +606,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 +630,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 +648,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 +724,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 +746,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 +777,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 +796,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 +838,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 +861,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 +897,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 +1081,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 +1093,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 +1112,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()))
{
@@ -1251,8 +1252,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 +1286,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 +1367,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 );
+ if (pOldValue)
+ {
+ // obtain the old value
+ SbxVariable* pVariable = pStandardLib->Find( rName, SbxClassType::Object );
+ if ( pVariable )
+ *pOldValue = sbxToUnoValue( pVariable );
+ }
SbxObjectRef xUnoObj = GetSbUnoObject( _rValue.getValueType ().getTypeName () , _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 +1406,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 +1534,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 +1570,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 +1589,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 +1612,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
@@ -1732,7 +1729,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("types do not match", getXWeak(), 2);
}
uno::Reference< script::XStarBasicModuleInfo > xMod;
aElement >>= xMod;
@@ -1896,7 +1893,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("types do not match", getXWeak(), 2);
}
uno::Reference< script::XStarBasicDialogInfo > xMod;
aElement >>= xMod;
diff --git a/basic/source/classes/eventatt.cxx b/basic/source/classes/eventatt.cxx
index 6489d88d8339..6cf371f3869a 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;
@@ -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 );
diff --git a/basic/source/classes/image.cxx b/basic/source/classes/image.cxx
index 229dc8058518..eafb129894ab 100644
--- a/basic/source/classes/image.cxx
+++ b/basic/source/classes/image.cxx
@@ -124,11 +124,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 )
@@ -373,31 +373,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 +411,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?
@@ -468,7 +440,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 +551,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;
}
@@ -606,7 +579,7 @@ void SbiImage::AddString( const OUString& r )
memcpy( pStrings.get() + nStringOff, r.getStr(), len * sizeof( sal_Unicode ) );
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 +616,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 +688,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..f9eacc3d1298 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,7 +129,7 @@ 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("m_aPropVals not empty", getXWeak(), -1);
for (const PropertyValue& i : rPropertyValues)
{
@@ -157,26 +150,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..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>
@@ -47,9 +48,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 +55,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;
@@ -746,7 +744,7 @@ SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule )
}
}
SetModuleType( ModuleType::CLASS );
- mbVBACompat = pClassModule->mbVBACompat;
+ mbVBASupport = pClassModule->mbVBASupport;
}
SbClassModuleObject::~SbClassModuleObject()
@@ -758,8 +756,8 @@ SbClassModuleObject::~SbClassModuleObject()
if( !pDocBasicItem->isDocClosed() )
triggerTerminateEvent();
- // prevent the base class destructor from deleting these because
- // we do not actually own them
+ // prevent the base class destructor from deleting this because:
+ // coverity[leaked_storage] - we do not actually own it
pImage.release();
pBreaks = nullptr;
}
@@ -903,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
@@ -942,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 )
@@ -1076,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() );
}
@@ -1308,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 ) )
{
@@ -1327,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;
}
@@ -1431,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:
@@ -1533,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();
@@ -1588,9 +1586,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 +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() )
@@ -1653,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
@@ -1663,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 );
@@ -1682,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 )
@@ -1854,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 )
@@ -1894,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)
- static const OUStringLiteral sThisComponent( u"ThisComponent");
+ static constexpr OUStringLiteral sThisComponent( u"ThisComponent");
SbxVariable* pThisComponent = nullptr;
SbxObject* pLookup = pBasic->GetParent();
@@ -1941,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);
@@ -2070,26 +2074,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 +2184,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 +2208,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 999972c94744..5fea3f14179f 100644
--- a/basic/source/classes/sbunoobj.cxx
+++ b/basic/source/classes/sbunoobj.cxx
@@ -20,8 +20,10 @@
#include <sal/config.h>
#include <o3tl/any.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>
@@ -98,9 +100,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[] = "[]";
@@ -967,6 +969,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;
@@ -1047,19 +1055,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;
}
@@ -1533,7 +1532,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]);
}
@@ -1606,9 +1605,7 @@ static OUString getDbgObjectName(SbUnoObject& rUnoObj)
{
aRet.append( "\n" );
}
- aRet.append( "\"" );
- aRet.append( aName );
- aRet.append( "\":" );
+ aRet.append( "\"" + aName + "\":" );
return aRet.makeStringAndClear();
}
@@ -1740,16 +1737,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
@@ -1770,9 +1767,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" );
}
}
}
@@ -1828,9 +1825,7 @@ 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();
@@ -1888,8 +1883,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" );
@@ -1905,9 +1899,7 @@ 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();
@@ -1954,10 +1946,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();
@@ -2051,7 +2041,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() );
}
@@ -2311,12 +2301,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() )
{
@@ -2324,6 +2311,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;
@@ -2436,11 +2424,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();
@@ -2455,8 +2443,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 )
@@ -2469,7 +2457,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;
@@ -2481,7 +2469,7 @@ void clearUnoMethodsForBasic( StarBASIC const * pBasic )
void clearUnoMethods()
{
- SbUnoMethod* pMeth = pFirst;
+ SbUnoMethod* pMeth = s_pFirst;
while( pMeth )
{
pMeth->SbxValue::Clear();
@@ -2504,9 +2492,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;
}
@@ -2515,8 +2503,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 )
@@ -2565,13 +2553,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 )
@@ -2755,15 +2743,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() );
}
@@ -3271,14 +3259,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;
@@ -3783,7 +3771,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;
@@ -3795,8 +3783,8 @@ public:
}
-BasicAllListener_Impl::BasicAllListener_Impl(const OUString& aPrefixName_)
- : aPrefixName( aPrefixName_ )
+BasicAllListener_Impl::BasicAllListener_Impl(OUString aPrefixName_)
+ : aPrefixName(std::move( aPrefixName_ ))
{
}
@@ -3881,7 +3869,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;
@@ -3922,10 +3910,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 ))
{
}
@@ -3972,7 +3960,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;
@@ -4125,9 +4113,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;
@@ -4298,17 +4285,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 );
@@ -4343,7 +4326,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?
@@ -4631,7 +4614,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 +4662,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 +4701,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 +4723,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 +4741,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 +4774,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 +4896,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 2d38de16dcfd..59eb93f665c4 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("DocObjectWrapper::invoke - Could not get the method reference!");
// check number of parameters
sal_Int32 nParamsCount = aParams.getLength();
SbxInfo* pInfo = pMethod->GetInfo();
@@ -415,9 +416,9 @@ 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 )
+SbModule::SbModule( const OUString& rName, bool bVBASupport )
: SbxObject( "StarBASICModule" ),
- pBreaks(nullptr), mbVBACompat( bVBACompat ), bIsProxyModule( false )
+ pBreaks(nullptr), mbVBASupport(bVBASupport), mbCompat(bVBASupport), bIsProxyModule(false)
{
SetName( rName );
SetFlag( SbxFlagBits::ExtSearch | SbxFlagBits::GlobalSearch );
@@ -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 );
}
}
@@ -915,8 +917,8 @@ 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
@@ -973,15 +975,16 @@ 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" );
@@ -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
@@ -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;
@@ -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 )
@@ -1607,7 +1606,7 @@ bool SbModule::LoadData( SvStream& rStrm, sal_uInt16 nVer )
return false;
}
// If the image is in old format, we fix up the method start offsets
- if ( nImgVer < B_EXT_IMG_VERSION )
+ if ( nImgVer < B_IMG_VERSION_12 )
{
fixUpMethodStart( false, p.get() );
p->ReleaseLegacyBuffer();
@@ -1632,14 +1631,14 @@ bool SbModule::LoadData( SvStream& rStrm, sal_uInt16 nVer )
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 +1650,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 +1663,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 {
@@ -1736,7 +1735,7 @@ void SbModule::GetCodeCompleteDataFromParse(CodeCompleteDataCache& aCache)
}
-OUString SbModule::GetKeywordCase( const OUString& sKeyword )
+OUString SbModule::GetKeywordCase( std::u16string_view sKeyword )
{
return SbiParser::GetKeywordCase( sKeyword );
}
@@ -1768,7 +1767,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 +1776,7 @@ void SbModule::StoreBinaryData( SvStream& rStrm )
pImage->aName = GetName();
rStrm.WriteUChar(1);
- pImage->Save(rStrm);
+ pImage->Save(rStrm, nVersion);
pImage->aOUSource = aOUSource;
}
@@ -1917,15 +1917,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 +2008,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 +2033,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 +2071,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 );
@@ -2149,7 +2161,7 @@ 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 );
@@ -2206,8 +2218,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 +2389,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 )
@@ -2500,7 +2513,7 @@ void SbUserFormModule::triggerResizeEvent()
SbUserFormModuleInstance* SbUserFormModule::CreateInstance()
{
- SbUserFormModuleInstance* pInstance = new SbUserFormModuleInstance( this, GetName(), m_mInfo, IsVBACompat() );
+ SbUserFormModuleInstance* pInstance = new SbUserFormModuleInstance( this, GetName(), m_mInfo, IsVBASupport() );
return pInstance;
}
@@ -2610,9 +2623,9 @@ 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 ) ) );
diff --git a/basic/source/comp/buffer.cxx b/basic/source/comp/buffer.cxx
index ff6b5173f3fd..06dafe7a21d7 100644
--- a/basic/source/comp/buffer.cxx
+++ b/basic/source/comp/buffer.cxx
@@ -49,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);
}
diff --git a/basic/source/comp/codegen.cxx b/basic/source/comp/codegen.cxx
index e2f675a369de..9f2f4960bf9a 100644
--- a/basic/source/comp/codegen.cxx
+++ b/basic/source/comp/codegen.cxx
@@ -31,6 +31,7 @@
#include <algorithm>
#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
@@ -200,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/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..989f1c6330c5 100644
--- a/basic/source/comp/exprtree.cxx
+++ b/basic/source/comp/exprtree.cxx
@@ -719,7 +719,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 +733,6 @@ std::unique_ptr<SbiExprNode> SbiExpression::Comp()
}
eTok = pParser->Next();
pNd = std::make_unique<SbiExprNode>( std::move(pNd), eTok, Cat() );
- nCount++;
}
}
return pNd;
diff --git a/basic/source/comp/loops.cxx b/basic/source/comp/loops.cxx
index 07aac44943a6..2a756b6fb3a5 100644
--- a/basic/source/comp/loops.cxx
+++ b/basic/source/comp/loops.cxx
@@ -210,6 +210,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 )
diff --git a/basic/source/comp/parser.cxx b/basic/source/comp/parser.cxx
index 777db4071615..97bd27675fa8 100644
--- a/basic/source/comp/parser.cxx
+++ b/basic/source/comp/parser.cxx
@@ -145,7 +145,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();
@@ -818,9 +818,9 @@ 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;
}
@@ -849,6 +849,15 @@ 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, "vbHide", 0);
+ addNumericConst(aPublics, "vbNormalFocus", 1);
+ addNumericConst(aPublics, "vbMinimizedFocus", 2);
+ addNumericConst(aPublics, "vbMaximizedFocus", 3);
+ addNumericConst(aPublics, "vbNormalNoFocus", 4);
+ addNumericConst(aPublics, "vbMinimizedNoFocus", 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);
diff --git a/basic/source/comp/scanner.cxx b/basic/source/comp/scanner.cxx
index a0d9b9ab6c76..820951889ad7 100644
--- a/basic/source/comp/scanner.cxx
+++ b/basic/source/comp/scanner.cxx
@@ -27,9 +27,12 @@
#include <svl/numformat.hxx>
#include <svl/zforlist.hxx>
#include <rtl/character.hxx>
+#include <o3tl/string_view.hxx>
+#include <utility>
+#include <vector>
-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 +56,7 @@ SbiScanner::SbiScanner(const OUString& rBuf, StarBASIC* p)
, bVBASupportOn(false)
, bPrevLineExtentsComment(false)
, bClosingUnderscore(false)
+ , bLineEndsWithWhitespace(false)
, bInStatement(false)
{
}
@@ -160,8 +164,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 +190,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 +210,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 const std::vector<std::u16string_view> validDirectives = {
+ u"if", u"elseif", u"else", u"end", u"const"
+ };
+
+ return std::any_of(validDirectives.begin(), validDirectives.end(), [&](const auto& valid) {
+ return o3tl::matchIgnoreAsciiCase(directive, valid);
+ });
+}
+
bool SbiScanner::NextSym()
{
// memorize for the EOLN-case
@@ -215,7 +232,6 @@ bool SbiScanner::NextSym()
eScanType = SbxVARIANT;
aSym.clear();
bHash = bSymbol = bNumber = bSpaces = false;
- bool bCompilerDirective = false;
// read in line?
if (nLineIdx == -1)
@@ -251,6 +267,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 +279,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 +684,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 +731,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..6caa3b2ed3d3 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
@@ -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),
diff --git a/basic/source/comp/token.cxx b/basic/source/comp/token.cxx
index 9be47bf41ba1..814d5488f8ee 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>
@@ -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 e56d60b6c615..5c555d74c089 100644
--- a/basic/source/inc/buffer.hxx
+++ b/basic/source/inc/buffer.hxx
@@ -21,7 +21,7 @@
#include <rtl/ustring.hxx>
#include <sal/types.h>
-#include <vcl/errcode.hxx>
+#include <comphelper/errcode.hxx>
#include <vector>
// Stores all numbers big endian
diff --git a/basic/source/inc/dlgcont.hxx b/basic/source/inc/dlgcont.hxx
index 58d1dbeb65f4..e66a23701759 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();
@@ -108,7 +108,7 @@ public:
SfxDialogLibrary
(
ModifiableHelper& _rModifiable,
- const OUString& aName,
+ OUString aName,
const css::uno::Reference< css::ucb::XSimpleFileAccess3 >& xSFI,
SfxDialogLibraryContainer* pParent
);
@@ -116,7 +116,7 @@ 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
diff --git a/basic/source/inc/expr.hxx b/basic/source/inc/expr.hxx
index 93f344e89fac..d1e7fbcfa25d 100644
--- a/basic/source/inc/expr.hxx
+++ b/basic/source/inc/expr.hxx
@@ -85,6 +85,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 +133,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 +224,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/namecont.hxx b/basic/source/inc/namecont.hxx
index 5635c91144e0..4db38ac881a4 100644
--- a/basic/source/inc/namecont.hxx
+++ b/basic/source/inc/namecont.hxx
@@ -37,32 +37,34 @@
#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/interfacecontainer4.hxx>
#include <xmlscript/xmllib_imexp.hxx>
class BasicManager;
namespace basic
{
-typedef ::cppu::WeakImplHelper<
+typedef ::comphelper::WeakImplHelper<
css::container::XNameContainer,
css::container::XContainer,
css::util::XChangesNotifier > NameContainer_BASE;
-class NameContainer final : public ::cppu::BaseMutex, public NameContainer_BASE
+class NameContainer final : public NameContainer_BASE
{
typedef std::unordered_map < OUString, sal_Int32 > NameContainerNameMap;
@@ -74,16 +76,14 @@ class NameContainer final : public ::cppu::BaseMutex, public NameContainer_BASE
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 )
, mType( rType )
, mpxEventSource( nullptr )
- , maContainerListeners( m_aMutex )
- , maChangesListeners( m_aMutex )
{}
void setEventSource( css::uno::XInterface* pxEventSource )
@@ -170,7 +170,8 @@ 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
@@ -181,6 +182,7 @@ class SfxLibraryContainer
sal_Int32 mnRunningVBAScripts;
bool mbVBACompat;
OUString msProjectName;
+ rtl_TextEncoding meVBATextEncoding;
protected:
css::uno::Reference< css::uno::XComponentContext > mxContext;
css::uno::Reference< css::ucb::XSimpleFileAccess3 > mxSFI;
@@ -221,7 +223,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 );
@@ -231,7 +233,7 @@ 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,
@@ -294,10 +296,10 @@ protected:
void init( const OUString& rInitialDocumentURL,
const css::uno::Reference< css::embed::XStorage >& _rxInitialStorage );
- 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
@@ -328,6 +330,7 @@ private:
void init_Impl( const OUString& rInitialDocumentURL,
const css::uno::Reference< css::embed::XStorage >& _rxInitialStorage );
void implScanExtensions();
+ static constexpr OUString sVBATextEncodingPropName = u"VBATextEncoding"_ustr;
public:
SfxLibraryContainer();
@@ -423,6 +426,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;
+
};
@@ -445,8 +468,7 @@ class SfxLibrary
: public css::container::XNameContainer
, public css::container::XContainer
, public css::util::XChangesNotifier
- , public ::cppu::BaseMutex
- , public ::cppu::OComponentHelper
+ , public ::comphelper::WeakComponentImplHelper<>
{
friend class SfxLibraryContainer;
friend class SfxDialogLibraryContainer;
@@ -519,15 +541,15 @@ 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(); }
+ virtual void SAL_CALL acquire() noexcept override { WeakComponentImplHelper::acquire(); }
+ virtual void SAL_CALL release() noexcept override { WeakComponentImplHelper::release(); }
// Methods XElementAccess
virtual css::uno::Type SAL_CALL getElementType( ) override;
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 06f0bd8b0c30..002359435749 100644
--- a/basic/source/inc/rtlproto.hxx
+++ b/basic/source/inc/rtlproto.hxx
@@ -72,6 +72,7 @@ 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_IDIGNORE(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);
@@ -200,7 +201,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 +232,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..662a7d696859 100644
--- a/basic/source/inc/runtime.hxx
+++ b/basic/source/inc/runtime.hxx
@@ -32,12 +32,14 @@
#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
@@ -99,8 +101,6 @@ namespace o3tl
template<> struct typed_flags<SbAttributes> : is_typed_flags<SbAttributes, 0x13> {};
}
-class WildCard;
-
class SbiRTLData
{
public:
@@ -110,7 +110,7 @@ public:
short nCurDirPos;
OUString sFullNameToBeChecked;
- std::unique_ptr<WildCard> pWildCard;
+ std::optional<WildCard> moWildCard;
css::uno::Sequence< OUString > aDirSeq;
@@ -188,7 +188,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 +226,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 +348,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 fe897ab6bcd6..ae18e0f9e30b 100644
--- a/basic/source/inc/sbintern.hxx
+++ b/basic/source/inc/sbintern.hxx
@@ -21,9 +21,11 @@
#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
{
@@ -105,15 +107,15 @@ struct SbiGlobals
static SbiGlobals* pGlobals;
SbiInstance* pInst; // all active runtime instances
#if HAVE_FEATURE_SCRIPTING
- std::unique_ptr<SbiFactory> pSbFac; // StarBASIC-Factory
- std::unique_ptr<SbUnoFactory> pUnoFac; // Factory for Uno-Structs at DIM AS NEW
- std::unique_ptr<SbTypeFactory>
+ 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
@@ -122,7 +124,7 @@ struct SbiGlobals
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
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..4dee669219ef 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,7 +194,7 @@ 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
@@ -217,9 +219,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 +246,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 +295,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 +352,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 +374,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..2d0e8bcf3232 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;
@@ -75,13 +75,10 @@ class SfxScriptLibraryContainer final : public SfxLibraryContainer, public OldBa
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,6 +96,9 @@ 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 );
};
diff --git a/basic/source/inc/stdobj.hxx b/basic/source/inc/stdobj.hxx
index 18df1fbbdda7..824cb90ea1a2 100644
--- a/basic/source/inc/stdobj.hxx
+++ b/basic/source/inc/stdobj.hxx
@@ -20,13 +20,14 @@
#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;
diff --git a/basic/source/inc/symtbl.hxx b/basic/source/inc/symtbl.hxx
index b8a2f6ebbaad..56f68d4fe882 100644
--- a/basic/source/inc/symtbl.hxx
+++ b/basic/source/inc/symtbl.hxx
@@ -107,7 +107,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.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 7d49ba1bdcdb..2a03e2ae7855 100644
--- a/basic/source/runtime/dllmgr-none.cxx
+++ b/basic/source/runtime/dllmgr-none.cxx
@@ -106,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/iosys.cxx b/basic/source/runtime/iosys.cxx
index 705905acfce7..015ed8abc29b 100644
--- a/basic/source/runtime/iosys.cxx
+++ b/basic/source/runtime/iosys.cxx
@@ -37,14 +37,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 {
@@ -562,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 );
}
}
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index 2361466ea5e3..4dfcdc210ea3 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -27,7 +27,7 @@
#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>
@@ -59,6 +59,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>
@@ -67,19 +68,12 @@
#include <o3tl/char16_t2wchar_t.hxx>
// include search util
+#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,6 +103,14 @@ using namespace com::sun::star::uno;
#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 void FilterWhiteSpace( OUString& rStr )
@@ -132,8 +134,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() );
@@ -181,16 +181,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 )
@@ -198,54 +199,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)
- {
- 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())
+ nCode = rPar.Get(1)->GetLong();
+ if( nCode > 65535 )
{
- 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
@@ -253,106 +251,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()));
- }
+ 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)
@@ -392,22 +371,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 ];
@@ -417,14 +395,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
@@ -436,20 +410,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;
};
@@ -459,18 +429,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());
}
}
@@ -478,9 +444,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 );
}
@@ -529,129 +493,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 ) );
}
}
@@ -669,16 +623,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();
@@ -701,8 +653,7 @@ void SbRtl_RmDir(StarBASIC *, SbxArray & rPar, bool)
{
if( !xSFI->isFolder( aPath ) )
{
- StarBASIC::Error( ERRCODE_BASIC_PATH_NOT_FOUND );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_PATH_NOT_FOUND );
}
SbiInstance* pInst = GetSbData()->pInst;
bool bCompatibility = ( pInst && pInst->IsCompatibility() );
@@ -711,8 +662,7 @@ void SbRtl_RmDir(StarBASIC *, SbxArray & rPar, bool)
Sequence< OUString > aContent = xSFI->getFolderContents( aPath, true );
if( aContent.hasElements() )
{
- StarBASIC::Error( ERRCODE_BASIC_ACCESS_ERROR );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_ACCESS_ERROR );
}
}
@@ -744,72 +694,65 @@ 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)
@@ -919,78 +862,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);
}
@@ -1004,110 +945,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);
}
@@ -1159,8 +1076,7 @@ void SbRtl_Mid(StarBASIC *, SbxArray & rPar, bool bWrite)
bool bCompatibility = ( pInst && pInst->IsCompatibility() );
if( bCompatibility )
{
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
nStartPos = nArgLen;
}
@@ -1220,23 +1136,14 @@ void SbRtl_Mid(StarBASIC *, SbxArray & rPar, bool bWrite)
void SbRtl_Oct(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- char aBuffer[16];
- SbxVariableRef pArg = rPar.Get(1);
- if ( pArg->IsInteger() )
- {
- snprintf( aBuffer, sizeof(aBuffer), "%o", pArg->GetInteger() );
- }
- else
- {
- snprintf( aBuffer, sizeof(aBuffer), "%lo", static_cast<long unsigned int>(pArg->GetLong()) );
- }
- rPar.Get(0)->PutString(OUString::createFromAscii(aBuffer));
- }
+ 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]]])
@@ -1245,10 +1152,7 @@ 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)
@@ -1259,10 +1163,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)
@@ -1273,8 +1177,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);
}
}
@@ -1298,66 +1201,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& rStr = rPar.Get(1)->GetOUString();
+ int nResultLen = rPar.Get(2)->GetLong();
+ if( nResultLen < 0 )
{
+ nResultLen = 0;
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
- else
+ int nStrLen = rStr.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 = rStr.copy( nStrLen - nResultLen );
+ rPar.Get(0)->PutString(aResultStr);
}
void SbRtl_RTL(StarBASIC * pBasic, SbxArray & rPar, bool)
@@ -1368,53 +1279,31 @@ 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)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- }
- else
- {
- 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);
- }
-}
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
-void SbRtl_Space(StarBASIC *, SbxArray & rPar, bool)
-{
- if (rPar.Count() < 2)
+ 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 )
{
- OUStringBuffer aBuf;
- string::padToLength(aBuf, rPar.Get(1)->GetLong(), ' ');
- rPar.Get(0)->PutString(aBuf.makeStringAndClear());
+ nResult = -1;
}
+ rPar.Get(0)->PutInteger(nResult);
}
-void SbRtl_Spc(StarBASIC *, SbxArray & rPar, bool)
+void SbRtl_Space(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
{
@@ -1422,8 +1311,9 @@ void SbRtl_Spc(StarBASIC *, SbxArray & rPar, bool)
}
else
{
- OUStringBuffer aBuf;
- string::padToLength(aBuf, rPar.Get(1)->GetLong(), ' ');
+ const sal_Int32 nCount = rPar.Get(1)->GetLong();
+ OUStringBuffer aBuf(nCount);
+ string::padToLength(aBuf, nCount, ' ');
rPar.Get(0)->PutString(aBuf.makeStringAndClear());
}
}
@@ -1609,8 +1499,9 @@ void SbRtl_Tab(StarBASIC *, SbxArray & rPar, bool)
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
else
{
- OUStringBuffer aStr;
- comphelper::string::padToLength(aStr, rPar.Get(1)->GetLong(), '\t');
+ 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());
}
}
@@ -1703,9 +1594,8 @@ void SbRtl_Val(StarBASIC *, SbxArray & rPar, bool)
// 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() );
@@ -1714,9 +1604,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;
@@ -1748,8 +1637,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))));
@@ -1760,8 +1648,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()));
@@ -1795,8 +1682,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))));
@@ -1807,8 +1693,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()));
@@ -1851,8 +1736,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))));
@@ -1863,8 +1747,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()));
@@ -1933,7 +1816,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
@@ -1943,9 +1826,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
{
@@ -1956,9 +1839,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))
@@ -1966,8 +1849,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;
@@ -1989,8 +1872,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();
@@ -2007,8 +1889,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 )
@@ -2021,8 +1902,7 @@ 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
@@ -2353,176 +2233,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;
+ ErrCode nPrevError = SbxBase::GetError();
+ SbxBase::ResetError();
- if( eType == SbxDATE )
- {
- bDate = true;
- }
- else if( eType == SbxSTRING )
- {
- 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
@@ -2533,7 +2381,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;
@@ -2587,7 +2435,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;
}
@@ -2596,15 +2444,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;
@@ -2956,8 +2804,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 );
@@ -3124,8 +2971,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();
@@ -3165,8 +3011,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)
@@ -3194,8 +3039,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;
@@ -3239,8 +3083,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();
@@ -3255,16 +3098,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();
@@ -3283,8 +3124,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 );
@@ -3320,14 +3160,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
@@ -3338,8 +3198,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;
@@ -3362,8 +3221,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);
}
}
@@ -3380,8 +3238,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);
}
}
@@ -3398,53 +3255,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 {
@@ -3475,7 +3338,11 @@ struct RandomNumberGenerator
}
};
-class theRandomNumberGenerator : public rtl::Static<RandomNumberGenerator, theRandomNumberGenerator> {};
+RandomNumberGenerator& theRandomNumberGenerator()
+{
+ static RandomNumberGenerator theGenerator;
+ return theGenerator;
+}
}
@@ -3488,7 +3355,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
}
@@ -3502,7 +3369,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);
}
}
@@ -3740,7 +3607,7 @@ OUString getBasicTypeName( SbxDataType eType )
};
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;
@@ -3857,8 +3724,7 @@ 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();
@@ -3900,8 +3766,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();
@@ -3917,8 +3782,7 @@ 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();
@@ -3941,8 +3805,7 @@ 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();
@@ -3960,8 +3823,7 @@ 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();
@@ -3979,8 +3841,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;
@@ -4001,56 +3862,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;
@@ -4099,31 +3946,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(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)
@@ -4131,127 +4008,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
+ if (nConversion == ooo::vba::VbStrConv::vbFromUnicode) // This mode does not combine
{
- 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 )
- {
- 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())
+ {
+ 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);
+ utl::TransliterationWrapper aWrapper(xContext, transliterationFlag);
+ aStr = aWrapper.transliterate(aStr, nLanguage, 0, aStr.getLength(), nullptr);
}
}
- 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];
- }
- 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);
}
@@ -4259,8 +4110,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();
}
@@ -4269,8 +4119,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 );
}
@@ -4297,8 +4146,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 );
}
@@ -4324,8 +4172,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());
@@ -4348,8 +4195,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();
@@ -4367,12 +4213,17 @@ 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());
+
+ // tdf#147529 - check for missing parameters
+ if (IsMissing(rPar, 1))
+ {
+ return StarBASIC::Error(ERRCODE_BASIC_NOT_OPTIONAL);
+ }
+
+ // tdf#151012 - initialize optional parameters with their default values (number of buttons)
+ WinBits nType = static_cast<WinBits>(GetOptionalIntegerParamOrDefault(rPar, 2, 0)); // MB_OK
WinBits nStyle = nType;
nStyle &= 15; // delete bits 4-16
if (nStyle > 5)
@@ -4390,15 +4241,8 @@ void SbRtl_MsgBox(StarBASIC *, SbxArray & rPar, bool)
};
OUString aMsg = rPar.Get(1)->GetOUString();
- OUString aTitle;
- if( nArgCount >= 4 )
- {
- aTitle = rPar.Get(3)->GetOUString();
- }
- else
- {
- aTitle = Application::GetDisplayName();
- }
+ // tdf#151012 - initialize optional parameters with their default values (title of dialog box)
+ OUString aTitle = GetOptionalOUStringParamOrDefault(rPar, 3, Application::GetDisplayName());
WinBits nDialogType = nType & (16+32+64);
@@ -4424,7 +4268,7 @@ void SbRtl_MsgBox(StarBASIC *, SbxArray & rPar, bool)
}
std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pParent,
- eType, VclButtonsType::NONE, aMsg));
+ eType, VclButtonsType::NONE, aMsg, GetpApp()));
switch (nStyle)
{
@@ -4605,8 +4449,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();
@@ -4616,8 +4459,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
@@ -4683,28 +4525,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;
@@ -4816,8 +4640,7 @@ 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;
}
diff --git a/basic/source/runtime/methods1.cxx b/basic/source/runtime/methods1.cxx
index 16104540ba96..57d95b93a526 100644
--- a/basic/source/runtime/methods1.cxx
+++ b/basic/source/runtime/methods1.cxx
@@ -122,7 +122,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
@@ -279,15 +279,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);
}
@@ -323,30 +319,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);
}
@@ -382,16 +370,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);
}
@@ -412,112 +395,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));
}
@@ -527,7 +484,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) )
@@ -547,10 +504,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 )
{
@@ -563,11 +518,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 );
@@ -604,14 +557,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)
@@ -811,10 +760,8 @@ void SbRtl_DimArray(StarBASIC *, SbxArray & rPar, bool)
void SbRtl_FindObject(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 2)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
OUString aNameStr = rPar.Get(1)->GetOUString();
@@ -834,10 +781,8 @@ void SbRtl_FindObject(StarBASIC *, SbxArray & rPar, bool)
void SbRtl_FindPropertyObject(StarBASIC *, SbxArray & rPar, bool)
{
if (rPar.Count() < 3)
- {
- StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- return;
- }
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
+
SbxBase* pObjVar = rPar.Get(1)->GetObject();
SbxObject* pObj = nullptr;
@@ -1109,10 +1054,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();
@@ -1128,10 +1071,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();
@@ -1194,10 +1134,8 @@ 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(),
@@ -1243,20 +1181,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()));
}
@@ -1273,109 +1206,97 @@ 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)
- {
- 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;
+ return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
- case SbxINTEGER:
- case SbxERROR:
- case SbxUSHORT:
- case SbxINT:
- case SbxUINT:
- nLen = 2;
- break;
+ 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 SbxLONG:
- case SbxSINGLE:
- case SbxULONG:
- nLen = 4;
- break;
+ case SbxINTEGER:
+ case SbxERROR:
+ case SbxUSHORT:
+ case SbxINT:
+ case SbxUINT:
+ nLen = 2;
+ break;
- case SbxDOUBLE:
- case SbxCURRENCY:
- case SbxDATE:
- case SbxSALINT64:
- case SbxSALUINT64:
- nLen = 8;
- break;
+ case SbxLONG:
+ case SbxSINGLE:
+ case SbxULONG:
+ nLen = 4;
+ break;
- case SbxOBJECT:
- case SbxVARIANT:
- case SbxDATAOBJECT:
- nLen = 0;
- break;
+ case SbxDOUBLE:
+ case SbxCURRENCY:
+ case SbxDATE:
+ case SbxSALINT64:
+ case SbxSALUINT64:
+ nLen = 8;
+ break;
- case SbxCHAR:
- case SbxBYTE:
- case SbxBOOL:
- nLen = 1;
- break;
+ case SbxOBJECT:
+ case SbxVARIANT:
+ case SbxDATAOBJECT:
+ nLen = 0;
+ break;
- case SbxLPSTR:
- case SbxLPWSTR:
- case SbxCoreSTRING:
- case SbxSTRING:
- nLen = static_cast<sal_Int16>(rPar.Get(1)->GetOUString().getLength());
+ case SbxCHAR:
+ case SbxBYTE:
+ case SbxBOOL:
+ nLen = 1;
break;
- default:
- nLen = 0;
- break;
- }
- rPar.Get(0)->PutInteger(nLen);
+ 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);
}
@@ -1456,44 +1377,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);
}
@@ -1507,47 +1421,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());
+
}
@@ -1807,13 +1714,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;
}
@@ -2446,10 +2353,10 @@ 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));
@@ -2469,9 +2376,9 @@ 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));
@@ -2511,11 +2418,11 @@ 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));
@@ -2556,12 +2463,12 @@ 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));
@@ -2601,11 +2508,11 @@ 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));
@@ -2631,7 +2538,7 @@ void SbRtl_NPV(StarBASIC *, SbxArray & rPar, bool)
Sequence< Any > aParams
{
- makeAny(rPar.Get(1)->GetDouble()),
+ Any(rPar.Get(1)->GetDouble()),
aValues
};
@@ -2672,11 +2579,11 @@ 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));
@@ -2705,8 +2612,8 @@ 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));
@@ -2742,7 +2649,7 @@ void SbRtl_IRR(StarBASIC *, SbxArray & rPar, bool)
Sequence< Any > aParams
{
aValues,
- makeAny(guess)
+ Any(guess)
};
CallFunctionAccessFunction(aParams, "IRR", rPar.Get(0));
@@ -2783,12 +2690,12 @@ 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));
@@ -2828,11 +2735,11 @@ 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));
@@ -2866,11 +2773,11 @@ 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));
@@ -2923,12 +2830,12 @@ 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));
@@ -3033,9 +2940,8 @@ bool LibreOffice6FloatingPointMode()
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 aa0a9e1c9d85..82478bf6d3cf 100644
--- a/basic/source/runtime/props.cxx
+++ b/basic/source/runtime/props.cxx
@@ -103,10 +103,10 @@ void SbRtl_MB_APPLMODAL(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInte
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_IDIGNORE(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(5); }
void SbRtl_IDYES(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(6); }
void SbRtl_IDNO(StarBASIC*, SbxArray& rPar, bool) { rPar.Get(0)->PutInteger(7); }
diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx
index afc785e76b32..b2f493689c0b 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 );
@@ -113,11 +113,8 @@ private:
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 +127,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_) {}
};
@@ -384,6 +375,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 +469,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 +592,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 );
}
@@ -791,23 +767,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();
}
}
@@ -1169,7 +1148,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))
{
@@ -1279,8 +1266,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 +1436,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 +1508,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 +1517,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 );
@@ -1774,10 +1740,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 )
{}
@@ -1815,7 +1781,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 )
{
@@ -2744,7 +2710,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() );
}
@@ -2847,7 +2813,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 )
@@ -2893,7 +2859,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 );
}
@@ -2915,7 +2881,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
@@ -3023,6 +2989,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
@@ -3426,7 +3400,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 )
@@ -3448,7 +3422,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 );
@@ -3461,7 +3435,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)
@@ -3515,7 +3489,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("[") )
@@ -4307,7 +4281,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 )
{
@@ -4325,7 +4299,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 )
{
@@ -4415,7 +4389,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 );
@@ -4458,7 +4432,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 )
{
@@ -4466,7 +4440,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 );
@@ -4528,7 +4502,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 )
{
@@ -4543,7 +4517,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);
@@ -4555,8 +4529,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 )
@@ -4585,7 +4559,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());
}
@@ -4605,7 +4579,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);
@@ -4620,7 +4594,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 );
@@ -4672,7 +4646,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
@@ -4732,7 +4706,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 );
@@ -4765,9 +4739,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 0bb572bbcd33..5b123d00d5a2 100644
--- a/basic/source/runtime/stdobj.cxx
+++ b/basic/source/runtime/stdobj.cxx
@@ -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 },
@@ -328,8 +328,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 },
@@ -401,6 +401,13 @@ 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),
@@ -451,6 +458,7 @@ constexpr Method aMethods[] = {
{ u"IDABORT", SbxINTEGER, CPROP_, SbRtl_IDABORT },
{ u"IDCANCEL", SbxINTEGER, CPROP_, SbRtl_IDCANCEL },
+{ u"IDIGNORE", SbxINTEGER, CPROP_, SbRtl_IDIGNORE },
{ u"IDNO", SbxINTEGER, CPROP_, SbRtl_IDNO },
{ u"IDOK", SbxINTEGER, CPROP_, SbRtl_IDOK },
{ u"IDRETRY", SbxINTEGER, CPROP_, SbRtl_IDRETRY },
@@ -479,10 +487,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 +535,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 +549,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),
@@ -585,9 +593,9 @@ constexpr Method aMethods[] = {
{ 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 +711,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,7 +742,7 @@ 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 },
@@ -744,8 +752,8 @@ constexpr Method aMethods[] = {
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 +770,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 +797,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),
@@ -867,7 +875,7 @@ constexpr Method aMethods[] = {
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,7 +890,7 @@ constexpr Method aMethods[] = {
arg(u"String", SbxSTRING),
{ u"VarType", SbxINTEGER, 1 | FUNCTION_, SbRtl_VarType },
- arg(u"Var", SbxVARIANT),
+ arg(u"Varname", SbxVARIANT),
{ u"V_EMPTY", SbxINTEGER, CPROP_, SbRtl_V_EMPTY },
{ u"V_NULL", SbxINTEGER, CPROP_, SbRtl_V_NULL },
@@ -926,15 +934,15 @@ SbiStdObject::SbiStdObject( const OUString& r, StarBASIC* pb ) : SbxObject( r )
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();
}
@@ -985,7 +993,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;
diff --git a/basic/source/runtime/stdobj1.cxx b/basic/source/runtime/stdobj1.cxx
index ee7df8d7a62d..c24c59af95a3 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()
{
@@ -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 );
@@ -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 );
@@ -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..81ad5bf64ada 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
{
@@ -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);
@@ -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..b90368f68f26 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 )
@@ -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 0b5f2111eca8..2f5f031329f2 100644
--- a/basic/source/sbx/sbxbool.cxx
+++ b/basic/source/sbx/sbxbool.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 <basic/sberrors.hxx>
#include "sbxconv.hxx"
#include "sbxres.hxx"
diff --git a/basic/source/sbx/sbxbyte.cxx b/basic/source/sbx/sbxbyte.cxx
index 1892167121c2..071fcd6338f3 100644
--- a/basic/source/sbx/sbxbyte.cxx
+++ b/basic/source/sbx/sbxbyte.cxx
@@ -20,7 +20,7 @@
#include <sal/config.h>
#include <o3tl/safeint.hxx>
-#include <vcl/errcode.hxx>
+#include <comphelper/errcode.hxx>
//#include <basic/sbx.hxx>
#include <basic/sberrors.hxx>
#include "sbxconv.hxx"
diff --git a/basic/source/sbx/sbxchar.cxx b/basic/source/sbx/sbxchar.cxx
index 36bd8d60d482..f3a6715a2911 100644
--- a/basic/source/sbx/sbxchar.cxx
+++ b/basic/source/sbx/sbxchar.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 <basic/sberrors.hxx>
#include "sbxconv.hxx"
#include <rtlproto.hxx>
diff --git a/basic/source/sbx/sbxcoll.cxx b/basic/source/sbx/sbxcoll.cxx
index ea4eb4cdea14..a29e832fa2a8 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>
@@ -188,7 +189,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 +211,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 +293,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/sbxcurr.cxx b/basic/source/sbx/sbxcurr.cxx
index 416229afbc95..ca67977a3a56 100644
--- a/basic/source/sbx/sbxcurr.cxx
+++ b/basic/source/sbx/sbxcurr.cxx
@@ -21,6 +21,12 @@
#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"
@@ -84,80 +90,62 @@ static OUString ImpCurrencyToString( sal_Int64 rVal )
return aAbsStr;
}
-
-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 )
+ }
+
+ if (!bSuccess)
+ {
+ SbxBase::SetError(ERRCODE_BASIC_CONVERSION);
+ }
+
+ sal_Int64 nRes = 0;
+ const auto fShiftedResult = fResult * CURRENCY_FACTOR;
+ if (fShiftedResult + 0.5 > static_cast<double>(SAL_MAX_INT64)
+ || fShiftedResult - 0.5 < static_cast<double>(SAL_MIN_INT64))
+ {
+ nRes = SAL_MAX_INT64;
+ if (fShiftedResult - 0.5 < static_cast<double>(SAL_MIN_INT64))
{
- // Round up if necessary
- if( *p >= '5' && *p <= '9' )
- bRoundUp = true;
- while( *p >= '0' && *p <= '9' )
- p++;
+ nRes = SAL_MIN_INT64;
}
+ SbxBase::SetError(ERRCODE_BASIC_MATH_OVERFLOW);
}
- // 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 )
+ else
{
- sNormalisedNumString.append( '0' );
- nFractDigit--;
+ nRes = ImpDoubleToCurrency(fResult);
}
- sal_Int64 result = sNormalisedNumString.makeStringAndClear().toInt64();
-
- if ( bRoundUp )
- ++result;
- return result;
+ return nRes;
}
-
sal_Int64 ImpGetCurrency( const SbxValues* p )
{
SbxValues aTmp;
diff --git a/basic/source/sbx/sbxdate.cxx b/basic/source/sbx/sbxdate.cxx
index 6b695a9c40c7..057e16f09d03 100644
--- a/basic/source/sbx/sbxdate.cxx
+++ b/basic/source/sbx/sbxdate.cxx
@@ -84,14 +84,8 @@ double ImpGetDate( const SbxValues* p )
break;
case SbxDECIMAL:
case SbxBYREF | SbxDECIMAL:
- if( p->pDecimal )
- {
- p->pDecimal->getDouble( nRes );
- }
- else
- {
+ if (!p->pDecimal || !p->pDecimal->getDouble(nRes))
nRes = 0.0;
- }
break;
case SbxBYREF | SbxSTRING:
case SbxSTRING:
diff --git a/basic/source/sbx/sbxdbl.cxx b/basic/source/sbx/sbxdbl.cxx
index aca18b3197e3..10cdbc203b0d 100644
--- a/basic/source/sbx/sbxdbl.cxx
+++ b/basic/source/sbx/sbxdbl.cxx
@@ -19,7 +19,7 @@
#include <config_features.h>
-#include <vcl/errcode.hxx>
+#include <comphelper/errcode.hxx>
#include "sbxconv.hxx"
#include <rtlproto.hxx>
#include <runtime.hxx>
@@ -61,9 +61,7 @@ double ImpGetDouble( const SbxValues* p )
nRes = ImpSalUInt64ToDouble( p->uInt64 ); break;
case SbxDECIMAL:
case SbxBYREF | SbxDECIMAL:
- if( p->pDecimal )
- p->pDecimal->getDouble( nRes );
- else
+ if (!p->pDecimal || !p->pDecimal->getDouble(nRes))
nRes = 0.0;
break;
case SbxBYREF | SbxSTRING:
diff --git a/basic/source/sbx/sbxdec.cxx b/basic/source/sbx/sbxdec.cxx
index acfc31acfbd0..cad5601f2f7b 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,10 +74,6 @@ void SbxDecimal::fillAutomationDecimal
#endif
}
-SbxDecimal::~SbxDecimal()
-{
-}
-
void releaseDecimalPtr( SbxDecimal*& rpDecimal )
{
if( rpDecimal )
@@ -342,7 +342,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 )
@@ -366,8 +366,7 @@ void SbxDecimal::getString( OUString& rString )
i++;
}
}
- rString = o3tl::toU( pBStr );
- SysFreeString( pBStr );
+ rString = pBStr;
}
#else
(void)rString;
diff --git a/basic/source/sbx/sbxdec.hxx b/basic/source/sbx/sbxdec.hxx
index 3db396ea6cb4..756fdc9f9273 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++; }
diff --git a/basic/source/sbx/sbxexec.cxx b/basic/source/sbx/sbxexec.cxx
index d830061f071d..af7d12c00651 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 );
@@ -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..84e5f22fd8da 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,15 +62,15 @@ 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 OUString BASICFORMAT_GENERALNUMBER = u"General Number"_ustr;
+constexpr OUString BASICFORMAT_CURRENCY = u"Currency"_ustr;
+constexpr OUString BASICFORMAT_FIXED = u"Fixed"_ustr;
+constexpr OUString BASICFORMAT_STANDARD = u"Standard"_ustr;
+constexpr OUString BASICFORMAT_PERCENT = u"Percent"_ustr;
+constexpr OUString BASICFORMAT_SCIENTIFIC = u"Scientific"_ustr;
+constexpr OUString BASICFORMAT_YESNO = u"Yes/No"_ustr;
+constexpr OUString BASICFORMAT_TRUEFALSE = u"True/False"_ustr;
+constexpr OUString BASICFORMAT_ONOFF = u"On/Off"_ustr;
// Comment: Visual-Basic has a maximum of 12 positions after the
// decimal point for floating-point-numbers.
@@ -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 );
@@ -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 432aaf9b9cad..1b57239ddba9 100644
--- a/basic/source/sbx/sbxint.cxx
+++ b/basic/source/sbx/sbxint.cxx
@@ -20,7 +20,7 @@
#include <sal/config.h>
#include <o3tl/safeint.hxx>
-#include <vcl/errcode.hxx>
+#include <comphelper/errcode.hxx>
#include <basic/sberrors.hxx>
#include "sbxconv.hxx"
#include <rtlproto.hxx>
@@ -485,8 +485,7 @@ start:
if( !p->pOUString )
p->pOUString = new OUString;
- ::OString aOStr = OString::number( n );
- (*p->pOUString) = ::OStringToOUString( aOStr, RTL_TEXTENCODING_ASCII_US );
+ (*p->pOUString) = OUString::number(n);
break;
}
case SbxOBJECT:
@@ -742,8 +741,7 @@ start:
SbxBase::SetError( ERRCODE_BASIC_CONVERSION );
else
{
- ::OString aOStr = OString::number( n );
- (*p->pOUString) = ::OStringToOUString( aOStr, RTL_TEXTENCODING_ASCII_US );
+ (*p->pOUString) = OUString::number(n);
}
break;
case SbxOBJECT:
diff --git a/basic/source/sbx/sbxlng.cxx b/basic/source/sbx/sbxlng.cxx
index 7011a13b0da8..e129406e2f3a 100644
--- a/basic/source/sbx/sbxlng.cxx
+++ b/basic/source/sbx/sbxlng.cxx
@@ -19,7 +19,7 @@
#include <sal/config.h>
-#include <vcl/errcode.hxx>
+#include <comphelper/errcode.hxx>
#include <basic/sberrors.hxx>
#include "sbxconv.hxx"
#include <rtlproto.hxx>
diff --git a/basic/source/sbx/sbxobj.cxx b/basic/source/sbx/sbxobj.cxx
index 7f3560a62003..be1aec16393a 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
@@ -262,6 +264,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 +276,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 +604,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 +623,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,7 +689,7 @@ 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;
@@ -695,38 +701,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 +757,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 +768,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 +794,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 +806,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 +814,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 +827,7 @@ void SbxObject::Dump( SvStream& rStrm, bool bFill )
}
}
- rStrm.WriteOString( aIndentNameStr ).WriteCharPtr( "}" ) << endl << endl;
+ rStrm.WriteOString( aIndentNameStr ).WriteOString( "}" ) << endl << endl;
--nLevel;
}
@@ -850,6 +856,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/sbxscan.cxx b/basic/source/sbx/sbxscan.cxx
index d8c1582af52d..0d6949e913d6 100644
--- a/basic/source/sbx/sbxscan.cxx
+++ b/basic/source/sbx/sbxscan.cxx
@@ -23,7 +23,7 @@
#include <config_features.h>
-#include <vcl/errcode.hxx>
+#include <comphelper/errcode.hxx>
#include <unotools/resmgr.hxx>
#include "sbxconv.hxx"
#include <rtlproto.hxx>
@@ -48,6 +48,7 @@
#include <rtl/math.hxx>
#include <svl/numformat.hxx>
#include <svl/zforlist.hxx>
+#include <o3tl/string_view.hxx>
void ImpGetIntntlSep( sal_Unicode& rcDecimalSep, sal_Unicode& rcThousandSep, sal_Unicode& rcDecimalSepAlt )
@@ -60,7 +61,7 @@ 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
@@ -113,8 +114,7 @@ ErrCode ImpScan( const OUString& rWSrc, double& nVal, SbxDataType& rType,
short decsep = 0;
short ndig = 0;
short ncdig = 0; // number of digits after decimal point
- OUStringBuffer aSearchStr("0123456789DEde");
- aSearchStr.append(cNonIntntlDecSep);
+ OUStringBuffer aSearchStr(OUString::Concat("0123456789DEde") + OUStringChar(cNonIntntlDecSep));
if( cIntntlDecSep != cNonIntntlDecSep )
aSearchStr.append(cIntntlDecSep);
if( cIntntlDecSepAlt && cIntntlDecSepAlt != cNonIntntlDecSep )
@@ -122,7 +122,7 @@ ErrCode ImpScan( const OUString& rWSrc, double& nVal, SbxDataType& rType,
if( bOnlyIntntl )
aSearchStr.append(cIntntlGrpSep);
const OUString pSearchStr = aSearchStr.makeStringAndClear();
- static const OUStringLiteral pDdEe = u"DdEe";
+ static constexpr OUStringLiteral pDdEe = u"DdEe";
while( ImpStrChr( pSearchStr, *p ) )
{
aBuf.append( *p );
@@ -171,11 +171,10 @@ ErrCode ImpScan( const OUString& rWSrc, double& nVal, SbxDataType& rType,
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() )
+ nVal = rtl::math::stringToDouble( aBuf, cIntntlDecSep, cIntntlGrpSep, &eStatus, &nParseEnd );
+ if( eStatus != rtl_math_ConversionStatus_Ok || nParseEnd != aBuf.getLength() )
bRes = false;
if( !decsep && !exp )
@@ -192,7 +191,7 @@ ErrCode ImpScan( const OUString& rWSrc, double& nVal, SbxDataType& rType,
eScanType = SbxDOUBLE;
// type detection?
- static const OUStringLiteral pTypes = u"%!&#";
+ static constexpr OUStringLiteral pTypes = u"%!&#";
if( ImpStrChr( pTypes, *p ) )
p++;
}
@@ -250,6 +249,9 @@ ErrCode ImpScan( const OUString& rWSrc, double& nVal, SbxDataType& rType,
return ERRCODE_BASIC_CONVERSION;
}
#endif
+ // tdf#146672 - skip whitespaces and tabs at the end of the scanned string
+ while (*p == ' ' || *p == '\t')
+ p++;
if( pLen )
*pLen = static_cast<sal_uInt16>( p - pStart );
if( !bRes )
@@ -467,12 +469,12 @@ const VbaFormatInfo pFormatInfoTable[] =
{ VbaFormatType::Null, std::u16string_view(u""), NF_INDEX_TABLE_ENTRIES, nullptr }
};
-const VbaFormatInfo* getFormatInfo( const OUString& rFmt )
+const VbaFormatInfo* getFormatInfo( std::u16string_view rFmt )
{
const VbaFormatInfo* pInfo = pFormatInfoTable;
while( pInfo->meType != VbaFormatType::Null )
{
- if( rFmt.equalsIgnoreAsciiCase( pInfo->mpVbaFormat ) )
+ if( o3tl::equalsIgnoreAsciiCase( rFmt, pInfo->mpVbaFormat ) )
break;
++pInfo;
}
@@ -486,7 +488,7 @@ const VbaFormatInfo* getFormatInfo( const OUString& rFmt )
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 OUString VBAFORMAT_NN = u"nn"_ustr;
constexpr OUStringLiteral VBAFORMAT_W = u"w";
constexpr OUStringLiteral VBAFORMAT_Y = u"y";
constexpr OUStringLiteral VBAFORMAT_LOWERCASE = u"<";
@@ -597,7 +599,7 @@ void SbxValue::Format( OUString& rRes, const OUString* pFmt ) const
sal_Unicode aBuf[2];
aBuf[0] = '0';
aBuf[1] = '0' + nMin;
- rRes = OUString(aBuf, SAL_N_ELEMENTS(aBuf));
+ rRes = OUString(aBuf, std::size(aBuf));
}
else
{
diff --git a/basic/source/sbx/sbxsng.cxx b/basic/source/sbx/sbxsng.cxx
index 2353968d2fde..27109971609a 100644
--- a/basic/source/sbx/sbxsng.cxx
+++ b/basic/source/sbx/sbxsng.cxx
@@ -19,7 +19,7 @@
#include <sal/config.h>
-#include <vcl/errcode.hxx>
+#include <comphelper/errcode.hxx>
#include <basic/sberrors.hxx>
#include "sbxconv.hxx"
#include <rtlproto.hxx>
@@ -54,9 +54,7 @@ start:
nRes = p->nSingle; break;
case SbxDECIMAL:
case SbxBYREF | SbxDECIMAL:
- if( p->pDecimal )
- p->pDecimal->getSingle( nRes );
- else
+ if (!p->pDecimal || !p->pDecimal->getSingle(nRes))
nRes = 0.0;
break;
case SbxDATE:
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
index 1a8013c1cc4b..d536ec99e217 100644
--- a/basic/source/sbx/sbxuint.cxx
+++ b/basic/source/sbx/sbxuint.cxx
@@ -19,7 +19,7 @@
#include <sal/config.h>
-#include <vcl/errcode.hxx>
+#include <comphelper/errcode.hxx>
#include <basic/sberrors.hxx>
#include "sbxconv.hxx"
#include <rtlproto.hxx>
diff --git a/basic/source/sbx/sbxulng.cxx b/basic/source/sbx/sbxulng.cxx
index a14f3b028712..68ae31457088 100644
--- a/basic/source/sbx/sbxulng.cxx
+++ b/basic/source/sbx/sbxulng.cxx
@@ -19,7 +19,7 @@
#include <sal/config.h>
-#include <vcl/errcode.hxx>
+#include <comphelper/errcode.hxx>
#include <basic/sberrors.hxx>
#include "sbxconv.hxx"
#include <rtlproto.hxx>
diff --git a/basic/source/sbx/sbxvalue.cxx b/basic/source/sbx/sbxvalue.cxx
index dee531ea28c0..d644ca0c3c73 100644
--- a/basic/source/sbx/sbxvalue.cxx
+++ b/basic/source/sbx/sbxvalue.cxx
@@ -32,6 +32,7 @@
#include "sbxconv.hxx"
#include <rtlproto.hxx>
#include <runtime.hxx>
+#include <filefmt.hxx>
///////////////////////////// constructors
@@ -1466,7 +1467,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 );
@@ -1560,9 +1561,9 @@ bool SbxValue::LoadData( SvStream& r, sal_uInt16 )
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 8fb11bf9f2a2..cc57a804bc61 100644
--- a/basic/source/sbx/sbxvar.cxx
+++ b/basic/source/sbx/sbxvar.cxx
@@ -30,8 +30,12 @@
#include <sbunoobj.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 +183,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 +203,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)
@@ -499,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;
@@ -516,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);
@@ -539,7 +556,7 @@ bool SbxVariable::StoreData( SvStream& rStrm ) const
{
rStrm.WriteUChar( 0 );
}
- return true;
+ return { true, B_IMG_VERSION_12 };
}
// SbxInfo
@@ -548,26 +565,26 @@ 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 )
{}
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 &&
@@ -575,7 +592,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..533deb182d58 100644
--- a/basic/source/uno/dlgcont.cxx
+++ b/basic/source/uno/dlgcont.cxx
@@ -33,7 +33,8 @@
#include <dlgcont.hxx>
#include <comphelper/fileformat.h>
#include <comphelper/processfactory.hxx>
-#include <tools/diagnose_ex.h>
+#include <comphelper/diagnose_ex.hxx>
+#include <utility>
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
#include <xmlscript/xmldlg_imexp.hxx>
@@ -52,7 +53,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 +62,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()
@@ -346,8 +362,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,12 +387,12 @@ 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("null returned from openStorageElement",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("null returned from openStorageElement",getXWeak());
}
catch(const uno::Exception& )
{
@@ -424,12 +440,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("null returned from openStorageElement",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("null returned from openStorageElement",getXWeak());
Reference< resource::XStringResourceWithStorage >
xStringResourceWithStorage( xStringResourcePersistence, UNO_QUERY );
@@ -454,30 +470,30 @@ 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 )
, 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,
@@ -486,7 +502,7 @@ SfxDialogLibrary::SfxDialogLibrary( ModifiableHelper& _rModifiable,
: SfxLibrary( _rModifiable, cppu::UnoType<XInputStreamProvider>::get(),
xSFI, aLibInfoFileURL, aStorageURL, ReadOnly)
, m_pParent( pParent )
- , m_aName( aName )
+ , m_aName(std::move( aName ))
{
}
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 b92f5a590617..228220182811 100644
--- a/basic/source/uno/namecont.cxx
+++ b/basic/source/uno/namecont.cxx
@@ -25,11 +25,14 @@
#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 <osl/mutex.hxx>
#include <vcl/errinf.hxx>
#include <rtl/ustring.hxx>
@@ -41,7 +44,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 +90,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;
@@ -141,7 +143,7 @@ void NameContainer::replaceByName( const OUString& aName, const Any& aElement )
const Type& aAnyType = aElement.getValueType();
if( mType != aAnyType )
{
- throw IllegalArgumentException("types do not match", static_cast<cppu::OWeakObject*>(this), 2);
+ throw IllegalArgumentException("types do not match", getXWeak(), 2);
}
NameContainerNameMap::iterator aIt = mHashMap.find( aName );
if( aIt == mHashMap.end() )
@@ -153,27 +155,29 @@ void NameContainer::replaceByName( const OUString& aName, const Any& aElement )
mValues[ iHashResult ] = aElement;
+ std::unique_lock aGuard(m_aMutex);
+
// Fire event
- if( maContainerListeners.getLength() > 0 )
+ if( maContainerListeners.getLength(aGuard) > 0 )
{
ContainerEvent aEvent;
aEvent.Source = mpxEventSource;
aEvent.Accessor <<= aName;
aEvent.Element = aElement;
aEvent.ReplacedElement = aOldElement;
- maContainerListeners.notifyEach( &XContainerListener::elementReplaced, aEvent );
+ maContainerListeners.notifyEach( aGuard, &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(aGuard) > 0 )
{
ChangesEvent aEvent;
aEvent.Source = mpxEventSource;
aEvent.Base <<= aEvent.Source;
aEvent.Changes = { { Any(aName), aElement, aOldElement } };
- maChangesListeners.notifyEach( &XChangesListener::changesOccurred, aEvent );
+ maChangesListeners.notifyEach( aGuard, &XChangesListener::changesOccurred, aEvent );
}
}
@@ -192,7 +196,7 @@ void NameContainer::insertNoCheck(const OUString& aName, const Any& aElement)
const Type& aAnyType = aElement.getValueType();
if( mType != aAnyType )
{
- throw IllegalArgumentException("types do not match", static_cast<cppu::OWeakObject*>(this), 2);
+ throw IllegalArgumentException("types do not match", getXWeak(), 2);
}
sal_Int32 nCount = mNames.size();
@@ -202,26 +206,28 @@ void NameContainer::insertNoCheck(const OUString& aName, const Any& aElement)
mHashMap[ aName ] = nCount;
mnElementCount++;
+ std::unique_lock aGuard(m_aMutex);
+
// Fire event
- if( maContainerListeners.getLength() > 0 )
+ if( maContainerListeners.getLength(aGuard) > 0 )
{
ContainerEvent aEvent;
aEvent.Source = mpxEventSource;
aEvent.Accessor <<= aName;
aEvent.Element = aElement;
- maContainerListeners.notifyEach( &XContainerListener::elementInserted, aEvent );
+ maContainerListeners.notifyEach( aGuard, &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(aGuard) > 0 )
{
ChangesEvent aEvent;
aEvent.Source = mpxEventSource;
aEvent.Base <<= aEvent.Source;
aEvent.Changes = { { Any(aName), aElement, {} } };
- maChangesListeners.notifyEach( &XChangesListener::changesOccurred, aEvent );
+ maChangesListeners.notifyEach( aGuard, &XChangesListener::changesOccurred, aEvent );
}
}
@@ -254,20 +260,22 @@ void NameContainer::removeByName( const OUString& aName )
mValues.resize( iLast );
mnElementCount--;
+ std::unique_lock aGuard(m_aMutex);
+
// Fire event
- if( maContainerListeners.getLength() > 0 )
+ if( maContainerListeners.getLength(aGuard) > 0 )
{
ContainerEvent aEvent;
aEvent.Source = mpxEventSource;
aEvent.Accessor <<= aName;
aEvent.Element = aOldElement;
- maContainerListeners.notifyEach( &XContainerListener::elementRemoved, aEvent );
+ maContainerListeners.notifyEach( aGuard, &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(aGuard) > 0 )
{
ChangesEvent aEvent;
aEvent.Source = mpxEventSource;
@@ -275,7 +283,7 @@ 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( aGuard, &XChangesListener::changesOccurred, aEvent );
}
}
@@ -285,18 +293,20 @@ void SAL_CALL NameContainer::addContainerListener( const Reference< XContainerLi
{
if( !xListener.is() )
{
- throw RuntimeException("addContainerListener called with null xListener",static_cast< cppu::OWeakObject * >(this));
+ throw RuntimeException("addContainerListener called with null xListener",getXWeak());
}
- maContainerListeners.addInterface( xListener );
+ std::unique_lock aGuard(m_aMutex);
+ maContainerListeners.addInterface( aGuard, xListener );
}
void SAL_CALL NameContainer::removeContainerListener( const Reference< XContainerListener >& xListener )
{
if( !xListener.is() )
{
- throw RuntimeException("removeContainerListener called with null xListener",static_cast< cppu::OWeakObject * >(this));
+ throw RuntimeException("removeContainerListener called with null xListener",getXWeak());
}
- maContainerListeners.removeInterface( xListener );
+ std::unique_lock aGuard(m_aMutex);
+ maContainerListeners.removeInterface( aGuard, xListener );
}
// Methods XChangesNotifier
@@ -304,18 +314,20 @@ void SAL_CALL NameContainer::addChangesListener( const Reference< XChangesListen
{
if( !xListener.is() )
{
- throw RuntimeException("addChangesListener called with null xListener",static_cast< cppu::OWeakObject * >(this));
+ throw RuntimeException("addChangesListener called with null xListener",getXWeak());
}
- maChangesListeners.addInterface( xListener );
+ std::unique_lock aGuard(m_aMutex);
+ maChangesListeners.addInterface( aGuard, xListener );
}
void SAL_CALL NameContainer::removeChangesListener( const Reference< XChangesListener >& xListener )
{
if( !xListener.is() )
{
- throw RuntimeException("removeChangesListener called with null xListener",static_cast< cppu::OWeakObject * >(this));
+ throw RuntimeException("removeChangesListener called with null xListener",getXWeak());
}
- maChangesListeners.removeInterface( xListener );
+ std::unique_lock aGuard(m_aMutex);
+ maChangesListeners.removeInterface( aGuard, xListener );
}
@@ -344,6 +356,7 @@ SfxLibraryContainer::SfxLibraryContainer()
, maVBAScriptListeners( m_aMutex )
, mnRunningVBAScripts( 0 )
, mbVBACompat( false )
+ , meVBATextEncoding( RTL_TEXTENCODING_DONTKNOW )
, maModifiable( *this, m_aMutex )
, maNameContainer( new NameContainer(cppu::UnoType<XNameAccess>::get()) )
, mbOldInfoFormat( false )
@@ -418,7 +431,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("no root storage", getXWeak(), 1);
}
mxStorage = _rxRootStorage;
onNewRootStorage();
@@ -429,7 +442,7 @@ 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("no root storage", getXWeak(), 1);
}
try
{
@@ -533,7 +546,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,
@@ -555,19 +570,23 @@ 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 )
{
@@ -585,10 +604,10 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
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 );
@@ -646,8 +665,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;
@@ -731,11 +748,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" );
@@ -755,7 +772,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 );
@@ -781,6 +798,7 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
// start parsing
auto pLibArray = std::make_unique<::xmlscript::LibDescriptorArray> ( );
+ Reference< XParser > xParser = xml::sax::Parser::create(mxContext);
try
{
xParser->setDocumentHandler( ::xmlscript::importLibraryContainer( pLibArray.get() ) );
@@ -828,7 +846,7 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
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 );
@@ -970,7 +988,11 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL,
if( meInitMode != DEFAULT )
return;
- INetURLObject aUserBasicInetObj( maLibraryPath.getToken(1, ';') );
+ // 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("Standard");
INetURLObject aPrevUserBasicInetObj_1( aUserBasicInetObj );
@@ -1254,6 +1276,17 @@ void SfxLibraryContainer::checkStorageURL( const OUString& aSourceURL,
{
aUnexpandedStorageURL = aSourceURL;
}
+ else
+ {
+ // try to re-create the variable URL: helps moving the profile
+ if (OUString 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" )
@@ -1318,7 +1351,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 );
@@ -1345,14 +1378,14 @@ 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 )
{
@@ -1413,7 +1446,7 @@ void SfxLibraryContainer::implStoreLibrary( SfxLibrary* pLib,
else
{
// Export?
- bool bExport = !aTargetURL.isEmpty();
+ bool bExport = !aTargetURL.empty();
try
{
Reference< XSimpleFileAccess3 > xSFI = mxSFI;
@@ -1497,14 +1530,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
@@ -1546,7 +1579,7 @@ void SfxLibraryContainer::implStoreLibraryIndexFile( SfxLibrary* pLib,
else
{
// Export?
- bool bExport = !aTargetURL.isEmpty();
+ bool bExport = !aTargetURL.empty();
Reference< XSimpleFileAccess3 > xSFI = mxSFI;
if( rToUseSFI.is() )
{
@@ -1781,10 +1814,7 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
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;
@@ -2051,7 +2081,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 ) );
@@ -2139,6 +2169,9 @@ Reference< XNameContainer > SAL_CALL SfxLibraryContainer::createLibrary( const O
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;
@@ -2204,7 +2237,7 @@ void SAL_CALL SfxLibraryContainer::removeLibrary( const OUString& Name )
SfxLibrary* pImplLib = static_cast< SfxLibrary* >( xNameAccess.get() );
if( pImplLib->mbReadOnly && !pImplLib->mbLink )
{
- throw IllegalArgumentException("readonly && !link", static_cast<cppu::OWeakObject*>(this), 1);
+ throw IllegalArgumentException("readonly && !link", getXWeak(), 1);
}
// Remove from container
maNameContainer->removeByName( Name );
@@ -2242,7 +2275,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 );
@@ -2310,7 +2343,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("null returned from openStorageElement",getXWeak());
}
xLibraryStor = xLibrariesStor->openStorageElement( Name, embed::ElementModes::READ );
@@ -2320,7 +2353,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("null returned from openStorageElement",getXWeak());
}
#if OSL_DEBUG_LEVEL > 0
}
@@ -2427,7 +2460,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("!link", getXWeak(), 1);
}
OUString aRetStr = pImplLib->maLibInfoFileURL;
return aRetStr;
@@ -2484,10 +2517,6 @@ void SAL_CALL SfxLibraryContainer::renameLibrary( const OUString& Name, const OU
}
loadLibrary( Name );
- // Remove from container
- maNameContainer->removeByName( Name );
- maModifiable.setModified( true );
-
// Rename library folder, but not for linked libraries
bool bMovedSuccessful = true;
@@ -2498,15 +2527,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.
+ 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
@@ -2574,12 +2611,13 @@ void SAL_CALL SfxLibraryContainer::renameLibrary( const OUString& Name, const OU
bMovedSuccessful = true;
pImplLib->implSetModified( true );
+ // Remove old library from container
+ maNameContainer->removeByName( Name );
+ maModifiable.setModified( true );
}
}
catch(const Exception& )
{
- // Restore old library
- maNameContainer->insertByName( Name, aLibAny ) ;
}
}
@@ -2600,7 +2638,7 @@ void SAL_CALL SfxLibraryContainer::initialize( const Sequence< Any >& _rArgument
LibraryContainerMethodGuard aGuard( *this );
sal_Int32 nArgCount = _rArguments.getLength();
if ( nArgCount != 1 )
- throw IllegalArgumentException("too many args", static_cast<cppu::OWeakObject*>(this), -1);
+ throw IllegalArgumentException("too many args", getXWeak(), -1);
OUString sInitialDocumentURL;
Reference< XStorageBasedDocument > xDocument;
@@ -2615,7 +2653,7 @@ void SAL_CALL SfxLibraryContainer::initialize( const Sequence< Any >& _rArgument
initializeFromDocument( xDocument );
return;
}
- throw IllegalArgumentException("arg1 unknown type", static_cast<cppu::OWeakObject*>(this), 1);
+ throw IllegalArgumentException("arg1 unknown type", getXWeak(), 1);
}
@@ -2640,7 +2678,7 @@ void SfxLibraryContainer::initializeFromDocument( const Reference< XStorageBased
if ( !xDocStorage.is() )
{
- throw IllegalArgumentException("no doc storage", static_cast<cppu::OWeakObject*>(this), 1);
+ throw IllegalArgumentException("no doc storage", getXWeak(), 1);
}
init( OUString(), xDocStorage );
}
@@ -2694,7 +2732,7 @@ 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->setEventSource( getXWeak() );
maNameContainer->addContainerListener( xListener );
}
@@ -2766,7 +2804,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("!link", getXWeak(), 1);
}
OUString aRetStr = pImplLib->maOriginalStorageURL;
return aRetStr;
@@ -2867,6 +2905,51 @@ void SAL_CALL SfxLibraryContainer::broadcastVBAScriptEvent( sal_Int32 nIdentifie
maVBAScriptListeners.notifyEach( &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
sal_Bool SAL_CALL SfxLibraryContainer::supportsService( const OUString& _rServiceName )
{
@@ -2878,8 +2961,7 @@ 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) )
, mbLoaded( true )
@@ -2899,16 +2981,15 @@ 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) )
, mbLoaded( false )
, mbIsModified( true )
, mbInitialised( false )
- , maLibInfoFileURL( aLibInfoFileURL )
- , maStorageURL( aStorageURL )
+ , maLibInfoFileURL(std::move( aLibInfoFileURL ))
+ , maStorageURL(std::move( aStorageURL ))
, mbLink( true )
, mbReadOnly( false )
, mbReadOnlyLink( ReadOnly )
@@ -2952,7 +3033,7 @@ Any SAL_CALL SfxLibrary::queryInterface( const Type& rType )
static_cast< XChangesNotifier * >( this ) );
if( !aRet.hasValue() )
{
- aRet = OComponentHelper::queryInterface( rType );
+ aRet = WeakComponentImplHelper::queryInterface( rType );
}
return aRet;
}
@@ -3088,7 +3169,7 @@ Sequence< Type > SfxLibrary::getTypes()
cppu::UnoType<XNameContainer>::get(),
cppu::UnoType<XContainer>::get(),
cppu::UnoType<XChangesNotifier>::get(),
- OComponentHelper::getTypes() );
+ WeakComponentImplHelper::getTypes() );
return ourTypes_NameContainer.getTypes();
}
@@ -3102,7 +3183,7 @@ Sequence< sal_Int8 > SfxLibrary::getImplementationId()
// Methods XContainer
void SAL_CALL SfxLibrary::addContainerListener( const Reference< XContainerListener >& xListener )
{
- maNameContainer->setEventSource( static_cast< XInterface* >( static_cast<OWeakObject*>(this) ) );
+ maNameContainer->setEventSource( getXWeak() );
maNameContainer->addContainerListener( xListener );
}
@@ -3114,7 +3195,7 @@ void SAL_CALL SfxLibrary::removeContainerListener( const Reference< XContainerLi
// Methods XChangesNotifier
void SAL_CALL SfxLibrary::addChangesListener( const Reference< XChangesListener >& xListener )
{
- maNameContainer->setEventSource( static_cast< XInterface* >( static_cast<OWeakObject*>(this) ) );
+ maNameContainer->setEventSource( getXWeak() );
maNameContainer->addChangesListener( xListener );
}
diff --git a/basic/source/uno/scriptcont.cxx b/basic/source/uno/scriptcont.cxx
index 5ccf6cc0ddfb..d078deddece4 100644
--- a/basic/source/uno/scriptcont.cxx
+++ b/basic/source/uno/scriptcont.cxx
@@ -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
@@ -319,13 +332,13 @@ 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 );
// Set info
- LibraryContainerInfo aInfo( this, nullptr, static_cast< OldBasicPassword* >( this ) );
+ LibraryContainerInfo aInfo( this, nullptr, this );
pBasicManager->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("!passwordProtected", getXWeak(), 1);
}
bool bRet = pImplLib->mbPasswordVerified;
return bRet;
@@ -361,7 +374,7 @@ sal_Bool SAL_CALL SfxScriptLibraryContainer::verifyLibraryPassword
SfxLibrary* pImplLib = getImplLib( Name );
if( !pImplLib->mbPasswordProtected || pImplLib->mbPasswordVerified )
{
- throw IllegalArgumentException("!PasswordProtected || PasswordVerified", static_cast<cppu::OWeakObject*>(this), 1);
+ throw IllegalArgumentException("!PasswordProtected || PasswordVerified", getXWeak(), 1);
}
// Test password
bool bSuccess = false;
@@ -557,7 +570,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() )
{
@@ -1098,13 +1111,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