Skip to content

Latest commit

 

History

History
46 lines (32 loc) · 1.84 KB

File metadata and controls

46 lines (32 loc) · 1.84 KB

Go SDK Reference

Import path:

import "github.com/startvibecoding/editpro"

Replacement

result, err := editpro.Replace(source, old, replacement, editpro.ReplaceOptions{
    Limit:           0,
    ExpectedMatches: 1,
    RequireMatch:    true,
})

Matches are byte-exact and non-overlapping. Limit == 0 replaces all matches. ExpectedMatches == 0 disables optimistic validation. The result reports total matches, applied replacements, changed state, and output bytes.

An empty old value is rejected. If no change is needed, result.Data may alias the input slice; callers must treat both input and result as immutable unless they own the storage.

Insertion

result, err := editpro.Insert(source, content, editpro.InsertOptions{
    Position: editpro.InsertBeforeLine,
    Line:     12,
    EOL:      nil,
})

Positions are InsertStart, InsertEnd, InsertBeforeLine, and InsertAfterLine. Line numbers are 1-based. A trailing newline creates an empty final line, consistent with byte-oriented editor behavior.

When Raw is false, EOL may be nil, LF, or CRLF. Nil detects the first source line ending and falls back to LF. Raw mode inserts content exactly.

Files

result, err := editpro.EditFile(path, old, replacement, editOptions, editpro.WriteOptions{})
result, err := editpro.InsertFile(path, content, insertOptions, editpro.WriteOptions{})

File operations read and validate the entire source before committing. Changed data is written to a temporary file in the destination directory, synced, closed, and then used to replace the destination. Existing permissions are preserved. NoSync skips the content sync when latency matters more than crash durability.

Symbolic links and non-regular files are rejected. Rename atomicity and power-loss durability still depend on the operating system and filesystem.