You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
330 B
18 lines
330 B
9 years ago
|
package pb
|
||
|
|
||
|
import (
|
||
|
"regexp"
|
||
|
"unicode/utf8"
|
||
|
)
|
||
|
|
||
|
// Finds the control character sequences (like colors)
|
||
|
var ctrlFinder = regexp.MustCompile("\x1b\x5b[0-9]+\x6d")
|
||
|
|
||
|
func escapeAwareRuneCountInString(s string) int {
|
||
|
n := utf8.RuneCountInString(s)
|
||
|
for _, sm := range ctrlFinder.FindAllString(s, -1) {
|
||
|
n -= len(sm)
|
||
|
}
|
||
|
return n
|
||
|
}
|