(*
/*
  [SYNTAX="PASCAL"]
*/
*)

unit KOL_parse{@||Parser};

interface

{$I KOLDEF.INC}

(*$ifdef al4*)
(*$else*)
uses KOL;
(*$endif*)

type
  PParser = ^TParser;
  TParser = object(TObj)
    S: String;
    function Parse(const Delim: String): String;
    destructor Destroy; virtual;
  end;

function NewParser(const S: String): PParser;

implementation

function NewParser(const S: String): PParser;
{@NEW}
begin
  (*$ifdef al4code*)
  Result = {Parser}
  (*$else*)
  new(Result, Create);
  (*$endif*)
  Result.S := S;
end;

{ TParser }

function TParser.Parse(const Delim: String): String;
begin
  (*$ifdef al4code*)
  INT found|_position = S.Len
  FOR i IN [0 TO Delim.Len-1] :
      INT pos|ition_of_delim = S.Find(Delim[i])
      CASE pos < found ? found = pos ;
  ;
  RESULT = S[0 TO found-1]
  S = S[found+1 TO *]
  (*$else*)
  Result := KOL.Parse(S, Delim);
  (*$endif*)
end;

destructor TParser.Destroy;
begin
    S := '';
    inherited;
end;

end.
