Hello!
I have issue when i try write transliterate rus - eng.
Code fine works on delphi10.
lets look a code:
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, ClipBrd, LCLProc;
function Translit(s: string): string;
const
rus: string = 'абвгдеёжзийклмнопрстуфхцчшщьыъэюя';
lat: array[1..33] of string = ('a', 'b', 'v', 'g', 'd', 'e', 'yo', 'zh', 'z', 'i', 'y', 'k',
'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'h', 'ts', 'ch', 'sh', 'sch', '', 'y', '', 'e', 'yu', 'ya');
var
p, i, l, r, r2, l2: integer;
rp, rp2: string;
begin
s:=widelowercase(s);
Result := '';
l := Length(s);
for i := 1 to l do
begin
p := Pos(s[i], rus);
if p<1 then Result := Result + s[i] else Result := Result + lat[p];
end;
end;
For example:
Length returns byte value, and it's different from needed value.(35 bytes, 18 chars), (it needs utf8length instead)
pos(викторов александр) returns: 1 6 1 20 1 24 13 40 1 32 13 36 1 32 1 6 0 1 2 1 26 1 12 1 24 13 38 1 2 1 30 1 10 13 36
but correct value is: 3 10 12 20 16 18 16 3 1 13 6 12 19 1 15 5 18
Example two, using utf8:
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, ClipBrd, LCLProc, lazutf8;
function Translit(s: string): string;
const
rus: string = 'абвгдеёжзийклмнопрстуфхцчшщьыъэюя';
lat: array[1..33] of string = ('a', 'b', 'v', 'g', 'd', 'e', 'yo', 'zh', 'z', 'i', 'y', 'k',
'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'h', 'ts', 'ch', 'sh', 'sch', '', 'y', '', 'e', 'yu', 'ya');
var
p, i, l, r, r2, l2: integer;
rp, rp2: string;
begin
s:=widelowercase(s);
Result := '';
l := utf8Length(s);
for i := 1 to l do
begin
p := utf8Pos(s[i], rus);
if p<1 then Result := Result + s[i] else Result := Result + lat[p];
end;
When we use utf8:
utf8length return correct value, 18 chars.
utf8pos(викторов александр) returns: 1 4 1 11 1 13 7 21 1 17 7 19 1 17 1 4 0 1
still not correct value. (3 10 12 20 16 18 16 3 1 13 6 12 19 1 15 5 18)
I repeat, in delphi, all code work fine.
My board:
Win10x64, Laz 1.6.4
Where i gone wrong? Help me please.