-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathiso-8859-5.go
46 lines (39 loc) · 949 Bytes
/
iso-8859-5.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
package cpd
//unit for ISO-8859-5
func matchISO88595(d []byte, tbl *cpTable) MatchRes {
for i := 0; i < len(d); i++ {
if isISO88595(d[i]) {
upper := lu88595(d[i])
j := tbl.index(rune(d[i]))
(*tbl)[j].count++
for i++; (i < len(d)) && isISO88595(d[i]); i++ {
if upper >= lu88595(d[i]) {
j = tbl.index(rune(d[i]))
(*tbl)[j].count++
}
}
}
}
return MatchRes{tbl.founded(), 0}
}
const (
cpISO88595BeginUpperChar = 0xB0
cpISO88595StopUpperChar = 0xCF
cpISO88595BeginLowerChar = 0xD0
cpISO88595StopLowerChar = 0xEF
)
func lu88595(r byte) (res int) {
if isUpperISO88595(r) {
res = 1
}
return
}
func isUpperISO88595(r byte) bool {
return (r >= cpISO88595BeginUpperChar) && (r <= cpISO88595StopUpperChar)
}
func isLowerISO88595(r byte) bool {
return (r >= cpISO88595BeginLowerChar) && (r <= cpISO88595StopLowerChar)
}
func isISO88595(r byte) bool {
return isUpperISO88595(r) || isLowerISO88595(r)
}