Documentation
¶
Overview ¶
Package textfile owns charset and line-ending detection/conversion at the boundary between a file's on-disk bytes and nib's in-memory, always-UTF-8-with-LF representation — the same split internal/textwidth makes for display-width math. Nothing outside a Buffer's Load/Save should need to know a file's charset or EOL style; everywhere else, text is plain UTF-8 split on "\n".
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Charset ¶
type Charset string
Charset identifies how a file's bytes are encoded. The zero value, UTF8, is deliberately today's default (no BOM) — every Buffer{} literal built without setting Charset (there are many, across tests) keeps behaving exactly as before.
func Decode ¶
Decode converts data to a UTF-8 string, detecting its charset from a byte-order mark. With no recognized BOM, data is assumed to already be UTF-8 — today's behavior, unchanged: an invalid byte sequence is not an error, it just decodes to the Unicode replacement character wherever it occurs (Go's string() conversion already does this for free).
type EOL ¶
type EOL string
EOL identifies a file's line-ending style. The zero value, LF, is deliberately today's default (a bare "\n"), for the same reason as Charset's zero value above.
func SplitLines ¶
SplitLines detects text's line-ending style (the first "\r\n", bare "\r", or "\n" wins; no terminator at all defaults to LF) and splits it into lines with every line-ending sequence stripped — including a lone trailing one, so an all-empty text is a single empty line. Mixed line endings within one text are all treated as line breaks; only the detected (first) style is reported back, to use on a subsequent JoinLines.
For an LF-only text (the common case) this produces byte-for-byte the same lines as the old TrimSuffix+Split it replaces.