46 lines
742 B
Go
46 lines
742 B
Go
package utils
|
|
|
|
import "strings"
|
|
|
|
func Strip(s string) string {
|
|
var result strings.Builder
|
|
for i := 0; i < len(s); i++ {
|
|
b := s[i]
|
|
if ('a' <= b && b <= 'z') ||
|
|
('A' <= b && b <= 'Z') ||
|
|
('0' <= b && b <= '9') {
|
|
result.WriteByte(b)
|
|
}
|
|
}
|
|
return result.String()
|
|
}
|
|
|
|
func DedupeSlice[T comparable](sliceList []T) []T {
|
|
dedupeMap := make(map[T]struct{})
|
|
list := []T{}
|
|
|
|
for _, slice := range sliceList {
|
|
if _, exists := dedupeMap[slice]; !exists {
|
|
dedupeMap[slice] = struct{}{}
|
|
list = append(list, slice)
|
|
}
|
|
}
|
|
|
|
return list
|
|
}
|
|
|
|
func Check(e error) {
|
|
if e != nil {
|
|
panic(e)
|
|
}
|
|
}
|
|
|
|
func Filter[T any](ss []T, test func(T) bool) (ret []T) {
|
|
for _, s := range ss {
|
|
if test(s) {
|
|
ret = append(ret, s)
|
|
}
|
|
}
|
|
return
|
|
}
|