MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / ReversePatch

Function ReversePatch

internal/diff/diff.go:130–135  ·  view source on GitHub ↗

ReversePatch is CreateReversePatch for text that may not be valid UTF-8 (BUG-3839). go-diff works on runes and slices the input at byte offsets it derives from them, so invalid UTF-8 near an edit either panics (slice bounds out of range) or yields a patch that does not reproduce oldText: "hello worl

(oldText, newText string)

Source from the content-addressed store, hash-verified

128// body instead. Never sanitize and diff: the version would then record a body
129// it does not hold.
130func ReversePatch(oldText, newText string) (patch string, ok bool) {
131 if !utf8.ValidString(oldText) || !utf8.ValidString(newText) {
132 return "", false
133 }
134 return CreatePatch(newText, oldText), true
135}
136
137// FormatDiffSummary returns a human-readable summary of changes. Its "lines"
138// are character-diff CHUNKS (a one-character edit reads +1/-1); LineCounts is

Calls 1

CreatePatchFunction · 0.85