]> Cypherpunks repositories - gostls13.git/commitdiff
fix / work around bugs in bufio test
authorRuss Cox <rsc@golang.org>
Tue, 16 Sep 2008 21:15:54 +0000 (14:15 -0700)
committerRuss Cox <rsc@golang.org>
Tue, 16 Sep 2008 21:15:54 +0000 (14:15 -0700)
R=r
DELTA=11  (8 added, 0 deleted, 3 changed)
OCL=15405
CL=15405

src/lib/bufio.go
test/bufiolib.go

index 323e39ff66df2b07066bff4d059f551f25d29ba6..3c29b236c36e56cf024c8dd9accfe624e9609675 100644 (file)
@@ -291,18 +291,26 @@ func (b *BufRead) ReadLineBytes(delim byte) (line *[]byte, err *os.Error) {
        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,
 // returning a new string containing the line.
 // If savedelim, keep delim in the result; otherwise chop it off.
 func (b *BufRead) ReadLineString(delim byte, savedelim bool) (line string, err *os.Error) {
        bytes, e := b.ReadLineBytes(delim)
        if e != nil {
-               return string(bytes), e
+               return ToString(bytes), e
        }
        if !savedelim {
                bytes = bytes[0:len(bytes)-1]
        }
-       return string(bytes), nil
+       return ToString(bytes), nil
 }
 
 
index b5d7453c1ba7879495e97c914109afd062646f87..a3c05036f741b522f5d15f2fb3b7c9b18912c363 100644 (file)
@@ -121,7 +121,7 @@ var readmakers = []*(p *[]byte) io.Read {
 func ReadLines(b *bufio.BufRead) string {
        s := ""
        for {
-               s1, e := b.ReadLineString('\n', false)
+               s1, e := b.ReadLineString('\n', true)
                if e == bufio.EndOfFile {
                        break
                }