Sign in Join

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

Mailing lists / fpc-pascal / 2016-03

TStringHelper.Split() issue?

7 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

silvioprog

Hello,

Just test this code below:

=== code ===

program Project1;
{$mode delphi}
uses
  SysUtils;
var
  content: string = 'x:y';
  splited: TArray<string>;
begin
  splited := content.Split([':']);
  WriteLn(Length(splited));
  ReadLn;
end.

=== /code ===

On FPC, it returns 1, on Delphi, it returns 2. And debuging the "splited" variable, on FPC I get only and "x" value, Delphi "x" and "y".

Is this a bug?

Silvio Clécio
Michael Van Canneyt
to silvioprog
silvioprog wrote 28 lines
Hello, Just test this code below: === code === program Project1; {$mode delphi} uses SysUtils; var content: string = 'x:y'; splited: TArray<string>; begin splited := content.Split([':']); WriteLn(Length(splited)); ReadLn; end. === /code === On FPC, it returns 1, on Delphi, it returns 2. And debuging the "splited" variable, on FPC I get only and "x" value, Delphi "x" and "y". Is this a bug?

Yes. Quite strange, because I have testcases for this ?

Michael.

silvioprog
to Michael Van Canneyt

On Tue, Mar 8, 2016 at 12:03 PM, Michael Van Canneyt <

wrote:

[...]

Yes. Quite strange, because I have testcases for this ?

It happens only when the second part of string has only one character, two or more (eg "content: string = 'x:yy'") it works.

Silvio Clécio
Michael Van Canneyt
to silvioprog
silvioprog wrote 9 lines
On Tue, Mar 8, 2016 at 12:03 PM, Michael Van Canneyt < > wrote: [...] > > Yes. Quite strange, because I have testcases for this ? It happens only when the second part of string has only one character, two or more (eg "content: string = 'x:yy'") it works.

Please report a bug !

Michael.

Rik van Kekem
to Michael Van Canneyt: Yes. Quite strange, because I have testcases for this ? Michael.
Michael Van Canneyt wrote 7 lines
> > On FPC, it returns 1, on Delphi, it returns 2. And debuging the "splited" > variable, on FPC I get only and "x" value, Delphi "x" and "y". > > Is this a bug? Yes. Quite strange, because I have testcases for this ?

And content: string = 'x:yb'; does work correctly.

The problem is in this line (Line 1196 of syshelp.inc):
   if (LastSep<Length-1) and ((ACount=0) or (Len<ACount)) then

In this case LastSep is 2 and Length - 1 is also 2. So the last y doesn't get into the array.

Grtz,
Rik

Michael Van Canneyt
to Rik van Kekem: And content: string = 'x:yb'; does work correctly. The problem is in this line (Line 1196…
Rik van Kekem wrote 16 lines
Michael Van Canneyt wrote: >> >> On FPC, it returns 1, on Delphi, it returns 2. And debuging the "splited" >> variable, on FPC I get only and "x" value, Delphi "x" and "y". >> >> Is this a bug? > > Yes. Quite strange, because I have testcases for this ? And content: string = 'x:yb'; does work correctly. The problem is in this line (Line 1196 of syshelp.inc): if (LastSep<Length-1) and ((ACount=0) or (Len<ACount)) then In this case LastSep is 2 and Length - 1 is also 2. So the last y doesn't get into the array.

Indeed, this is the problem. Fixed in rev. 33209.
Added testcase to my testsuite.

Probably the zero-based nature of these methods got me confused :/

Michael.