mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-23 00:19:37 +02:00
IDE: Improve speed on 6b1edee566
"UTF8 character handling with upper/lower size mismatch. Issue #40904"
This commit is contained in:
parent
be4d6c3bcc
commit
84bde0d39e
@ -529,7 +529,7 @@ var
|
||||
Src: String;
|
||||
NewMatchStartPos: PtrInt;
|
||||
NewMatchEndPos: PtrInt;
|
||||
lFoundUnmatchCaseChars: Boolean;
|
||||
lCaseMismatchCheckCompleted: Boolean;
|
||||
i, l, n1, n2: Integer;
|
||||
begin
|
||||
//debugln(['SearchInText TheFileName=',TheFileName,' SearchFor=',SearchFor,'" ReplaceText=',ReplaceText,'"']);
|
||||
@ -568,7 +568,7 @@ begin
|
||||
if OriginalFile.Source='' then exit;
|
||||
|
||||
CaseFile:=nil;
|
||||
lFoundUnmatchCaseChars := false;
|
||||
lCaseMismatchCheckCompleted := false;
|
||||
|
||||
if sesoRegExpr in Flags then begin
|
||||
// Setup the regular expression search engine
|
||||
@ -587,26 +587,6 @@ begin
|
||||
CaseFile:=TSourceLog.Create(UTF8UpperCase(OriginalFile.Source));
|
||||
TempSearch:=UTF8UpperCase(TempSearch);
|
||||
Src:=CaseFile.Source;
|
||||
|
||||
// Comparing character lengths after UTF8UpperCase:
|
||||
// their difference can lead to damage to the text when replacing
|
||||
// issue #40893
|
||||
if sesoReplace in Flags then
|
||||
begin
|
||||
// length of strings in bytes (not use UTF8Length)
|
||||
n1 := length(OriginalFile.Source);
|
||||
n2 := length(CaseFile.Source);
|
||||
l := n1; // assumed n1=n2
|
||||
i := 1;
|
||||
while (n1 = n2) and (i <= l) do
|
||||
begin
|
||||
// length of characters in bytes
|
||||
n1 := UTF8CodepointSize(@OriginalFile.Source[i]);
|
||||
n2 := UTF8CodepointSize(@CaseFile.Source[i]);
|
||||
inc(i, n1); // assumed n1=n2
|
||||
end;
|
||||
lFoundUnmatchCaseChars := n1 <> n2;
|
||||
end;
|
||||
end else
|
||||
Src:=OriginalFile.Source;
|
||||
end;
|
||||
@ -645,16 +625,40 @@ begin
|
||||
FoundEndPos.Y,FoundEndPos.X);
|
||||
//DebugLn(['SearchInText NewMatchStartPos=',NewMatchStartPos,' NewMatchEndPos=',NewMatchEndPos,' FoundStartPos=',dbgs(FoundStartPos),' FoundEndPos=',dbgs(FoundEndPos),' Found="',dbgstr(copy(Src,NewMatchStartPos,NewMatchEndPos-NewMatchStartPos)),'" Replace=',sesoReplace in Flags]);
|
||||
if sesoReplace in Flags then begin
|
||||
if lFoundUnmatchCaseChars then
|
||||
begin
|
||||
if IDEMessageDialog(lisCCOWarningCaption,
|
||||
lisFindFileReplacementIsNotPossible + LineEnding + LineEnding + TheFileName,
|
||||
mtWarning, [mbOK, mbCancel]) = mrCancel
|
||||
then
|
||||
DoAbort;
|
||||
|
||||
exit(mrAbort);
|
||||
// Comparing character lengths after UTF8UpperCase:
|
||||
// their difference can lead to damage to the text when replacing.
|
||||
// Issue #40893
|
||||
if not lCaseMismatchCheckCompleted then
|
||||
begin
|
||||
lCaseMismatchCheckCompleted := true;
|
||||
|
||||
// length of strings in bytes (don't use UTF8Length)
|
||||
n1 := length(OriginalFile.Source);
|
||||
n2 := length(CaseFile.Source);
|
||||
|
||||
l := n1; // assumed n1=n2
|
||||
i := 1;
|
||||
while (n1 = n2) and (i <= l) do
|
||||
begin
|
||||
// length of characters in bytes
|
||||
n1 := UTF8CodepointSize(@OriginalFile.Source[i]);
|
||||
n2 := UTF8CodepointSize(@CaseFile.Source[i]);
|
||||
inc(i, n1); // assumed n1=n2
|
||||
end;
|
||||
|
||||
if n1 <> n2 then
|
||||
begin
|
||||
if IDEMessageDialog(lisCCOWarningCaption,
|
||||
lisFindFileReplacementIsNotPossible + LineEnding + LineEnding + TheFileName,
|
||||
mtWarning, [mbOK, mbCancel]) = mrCancel
|
||||
then
|
||||
DoAbort;
|
||||
|
||||
exit(mrAbort);
|
||||
end;
|
||||
end;
|
||||
|
||||
DoReplaceLine;
|
||||
end else begin
|
||||
if (Progress<>nil)
|
||||
|
Loading…
Reference in New Issue
Block a user