forked from taglme/nfcuid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chars.go
55 lines (47 loc) · 1.1 KB
/
chars.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
47
48
49
50
51
52
53
54
55
package main
type CharFlag int
const (
CharFlagNone CharFlag = iota
CharFlagSpace
CharFlagTab
CharFlagHyphen
CharFlagEnter
CharFlagSemiColon
CharFlagColon
CharFlagComma
)
type CharFlagDef struct {
name string
output string
}
var charFlagStrings = map[CharFlag]CharFlagDef{
CharFlagNone: CharFlagDef{"none", ""},
CharFlagSpace: CharFlagDef{"space", " "},
CharFlagTab: CharFlagDef{"tab", "\\t"},
CharFlagHyphen: CharFlagDef{"hyphen", "-"},
CharFlagEnter: CharFlagDef{"enter", "\\n"},
CharFlagSemiColon: CharFlagDef{"semicolon", ";"},
CharFlagColon: CharFlagDef{"colon", ":"},
CharFlagComma: CharFlagDef{"comma", ","},
}
func StringToCharFlag(s string) (CharFlag, bool) {
for k, v := range charFlagStrings {
if v.name == s {
return k, true
}
}
return 0, false
}
func (charFlag CharFlag) Name() string {
return charFlagStrings[charFlag].name
}
func (charFlag CharFlag) Output() string {
return charFlagStrings[charFlag].output
}
func CharFlagOptions() string {
var s string
for _, v := range charFlagStrings {
s = s + "'" + v.name + "', "
}
return s
}