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
+9.4k Golang : Web(Javascript) to server-side websocket example
+10.2k Golang : How to get quoted string into another string?
+8.9k Golang : What is the default port number for connecting to MySQL/MariaDB database ?
+6k Golang : Convert Chinese UTF8 characters to Pin Yin
+5.4k Python : Delay with time.sleep() function example
+7.9k Golang : Grayscale Image
+7.8k Golang : Example of how to detect which type of script a word belongs to
+5k Python : Convert(cast) bytes to string example
+9.6k Golang : Validate IPv6 example
+14.9k Golang : Basic authentication with .htpasswd file
+5.6k PHP : Fix Call to undefined function curl_init() error
+18.8k Golang : How to make function callback or pass value from function as parameter?