Skip to content

Commit 50a7251

Browse files
Kenoclaude
andcommitted
Replace Regex with findnext for occurrence counting
- Use findnext in a loop instead of eachmatch(Regex(...)) - More efficient and avoids regex escaping complexities - Same functionality with simpler, more direct approach - Tested with various patterns to ensure correctness 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 3baea2a commit 50a7251

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/tools/str_replace_editor.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,17 @@ function execute(tool::StrReplaceEditorTool, params::Dict)
199199
return create_content_response("Error: String not found in file", is_error=true)
200200
end
201201

202-
# Count occurrences
203-
occurrences = length(collect(eachmatch(Regex(escape_string(old_str)), content)))
202+
# Count occurrences using findnext
203+
occurrences = 0
204+
pos = 1
205+
while true
206+
range = findnext(old_str, content, pos)
207+
if isnothing(range)
208+
break
209+
end
210+
occurrences += 1
211+
pos = last(range) + 1
212+
end
204213

205214
# Replace the string
206215
new_content = replace(content, old_str => new_str)

0 commit comments

Comments
 (0)