mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 23:39:40 +02:00
lcl: add function ValidUTF8String which checks a string to have valid utf8 chars and replaces 1..32 asci chars by their codes
ide: don't replace valid utf8 string by codes when we do search and a search string is not found git-svn-id: trunk@17794 -
This commit is contained in:
parent
8530d2cdc8
commit
f294976208
@ -1313,16 +1313,20 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
if (OldCaretXY.X=EditorComponent.CaretX)
|
|
||||||
and (OldCaretXY.Y=EditorComponent.CaretY)
|
if (OldCaretXY.X = EditorComponent.CaretX) and
|
||||||
and not (ssoReplaceAll in LazFindReplaceDialog.Options) then begin
|
(OldCaretXY.Y = EditorComponent.CaretY) and
|
||||||
ACaption:=lisUENotFound;
|
not (ssoReplaceAll in LazFindReplaceDialog.Options) then
|
||||||
AText:=Format(lisUESearchStringNotFound, [dbgstr(LazFindReplaceDialog.FindText)]);
|
begin
|
||||||
MessageDlg(ACaption,AText,mtInformation,[mbOk],0);
|
ACaption := lisUENotFound;
|
||||||
|
AText := Format(lisUESearchStringNotFound, [ValidUTF8String(LazFindReplaceDialog.FindText)]);
|
||||||
|
MessageDlg(ACaption, AText, mtInformation, [mbOk], 0);
|
||||||
TSourceNotebook(Owner).DeleteLastJumpPointClicked(Self);
|
TSourceNotebook(Owner).DeleteLastJumpPointClicked(Self);
|
||||||
end else begin
|
end else
|
||||||
|
begin
|
||||||
NewTopLine := EditorComponent.CaretY - (EditorComponent.LinesInWindow div 2);
|
NewTopLine := EditorComponent.CaretY - (EditorComponent.LinesInWindow div 2);
|
||||||
if NewTopLine < 1 then NewTopLine:=1;
|
if NewTopLine < 1 then
|
||||||
|
NewTopLine := 1;
|
||||||
EditorComponent.TopLine := NewTopLine;
|
EditorComponent.TopLine := NewTopLine;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
@ -314,6 +314,8 @@ function UTF8LowerCaseNew(const s: String): String;
|
|||||||
{$endif}
|
{$endif}
|
||||||
function FindInvalidUTF8Character(p: PChar; Count: integer;
|
function FindInvalidUTF8Character(p: PChar; Count: integer;
|
||||||
StopOnNonASCII: Boolean = false): integer;
|
StopOnNonASCII: Boolean = false): integer;
|
||||||
|
function ValidUTF8String(const s: String): String;
|
||||||
|
|
||||||
procedure AssignUTF8ListToAnsi(UTF8List, AnsiList: TStrings);
|
procedure AssignUTF8ListToAnsi(UTF8List, AnsiList: TStrings);
|
||||||
|
|
||||||
function UTF16CharacterLength(p: PWideChar): integer;
|
function UTF16CharacterLength(p: PWideChar): integer;
|
||||||
@ -3623,6 +3625,45 @@ begin
|
|||||||
Result:=-1;
|
Result:=-1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function ValidUTF8String(const s: String): String;
|
||||||
|
var
|
||||||
|
p, cur: PChar;
|
||||||
|
l, lr: integer;
|
||||||
|
NeedFree: Boolean;
|
||||||
|
begin
|
||||||
|
if FindInvalidUTF8Character(PChar(s), Length(s)) <> -1 then
|
||||||
|
begin
|
||||||
|
NeedFree := True;
|
||||||
|
GetMem(p, Length(s) + 1);
|
||||||
|
StrPCopy(p, s);
|
||||||
|
UTF8FixBroken(p);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
p := PChar(s);
|
||||||
|
NeedFree := False;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Result := '';
|
||||||
|
cur := p;
|
||||||
|
while cur^ <> #0 do
|
||||||
|
begin
|
||||||
|
l := UTF8CharacterLength(cur);
|
||||||
|
if (l = 1) and (cur^ < #32) then
|
||||||
|
Result := Result + '#' + IntToStr(Ord(cur^))
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
lr := Length(Result);
|
||||||
|
SetLength(Result, lr + l);
|
||||||
|
Move(cur^, Result[lr + 1], l);
|
||||||
|
end;
|
||||||
|
inc(cur, l)
|
||||||
|
end;
|
||||||
|
|
||||||
|
if NeedFree then
|
||||||
|
FreeMem(p);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure AssignUTF8ListToAnsi(UTF8List, AnsiList: TStrings);
|
procedure AssignUTF8ListToAnsi(UTF8List, AnsiList: TStrings);
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
|
Loading…
Reference in New Issue
Block a user