Ignore:
Timestamp:
Nov 17, 2010, 7:34:05 PM (14 years ago)
Author:
george
Message:
  • Added: Method Explode to create list items from string.
  • Modified: Definition for procedural type TGListStringConverter changed to TGListToStringConverter and TFListFromStringConverter.
  • Modified: Sepcialized unit ListObject renamed to SpecializedObjectList.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Generics/TemplateGenerics/Generic/GenericList.inc

    r90 r91  
    44
    55  TGListSortCompare = function(const Item1, Item2: TGListItem): Integer of object;
    6   TGListStringConverter = function(Item: TGListItem): string;
    7   //TGListNotification = (lnAdded, lnExtracted, lnDeleted);
     6  TGListToStringConverter = function(Item: TGListItem): string;
     7  TGListFromStringConverter = function(Text: string): TGListItem;
    88
    99  // TGList<TGListIndex, TGListItem> = class
     
    3131    procedure Delete(Index: TGListIndex); virtual;
    3232    procedure DeleteItems(Index, Count: TGListIndex);
    33     function Equals(List: TGList): Boolean;
     33    function EqualTo(List: TGList): Boolean;
    3434    procedure Expand;
    3535    function Extract(Item: TGListItem): TGListItem;
     
    3737    property First: TGListItem read GetFirst write SetFirst;
    3838    procedure Fill(Start, Count: TGListIndex; Value: TGListItem);
    39     function Implode(Separator: string; Converter: TGListStringConverter): string;
     39    function Implode(Separator: string; Converter: TGListToStringConverter): string;
     40    procedure Explode(Text, Separator: string; Converter: TGListFromStringConverter; SlicesCount: Integer = -1);
    4041    function IndexOf(Item: TGListItem; Start: TGListIndex = 0): TGListIndex;
    4142    function IndexOfList(List: TGList; Start: TGListIndex = 0): TGListIndex;
     
    304305end;
    305306
    306 function TGList.Equals(List: TGList): Boolean;
     307function TGList.EqualTo(List: TGList): Boolean;
    307308var
    308309  I: TGListIndex;
     
    372373end;
    373374
    374 function TGList.Implode(Separator: string; Converter: TGListStringConverter): string;
     375function TGList.Implode(Separator: string; Converter: TGListToStringConverter): string;
    375376var
    376377  I: TGListIndex;
     
    384385    I := I + 1;
    385386  end;
     387end;
     388
     389procedure TGList.Explode(Text, Separator: string; Converter: TGListFromStringConverter; SlicesCount: Integer = -1);
     390begin
     391  Clear;
     392  while (Pos(Separator, Text) > 0) and
     393  ((Count < (SlicesCount - 1)) or (SlicesCount = -1)) do begin
     394    Add(Converter(Copy(Text, 1, Pos(Separator, Text) - 1)));
     395    System.Delete(Text, 1, Pos(Separator, Text) + Length(Separator) - 1);
     396  end;
     397  Add(Converter(Text));
    386398end;
    387399
Note: See TracChangeset for help on using the changeset viewer.