-
Notifications
You must be signed in to change notification settings - Fork 465
/
transform.go
59 lines (56 loc) · 867 Bytes
/
transform.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 shell
func isGBK(data []byte) bool {
length := len(data)
var i int = 0
for i < length {
if data[i] <= 0x7f {
i++
continue
} else {
if data[i] >= 0x81 &&
data[i] <= 0xfe &&
data[i+1] >= 0x40 &&
data[i+1] <= 0xfe &&
data[i+1] != 0xf7 {
i += 2
continue
} else {
return false
}
}
}
return true
}
func preNUm(data byte) int {
var mask byte = 0x80
var num int = 0
for i := 0; i < 8; i++ {
if (data & mask) == mask {
num++
mask = mask >> 1
} else {
break
}
}
return num
}
func isUtf8(data []byte) bool {
i := 0
for i < len(data) {
if (data[i] & 0x80) == 0x00 {
i++
continue
} else if num := preNUm(data[i]); num > 2 {
i++
for j := 0; j < num-1; j++ {
if (data[i] & 0xc0) != 0x80 {
return false
}
i++
}
} else {
return false
}
}
return true
}