Documentation ¶
Overview ¶
Package width provides functionality for handling different widths in text.
Wide characters behave like ideographs; they tend to allow line breaks after each character and remain upright in vertical text layout. Narrow characters are kept together in words or runs that are rotated sideways in vertical text layout.
For more information, see https://unicode.org/reports/tr11/.
Index ¶
Constants ¶
const UnicodeVersion = "11.0.0"
UnicodeVersion is the Unicode version from which the tables in this package are derived.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Kind ¶
type Kind int
Kind indicates the type of width property as defined in https://unicode.org/reports/tr11/.
const ( // Neutral characters do not occur in legacy East Asian character sets. Neutral Kind = iota // EastAsianAmbiguous characters that can be sometimes wide and sometimes // narrow and require additional information not contained in the character // code to further resolve their width. EastAsianAmbiguous // EastAsianWide characters are wide in its usual form. They occur only in // the context of East Asian typography. These runes may have explicit // halfwidth counterparts. EastAsianWide // EastAsianNarrow characters are narrow in its usual form. They often have // fullwidth counterparts. EastAsianNarrow // EastAsianFullwidth characters have a compatibility decompositions of type // wide that map to a narrow counterpart. EastAsianFullwidth // EastAsianHalfwidth characters have a compatibility decomposition of type // narrow that map to a wide or ambiguous counterpart, plus U+20A9 ₩ WON // SIGN. EastAsianHalfwidth )
type Properties ¶
type Properties struct {
// contains filtered or unexported fields
}
Properties provides access to width properties of a rune.
func Lookup ¶
func Lookup(b []byte) (p Properties, size int)
Lookup reports the Properties of the first rune in b and the number of bytes of its UTF-8 encoding.
func LookupString ¶
func LookupString(s string) (p Properties, size int)
LookupString reports the Properties of the first rune in s and the number of bytes of its UTF-8 encoding.
func (Properties) Folded ¶
func (p Properties) Folded() rune
Folded returns the folded variant of a rune or 0 if the rune is canonical.
func (Properties) Kind ¶
func (p Properties) Kind() Kind
Kind returns the Kind of a rune as defined in Unicode TR #11. See https://unicode.org/reports/tr11/ for more details.
func (Properties) Narrow ¶
func (p Properties) Narrow() rune
Narrow returns the narrow variant of a rune or 0 if the rune is already narrow or doesn't have a narrow variant.
func (Properties) Wide ¶
func (p Properties) Wide() rune
Wide returns the wide variant of a rune or 0 if the rune is already wide or doesn't have a wide variant.
type Transformer ¶
type Transformer struct {
// contains filtered or unexported fields
}
Transformer implements the transform.Transformer interface.
var ( // Fold is a transform that maps all runes to their canonical width. // // Note that the NFKC and NFKD transforms in golang.org/x/text/unicode/norm // provide a more generic folding mechanism. Fold Transformer = Transformer{foldTransform{}} // Widen is a transform that maps runes to their wide variant, if // available. Widen Transformer = Transformer{wideTransform{}} // Narrow is a transform that maps runes to their narrow variant, if // available. Narrow Transformer = Transformer{narrowTransform{}} )
func (Transformer) Bytes ¶
func (t Transformer) Bytes(b []byte) []byte
Bytes returns a new byte slice with the result of applying t to b.
func (Transformer) Reset ¶
func (t Transformer) Reset()
Reset implements the transform.Transformer interface.
func (Transformer) Span ¶
func (t Transformer) Span(src []byte, atEOF bool) (n int, err error)
Span implements the transform.SpanningTransformer interface.
func (Transformer) String ¶
func (t Transformer) String(s string) string
String returns a string with the result of applying t to s.