utf8.DecodeRuneInString
instead of []rune(string)[0]
GO-P4006 505 } else if len(key) == 2 && strings.HasPrefix(lkey, "f") && key[1] >= '1' && key[1] <= '9' {
506 chord = tui.F1 + int(key[1]) - '1'
507 } else if utf8.RuneCountInString(key) == 1 {
508 chord = tui.AltZ + int([]rune(key)[0]) 509 } else {
510 errorExit("unsupported key: " + key)
511 }
It is recommended to use utf8.DecodeRuneInString
instead of
[]rune(string)[0]
to prevent unwanted rune
slice allocation.
package main
func getFirstRune(s string) rune {
r := []rune(s)[0]
return r
}
package main
import (
"unicode/utf8"
)
func getFirstRune(s string) rune {
r, _ := utf8.DecodeRuneInString(s)
return r
}