diff options
| author | cui fliter <imcusg@gmail.com> | 2023-10-12 14:13:36 +0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-10-12 14:39:08 +0000 |
| commit | cf97cd317be0d5fc1fa7b861f143060d7fd9b361 (patch) | |
| tree | dda2af02f9645e3b9668527f7e9d7b47344333d0 /src/bufio/scan.go | |
| parent | a762ea17ecb593d695601f0c1b4ea9fbd601c6cb (diff) | |
| download | go-cf97cd317be0d5fc1fa7b861f143060d7fd9b361.tar.xz | |
bufio: add available godoc link
Change-Id: Id32bae57c9fcc2074f82089ba9c69be9a601f128
Reviewed-on: https://go-review.googlesource.com/c/go/+/534758
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: shuang cui <imcusg@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/bufio/scan.go')
| -rw-r--r-- | src/bufio/scan.go | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/src/bufio/scan.go b/src/bufio/scan.go index d8dcf13ca1..558e168b2d 100644 --- a/src/bufio/scan.go +++ b/src/bufio/scan.go @@ -13,10 +13,10 @@ import ( // Scanner provides a convenient interface for reading data such as // a file of newline-delimited lines of text. Successive calls to -// the Scan method will step through the 'tokens' of a file, skipping +// the [Scanner.Scan] method will step through the 'tokens' of a file, skipping // the bytes between the tokens. The specification of a token is -// defined by a split function of type SplitFunc; the default split -// function breaks the input into lines with line termination stripped. Split +// defined by a split function of type [SplitFunc]; the default split +// function breaks the input into lines with line termination stripped. [Scanner.Split] // functions are defined in this package for scanning a file into // lines, bytes, UTF-8-encoded runes, and space-delimited words. The // client may instead provide a custom split function. @@ -25,7 +25,7 @@ import ( // large to fit in the buffer. When a scan stops, the reader may have // advanced arbitrarily far past the last token. Programs that need more // control over error handling or large tokens, or must run sequential scans -// on a reader, should use bufio.Reader instead. +// on a reader, should use [bufio.Reader] instead. type Scanner struct { r io.Reader // The reader provided by the client. split SplitFunc // The function to split the tokens. @@ -42,21 +42,21 @@ type Scanner struct { // SplitFunc is the signature of the split function used to tokenize the // input. The arguments are an initial substring of the remaining unprocessed -// data and a flag, atEOF, that reports whether the Reader has no more data +// data and a flag, atEOF, that reports whether the [Reader] has no more data // to give. The return values are the number of bytes to advance the input // and the next token to return to the user, if any, plus an error, if any. // // Scanning stops if the function returns an error, in which case some of -// the input may be discarded. If that error is ErrFinalToken, scanning +// the input may be discarded. If that error is [ErrFinalToken], scanning // stops with no error. // -// Otherwise, the Scanner advances the input. If the token is not nil, -// the Scanner returns it to the user. If the token is nil, the +// Otherwise, the [Scanner] advances the input. If the token is not nil, +// the [Scanner] returns it to the user. If the token is nil, the // Scanner reads more data and continues scanning; if there is no more -// data--if atEOF was true--the Scanner returns. If the data does not +// data--if atEOF was true--the [Scanner] returns. If the data does not // yet hold a complete token, for instance if it has no newline while -// scanning lines, a SplitFunc can return (0, nil, nil) to signal the -// Scanner to read more data into the slice and try again with a +// scanning lines, a [SplitFunc] can return (0, nil, nil) to signal the +// [Scanner] to read more data into the slice and try again with a // longer slice starting at the same point in the input. // // The function is never called with an empty data slice unless atEOF @@ -74,7 +74,7 @@ var ( const ( // MaxScanTokenSize is the maximum size used to buffer a token - // unless the user provides an explicit buffer with Scanner.Buffer. + // unless the user provides an explicit buffer with [Scanner.Buffer]. // The actual maximum token size may be smaller as the buffer // may need to include, for instance, a newline. MaxScanTokenSize = 64 * 1024 @@ -82,8 +82,8 @@ const ( startBufSize = 4096 // Size of initial allocation for buffer. ) -// NewScanner returns a new Scanner to read from r. -// The split function defaults to ScanLines. +// NewScanner returns a new [Scanner] to read from r. +// The split function defaults to [ScanLines]. func NewScanner(r io.Reader) *Scanner { return &Scanner{ r: r, @@ -92,7 +92,7 @@ func NewScanner(r io.Reader) *Scanner { } } -// Err returns the first non-EOF error that was encountered by the Scanner. +// Err returns the first non-EOF error that was encountered by the [Scanner]. func (s *Scanner) Err() error { if s.err == io.EOF { return nil @@ -100,14 +100,14 @@ func (s *Scanner) Err() error { return s.err } -// Bytes returns the most recent token generated by a call to Scan. +// Bytes returns the most recent token generated by a call to [Scanner.Scan]. // The underlying array may point to data that will be overwritten // by a subsequent call to Scan. It does no allocation. func (s *Scanner) Bytes() []byte { return s.token } -// Text returns the most recent token generated by a call to Scan +// Text returns the most recent token generated by a call to [Scanner.Scan] // as a newly allocated string holding its bytes. func (s *Scanner) Text() string { return string(s.token) @@ -123,11 +123,11 @@ func (s *Scanner) Text() string { // See the emptyFinalToken example for a use of this value. var ErrFinalToken = errors.New("final token") -// Scan advances the Scanner to the next token, which will then be -// available through the Bytes or Text method. It returns false when the +// Scan advances the [Scanner] to the next token, which will then be +// available through the [Scanner.Bytes] or [Scanner.Text] method. It returns false when the // scan stops, either by reaching the end of the input or an error. -// After Scan returns false, the Err method will return any error that -// occurred during scanning, except that if it was io.EOF, Err +// After Scan returns false, the [Scanner.Err] method will return any error that +// occurred during scanning, except that if it was [io.EOF], [Scanner.Err] // will return nil. // Scan panics if the split function returns too many empty // tokens without advancing the input. This is a common error mode for @@ -256,10 +256,10 @@ func (s *Scanner) setErr(err error) { // Buffer sets the initial buffer to use when scanning // and the maximum size of buffer that may be allocated during scanning. // The maximum token size must be less than the larger of max and cap(buf). -// If max <= cap(buf), Scan will use this buffer only and do no allocation. +// If max <= cap(buf), [Scanner.Scan] will use this buffer only and do no allocation. // -// By default, Scan uses an internal buffer and sets the -// maximum token size to MaxScanTokenSize. +// By default, [Scanner.Scan] uses an internal buffer and sets the +// maximum token size to [MaxScanTokenSize]. // // Buffer panics if it is called after scanning has started. func (s *Scanner) Buffer(buf []byte, max int) { @@ -270,8 +270,8 @@ func (s *Scanner) Buffer(buf []byte, max int) { s.maxTokenSize = max } -// Split sets the split function for the Scanner. -// The default split function is ScanLines. +// Split sets the split function for the [Scanner]. +// The default split function is [ScanLines]. // // Split panics if it is called after scanning has started. func (s *Scanner) Split(split SplitFunc) { @@ -283,7 +283,7 @@ func (s *Scanner) Split(split SplitFunc) { // Split functions -// ScanBytes is a split function for a Scanner that returns each byte as a token. +// ScanBytes is a split function for a [Scanner] that returns each byte as a token. func ScanBytes(data []byte, atEOF bool) (advance int, token []byte, err error) { if atEOF && len(data) == 0 { return 0, nil, nil @@ -293,7 +293,7 @@ func ScanBytes(data []byte, atEOF bool) (advance int, token []byte, err error) { var errorRune = []byte(string(utf8.RuneError)) -// ScanRunes is a split function for a Scanner that returns each +// ScanRunes is a split function for a [Scanner] that returns each // UTF-8-encoded rune as a token. The sequence of runes returned is // equivalent to that from a range loop over the input as a string, which // means that erroneous UTF-8 encodings translate to U+FFFD = "\xef\xbf\xbd". @@ -339,7 +339,7 @@ func dropCR(data []byte) []byte { return data } -// ScanLines is a split function for a Scanner that returns each line of +// ScanLines is a split function for a [Scanner] that returns each line of // text, stripped of any trailing end-of-line marker. The returned line may // be empty. The end-of-line marker is one optional carriage return followed // by one mandatory newline. In regular expression notation, it is `\r?\n`. @@ -386,7 +386,7 @@ func isSpace(r rune) bool { return false } -// ScanWords is a split function for a Scanner that returns each +// ScanWords is a split function for a [Scanner] that returns each // space-separated word of text, with surrounding spaces deleted. It will // never return an empty string. The definition of space is set by // unicode.IsSpace. |
