textsafe

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: CC0-1.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package textsafe validates input text and sanitizes terminal and log output.

Index

Constants

View Source
const (
	// MaxTitleRunes is the maximum number of Unicode code points in a title.
	MaxTitleRunes = 500
	// MaxNotesBytes is the maximum UTF-8 byte length of normalized notes.
	// AIDEV-NOTE: Change markdown.maxNoteBytes with this limit so the
	// pre-render guard matches validation.
	MaxNotesBytes = 65536
)

Variables

This section is empty.

Functions

func Sanitize

func Sanitize(s string) string

Sanitize replaces unsafe runes and each invalid UTF-8 byte with U+FFFD. It preserves graphic runes, newlines, tabs, ZWNJ, and ZWJ for terminal/log output.

func SanitizeLine

func SanitizeLine(s string) string

SanitizeLine sanitizes s and also replaces newlines and tabs with U+FFFD.

func Truncate

func Truncate(s string, width int, tail string) string

Truncate shortens s to width terminal cells, including tail when truncated, while preserving grapheme clusters and ANSI sequences. It does not sanitize s.

func ValidateName

func ValidateName(s string, maxLen int) error

ValidateName checks that s contains 1..maxLen ASCII letters, digits, dots, underscores, or hyphens, without trimming or otherwise normalizing it.

func ValidateNotes

func ValidateNotes(s string) (string, error)

ValidateNotes strips one leading BOM, converts CRLF and CR to LF, and validates notes of at most MaxNotesBytes bytes. Empty notes are valid.

func ValidateTitle

func ValidateTitle(s string) (string, error)

ValidateTitle strips one leading BOM, trims whitespace, and validates a nonempty, single-line title of at most MaxTitleRunes Unicode code points.

func Width

func Width(s string) int

Width returns the terminal cell width of s, ignoring ANSI escape sequences. Sanitize user text before applying trusted terminal styles and measuring it.

Types

This section is empty.

Jump to

Keyboard shortcuts

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