mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-07 22:47:59 +02:00
* patch by Bart B. to improve DelSpace1, resolves #39465
+ test
(cherry picked from commit 60c26a11ef
)
This commit is contained in:
parent
18d4d2cfc8
commit
55d25eea07
@ -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;
|
||||
|
24
tests/test/packages/rtl-objpas/tdelspace1.pp
Normal file
24
tests/test/packages/rtl-objpas/tdelspace1.pp
Normal 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.
|
Loading…
Reference in New Issue
Block a user