Skip to content

Commit 0f94aa8

Browse files
committed
implemented a potential fix for #772 using ettle/strcase#13
1 parent d1df80b commit 0f94aa8

4 files changed

Lines changed: 8 additions & 6 deletions

File tree

glop/sentence/case.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"strings"
1010
"unicode"
1111

12+
"github.com/ettle/strcase"
1213
"github.com/fatih/camelcase"
13-
"github.com/iancoleman/strcase"
1414
)
1515

1616
// ProperNouns is a set-style map that contains all of the proper
@@ -38,10 +38,9 @@ func AddProperNouns(nouns ...string) {
3838
//
3939
// This is a string in sentence case that I wrote in the USA with the help of Google
4040
func Case(s string) string {
41-
// if we are not already in camel case, we convert to it
42-
if strings.ContainsAny(s, "-_.\t ") {
43-
s = strcase.ToCamel(s)
44-
}
41+
caser := strcase.NewCaser(false, nil, nil)
42+
s = caser.ToCase(s, strcase.TitleCase|strcase.PreserveInitialism, 0)
43+
4544
words := camelcase.Split(s)
4645
for i, word := range words {
4746
// "I" is always capitalized

glop/sentence/case_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"testing"
99
)
1010

11-
func TestSentenceCase(t *testing.T) {
11+
func TestCase(t *testing.T) {
1212
AddProperNouns("Google")
1313
src := "thisIsAStringInSentenceCaseThatIWroteInTheUSAWithTheHelpOfGoogle"
1414
want := "This is a string in sentence case that I wrote in the USA with the help of Google"

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/aymerick/douceur v0.2.0
1111
github.com/chewxy/math32 v1.10.1
1212
github.com/ericchiang/css v1.3.0
13+
github.com/ettle/strcase v0.2.1-0.20230114185658-e5db6a6becf3
1314
github.com/fatih/camelcase v1.0.0
1415
github.com/fsnotify/fsnotify v1.7.0
1516
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240118000515-a250818d05e3

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ github.com/dlclark/regexp2 v1.10.0 h1:+/GIL799phkJqYW+3YbOd8LCcbHzT0Pbo8zl70MHsq
3131
github.com/dlclark/regexp2 v1.10.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
3232
github.com/ericchiang/css v1.3.0 h1:e0vS+vpujMjtT3/SYu7qTHn1LVzXWcLCCDjlfq3YlLY=
3333
github.com/ericchiang/css v1.3.0/go.mod h1:sVSdL+MFR9Q4cKJMQzpIkHIDOLiK+7Wmjjhq7D+MubA=
34+
github.com/ettle/strcase v0.2.1-0.20230114185658-e5db6a6becf3 h1:UveVPOxnOkBoelw2vLZTm+L0Z7fe/nz5d6JlY+A3QdE=
35+
github.com/ettle/strcase v0.2.1-0.20230114185658-e5db6a6becf3/go.mod h1:DajmHElDSaX76ITe3/VHVyMin4LWSJN5Z909Wp+ED1A=
3436
github.com/fatih/camelcase v1.0.0 h1:hxNvNX/xYBp0ovncs8WyWZrOrpBNub/JfaMvbURyft8=
3537
github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc=
3638
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=

0 commit comments

Comments
 (0)