func GetRangeLines(f *token.File, Pos, End token.Pos, fileSize int) (lines []int, firstLineNum int) { lines = []int{} firstLineNum = -1 l := f.Line(Pos) for p := Pos; p <= End; p++ { if f.Line(p) > l { l = f.Line(p) if firstLineNum == -1 { firstLineNum = l } lines = append(lines, f.Offset(p)) } } print(End) print(" -> ") println(fileSize + f.Base() - 1) if (int(End) == fileSize+f.Base()-1) || f.Line(End+1) > l { lines = append(lines, f.Offset(End+1)) if firstLineNum == -1 { firstLineNum = f.Line(End + 1) } } return }
func getRangeLinesAtLeastOne(f *token.File, Pos, End token.Pos, fileSize int) (lines []int, firstLineNum int) { lines = []int{} firstLineNum = -1 l := f.Line(Pos) for p := Pos; p <= End; p++ { if f.Line(p) > l { l = f.Line(p) if firstLineNum == -1 { firstLineNum = l } lines = append(lines, f.Offset(p)) } } if (int(End) == fileSize+f.Base()-1) || f.Line(End+1) > l { lines = append(lines, f.Offset(End+1)) if firstLineNum == -1 { firstLineNum = f.Line(End + 1) } } if firstLineNum < 0 { for p := End; ; p++ { if f.Line(p) > l { firstLineNum = l lines = append(lines, f.Offset(p)) break } } } return }
func GetLines(f *token.File) []int { lines := make([]int, 0, 20) l := -1 for i := f.Base(); i < f.Base()+f.Size(); i++ { if f.Line(token.Pos(i)) > l { l = f.Line(token.Pos(i)) lines = append(lines, f.Offset(token.Pos(i))) } } return lines }
// TODO(adonovan): make this a method: func (*token.File) Contains(token.Pos) func tokenFileContainsPos(f *token.File, pos token.Pos) bool { p := int(pos) base := f.Base() return base <= p && p < base+f.Size() }