6 changed files with 56 additions and 14 deletions
@ -0,0 +1,30 @@ |
|||
package str |
|||
|
|||
import ( |
|||
"unicode/utf8" |
|||
|
|||
"golang.org/x/text/width" |
|||
) |
|||
|
|||
func C(args ...string) (count int) { |
|||
for i := range args { |
|||
count += utf8.RuneCountInString(args[i]) |
|||
} |
|||
return count |
|||
} |
|||
|
|||
func DisplayWidth(ss ...string) int { |
|||
_width := 0 |
|||
for _, s := range ss { |
|||
for _, r := range s { |
|||
prop := width.LookupRune(r) |
|||
switch prop.Kind() { |
|||
case width.EastAsianWide, width.EastAsianFullwidth: |
|||
_width += 2 |
|||
default: |
|||
_width += 1 |
|||
} |
|||
} |
|||
} |
|||
return _width |
|||
} |
Loading…
Reference in new issue