mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-02 15:20:33 +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;
|
Src: String;
|
||||||
NewMatchStartPos: PtrInt;
|
NewMatchStartPos: PtrInt;
|
||||||
NewMatchEndPos: PtrInt;
|
NewMatchEndPos: PtrInt;
|
||||||
lFoundUnmatchCaseChars: Boolean;
|
lCaseMismatchCheckCompleted: Boolean;
|
||||||
i, l, n1, n2: Integer;
|
i, l, n1, n2: Integer;
|
||||||
begin
|
begin
|
||||||
//debugln(['SearchInText TheFileName=',TheFileName,' SearchFor=',SearchFor,'" ReplaceText=',ReplaceText,'"']);
|
//debugln(['SearchInText TheFileName=',TheFileName,' SearchFor=',SearchFor,'" ReplaceText=',ReplaceText,'"']);
|
||||||
@ -568,7 +568,7 @@ begin
|
|||||||
if OriginalFile.Source='' then exit;
|
if OriginalFile.Source='' then exit;
|
||||||
|
|
||||||
CaseFile:=nil;
|
CaseFile:=nil;
|
||||||
lFoundUnmatchCaseChars := false;
|
lCaseMismatchCheckCompleted := false;
|
||||||
|
|
||||||
if sesoRegExpr in Flags then begin
|
if sesoRegExpr in Flags then begin
|
||||||
// Setup the regular expression search engine
|
// Setup the regular expression search engine
|
||||||
@ -587,26 +587,6 @@ begin
|
|||||||
CaseFile:=TSourceLog.Create(UTF8UpperCase(OriginalFile.Source));
|
CaseFile:=TSourceLog.Create(UTF8UpperCase(OriginalFile.Source));
|
||||||
TempSearch:=UTF8UpperCase(TempSearch);
|
TempSearch:=UTF8UpperCase(TempSearch);
|
||||||
Src:=CaseFile.Source;
|
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
|
end else
|
||||||
Src:=OriginalFile.Source;
|
Src:=OriginalFile.Source;
|
||||||
end;
|
end;
|
||||||
@ -645,7 +625,29 @@ begin
|
|||||||
FoundEndPos.Y,FoundEndPos.X);
|
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]);
|
//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 sesoReplace in Flags then begin
|
||||||
if lFoundUnmatchCaseChars then
|
|
||||||
|
// 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
|
begin
|
||||||
if IDEMessageDialog(lisCCOWarningCaption,
|
if IDEMessageDialog(lisCCOWarningCaption,
|
||||||
lisFindFileReplacementIsNotPossible + LineEnding + LineEnding + TheFileName,
|
lisFindFileReplacementIsNotPossible + LineEnding + LineEnding + TheFileName,
|
||||||
@ -655,6 +657,8 @@ begin
|
|||||||
|
|
||||||
exit(mrAbort);
|
exit(mrAbort);
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
DoReplaceLine;
|
DoReplaceLine;
|
||||||
end else begin
|
end else begin
|
||||||
if (Progress<>nil)
|
if (Progress<>nil)
|
||||||
|
Loading…
Reference in New Issue
Block a user