-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathposition.go
More file actions
35 lines (30 loc) · 789 Bytes
/
position.go
File metadata and controls
35 lines (30 loc) · 789 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
package gitignore
import (
"fmt"
)
// Position represents the position of the .gitignore parser, and the position
// of a .gitignore pattern within the parsed stream.
type Position struct {
File string
Line int
Column int
Offset int
}
// String returns a string representation of the current position.
func (p Position) String() string {
_prefix := ""
if p.File != "" {
_prefix = p.File + ": "
}
if p.Line == 0 {
return fmt.Sprintf("%s+%d", _prefix, p.Offset)
} else if p.Column == 0 {
return fmt.Sprintf("%s%d", _prefix, p.Line)
} else {
return fmt.Sprintf("%s%d:%d", _prefix, p.Line, p.Column)
}
} // String()
// Zero returns true if the Position represents the zero Position
func (p Position) Zero() bool {
return p.Line+p.Column+p.Offset == 0
} // Zero()