Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2000-03

Bug in Trim not in Pos ("PATCH")

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Cliff Baeseman

Here is a patch to a bug I found in the trim function in the rtl.

It is inconsistant with delphi which removes the cr's and linefeeds the below copy works like delphi's. I just added the or's.

That one was causing me a bitch of a time porting my code if this would have been consistant with delphi it would have compiled on the first shot. For now in my parser I just copied it to my unit and called it StringTrim.

function Trim(const S: string): string;
var Ofs, Len: integer;
begin
  len := Length(S);
  while (Len>0) and (S[Len] = ' ') or (S[Len] = #10) or (S[Len] = #13) do
   dec(Len);
  Ofs := 1;
  while (Ofs<=Len) and (S[Ofs] = ' ') or (S[Ofs] = #10) or (S[Len] = #13) do
   Inc(Ofs);
  result := Copy(S, Ofs, 1 + Len - Ofs);
end ;

Cliff

Reply by email