mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-14 04:39:45 +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;
|
||||
end;
|
||||
end;
|
||||
if (OldCaretXY.X=EditorComponent.CaretX)
|
||||
and (OldCaretXY.Y=EditorComponent.CaretY)
|
||||
and not (ssoReplaceAll in LazFindReplaceDialog.Options) then begin
|
||||
ACaption:=lisUENotFound;
|
||||
AText:=Format(lisUESearchStringNotFound, [dbgstr(LazFindReplaceDialog.FindText)]);
|
||||
MessageDlg(ACaption,AText,mtInformation,[mbOk],0);
|
||||
|
||||
if (OldCaretXY.X = EditorComponent.CaretX) and
|
||||
(OldCaretXY.Y = EditorComponent.CaretY) and
|
||||
not (ssoReplaceAll in LazFindReplaceDialog.Options) then
|
||||
begin
|
||||
ACaption := lisUENotFound;
|
||||
AText := Format(lisUESearchStringNotFound, [ValidUTF8String(LazFindReplaceDialog.FindText)]);
|
||||
MessageDlg(ACaption, AText, mtInformation, [mbOk], 0);
|
||||
TSourceNotebook(Owner).DeleteLastJumpPointClicked(Self);
|
||||
end else begin
|
||||
end else
|
||||
begin
|
||||
NewTopLine := EditorComponent.CaretY - (EditorComponent.LinesInWindow div 2);
|
||||
if NewTopLine < 1 then NewTopLine:=1;
|
||||
if NewTopLine < 1 then
|
||||
NewTopLine := 1;
|
||||
EditorComponent.TopLine := NewTopLine;
|
||||
end;
|
||||
end;
|
||||
|
@ -314,6 +314,8 @@ function UTF8LowerCaseNew(const s: String): String;
|
||||
{$endif}
|
||||
function FindInvalidUTF8Character(p: PChar; Count: integer;
|
||||
StopOnNonASCII: Boolean = false): integer;
|
||||
function ValidUTF8String(const s: String): String;
|
||||
|
||||
procedure AssignUTF8ListToAnsi(UTF8List, AnsiList: TStrings);
|
||||
|
||||
function UTF16CharacterLength(p: PWideChar): integer;
|
||||
@ -3623,6 +3625,45 @@ begin
|
||||
Result:=-1;
|
||||
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);
|
||||
var
|
||||
i: Integer;
|
||||
|
Loading…
Reference in New Issue
Block a user