forked from xellio/whois
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnormalize.go
102 lines (77 loc) · 1.79 KB
/
normalize.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
91
92
93
94
95
96
97
98
99
100
101
102
package whois
import (
"strings"
"github.com/fatih/camelcase"
)
//
// normalizeKey normalizes the given keys from the whois formats
//
func normalizeKey(key string) string {
ret := strings.Trim(key, " -\r")
next:
switch {
case (strings.Index(ret, "Tech ") == 0):
ret = ret[5:]
goto next
case (strings.Index(ret, "Admin ") == 0):
ret = ret[6:]
goto next
case (strings.Index(ret, "Registrant ") == 0):
ret = ret[11:]
goto next
case (strings.Index(ret, "Registrar ") == 0):
ret = ret[10:]
goto next
case (strings.Index(ret, "OrgTech") == 0):
ret = ret[7:]
goto next
case (strings.Index(ret, "OrgAdmin") == 0), (strings.Index(ret, "OrgAbuse") == 0):
ret = ret[8:]
goto next
case (strings.Index(ret, "Net") == 0):
ret = ret[3:]
goto next
case (ret == "StateProv"):
ret = "StateProvince"
case (ret == "fax-no"):
ret = "fax"
case (ret == "e-mail"):
ret = "email"
case (ret == "OrgName"):
ret = "organization"
case (ret == "OrgId"):
ret = "id"
case (ret == "WHOIS Server"):
ret = "whois"
case (ret == "inetnum"):
ret = "range"
case (strings.Index(ret, "-") > 0):
return strings.ToLower(ret)
}
ret = strings.Replace(ret, " ", "", -1)
ret = strings.Replace(ret, "/", "-", -1)
split := camelcase.Split(ret)
ret = strings.ToLower(strings.Join(split, "-"))
return ret
}
//
// normalizeValue normalizes the given value and removes
// useless parts like control characters and trailing / beginning spaces.
//
func normalizeValue(value string) string {
value = strings.Trim(value, " \r")
ret := make([]byte, len(value))
pos := 0
//
// pretty slow ..
// TODO: find a faster solution
//
for i := 0; i < len(value); i++ {
if value[i] != '\n' && byte(value[i]) < 30 {
continue
}
ret[pos] = value[i]
pos++
}
return string(ret[:pos])
}