width

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

package width provides methods to get text width defined by unicode east asisn width. see http://unicode.org/reports/tr11/

Index

Constants

This section is empty.

Variables

View Source
var Default = NewCondition(runewidth.EastAsianWidth)

default Condition which can calucate east asian width depended on running system environment. you can check your system's east asian condition using by:

isEastAsian = Default.IsEastAsian

Functions

func BytesWidth

func BytesWidth(bs []byte) int

return unicode east asian width in given bytes, using default condition. It will panic if the bytes is invalid utf8 encoding.

func RuneWidth

func RuneWidth(r rune) int

return unicode east asian width in a rune, using default condition. It will panic if the rune is invalid.

func StringWidth

func StringWidth(s string) int

return unicode east asian width in given string, using default condition. It will panic if the string is invalid utf8 encoding.

Types

type Condition

type Condition struct {
	IsEastAsian bool
	// contains filtered or unexported fields
}

Condition holds isEastAsian flag and can calucate east asian width using that flag. zero value of Condition can not use .RuneWidth(), but other methods can do.

func NewCondition

func NewCondition(isEastAsian bool) *Condition

return new condition

func (Condition) BytesWidth

func (c Condition) BytesWidth(bs []byte) int

return unicode east asian width in given bytes. it will panic if the bytes is invalid utf8 encoding.

func (Condition) RuneWidth

func (c Condition) RuneWidth(r rune) int

return unicode east asian width in a rune.

func (Condition) StringWidth

func (c Condition) StringWidth(s string) int

same as BytesWidth exception that input type is string.

Jump to

Keyboard shortcuts

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