Standard library / go/token
go/token.File.SetLinesForContent()
Computes physical line offsets from bytes, ignoring line directives. Expected stdout: '[0 3]\n'.
Formal Syntax & Structure
go syntaxgo
func (f *File) SetLinesForContent(content []byte)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| content | []byte | Source bytes used to compute line offsets. |
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.Lines())}