Skip to content

Instantly share code, notes, and snippets.

@yhirose
Created December 6, 2015 01:54
Show Gist options
  • Select an option

  • Save yhirose/0c9f62941b1e878dd23b to your computer and use it in GitHub Desktop.

Select an option

Save yhirose/0c9f62941b1e878dd23b to your computer and use it in GitHub Desktop.
func columnWidth(s string) int {
runes := []rune(s)
w := 0
for _, r := range runes {
k := width.LookupRune(r).Kind()
if k == width.EastAsianWide || k == width.EastAsianFullwidth {
w = w + 2
} else {
w = w + 1
}
}
return w
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment