textutil

package
v1.0.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: Apache-2.0, Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package textutil provides byte-level text utilities: binary detection, line counting, JSON encoding, and byte-slice reader adapters.

Index

Constants

View Source
const BinarySniffLength = 8000

BinarySniffLength is the maximum number of bytes scanned for null-byte detection. Matches the heuristic used by Git and most editors.

Variables

This section is empty.

Functions

func CountLines

func CountLines(data []byte) int

CountLines returns the number of newline-delimited lines in data. A non-empty buffer without a trailing newline counts the last partial line. Returns 0 for empty data.

func IsBinary

func IsBinary(data []byte) bool

IsBinary returns true if data contains a null byte within the first BinarySniffLength bytes. Empty data is not binary.

func WriteJSON

func WriteJSON(w io.Writer, v any, pretty bool) error

WriteJSON encodes v as JSON to w. If pretty is true, output is indented with two spaces.

Types

This section is empty.

Jump to

Keyboard shortcuts

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