MCPcopy Create free account
hub / github.com/codehamr/codehamr / differsOnlyInWhitespace

Function differsOnlyInWhitespace

internal/tools/edit.go:68–71  ·  view source on GitHub ↗

differsOnlyInWhitespace reports whether oldString matches content at exactly one spot once every whitespace run is collapsed: i.e. the sole mismatch is indentation/tabs/newlines. Bounded with spaces so a match can't straddle a token boundary and mislabel an unrelated near-miss.

(content, oldString string)

Source from the content-addressed store, hash-verified

66 // so the exactly-once guarantee holds.
67 if idx := strings.Index(content, oldString); strings.Contains(content[idx+1:], oldString) {
68 return "(ambiguous: old_string overlaps itself - provide more context to make it unique)"
69 }
70 updated := strings.Replace(content, oldString, newString, 1)
71 if err := os.WriteFile(path, []byte(updated), 0o644); err != nil {
72 return fmt.Sprintf("(write error: %v)", err)
73 }
74 return fmt.Sprintf("edited %s: -%d +%d bytes", path, len(oldString), len(newString))

Callers 1

EditFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected