@@ -7,6 +7,7 @@ func (this *phoneRedaction) clear() {
7
7
this .numericLength = 0
8
8
}
9
9
func (this * phoneRedaction ) match (input []byte ) {
10
+ var previousBreak byte
10
11
for i := 0 ; i < len (input )- 1 ; i ++ {
11
12
if i < len (this .used )- 1 && this .used [i ] {
12
13
this .resetCount (i )
@@ -27,7 +28,8 @@ func (this *phoneRedaction) match(input []byte) {
27
28
continue
28
29
}
29
30
if i < len (input )- 1 {
30
- this .validateBreaks (input [i ], i )
31
+ this .validateBreaks (input [i ], previousBreak , i )
32
+ previousBreak = input [i ]
31
33
}
32
34
}
33
35
}
@@ -38,37 +40,45 @@ func (this *phoneRedaction) resetCount(i int) {
38
40
this .breakLength = 0
39
41
this .numericLength = 0
40
42
}
41
- func (this * phoneRedaction ) validateBreaks (input byte , i int ) {
42
- switch input {
43
- case '-' :
44
- this .length ++
45
- this .breakLength ++
46
- case '(' :
47
- this .length ++
48
- this .breakLength ++
49
- case ')' :
50
- this .length ++
51
- this .breakLength ++
52
- case '+' :
43
+ func (this * phoneRedaction ) validateBreaks (input , previousBreak byte , i int ) {
44
+ if ! validBreak (input ) {
45
+ this .resetCount (i )
46
+ return
47
+ }
48
+ if input == ' ' && previousBreak != ')' {
49
+ this .resetCount (i )
50
+ return
51
+ }
52
+ if input == '+' {
53
53
if this .start != i {
54
54
this .resetCount (i )
55
- break
56
55
}
57
56
this .start = i + 1
58
57
this .length = 1
59
- default :
60
- this .resetCount (i )
58
+ return
61
59
}
60
+
61
+ this .length ++
62
+ this .breakLength ++
62
63
}
64
+ func validBreak (input byte ) bool {
65
+ return input == '-' || input == '(' || input == ')' || input == ' ' || input == '+'
66
+ }
67
+
63
68
func (this * phoneRedaction ) validateMatch (testMatch []byte ) {
64
69
switch {
65
70
case this .length == MinPhoneLength_WithBreaks && this .breakLength == MinPhoneBreakLength :
66
71
if testMatch [3 ] == '-' && testMatch [7 ] == '-' {
67
72
this .appendMatch (this .start , this .length )
68
73
}
69
- case this .length == MaxPhoneLength_WithBreaks && this .breakLength == MaxPhoneBreakLength :
74
+
75
+ case this .length == MaxPhoneLength_WithBreaks - 1 && this .breakLength == MaxPhoneBreakLength - 1 : // No space
70
76
if testMatch [1 ] == '(' && testMatch [5 ] == ')' && testMatch [9 ] == '-' {
71
77
this .appendMatch (this .start , this .length )
72
78
}
79
+ case this .length == MaxPhoneLength_WithBreaks && this .breakLength == MaxPhoneBreakLength : // With space
80
+ if testMatch [1 ] == '(' && testMatch [5 ] == ')' && testMatch [6 ] == ' ' && testMatch [10 ] == '-' {
81
+ this .appendMatch (this .start , this .length )
82
+ }
73
83
}
74
84
}
0 commit comments