Move to Go 1.27, and fix initials for non-ASCII names
Initials() capped the loop with len(out) == 2, which counts bytes: a name starting with Ä, Ö or Å filled the budget on its own and returned a single letter. Count the initials taken instead. go fix also wanted a strings.Builder here, but that allocates a string per iteration to measure a two-character result. Took its SplitSeq suggestion in lyrics.go, which drops an intermediate slice.
This commit is contained in:
@@ -35,10 +35,11 @@ type member struct {
|
||||
|
||||
// Initials for the avatar circle: no default image on disk, no identicon generator.
|
||||
func (m *member) Initials() string {
|
||||
out := ""
|
||||
out, n := "", 0
|
||||
for _, f := range strings.Fields(m.Name) {
|
||||
out += strings.ToUpper(string([]rune(f)[0]))
|
||||
if len(out) == 2 {
|
||||
// ponytail: count runes taken, not bytes — "Ä" is 2 bytes and used to end the loop early.
|
||||
if n++; n == 2 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user