From 226843b5d3c171734426756ceecba13817294eb9 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sun, 8 Jun 2008 13:52:16 +0200 Subject: Internal viewer: detect file encoding from the first 100 lines only --- UCoreUtils.pas | 8 ++++++++ UViewer.pas | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/UCoreUtils.pas b/UCoreUtils.pas index 1781a41..f297fe0 100644 --- a/UCoreUtils.pas +++ b/UCoreUtils.pas @@ -128,6 +128,7 @@ function UTF8ToStr(s: PChar): PChar; overload; function EnsureUTF8String(s: PChar): PChar; overload; +function Min(Val1, Val2: longint): longint; // Calculate CRC32 Checksum, CRC is default $FFFFFFFF, // After calc you must inverse Result with NOT @@ -1424,6 +1425,13 @@ begin end; +(********************************************************************************************************************************) +function Min(Val1, Val2: longint): longint; +begin + if Val1 < Val2 then Result := Val1 + else Result := Val2; +end; + (********************************************************************************************************************************) {$IFDEF CPU64} function CRC32(CRC: LongWord; Data: Pointer; DataSize: LongWord): LongWord; diff --git a/UViewer.pas b/UViewer.pas index 70d3a64..4169b6a 100644 --- a/UViewer.pas +++ b/UViewer.pas @@ -392,7 +392,7 @@ begin LineBuffer.LoadFromFile(FileName); Valid := True; - for i := 0 to LineBuffer.Count - 1 do begin + for i := 0 to Min(100, LineBuffer.Count - 1) do begin Valid := Valid and g_utf8_validate(PChar(LineBuffer[i]), Length(LineBuffer[i]), nil); if not Valid then begin DebugMsg(['** TFViewer.LoadFile(', FileName, ', Line ', i + 1, ') is not UTF-8 valid.']); -- cgit v1.2.3