package width

Import Path
	golang.org/x/text/width (on go.dev)

Dependency Relation
	imports 3 packages, and imported by one package

Involved Source Files kind_string.go tables15.0.0.go transform.go trieval.go 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/.
Code Examples package main import ( "fmt" "golang.org/x/text/width" ) func main() { s := "abヲ₩○¥A" f := width.Fold.String(s) fmt.Printf("%U: %s\n", []rune(s), s) fmt.Printf("%U: %s\n", []rune(f), f) } package main import ( "fmt" "golang.org/x/text/width" ) func main() { s := "abヲ₩○¥A" n := width.Narrow.String(s) fmt.Printf("%U: %s\n", []rune(s), s) fmt.Printf("%U: %s\n", []rune(n), n) // Ambiguous characters with a halfwidth equivalent get mapped as well. s = "←" n = width.Narrow.String(s) fmt.Printf("%U: %s\n", []rune(s), s) fmt.Printf("%U: %s\n", []rune(n), n) } package main import ( "fmt" "golang.org/x/text/width" ) func main() { s := "ab¥ヲ₩○" w := width.Widen.String(s) fmt.Printf("%U: %s\n", []rune(s), s) fmt.Printf("%U: %s\n", []rune(w), w) }
Package-Level Type Names (total 3)
/* sort by: | */
Kind indicates the type of width property as defined in https://unicode.org/reports/tr11/. ( Kind) String() string Kind : fmt.Stringer Kind : github.com/ChrisTrenkamp/goxpath/tree.Result func Properties.Kind() Kind const EastAsianAmbiguous const EastAsianFullwidth const EastAsianHalfwidth const EastAsianNarrow const EastAsianWide const Neutral
Properties provides access to width properties of a rune. Folded returns the folded variant of a rune or 0 if the rune is canonical. Kind returns the Kind of a rune as defined in Unicode TR #11. See https://unicode.org/reports/tr11/ for more details. Narrow returns the narrow variant of a rune or 0 if the rune is already narrow or doesn't have a narrow variant. Wide returns the wide variant of a rune or 0 if the rune is already wide or doesn't have a wide variant. func Lookup(b []byte) (p Properties, size int) func LookupRune(r rune) Properties func LookupString(s string) (p Properties, size int)
Transformer implements the transform.Transformer interface. Bytes returns a new byte slice with the result of applying t to b. Reset implements the transform.Transformer interface. Span implements the transform.SpanningTransformer interface. String returns a string with the result of applying t to s. Transform implements the transform.Transformer interface. Transformer : golang.org/x/text/transform.SpanningTransformer Transformer : golang.org/x/text/transform.Transformer Transformer : vendor/golang.org/x/text/transform.SpanningTransformer Transformer : vendor/golang.org/x/text/transform.Transformer var Fold var Narrow var Widen
Package-Level Functions (total 3)
Lookup reports the Properties of the first rune in b and the number of bytes of its UTF-8 encoding.
LookupRune reports the Properties of rune r.
LookupString reports the Properties of the first rune in s and the number of bytes of its UTF-8 encoding.
Package-Level Variables (total 3)
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.
Narrow is a transform that maps runes to their narrow variant, if available.
Widen is a transform that maps runes to their wide variant, if available.
Package-Level Constants (total 7)
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.
EastAsianFullwidth characters have a compatibility decompositions of type wide that map to a narrow counterpart.
EastAsianHalfwidth characters have a compatibility decomposition of type narrow that map to a wide or ambiguous counterpart, plus U+20A9 ₩ WON SIGN.
EastAsianNarrow characters are narrow in its usual form. They often have fullwidth counterparts.
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.
Neutral characters do not occur in legacy East Asian character sets.
UnicodeVersion is the Unicode version from which the tables in this package are derived.