#1 2015-12-07 00:48:26

GoSane
Member
From: France
Registered: 2015-12-06
Posts: 5
Website

Bug in Trim() ?

When using SynCommons.Trim() on a (string) variant and placing the result in another (string) variant, we lose all accented characters. No problem when using SysUtils.Trim.

Uses SynCommons;

procedure TForm2.Button1Click(Sender: TObject);
var st  : String;
    v,v2    : Variant;
begin
  v:='sérieux  ';
  v2:=Trim(v);
  st:=v2;
  showmessage(v+' => '+st); // st contains "srieux"
end;

Using mORMot framework 1.18 (today's nightly build) on Delphi 2010

Offline

#2 2015-12-07 06:36:44

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,666
Website

Re: Bug in Trim() ?

This is how the compiler works.

It makes wrong conversions in this case.

When using variants, always make explicit  conversions to string.

Offline

#3 2015-12-07 15:50:04

GoSane
Member
From: France
Registered: 2015-12-06
Posts: 5
Website

Re: Bug in Trim() ?

But SysUtils.Trim() works as expected (by just removing the line "Uses SynCommons;") so I see this as a bug.

Offline

#4 2015-12-07 16:18:01

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,666
Website

Re: Bug in Trim() ?

No, this is more likely a compiler bug.
The compiler is not clever enough to efficiently convert a variant into a RawUTF8 variable.

If you try

v2 := UTF8ToString(Trim(VariantToUTF8(v)));

that is, if you avoid hidden comparison made by the compiler, it should be fine.

BTW, did you notice the compiler warnings/hints in your source code?
Do not let them happen.

Offline

#5 2015-12-07 18:50:49

GoSane
Member
From: France
Registered: 2015-12-06
Posts: 5
Website

Re: Bug in Trim() ?

Ok I get it, thanks for the explanations and for pointing me to the warnings. And for the great component !

Offline

Board footer

Powered by FluxBB