forked from rqlite/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_pos.go
More file actions
40 lines (32 loc) · 706 Bytes
/
debug_pos.go
File metadata and controls
40 lines (32 loc) · 706 Bytes
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
//go:build debugpos
// +build debugpos
package sql
import "fmt"
type Pos struct {
Offset int // offset, starting at 0 (byte offset)
Line int // line number, starting at 1
Column int // column number, starting at 1 (byte count)
}
// String returns a string representation of the position.
func (p Pos) String() string {
if !(p.Line > 0 && p.Column > 0 && p.Offset >= 0) {
return "-"
}
return fmt.Sprintf("%d:%d", p.Line, p.Column)
}
func NewValidPos() Pos {
return Pos{Offset: 0, Line: 1, Column: 1}
}
func (p Pos) Increase(ch byte) Pos {
p.Offset += 1
if ch == '\n' {
p.Line++
p.Column = 1
} else {
p.Column += 1
}
return p
}
func (p Pos) GetOffset() int {
return p.Offset
}