-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
89 lines (72 loc) · 1.3 KB
/
main.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
package main
import (
"fmt"
"os"
"unicode"
"golang.org/x/exp/mmap"
)
var BasicLatin = &unicode.RangeTable{
R16: []unicode.Range16{
{0x0020, 0x007f, 1},
},
LatinOffset: 6,
}
func main() {
if len(os.Args) == 1 {
fmt.Println("Usage: gostrings {file}")
return
}
p := os.Args[1]
file, err := mmap.Open(p)
if err != nil {
panic(err)
}
defer file.Close()
offset := 0
s := ""
for i := 0; i < file.Len(); i++ {
b := file.At(i)
c := rune(b)
if unicode.Is(BasicLatin, c) {
s += fmt.Sprintf("%c", c)
continue
} else if c == 0x0d {
s += fmt.Sprintf("%c", c)
continue
} else if c == 0x09 {
s += fmt.Sprintf("%c", c)
continue
} else if c == 0x0a {
s += fmt.Sprintf("%c", c)
continue
} else if len(s) > 6 {
fmt.Printf("0x%x: %s\n", offset, s)
s = ""
offset = i + 1
continue
} else {
s = ""
offset = i + 1
continue
}
/*
// only ascii supported now
if unicode.IsLetter(rune(b)) {
} else if unicode.IsDigit(rune(b)) {
} else if unicode.IsPunct(rune(b)) {
} else if unicode.IsSpace(rune(b)) {
} else if unicode.IsGraphic(rune(b)) {
s = ""
offset = i + 1
} else if len(s) > 6 {
fmt.Printf("0x%x: %s\n", offset, s)
s = ""
offset = i + 1
} else {
s = ""
offset = i + 1
continue
}
*/
}
}