Skip to content

Commit 7572ff3

Browse files
authored
Update php.go
modify ucwords
1 parent 558cf5e commit 7572ff3

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

php.go

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ import (
3333
"time"
3434
"unicode"
3535
"unicode/utf8"
36-
37-
"golang.org/x/text/cases"
38-
"golang.org/x/text/language"
3936
)
4037

4138
//////////// Date/Time Functions ////////////
@@ -208,10 +205,36 @@ func Lcfirst(str string) string {
208205

209206
// Ucwords ucwords()
210207
func Ucwords(str string) string {
211-
caser := cases.Title(language.English)
212-
titleStr := caser.String(str)
208+
isSeparator := func(r rune) bool {
209+
if r <= 0x7F {
210+
switch {
211+
case '0' <= r && r <= '9':
212+
return false
213+
case 'a' <= r && r <= 'z':
214+
return false
215+
case 'A' <= r && r <= 'Z':
216+
return false
217+
case r == '_':
218+
return false
219+
}
220+
return true
221+
}
222+
if unicode.IsLetter(r) || unicode.IsDigit(r) {
223+
return false
224+
}
213225

214-
return titleStr
226+
return unicode.IsSpace(r)
227+
}
228+
229+
prev := ' '
230+
return strings.Map(func(r rune) rune {
231+
if isSeparator(prev) {
232+
prev = r
233+
return unicode.ToTitle(r)
234+
}
235+
prev = r
236+
return r
237+
}, str)
215238
}
216239

217240
// Substr substr()

0 commit comments

Comments
 (0)