亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

directory search
archive archive/tar archive/zip bufio bufio(緩存) builtin builtin(內置包) bytes bytes(包字節(jié)) compress compress/bzip2(壓縮/bzip2) compress/flate(壓縮/flate) compress/gzip(壓縮/gzip) compress/lzw(壓縮/lzw) compress/zlib(壓縮/zlib) container container/heap(容器數(shù)據(jù)結構heap) container/list(容器數(shù)據(jù)結構list) container/ring(容器數(shù)據(jù)結構ring) context context(上下文) crypto crypto(加密) crypto/aes(加密/aes) crypto/cipher(加密/cipher) crypto/des(加密/des) crypto/dsa(加密/dsa) crypto/ecdsa(加密/ecdsa) crypto/elliptic(加密/elliptic) crypto/hmac(加密/hmac) crypto/md5(加密/md5) crypto/rand(加密/rand) crypto/rc4(加密/rc4) crypto/rsa(加密/rsa) crypto/sha1(加密/sha1) crypto/sha256(加密/sha256) crypto/sha512(加密/sha512) crypto/subtle(加密/subtle) crypto/tls(加密/tls) crypto/x509(加密/x509) crypto/x509/pkix(加密/x509/pkix) database database/sql(數(shù)據(jù)庫/sql) database/sql/driver(數(shù)據(jù)庫/sql/driver) debug debug/dwarf(調試/dwarf) debug/elf(調試/elf) debug/gosym(調試/gosym) debug/macho(調試/macho) debug/pe(調試/pe) debug/plan9obj(調試/plan9obj) encoding encoding(編碼) encoding/ascii85(編碼/ascii85) encoding/asn1(編碼/asn1) encoding/base32(編碼/base32) encoding/base64(編碼/base64) encoding/binary(編碼/binary) encoding/csv(編碼/csv) encoding/gob(編碼/gob) encoding/hex(編碼/hex) encoding/json(編碼/json) encoding/pem(編碼/pem) encoding/xml(編碼/xml) errors errors(錯誤) expvar expvar flag flag(命令行參數(shù)解析flag包) fmt fmt go go/ast(抽象語法樹) go/build go/constant(常量) go/doc(文檔) go/format(格式) go/importer go/parser go/printer go/scanner(掃描儀) go/token(令牌) go/types(類型) hash hash(散列) hash/adler32 hash/crc32 hash/crc64 hash/fnv html html html/template(模板) image image(圖像) image/color(顏色) image/color/palette(調色板) image/draw(繪圖) image/gif image/jpeg image/png index index/suffixarray io io io/ioutil log log log/syslog(日志系統(tǒng)) math math math/big math/big math/bits math/bits math/cmplx math/cmplx math/rand math/rand mime mime mime/multipart(多部分) mime/quotedprintable net net net/http net/http net/http/cgi net/http/cookiejar net/http/fcgi net/http/httptest net/http/httptrace net/http/httputil net/http/internal net/http/pprof net/mail net/mail net/rpc net/rpc net/rpc/jsonrpc net/smtp net/smtp net/textproto net/textproto net/url net/url os os os/exec os/signal os/user path path path/filepath(文件路徑) plugin plugin(插件) reflect reflect(反射) regexp regexp(正則表達式) regexp/syntax runtime runtime(運行時) runtime/debug(調試) runtime/internal/sys runtime/pprof runtime/race(競爭) runtime/trace(執(zhí)行追蹤器) sort sort(排序算法) strconv strconv(轉換) strings strings(字符串) sync sync(同步) sync/atomic(原子操作) syscall syscall(系統(tǒng)調用) testing testing(測試) testing/iotest testing/quick text text/scanner(掃描文本) text/tabwriter text/template(定義模板) text/template/parse time time(時間戳) unicode unicode unicode/utf16 unicode/utf8 unsafe unsafe
characters

  • import "text/scanner"

  • 概觀

  • 索引

  • 示例

概觀

程序包掃描程序為 UTF-8 編碼的文本提供掃描程序和標記程序。它需要一個提供源的 io.Reader ,然后可以通過重復調用掃描功能對其進行標記。為了與現(xiàn)有工具兼容, NUL 字符是不允許的。如果源中的第一個字符是 UTF-8 編碼的字節(jié)順序標記 (BOM) ,它將被丟棄。

默認情況下,掃描程序會跳過空格并執(zhí)行注釋并識別 Go 語言規(guī)范定義的所有文字。它可以被定制為僅識別這些文字的一個子集并識別不同的標識符和空白字符。

示例

package mainimport ("fmt""strings""text/scanner")func main() {const src = `
// This is scanned code.
if a > 10 {
	someParsable = text
}`var s scanner.Scanner
	s.Init(strings.NewReader(src))
	s.Filename = "example"for tok := s.Scan(); tok != scanner.EOF; tok = s.Scan() {
		fmt.Printf("%s: %s\n", s.Position, s.TokenText())}}

索引

  • 常量

  • func TokenString(tok rune) string

  • type Position

  • func (pos *Position) IsValid() bool

  • func (pos Position) String() string

  • type Scanner

  • func (s *Scanner) Init(src io.Reader) *Scanner

  • func (s *Scanner) Next() rune

  • func (s *Scanner) Peek() rune

  • func (s *Scanner) Pos() (pos Position)

  • func (s *Scanner) Scan() rune

  • func (s *Scanner) TokenText() string

