Ïåðåêîäèðîâàíèå
Ýòîò àëãîðèòì ïîçâîëÿåò ïåðåêîäèðîâàòü òåêñò.
Ðåàëèçîâàíû êîäèðîâêè Windows-1251, KOI8-R, ISO-8859-5 è DOS.
Êîäèðîâêà – ýòî òàáëèöà, â êîòîðîé óêàçàíî,
íàïðèìåð, ÷òî ñèìâîë ïîä íîìåðîì 160 - ýòî ðóññêàÿ áóêâà "à", à ïîä íîìåðîì 150 – "Ö" è ò. ä.
Êîäèðîâêè ðàçëè÷àþòñÿ íîìåðàìè ðóññêèõ áóêâ
(êàê ðàñïîëàãàòü àíãëèéñêèå áóêâû äîãîâîðèëèñü).
Ðàçíûå êîìïüþòåðû â Èíòåðíåòå èñïîëüçóþò ðàçíûå êîäèðîâêè.
È ïîýòîìó, êîãäà ðóññêèé òåêñò èäåò ïî Èíòåðíåòó, åãî ìíîãîêðàòíî ïåðåêîäèðóþò.
Ýòîò àëãîðèòì îáåñïå÷èâàåò âûñîêóþ ñêîðîñòü ïåðåêîäèðîâàíèÿ áîëüøèõ îáúåìîâ äàííûõ.
procedure TForm1.Button1Click(Sender: TObject);
var
code1, code2: TCode;
s: string;
c: char;
i: integer;
chars: array [char] of char;
str: array [TCode] of string;
begin
case ComboBox1.ItemIndex of
1: code1 := koi;
2: code1 := iso;
3: code1 := dos;
else code1 := win;
end;
case ComboBox2.ItemIndex of
1: code2 := koi;
2: code2 := iso;
3: code2 := dos;
else code2 := win;
end;
s := Memo1.Text;
Str[win] := 'ÀàÁáÂâÃãÄäÅåÆæÇçÈèÉéÊêËëÌìÍíÎîÏïÐðÑñÒòÓóÔôÕõÖö×÷ØøÙùÚúÛûÜüÝýÞþßÿ';
Str[koi] := 'þÞàÀáÁöÖäÄåÅôÔãÃõÕèÈéÉêÊëËìÌíÍîÎïÏÿßðÐñÑòÒóÓæÆâÂüÜûÛçÇøØýÝùÙ÷×úÚ';
Str[iso] := 'ÐðÑñÒòÓóÔôÕõÖö×÷ØøÙùÚúÛûÜüÝýÞþßÿà¹á¸â?ãƒäºå¾æ³ç¿è¼éšêœëžì?í§î¢ïŸ';
Str[dos] := 'ˆ ?¡‚¢ƒ£„¤…¥†¦‡§ˆ¨‰©Šª‹"Œ¬?Ž®?¯?à'á'â“ã”ä•å–æ—ç˜è™éšê›ëœì?ížîŸï';
for c := #0 to #255 do
Chars[c] := c;
for i := 1 to Length(Str[win]) do
Chars[Str[code2][i]] := Str[code1][i];
for i := 1 to Length(s) do
s[i] := Chars[s[i]];
Memo2.Text := s;
end;
|
|