Standard library / go/token

go/token.File.SetLines()

Replaces the line table if all offsets are increasing and below size; do not mutate the supplied slice. Expected stdout: 'true [0 2]\nfalse\n'.

Formal Syntax & Structure

go syntaxgo
func (f *File) SetLines(lines []int) bool

Parameters & Attributes

NameTypeDescription
lines[]intIncreasing byte offsets for line starts; do not mutate after registration.

Return Value

bool

Replaces the line table if all offsets are increasing and below size; do not mutate the supplied slice.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/token")
func main() {  s := token.NewFileSet()  f := s.AddFile("demo.go", -1, 5)  f.SetLinesForContent([]byte("ab\ncd"))  fmt.Println(f.SetLines([]int{0, 2}), f.Lines())  fmt.Println(f.SetLines([]int{0, 5}))}
Go Reference