Golang go/scanner.Scanner.Init() function example
package go/scanner
func (s *Scanner) Init(file *token.File, src []byte, err ErrorHandler, mode Mode)
Init prepares the scanner s to tokenize the text src by setting the scanner at the beginning of src. The scanner uses the file set file for position information and it adds line information for each line. It is ok to re-use the same file when re-scanning the same file as line information which is already present is ignored. Init causes a panic if the file size does not match the src size.
Calls to Scan will invoke the error handler err if they encounter a syntax error and err is not nil. Also, for each error encountered, the Scanner field ErrorCount is incremented by one. The mode parameter determines how comments are handled.
Note that Init may call err if there is an error in the first character of the file.
Golang go/scanner.Scanner.Init() function usage example
func tokenSelection(src []byte, sel token.Token) Selection {
var s scanner.Scanner
fset := token.NewFileSet()
file := fset.AddFile("", fset.Base(), len(src))
s.Init(file, src, nil, scanner.ScanComments)
...
Reference :
Advertisement
Something interesting
Tutorials
+8k Findstr command the Grep equivalent for Windows
+8.2k Golang : Metaprogramming example of wrapping a function
+9.1k Golang : Serving HTTP and Websocket from different ports in a program example
+22.7k Golang : Strings to lowercase and uppercase example
+20.2k Golang : Reset or rewind io.Reader or io.Writer
+11k Golang : Create S3 bucket with official aws-sdk-go package
+26.8k Golang : Find files by extension
+7.7k Golang : Error reading timestamp with GORM or SQL driver
+9.3k Golang : Temperatures conversion example
+7.6k Golang : Convert(cast) io.Reader type to string
+12.9k Golang : Convert IPv4 address to packed 32-bit binary format
+35.1k Golang : Upload and download file to/from AWS S3