> Ovaj moj pokušaj ne radi za slova Č,Ć,Ž,Š, ispisuje mi kukice.
Možda nemaš dobar (unicode) font, takođe moraš imati unicode kontrolu.
> Kako da konvertujem Nj,Lj i Dž?
Moraš da jedno slovo zameniš sa dva.
Šaljem primer funkcija za konverziju iz latinice u ćirilicu i obratno, rađene su za AnsiString ali verujem da ti mogu koristiti i za Unicode.
Code:
var
MapWin1250to1251: array of Char;
MapWin1251to1250: array of Char;
procedure CreateCharConversionMap(const ACodePage: Smallint);
const
Win1250_Capital = 'ABCDEFGHIJKLMNOPQRSTUVWXYZÈÆŠÐŽ';
Win1251_Capital = #192#193#214#196#197#212#195#213#200#163#202#203#204#205#206#207'Q'#208#209#210#211#194'WXY'#199#215#142#216#128#198;
Win1250_Small = 'abcdefghijklmnopqrstuvwxyzèæšðž';
Win1251_Small = #224#225#246#228#229#244#227#245#232#188#234#235#236#237#238#239'q'#240#241#242#243#226'wxy'#231#247#158#248#144#230;
Win1251_ThreeLetters = #140#156#138#154#143#159; // Nj, nj, Lj, lj, Dž, dž
Win1250_ThreeLetters = 'NnLlDd';
var
i: Integer;
Source, Dest: string;
begin
case ACodePage of
1250:
begin
if Length(MapWin1250to1251) = 0 then
begin
Source := Win1250_Capital + Win1250_Small;
Dest := Win1251_Capital + Win1251_Small;
SetLength(MapWin1250to1251, 256);
for i := 1 to Length(Source) do
MapWin1250to1251[Ord(Source[i])] := Dest[i];
end;
end;
1251:
begin
if Length(MapWin1251to1250) = 0 then
begin
Source := Win1251_Capital + Win1251_Small + Win1251_ThreeLetters;
Dest := Win1250_Capital + Win1250_Small + Win1250_ThreeLetters;
SetLength(MapWin1251to1250, 256);
for i := 1 to Length(Source) do
MapWin1251to1250[Ord(Source[i])] := Dest[i];
end;
end;
end;
end;
function Win1250to1251(const AValue: string): string;
var
Source, Dest: PChar;
begin
// Konvertujemo latinicu po kodnoj strani win1250 u cirilicu win1251
CreateCharConversionMap(1250);
SetLength(Result, Length(AValue));
Source := PChar(AValue);
Dest := PChar(Result);
while Source^ <> #0 do
begin
if MapWin1250to1251[Ord(Source^)] <> #0 then
begin
Dest^ := MapWin1250to1251[Ord(Source^)];
case Source^ of
'N', 'n', 'L', 'l':
begin
if (Source + 1)^ in ['J', 'j'] then
begin
case Source^ of
'N': Dest^ := #140;
'n': Dest^ := #156;
'L': Dest^ := #138;
'l': Dest^ := #154;
end;
Inc(Source);
end;
end;
'D', 'd':
begin
if (Source + 1)^ in ['Ž', 'ž'] then
begin
if Source^ = 'D' then
Dest^ := #143
else
Dest^ := #159;
Inc(Source);
end;
end;
end;
end
else
Dest^ := Source^;
Inc(Dest);
Inc(Source);
end;
SetLength(Result, Dest - PChar(Result));
end;
function Win1251to1250(const AValue: string): string;
var
Source, Dest: PChar;
Temp: Integer;
begin
// Konvertujemo cirilicu u kodnoj strani Win1251 u latinicu Win1250
CreateCharConversionMap(1251);
SetLength(Result, Length(AValue));
Source := PChar(AValue);
Dest := PChar(Result);
while Source^ <> #0 do
begin
if MapWin1251to1250[Ord(Source^)] <> #0 then
begin
Dest^ := MapWin1251to1250[Ord(Source^)];
if Source^ in [#140, #156, #138, #154, #143, #159] then
begin
Temp := Dest - PChar(Result);
SetLength(Result, Length(Result) + 1);
Dest := PChar(Result) + Temp + 1;
if Source^ in [#143, #159] then
Dest^ := 'ž'
else
Dest^ := 'j';
end;
end
else
Dest^ := Source^;
Inc(Dest);
Inc(Source);
end;
end;