summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pkg/bufio/bufio.go45
-rw-r--r--src/pkg/bufio/bufio_test.go4
-rw-r--r--src/pkg/http/request.go2
-rw-r--r--src/pkg/log/log_test.go3
-rw-r--r--src/pkg/net/parse_test.go5
-rw-r--r--src/pkg/strconv/fp_test.go3
-rw-r--r--src/pkg/unicode/maketables.go2
7 files changed, 36 insertions, 28 deletions
diff --git a/src/pkg/bufio/bufio.go b/src/pkg/bufio/bufio.go
index 4f9787103..895dbf6e7 100644
--- a/src/pkg/bufio/bufio.go
+++ b/src/pkg/bufio/bufio.go
@@ -214,13 +214,17 @@ func (b *Reader) Buffered() int {
return b.w - b.r;
}
-// ReadLineSlice reads until the first occurrence of delim in the input,
+// ReadSlice reads until the first occurrence of delim in the input,
// returning a slice pointing at the bytes in the buffer.
// The bytes stop being valid at the next read call.
-// Fails if the line doesn't fit in the buffer.
-// For internal or advanced use only; most uses should
-// call ReadLineString or ReadLineBytes instead.
-func (b *Reader) ReadLineSlice(delim byte) (line []byte, err os.Error) {
+// If ReadSlice encounters an error before finding a delimiter,
+// it returns all the data in the buffer and the error itself (often os.EOF).
+// ReadSlice fails with error ErrBufferFull if the buffer fills without a delim.
+// Because the data returned from ReadSlice will be overwritten
+// by the next I/O operation, most clients should use
+// ReadBytes or ReadString instead.
+// ReadSlice returns err != nil if and only if line does not end in delim.
+func (b *Reader) ReadSlice(delim byte) (line []byte, err os.Error) {
// Look in buffer.
if i := findByte(b.buf[b.r:b.w], delim); i >= 0 {
line1 := b.buf[b.r:b.r+i+1];
@@ -254,13 +258,13 @@ func (b *Reader) ReadLineSlice(delim byte) (line []byte, err os.Error) {
panic("not reached");
}
-// ReadLineBytes reads until the first occurrence of delim in the input,
-// returning a new byte array containing the line.
-// If an error happens, returns the data (without a delimiter)
-// and the error. (It can't leave the data in the buffer because
-// it might have read more than the buffer size.)
-func (b *Reader) ReadLineBytes(delim byte) (line []byte, err os.Error) {
- // Use ReadLineSlice to look for array,
+// ReadBytes reads until the first occurrence of delim in the input,
+// returning a string containing the data up to and including the delimiter.
+// If ReadBytes encounters an error before finding a delimiter,
+// it returns the data read before the error and the error itself (often os.EOF).
+// ReadBytes returns err != nil if and only if line does not end in delim.
+func (b *Reader) ReadBytes(delim byte) (line []byte, err os.Error) {
+ // Use ReadSlice to look for array,
// accumulating full buffers.
var frag []byte;
var full [][]byte;
@@ -269,7 +273,7 @@ func (b *Reader) ReadLineBytes(delim byte) (line []byte, err os.Error) {
for {
var e os.Error;
- frag, e = b.ReadLineSlice(delim);
+ frag, e = b.ReadSlice(delim);
if e == nil { // got final fragment
break
}
@@ -327,14 +331,13 @@ func (b *Reader) ReadLineBytes(delim byte) (line []byte, err os.Error) {
return buf, err
}
-// ReadLineString reads until the first occurrence of delim in the input,
-// returning a new string containing the line.
-// If savedelim, keep delim in the result; otherwise drop it.
-func (b *Reader) ReadLineString(delim byte, savedelim bool) (line string, err os.Error) {
- bytes, e := b.ReadLineBytes(delim);
- if n := len(bytes); !savedelim && n > 0 && bytes[n-1] == delim {
- bytes = bytes[0:n-1]
- }
+// ReadString reads until the first occurrence of delim in the input,
+// returning a string containing the data up to and including the delimiter.
+// If ReadString encounters an error before finding a delimiter,
+// it returns the data read before the error and the error itself (often os.EOF).
+// ReadString returns err != nil if and only if line does not end in delim.
+func (b *Reader) ReadString(delim byte) (line string, err os.Error) {
+ bytes, e := b.ReadBytes(delim);
return string(bytes), e;
}
diff --git a/src/pkg/bufio/bufio_test.go b/src/pkg/bufio/bufio_test.go
index 389b4097d..7100bcfa5 100644
--- a/src/pkg/bufio/bufio_test.go
+++ b/src/pkg/bufio/bufio_test.go
@@ -84,12 +84,12 @@ var readMakers = []readMaker {
readMaker{ "data+err", iotest.DataErrReader },
}
-// Call ReadLineString (which ends up calling everything else)
+// Call ReadString (which ends up calling everything else)
// to accumulate the text of a file.
func readLines(b *Reader) string {
s := "";
for {
- s1, e := b.ReadLineString('\n', true);
+ s1, e := b.ReadString('\n');
if e == os.EOF {
break
}
diff --git a/src/pkg/http/request.go b/src/pkg/http/request.go
index dabd39d20..e276deeff 100644
--- a/src/pkg/http/request.go
+++ b/src/pkg/http/request.go
@@ -204,7 +204,7 @@ func (req *Request) write(w io.Writer) os.Error {
// The returned bytes are a pointer into storage in
// the bufio, so they are only valid until the next bufio read.
func readLineBytes(b *bufio.Reader) (p []byte, err os.Error) {
- if p, err = b.ReadLineSlice('\n'); err != nil {
+ if p, err = b.ReadSlice('\n'); err != nil {
// We always know when EOF is coming.
// If the caller asked for a line, there should be a line.
if err == os.EOF {
diff --git a/src/pkg/log/log_test.go b/src/pkg/log/log_test.go
index 12f732632..52be6803d 100644
--- a/src/pkg/log/log_test.go
+++ b/src/pkg/log/log_test.go
@@ -59,10 +59,11 @@ func testLog(t *testing.T, flag int, prefix string, pattern string, useLogf bool
} else {
l.Log("hello", 23, "world");
}
- line, err3 := buf.ReadLineString('\n', false);
+ line, err3 := buf.ReadString('\n');
if err3 != nil {
t.Fatal("log error", err3);
}
+ line = line[0:len(line)-1];
pattern = "^"+pattern+"hello 23 world$";
matched, err4 := regexp.MatchString(pattern, line);
if err4 != nil{
diff --git a/src/pkg/net/parse_test.go b/src/pkg/net/parse_test.go
index 227ae55f1..c95138896 100644
--- a/src/pkg/net/parse_test.go
+++ b/src/pkg/net/parse_test.go
@@ -28,7 +28,10 @@ func TestReadLine(t *testing.T) {
lineno := 1;
byteno := 0;
for {
- bline, berr := br.ReadLineString('\n', false);
+ bline, berr := br.ReadString('\n');
+ if n := len(bline); n > 0 {
+ bline = bline[0:n-1];
+ }
line, ok := file.readLine();
if (berr != nil) != !ok || bline != line {
t.Fatalf("%s:%d (#%d)\nbufio => %q, %v\nnet => %q, %v",
diff --git a/src/pkg/strconv/fp_test.go b/src/pkg/strconv/fp_test.go
index 0890b0fad..c38762dfb 100644
--- a/src/pkg/strconv/fp_test.go
+++ b/src/pkg/strconv/fp_test.go
@@ -104,13 +104,14 @@ func TestFp(t *testing.T) {
lineno := 0;
for {
- line, err2 := b.ReadLineString('\n', false);
+ line, err2 := b.ReadString('\n');
if err2 == os.EOF {
break;
}
if err2 != nil {
panicln("testfp: read testfp.txt:", err2.String());
}
+ line = line[0:len(line)-1];
lineno++;
if len(line) == 0 || line[0] == '#' {
continue
diff --git a/src/pkg/unicode/maketables.go b/src/pkg/unicode/maketables.go
index 36e67be1b..8e91276bf 100644
--- a/src/pkg/unicode/maketables.go
+++ b/src/pkg/unicode/maketables.go
@@ -202,7 +202,7 @@ func main() {
}
input := bufio.NewReader(resp.Body);
for {
- line, err := input.ReadLineString('\n', false);
+ line, err := input.ReadString('\n', false);
if err != nil {
if err == os.EOF {
break;