
unit Detect;

interface

function DetectEngineMove(const AText: string): string;
function DetectGuiMove(const AText: string): string;

implementation

uses
  SysUtils, RegExpr;

const
  CEngineMoveExpr = 'move ([a-h][1-8][a-h][1-8])';
  CGuiMoveExpr = '^(usermove )?[a-h][1-8][a-h][1-8][rnbq]?$';
  
var
  LEngineMoveExpr, LGuiMoveExpr: TRegExpr;

function DetectEngineMove(const AText: string): string;
begin
  if LEngineMoveExpr.Exec(AText) then
    result := LEngineMoveExpr.Match[1]
  else
    result := EmptyStr;
end;

function DetectGuiMove(const AText: string): string;
begin
  if LGuiMoveExpr.Exec(AText) then
    result := LGuiMoveExpr.Match[0]
  else
    result := EmptyStr;
end;

initialization
  LEngineMoveExpr := TRegExpr.Create(CEngineMoveExpr);
  LGuiMoveExpr := TRegExpr.Create(CGuiMoveExpr);

finalization
  LEngineMoveExpr.Free;
  LGuiMoveExpr.Free;

end.
