function espace(check: string): Boolean;
procedure GO(txt: string; var msg: string);
procedure UNGO(txt: string; var msg: string);
implementation
var respecterCasse: Boolean = true;
var ignorerCasse: Boolean = false;
var motsEntiers: Boolean = true;
var touteSousChaine: Boolean = false;
function rechercher(cible,terme: string; respecterCasse,motSeulement: Boolean): Boolean;
var
ind: Integer;
suivant: Integer;
avant: Integer;
apres: Integer;
begin
suivant := 0;
if (not respecterCasse) then
begin
terme := LowerCase(terme);
cible := LowerCase(cible);
end;
ind := PosEx(terme, cible, suivant);
while (ind >= 1) do
begin
if (motSeulement) then
begin
avant := ind - 1;
apres := ind + Length(terme);
if (avant > 0) and (apres > 0)then
begin
if (not (espace(cible[avant]) and espace(cible[apres]))) then
begin
suivant := ind + Length(terme);
ind := PosEx(terme, cible, suivant);
continue;
end;
end;
end;
Result := true;
Exit;
end;
Result := False;
end;
function remplacer(cible, ancienTerme,nouveauTerme: string;
respecterCasse: Boolean = False; motSeulement: Boolean = False): string;
var
travail: string;
ind: Integer;
suivant: Integer;
avant: Integer;
apres: Integer;
begin
travail := cible;
suivant := 1;
if (not respecterCasse) then
begin
ancienTerme := LowerCase(ancienTerme);
travail := LowerCase(cible);
end;
ind := PosEx(ancienTerme, travail, suivant);
while (ind >= 1) do
begin
if (motSeulement) then
begin
avant := ind - 1;
apres := ind + Length(ancienTerme);
if (avant > 0) and (apres > 0)then
begin
if (not ((espace(travail[avant])) and espace(travail[apres]))) then
begin
suivant := ind + Length(ancienTerme);
ind := PosEx(ancienTerme, travail, suivant);
continue;
end;
end;
end;
cible := Copy(cible, 1, ind -1) + nouveauTerme +
Copy(cible, ind + Length(ancienTerme), Length(cible));
travail := Copy(travail, 1, ind -1) + nouveauTerme +
Copy(travail, ind+Length(ancienTerme),Length(travail));
suivant := ind + Length(nouveauTerme);
if (suivant >= Length(travail)) then break;
ind := PosEx(ancienTerme, travail, suivant);
end;
Result := cible;
end;
function espace(check: string): Boolean;
var
esp: string;
i: Integer;
begin
Result := True;
// esp = ' ,/<>?!`'';:%^&()=|beginend;' + '''' + '\\\n\t';
esp := ' ,/<>?!`'';:%^&()=|beginend;' + '"' + '\'#13#10#9;
if check = '' then Exit;
for i := 1 to Length(esp) do
if check = esp[i] then Exit;
Result := False;
end;
// STOP HIDING -->
var CARACTERES: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ[@*]$#';
function CODE(LETTRE: string): string;
var
tg: Integer;
LT: string;
begin
if(LETTRE = ' ') then
begin
Result := ' ';
Exit;
end;
for tg := 1 to 32 do
begin
LT := CARACTERES[tg];
if(LT = LETTRE) then
begin
Result := MORSE[tg];
Exit;
end;
end;
Result := '';
end;
procedure GO(txt: string; var msg: string);
var
t, num: Integer;
ltr: Char;
begin
txt := UpperCase(txt);
msg := '';
NUM := Length(txt);
t := 1;
while (t <= NUM) do
begin
if (txt[t]= '^') then
begin
Inc(t);
LTR := txt[t];
case (LTR) of
'C', 'c': LTR := '[';
'G', 'g': LTR := '@';
'H', 'h': LTR := '*';
'J', 'j': LTR := ']';
'S', 's': LTR := '$';
'U', 'u': LTR := '#';
end;
end else
begin
LTR := txt[t];
end;
MSG := MSG + ( CODE(LTR) + ' ') ;
Inc(t);
end;
end;
procedure UNGO(txt: string; var msg: string);
var
th: Integer;
AA: string;
BB: string;
begin
txt := UpperCase(txt);
MSG := txt + ' ';
for th := 1 to 32 do
begin
AA := MORSE[th];
BB := CARACTERES[th];
Msg := remplacer(Msg, AA, BB, False, True);
end;
Msg := remplacer(Msg, ' ','%');
Msg := remplacer(Msg, ' ','');
Msg := remplacer(Msg, '%',' ');
end;