1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 21:02:27 +08:00

feat: add UpperFirst func

This commit is contained in:
dudaodong
2022-01-22 18:55:41 +08:00
parent aa64bf5bee
commit ca88687f3d
2 changed files with 23 additions and 0 deletions

View File

@@ -54,6 +54,18 @@ func Capitalize(s string) string {
return string(out)
}
// UpperFirst converts the first character of string to upper case.
func UpperFirst(s string) string {
if len(s) == 0 {
return ""
}
r, size := utf8.DecodeRuneInString(s)
r = unicode.ToUpper(r)
return string(r) + s[size:]
}
// LowerFirst converts the first character of string to lower case.
func LowerFirst(s string) string {
if len(s) == 0 {

View File

@@ -50,6 +50,17 @@ func TestSnakeCase(t *testing.T) {
assert.NotEqual("foo-bar", SnakeCase("foo_Bar"))
}
func TestUpperFirst(t *testing.T) {
assert := internal.NewAssert(t, "TestLowerFirst")
assert.Equal("Foo", UpperFirst("foo"))
assert.Equal("BAR", UpperFirst("bAR"))
assert.Equal("FOo", UpperFirst("FOo"))
assert.Equal("FOo大", UpperFirst("fOo大"))
assert.NotEqual("Bar", UpperFirst("BAR"))
}
func TestLowerFirst(t *testing.T) {
assert := internal.NewAssert(t, "TestLowerFirst")