Documentation
¶
Index ¶
- type Spec
- func Unique(haystack, needle, replace string) (*Spec, int)
- func UniqueDedent(haystack, needle, replace string) (*Spec, bool)
- func UniqueGoTokens(haystack, needle, replace string) (*Spec, bool)
- func UniqueInValidGo(haystack, needle, replace string) (*Spec, bool)
- func UniqueTrim(haystack, needle, replace string) (*Spec, bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Spec ¶
type Spec struct { Off int // Byte offset to apply the replacement Len int // Length of the replacement Src string // Original string (for debugging) Old string // Search string New string // Replacement string }
A Spec specifies a single patch.
func Unique ¶
Unique generates a patch spec to apply op, given a unique occurrence of needle in haystack and replacement text replace. It reports the number of matches found for needle in haystack: 0, 1, or 2 (for any value > 1).
func UniqueDedent ¶
UniqueDedent is Unique, but with flexibility around consistent whitespace prefix changes. Unlike Unique, which returns a count of matches, UniqueDedent returns a boolean indicating whether a unique match was found. It is for LLMs that have a hard time reliably reproducing uniform whitespace prefixes. For example, they may generate 8 spaces instead of 6 for all relevant lines. UniqueDedent adjusts the needle's whitespace prefix to match the haystack's and then replaces the unique instance of needle in haystack with replacement.
func UniqueGoTokens ¶
UniqueGoTokens is Unique, but with flexibility around all insignificant whitespace. Like UniqueDedent, it returns a boolean indicating whether a unique match was found. It is safe (enough) because it ensures that the needle alterations occurs only in places where whitespace is not semantically significant. In practice, this appears safe.
func UniqueInValidGo ¶
UniqueInValidGo is Unique, but with flexibility around all leading and trailing whitespace. Like UniqueDedent, it returns a boolean indicating whether a unique match was found. It is safe (enough) because it ensures that the needle alterations occurs only in places where whitespace is not semantically significant. In practice, this appears safe.
func UniqueTrim ¶
UniqueTrim is Unique, but with flexibility to shrink old/replace in tandem.
func (*Spec) ApplyToEditBuf ¶
ApplyToEditBuf applies the patch to the given edit buffer.