Golang go/token.File.SetLines function example
package go/token
SetLines sets the line offsets for a file and returns true if successful. The line offsets are the offsets of the first character of each line; for instance for the content "ab\nc\n" the line offsets are {0, 3}. An empty file has an empty line offset table. Each line offset must be larger than the offset for the previous line and smaller than the file size; otherwise SetLines fails and returns false.
Golang go/token.File.SetLines function usage example
fset := token.NewFileSet()
var src []byte
file := fset.AddFile("", fset.Base(), len(src))
...
if ok := f.SetLines(test.lines); !ok {
t.Errorf("%s: SetLines failed", f.Name())
}
Reference :
Advertisement
Something interesting
Tutorials
+7.2k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+17.1k Golang : XML to JSON example
+27.6k PHP : Convert(cast) string to bigInt
+18.6k Golang : Generate thumbnails from images
+27.5k Golang : Convert integer to binary, octal, hexadecimal and back to integer
+22.4k Golang : Read directory content with filepath.Walk()
+35.1k Golang : Upload and download file to/from AWS S3
+5.4k Golang *File points to a file or directory ?
+5.1k Golang : Check if a word is countable or not
+19k Golang : Padding data for encryption and un-padding data for decryption
+11.8k Golang : GTK Input dialog box examples
+25.3k Golang : Get current file path of a file or executable