-
Notifications
You must be signed in to change notification settings - Fork 9
/
linespec.go
61 lines (55 loc) · 1.19 KB
/
linespec.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
package main
import (
"bytes"
"strconv"
)
// ParseFileLine
// ../../abc.go:688: cannot inline ...
// /go/src/abc.go:688: cannot inline ...
// /go/src/abc.go:688:123: cannot inline ...
// ..\..\abc.go:688: cannot inline ...
// C:\Go\src\example\abc.go:688: cannot inline ...
// C:\Go\src\example\abc.go:688:123: cannot inline ...
func ParseFileLine(line []byte) (path []byte, lineno, column int, msg []byte, ok bool) {
lineno = -1
column = -1
// skip first 2 characters, to handle windows letter "C:"
first := IndexByteAt(line, 2, ':')
if first < 0 {
return
}
second := IndexByteAt(line, first+1, ':')
if second < 0 {
return
}
third := IndexByteAt(line, second+1, ' ')
if third < 0 {
return
}
path = line[:first]
lineno, ok = ParseInt(line[first+1 : second])
if !ok {
return
}
if second+1 < third-1 {
if col, colok := ParseInt(line[second+1 : third-1]); colok {
column = col
}
}
msg = line[third+1:]
return
}
func ParseInt(data []byte) (int, bool) {
x, err := strconv.Atoi(string(data))
if err != nil {
return -1, false
}
return x, true
}
func IndexByteAt(data []byte, at int, b byte) int {
s := bytes.IndexByte(data[at:], b)
if s < 0 {
return s
}
return s + at
}