Documentation
¶
Overview ¶
Package diff provides bounded, dependency-free line diffs for tool output.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatUnified ¶
func FormatUnifiedAt ¶
func TruncateUTF8 ¶
TruncateUTF8 returns the longest prefix of s that is valid UTF-8 and at most maxBytes long; a non-positive maxBytes is treated as no limit, so a valid s is returned whole. It walks the window forward with utf8.DecodeRuneInString, so a long valid prefix followed by an invalid byte costs O(n) instead of the O(n^2) rescans of the previous trim-one-byte loop. A decoded U+FFFD with size 3 is a genuine replacement character and does not stop the walk; only RuneError with size 1 (an invalid or truncated sequence) does. The walk runs even when s already fits maxBytes, so a short input containing an invalid byte is cut back to its longest valid prefix rather than returned whole.