use bufio.Reader instead of io.Reader
This commit is contained in:
parent
b8c09a905b
commit
3dc2842e2e
@ -2,7 +2,6 @@ package parse
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"strconv"
|
||||
|
||||
"github.com/mediocregopher/ginger/types"
|
||||
@ -19,11 +18,10 @@ import (
|
||||
// double-quote has already been read off. Ginger strings are wrapped with " and
|
||||
// are allowed to have newlines literal in them. In all other respects they are
|
||||
// the same as go strings.
|
||||
func ReadString(r io.Reader) (types.Str, error) {
|
||||
buf := bufio.NewReader(r)
|
||||
func ReadString(r *bufio.Reader) (types.Str, error) {
|
||||
str := types.Str("\"")
|
||||
for {
|
||||
piece, err := buf.ReadBytes('"')
|
||||
piece, err := r.ReadBytes('"')
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
BIN
parse/parse.test
BIN
parse/parse.test
Binary file not shown.
@ -2,6 +2,7 @@ package parse
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"bufio"
|
||||
. "testing"
|
||||
|
||||
"github.com/mediocregopher/ginger/types"
|
||||
@ -18,8 +19,9 @@ func TestReadString(t *T) {
|
||||
for input, output := range m {
|
||||
buf := bytes.NewBufferString(input)
|
||||
buf.ReadByte()
|
||||
buf2 := bufio.NewReader(buf)
|
||||
|
||||
parseOut, err := ReadString(buf)
|
||||
parseOut, err := ReadString(buf2)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user