From f294976208725112e8ed1c464d71fb21ed3871b9 Mon Sep 17 00:00:00 2001 From: paul Date: Thu, 11 Dec 2008 09:10:29 +0000 Subject: [PATCH] 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 - --- ide/sourceeditor.pp | 20 ++++++++++++-------- lcl/lclproc.pas | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/ide/sourceeditor.pp b/ide/sourceeditor.pp index 6bfb9a82a2..82a9e0f676 100644 --- a/ide/sourceeditor.pp +++ b/ide/sourceeditor.pp @@ -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; diff --git a/lcl/lclproc.pas b/lcl/lclproc.pas index bfc8cd87aa..aebfc4b80e 100644 --- a/lcl/lclproc.pas +++ b/lcl/lclproc.pas @@ -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;