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