1 Star 0 Fork 0

CNCF/devstatscode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
unicode.go 940 Bytes
一键复制 编辑 原始数据 按行查看 历史
Lukasz Gryglicki 提交于 2019-03-18 20:33 +08:00 . Fixing package name and tests
package devstatscode
import (
"strings"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
)
// StripUnicode strip non-unicode and control characters from a string
// From: https://rosettacode.org/wiki/Strip_control_codes_and_extended_characters_from_a_string#Go
func StripUnicode(str string) string {
isOk := func(r rune) bool {
return r < 32 || r >= 127
}
t := transform.Chain(norm.NFKD, transform.RemoveFunc(isOk))
str, _, _ = transform.String(t, str)
return str
}
// NormalizeName - clean DB string from ", ', -, /, ., " ",), (, ], [ trim leading and trailing space, lowercase
// Normalize Unicode characters
func NormalizeName(str string) string {
r := strings.NewReplacer(
"-", "", "/", "", ".", "", " ", "", ",", "", ";", "", ":", "", "`", "", "(", "", ")", "", "[", "", "]", "", "<", "", ">", "", "_", "", "\"", "", "'", "",
)
return r.Replace(strings.ToLower(strings.TrimSpace(StripUnicode(str))))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cncf/devstatscode.git
git@gitee.com:cncf/devstatscode.git
cncf
devstatscode
devstatscode
master

搜索帮助