diff options
author | Jake Champlin <jake.champlin.27@gmail.com> | 2017-06-06 12:40:07 -0400 |
---|---|---|
committer | Jake Champlin <jake.champlin.27@gmail.com> | 2017-06-06 12:40:07 -0400 |
commit | bae9f6d2fd5eb5bc80929bd393932b23f14d7c93 (patch) | |
tree | ca9ab12a7d78b1fc27a8f734729081357ce6d252 /vendor/github.com/hashicorp/hcl/json/token/position.go | |
parent | 254c495b6bebab3fb72a243c4bce858d79e6ee99 (diff) | |
download | terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.tar.gz terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.tar.zst terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.zip |
Initial transfer of provider code
Diffstat (limited to 'vendor/github.com/hashicorp/hcl/json/token/position.go')
-rw-r--r-- | vendor/github.com/hashicorp/hcl/json/token/position.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/hcl/json/token/position.go b/vendor/github.com/hashicorp/hcl/json/token/position.go new file mode 100644 index 0000000..59c1bb7 --- /dev/null +++ b/vendor/github.com/hashicorp/hcl/json/token/position.go | |||
@@ -0,0 +1,46 @@ | |||
1 | package token | ||
2 | |||
3 | import "fmt" | ||
4 | |||
5 | // Pos describes an arbitrary source position | ||
6 | // including the file, line, and column location. | ||
7 | // A Position is valid if the line number is > 0. | ||
8 | type Pos struct { | ||
9 | Filename string // filename, if any | ||
10 | Offset int // offset, starting at 0 | ||
11 | Line int // line number, starting at 1 | ||
12 | Column int // column number, starting at 1 (character count) | ||
13 | } | ||
14 | |||
15 | // IsValid returns true if the position is valid. | ||
16 | func (p *Pos) IsValid() bool { return p.Line > 0 } | ||
17 | |||
18 | // String returns a string in one of several forms: | ||
19 | // | ||
20 | // file:line:column valid position with file name | ||
21 | // line:column valid position without file name | ||
22 | // file invalid position with file name | ||
23 | // - invalid position without file name | ||
24 | func (p Pos) String() string { | ||
25 | s := p.Filename | ||
26 | if p.IsValid() { | ||
27 | if s != "" { | ||
28 | s += ":" | ||
29 | } | ||
30 | s += fmt.Sprintf("%d:%d", p.Line, p.Column) | ||
31 | } | ||
32 | if s == "" { | ||
33 | s = "-" | ||
34 | } | ||
35 | return s | ||
36 | } | ||
37 | |||
38 | // Before reports whether the position p is before u. | ||
39 | func (p Pos) Before(u Pos) bool { | ||
40 | return u.Offset > p.Offset || u.Line > p.Line | ||
41 | } | ||
42 | |||
43 | // After reports whether the position p is after u. | ||
44 | func (p Pos) After(u Pos) bool { | ||
45 | return u.Offset < p.Offset || u.Line < p.Line | ||
46 | } | ||