{----------------------------------------------------------------- autodetekce kodove stranky ------------------------------------------------------------------} procedure TfChildEdit.AutoDetectCP(const Text: string; var CP: TPrevod); var j, MaxL : Integer; CountKam, CountOEM, CountANSI, CountISO: Integer; p: PAnsiChar; begin if CP in [UTF16LE, UTF16BE] then Exit; CountKam := 0; CountOEM := 0; CountANSI := 0; CountISO := 0; { provedeme detekci CP pri Reopen ignorujeme nastaveni v parametrech a bereme ohled na nastaveni v menu. Promenna FAcceptMenuCP se nastavuje v TfChildParent pri volani Reopen } if CP = Auto then begin { zjistime si velikost vzorku } MaxL := Min(20000, Length(Text)); { Projdeme to } p := Pointer(Text); for j:= 1 to MaxL do begin case p^ of #138,#141,#154,#193,#200,#201,#204,#207,#211,#217,#218, #221,#225,#232,#239,#242,#243,#248,#249,#250: Inc(CountAnsi); #128,#135,#139,#143,#151,#157,#168,#169 : Inc(CountKam); #133,#181,#183,#210,#213,#214,#224,#229,#230,#231,#252: Inc(CountOEM); #185,#174,#171: Inc(CountISO); end; Inc(p); end; { podle vysledku analyzy se prepneme do prislusne CP } if (CountKam > CountOEM) and (CountKam > CountANSI) then CP := Kam else If CountOEM > CountAnsi then CP := Lat else if CountISO > 0 then CP := ISO else CP := Win; end; if (CP = Auto) and (SynEdit.Lines.Count = 0) then CP := Win; CodePage := CP; { mame tu UTF-8 bez identifikacnich bytu } if CodePage = UTF8 then begin SynUnicode.LoadFromFile(SynEdit.Lines, FileName, seUTF8); { pokud se nepodari soubor nacist jako UTF-8, nacteme jej jako ANSI } if SynEdit.Lines.Count = 0 then begin SynEdit.Lines.Text := Text; CodePage := WIN; end; end { provedeme konverzi } else begin ConvertText(Text, CodePage, True); SynEdit.Lines.Text := Text; end; end;