Golang go/token.File.SetLinesForContent function example

package go/token

SetLinesForContent sets the line offsets for the given file content.

Golang go/token.File.SetLinesForContent function usage example

Example 1:

 var str string
 fset := token.NewFileSet()
 fset.AddFile("", len(str), fset.Base()).SetLinesForContent([]byte(str))

Example 2:

 if util.IsText(src) {
 // only add the file to the file set (for the full text index)
 file = x.fset.AddFile(filename, x.fset.Base(), len(src))
 file.SetLinesForContent(src)
 return
 }

Reference :

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

Advertisement