27 lines
491 B
Go
27 lines
491 B
Go
package utils
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/mozillazg/go-pinyin"
|
|
)
|
|
|
|
func Contains[T string | int | uint](element T, slice []T) bool {
|
|
for _, v := range slice {
|
|
if v == element {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func PinyinAbbr(source string) string {
|
|
abbr := pinyin.Pinyin(source, pinyin.NewArgs())
|
|
var abbrCollect = make([]string, 0)
|
|
for _, a := range abbr {
|
|
abbrCollect = append(abbrCollect, a[0][0:1])
|
|
}
|
|
finalAbbr := strings.Join(abbrCollect, "")
|
|
return finalAbbr
|
|
}
|