1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-09 07:02:29 +08:00

Compare commits

..

4 Commits

Author SHA1 Message Date
dudaodong
56fc2aabd6 fmt: fix lint issue 2021-12-28 10:08:08 +08:00
dudaodong
0ddd52225b Merge branch 'main' of github.com:duke-git/lancet into main 2021-12-28 10:07:33 +08:00
donutloop
3919160e38 Optimized: Capitalize (#4)
* Use unicode.ToUpper func to convert first letter in string to upper case
letter.

* Preallocate memory with correct length and cap because the final
  string is not changing.
2021-12-28 10:04:15 +08:00
dudaodong
40ec5bc0f6 fmt: fix lint issue 2021-12-27 20:40:54 +08:00
2 changed files with 9 additions and 11 deletions

View File

@@ -2,7 +2,6 @@
// Use of this source code is governed by MIT license // Use of this source code is governed by MIT license
// Package function implements some functions for control the function execution and some is for functional programming. // Package function implements some functions for control the function execution and some is for functional programming.
package function package function
import ( import (
@@ -36,10 +35,10 @@ func Before(n int, fn interface{}) func(args ...interface{}) []reflect.Value {
return res return res
} }
} }
// Fn is for curry function which is func(...interface{}) interface{}
type Fn func(...interface{}) interface{} type Fn func(...interface{}) interface{}
// Curry make a curryed function // Curry make a curry function
func (f Fn) Curry(i interface{}) func(...interface{}) interface{} { func (f Fn) Curry(i interface{}) func(...interface{}) interface{} {
return func(values ...interface{}) interface{} { return func(values ...interface{}) interface{} {
v := append([]interface{}{i}, values...) v := append([]interface{}{i}, values...)

View File

@@ -7,6 +7,7 @@ package strutil
import ( import (
"regexp" "regexp"
"strings" "strings"
"unicode"
) )
// CamelCase covert string to camelCase string. // CamelCase covert string to camelCase string.
@@ -40,18 +41,16 @@ func Capitalize(s string) string {
return "" return ""
} }
res := "" out := make([]rune, len(s))
for i, v := range []rune(s) { for i, v := range s {
if i == 0 { if i == 0 {
if v >= 97 && v <= 122 { out[i] = unicode.ToUpper(v)
v -= 32
}
res += string(v)
} else { } else {
res += strings.ToLower(string(v)) out[i] = unicode.ToLower(v)
} }
} }
return res
return string(out)
} }
// LowerFirst converts the first character of string to lower case. // LowerFirst converts the first character of string to lower case.