patchkit

package
v0.0.33 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

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

func Unique(haystack, needle, replace string) (*Spec, int)

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

func UniqueDedent(haystack, needle, replace string) (*Spec, bool)

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

func UniqueGoTokens(haystack, needle, replace string) (*Spec, bool)

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

func UniqueInValidGo(haystack, needle, replace string) (*Spec, bool)

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

func UniqueTrim(haystack, needle, replace string) (*Spec, bool)

UniqueTrim is Unique, but with flexibility to shrink old/replace in tandem.

func (*Spec) ApplyToEditBuf

func (s *Spec) ApplyToEditBuf(buf *editbuf.Buffer)

ApplyToEditBuf applies the patch to the given edit buffer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL