Detect and process NUL characters before giving loaded SQL to SynEdit. Works around issue #1093.

This commit is contained in:
rosenfield.albert
2009-04-28 21:16:18 +00:00
parent 1d0b3d2b85
commit d25e271591
2 changed files with 35 additions and 2 deletions

View File

@@ -133,8 +133,9 @@ type
function MakeFloat( Str: String ): Extended;
function FloatStr(Val: String): String;
function esc(Text: WideString; ProcessJokerChars: Boolean = false; sql_version: integer = 50000): WideString;
function hasNullChar(Text: WideString): boolean;
function ScanNulChar(Text: WideString): Boolean;
function ScanLineBreaks(Text: WideString): TLineBreaks;
function RemoveNulChars(Text: WideString): WideString;
procedure debug(txt: String);
function fixNewlines(txt: string): string;
function bool2str( boolval : Boolean ) : String;
@@ -1638,8 +1639,9 @@ end;
{***
Detect NUL character in a text.
Useful because fx SynEdit cuts of all text after it encounters a NUL.
}
function hasNullChar(Text: WideString): boolean;
function ScanNulChar(Text: WideString): boolean;
var
i: integer;
begin
@@ -1703,6 +1705,30 @@ end;
{***
Mangle input text so that SynEdit can load it.
@param string Text to test
@return Boolean
}
function RemoveNulChars(Text: WideString): WideString;
var
i: integer;
c: WideChar;
begin
SetLength(Result, Length(Text));
if Length(Text) = 0 then Exit;
i := 1;
repeat
c := Text[i];
if c = #0 then Result[i] := #32
else Result[i] := c;
i := i + 1;
until i > length(Text);
end;
{***
Use DebugView from SysInternals or Delphi's Event Log to view.

View File

@@ -5476,6 +5476,12 @@ begin
FillPopupQueryLoad;
PagecontrolMain.ActivePage := tabQuery;
SynCompletionProposal1.Editor.UndoList.AddGroupBreak;
if ScanNulChar(filecontent) then begin
filecontent := RemoveNulChars(filecontent);
MessageDlg('This file contains NUL characters. They have been converted to ASCII spaces (SP).', mtInformation, [mbOK], 0);
end;
SynMemoQuery.BeginUpdate;
LineBreaks := ScanLineBreaks(filecontent);
if ReplaceContent then begin
@@ -5489,6 +5495,7 @@ begin
end;
if QueryMemoLineBreaks = lbsMixed then
MessageDlg('This file contains mixed linebreaks. They have been converted to Windows linebreaks (CR+LF).', mtInformation, [mbOK], 0);
SynMemoQuery.SelText := filecontent;
SynMemoQuery.SelStart := SynMemoQuery.SelEnd;
SynMemoQuery.EndUpdate;