...
1
2
3
4
5 package precis
6
7 import (
8 "unicode"
9
10 "golang.org/x/text/runes"
11 "golang.org/x/text/transform"
12 "golang.org/x/text/unicode/norm"
13 )
14
15 var (
16
17 Nickname *Profile = nickname
18
19
20 UsernameCaseMapped *Profile = usernameCaseMap
21
22
23 UsernameCasePreserved *Profile = usernameNoCaseMap
24
25
26
27 OpaqueString *Profile = opaquestring
28 )
29
30 var (
31 nickname = &Profile{
32 options: getOpts(
33 AdditionalMapping(func() transform.Transformer {
34 return &nickAdditionalMapping{}
35 }),
36 IgnoreCase,
37 Norm(norm.NFKC),
38 DisallowEmpty,
39 repeat,
40 ),
41 class: freeform,
42 }
43 usernameCaseMap = &Profile{
44 options: getOpts(
45 FoldWidth,
46 LowerCase(),
47 Norm(norm.NFC),
48 BidiRule,
49 ),
50 class: identifier,
51 }
52 usernameNoCaseMap = &Profile{
53 options: getOpts(
54 FoldWidth,
55 Norm(norm.NFC),
56 BidiRule,
57 ),
58 class: identifier,
59 }
60 opaquestring = &Profile{
61 options: getOpts(
62 AdditionalMapping(func() transform.Transformer {
63 return mapSpaces
64 }),
65 Norm(norm.NFC),
66 DisallowEmpty,
67 ),
68 class: freeform,
69 }
70 )
71
72
73 var mapSpaces transform.Transformer = runes.Map(func(r rune) rune {
74 if unicode.Is(unicode.Zs, r) {
75 return ' '
76 }
77 return r
78 })
79
View as plain text