1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 13:19:43 +02:00

Ensure initials calculate correctly for Unicode via runes

This commit is contained in:
Harvey Kandola 2018-05-02 14:50:22 +01:00
parent b839a0753c
commit e234471b1e
2 changed files with 4 additions and 2 deletions

View file

@ -23,11 +23,11 @@ func MakeInitials(firstname, lastname string) string {
b := "" b := ""
if len(firstname) > 0 { if len(firstname) > 0 {
a = firstname[:1] a = string([]rune(firstname)[:1])
} }
if len(lastname) > 0 { if len(lastname) > 0 {
b = lastname[:1] b = string([]rune(lastname)[:1])
} }
return strings.ToUpper(a + b) return strings.ToUpper(a + b)

View file

@ -13,11 +13,13 @@ package stringutil
import "testing" import "testing"
// go test github.com/documize/community/core/stringutil -run TestInitials
func TestInitials(t *testing.T) { func TestInitials(t *testing.T) {
in(t, "Harvey", "Kandola", "HK") in(t, "Harvey", "Kandola", "HK")
in(t, "Harvey", "", "H") in(t, "Harvey", "", "H")
in(t, "", "Kandola", "K") in(t, "", "Kandola", "K")
in(t, "", "", "") in(t, "", "", "")
in(t, "Иванов", "Иванов", "ИИ")
} }
func in(t *testing.T, firstname, lastname, expecting string) { func in(t *testing.T, firstname, lastname, expecting string) {