-
Notifications
You must be signed in to change notification settings - Fork 0
/
foo.go
46 lines (42 loc) · 896 Bytes
/
foo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"fmt"
"github.com/henrylee2cn/pholcus/common/pinyin"
"regexp"
)
func ValidateFullName(fullName string) any {
reg := regexp.MustCompile(`^[\p{Han}\w]+([\p{Han}\w\s.-]*)$`)
println(fullName)
if !reg.MatchString(fullName) {
fmt.Println("名字中含有特殊字符")
return nil
}
return nil
}
func main() {
//ValidateFullName("panjinhao")
urlToken("潘金豪pan0320爱你")
// [pan jin hao pan0320 ai ni]
}
func urlToken(name string) {
rs := []rune(name)
var ss []string
i := 0
isLetterDigit := func(r rune) bool {
return r >= 'a' && r <= 'z' || r >= 'A' && r <= 'Z' || r >= '0' && r <= '9'
}
for i < len(rs) {
if isLetterDigit(rs[i]) {
s := ""
for isLetterDigit(rs[i]) {
s += string(rs[i])
i++
}
ss = append(ss, s)
} else {
ss = append(ss, pinyin.SinglePinyin(rs[i], pinyin.NewArgs())[0])
i++
}
}
fmt.Println(ss)
}