Example #1
0
func trimStr2Runes(s string, w int) []rune {
	if w <= 0 {
		return []rune{}
	}
	sw := rw.StringWidth(s)
	if sw > w {
		return []rune(rw.Truncate(s, w, dot))
	}
	return str2runes(s) //[]rune(rw.Truncate(s, w, ""))
}
Example #2
0
// TrimStrIfAppropriate trim string to "s[:-1] + …"
// if string > width otherwise return string
func TrimStrIfAppropriate(s string, w int) string {
	if w <= 0 {
		return ""
	}

	sw := rw.StringWidth(s)
	if sw > w {
		return rw.Truncate(s, w, dot)
	}

	return s
}
Example #3
0
func BenchmarkOtherlib3(b *testing.B) {
	for n := 0; n < b.N; n++ {
		_ = mattn.StringWidth("あいうえおあいうえおえおおおおおおおおおおおおおおおおおおおおおおおおおおおおおお")
	}
}
Example #4
0
func BenchmarkOtherlib2(b *testing.B) {
	for n := 0; n < b.N; n++ {
		_ = mattn.StringWidth("■㈱の世界①")
	}

}
Example #5
0
func BenchmarkOtherlibEasyString(b *testing.B) {
	for n := 0; n < b.N; n++ {
		_ = mattn.StringWidth("abcdefgkljjsfkjn")
	}
}
Example #6
0
func BenchmarkOtherlib4(b *testing.B) {
	for n := 0; n < b.N; n++ {
		_ = mattn.StringWidth(long)
	}
}
Example #7
0
func strWidth(s string) int {
	return rw.StringWidth(s)
}
Example #8
0
	ColorBlue
	ColorMagenta
	ColorCyan
	ColorWhite
)

const NumberofColors = 8 //Have a constant that defines number of colors
const (
	AttrBold Attribute = 1 << (iota + 9)
	AttrUnderline
	AttrReverse
)

var (
	dot  = "…"
	dotw = rw.StringWidth(dot)
)

/* ----------------------- End ----------------------------- */

func toTmAttr(x Attribute) tm.Attribute {
	return tm.Attribute(x)
}

func str2runes(s string) []rune {
	return []rune(s)
}

func trimStr2Runes(s string, w int) []rune {
	if w <= 0 {
		return []rune{}