tdf#147132 Flatten Basic function implementations.

Change-Id: I5e5d01c43b39f68f38290ce04b26730af362b43e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180282
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
bruh
2025-01-15 18:05:36 +05:30
committed by Mike Kaganski
parent 28e449d31f
commit c67bd0a332

View File

@@ -785,9 +785,8 @@ void SbRtl_InStr(StarBASIC *, SbxArray & rPar, bool)
{ {
const sal_uInt32 nArgCount = rPar.Count() - 1; const sal_uInt32 nArgCount = rPar.Count() - 1;
if ( nArgCount < 2 ) if ( nArgCount < 2 )
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
else
{
sal_Int32 nStartPos = 1; sal_Int32 nStartPos = 1;
sal_Int32 nFirstStringPos = 1; sal_Int32 nFirstStringPos = 1;
@@ -858,7 +857,6 @@ void SbRtl_InStr(StarBASIC *, SbxArray & rPar, bool)
} }
rPar.Get(0)->PutLong(nPos); rPar.Get(0)->PutLong(nPos);
} }
}
// InstrRev(string1, string2[, start[, compare]]) // InstrRev(string1, string2[, start[, compare]])
@@ -1041,10 +1039,8 @@ void SbRtl_Mid(StarBASIC *, SbxArray & rPar, bool bWrite)
int nArgCount = rPar.Count() - 1; int nArgCount = rPar.Count() - 1;
if ( nArgCount < 2 ) if ( nArgCount < 2 )
{ {
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
} }
else
{
// #23178: replicate the functionality of Mid$ as a command // #23178: replicate the functionality of Mid$ as a command
// by adding a replacement-string as a fourth parameter. // by adding a replacement-string as a fourth parameter.
// In contrast to the original the third parameter (nLength) // In contrast to the original the third parameter (nLength)
@@ -1057,10 +1053,9 @@ void SbRtl_Mid(StarBASIC *, SbxArray & rPar, bool bWrite)
sal_Int32 nStartPos = rPar.Get(2)->GetLong(); sal_Int32 nStartPos = rPar.Get(2)->GetLong();
if ( nStartPos < 1 ) if ( nStartPos < 1 )
{ {
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
} }
else
{
nStartPos--; nStartPos--;
sal_Int32 nLen = -1; sal_Int32 nLen = -1;
bool bWriteNoLenParam = false; bool bWriteNoLenParam = false;
@@ -1136,8 +1131,6 @@ void SbRtl_Mid(StarBASIC *, SbxArray & rPar, bool bWrite)
rPar.Get(0)->PutString(aResultStr); rPar.Get(0)->PutString(aResultStr);
} }
} }
}
}
void SbRtl_Oct(StarBASIC *, SbxArray & rPar, bool) void SbRtl_Oct(StarBASIC *, SbxArray & rPar, bool)
{ {
@@ -1313,45 +1306,37 @@ void SbRtl_Space(StarBASIC *, SbxArray & rPar, bool)
{ {
if (rPar.Count() < 2) if (rPar.Count() < 2)
{ {
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
} }
else
{
const sal_Int32 nCount = rPar.Get(1)->GetLong(); const sal_Int32 nCount = rPar.Get(1)->GetLong();
OUStringBuffer aBuf(nCount); OUStringBuffer aBuf(nCount);
string::padToLength(aBuf, nCount, ' '); string::padToLength(aBuf, nCount, ' ');
rPar.Get(0)->PutString(aBuf.makeStringAndClear()); rPar.Get(0)->PutString(aBuf.makeStringAndClear());
} }
}
void SbRtl_Sqr(StarBASIC *, SbxArray & rPar, bool) void SbRtl_Sqr(StarBASIC *, SbxArray & rPar, bool)
{ {
if (rPar.Count() < 2) if (rPar.Count() < 2)
{ {
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
} }
else
{
double aDouble = rPar.Get(1)->GetDouble(); double aDouble = rPar.Get(1)->GetDouble();
if ( aDouble >= 0 ) if ( aDouble < 0 )
{ {
return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
rPar.Get(0)->PutDouble(sqrt(aDouble)); rPar.Get(0)->PutDouble(sqrt(aDouble));
} }
else
{
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
}
}
}
void SbRtl_Str(StarBASIC *, SbxArray & rPar, bool) void SbRtl_Str(StarBASIC *, SbxArray & rPar, bool)
{ {
if (rPar.Count() < 2) if (rPar.Count() < 2)
{ {
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
} }
else
{
OUString aStr; OUString aStr;
OUString aStrNew(u""_ustr); OUString aStrNew(u""_ustr);
SbxVariableRef pArg = rPar.Get(1); SbxVariableRef pArg = rPar.Get(1);
@@ -1403,7 +1388,6 @@ void SbRtl_Str(StarBASIC *, SbxArray & rPar, bool)
} }
rPar.Get(0)->PutString(aStrNew); rPar.Get(0)->PutString(aStrNew);
} }
}
void SbRtl_StrComp(StarBASIC *, SbxArray & rPar, bool) void SbRtl_StrComp(StarBASIC *, SbxArray & rPar, bool)
{ {
@@ -1474,10 +1458,9 @@ void SbRtl_String(StarBASIC *, SbxArray & rPar, bool)
{ {
if (rPar.Count() < 2) if (rPar.Count() < 2)
{ {
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
} }
else
{
sal_Unicode aFiller; sal_Unicode aFiller;
sal_Int32 lCount = rPar.Get(1)->GetLong(); sal_Int32 lCount = rPar.Get(1)->GetLong();
if( lCount < 0 || lCount > 0xffff ) if( lCount < 0 || lCount > 0xffff )
@@ -1497,58 +1480,51 @@ void SbRtl_String(StarBASIC *, SbxArray & rPar, bool)
string::padToLength(aBuf, lCount, aFiller); string::padToLength(aBuf, lCount, aFiller);
rPar.Get(0)->PutString(aBuf.makeStringAndClear()); rPar.Get(0)->PutString(aBuf.makeStringAndClear());
} }
}
void SbRtl_Tab(StarBASIC *, SbxArray & rPar, bool) void SbRtl_Tab(StarBASIC *, SbxArray & rPar, bool)
{ {
if (rPar.Count() < 2) if (rPar.Count() < 2)
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
else
{ {
return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
}
const sal_Int32 nCount = std::max(rPar.Get(1)->GetLong(), sal_Int32(0)); const sal_Int32 nCount = std::max(rPar.Get(1)->GetLong(), sal_Int32(0));
OUStringBuffer aStr(nCount); OUStringBuffer aStr(nCount);
comphelper::string::padToLength(aStr, nCount, '\t'); comphelper::string::padToLength(aStr, nCount, '\t');
rPar.Get(0)->PutString(aStr.makeStringAndClear()); rPar.Get(0)->PutString(aStr.makeStringAndClear());
} }
}
void SbRtl_Tan(StarBASIC *, SbxArray & rPar, bool) void SbRtl_Tan(StarBASIC *, SbxArray & rPar, bool)
{ {
if (rPar.Count() < 2) if (rPar.Count() < 2)
{ {
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
} }
else
{
SbxVariableRef pArg = rPar.Get(1); SbxVariableRef pArg = rPar.Get(1);
rPar.Get(0)->PutDouble(tan(pArg->GetDouble())); rPar.Get(0)->PutDouble(tan(pArg->GetDouble()));
} }
}
void SbRtl_UCase(StarBASIC *, SbxArray & rPar, bool) void SbRtl_UCase(StarBASIC *, SbxArray & rPar, bool)
{ {
if (rPar.Count() < 2) if (rPar.Count() < 2)
{ {
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
} }
else
{
const CharClass& rCharClass = GetCharClass(); const CharClass& rCharClass = GetCharClass();
OUString aStr(rPar.Get(1)->GetOUString()); OUString aStr(rPar.Get(1)->GetOUString());
aStr = rCharClass.uppercase( aStr ); aStr = rCharClass.uppercase( aStr );
rPar.Get(0)->PutString(aStr); rPar.Get(0)->PutString(aStr);
} }
}
void SbRtl_Val(StarBASIC *, SbxArray & rPar, bool) void SbRtl_Val(StarBASIC *, SbxArray & rPar, bool)
{ {
if (rPar.Count() < 2) if (rPar.Count() < 2)
{ {
StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT);
} }
else
{
double nResult = 0.0; double nResult = 0.0;
char* pEndPtr; char* pEndPtr;
@@ -1594,7 +1570,6 @@ void SbRtl_Val(StarBASIC *, SbxArray & rPar, bool)
rPar.Get(0)->PutDouble(nResult); rPar.Get(0)->PutDouble(nResult);
} }
}
// Helper functions for date conversion // Helper functions for date conversion