2 Star 2 Fork 9

王布衣/gox

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
string_camel.go 868 Bytes
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2021-08-23 12:30 . 增加string书写风格转换
// Copyright (c) 2017, A. Stoewer <adrian.stoewer@rz.ifi.lmu.de>
// All rights reserved.
package api
import (
"strings"
)
// UpperCamelCase converts a string into camel case starting with a upper case letter.
func UpperCamelCase(s string) string {
return camelCase(s, true)
}
// LowerCamelCase converts a string into camel case starting with a lower case letter.
func LowerCamelCase(s string) string {
return camelCase(s, false)
}
func camelCase(s string, upper bool) string {
s = strings.TrimSpace(s)
buffer := make([]rune, 0, len(s))
stringIter(s, func(prev, curr, next rune) {
if !isDelimiter(curr) {
if isDelimiter(prev) || (upper && prev == 0) {
buffer = append(buffer, toUpper(curr))
} else if isLower(prev) {
buffer = append(buffer, curr)
} else {
buffer = append(buffer, toLower(curr))
}
}
})
return string(buffer)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/gox.git
git@gitee.com:quant1x/gox.git
quant1x
gox
gox
v1.12.7

搜索帮助