Documentation
¶
Overview ¶
Package clean turns bytes read from a file into strings that obey the text conventions of the shared document model: valid UTF-8, no control characters other than line feed and tab, and for prose no surrounding white space and no presentation-form ligatures.
Content is kept where it can be: what is changed is how it is written. Line and page separators become line feeds, ligatures become their letters. The only thing removed is control characters that have no meaning as text, and they are counted so the caller can report it.
Index ¶
- Constants
- func Address(s string) string
- func AddressCut(s string) (string, bool)
- func Append(dst, b []byte, flags Flags) ([]byte, int)
- func Bounded(s string, limit int) (string, bool)
- func Label(s string) string
- func LabelCut(s string) (string, bool)
- func Name(s string) string
- func NameCut(s string) (string, bool)
- func Plain(b []byte) bool
- func String(b []byte, flags Flags) (s string, removed int)
- type Flags
Constants ¶
const MaxAddress = 8 << 10
MaxAddress bounds an address. Addresses run longer than names: one with a query or a token in it is often over a thousand bytes, and one cut short leads nowhere. This is more than servers accept.
const MaxLabel = 4 << 10
MaxLabel bounds a label. Names and messages are short, but a title used as a name is a line of text, and in a script of three bytes a character 512 bytes held only 170: 4 KiB holds any real one.
Variables ¶
This section is empty.
Functions ¶
func Address ¶
Address is Label for the target of a link: the same cleaning, with room for the length addresses have. A caller that puts an address into the document counts it against the text the document may hold, since one address may be linked to any number of times.
func AddressCut ¶
AddressCut is Address that also reports whether the bound left out anything but white space.
func Append ¶
Append appends b to dst in the form the conventions ask for, and returns the extended slice and the number of control characters it removed. It does not trim: a caller that builds a paragraph out of pieces trims the whole once, and the offsets of the pieces stay true until then.
func Bounded ¶
Bounded is Label with a bound of the caller's, for values that are content and so run longer than names. It reports whether the bound left out anything but white space.
func Label ¶
Label makes a string that came from the file fit to appear as a name, an identifier or part of a message in the output: valid UTF-8, no control characters, no line breaks, trimmed, and of bounded length. It is for part names, content types, addresses and error text, which a file controls as much as it controls its content.
func LabelCut ¶
LabelCut is Label that also reports whether the bound left out anything but white space.
func Name ¶
Name is Label for a name that is text to be read, such as the name of an author: its ligatures are written as their letters as well.
func NameCut ¶
NameCut is Name that also reports whether the bound left out anything but white space.
Types ¶
type Flags ¶
type Flags uint8
Flags select the conventions to apply beyond validity and control characters, which always apply.
const ( // Trim removes leading and trailing white space. Trim Flags = 1 << iota // Ligatures expands U+FB00 to U+FB06 to their letters. Ligatures // Prose is what block text and table cells need. Prose = Trim | Ligatures // Verbatim is for code: nothing beyond validity and control characters. Verbatim Flags = 0 )