MCPcopy Create free account
hub / github.com/agentforce314/clawcodex / _apply_edit

Function _apply_edit

src/tool_system/tools/edit.py:139–153  ·  view source on GitHub ↗
(original: str, old_string: str, new_string: str, replace_all: bool)

Source from the content-addressed store, hash-verified

137# -- Smart edit application ----------------------------------------------------
138
139def _apply_edit(original: str, old_string: str, new_string: str, replace_all: bool) -> str:
140 if new_string != "":
141 if replace_all:
142 return original.replace(old_string, new_string)
143 idx = original.index(old_string)
144 return original[:idx] + new_string + original[idx + len(old_string):]
145
146 strip_trailing_newline = (
147 not old_string.endswith("\n") and (old_string + "\n") in original
148 )
149 target = old_string + "\n" if strip_trailing_newline else old_string
150 if replace_all:
151 return original.replace(target, "")
152 idx = original.index(target)
153 return original[:idx] + original[idx + len(target):]
154
155
156# -- Trailing whitespace stripping ---------------------------------------------

Callers 1

_edit_callFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected