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 : Play .WAV file from command line
+12.1k Golang : md5 hash of a string
+8.2k Golang : Find relative luminance or color brightness
+6.2k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations
+17.5k Golang : Find smallest number in array
+6.6k Golang : How to validate ISBN?
+80.6k Golang : How to return HTTP status code?
+6.8k Golang : Find the longest line of text example
+14.8k Golang : Normalize unicode strings for comparison purpose
+23.9k Golang : Use regular expression to validate domain name
+7.2k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream