github.com/boyter/gocodewalker@v1.3.2/go-gitignore/position.go (about)

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