http urls monitor.

position.go 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package token
  2. import "fmt"
  3. // Pos describes an arbitrary source position
  4. // including the file, line, and column location.
  5. // A Position is valid if the line number is > 0.
  6. type Pos struct {
  7. Filename string // filename, if any
  8. Offset int // offset, starting at 0
  9. Line int // line number, starting at 1
  10. Column int // column number, starting at 1 (character count)
  11. }
  12. // IsValid returns true if the position is valid.
  13. func (p *Pos) IsValid() bool { return p.Line > 0 }
  14. // String returns a string in one of several forms:
  15. //
  16. // file:line:column valid position with file name
  17. // line:column valid position without file name
  18. // file invalid position with file name
  19. // - invalid position without file name
  20. func (p Pos) String() string {
  21. s := p.Filename
  22. if p.IsValid() {
  23. if s != "" {
  24. s += ":"
  25. }
  26. s += fmt.Sprintf("%d:%d", p.Line, p.Column)
  27. }
  28. if s == "" {
  29. s = "-"
  30. }
  31. return s
  32. }
  33. // Before reports whether the position p is before u.
  34. func (p Pos) Before(u Pos) bool {
  35. return u.Offset > p.Offset || u.Line > p.Line
  36. }
  37. // After reports whether the position p is after u.
  38. func (p Pos) After(u Pos) bool {
  39. return u.Offset < p.Offset || u.Line < p.Line
  40. }