
unit STRINGS2;

interface

uses
  CYPHER;

(*function LeftString (Tekst : string; Getal : byte) : string;
function RightString (Tekst : string; Getal : byte) : string;
function MidString (Tekst : string; Start, Len : byte) : string;
function StringCat (Tekst1, Tekst2 : string) : string;
function StringLength (Tekst : string) : byte;
function CompareStrings (Tekst1, Tekst2 : string) : shortint;
*)
function TranslateBASICStringExpression (Tekst : string) : string;

implementation

function LeftString (Tekst : string; Getal : byte) : string;
  begin
    Tekst[0]:= char(Getal);
    LeftString:= Tekst;
  end;

function RightString (Tekst : string; Getal : byte) : string;
  begin
    RightString:= copy (Tekst, length(Tekst)-Getal+1, Getal);
  end;

function MidString (Tekst : string; Start, Len : byte) : string;
  begin
    MidString:= copy (Tekst, Start, Len);
  end;

function StringCat (Tekst1, Tekst2 : string) : string;
  begin
    StringCat:= Tekst1 + Tekst2;
  end;

function StringLength (Tekst : string) : byte;
  begin
    StringLength:= length (Tekst);
  end;

function CompareStrings (Tekst1, Tekst2 : string) : shortint;
  var
    Equal, SmallerThan, GreaterThan : boolean;
  begin
    Equal:= false;
    SmallerThan:= false;
    GreaterThan:= false;
    Equal:= (Tekst1 = Tekst2);
    SmallerThan := (Tekst1 < Tekst2);
    GreaterThan := (Tekst1 > Tekst2);
    if Equal then
      CompareStrings:= 0
        else if SmallerThan then
          CompareStrings:= -1
            else
              CompareStrings:= 1;
  end;

function TranslateBASICStringExpression (Tekst : string) : string;
  var
    Temp, Temp2 : string;
    B           : shortint;
  begin
    if Tekst = '' then begin
      TranslateBasicStringExpression:= '';
      exit;
    end;
    if pos('=', Tekst) > 0 then begin
      Temp:= ANYTHING (copy (Tekst, 1, pos('=', Tekst)-1));
      Temp2:= TranslateBASICSTRINGEXPRESSION (copy (Tekst, pos('=', Tekst)+1, 255));
      B:= CompareStrings (Temp, Temp2);
      case B of
        0: TranslateBasicStringExpression:= '1';
        else TransLateBasicStringExpression:= '0';
      end;
    end else
    if pos('<', Tekst) > 0 then begin
      Temp:= ANYTHING (copy (Tekst, 1, pos('<', Tekst)-1));
      Temp2:= TranslateBASICSTRINGEXPRESSION (copy (Tekst, pos('<', Tekst)+1, 255));
      B:= CompareStrings (Temp, Temp2);
      case B of
        -1: TranslateBasicStringExpression:= '0';
        else TransLateBasicStringExpression:= '1';
      end;
    end else
    if pos('>', Tekst) > 0 then begin
      Temp:= ANYTHING (copy (Tekst, 1, pos('>', Tekst)-1));
      Temp2:= TranslateBASICSTRINGEXPRESSION (copy (Tekst, pos('>', Tekst)+1, 255));
      B:= CompareStrings (Temp, Temp2);
      case B of
        1: TranslateBasicStringExpression:= '0';
        else TransLateBasicStringExpression:= '1';
      end;
    end else
    TranslateBASICStringExpression:= ANYTHING (Tekst);
  end;

begin
end.