初次提交

This commit is contained in:
liuzhihang1
2024-06-26 20:45:23 +08:00
parent 4b388a5be1
commit 831ea9889f
57 changed files with 3945 additions and 0 deletions

32
utils/unicode.go Normal file
View File

@@ -0,0 +1,32 @@
package utils
import (
"regexp"
"unicode/utf8"
)
func RemoveNotValidUtf8InString(s string) string {
ret := s
if !utf8.ValidString(s) {
v := make([]rune, 0, len(s))
for i, r := range s {
if r == utf8.RuneError {
_, size := utf8.DecodeRuneInString(s[i:])
if size == 1 {
continue
}
}
v = append(v, r)
}
ret = string(v)
}
return ret
}
func RemoveANSI(input string) string {
// Define the regular expression to match ANSI escape sequences
re := regexp.MustCompile(`\x1b\[[0-9;]*[a-zA-Z]`)
// Replace all ANSI escape sequences with an empty string
cleanedString := re.ReplaceAllString(input, "")
return cleanedString
}