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:
@@ -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 {
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user