Вверх ↑
Разработчик
Ответов: 26268
Рейтинг: 2141
#1: 2010-02-03 21:48:27 ЛС | профиль | цитата
Tad, я вот подумал -- а на кой черт на выходе имя файла, лучше сделать один выод события с индексом обнарущенной кодировки Да и защита не помешает от файла меньше 4-х байт
------------ Дoбавленo в 21.54:
Как-то вот так


procedure THITextFileDecision._work_doTextFileDecision;
var
fn: string;
st: PStream;
c: cardinal;
cs: integer;
dc, ds: TData;
begin
fn := ReadString(_Data,_data_FileName,_prop_FileName);
dtString(ds, fn);
if FileExists(Fn) then
begin
st := NewReadFileStream(Fn);
if st.size < 4 then exit;
st.read(c, 4);
st.free;
if c and $00FFFFFF = $00BFBBEF then cs := 1 // UTF-8
else if (c and $FFFF0000 <> $00000000) and (c and $0000FFFF = $0000FEFF) then cs := 2 // UTF-16LE
else if (c and $FFFF0000 <> $00000000) and (c and $0000FFFF = $0000FFFE) then cs := 3 // UTF-16BE
else if (c and $FFFF0000 = $00000000) and (c and $0000FFFF = $0000FEFF) then cs := 4 // UTF-32LE
else if (c and $0000FFFF = $00000000) and (c and $FFFF0000 = $FFFE0000) then cs :=5 // UTF-32BE
else cs := 0; // ANSI
dtInteger(dc, cs);
dc.ldata := @ds;
_hi_onEvent(_event_ANSI, dc);
end
else
begin
dtInteger(dc, -1);
dc.ldata := @ds;
_hi_onEvent(_event_onNotFile, dc);
end;
end;
карма: 22

0