View Issue Details

IDProjectCategoryView StatusLast Update
0035669FPCRTLpublic2019-06-03 08:34
ReporterSerge AnvarovAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformWindowsOSOS Version
Product Version3.0.4Product Build 
Target VersionFixed in Version3.3.1 
Summary0035669: For a string that ends with the delimiter, split returns one string too little.
DescriptionContinue 0035663
Steps To Reproduce{$APPTYPE CONSOLE}
{$IFDEF FPC}{$MODE DELPHI}{$ENDIF}

uses SysUtils;

const
  CA: array[0..7] of string = ('F0;F1;F2', ';F1;F2', ';;F2', 'F0;;F2', ';;', 'F0;F1;', 'F0;;', ';F1;');
var
  S: string;
  A: TArray<string>;
begin
  for S in CA do
  begin
    A := S.Split([';']);
    Writeln(S, ' = ':12-Length(S), Length(A));
  end;
  Readln;
end.
Additional InformationThis project shows four "3" and four "2". But should always show "3" as it is done in Delphi.
I think the error is somewhere in the borders instead of "<=" is used strictly "<".
FPC 3.3.1 same error.
TagsNo tags attached.
Fixed in Revision42168
FPCOldBugId
FPCTarget3.2.0
Attached Files

Relationships

has duplicate 0035663 resolvedMichael Van Canneyt For a string that ends with the delimiter, split returns one string too little. 

Activities

Michael Van Canneyt

2019-06-02 18:56

administrator   ~0116536

Delphi Tokio prints this:

F0;F1;F2 = 3
;F1;F2 = 3
;;F2 = 3
F0;;F2 = 3
;; = 2
F0;F1; = 2
F0;; = 2
;F1; = 2

The same as FPC

Serge Anvarov

2019-06-02 23:58

reporter   ~0116540

Delphi 10.3 (Rio):
F0;F1;F2 = 3
;F1;F2 = 3
;;F2 = 3
F0;;F2 = 3
;; = 3
F0;F1; = 3
F0;; = 3
;F1; = 3

And logically this is wrong. Why is the empty last section suddenly missing? It is worse than the other. If I don't need empty sections, I use the ExcludeEmpty option. If the ExcludeEmpty option is not set, all sections must be counted.

I extend the example to make it more obvious:
{$APPTYPE CONSOLE}
{$IFDEF FPC}{$MODE DELPHI}{$ENDIF}

uses Classes, SysUtils;

const
  CA: array[0..7] of string = ('F0;F1;F2', ';F1;F2', ';;F2', 'F0;;F2', ';;', 'F0;F1;', 'F0;;', ';F1;');
var
  S: string;
  A: TArray<string>;
  L: TStringList;
begin
  L := TStringList.Create;
  try
    L.Delimiter := ';';
    for S in CA do
    begin
      A := S.Split([';']);
      L.DelimitedText := S;
      Writeln(S, ' = ':12-Length(S), Length(A), '':3, L.Count);
    end;
  finally
    L.Free;
  end;
  Readln;
end.

Michael Van Canneyt

2019-06-03 00:07

administrator   ~0116541

I agree that the behaviour in Tokio (and Berlin, which I compared it to originally) is not logical. (see also the related bugreport)

But I don't have Rio so I can not check it in Rio. I take your word for it.

It's a simple fix, I'll fix it asap.

Michael Van Canneyt

2019-06-03 08:34

administrator   ~0116544

Fixed. It was a little more than just changing < to <=.

Issue History

Date Modified Username Field Change
2019-06-02 18:30 Serge Anvarov New Issue
2019-06-02 18:48 Michael Van Canneyt Assigned To => Michael Van Canneyt
2019-06-02 18:48 Michael Van Canneyt Status new => assigned
2019-06-02 18:54 Michael Van Canneyt Relationship added has duplicate 0035663
2019-06-02 18:56 Michael Van Canneyt Status assigned => resolved
2019-06-02 18:56 Michael Van Canneyt Resolution open => no change required
2019-06-02 18:56 Michael Van Canneyt FPCTarget => -
2019-06-02 18:56 Michael Van Canneyt Note Added: 0116536
2019-06-02 23:58 Serge Anvarov Status resolved => feedback
2019-06-02 23:58 Serge Anvarov Resolution no change required => reopened
2019-06-02 23:58 Serge Anvarov Note Added: 0116540
2019-06-03 00:07 Michael Van Canneyt Note Added: 0116541
2019-06-03 08:34 Michael Van Canneyt Status feedback => resolved
2019-06-03 08:34 Michael Van Canneyt Resolution reopened => fixed
2019-06-03 08:34 Michael Van Canneyt Fixed in Version => 3.3.1
2019-06-03 08:34 Michael Van Canneyt Fixed in Revision => 42168
2019-06-03 08:34 Michael Van Canneyt FPCTarget - => 3.2.0
2019-06-03 08:34 Michael Van Canneyt Note Added: 0116544