-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdob_numeric.go
90 lines (85 loc) · 2.21 KB
/
dob_numeric.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
80
81
82
83
84
85
86
87
88
89
90
package redact
type allNumericDOB struct {
redact *dobRedaction
validNumericMonth bool
}
func (this *allNumericDOB) findMatch(input []byte) {
for i := 0; i < len(input); i++ {
if i < len(this.redact.used)-1 && this.redact.used[i] {
continue
}
if isNumeric(input[i]) {
this.redact.numericLength++
this.redact.length++
continue
}
if this.redact.length > MinDOBLength_WithBreaks && this.redact.length < MaxDOBLength_WithBreaks {
if this.redact.breakLength == MaxDOBBreakLength && this.validNumericMonth {
this.redact.appendMatch(this.redact.start, this.redact.length)
this.resetCount(i)
continue
}
}
this.validateBreaks(input[i], i)
if !this.validateDOB(input[i-this.redact.numericLength : i]) {
this.resetCount(i)
}
}
if this.redact.length >= MinDOBLength_WithBreaks && this.redact.length <= 10 && this.redact.breakLength == MaxDOBBreakLength && this.validNumericMonth {
if this.validateDOB(input[this.redact.length-this.redact.numericLength : this.redact.length]) {
this.redact.appendMatch(this.redact.start, this.redact.length)
}
}
this.resetCount(0)
}
func (this *allNumericDOB) validateDOB(input []byte) bool {
this.redact.numericLength = 0
switch len(input) {
case 0:
return true
case 4:
return validateYear(input)
case 2:
return this.validateDate(input)
case 1:
if input[0] != '0' {
return true
}
}
return false
}
func (this *allNumericDOB) validateDate(input []byte) bool {
switch {
case input[0] == '0' && input[1] <= '9' && input[1] > 0:
this.validNumericMonth = true
return true
case input[0] == '1' && input[1] <= '2':
this.validNumericMonth = true
return true
case input[0] == '3' && input[1] > 1:
return false
default:
return false
}
}
func (this *allNumericDOB) resetCount(i int) {
this.redact.start = i + 1
this.redact.length = 0
this.redact.breakLength = 0
this.redact.numericLength = 0
this.validNumericMonth = false
}
func (this *allNumericDOB) validateBreaks(input byte, i int) {
switch {
case input == '/':
this.redact.length++
this.redact.breakLength++
case input == '-':
this.redact.length++
this.redact.breakLength++
case this.redact.breakLength > 2:
this.resetCount(i)
default:
this.resetCount(i)
}
}