mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-08 23:18:01 +02:00
lazutils: fixed ReplaceSubString not changing original string
git-svn-id: trunk@35507 -
This commit is contained in:
parent
2e114fe055
commit
9a2c21130a
@ -953,6 +953,7 @@ begin
|
||||
if InsertionLen<Count then begin
|
||||
// shorten
|
||||
if RestLen>0 then begin
|
||||
UniqueString(s);
|
||||
p:=PByte(s)+StartPos-1;
|
||||
System.Move((p+Count)^,(p+InsertionLen)^,RestLen);
|
||||
end;
|
||||
|
@ -32,9 +32,14 @@ procedure TTestLazUtils.TestReplaceSubstring;
|
||||
|
||||
function r(const s: string; StartPos, Count: SizeInt;
|
||||
const Insertion: string): string;
|
||||
var
|
||||
OldS: String;
|
||||
begin
|
||||
Result:=s;
|
||||
OldS:=s;
|
||||
UniqueString(OldS);
|
||||
ReplaceSubstring(Result,StartPos,Count,Insertion);
|
||||
AssertEquals('s unchanged',OldS,s);
|
||||
end;
|
||||
|
||||
begin
|
||||
@ -51,8 +56,10 @@ begin
|
||||
AssertEquals('last char multi','ababc',r('abc',3,1,'abc'));
|
||||
AssertEquals('middle char same','abc',r('abc',2,1,'b'));
|
||||
AssertEquals('middle char single','adc',r('abc',2,1,'d'));
|
||||
AssertEquals('middle char multi','acdec',r('abc',2,1,'cde'));
|
||||
AssertEquals('middle char longen','acdec',r('abc',2,1,'cde'));
|
||||
AssertEquals('last multi','adef',r('abc',2,2,'def'));
|
||||
AssertEquals('middle chars same','abcde',r('abcde',2,3,'bcd'));
|
||||
AssertEquals('middle chars shorten','axe',r('abcde',2,3,'x'));
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
Loading…
Reference in New Issue
Block a user