Golang go/token.File.Position function examples
package go/token
Position returns the Position value for the given file position p(1st parameter); p must be a Pos value in that file or NoPos.
Golang go/token.File.Position function usage examples
Example 1:
fs := token.NewFileSet()
tf := fs.AddFile("", fs.Base(), len(data))
tf.SetLinesForContent(data)
pos := tf.Position(tf.Pos(offset))
return pos.Line, pos.Column
Example 2:
// verify scan
var S Scanner
file := fset.AddFile(filepath.Join("dir", "TestLineComments"), fset.Base(), len(src))
S.Init(file, []byte(src), nil, dontInsertSemis)
for _, s := range segs {
p, _, lit := S.Scan()
pos := file.Position(p)
checkPos(t, lit, p, token.Position{
Filename: s.filename,
Offset: pos.Offset,
Line: s.line,
Column: pos.Column,
})
}
Reference :
Advertisement
Something interesting
Tutorials
+6.8k Golang : Muxing with Martini example
+32.1k Golang : Validate email address with regular expression
+8.4k Golang : Convert word to its plural form example
+5.3k Golang : Pad file extension automagically
+6.5k PHP : Shuffle to display different content or advertisement
+5.4k Golang : Intercept, inject and replay HTTP traffics from web server
+15.7k Golang : Get checkbox or extract multipart form data value example
+5.3k PHP : Hide PHP version information from curl
+8.4k Your page has meta tags in the body instead of the head
+11.5k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions
+18.7k Golang : Iterating Elements Over A List