github.com/Wrdlbrnft/go-gitignore@v0.0.0-20201129201858-74ef740b8b77/position.go (about) 1 package gitignore 2 3 import ( 4 "fmt" 5 ) 6 7 // Position represents the position of the .gitignore parser, and the position 8 // of a .gitignore pattern within the parsed stream. 9 type Position struct { 10 File string 11 Line int 12 Column int 13 Offset int 14 } 15 16 // String returns a string representation of the current position. 17 func (p Position) String() string { 18 _prefix := "" 19 if p.File != "" { 20 _prefix = p.File + ": " 21 } 22 23 if p.Line == 0 { 24 return fmt.Sprintf("%s+%d", _prefix, p.Offset) 25 } else if p.Column == 0 { 26 return fmt.Sprintf("%s%d", _prefix, p.Line) 27 } else { 28 return fmt.Sprintf("%s%d:%d", _prefix, p.Line, p.Column) 29 } 30 } // String() 31 32 // Zero returns true if the Position represents the zero Position 33 func (p Position) Zero() bool { 34 return p.Line+p.Column+p.Offset == 0 35 } // Zero()