Skip to content
Permalink
Browse files

Revert a part of 406ab56: Prefer TEncoding.UTF8 again over the TUTF8N…

…oBomEncoding with an overridden .GetPreamble(). The grid export crashed when used a second time, probably because the TStringStream overtakes ownership of the encoding. Also, I see no BOM in files encoded via TEncoding.UTF8, so this was probably a fix for nothing anyway.
  • Loading branch information...
ansgarbecker committed Apr 28, 2019
1 parent 076f6c6 commit 155cedace9102c06d4f68f7095f3ffb3ab0f0275
Showing with 7 additions and 25 deletions.
  1. +2 −20 source/apphelpers.pas
  2. +1 −1 source/exportgrid.pas
  3. +4 −4 source/main.pas
@@ -254,10 +254,6 @@ TAppSettings = class(TObject)
// "Static" options, initialized in OnCreate only. For settings which need a restart to take effect.
property RestoreTabsInitValue: Boolean read FRestoreTabsInitValue;
end;
TUTF8NoBOMEncoding = class(TUTF8Encoding)
public
function GetPreamble: TBytes; override;
end;

{$I const.inc}

@@ -371,7 +367,6 @@ TUTF8NoBOMEncoding = class(TUTF8Encoding)
SystemImageList: TImageList;
mtCriticalConfirmation: TMsgDlgType = mtCustom;
ConfirmIcon: TIcon;
UTF8NoBOM: TUTF8NoBOMEncoding;

implementation

@@ -1277,7 +1272,7 @@ function DetectEncoding(Stream: TStream): TEncoding;
i := 0;
while i < BufferSize do begin
if FoundUTF8Strings = MinimumCountOfUTF8Strings then begin
Result := UTF8NoBOM;
Result := TEncoding.UTF8;
Break;
end;
case Buffer[i] of
@@ -2617,7 +2612,7 @@ function GetHTMLCharsetByEncoding(Encoding: TEncoding): String;
Result := 'utf-16le'
else if Encoding = TEncoding.BigEndianUnicode then
Result := 'utf-16'
else if Encoding = UTF8NoBOM then
else if Encoding = TEncoding.UTF8 then
Result := 'utf-8'
else if Encoding = TEncoding.UTF7 then
Result := 'utf-7';
@@ -4272,19 +4267,6 @@ function TAppSettings.DirnameBackups: String;



{ TUTF8NoBOMEncoding }

function TUTF8NoBOMEncoding.GetPreamble: TBytes;
begin
// Overwriting default UTF8 encoding, which has a preamble which we don't want
// See https://forums.embarcadero.com/thread.jspa?threadID=112112
SetLength(Result, 0);
end;


initialization

UTF8NoBOM := TUTF8NoBOMEncoding.Create;

end.

@@ -549,7 +549,7 @@ procedure TfrmExportGrid.btnOKClick(Sender: TObject);
ExcludeCol := GridData.AutoIncrementColumn;

if radioOutputCopyToClipboard.Checked then
Encoding := UTF8NoBOM
Encoding := TEncoding.UTF8
else begin
Encoding := MainForm.GetEncodingByName(comboEncoding.Text);
// Add selected file to file list, and sort it onto the top of the list
@@ -2228,7 +2228,7 @@ procedure TMainForm.RestoreTabs;
if FileExists(BackupFilename) then begin
Tab := ActiveOrEmptyQueryTab(False);
Tab.Uid := Section;
Tab.LoadContents(BackupFilename, True, UTF8NoBOM);
Tab.LoadContents(BackupFilename, True, TEncoding.UTF8);
Tab.MemoFilename := Filename;
Tab.Memo.Modified := True;
end else begin
@@ -11846,7 +11846,7 @@ function TMainForm.GetEncodingByName(Name: String): TEncoding;
2: Result := TEncoding.GetEncoding(437);
3: Result := TEncoding.Unicode;
4: Result := TEncoding.BigEndianUnicode;
5: Result := UTF8NoBOM;
5: Result := TEncoding.UTF8;
6: Result := TEncoding.UTF7;
end;
end;
@@ -11860,7 +11860,7 @@ function TMainForm.GetEncodingName(Encoding: TEncoding): String;
else if (Encoding <> nil) and (Encoding.CodePage = 437) then idx := 2
else if Encoding = TEncoding.Unicode then idx := 3
else if Encoding = TEncoding.BigEndianUnicode then idx := 4
else if Encoding = UTF8NoBOM then idx := 5
else if Encoding = TEncoding.UTF8 then idx := 5
else if Encoding = TEncoding.UTF7 then idx := 6
else idx := 0;
Result := FileEncodings[idx];
@@ -11928,7 +11928,7 @@ function TMainForm.GetCharsetByEncoding(Encoding: TEncoding): String;
Result := 'utf16le'
else if Encoding = TEncoding.BigEndianUnicode then
Result := 'utf16'
else if Encoding = UTF8NoBOM then
else if Encoding = TEncoding.UTF8 then
Result := 'utf8'
else if Encoding = TEncoding.UTF7 then
Result := 'utf7';

0 comments on commit 155ceda

Please sign in to comment.
You can’t perform that action at this time.