patch

package
v0.4.2-rc.2 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package patch is the exact-match text editor behind `codeaf patch`: one old text in, the file with its single occurrence replaced out.

The law it keeps is the edit hand's (internal/exec/bare), which cannot be imported from here: an exact match is counted in line-ending-normalized space, so a caller who typed their old text with the endings their terminal shows still edits a CRLF file, and a replacement is refused rather than guessed at when the text matches nothing or matches several places at once. A shell has no model to ask for more context, so the refusals name the count — "found 3 matches" is something a person can act on, and a silent first-match replacement is not.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(content, oldText, newText string) (string, error)

Apply replaces the ONE occurrence of oldText in content with newText.

Matching is exact after three normalizations the edit hand also makes: a leading byte-order mark is set aside (a shell will not include one in the text it passes), every line ending is folded to LF (so LF text edits a CRLF file), and the replacement is written back with the file's own ending. The match is a plain substring count after that folding — no fuzzy fallback, because a person typing a patch into a shell wants either the edit they described or a refusal, and a "close enough" match would apply the wrong one.

The returned error carries the count when the match is not exactly one: none, or two or more. Content is only returned when the edit was made.

Types

This section is empty.

Jump to

Keyboard shortcuts

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