This commit is contained in:
Shen Junzheng
2025-03-12 01:19:35 +08:00
parent 160040f3e1
commit 78cce92ce3
70 changed files with 10134 additions and 1 deletions

34
pkg/util/strings.go Normal file
View File

@@ -0,0 +1,34 @@
package util
import (
"fmt"
"strconv"
"unicode"
"unicode/utf8"
)
func IsNormalString(b []byte) bool {
str := string(b)
// 检查是否为有效的 UTF-8
if !utf8.ValidString(str) {
return false
}
// 检查是否全部为可打印字符
for _, r := range str {
if !unicode.IsPrint(r) {
return false
}
}
return true
}
func MustAnyToInt(v interface{}) int {
str := fmt.Sprintf("%v", v)
if i, err := strconv.Atoi(str); err == nil {
return i
}
return 0
}