]> Cypherpunks repositories - gostls13.git/commit
bufio: allow Scanner to accept a user-provided buffer
authorRob Pike <r@golang.org>
Tue, 15 Sep 2015 21:14:44 +0000 (14:14 -0700)
committerRob Pike <r@golang.org>
Fri, 18 Sep 2015 18:56:49 +0000 (18:56 +0000)
commit13be616e560411f6f252f728deed3c0b3e145fed
tree7284824a05ed97c1cabc8af7fdc0a896aa827bbe
parent1536c2e0f6f2cf0b42b8f4db329f969cabc8eabb
bufio: allow Scanner to accept a user-provided buffer

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>
src/bufio/scan.go
src/bufio/scan_test.go