Advertisement
tolikpunkoff

function Translit

Nov 25th, 2022
1,610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.19 KB | None | 0 0
  1. function Translit(Str:string):string;
  2. var Regex:TRegExpr;
  3.     Dict:TDictTrans;
  4.     Ch,oStr,oTrans:string;
  5.     I:LongInt;
  6. begin
  7.      Regex:=TRegExpr.Create;
  8.      Regex.Expression:='[А-Я]|[а-я]|\s';
  9.      if not Regex.Exec(Str) then begin
  10.        exit(Str);
  11.      end;
  12.      Dict:=TDictTrans.Create;
  13.      Dict.Add(' ','_');
  14.      Dict.Add('А','A'); Dict.Add('а','a');
  15.      Dict.Add('Б','B'); Dict.Add('б','b');
  16.      Dict.Add('В','V'); Dict.Add('в','v');
  17.      Dict.Add('Г','G'); Dict.Add('г','g');
  18.      Dict.Add('Д','D'); Dict.Add('д','d');
  19.      Dict.Add('Е','E'); Dict.Add('е','e');
  20.      Dict.Add('Ё','YO'); Dict.Add('ё','yo');
  21.      Dict.Add('Ж','ZH'); Dict.Add('ж','zh');
  22.      Dict.Add('З','Z'); Dict.Add('з','z');
  23.      Dict.Add('И','I'); Dict.Add('и','i');
  24.      Dict.Add('Й','J'); Dict.Add('й','j');
  25.      Dict.Add('К','K'); Dict.Add('к','k');
  26.      Dict.Add('Л','L'); Dict.Add('л','l');
  27.      Dict.Add('М','M'); Dict.Add('м','m');
  28.      Dict.Add('Н','N'); Dict.Add('н','n');
  29.      Dict.Add('О','O'); Dict.Add('о','o');
  30.      Dict.Add('П','P'); Dict.Add('п','p');
  31.      Dict.Add('Р','R'); Dict.Add('р','r');
  32.      Dict.Add('С','S'); Dict.Add('с','s');
  33.      Dict.Add('Т','T'); Dict.Add('т','t');
  34.      Dict.Add('У','U'); Dict.Add('у','u');
  35.      Dict.Add('Ф','F'); Dict.Add('ф','f');
  36.      Dict.Add('Х','KH'); Dict.Add('х','kh');
  37.      Dict.Add('Ц','TS'); Dict.Add('ц','ts');
  38.      Dict.Add('Ч','CH'); Dict.Add('ч','ch');
  39.      Dict.Add('Ш','SH'); Dict.Add('ш','sh');
  40.      Dict.Add('Щ','SHCH'); Dict.Add('щ','shch');
  41.      Dict.Add('Ъ','_'); Dict.Add('ъ','_');
  42.      Dict.Add('Ы','Y'); Dict.Add('ы','y');
  43.      Dict.Add('Ь','_'); Dict.Add('ь','_');
  44.      Dict.Add('Э','JE'); Dict.Add('э','je');
  45.      Dict.Add('Ю','JU'); Dict.Add('ю','ju');
  46.      Dict.Add('Я','JA'); Dict.Add('я','ja');
  47.  
  48.      Ch:=''; oStr:='';
  49.      for I:=1 to Length(Str) do begin
  50.        Ch:=Copy(Str,I,1);
  51.        if Dict.TryGetData(Ch, oTrans) then begin
  52.           oStr:=oStr+oTrans; //russkaya bukva - transliteriruem
  53.        end
  54.        else begin
  55.          oStr:=oStr+Ch; //nerusskaya bukva, ostavlaem v pokoe
  56.        end;
  57.      end;
  58.      Dict.Free;
  59.      exit(oStr);
  60. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement