equal
deleted
inserted
replaced
1 // Position support for go-toml |
|
2 |
|
3 package toml |
|
4 |
|
5 import ( |
|
6 "fmt" |
|
7 ) |
|
8 |
|
9 // Position of a document element within a TOML document. |
|
10 // |
|
11 // Line and Col are both 1-indexed positions for the element's line number and |
|
12 // column number, respectively. Values of zero or less will cause Invalid(), |
|
13 // to return true. |
|
14 type Position struct { |
|
15 Line int // line within the document |
|
16 Col int // column within the line |
|
17 } |
|
18 |
|
19 // String representation of the position. |
|
20 // Displays 1-indexed line and column numbers. |
|
21 func (p Position) String() string { |
|
22 return fmt.Sprintf("(%d, %d)", p.Line, p.Col) |
|
23 } |
|
24 |
|
25 // Invalid returns whether or not the position is valid (i.e. with negative or |
|
26 // null values) |
|
27 func (p Position) Invalid() bool { |
|
28 return p.Line <= 0 || p.Col <= 0 |
|
29 } |
|