-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.go
More file actions
70 lines (59 loc) · 1.24 KB
/
Copy pathutil.go
File metadata and controls
70 lines (59 loc) · 1.24 KB
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
package logl
import (
"bytes"
"unicode/utf8"
)
func lastByteIs(s string, b byte) bool {
if n := len(s); n > 0 {
return s[n-1] == b
}
return false
}
func quoRem(x, y int) (quo, rem int) {
quo = x / y
rem = x % y
return
}
// ------------------------------------------------------------------------------
// Nibbles
func byteToNibbles(b byte) (hi, lo byte) {
hi = b >> 4
lo = b & 0xF
return
}
func nibblesToByte(hi, lo byte) (b byte) {
b |= hi << 4
b |= lo & 0xF
return
}
// ------------------------------------------------------------------------------
var (
hexTableLower = []byte("0123456789abcdef")
hexTableUpper = []byte("0123456789ABCDEF")
hexTable = hexTableLower
)
func byteHex(x byte) string {
hi, lo := byteToNibbles(x)
bs := []byte{
hexTable[hi],
hexTable[lo],
}
return string(bs)
}
func writeByteHex(b *bytes.Buffer, x byte) {
hi, lo := byteToNibbles(x)
b.WriteByte(hexTable[hi])
b.WriteByte(hexTable[lo])
}
// ------------------------------------------------------------------------------
var safeSet = makeSafeSet()
func makeSafeSet() (set [utf8.RuneSelf]bool) {
for i := range set {
x := byte(i)
// ASCII control characters (0-31)
if (x > 31) && (x != '\\') && (x != '"') {
set[i] = true
}
}
return
}