diff --git a/components/codetools/stdcodetools.pas b/components/codetools/stdcodetools.pas index 7789918d4d..f5f68b70ef 100644 --- a/components/codetools/stdcodetools.pas +++ b/components/codetools/stdcodetools.pas @@ -235,11 +235,13 @@ type // search & replace function ReplaceWords(IdentList: TStrings; ChangeStrings: boolean; - SourceChangeCache: TSourceChangeCache): boolean; + SourceChangeCache: TSourceChangeCache; + SkipPointWords: boolean = false): boolean; function FindNearestIdentifierNode(const CursorPos: TCodeXYPosition; IdentTree: TAVLTree): TAVLTreeNode; function ReplaceWord(const OldWord, NewWord: string; ChangeStrings: boolean; - SourceChangeCache: TSourceChangeCache): boolean; + SourceChangeCache: TSourceChangeCache; + SkipPointWords: boolean = false): boolean; // expressions function GetStringConstBounds(const CursorPos: TCodeXYPosition; @@ -2969,8 +2971,20 @@ end; ChangeStrings = true, means to replace in string constants too -------------------------------------------------------------------------------} function TStandardCodeTool.ReplaceWords(IdentList: TStrings; - ChangeStrings: boolean; SourceChangeCache: TSourceChangeCache): boolean; - + ChangeStrings: boolean; SourceChangeCache: TSourceChangeCache; + SkipPointWords: boolean): boolean; + + function CheckIdentifier(const CurSource: string; + IdentStart: integer): boolean; + var + p: integer; + begin + if not SkipPointWords then exit(true); + p:=IdentStart-1; + while (p>0) and (IsSpaceChar[CurSource[p]]) do dec(p); + Result:=(p<1) or (CurSource[p]<>'.'); + end; + procedure ReplaceWordsInSource(ACode: TCodeBuffer); var StartPos, EndPos, MaxPos, IdentStart, IdentEnd: integer; @@ -2992,32 +3006,31 @@ function TStandardCodeTool.ReplaceWords(IdentList: TStrings; IdentStart:=FindNextIdentifier(CurSource,StartPos,EndPos-1) else IdentStart:=FindNextIdentifierSkipStrings(CurSource,StartPos,EndPos-1); - if IdentStart'') - and (BasicCodeTools.CompareIdentifiers(PChar(Pointer(IdentList[i])), - @CurSource[IdentStart])=0) - and (IdentList[i]<>IdentList[i+1]) then - begin - // identifier found -> replace - IdentEnd:=IdentStart+length(IdentList[i]); - //DebugLn('TStandardCodeTool.ReplaceWords replacing: ', - //' "',copy(CurSource,IdentStart,IdentEnd-IdentStart),'" -> "',IdentList[i+1],'" at ',IdentStart - //); - SourceChangeCache.ReplaceEx(gtNone,gtNone,1,1, - ACode,IdentStart,IdentEnd,IdentList[i+1]); - break; - end; - inc(i,2); - end; - // skip identifier - StartPos:=IdentStart; - while (StartPos=EndPos then break; + i:=0; + while i'') + and (BasicCodeTools.CompareIdentifiers(PChar(Pointer(IdentList[i])), + @CurSource[IdentStart])=0) + and CheckIdentifier(CurSource,IdentStart) + and (IdentList[i]<>IdentList[i+1]) + then begin + // identifier found -> replace + IdentEnd:=IdentStart+length(IdentList[i]); + //DebugLn('TStandardCodeTool.ReplaceWords replacing: ', + //' "',copy(CurSource,IdentStart,IdentEnd-IdentStart),'" -> "',IdentList[i+1],'" at ',IdentStart + //); + SourceChangeCache.ReplaceEx(gtNone,gtNone,1,1, + ACode,IdentStart,IdentEnd,IdentList[i+1]); + break; + end; + inc(i,2); end; + // skip identifier + StartPos:=IdentStart; + while (StartPos