-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_initMethods.go
79 lines (68 loc) · 1.85 KB
/
data_initMethods.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package passwordGenerator
import "math/big"
func (d *Data) initAvailableRunes() {
d.initAvailableRunesByIncludingUpperCaseLetters()
d.initAvailableRunesByIncludingLowerCaseLetters()
d.initAvailableRunesByIncludingDigits()
d.initAvailableRunesByIncludingRunesList()
d.initAvailableRunesByExcludingAmbiguousRunes()
d.initAvailableRunesByExcludingRunesList()
d.availableRunesLenBig = big.NewInt(int64(len(d.availableRunes)))
}
func (d *Data) initAvailableRunesByIncludingUpperCaseLetters() {
if d.options.IncludeUpperCaseLetters {
for r := 'A'; r <= 'Z'; r++ {
d.availableRunes = append(d.availableRunes, r)
}
}
}
func (d *Data) initAvailableRunesByIncludingLowerCaseLetters() {
if d.options.IncludeLowerCaseLetters {
for r := 'a'; r <= 'z'; r++ {
d.availableRunes = append(d.availableRunes, r)
}
}
}
func (d *Data) initAvailableRunesByIncludingDigits() {
if d.options.IncludeDigits {
for r := '0'; r <= '9'; r++ {
d.availableRunes = append(d.availableRunes, r)
}
}
}
func (d *Data) initAvailableRunesByIncludingRunesList() {
for _, r := range d.options.IncludeRunesList {
var alreadyFound bool
for _, r2 := range d.availableRunes {
if r2 == r {
alreadyFound = true
break
}
}
if !alreadyFound {
d.availableRunes = append(d.availableRunes, r)
}
}
}
func (d *Data) initAvailableRunesByExcludingAmbiguousRunes() {
if d.options.ExcludeAmbiguousRunes {
for _, r := range dataAmbiguousRunes {
for i, r2 := range d.availableRunes {
if r2 == r {
d.availableRunes = append(d.availableRunes[:i], d.availableRunes[i+1:]...)
break
}
}
}
}
}
func (d *Data) initAvailableRunesByExcludingRunesList() {
for _, r := range d.options.ExcludeRunesList {
for i, r2 := range d.availableRunes {
if r2 == r {
d.availableRunes = append(d.availableRunes[:i], d.availableRunes[i+1:]...)
break
}
}
}
}