aboutsummaryrefslogtreecommitdiff
path: root/src/bufio/scan.go
AgeCommit message (Collapse)Author
2026-02-03bufio: realign struct ScannerShulhan
This reduce the Scanner allocation size from 112 to 72 bytes.
2025-05-21bufio: update buffer documentationLokesh Kumar
Fixes #73778 Change-Id: If6d87a92786c9b0ee2bd790b57937919afe0fc5c GitHub-Last-Rev: 4b4c7595d5779a127b01a5d71adca91cb5aa6c05 GitHub-Pull-Request: golang/go#73804 Reviewed-on: https://go-review.googlesource.com/c/go/+/674695 Auto-Submit: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Alan Donovan <adonovan@google.com>
2023-10-23bufio: allow terminating Scanner early cleanly without a final token or an errorfavonia
Fixes #56381 Change-Id: I95cd603831a7032d764ab312869fe9fb05848a4b Reviewed-on: https://go-review.googlesource.com/c/go/+/498117 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Benny Siegert <bsiegert@gmail.com>
2023-10-14bufio: link "too large to fit" to Scanner.BufferIan Lance Taylor
Change-Id: Id0a4f5716da98008eec10eee05b74fc2a155ba3c Reviewed-on: https://go-review.googlesource.com/c/go/+/535216 Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Rob Pike <r@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2023-10-12bufio: add available godoc linkcui fliter
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>
2023-10-04bufio: use max/min funcqiulaidongfeng
Change-Id: I52875f8dd4bbdc9296ba8e4f801356047ee14e62 GitHub-Last-Rev: dfb2a343e60f0994a5741e1b4534e464a80ba2ef GitHub-Pull-Request: golang/go#63344 Reviewed-on: https://go-review.googlesource.com/c/go/+/532216 Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@google.com> Run-TryBot: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com>
2023-08-16bufio: clarify the maximum token sizeqiulaidongfeng
Fixes #43183. Change-Id: I50d99ef8ed513bba47166a25ea5c7c80cd8bd799 GitHub-Last-Rev: 684d70e9a3dbc0ce280e1112105d666cd5754e9f GitHub-Pull-Request: golang/go#61979 Reviewed-on: https://go-review.googlesource.com/c/go/+/518860 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2022-04-01all: remove trailing blank doc comment linesRuss Cox
A future change to gofmt will rewrite // Doc comment. // func f() to // Doc comment. func f() Apply that change preemptively to all doc comments. For #51082. Change-Id: I4023e16cfb0729b64a8590f071cd92f17343081d Reviewed-on: https://go-review.googlesource.com/c/go/+/384259 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-04-30bufio: mention ErrFinalToken in SplitFunc documentationMatt Harden
It is documented elsewhere in the package documentation but this additional mention of it will hopefully reduce confusion. Fixes #44261 Change-Id: I4e9d8f4564ebb7fbe047c92ee2cdffedb39f2a31 GitHub-Last-Rev: 64b6421503dfb9396e46f94f9805ff7f8bf2b31b GitHub-Pull-Request: golang/go#45839 Reviewed-on: https://go-review.googlesource.com/c/go/+/314969 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2020-03-25scan: for style, adjust code for bad scan read countsRob Pike
Make the code more consistent with the rest of the file. Should have caught this in review of CL 225357. Change-Id: I12824cb436539c31604684e043ebb7587cc92471 Reviewed-on: https://go-review.googlesource.com/c/go/+/225557 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org>
2020-03-25bufio: don't panic when Scanner sees an impossible Read countIan Lance Taylor
Fixes #38053 Change-Id: Ib0f9777f37eeaa07eb8ecb6df3e97e9d4b46dcd8 Reviewed-on: https://go-review.googlesource.com/c/go/+/225357 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2019-05-23bufio: Fix typo in scan.go documentationMickey Reiss
Apologies for the the nitpicky PR. I believe there is a minor typo in the documentation of `MaxScanTokenSize`, which confused me for a moment when I went to search for the referenced method, `Scan.Buffer`. Thanks! Change-Id: I5d21e77276285206497fe75291001032c255cace GitHub-Last-Rev: 635e35c0191c11f2b6966b5e58cf91a1064099da GitHub-Pull-Request: golang/go#32193 Reviewed-on: https://go-review.googlesource.com/c/go/+/178637 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-13bufio: clarify SplitFunc docs for nil tokenIan Lance Taylor
Fixes #25472 Change-Id: Idb72ed06a3dc43c49ab984a80f8885352b036465 Reviewed-on: https://go-review.googlesource.com/118695 Reviewed-by: Rob Pike <r@golang.org>
2017-11-14bufio: Use maxConsecutiveEmptyReads instead of 100Ryoichi KATO
Use maxConsecutiveEmptyReads const instead of hardcoded 100 in scan.go too. Change-Id: I993f353a3748f0d6bdefab38bf5cb224eea8a969 Reviewed-on: https://go-review.googlesource.com/46915 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-10-24bufio: remove unnecessary "continue"Quentin Smith
After resizing the scan buffer, we can immediately read into the newly-resized buffer since we know there is now space. Fixes #15712. Change-Id: I56fcfaeb67045ee753a012c37883aa7c81b6e877 Reviewed-on: https://go-review.googlesource.com/31715 Run-TryBot: Quentin Smith <quentin@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2015-09-25bufio: fix scanning with a final empty token.Rob Pike
The Scan function's interface to the split function was not sufficient to handle an empty final token in a pure function; state was required. This was ugly. We introduce a special error value that a split function can return that signals that this token is OK, but is the last one and scanning should stop immediately _after_ this token. The same effect could be achieved using the same trick (a special error value) and checking for that error after Scan finishes, but it's a little clumsy. Providing a published sentinel value in bufio is cleaner and means everyone can use the same trick. The result is an error-free scan. Rewrite the test (that was only barely working) to use the value and be more robust. Also write a new example showing how to do it. Fixes #11836 Change-Id: Iaae77d0f95b4a2efa0175ced94d93c66353079e8 Reviewed-on: https://go-review.googlesource.com/14924 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-09-20bufio: fix overflow calculation in ScanRob Pike
I was being too clever, as usual. Write the obvious code to make sure that when we grow the buffer we don't overflow. Change-Id: I1641831177b0bb8a89ab6e9bcabccf6c2fcfe1d2 Reviewed-on: https://go-review.googlesource.com/14781 Reviewed-by: Minux Ma <minux@golang.org>
2015-09-18bufio: allow Scanner to accept a user-provided bufferRob Pike
Add Scanner.Buffer, which lets the user give a buffer to the scanner and set the maximum token size. We call it Buffer not SetBuffer for consistency with Split, which perhaps should have been called SetSplit; too late regardless. Both Buffer and Split panic if they are called after Scan. The panic in Split is new, but the comment on the method already said it needed to be called first, so we might as well add the verification while we're doing it for Buffer. This method allows precise user control of storage. Fixes #11702. Change-Id: I80e3d0e3830562fdabd4f7b08f322e1378248c39 Reviewed-on: https://go-review.googlesource.com/14599 Reviewed-by: Andrew Gerrand <adg@golang.org> Reviewed-by: roger peppe <rogpeppe@gmail.com>
2015-03-18bufio: fix incorrect comment on Scanner.ScanAaron Jacobs
Change-Id: I216511a4bce431de0a468f618a7a7c4da79e2979 Reviewed-on: https://go-review.googlesource.com/7710 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2014-11-05bufio: fix reading of many blank lines in a rowRuss Cox
Fixes #9020. LGTM=bradfitz, r R=r, bradfitz CC=golang-codereviews https://golang.org/cl/170030043
2014-11-06bufio: don't loop generating empty tokensRob Pike
The new rules for split functions mean that we are exposed to the common bug of a function that loops forever at EOF. Pick these off by shutting down the scanner if too many consecutive empty tokens are delivered. Fixes #9020. LGTM=rsc, adg R=golang-codereviews, rsc, adg, bradfitz CC=golang-codereviews https://golang.org/cl/169970043
2014-09-25bufio: fix handling of empty tokens at end of line/fileRob Pike
Fixes #8672. LGTM=rsc R=golang-codereviews, rsc CC=golang-codereviews https://golang.org/cl/145390043
2014-09-08build: move package sources from src/pkg to srcRuss Cox
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.