From 476f75802a538fb3576cdac996fca6c348913d6f Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Fri, 9 Jan 2015 09:31:01 +0000 Subject: Resolves: #i94895# fix illegal result of Replace runtime function" and adjust the basic test-case, which is surely wrong The syntax for REPLACE is: // Replace(expression, find, replace[, start[, count[, compare]]]) surely in the case of a start of 3 the preceeding chars should be returned unchanged in the result, not stripped off as before this change. This reverts commit 869402a58720b45e7227438b2e56e5a9532c0000. Change-Id: Ie710e4de9e7e35c84abe2770142a963532820af4 --- basic/qa/vba_tests/replace.vb | 2 +- basic/source/runtime/methods.cxx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/basic/qa/vba_tests/replace.vb b/basic/qa/vba_tests/replace.vb index e04cde058eb2..bd4817b1e455 100644 --- a/basic/qa/vba_tests/replace.vb +++ b/basic/qa/vba_tests/replace.vb @@ -37,7 +37,7 @@ Function verify_testReplace() as String retStr = Replace(srcStr, destStr, repStr, compare:=vbTextCompare) TestLog_ASSERT retStr = "aefefdef", "text compare:" & retStr retStr = Replace(srcStr, destStr, repStr, 3, -1, vbBinaryCompare) - TestLog_ASSERT retStr = "cefdBc", "start = 3:" & retStr + TestLog_ASSERT retStr = "abcefdBc", "start = 3:" & retStr retStr = Replace(srcStr, destStr, repStr, 1, 2, vbBinaryCompare) TestLog_ASSERT retStr = "aefefdBc", "count = 2: " & retStr retStr = Replace(srcStr, destStr, repStr, 1, 0, vbBinaryCompare) diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx index 7ccbab73430d..baa9603afbae 100644 --- a/basic/source/runtime/methods.cxx +++ b/basic/source/runtime/methods.cxx @@ -1405,7 +1405,7 @@ RTLFUNC(Replace) if( nPos >= 0 ) { aExpStr = aExpStr.replaceAt( nPos, nFindStrLen, aReplaceStr ); - nPos = nPos - nFindStrLen + nReplaceStrLen + 1; + nPos = nPos + nReplaceStrLen; nCounts++; } else @@ -1414,7 +1414,7 @@ RTLFUNC(Replace) } } } - rPar.Get(0)->PutString( aExpStr.copy( lStartPos - 1 ) ); + rPar.Get(0)->PutString( aExpStr ); } } -- cgit v1.2.3