Trim(): incompatibility with Delphi

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Trim(): incompatibility with Delphi

Bart-48
Hi,

Brought up in Lazarus forums.

Fpc Trim(): Trim whitespace from the ends of a string.
Delphi Trim(): Trims leading and trailing spaces and control
characters from a string.

Bug or by design?

Bart
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Trim(): incompatibility with Delphi

leledumbo
Administrator
> Fpc Trim(): Trim whitespace from the ends of a string.

Where did you get that? The documentation (http://www.freepascal.org/docs-html/rtl/sysutils/trim.html) doesn't say so...
Reply | Threaded
Open this post in threaded view
|

Re: Trim(): incompatibility with Delphi

etrusco
On Mon, Mar 5, 2012 at 11:36 PM, leledumbo <[hidden email]> wrote:
>> Fpc Trim(): Trim whitespace from the ends of a string.
>
> Where did you get that? The documentation
> (http://www.freepascal.org/docs-html/rtl/sysutils/trim.html) doesn't say
> so...
>

And a simple test confirms the docs (FPC 2.6):

  ShowMessage(Trim('test             ') + Trim ('       !'));

-Flávio
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Trim(): incompatibility with Delphi

Mark Morgan Lloyd-5
Flávio Etrusco wrote:

> On Mon, Mar 5, 2012 at 11:36 PM, leledumbo <[hidden email]> wrote:
>>> Fpc Trim(): Trim whitespace from the ends of a string.
>> Where did you get that? The documentation
>> (http://www.freepascal.org/docs-html/rtl/sysutils/trim.html) doesn't say
>> so...
>>
>
> And a simple test confirms the docs (FPC 2.6):
>
>   ShowMessage(Trim('test             ') + Trim ('       !'));

More to the point, putting in control characters instead of spaces:

program trimtest;

uses SysUtils;

begin
   WriteLn(Trim('test' + #$0d + #$0a) + Trim (#$0d + #$0a + '!'))
end.

test!

Unless there's some weird locale-specific problem.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Trim(): incompatibility with Delphi

michael.vancanneyt
In reply to this post by Bart-48


On Mon, 5 Mar 2012, Bart wrote:

> Hi,
>
> Brought up in Lazarus forums.
>
> Fpc Trim(): Trim whitespace from the ends of a string.
> Delphi Trim(): Trims leading and trailing spaces and control
> characters from a string.

Depends on what you mean by whitespace, of course.
FPC strips everything below Ord(' '), and thus should behave the same as Delphi.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Trim(): incompatibility with Delphi

Bernd Kreuss
The documentation is incorrect. It says:

"Description

Trim strips blank characters (spaces) at the beginning and end of S
and returns the resulting string. Only #32 characters are stripped. "

But it will strip everything <= #32, not only #32 as the documentation
suggests. The same error is in the docs for TrimLeft() and TrimRight()
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Trim(): incompatibility with Delphi

patspiper
In reply to this post by michael.vancanneyt
On 06/03/12 11:00, [hidden email] wrote:


On Mon, 5 Mar 2012, Bart wrote:

Hi,

Brought up in Lazarus forums.

Fpc Trim(): Trim whitespace from the ends of a string.
Delphi Trim(): Trims leading and trailing spaces and control
characters from a string.

Depends on what you mean by whitespace, of course. FPC strips everything below Ord(' '), and thus should behave the same as Delphi.
From http://www.freepascal.org/docs-html/rtl/sysutils/trim.html:

"Trim strips blank characters (spaces) at the beginning and end of S and returns the resulting string. Only #32 characters are stripped."

Stephano

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Trim(): incompatibility with Delphi

Bart-48
In reply to this post by Bernd Kreuss
On 3/6/12, Bernd <[hidden email]> wrote:
> The documentation is incorrect. It says:
>

Yes, and I misread the actual implementation.
I was too lazy to write a test program.
I really shouldn't post "bugs" after 23:00 (local time).

Sorry for wasting your time.

Bart
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Trim(): incompatibility with Delphi

Graeme Geldenhuys-2
In reply to this post by Bernd Kreuss
On 6 March 2012 18:12, Bernd <prof7bit@g.....> wrote:
> The documentation is incorrect. It says:


As usual, please file a 'FPC >> Docs' bug report so the issue doesn't
get forgotten. It should be auto-assigned to Michael van Canneyt.
Supplying a documentation patch is always nice too.


--
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://fpgui.sourceforge.net
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Trim(): incompatibility with Delphi

michael.vancanneyt


On Wed, 7 Mar 2012, Graeme Geldenhuys wrote:

> On 6 March 2012 18:12, Bernd <prof7bit@g.....> wrote:
>> The documentation is incorrect. It says:
>
>
> As usual, please file a 'FPC >> Docs' bug report so the issue doesn't
> get forgotten. It should be auto-assigned to Michael van Canneyt.
> Supplying a documentation patch is always nice too.

No need. I already fixed the docs.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Trim(): incompatibility with Delphi

Bart-48
On 3/7/12, [hidden email] <[hidden email]> wrote:

> No need. I already fixed the docs.

You're writing (code/docs) faster than I can think ;-)

Bart
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Trim(): incompatibility with Delphi

Graeme Geldenhuys-2
On 7 March 2012 11:20, Bart <bartjunk64@*****> wrote:
>
> You're writing (code/docs) faster than I can think ;-)


Yeah, I'm jealous about that too.   Maybe he perfected his clones -
mine went totally haywire after a while! :-)



--
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://fpgui.sourceforge.net
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal