Help us shape the future of Go! Take the 2026 Go Developer Survey

printable

package
v0.25.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package printable is the rule for text a reviewer reads as an identifier (a node, block or flow name): every character prints. A control character, an invisible or direction-changing format character (a zero-width space, a joiner, a bidirectional override), a space other than the plain one, a private-use or unassigned code point, and a space at either end are what let one name read as another in a diff, so a config that holds one is refused (package plan) and output that would show one writes it out as \u{XXXX} instead (Escape, Writer). The package is the standard library only, so bide audit's build stays core-only.

Index

Constants

View Source
const UnicodeVersion = unicode.Version

UnicodeVersion is the version of the Unicode tables the check uses.

Variables

This section is empty.

Functions

func Bad

func Bad(s string) (r rune, ok bool)

Bad returns the first character of s that does not print, and whether there is one. Besides the characters unicode.IsPrint refuses (control, format, non-plain spaces, private-use, unassigned), it refuses every character with the Unicode property Default_Ignorable_Code_Point, which is what a renderer is allowed to draw as nothing (the Hangul and Khmer fillers, the grapheme joiner, the variation selectors, the Mongolian selectors, the format characters), U+2800 (the Braille blank), and a combining mark at the start with nothing to combine with. A space at either end counts, as the first or last character.

Default_Ignorable_Code_Point is derived as the Unicode standard derives it (PropList.txt): Other_Default_Ignorable_Code_Point, plus the format characters (general category Cf), plus the variation selectors, minus white space, the interlinear annotation characters U+FFF9 to U+FFFB, the Egyptian hieroglyph format controls U+13430 to U+13440 and the prepended concatenation marks; the Cf characters are refused by IsPrint already, so the set added here is the other two. It comes from the tables of the Go toolchain that built this program (Unicode UnicodeVersion).

func Describe

func Describe(r rune) string

Describe is r as a reader should see it: U+202E.

func Escape

func Escape(s string) string

Escape is s with every character that does not print written as \u{XXXX}. A plain space, a line break and a tab stay (text has lines and columns); everything else that does not print is written out.

func EscapeName

func EscapeName(s string) string

EscapeName is Escape for an identifier: a line break and a tab are written out too, since a name has neither.

Types

type EscapingWriter

type EscapingWriter struct {
	// contains filtered or unexported fields
}

EscapingWriter is the writer Writer returns. It keeps the start of a character or color sequence a Write ended in the middle of, and escapes it with the rest on the next Write, so a character split across two writes is not taken for two bad ones. Close writes what is still held back with each unfinished byte written out, and does not close the writer underneath.

func Writer

func Writer(w io.Writer) *EscapingWriter

Writer is w with Escape applied to everything written to it, except the terminal color sequences the command's own styling writes (ESC [ ... m). It is the second line of defence: a name that reached the output by a path that did not refuse it is still shown in a form that cannot spoof.

The writer holds back the tail of a character or of a color sequence a write ends in the middle of, and writes it with the next write; Close writes what is still held (escaped, as the invalid text it is), so nothing is dropped.

func (*EscapingWriter) Close

func (e *EscapingWriter) Close() error

Close writes what is held back, escaped as invalid text.

func (*EscapingWriter) Write

func (e *EscapingWriter) Write(p []byte) (int, error)

Write writes p with every character that does not print written out, except terminal color sequences. It reports len(p) written; the start of an unfinished character or color sequence at the end of p is held for the next write or Close.

Jump to

Keyboard shortcuts

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