summaryrefslogtreecommitdiff
path: root/src/lib/bufio.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2008-09-16 14:15:54 -0700
committerRuss Cox <rsc@golang.org>2008-09-16 14:15:54 -0700
commit2e8c4ed26bb3f3dbf3dc1ca9661303c2ef15bb55 (patch)
tree4802a3cf42feb0a3e246c01dfcd3c618449c4a46 /src/lib/bufio.go
parentecb6c06cd654e0736f0e305182b97df4bea44218 (diff)
downloadgolang-2e8c4ed26bb3f3dbf3dc1ca9661303c2ef15bb55.tar.gz
fix / work around bugs in bufio test
R=r DELTA=11 (8 added, 0 deleted, 3 changed) OCL=15405 CL=15405
Diffstat (limited to 'src/lib/bufio.go')
-rw-r--r--src/lib/bufio.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/lib/bufio.go b/src/lib/bufio.go
index 323e39ff6..3c29b236c 100644
--- a/src/lib/bufio.go
+++ b/src/lib/bufio.go
@@ -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
}