mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-16 00:00:49 +01:00
LazUtils: Fix SpecialCharsToHex output to actual hex. Move code to reusable functions ShortDotsLine and BeautifyLineXY. Issue #38029.
git-svn-id: trunk@64102 -
This commit is contained in:
parent
2ebdf2a994
commit
5d89968871
@ -57,6 +57,8 @@ function SimpleSyntaxToRegExpr(const Src: string): string;
|
||||
function BinaryStrToText(const s: string): string;
|
||||
function SpecialCharsToSpaces(const s: string; FixUTF8: boolean): string;
|
||||
function SpecialCharsToHex(const s: string): string;
|
||||
function ShortDotsLine(const Line: string): string;
|
||||
function BeautifyLineXY(const Filename, Line: string; X, Y: integer): string;
|
||||
function BreakString(const s: string; MaxLineLength, Indent: integer): string;
|
||||
|
||||
// Conversions to and from a StringList
|
||||
@ -103,6 +105,9 @@ function StrLScan(P: PChar; c: Char; MaxLen: Cardinal): PChar;
|
||||
function LazIsValidIdent(const Ident: string; AllowDots: Boolean = False;
|
||||
StrictDots: Boolean = False): Boolean;
|
||||
|
||||
const
|
||||
MaxTextLen = 80;
|
||||
|
||||
implementation
|
||||
|
||||
function IsNumber(s: String): Boolean;
|
||||
@ -723,10 +728,22 @@ begin
|
||||
for i:=length(Result) downto 1 do
|
||||
if Result[i]<' ' then
|
||||
Result:=copy(Result,1,i-1)
|
||||
+'#'+Format('%d',[ord(Result[i])])
|
||||
+'#'+Format('%x',[ord(Result[i])])
|
||||
+copy(Result,i+1,length(Result));
|
||||
end;
|
||||
|
||||
function ShortDotsLine(const Line: string): string;
|
||||
begin
|
||||
Result:=SpecialCharsToHex(Line);
|
||||
if UTF8Length(Result)>MaxTextLen then
|
||||
Result:=UTF8Copy(Result,1,MaxTextLen)+'...';
|
||||
end;
|
||||
|
||||
function BeautifyLineXY(const Filename, Line: string; X, Y: integer): string;
|
||||
begin
|
||||
Result:=Filename+' ('+IntToStr(Y)+','+IntToStr(X)+')'+' '+ShortDotsLine(Line);
|
||||
end;
|
||||
|
||||
function BreakString(const s: string; MaxLineLength, Indent: integer): string;
|
||||
var
|
||||
SrcLen: Integer;
|
||||
|
||||
@ -51,8 +51,6 @@ type
|
||||
fOnSelectionChanged : TNotifyEvent;
|
||||
fProjectChangeStamp: integer;
|
||||
function GetSelectedIndex : Integer;
|
||||
function BeautifyLine(const Filename: string; X, Y: integer;
|
||||
const Line: string): string;
|
||||
procedure InitDisplay;
|
||||
protected
|
||||
procedure IndexChanged(Sender: TObject; {%H-}Index: Integer);
|
||||
@ -71,9 +69,6 @@ implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
const
|
||||
MaxTextLen = 80;
|
||||
|
||||
{ TJumpHistoryViewWin }
|
||||
|
||||
procedure TJumpHistoryViewWin.FormCreate(Sender : TObject);
|
||||
@ -115,25 +110,12 @@ begin
|
||||
Result := listHistory.ItemIndex;
|
||||
end;
|
||||
|
||||
function TJumpHistoryViewWin.BeautifyLine(const Filename : string; X, Y : integer;
|
||||
const Line : string) : string;
|
||||
begin
|
||||
Result:=SpecialCharsToHex(Line);
|
||||
if UTF8Length(Result)>MaxTextLen then
|
||||
Result:=UTF8Copy(Result,1,MaxTextLen)+'...';
|
||||
Result:=Filename
|
||||
+' ('+IntToStr(Y)
|
||||
+','+IntToStr(X)+')'
|
||||
+' '+Result;
|
||||
end;
|
||||
|
||||
procedure TJumpHistoryViewWin.InitDisplay;
|
||||
var
|
||||
i : integer;
|
||||
jh_item : TProjectJumpHistoryPosition;
|
||||
SrcLine: String;
|
||||
SrcLine, Filename: String;
|
||||
CodeBuf: TCodeBuffer;
|
||||
Filename: String;
|
||||
begin
|
||||
if (Project1<>nil)
|
||||
and (fProjectChangeStamp=Project1.JumpHistory.ChangeStamp) then exit;
|
||||
@ -150,12 +132,8 @@ begin
|
||||
Filename:=jh_item.Filename;
|
||||
if Project1<>nil then
|
||||
Filename:=Project1.GetShortFilename(Filename,true);
|
||||
listHistory.Items.Append
|
||||
(BeautifyLine(Filename,
|
||||
jh_item.CaretXY.X,
|
||||
jh_item.CaretXY.Y,
|
||||
SrcLine
|
||||
)
|
||||
listHistory.Items.Append(
|
||||
BeautifyLineXY(Filename, SrcLine, jh_item.CaretXY.X, jh_item.CaretXY.Y)
|
||||
);
|
||||
end;
|
||||
//DebugLn(['TJumpHistoryViewWin.InitDisplay Project1.JumpHistory.HistoryIndex=',Project1.JumpHistory.HistoryIndex]);
|
||||
|
||||
@ -120,8 +120,7 @@ type
|
||||
procedure ShortenPaths;
|
||||
procedure FreeObjectsTN(tnItems: TTreeNodes);
|
||||
procedure FreeObjects(slItems: TStrings);
|
||||
function BeautifyLine(const Filename: string; X, Y: integer; const Line: string): string;
|
||||
function BeautifyLine(SearchPos: TLazSearchMatchPos): string;
|
||||
function BeautifyLineAt(SearchPos: TLazSearchMatchPos): string;
|
||||
property Filtered: Boolean read fFiltered write fFiltered;
|
||||
property SearchInListPhrases: string read FSearchInListPhrases write FSearchInListPhrases;
|
||||
property UpdateItems: TStrings read fUpdateStrings write fUpdateStrings;
|
||||
@ -261,9 +260,6 @@ implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
const
|
||||
MaxTextLen = 80;
|
||||
|
||||
function CompareTVNodeTextAsFilename(Node1, Node2: Pointer): integer;
|
||||
var
|
||||
TVNode1: TTreeNode absolute Node1;
|
||||
@ -714,7 +710,7 @@ begin
|
||||
SearchPos.FileEndPos:=EndPos;
|
||||
SearchPos.TheText:=TheText;
|
||||
SearchPos.ShownFilename:=SearchPos.Filename;
|
||||
ShownText:=CurrentTV.BeautifyLine(SearchPos);
|
||||
ShownText:=CurrentTV.BeautifyLineAt(SearchPos);
|
||||
LastPos:=nil;
|
||||
if CurrentTV.Updating then begin
|
||||
if (CurrentTV.UpdateItems.Count>0)
|
||||
@ -1116,7 +1112,6 @@ begin
|
||||
|
||||
if Assigned(MatchPos) then
|
||||
begin
|
||||
|
||||
FirstMatchPos:=MatchPos;
|
||||
TheTop:= ARect.Top;
|
||||
TextEnd:=ARect.Left;
|
||||
@ -1138,23 +1133,22 @@ begin
|
||||
while assigned(MatchPos) do begin
|
||||
//debugln(['TSearchResultsView.TreeViewAdvancedCustomDrawItem MatchPos.TheText="',MatchPos.TheText,'" MatchPos.MatchStart=',MatchPos.MatchStart,' MatchPos.MatchLen=',MatchPos.MatchLen]);
|
||||
// draw normal text
|
||||
CurPart:=SpecialCharsToHex(copy(MatchPos.TheText,DrawnTextLength+1,MatchPos.MatchStart-1-DrawnTextLength));
|
||||
CurPart:=SpecialCharsToHex(copy(MatchPos.TheText, DrawnTextLength+1,
|
||||
MatchPos.MatchStart-1-DrawnTextLength));
|
||||
DrawnTextLength:=MatchPos.MatchStart-1;
|
||||
TV.Canvas.TextOut(TextEnd, TheTop, CurPart);
|
||||
TextEnd:= TextEnd + TV.Canvas.TextWidth(CurPart);
|
||||
|
||||
// draw found text (matched)
|
||||
CurPart:=SpecialCharsToHex(copy(MatchPos.TheText,DrawnTextLength+1,MatchPos.MatchLen));
|
||||
CurPart:=ShortDotsLine(copy(MatchPos.TheText, DrawnTextLength+1, MatchPos.MatchLen));
|
||||
DrawnTextLength:=DrawnTextLength+MatchPos.MatchLen;
|
||||
if UTF8Length(CurPart)>MaxTextLen then
|
||||
CurPart:=UTF8Copy(CurPart,1,MaxTextLen)+'...';
|
||||
TV.Canvas.Font.Style:= TV.Canvas.Font.Style + [fsBold];
|
||||
TV.Canvas.TextOut(TextEnd, TheTop, CurPart);
|
||||
TextEnd:= TextEnd + TV.Canvas.TextWidth(CurPart);
|
||||
TV.Canvas.Font.Style:= TV.Canvas.Font.Style - [fsBold];
|
||||
|
||||
if MatchPos.NextInThisLine=nil then begin
|
||||
CurPart:=SpecialCharsToHex(copy(MatchPos.TheText, DrawnTextLength+1,Length(MatchPos.TheText)));
|
||||
CurPart:=SpecialCharsToHex(copy(MatchPos.TheText, DrawnTextLength+1,
|
||||
Length(MatchPos.TheText)));
|
||||
TV.Canvas.TextOut(TextEnd, TheTop, CurPart);
|
||||
end;
|
||||
MatchPos:=MatchPos.NextInThisLine;
|
||||
@ -1455,7 +1449,7 @@ begin
|
||||
MatchPos:=TLazSearchMatchPos(AnObject);
|
||||
MatchPos.ShownFilename:=copy(MatchPos.Filename,SharedLen+1,
|
||||
length(MatchPos.Filename));
|
||||
ShownText:=BeautifyLine(MatchPos);
|
||||
ShownText:=BeautifyLineAt(MatchPos);
|
||||
SrcList[i]:=ShownText;
|
||||
SrcList.Objects[i]:=MatchPos;
|
||||
end;
|
||||
@ -1483,22 +1477,10 @@ begin
|
||||
slItems.Objects[i].Free;
|
||||
end;
|
||||
|
||||
function TLazSearchResultTV.BeautifyLine(const Filename: string; X, Y: integer;
|
||||
const Line: string): string;
|
||||
function TLazSearchResultTV.BeautifyLineAt(SearchPos: TLazSearchMatchPos): string;
|
||||
begin
|
||||
Result:=SpecialCharsToHex(Line);
|
||||
if UTF8Length(Result)>MaxTextLen then
|
||||
Result:=UTF8Copy(Result,1,MaxTextLen)+'...';
|
||||
Result:=Filename
|
||||
+' ('+IntToStr(Y)
|
||||
+','+IntToStr(X)+')'
|
||||
+' '+Result;
|
||||
end;
|
||||
|
||||
function TLazSearchResultTV.BeautifyLine(SearchPos: TLazSearchMatchPos): string;
|
||||
begin
|
||||
Result:=BeautifyLine(SearchPos.ShownFilename,SearchPos.FileStartPos.X,
|
||||
SearchPos.FileStartPos.Y,SearchPos.TheText);
|
||||
with SearchPos do
|
||||
Result:=BeautifyLineXY(ShownFilename, TheText, FileStartPos.X, FileStartPos.Y);
|
||||
end;
|
||||
|
||||
function TLazSearchResultTV.ItemsAsStrings: TStrings;
|
||||
@ -1506,7 +1488,6 @@ var
|
||||
i: integer;
|
||||
begin
|
||||
Result := TStringList.Create;
|
||||
|
||||
for i := 0 to Items.Count - 1 do
|
||||
Result.AddObject(Items[i].Text,TObject(Items[i].Data));
|
||||
end;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user