Skip to content

Commit

Permalink
Merge pull request #42 from divan/master
Browse files Browse the repository at this point in the history
Fix capitalization for non-English strings
  • Loading branch information
paganotoni authored Aug 28, 2020
2 parents 4230f63 + db3defb commit 64ac02e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
9 changes: 3 additions & 6 deletions capitalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ func Capitalize(s string) string {
// bob dylan = Bob dylan
// widget_id = Widget_id
func (i Ident) Capitalize() Ident {
var x string
if len(i.Parts) == 0 {
return New("")
}
x = string(unicode.ToTitle(rune(i.Original[0])))
if len(i.Original) > 1 {
x += i.Original[1:]
}
return New(x)
runes := []rune(i.Original)
runes[0] = unicode.ToTitle(runes[0])
return New(string(runes))
}
1 change: 1 addition & 0 deletions capitalize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func Test_Capitalize(t *testing.T) {
{"widget_id", "Widget_id"},
{"widget_ID", "Widget_ID"},
{"widget ID", "Widget ID"},
{"гофер", "Гофер"}, // it's "gopher" in Ukrainian
}

for _, tt := range table {
Expand Down

0 comments on commit 64ac02e

Please sign in to comment.