Golang go/token.File.SetLines function example

package go/token

SetLines sets the line offsets for a file and returns true if successful. The line offsets are the offsets of the first character of each line; for instance for the content "ab\nc\n" the line offsets are {0, 3}. An empty file has an empty line offset table. Each line offset must be larger than the offset for the previous line and smaller than the file size; otherwise SetLines fails and returns false.

Golang go/token.File.SetLines function usage example

 fset := token.NewFileSet()
 var src []byte
 file := fset.AddFile("", fset.Base(), len(src))
 ...
 if ok := f.SetLines(test.lines); !ok {
 t.Errorf("%s: SetLines failed", f.Name())
 }

Reference :

http://golang.org/pkg/go/token/#File.SetLines

Advertisement