Commit 4dfc7f0f authored by Russ Cox's avatar Russ Cox

fix / work around bugs in bufio test

R=r
DELTA=11  (8 added, 0 deleted, 3 changed)
OCL=15405
CL=15405
parent 85f8d450
...@@ -291,18 +291,26 @@ func (b *BufRead) ReadLineBytes(delim byte) (line *[]byte, err *os.Error) { ...@@ -291,18 +291,26 @@ func (b *BufRead) ReadLineBytes(delim byte) (line *[]byte, err *os.Error) {
return buf, err return buf, err
} }
// BUG(bugs/bug102.go): string(empty bytes array) throws error
func ToString(p *[]byte) string {
if len(p) == 0 {
return ""
}
return string(p)
}
// Read until the first occurrence of delim in the input, // Read until the first occurrence of delim in the input,
// returning a new string containing the line. // returning a new string containing the line.
// If savedelim, keep delim in the result; otherwise chop it off. // If savedelim, keep delim in the result; otherwise chop it off.
func (b *BufRead) ReadLineString(delim byte, savedelim bool) (line string, err *os.Error) { func (b *BufRead) ReadLineString(delim byte, savedelim bool) (line string, err *os.Error) {
bytes, e := b.ReadLineBytes(delim) bytes, e := b.ReadLineBytes(delim)
if e != nil { if e != nil {
return string(bytes), e return ToString(bytes), e
} }
if !savedelim { if !savedelim {
bytes = bytes[0:len(bytes)-1] bytes = bytes[0:len(bytes)-1]
} }
return string(bytes), nil return ToString(bytes), nil
} }
......
...@@ -121,7 +121,7 @@ var readmakers = []*(p *[]byte) io.Read { ...@@ -121,7 +121,7 @@ var readmakers = []*(p *[]byte) io.Read {
func ReadLines(b *bufio.BufRead) string { func ReadLines(b *bufio.BufRead) string {
s := "" s := ""
for { for {
s1, e := b.ReadLineString('\n', false) s1, e := b.ReadLineString('\n', true)
if e == bufio.EndOfFile { if e == bufio.EndOfFile {
break break
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment