Golang go/token.File.Offset function example

package go/token

Offset returns the offset for the given file position p(1st parameter); p must be a valid Pos value in that file. f.Offset(f.Pos(offset)) == offset.

Golang go/token.File.Offset function usage example

 var s scanner.Scanner
 pos, tok, lit := s.Scan()
 if tok == token.EOF {
 break
 }
 offset := file.Offset(pos)

Reference :

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

Advertisement