runewidth

package module
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2023 License: MIT Imports: 4 Imported by: 2,148

README

go-runewidth

Build Status Codecov GoDoc Go Report Card

Provides functions to get fixed width of the character or string.

Usage

runewidth.StringWidth("つのだ☆HIRO") == 12

Author

Yasuhiro Matsumoto

License

under the MIT License: http://mattn.mit-license.org/2013

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// EastAsianWidth will be set true if the current locale is CJK
	EastAsianWidth bool

	// StrictEmojiNeutral should be set false if handle broken fonts
	StrictEmojiNeutral bool = true

	// DefaultCondition is a condition in current locale
	DefaultCondition = &Condition{
		EastAsianWidth:     false,
		StrictEmojiNeutral: true,
	}
)

Functions

func CreateLUT added in v0.0.14

func CreateLUT()

CreateLUT will create an in-memory lookup table of 557055 bytes for faster operation. This should not be called concurrently with other operations.

func FillLeft

func FillLeft(s string, w int) string

FillLeft return string filled in left by spaces in w cells

func FillRight

func FillRight(s string, w int) string

FillRight return string filled in left by spaces in w cells

func IsAmbiguousWidth

func IsAmbiguousWidth(r rune) bool

IsAmbiguousWidth returns whether is ambiguous width or not.

func IsEastAsian

func IsEastAsian() bool

IsEastAsian return true if the current locale is CJK

func IsNeutralWidth

func IsNeutralWidth(r rune) bool

IsNeutralWidth returns whether is neutral width or not.

func RuneWidth

func RuneWidth(r rune) int

RuneWidth returns the number of cells in r. See http://www.unicode.org/reports/tr11/

func StringWidth

func StringWidth(s string) (width int)

StringWidth return width as you can see

func Truncate

func Truncate(s string, w int, tail string) string

Truncate return string truncated with w cells

func TruncateLeft added in v0.0.14

func TruncateLeft(s string, w int, prefix string) string

TruncateLeft cuts w cells from the beginning of the `s`.

func Wrap

func Wrap(s string, w int) string

Wrap return string wrapped with w cells

Types

type Condition

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

Condition have flag EastAsianWidth whether the current locale is CJK or not.

func NewCondition

func NewCondition() *Condition

NewCondition return new instance of Condition which is current locale.

func (*Condition) CreateLUT added in v0.0.14

func (c *Condition) CreateLUT()

CreateLUT will create an in-memory lookup table of 557056 bytes for faster operation. This should not be called concurrently with other operations on c. If options in c is changed, CreateLUT should be called again.

func (*Condition) FillLeft

func (c *Condition) FillLeft(s string, w int) string

FillLeft return string filled in left by spaces in w cells

func (*Condition) FillRight

func (c *Condition) FillRight(s string, w int) string

FillRight return string filled in left by spaces in w cells

func (*Condition) RuneWidth

func (c *Condition) RuneWidth(r rune) int

RuneWidth returns the number of cells in r. See http://www.unicode.org/reports/tr11/

func (*Condition) StringWidth

func (c *Condition) StringWidth(s string) (width int)

StringWidth return width as you can see

func (*Condition) Truncate

func (c *Condition) Truncate(s string, w int, tail string) string

Truncate return string truncated with w cells

func (*Condition) TruncateLeft added in v0.0.14

func (c *Condition) TruncateLeft(s string, w int, prefix string) string

TruncateLeft cuts w cells from the beginning of the `s`.

func (*Condition) Wrap

func (c *Condition) Wrap(s string, w int) string

Wrap return string wrapped with w cells

Jump to

Keyboard shortcuts

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