Files
KubeSphere CI Bot 447a51f08b feat: kubesphere 4.0 (#6115)
* feat: kubesphere 4.0

Signed-off-by: ci-bot <ci-bot@kubesphere.io>

* feat: kubesphere 4.0

Signed-off-by: ci-bot <ci-bot@kubesphere.io>

---------

Signed-off-by: ci-bot <ci-bot@kubesphere.io>
Co-authored-by: ks-ci-bot <ks-ci-bot@example.com>
Co-authored-by: joyceliu <joyceliu@yunify.com>
2024-09-06 11:05:52 +08:00

39 lines
1.1 KiB
Go

package flect
import (
"strings"
"unicode"
)
// Titleize will capitalize the start of each part
// "Nice to see you!" = "Nice To See You!"
// "i've read a book! have you?" = "I've Read A Book! Have You?"
// "This is `code` ok" = "This Is `code` OK"
func Titleize(s string) string {
return New(s).Titleize().String()
}
// Titleize will capitalize the start of each part
// "Nice to see you!" = "Nice To See You!"
// "i've read a book! have you?" = "I've Read A Book! Have You?"
// "This is `code` ok" = "This Is `code` OK"
func (i Ident) Titleize() Ident {
var parts []string
// TODO: we need to reconsider the design.
// this approach preserves inline code block as is but it also
// preserves the other words start with a special character.
// I would prefer: "*wonderful* world" to be "*Wonderful* World"
for _, part := range i.Parts {
// CAUTION: in unicode, []rune(str)[0] is not rune(str[0])
runes := []rune(part)
x := string(unicode.ToTitle(runes[0]))
if len(runes) > 1 {
x += string(runes[1:])
}
parts = append(parts, x)
}
return New(strings.Join(parts, " "))
}