示例

打包

打包文件

scanner.go

常量

預定義的模式位控制令牌的識別。例如,要配置掃描儀,使其僅識別 (Go) 標識符,整數(shù)并跳過注釋,請將掃描儀的模式字段設置為:

ScanIdents | ScanInts | SkipComments

除注釋外,如果設置了 SkipComments ,將跳過注釋,但不會忽略無法識別的令牌。相反,掃描儀只是返回相應的單個字符(或可能是子令牌)。例如,如果模式是 ScanIdents(而不是 ScanStrings ) ,則將字符串“ foo ”作為標記序列'' 'Ident '''進行掃描。

const (
        ScanIdents     = 1 << -Ident
        ScanInts       = 1 << -Int
        ScanFloats     = 1 << -Float // includes Ints
        ScanChars      = 1 << -Char
        ScanStrings    = 1 << -String
        ScanRawStrings = 1 << -RawString
        ScanComments   = 1 << -Comment
        SkipComments   = 1 << -skipComment // if set with ScanComments, comments become white space
        GoTokens       = ScanIdents | ScanFloats | ScanChars | ScanStrings | ScanRawStrings | ScanComments | SkipComments)

Scan 的結果是這些標志或 Unicode 字符之一。

const (
        EOF = -(iota + 1)
        Ident
        Int
        Float
        Char
        String
        RawString
        Comment)

GoWhitespace 是掃描儀空白字段的默認值。它的值選擇 Go 的空白字符。

const GoWhitespace = 1<<'\t' | 1<<'\n' | 1<<'\r' | 1<<' '

func TokenString

func TokenString(tok rune) string

TokenString 為標志或 Unicode 字符返回可打印的字符串。

type Position

源位置由位置值表示。如果 Line> 0,則位置有效。

type Position struct {
        Filename string // filename, if any
        Offset   int    // byte offset, starting at 0
        Line     int    // line number, starting at 1
        Column   int    // column number, starting at 1 (character count per line)}

func (*Position) IsValid

func (pos *Position) IsValid() bool

IsValid 報告該位置是否有效。

func (Position) String

func (pos Position) String() string

鍵入 掃描儀

掃描儀實現(xiàn)從 io.Reader 讀取 Unicode 字符和標記。

type Scanner struct {        // Error is called for each error encountered. If no Error        // function is set, the error is reported to os.Stderr.
        Error func(s *Scanner, msg string)        // ErrorCount is incremented by one for each error encountered.
        ErrorCount int        // The Mode field controls which tokens are recognized. For instance,        // to recognize Ints, set the ScanInts bit in Mode. The field may be        // changed at any time.
        Mode uint        // The Whitespace field controls which characters are recognized        // as white space. To recognize a character ch <= ' ' as white space,        // set the ch'th bit in Whitespace (the Scanner's behavior is undefined        // for values ch > ' '). The field may be changed at any time.
        Whitespace uint64        // IsIdentRune is a predicate controlling the characters accepted        // as the ith rune in an identifier. The set of valid characters        // must not intersect with the set of white space characters.        // If no IsIdentRune function is set, regular Go identifiers are        // accepted instead. The field may be changed at any time.
        IsIdentRune func(ch rune, i int) bool        // Start position of most recently scanned token; set by Scan.        // Calling Init or Next invalidates the position (Line == 0).        // The Filename field is always left untouched by the Scanner.        // If an error is reported (via Error) and Position is invalid,        // the scanner is not inside a token. Call Pos to obtain an error        // position in that case, or to obtain the position immediately        // after the most recently scanned token.
        Position        // contains filtered or unexported fields}

func (*Scanner) Init

func (s *Scanner) Init(src io.Reader) *Scanner

Init 用新源初始化掃描儀并返回 s 。錯誤設置為零, ErrorCount 設置為0,模式設置為 GoTokens ,并且空白設置為 GoWhitespace 。

func (*Scanner) Next

func (s *Scanner) Next() rune

接下來讀取并返回下一個 Unicode 字符。它在源的末尾返回 EOF 。它通過調用 s.Error 來報告讀取錯誤,如果不是零; 否則它會向 os.Stderr 輸出一條錯誤消息。接下來不更新掃描儀的位置字段; 使用 Pos() 來獲取當前位置。

func (*Scanner) Peek

func (s *Scanner) Peek() rune

Peek 將返回源中的下一個 Unicode 字符,而不會推進掃描程序。如果掃描儀的位置在源的最后一個字符處,它會返回 EOF 。

func (*Scanner) Pos

func (s *Scanner) Pos() (pos Position)

Pos 返回最后一次調用 Next 或 Scan 時返回的字符或標記之后的字符位置。將掃描儀的位置字段用于最近掃描的標記的開始位置。

func (*Scanner) Scan

func (s *Scanner) Scan() rune

掃描從源讀取下一個標記或Unicode字符并將其返回。它只識別設置了相應模式位  (1<<-t)  的標志 t 。它在源的末尾返回 EOF 。它通過調用 s.Error 來報告掃描器錯誤(讀取和令牌錯誤),如果不是零; 否則它會向 os.Stder r輸出一條錯誤消息。

func (*Scanner) TokenText

func (s *Scanner) TokenText() string

TokenText 返回對應于最近掃描的標記的字符串。調用 Scan() 后有效。

Previous article: Next article: