This commit is contained in:
XOF
2025-11-20 12:24:05 +08:00
commit f28bdc751f
164 changed files with 64248 additions and 0 deletions

34
internal/utils/parser.go Normal file
View File

@@ -0,0 +1,34 @@
// Filename: internal/utils/parser.go
package utils
import (
"encoding/json"
"regexp"
"strings"
)
// ParseKeysFromText 是一个共享的工具函数,用于从各种格式的文本中解析出密钥列表。
// 因为它是共享的,所以函数名首字母大写以导出。
func ParseKeysFromText(text string) []string {
var keys []string
if json.Unmarshal([]byte(text), &keys) == nil && len(keys) > 0 {
var cleanedKeys []string
for _, key := range keys {
trimmed := strings.TrimSpace(key)
if trimmed != "" {
cleanedKeys = append(cleanedKeys, trimmed)
}
}
return cleanedKeys
}
keys = []string{}
delimiters := regexp.MustCompile(`[\s,;|\n\r\t]+`)
splitKeys := delimiters.Split(strings.TrimSpace(text), -1)
for _, key := range splitKeys {
trimmed := strings.TrimSpace(key)
if trimmed != "" {
keys = append(keys, trimmed)
}
}
return keys
}