* patch by Bart B. to improve DelSpace1, resolves #39465

+ test

(cherry picked from commit 60c26a11ef)
This commit is contained in:
Florian Klämpfl 2021-12-09 22:51:13 +01:00 committed by marcoonthegit
parent 18d4d2cfc8
commit 55d25eea07
2 changed files with 42 additions and 4 deletions

View File

@ -2037,13 +2037,27 @@ end;
function DelSpace1(const S: string): string;
var
I : SizeInt;
I,J: SizeInt;
begin
Result:=S;
for i:=Length(Result) downto 2 do
if (Result[i]=' ') and (Result[I-1]=' ') then
Delete(Result,I,1);
I:=Length(Result);
While I>0 do
begin
if Result[I]=#32 then
begin
J:=I-1;
While (J>0) and (Result[J]=#32) do
Dec(j);
Inc(J);
if I<>J then
begin
Delete(Result,J+1,I-J);
I:=J+1;
end;
end;
dec(I);
end;
end;
function Tab2Space(const S: string; Numb: Byte): string;

View File

@ -0,0 +1,24 @@
uses
strutils;
begin
if DelSpace1('asdf')<>'asdf' then
halt(1);
if DelSpace1(' asdf')<>' asdf' then
halt(2);
if DelSpace1('asdf ')<>'asdf ' then
halt(3);
if DelSpace1(' asdf')<>' asdf' then
halt(4);
if DelSpace1('asdf ')<>'asdf ' then
halt(5);
if DelSpace1('as df')<>'as df' then
halt(6);
if DelSpace1('as df')<>'as df' then
halt(7);
if DelSpace1(' a s d f')<>' a s d f' then
halt(8);
if DelSpace1(' a b c ')<>' a b c ' then
halt(9);
writeln('ok')
end.