-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssn.go
59 lines (56 loc) · 1.41 KB
/
ssn.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
package redact
func (this *ssnRedaction) clear() {
this.start = 0
this.length = 0
this.breakLength = 0
}
func (this *ssnRedaction) match(input []byte) {
for i, val := range input {
if i < len(this.used)-1 && this.used[i] {
this.resetCount(i)
continue
}
if isNumeric(val) {
this.length++
switch {
case this.length < MaxSSNLength_WithBreaks && this.breakLength <= MaxSSNBreakLength:
continue
case this.length == MaxSSNLength_WithBreaks && this.breakLength == MaxSSNBreakLength:
this.validateMatch(input[this.start : this.start+this.length])
}
if i < len(input)-1 {
this.resetCount(i)
}
continue
}
if i < len(input)-1 {
this.validateBreaks(val, i)
}
}
this.resetCount(0)
}
func (this *ssnRedaction) resetCount(i int) {
this.start = i + 1
this.length = 0
this.breakLength = 0
}
func (this *ssnRedaction) validateMatch(testMatch []byte) {
switch {
case testMatch[MinSSNBreakPosition] == '-' && testMatch[MaxSSNBreakPosition] == '-':
this.appendMatch(this.start, this.length)
case testMatch[MinSSNBreakPosition] == ' ' && testMatch[MaxSSNBreakPosition] == ' ':
this.appendMatch(this.start, this.length)
}
}
func (this *ssnRedaction) validateBreaks(input byte, i int) {
switch {
case input == ' ' && this.length >= 3:
this.length++
this.breakLength++
case input == '-' && this.length >= 3:
this.length++
this.breakLength++
default:
this.resetCount(i)
}
}