diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2018-11-13 13:05:01 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2018-11-13 15:26:09 +0100 |
commit | a6a48eeef16e473be14642469cd922f177f54998 (patch) | |
tree | 66c91a93a1b0a22f3cefce3c9e5d269a003305cf /basic/source | |
parent | 4866a441cab472c1f44360abdc7074097aad1a26 (diff) |
tdf#121325: Replace all of given length, even if replacement is shorter
Both LO and MS Basic restrict the amount of replacement text ("If the Length
parameter in the <emph>Mid statement</emph> is less than the length of the text
that you want to replace, the text is reduced to the specified length." in
helpcontent2/source/text/sbasic/shared/03120306.xhp, resp. "The number of
characters replaced is always less than or equal to the number of characters in
Target." at <https://docs.microsoft.com/en-us/dotnet/visual-basic/
language-reference/statements/mid-statement>).
But cc20344010e94eda22fee662aab966d395a0796a "tdf#111313: Honor bWriteNoLenParam
in !bCompatibility, too" had introduced a regression (in the non--compatibility-
mode case), restricting the amount of replaced text to be no more than the
amount of replacement text, even if the given length argument was larger.
(Which had already regressed in the past, see
<https://bugs.documentfoundation.org/show_bug.cgi?id=62090> "Mid statement
doesn't work as expected".)
Added test cases now.
Change-Id: I21d4409f49a2437eb0e1a1e200561d803c42a24c
Reviewed-on: https://gerrit.libreoffice.org/63328
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'basic/source')
-rw-r--r-- | basic/source/runtime/methods.cxx | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx index 20348c850839..b2f639e1a6c4 100644 --- a/basic/source/runtime/methods.cxx +++ b/basic/source/runtime/methods.cxx @@ -1159,26 +1159,22 @@ void SbRtl_Mid(StarBASIC *, SbxArray & rPar, bool bWrite) sal_Int32 nReplaceLen; if( bWriteNoLenParam ) { - nReplaceLen = nReplaceStrLen; + nReplaceLen = nArgLen - nStartPos; } else { nReplaceLen = nLen; - if( nReplaceLen < 0 || nReplaceLen > nReplaceStrLen ) + if( nReplaceLen < 0 || nReplaceLen > nArgLen - nStartPos ) { - nReplaceLen = nReplaceStrLen; + nReplaceLen = nArgLen - nStartPos; } } - sal_Int32 nReplaceEndPos = nStartPos + nReplaceLen; - if( nReplaceEndPos > nArgLen ) - { - nReplaceLen -= (nReplaceEndPos - nArgLen); - } OUStringBuffer aResultStr = aArgStr; sal_Int32 nErase = nReplaceLen; aResultStr.remove( nStartPos, nErase ); - aResultStr.insert( nStartPos, aReplaceStr.getStr(), nReplaceLen); + aResultStr.insert( + nStartPos, aReplaceStr.getStr(), std::min(nReplaceLen, nReplaceStrLen)); rPar.Get(1)->PutString( aResultStr.makeStringAndClear() ); } |