mirror of
https://github.com/documize/community.git
synced 2025-07-19 05:09:42 +02:00
Ensure initials calculate correctly for Unicode via runes
This commit is contained in:
parent
b839a0753c
commit
e234471b1e
2 changed files with 4 additions and 2 deletions
|
@ -23,11 +23,11 @@ func MakeInitials(firstname, lastname string) string {
|
|||
b := ""
|
||||
|
||||
if len(firstname) > 0 {
|
||||
a = firstname[:1]
|
||||
a = string([]rune(firstname)[:1])
|
||||
}
|
||||
|
||||
if len(lastname) > 0 {
|
||||
b = lastname[:1]
|
||||
b = string([]rune(lastname)[:1])
|
||||
}
|
||||
|
||||
return strings.ToUpper(a + b)
|
||||
|
|
|
@ -13,11 +13,13 @@ package stringutil
|
|||
|
||||
import "testing"
|
||||
|
||||
// go test github.com/documize/community/core/stringutil -run TestInitials
|
||||
func TestInitials(t *testing.T) {
|
||||
in(t, "Harvey", "Kandola", "HK")
|
||||
in(t, "Harvey", "", "H")
|
||||
in(t, "", "Kandola", "K")
|
||||
in(t, "", "", "")
|
||||
in(t, "Иванов", "Иванов", "ИИ")
|
||||
}
|
||||
|
||||
func in(t *testing.T, firstname, lastname, expecting string) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue