Skip to content

Commit

Permalink
Update php.go
Browse files Browse the repository at this point in the history
modify ucwords
  • Loading branch information
syyongx authored Dec 19, 2022
1 parent 558cf5e commit 7572ff3
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions php.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ import (
"time"
"unicode"
"unicode/utf8"

"golang.org/x/text/cases"
"golang.org/x/text/language"
)

//////////// Date/Time Functions ////////////
Expand Down Expand Up @@ -208,10 +205,36 @@ func Lcfirst(str string) string {

// Ucwords ucwords()
func Ucwords(str string) string {
caser := cases.Title(language.English)
titleStr := caser.String(str)
isSeparator := func(r rune) bool {
if r <= 0x7F {
switch {
case '0' <= r && r <= '9':
return false
case 'a' <= r && r <= 'z':
return false
case 'A' <= r && r <= 'Z':
return false
case r == '_':
return false
}
return true
}
if unicode.IsLetter(r) || unicode.IsDigit(r) {
return false
}

return titleStr
return unicode.IsSpace(r)
}

prev := ' '
return strings.Map(func(r rune) rune {
if isSeparator(prev) {
prev = r
return unicode.ToTitle(r)
}
prev = r
return r
}, str)
}

// Substr substr()
Expand Down

0 comments on commit 7572ff3

Please sign in to comment.