Commit d3a412a5 authored by Russ Cox's avatar Russ Cox

io.StringBytes -> strings.Bytes

io.ByteBuffer -> bytes.Buffer

left io.ByteBuffer stub around for now,
for protocol compiler.

R=r
OCL=30861
CL=30872
parent b948c437
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
package main package main
import ( import (
"bytes";
"container/vector"; "container/vector";
"flag"; "flag";
"fmt"; "fmt";
...@@ -198,7 +199,7 @@ func parse(path string, mode uint) (*ast.Program, *parseErrors) { ...@@ -198,7 +199,7 @@ func parse(path string, mode uint) (*ast.Program, *parseErrors) {
// Return text for an AST node. // Return text for an AST node.
func nodeText(node interface{}, mode uint) []byte { func nodeText(node interface{}, mode uint) []byte {
var buf io.ByteBuffer; var buf bytes.Buffer;
tw := makeTabwriter(&buf); tw := makeTabwriter(&buf);
printer.Fprint(tw, node, mode); printer.Fprint(tw, node, mode);
tw.Flush(); tw.Flush();
...@@ -214,15 +215,15 @@ func toText(x interface{}) []byte { ...@@ -214,15 +215,15 @@ func toText(x interface{}) []byte {
case []byte: case []byte:
return v; return v;
case string: case string:
return io.StringBytes(v); return strings.Bytes(v);
case String: case String:
return io.StringBytes(v.String()); return strings.Bytes(v.String());
case ast.Decl: case ast.Decl:
return nodeText(v, printer.ExportsOnly); return nodeText(v, printer.ExportsOnly);
case ast.Expr: case ast.Expr:
return nodeText(v, printer.ExportsOnly); return nodeText(v, printer.ExportsOnly);
} }
var buf io.ByteBuffer; var buf bytes.Buffer;
fmt.Fprint(&buf, x); fmt.Fprint(&buf, x);
return buf.Data(); return buf.Data();
} }
...@@ -315,7 +316,7 @@ func serveText(c *http.Conn, text []byte) { ...@@ -315,7 +316,7 @@ func serveText(c *http.Conn, text []byte) {
func serveParseErrors(c *http.Conn, errors *parseErrors) { func serveParseErrors(c *http.Conn, errors *parseErrors) {
// format errors // format errors
var buf io.ByteBuffer; var buf bytes.Buffer;
parseerrorHtml.Execute(errors, &buf); parseerrorHtml.Execute(errors, &buf);
servePage(c, errors.filename + " - Parse Errors", buf.Data()); servePage(c, errors.filename + " - Parse Errors", buf.Data());
} }
...@@ -328,7 +329,7 @@ func serveGoSource(c *http.Conn, name string) { ...@@ -328,7 +329,7 @@ func serveGoSource(c *http.Conn, name string) {
return; return;
} }
var buf io.ByteBuffer; var buf bytes.Buffer;
fmt.Fprintln(&buf, "<pre>"); fmt.Fprintln(&buf, "<pre>");
template.HtmlEscape(&buf, nodeText(prog, printer.DocComments)); template.HtmlEscape(&buf, nodeText(prog, printer.DocComments));
fmt.Fprintln(&buf, "</pre>"); fmt.Fprintln(&buf, "</pre>");
...@@ -518,7 +519,7 @@ func servePkg(c *http.Conn, r *http.Request) { ...@@ -518,7 +519,7 @@ func servePkg(c *http.Conn, r *http.Request) {
return; return;
} }
var buf io.ByteBuffer; var buf bytes.Buffer;
if false { // TODO req.Params["format"] == "text" if false { // TODO req.Params["format"] == "text"
err := packageText.Execute(PageInfo{pdoc, dirs}, &buf); err := packageText.Execute(PageInfo{pdoc, dirs}, &buf);
if err != nil { if err != nil {
...@@ -571,7 +572,7 @@ func exec(c *http.Conn, args []string) bool { ...@@ -571,7 +572,7 @@ func exec(c *http.Conn, args []string) bool {
return false; return false;
} }
var buf io.ByteBuffer; var buf bytes.Buffer;
io.Copy(r, &buf); io.Copy(r, &buf);
wait, err := os.Wait(pid, 0); wait, err := os.Wait(pid, 0);
if err != nil { if err != nil {
......
...@@ -2,7 +2,7 @@ archive/tar.install: bufio.install bytes.install io.install os.install strconv.i ...@@ -2,7 +2,7 @@ archive/tar.install: bufio.install bytes.install io.install os.install strconv.i
base64.install: bytes.install io.install os.install strconv.install base64.install: bytes.install io.install os.install strconv.install
bignum.install: fmt.install bignum.install: fmt.install
bufio.install: io.install os.install strconv.install utf8.install bufio.install: io.install os.install strconv.install utf8.install
bytes.install: utf8.install bytes.install: os.install utf8.install
compress/flate.install: bufio.install io.install os.install strconv.install compress/flate.install: bufio.install io.install os.install strconv.install
compress/gzip.install: bufio.install compress/flate.install hash.install hash/crc32.install io.install os.install compress/gzip.install: bufio.install compress/flate.install hash.install hash/crc32.install io.install os.install
container/list.install: container/list.install:
...@@ -12,41 +12,41 @@ crypto/block.install: fmt.install io.install os.install strconv.install ...@@ -12,41 +12,41 @@ crypto/block.install: fmt.install io.install os.install strconv.install
crypto/hmac.install: crypto/md5.install crypto/sha1.install hash.install os.install crypto/hmac.install: crypto/md5.install crypto/sha1.install hash.install os.install
crypto/md5.install: hash.install os.install crypto/md5.install: hash.install os.install
crypto/sha1.install: hash.install os.install crypto/sha1.install: hash.install os.install
datafmt.install: container/vector.install fmt.install go/scanner.install go/token.install io.install os.install reflect.install runtime.install strconv.install strings.install datafmt.install: bytes.install container/vector.install fmt.install go/scanner.install go/token.install io.install os.install reflect.install runtime.install strconv.install strings.install
exec.install: os.install strings.install exec.install: os.install strings.install
exvar.install: fmt.install http.install io.install log.install strconv.install sync.install exvar.install: bytes.install fmt.install http.install io.install log.install strconv.install sync.install
flag.install: fmt.install os.install strconv.install flag.install: fmt.install os.install strconv.install
fmt.install: io.install os.install reflect.install strconv.install utf8.install fmt.install: io.install os.install reflect.install strconv.install utf8.install
go/ast.install: go/token.install unicode.install utf8.install go/ast.install: go/token.install unicode.install utf8.install
go/doc.install: container/vector.install fmt.install go/ast.install go/token.install io.install once.install regexp.install sort.install strings.install template.install go/doc.install: container/vector.install fmt.install go/ast.install go/token.install io.install once.install regexp.install sort.install strings.install template.install
go/parser.install: container/vector.install fmt.install go/ast.install go/scanner.install go/token.install io.install os.install go/parser.install: bytes.install container/vector.install fmt.install go/ast.install go/scanner.install go/token.install io.install os.install strings.install
go/printer.install: fmt.install go/ast.install go/token.install io.install os.install reflect.install go/printer.install: fmt.install go/ast.install go/token.install io.install os.install reflect.install strings.install
go/scanner.install: go/token.install strconv.install unicode.install utf8.install go/scanner.install: go/token.install strconv.install unicode.install utf8.install
go/token.install: strconv.install go/token.install: strconv.install
hash.install: io.install hash.install: io.install
hash/adler32.install: hash.install os.install hash/adler32.install: hash.install os.install
hash/crc32.install: hash.install os.install hash/crc32.install: hash.install os.install
http.install: bufio.install bytes.install container/vector.install fmt.install io.install log.install net.install os.install path.install strconv.install strings.install utf8.install http.install: bufio.install bytes.install container/vector.install fmt.install io.install log.install net.install os.install path.install strconv.install strings.install utf8.install
io.install: bytes.install os.install sync.install io.install: bytes.install os.install strings.install sync.install
json.install: container/vector.install fmt.install io.install math.install reflect.install strconv.install strings.install utf8.install json.install: bytes.install container/vector.install fmt.install io.install math.install reflect.install strconv.install strings.install utf8.install
log.install: fmt.install io.install os.install runtime.install time.install log.install: fmt.install io.install os.install runtime.install time.install
malloc.install: malloc.install:
math.install: math.install:
net.install: fmt.install io.install once.install os.install reflect.install strconv.install strings.install sync.install syscall.install net.install: fmt.install io.install once.install os.install reflect.install strconv.install strings.install sync.install syscall.install
once.install: sync.install once.install: sync.install
os.install: once.install syscall.install os.install: once.install syscall.install
path.install: io.install path.install: strings.install
rand.install: rand.install:
reflect.install: strconv.install sync.install utf8.install reflect.install: strconv.install sync.install utf8.install
regexp.install: container/vector.install io.install os.install runtime.install utf8.install regexp.install: bytes.install container/vector.install io.install os.install runtime.install utf8.install
runtime.install: runtime.install:
sort.install: sort.install:
strconv.install: bytes.install math.install os.install utf8.install strconv.install: bytes.install math.install os.install utf8.install
strings.install: utf8.install strings.install: utf8.install
sync.install: sync.install:
syscall.install: sync.install syscall.install: sync.install
tabwriter.install: container/vector.install io.install os.install utf8.install tabwriter.install: bytes.install container/vector.install io.install os.install utf8.install
template.install: container/vector.install fmt.install io.install os.install reflect.install runtime.install strings.install template.install: bytes.install container/vector.install fmt.install io.install os.install reflect.install runtime.install strings.install
testing.install: flag.install fmt.install os.install regexp.install runtime.install testing.install: flag.install fmt.install os.install regexp.install runtime.install
testing/iotest.install: io.install log.install os.install testing/iotest.install: io.install log.install os.install
time.install: io.install once.install os.install syscall.install time.install: io.install once.install os.install syscall.install
......
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"io"; "io";
"os"; "os";
"reflect"; "reflect";
"strings";
"testing"; "testing";
) )
...@@ -127,7 +128,7 @@ func TestPartialRead(t *testing.T) { ...@@ -127,7 +128,7 @@ func TestPartialRead(t *testing.T) {
if n, err := io.ReadFull(tr, buf); err != nil { if n, err := io.ReadFull(tr, buf); err != nil {
t.Fatalf("Unexpected error: %v", err); t.Fatalf("Unexpected error: %v", err);
} }
if expected := io.StringBytes("Kilt"); !bytes.Equal(buf, expected) { if expected := strings.Bytes("Kilt"); !bytes.Equal(buf, expected) {
t.Errorf("Contents = %v, want %v", buf, expected); t.Errorf("Contents = %v, want %v", buf, expected);
} }
...@@ -140,7 +141,7 @@ func TestPartialRead(t *testing.T) { ...@@ -140,7 +141,7 @@ func TestPartialRead(t *testing.T) {
if n, err := io.ReadFull(tr, buf); err != nil { if n, err := io.ReadFull(tr, buf); err != nil {
t.Fatalf("Unexpected error: %v", err); t.Fatalf("Unexpected error: %v", err);
} }
if expected := io.StringBytes("Google"); !bytes.Equal(buf, expected) { if expected := strings.Bytes("Google"); !bytes.Equal(buf, expected) {
t.Errorf("Contents = %v, want %v", buf, expected); t.Errorf("Contents = %v, want %v", buf, expected);
} }
} }
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"io"; "io";
"os"; "os";
"reflect"; "reflect";
"strings";
"testing"; "testing";
) )
...@@ -62,26 +63,26 @@ func testEqual(t *testing.T, msg string, args ...) bool { ...@@ -62,26 +63,26 @@ func testEqual(t *testing.T, msg string, args ...) bool {
func TestEncode(t *testing.T) { func TestEncode(t *testing.T) {
for _, p := range pairs { for _, p := range pairs {
buf := make([]byte, StdEncoding.EncodedLen(len(p.decoded))); buf := make([]byte, StdEncoding.EncodedLen(len(p.decoded)));
StdEncoding.Encode(io.StringBytes(p.decoded), buf); StdEncoding.Encode(strings.Bytes(p.decoded), buf);
testEqual(t, "Encode(%q) = %q, want %q", p.decoded, string(buf), p.encoded); testEqual(t, "Encode(%q) = %q, want %q", p.decoded, string(buf), p.encoded);
} }
} }
func TestEncoder(t *testing.T) { func TestEncoder(t *testing.T) {
for _, p := range pairs { for _, p := range pairs {
bb := &io.ByteBuffer{}; bb := &bytes.Buffer{};
encoder := NewEncoder(StdEncoding, bb); encoder := NewEncoder(StdEncoding, bb);
encoder.Write(io.StringBytes(p.decoded)); encoder.Write(strings.Bytes(p.decoded));
encoder.Close(); encoder.Close();
testEqual(t, "Encode(%q) = %q, want %q", p.decoded, string(bb.Data()), p.encoded); testEqual(t, "Encode(%q) = %q, want %q", p.decoded, string(bb.Data()), p.encoded);
} }
} }
func TestEncoderBuffering(t *testing.T) { func TestEncoderBuffering(t *testing.T) {
input := io.StringBytes(bigtest.decoded); input := strings.Bytes(bigtest.decoded);
for bs := 1; bs <= 12; bs++ { for bs := 1; bs <= 12; bs++ {
buf := make([]byte, bs); buf := make([]byte, bs);
bb := &io.ByteBuffer{}; bb := &bytes.Buffer{};
encoder := NewEncoder(StdEncoding, bb); encoder := NewEncoder(StdEncoding, bb);
for pos := 0; pos < len(input); pos += bs { for pos := 0; pos < len(input); pos += bs {
end := pos+bs; end := pos+bs;
...@@ -101,7 +102,7 @@ func TestEncoderBuffering(t *testing.T) { ...@@ -101,7 +102,7 @@ func TestEncoderBuffering(t *testing.T) {
func TestDecode(t *testing.T) { func TestDecode(t *testing.T) {
for _, p := range pairs { for _, p := range pairs {
dbuf := make([]byte, StdEncoding.DecodedLen(len(p.encoded))); dbuf := make([]byte, StdEncoding.DecodedLen(len(p.encoded)));
count, end, err := StdEncoding.decode(io.StringBytes(p.encoded), dbuf); count, end, err := StdEncoding.decode(strings.Bytes(p.encoded), dbuf);
testEqual(t, "Decode(%q) = error %v, want %v", p.encoded, err, os.Error(nil)); testEqual(t, "Decode(%q) = error %v, want %v", p.encoded, err, os.Error(nil));
testEqual(t, "Decode(%q) = length %v, want %v", p.encoded, count, len(p.decoded)); testEqual(t, "Decode(%q) = length %v, want %v", p.encoded, count, len(p.decoded));
if len(p.encoded) > 0 { if len(p.encoded) > 0 {
...@@ -113,7 +114,7 @@ func TestDecode(t *testing.T) { ...@@ -113,7 +114,7 @@ func TestDecode(t *testing.T) {
func TestDecoder(t *testing.T) { func TestDecoder(t *testing.T) {
for _, p := range pairs { for _, p := range pairs {
decoder := NewDecoder(StdEncoding, io.NewByteReader(io.StringBytes(p.encoded))); decoder := NewDecoder(StdEncoding, io.NewByteReader(strings.Bytes(p.encoded)));
dbuf := make([]byte, StdEncoding.DecodedLen(len(p.encoded))); dbuf := make([]byte, StdEncoding.DecodedLen(len(p.encoded)));
count, err := decoder.Read(dbuf); count, err := decoder.Read(dbuf);
if err != nil && err != os.EOF { if err != nil && err != os.EOF {
...@@ -129,7 +130,7 @@ func TestDecoder(t *testing.T) { ...@@ -129,7 +130,7 @@ func TestDecoder(t *testing.T) {
} }
func TestDecoderBuffering(t *testing.T) { func TestDecoderBuffering(t *testing.T) {
input := io.StringBytes(bigtest.encoded); input := strings.Bytes(bigtest.encoded);
for bs := 1; bs <= 12; bs++ { for bs := 1; bs <= 12; bs++ {
decoder := NewDecoder(StdEncoding, io.NewByteReader(input)); decoder := NewDecoder(StdEncoding, io.NewByteReader(input));
buf := make([]byte, len(bigtest.decoded) + 12); buf := make([]byte, len(bigtest.decoded) + 12);
...@@ -159,7 +160,7 @@ func TestDecodeCorrupt(t *testing.T) { ...@@ -159,7 +160,7 @@ func TestDecodeCorrupt(t *testing.T) {
for _, e := range examples { for _, e := range examples {
dbuf := make([]byte, StdEncoding.DecodedLen(len(e.e))); dbuf := make([]byte, StdEncoding.DecodedLen(len(e.e)));
count, err := StdEncoding.Decode(io.StringBytes(e.e), dbuf); count, err := StdEncoding.Decode(strings.Bytes(e.e), dbuf);
switch err := err.(type) { switch err := err.(type) {
case CorruptInputError: case CorruptInputError:
testEqual(t, "Corruption in %q at offset %v, want %v", e.e, int(err), e.p); testEqual(t, "Corruption in %q at offset %v, want %v", e.e, int(err), e.p);
...@@ -176,7 +177,7 @@ func TestBig(t *testing.T) { ...@@ -176,7 +177,7 @@ func TestBig(t *testing.T) {
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
raw[i] = alpha[i%len(alpha)]; raw[i] = alpha[i%len(alpha)];
} }
encoded := new(io.ByteBuffer); encoded := new(bytes.Buffer);
w := NewEncoder(StdEncoding, encoded); w := NewEncoder(StdEncoding, encoded);
nn, err := w.Write(raw); nn, err := w.Write(raw);
if nn != n || err != nil { if nn != n || err != nil {
...@@ -190,7 +191,7 @@ func TestBig(t *testing.T) { ...@@ -190,7 +191,7 @@ func TestBig(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("io.ReadAll(NewDecoder(...)): %v", err); t.Fatalf("io.ReadAll(NewDecoder(...)): %v", err);
} }
if !bytes.Equal(raw, decoded) { if !bytes.Equal(raw, decoded) {
var i int; var i int;
for i = 0; i < len(decoded) && i < len(raw); i++ { for i = 0; i < len(decoded) && i < len(raw); i++ {
......
...@@ -5,10 +5,12 @@ ...@@ -5,10 +5,12 @@
package bufio package bufio
import ( import (
"bytes";
"bufio"; "bufio";
"fmt"; "fmt";
"io"; "io";
"os"; "os";
"strings";
"testing"; "testing";
"testing/iotest"; "testing/iotest";
) )
...@@ -59,7 +61,7 @@ func readBytes(buf *Reader) string { ...@@ -59,7 +61,7 @@ func readBytes(buf *Reader) string {
} }
func TestReaderSimple(t *testing.T) { func TestReaderSimple(t *testing.T) {
data := io.StringBytes("hello world"); data := strings.Bytes("hello world");
b := NewReader(io.NewByteReader(data)); b := NewReader(io.NewByteReader(data));
if s := readBytes(b); s != "hello world" { if s := readBytes(b); s != "hello world" {
t.Errorf("simple hello world test failed: got %q", s); t.Errorf("simple hello world test failed: got %q", s);
...@@ -146,7 +148,7 @@ func TestReader(t *testing.T) { ...@@ -146,7 +148,7 @@ func TestReader(t *testing.T) {
for h := 0; h < len(texts); h++ { for h := 0; h < len(texts); h++ {
text := texts[h]; text := texts[h];
textbytes := io.StringBytes(text); textbytes := strings.Bytes(text);
for i := 0; i < len(readMakers); i++ { for i := 0; i < len(readMakers); i++ {
for j := 0; j < len(bufreaders); j++ { for j := 0; j < len(bufreaders); j++ {
for k := 0; k < len(bufsizes); k++ { for k := 0; k < len(bufsizes); k++ {
...@@ -172,7 +174,7 @@ func TestWriter(t *testing.T) { ...@@ -172,7 +174,7 @@ func TestWriter(t *testing.T) {
for i := 0; i < len(data); i++ { for i := 0; i < len(data); i++ {
data[i] = byte(' '+ i%('~'-' ')); data[i] = byte(' '+ i%('~'-' '));
} }
w := new(io.ByteBuffer); w := new(bytes.Buffer);
for i := 0; i < len(bufsizes); i++ { for i := 0; i < len(bufsizes); i++ {
for j := 0; j < len(bufsizes); j++ { for j := 0; j < len(bufsizes); j++ {
nwrite := bufsizes[i]; nwrite := bufsizes[i];
...@@ -237,7 +239,7 @@ var errorWriterTests = []errorWriterTest { ...@@ -237,7 +239,7 @@ var errorWriterTests = []errorWriterTest {
func TestWriteErrors(t *testing.T) { func TestWriteErrors(t *testing.T) {
for i, w := range errorWriterTests { for i, w := range errorWriterTests {
buf := NewWriter(w); buf := NewWriter(w);
n, e := buf.Write(io.StringBytes("hello world")); n, e := buf.Write(strings.Bytes("hello world"));
if e != nil { if e != nil {
t.Errorf("Write hello to %v: %v", w, e); t.Errorf("Write hello to %v: %v", w, e);
continue; continue;
...@@ -251,7 +253,7 @@ func TestWriteErrors(t *testing.T) { ...@@ -251,7 +253,7 @@ func TestWriteErrors(t *testing.T) {
func TestNewReaderSizeIdempotent(t *testing.T) { func TestNewReaderSizeIdempotent(t *testing.T) {
const BufSize = 1000; const BufSize = 1000;
b, err := NewReaderSize(io.NewByteReader(io.StringBytes("hello world")), BufSize); b, err := NewReaderSize(io.NewByteReader(strings.Bytes("hello world")), BufSize);
if err != nil { if err != nil {
t.Error("NewReaderSize create fail", err); t.Error("NewReaderSize create fail", err);
} }
...@@ -275,7 +277,7 @@ func TestNewReaderSizeIdempotent(t *testing.T) { ...@@ -275,7 +277,7 @@ func TestNewReaderSizeIdempotent(t *testing.T) {
func TestNewWriterSizeIdempotent(t *testing.T) { func TestNewWriterSizeIdempotent(t *testing.T) {
const BufSize = 1000; const BufSize = 1000;
b, err := NewWriterSize(new(io.ByteBuffer), BufSize); b, err := NewWriterSize(new(bytes.Buffer), BufSize);
if err != nil { if err != nil {
t.Error("NewWriterSize create fail", err); t.Error("NewWriterSize create fail", err);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style # Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file. # license that can be found in the LICENSE file.
# DO NOT EDIT. Automatically generated by gobuild. # DO NOT EDIT. Automatically generated by gobuild.
# gobuild -m >Makefile # gobuild -m >Makefile
...@@ -20,7 +21,7 @@ test: packages ...@@ -20,7 +21,7 @@ test: packages
coverage: packages coverage: packages
gotest gotest
6cov -g `pwd` | grep -v '_test\.go:' 6cov -g $$(pwd) | grep -v '_test\.go:'
%.$O: %.go %.$O: %.go
$(GC) -I_obj $*.go $(GC) -I_obj $*.go
...@@ -32,6 +33,7 @@ coverage: packages ...@@ -32,6 +33,7 @@ coverage: packages
$(AS) $*.s $(AS) $*.s
O1=\ O1=\
buffer.$O\
bytes.$O\ bytes.$O\
...@@ -39,7 +41,7 @@ phases: a1 ...@@ -39,7 +41,7 @@ phases: a1
_obj$D/bytes.a: phases _obj$D/bytes.a: phases
a1: $(O1) a1: $(O1)
$(AR) grc _obj$D/bytes.a bytes.$O $(AR) grc _obj$D/bytes.a buffer.$O bytes.$O
rm -f $(O1) rm -f $(O1)
......
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package io package bytes
// Simple byte buffer for marshaling data. // Simple byte buffer for marshaling data.
import ( import (
"io"; "bytes";
"os"; "os";
) )
...@@ -19,29 +19,29 @@ func bytecopy(dst []byte, doff int, src []byte, soff int, count int) { ...@@ -19,29 +19,29 @@ func bytecopy(dst []byte, doff int, src []byte, soff int, count int) {
} }
} }
// A ByteBuffer is a simple implementation of the io.Read and io.Write interfaces // A Buffer is a variable-sized buffer of bytes
// connected to a buffer of bytes. // with Read and Write methods.
// The zero value for ByteBuffer is an empty buffer ready to use. // The zero value for Buffer is an empty buffer ready to use.
type ByteBuffer struct { type Buffer struct {
buf []byte; // contents are the bytes buf[off : len(buf)] buf []byte; // contents are the bytes buf[off : len(buf)]
off int; // read at &buf[off], write at &buf[len(buf)] off int; // read at &buf[off], write at &buf[len(buf)]
} }
// Data returns the contents of the unread portion of the buffer; // Data returns the contents of the unread portion of the buffer;
// len(b.Data()) == b.Len(). // len(b.Data()) == b.Len().
func (b *ByteBuffer) Data() []byte { func (b *Buffer) Data() []byte {
return b.buf[b.off : len(b.buf)] return b.buf[b.off : len(b.buf)]
} }
// Len returns the number of bytes of the unread portion of the buffer; // Len returns the number of bytes of the unread portion of the buffer;
// b.Len() == len(b.Data()). // b.Len() == len(b.Data()).
func (b *ByteBuffer) Len() int { func (b *Buffer) Len() int {
return len(b.buf) - b.off return len(b.buf) - b.off
} }
// Truncate discards all but the first n unread bytes from the buffer. // Truncate discards all but the first n unread bytes from the buffer.
// It is an error to call b.Truncate(n) with n > b.Len(). // It is an error to call b.Truncate(n) with n > b.Len().
func (b *ByteBuffer) Truncate(n int) { func (b *Buffer) Truncate(n int) {
if n == 0 { if n == 0 {
// Reuse buffer space. // Reuse buffer space.
b.off = 0; b.off = 0;
...@@ -51,13 +51,13 @@ func (b *ByteBuffer) Truncate(n int) { ...@@ -51,13 +51,13 @@ func (b *ByteBuffer) Truncate(n int) {
// Reset resets the buffer so it has no content. // Reset resets the buffer so it has no content.
// b.Reset() is the same as b.Truncate(0). // b.Reset() is the same as b.Truncate(0).
func (b *ByteBuffer) Reset() { func (b *Buffer) Reset() {
b.Truncate(0); b.Truncate(0);
} }
// Write appends the contents of p to the buffer. The return // Write appends the contents of p to the buffer. The return
// value n is the length of p; err is always nil. // value n is the length of p; err is always nil.
func (b *ByteBuffer) Write(p []byte) (n int, err os.Error) { func (b *Buffer) Write(p []byte) (n int, err os.Error) {
m := b.Len(); m := b.Len();
n = len(p); n = len(p);
...@@ -81,7 +81,7 @@ func (b *ByteBuffer) Write(p []byte) (n int, err os.Error) { ...@@ -81,7 +81,7 @@ func (b *ByteBuffer) Write(p []byte) (n int, err os.Error) {
// WriteByte appends the byte c to the buffer. // WriteByte appends the byte c to the buffer.
// The returned error is always nil, but is included // The returned error is always nil, but is included
// to match bufio.Writer's WriteByte. // to match bufio.Writer's WriteByte.
func (b *ByteBuffer) WriteByte(c byte) os.Error { func (b *Buffer) WriteByte(c byte) os.Error {
b.Write([]byte{c}); b.Write([]byte{c});
return nil; return nil;
} }
...@@ -90,7 +90,7 @@ func (b *ByteBuffer) WriteByte(c byte) os.Error { ...@@ -90,7 +90,7 @@ func (b *ByteBuffer) WriteByte(c byte) os.Error {
// is drained. The return value n is the number of bytes read. If the // is drained. The return value n is the number of bytes read. If the
// buffer has no data to return, err is os.EOF even if len(p) is zero; // buffer has no data to return, err is os.EOF even if len(p) is zero;
// otherwise it is nil. // otherwise it is nil.
func (b *ByteBuffer) Read(p []byte) (n int, err os.Error) { func (b *Buffer) Read(p []byte) (n int, err os.Error) {
if b.off >= len(b.buf) { if b.off >= len(b.buf) {
return 0, os.EOF return 0, os.EOF
} }
...@@ -109,7 +109,7 @@ func (b *ByteBuffer) Read(p []byte) (n int, err os.Error) { ...@@ -109,7 +109,7 @@ func (b *ByteBuffer) Read(p []byte) (n int, err os.Error) {
// ReadByte reads and returns the next byte from the buffer. // ReadByte reads and returns the next byte from the buffer.
// If no byte is available, it returns error os.EOF. // If no byte is available, it returns error os.EOF.
func (b *ByteBuffer) ReadByte() (c byte, err os.Error) { func (b *Buffer) ReadByte() (c byte, err os.Error) {
if b.off >= len(b.buf) { if b.off >= len(b.buf) {
return 0, os.EOF; return 0, os.EOF;
} }
...@@ -118,8 +118,8 @@ func (b *ByteBuffer) ReadByte() (c byte, err os.Error) { ...@@ -118,8 +118,8 @@ func (b *ByteBuffer) ReadByte() (c byte, err os.Error) {
return c, nil; return c, nil;
} }
// NewByteBufferFromArray creates and initializes a new ByteBuffer // NewBuffer creates and initializes a new Buffer
// with buf as its initial contents. // using buf as its initial contents.
func NewByteBufferFromArray(buf []byte) *ByteBuffer { func NewBuffer(buf []byte) *Buffer {
return &ByteBuffer{buf, 0}; return &Buffer{buf, 0};
} }
...@@ -6,7 +6,7 @@ package bytes ...@@ -6,7 +6,7 @@ package bytes
import ( import (
"bytes"; "bytes";
"io"; "strings";
"testing"; "testing";
) )
...@@ -59,8 +59,8 @@ var comparetests = []CompareTest { ...@@ -59,8 +59,8 @@ var comparetests = []CompareTest {
func TestCompare(t *testing.T) { func TestCompare(t *testing.T) {
for i := 0; i < len(comparetests); i++ { for i := 0; i < len(comparetests); i++ {
tt := comparetests[i]; tt := comparetests[i];
a := io.StringBytes(tt.a); a := strings.Bytes(tt.a);
b := io.StringBytes(tt.b); b := strings.Bytes(tt.b);
cmp := Compare(a, b); cmp := Compare(a, b);
eql := Equal(a, b); eql := Equal(a, b);
if cmp != tt.cmp { if cmp != tt.cmp {
...@@ -85,7 +85,7 @@ var explodetests = []ExplodeTest { ...@@ -85,7 +85,7 @@ var explodetests = []ExplodeTest {
} }
func TestExplode(t *testing.T) { func TestExplode(t *testing.T) {
for _, tt := range(explodetests) { for _, tt := range(explodetests) {
a := explode(io.StringBytes(tt.s), tt.n); a := explode(strings.Bytes(tt.s), tt.n);
result := arrayOfString(a); result := arrayOfString(a);
if !eq(result, tt.a) { if !eq(result, tt.a) {
t.Errorf(`Explode("%s", %d) = %v; want %v`, tt.s, tt.n, result, tt.a); t.Errorf(`Explode("%s", %d) = %v; want %v`, tt.s, tt.n, result, tt.a);
...@@ -122,13 +122,13 @@ var splittests = []SplitTest { ...@@ -122,13 +122,13 @@ var splittests = []SplitTest {
} }
func TestSplit(t *testing.T) { func TestSplit(t *testing.T) {
for _, tt := range splittests { for _, tt := range splittests {
a := Split(io.StringBytes(tt.s), io.StringBytes(tt.sep), tt.n); a := Split(strings.Bytes(tt.s), strings.Bytes(tt.sep), tt.n);
result := arrayOfString(a); result := arrayOfString(a);
if !eq(result, tt.a) { if !eq(result, tt.a) {
t.Errorf(`Split(%q, %q, %d) = %v; want %v`, tt.s, tt.sep, tt.n, result, tt.a); t.Errorf(`Split(%q, %q, %d) = %v; want %v`, tt.s, tt.sep, tt.n, result, tt.a);
continue; continue;
} }
s := Join(a, io.StringBytes(tt.sep)); s := Join(a, strings.Bytes(tt.sep));
if string(s) != tt.s { if string(s) != tt.s {
t.Errorf(`Join(Split(%q, %q, %d), %q) = %q`, tt.s, tt.sep, tt.n, tt.sep, s); t.Errorf(`Join(Split(%q, %q, %d), %q) = %q`, tt.s, tt.sep, tt.n, tt.sep, s);
} }
...@@ -154,8 +154,8 @@ var copytests = []CopyTest { ...@@ -154,8 +154,8 @@ var copytests = []CopyTest {
func TestCopy(t *testing.T) { func TestCopy(t *testing.T) {
for i := 0; i < len(copytests); i++ { for i := 0; i < len(copytests); i++ {
tt := copytests[i]; tt := copytests[i];
dst := io.StringBytes(tt.a); dst := strings.Bytes(tt.a);
n := Copy(dst, io.StringBytes(tt.b)); n := Copy(dst, strings.Bytes(tt.b));
result := string(dst); result := string(dst);
if result != tt.res || n != tt.n { if result != tt.res || n != tt.n {
t.Errorf(`Copy(%q, %q) = %d, %q; want %d, %q`, tt.a, tt.b, n, result, tt.n, tt.res); t.Errorf(`Copy(%q, %q) = %d, %q; want %d, %q`, tt.a, tt.b, n, result, tt.n, tt.res);
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package gzip package gzip
import ( import (
"bytes";
"compress/gzip"; "compress/gzip";
"fmt"; "fmt";
"io"; "io";
...@@ -265,7 +266,7 @@ var gzipTests = []gzipTest { ...@@ -265,7 +266,7 @@ var gzipTests = []gzipTest {
} }
func TestGzipInflater(t *testing.T) { func TestGzipInflater(t *testing.T) {
b := new(io.ByteBuffer); b := new(bytes.Buffer);
for i, tt := range gzipTests { for i, tt := range gzipTests {
in := io.NewByteReader(tt.gzip); in := io.NewByteReader(tt.gzip);
gzip, err := NewGzipInflater(in); gzip, err := NewGzipInflater(in);
......
...@@ -13,6 +13,7 @@ package block ...@@ -13,6 +13,7 @@ package block
// gobuild: $GC ecb_aes_test.go // gobuild: $GC ecb_aes_test.go
import ( import (
"bytes";
"crypto/aes"; "crypto/aes";
"crypto/block"; "crypto/block";
"io"; "io";
...@@ -80,7 +81,7 @@ func TestCBC_AES(t *testing.T) { ...@@ -80,7 +81,7 @@ func TestCBC_AES(t *testing.T) {
continue; continue;
} }
var crypt io.ByteBuffer; var crypt bytes.Buffer;
w := NewCBCEncrypter(c, tt.iv, &crypt); w := NewCBCEncrypter(c, tt.iv, &crypt);
var r io.Reader = io.NewByteReader(tt.in); var r io.Reader = io.NewByteReader(tt.in);
n, err := io.Copy(r, w); n, err := io.Copy(r, w);
...@@ -90,7 +91,7 @@ func TestCBC_AES(t *testing.T) { ...@@ -90,7 +91,7 @@ func TestCBC_AES(t *testing.T) {
t.Errorf("%s: CBCEncrypter\nhave %x\nwant %x", test, d, tt.out); t.Errorf("%s: CBCEncrypter\nhave %x\nwant %x", test, d, tt.out);
} }
var plain io.ByteBuffer; var plain bytes.Buffer;
r = NewCBCDecrypter(c, tt.iv, io.NewByteReader(tt.out)); r = NewCBCDecrypter(c, tt.iv, io.NewByteReader(tt.out));
w = &plain; w = &plain;
n, err = io.Copy(r, w); n, err = io.Copy(r, w);
......
...@@ -13,6 +13,7 @@ package block ...@@ -13,6 +13,7 @@ package block
// gobuild: $GC ecb_aes_test.go // gobuild: $GC ecb_aes_test.go
import ( import (
"bytes";
"crypto/aes"; "crypto/aes";
"crypto/block"; "crypto/block";
"io"; "io";
...@@ -289,7 +290,7 @@ func TestCFB_AES(t *testing.T) { ...@@ -289,7 +290,7 @@ func TestCFB_AES(t *testing.T) {
continue; continue;
} }
var crypt io.ByteBuffer; var crypt bytes.Buffer;
w := NewCFBEncrypter(c, tt.s, tt.iv, &crypt); w := NewCFBEncrypter(c, tt.s, tt.iv, &crypt);
var r io.Reader = io.NewByteReader(tt.in); var r io.Reader = io.NewByteReader(tt.in);
n, err := io.Copy(r, w); n, err := io.Copy(r, w);
...@@ -299,7 +300,7 @@ func TestCFB_AES(t *testing.T) { ...@@ -299,7 +300,7 @@ func TestCFB_AES(t *testing.T) {
t.Errorf("%s: CFBEncrypter\nhave %x\nwant %x", test, d, tt.out); t.Errorf("%s: CFBEncrypter\nhave %x\nwant %x", test, d, tt.out);
} }
var plain io.ByteBuffer; var plain bytes.Buffer;
r = NewCFBDecrypter(c, tt.s, tt.iv, io.NewByteReader(tt.out)); r = NewCFBDecrypter(c, tt.s, tt.iv, io.NewByteReader(tt.out));
w = &plain; w = &plain;
n, err = io.Copy(r, w); n, err = io.Copy(r, w);
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
package block package block
import ( import (
"bytes";
"crypto/aes"; "crypto/aes";
"crypto/block"; "crypto/block";
"io"; "io";
...@@ -83,7 +84,7 @@ func TestCTR_AES(t *testing.T) { ...@@ -83,7 +84,7 @@ func TestCTR_AES(t *testing.T) {
} }
for j := 0; j <= 5; j += 5 { for j := 0; j <= 5; j += 5 {
var crypt io.ByteBuffer; var crypt bytes.Buffer;
in := tt.in[0:len(tt.in) - j]; in := tt.in[0:len(tt.in) - j];
w := block.NewCTRWriter(c, tt.iv, &crypt); w := block.NewCTRWriter(c, tt.iv, &crypt);
var r io.Reader = io.NewByteReader(in); var r io.Reader = io.NewByteReader(in);
...@@ -96,7 +97,7 @@ func TestCTR_AES(t *testing.T) { ...@@ -96,7 +97,7 @@ func TestCTR_AES(t *testing.T) {
} }
for j := 0; j <= 7; j += 7 { for j := 0; j <= 7; j += 7 {
var plain io.ByteBuffer; var plain bytes.Buffer;
out := tt.out[0:len(tt.out) - j]; out := tt.out[0:len(tt.out) - j];
r := block.NewCTRReader(c, tt.iv, io.NewByteReader(out)); r := block.NewCTRReader(c, tt.iv, io.NewByteReader(out));
w := &plain; w := &plain;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package block package block
import ( import (
"bytes";
"crypto/aes"; "crypto/aes";
"crypto/block"; "crypto/block";
"fmt"; "fmt";
...@@ -195,7 +196,7 @@ var eaxAESTests = []eaxAESTest { ...@@ -195,7 +196,7 @@ var eaxAESTests = []eaxAESTest {
} }
func TestEAXEncrypt_AES(t *testing.T) { func TestEAXEncrypt_AES(t *testing.T) {
b := new(io.ByteBuffer); b := new(bytes.Buffer);
for i, tt := range eaxAESTests { for i, tt := range eaxAESTests {
test := fmt.Sprintf("test %d", i); test := fmt.Sprintf("test %d", i);
c, err := aes.NewCipher(tt.key); c, err := aes.NewCipher(tt.key);
...@@ -219,7 +220,7 @@ func TestEAXEncrypt_AES(t *testing.T) { ...@@ -219,7 +220,7 @@ func TestEAXEncrypt_AES(t *testing.T) {
} }
func TestEAXDecrypt_AES(t *testing.T) { func TestEAXDecrypt_AES(t *testing.T) {
b := new(io.ByteBuffer); b := new(bytes.Buffer);
for i, tt := range eaxAESTests { for i, tt := range eaxAESTests {
test := fmt.Sprintf("test %d", i); test := fmt.Sprintf("test %d", i);
c, err := aes.NewCipher(tt.key); c, err := aes.NewCipher(tt.key);
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
package block package block
import ( import (
"bytes";
"crypto/aes"; "crypto/aes";
"crypto/block"; "crypto/block";
"io"; "io";
...@@ -109,7 +110,7 @@ func TestECB_AES(t *testing.T) { ...@@ -109,7 +110,7 @@ func TestECB_AES(t *testing.T) {
continue; continue;
} }
var crypt io.ByteBuffer; var crypt bytes.Buffer;
w := NewECBEncrypter(c, &crypt); w := NewECBEncrypter(c, &crypt);
var r io.Reader = io.NewByteReader(tt.in); var r io.Reader = io.NewByteReader(tt.in);
n, err := io.Copy(r, w); n, err := io.Copy(r, w);
...@@ -119,7 +120,7 @@ func TestECB_AES(t *testing.T) { ...@@ -119,7 +120,7 @@ func TestECB_AES(t *testing.T) {
t.Errorf("%s: ECBReader\nhave %x\nwant %x", test, d, tt.out); t.Errorf("%s: ECBReader\nhave %x\nwant %x", test, d, tt.out);
} }
var plain io.ByteBuffer; var plain bytes.Buffer;
r = NewECBDecrypter(c, io.NewByteReader(tt.out)); r = NewECBDecrypter(c, io.NewByteReader(tt.out));
w = &plain; w = &plain;
n, err = io.Copy(r, w); n, err = io.Copy(r, w);
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package block package block
import ( import (
"bytes";
"crypto/block"; "crypto/block";
"fmt"; "fmt";
"io"; "io";
...@@ -55,7 +56,7 @@ func TestECBEncrypter(t *testing.T) { ...@@ -55,7 +56,7 @@ func TestECBEncrypter(t *testing.T) {
for i := 0; i < len(plain); i++ { for i := 0; i < len(plain); i++ {
plain[i] = byte(i); plain[i] = byte(i);
} }
b := new(io.ByteBuffer); b := new(bytes.Buffer);
for block := 1; block <= 64; block *= 2 { for block := 1; block <= 64; block *= 2 {
// compute encrypted version // compute encrypted version
delta := byte(0); delta := byte(0);
...@@ -119,7 +120,7 @@ func testECBDecrypter(t *testing.T, maxio int) { ...@@ -119,7 +120,7 @@ func testECBDecrypter(t *testing.T, maxio int) {
for i := 0; i < len(plain); i++ { for i := 0; i < len(plain); i++ {
plain[i] = byte(255 - i); plain[i] = byte(255 - i);
} }
b := new(io.ByteBuffer); b := new(bytes.Buffer);
for block := 1; block <= 64 && block <= maxio; block *= 2 { for block := 1; block <= 64 && block <= maxio; block *= 2 {
// compute encrypted version // compute encrypted version
delta := byte(0); delta := byte(0);
......
...@@ -13,6 +13,7 @@ package block ...@@ -13,6 +13,7 @@ package block
// gotest: $GC ecb_aes_test.go // gotest: $GC ecb_aes_test.go
import ( import (
"bytes";
"crypto/aes"; "crypto/aes";
"crypto/block"; "crypto/block";
"io"; "io";
...@@ -81,7 +82,7 @@ func TestOFB_AES(t *testing.T) { ...@@ -81,7 +82,7 @@ func TestOFB_AES(t *testing.T) {
} }
for j := 0; j <= 5; j += 5 { for j := 0; j <= 5; j += 5 {
var crypt io.ByteBuffer; var crypt bytes.Buffer;
in := tt.in[0:len(tt.in) - j]; in := tt.in[0:len(tt.in) - j];
w := NewOFBWriter(c, tt.iv, &crypt); w := NewOFBWriter(c, tt.iv, &crypt);
var r io.Reader = io.NewByteReader(in); var r io.Reader = io.NewByteReader(in);
...@@ -94,7 +95,7 @@ func TestOFB_AES(t *testing.T) { ...@@ -94,7 +95,7 @@ func TestOFB_AES(t *testing.T) {
} }
for j := 0; j <= 7; j += 7 { for j := 0; j <= 7; j += 7 {
var plain io.ByteBuffer; var plain bytes.Buffer;
out := tt.out[0:len(tt.out) - j]; out := tt.out[0:len(tt.out) - j];
r := NewOFBReader(c, tt.iv, io.NewByteReader(out)); r := NewOFBReader(c, tt.iv, io.NewByteReader(out));
w := &plain; w := &plain;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package block package block
import ( import (
"bytes";
"crypto/block"; "crypto/block";
"fmt"; "fmt";
"io"; "io";
...@@ -38,7 +39,7 @@ func testXorWriter(t *testing.T, maxio int) { ...@@ -38,7 +39,7 @@ func testXorWriter(t *testing.T, maxio int) {
for i := 0; i < len(plain); i++ { for i := 0; i < len(plain); i++ {
plain[i] = byte(i); plain[i] = byte(i);
} }
b := new(io.ByteBuffer); b := new(bytes.Buffer);
for block := 1; block <= 64 && block <= maxio; block *= 2 { for block := 1; block <= 64 && block <= maxio; block *= 2 {
// compute encrypted version // compute encrypted version
n := byte(0); n := byte(0);
...@@ -106,7 +107,7 @@ func testXorReader(t *testing.T, maxio int) { ...@@ -106,7 +107,7 @@ func testXorReader(t *testing.T, maxio int) {
for i := 0; i < len(plain); i++ { for i := 0; i < len(plain); i++ {
plain[i] = byte(255 - i); plain[i] = byte(255 - i);
} }
b := new(io.ByteBuffer); b := new(bytes.Buffer);
for block := 1; block <= 64 && block <= maxio; block *= 2 { for block := 1; block <= 64 && block <= maxio; block *= 2 {
// compute encrypted version // compute encrypted version
n := byte(0); n := byte(0);
......
...@@ -9,8 +9,8 @@ package hmac ...@@ -9,8 +9,8 @@ package hmac
import ( import (
"hash"; "hash";
"crypto/hmac"; "crypto/hmac";
"io";
"fmt"; "fmt";
"strings";
"testing"; "testing";
) )
...@@ -36,7 +36,7 @@ var hmacTests = []hmacTest { ...@@ -36,7 +36,7 @@ var hmacTests = []hmacTest {
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
}, },
io.StringBytes("Sample #1"), strings.Bytes("Sample #1"),
"4f4ca3d5d68ba7cc0a1208c9c61e9c5da0403c0a", "4f4ca3d5d68ba7cc0a1208c9c61e9c5da0403c0a",
}, },
hmacTest { hmacTest {
...@@ -46,7 +46,7 @@ var hmacTests = []hmacTest { ...@@ -46,7 +46,7 @@ var hmacTests = []hmacTest {
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0x40, 0x41, 0x42, 0x43, 0x40, 0x41, 0x42, 0x43,
}, },
io.StringBytes("Sample #2"), strings.Bytes("Sample #2"),
"0922d3405faa3d194f82a45830737d5cc6c75d24", "0922d3405faa3d194f82a45830737d5cc6c75d24",
}, },
hmacTest { hmacTest {
...@@ -66,15 +66,15 @@ var hmacTests = []hmacTest { ...@@ -66,15 +66,15 @@ var hmacTests = []hmacTest {
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
0xb0, 0xb1, 0xb2, 0xb3, 0xb0, 0xb1, 0xb2, 0xb3,
}, },
io.StringBytes("Sample #3"), strings.Bytes("Sample #3"),
"bcf41eab8bb2d802f3d05caf7cb092ecf8d1a3aa", "bcf41eab8bb2d802f3d05caf7cb092ecf8d1a3aa",
}, },
// Test from Plan 9. // Test from Plan 9.
hmacTest { hmacTest {
NewMD5, NewMD5,
io.StringBytes("Jefe"), strings.Bytes("Jefe"),
io.StringBytes("what do ya want for nothing?"), strings.Bytes("what do ya want for nothing?"),
"750c783e6ab0b503eaa86e310a5db738", "750c783e6ab0b503eaa86e310a5db738",
} }
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
A format specification is a set of package declarations and format rules: A format specification is a set of package declarations and format rules:
Format = [ Entry { ";" Entry } [ ";" ] ] . Format = [ Entry { ";" Entry } [ ";" ] ] .
Entry = PackageDecl | FormatRule . Entry = PackageDecl | FormatRule .
(The syntax of a format specification is presented in the same EBNF (The syntax of a format specification is presented in the same EBNF
notation as used in the Go language specification. The syntax of white notation as used in the Go language specification. The syntax of white
...@@ -111,7 +111,7 @@ ...@@ -111,7 +111,7 @@
The following example shows a complete format specification for a The following example shows a complete format specification for a
struct 'myPackage.Point'. Assume the package struct 'myPackage.Point'. Assume the package
package myPackage // in directory myDir/myPackage package myPackage // in directory myDir/myPackage
type Point struct { type Point struct {
name string; name string;
...@@ -155,7 +155,7 @@ ...@@ -155,7 +155,7 @@
Repetition = "{" Body [ "/" Separator ] "}" . Repetition = "{" Body [ "/" Separator ] "}" .
Separator = Expression . Separator = Expression .
A repeated expression is evaluated as follows: The body is evaluated A repeated expression is evaluated as follows: The body is evaluated
repeatedly and its results are concatenated until the body evaluates repeatedly and its results are concatenated until the body evaluates
to nil. The result of the repetition is the (possibly empty) concatenation, to nil. The result of the repetition is the (possibly empty) concatenation,
...@@ -202,6 +202,7 @@ ...@@ -202,6 +202,7 @@
package datafmt package datafmt
import ( import (
"bytes";
"container/vector"; "container/vector";
"fmt"; "fmt";
"go/token"; "go/token";
...@@ -306,8 +307,8 @@ type State struct { ...@@ -306,8 +307,8 @@ type State struct {
env Environment; // user-supplied environment env Environment; // user-supplied environment
errors chan os.Error; // not chan *Error (errors <- nil would be wrong!) errors chan os.Error; // not chan *Error (errors <- nil would be wrong!)
hasOutput bool; // true after the first literal has been written hasOutput bool; // true after the first literal has been written
indent io.ByteBuffer; // current indentation indent bytes.Buffer; // current indentation
output io.ByteBuffer; // format output output bytes.Buffer; // format output
linePos token.Position; // position of line beginning (Column == 0) linePos token.Position; // position of line beginning (Column == 0)
default_ expr; // possibly nil default_ expr; // possibly nil
separator expr; // possibly nil separator expr; // possibly nil
...@@ -418,7 +419,7 @@ func getField(val reflect.Value, fieldname string) (reflect.Value, int) { ...@@ -418,7 +419,7 @@ func getField(val reflect.Value, fieldname string) (reflect.Value, int) {
if val.Kind() != reflect.StructKind { if val.Kind() != reflect.StructKind {
return nil, 0; return nil, 0;
} }
sval, styp := val.(reflect.StructValue), val.Type().(reflect.StructType); sval, styp := val.(reflect.StructValue), val.Type().(reflect.StructType);
// look for field at the top level // look for field at the top level
...@@ -450,7 +451,7 @@ func getField(val reflect.Value, fieldname string) (reflect.Value, int) { ...@@ -450,7 +451,7 @@ func getField(val reflect.Value, fieldname string) (reflect.Value, int) {
} }
} }
} }
return field, level + 1; return field, level + 1;
} }
...@@ -668,7 +669,7 @@ func (s *State) eval(fexpr expr, value reflect.Value, index int) bool { ...@@ -668,7 +669,7 @@ func (s *State) eval(fexpr expr, value reflect.Value, index int) bool {
s.restore(mark); s.restore(mark);
b = false; b = false;
} }
// reset indentation // reset indentation
s.indent.Truncate(indentLen); s.indent.Truncate(indentLen);
return b; return b;
...@@ -780,7 +781,7 @@ func (f Format) Print(args ...) (int, os.Error) { ...@@ -780,7 +781,7 @@ func (f Format) Print(args ...) (int, os.Error) {
// partially formatted result followed by an error message. // partially formatted result followed by an error message.
// //
func (f Format) Sprint(args ...) string { func (f Format) Sprint(args ...) string {
var buf io.ByteBuffer; var buf bytes.Buffer;
n, err := f.Fprint(&buf, nil, args); n, err := f.Fprint(&buf, nil, args);
if err != nil { if err != nil {
fmt.Fprintf(&buf, "--- Sprint(%s) failed: %v", fmt.Sprint(args), err); fmt.Fprintf(&buf, "--- Sprint(%s) failed: %v", fmt.Sprint(args), err);
......
...@@ -7,14 +7,14 @@ package datafmt ...@@ -7,14 +7,14 @@ package datafmt
import ( import (
"fmt"; "fmt";
"datafmt"; "datafmt";
"io";
"os"; "os";
"strings";
"testing"; "testing";
) )
func parse(t *testing.T, form string, fmap FormatterMap) Format { func parse(t *testing.T, form string, fmap FormatterMap) Format {
f, err := Parse(io.StringBytes(form), fmap); f, err := Parse(strings.Bytes(form), fmap);
if err != nil { if err != nil {
t.Errorf("Parse(%s): %v", form, err); t.Errorf("Parse(%s): %v", form, err);
return nil; return nil;
...@@ -55,7 +55,7 @@ func formatter(s *State, value interface{}, rule_name string) bool { ...@@ -55,7 +55,7 @@ func formatter(s *State, value interface{}, rule_name string) bool {
case "nil": case "nil":
return false; return false;
case "testing.T": case "testing.T":
s.Write(io.StringBytes("testing.T")); s.Write(strings.Bytes("testing.T"));
return true; return true;
} }
panic("unreachable"); panic("unreachable");
...@@ -115,7 +115,7 @@ func TestBasicTypes(t *testing.T) { ...@@ -115,7 +115,7 @@ func TestBasicTypes(t *testing.T) {
check(t, ``, ``); check(t, ``, ``);
check(t, `bool=":%v"`, `:true:false`, true, false); check(t, `bool=":%v"`, `:true:false`, true, false);
check(t, `int="%b %d %o 0x%x"`, `101010 42 52 0x2a`, 42); check(t, `int="%b %d %o 0x%x"`, `101010 42 52 0x2a`, 42);
check(t, `int="%"`, `%`, 42); check(t, `int="%"`, `%`, 42);
check(t, `int="%%"`, `%`, 42); check(t, `int="%%"`, `%`, 42);
check(t, `int="**%%**"`, `**%**`, 42); check(t, `int="**%%**"`, `**%**`, 42);
...@@ -259,13 +259,13 @@ const F2a = ...@@ -259,13 +259,13 @@ const F2a =
`string = "%s";` `string = "%s";`
`ptr = *;` `ptr = *;`
`datafmt.T2 = s ["-" p "-"];` `datafmt.T2 = s ["-" p "-"];`
const F2b = const F2b =
F1 + F1 +
`string = "%s";` `string = "%s";`
`ptr = *;` `ptr = *;`
`datafmt.T2 = s ("-" p "-" | "empty");`; `datafmt.T2 = s ("-" p "-" | "empty");`;
func TestStruct2(t *testing.T) { func TestStruct2(t *testing.T) {
check(t, F2a, "foo", T2{"foo", nil}); check(t, F2a, "foo", T2{"foo", nil});
check(t, F2a, "bar-<17>-", T2{"bar", &T1{17}}); check(t, F2a, "bar-<17>-", T2{"bar", &T1{17}});
...@@ -366,7 +366,7 @@ func TestStructPoint(t *testing.T) { ...@@ -366,7 +366,7 @@ func TestStructPoint(t *testing.T) {
const FSlice = const FSlice =
`int = "%b";` `int = "%b";`
`array = { * / ", " }` `array = { * / ", " }`
func TestSlice(t *testing.T) { func TestSlice(t *testing.T) {
check(t, FSlice, "10, 11, 101, 111", []int{2, 3, 5, 7}); check(t, FSlice, "10, 11, 101, 111", []int{2, 3, 5, 7});
} }
......
...@@ -10,7 +10,6 @@ import ( ...@@ -10,7 +10,6 @@ import (
"fmt"; "fmt";
"go/scanner"; "go/scanner";
"go/token"; "go/token";
"io";
"os"; "os";
"strconv"; "strconv";
"strings"; "strings";
...@@ -194,7 +193,7 @@ func (p *parser) parseString() string { ...@@ -194,7 +193,7 @@ func (p *parser) parseString() string {
func (p *parser) parseLiteral() literal { func (p *parser) parseLiteral() literal {
s := io.StringBytes(p.parseString()); s := strings.Bytes(p.parseString());
// A string literal may contain %-format specifiers. To simplify // A string literal may contain %-format specifiers. To simplify
// and speed up printing of the literal, split it into segments // and speed up printing of the literal, split it into segments
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
package exvar package exvar
import ( import (
"bytes";
"fmt"; "fmt";
"http"; "http";
"io"; "io";
...@@ -52,7 +53,7 @@ type KeyValue struct { ...@@ -52,7 +53,7 @@ type KeyValue struct {
func (v *Map) String() string { func (v *Map) String() string {
v.mu.Lock(); v.mu.Lock();
defer v.mu.Unlock(); defer v.mu.Unlock();
b := new(io.ByteBuffer); b := new(bytes.Buffer);
fmt.Fprintf(b, "{"); fmt.Fprintf(b, "{");
first := true; first := true;
for key, val := range v.m { for key, val := range v.m {
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"fmt"; "fmt";
"io"; "io";
"math"; "math";
"strings";
"testing"; "testing";
) )
...@@ -40,12 +41,12 @@ var fmttests = []fmtTest{ ...@@ -40,12 +41,12 @@ var fmttests = []fmtTest{
fmtTest{ "%q", "abc", `"abc"` }, fmtTest{ "%q", "abc", `"abc"` },
// basic bytes // basic bytes
fmtTest{ "%s", io.StringBytes("abc"), "abc" }, fmtTest{ "%s", strings.Bytes("abc"), "abc" },
fmtTest{ "%x", io.StringBytes("abc"), "616263" }, fmtTest{ "%x", strings.Bytes("abc"), "616263" },
fmtTest{ "% x", io.StringBytes("abc"), "61 62 63" }, fmtTest{ "% x", strings.Bytes("abc"), "61 62 63" },
fmtTest{ "%x", io.StringBytes("xyz"), "78797a" }, fmtTest{ "%x", strings.Bytes("xyz"), "78797a" },
fmtTest{ "%X", io.StringBytes("xyz"), "78797A" }, fmtTest{ "%X", strings.Bytes("xyz"), "78797A" },
fmtTest{ "%q", io.StringBytes("abc"), `"abc"` }, fmtTest{ "%q", strings.Bytes("abc"), `"abc"` },
// escaped strings // escaped strings
fmtTest{ "%#q", `abc`, "`abc`" }, fmtTest{ "%#q", `abc`, "`abc`" },
......
...@@ -142,8 +142,8 @@ func split(text []byte) [][]byte { ...@@ -142,8 +142,8 @@ func split(text []byte) [][]byte {
var ( var (
ldquo = io.StringBytes("&ldquo;"); ldquo = strings.Bytes("&ldquo;");
rdquo = io.StringBytes("&rdquo;"); rdquo = strings.Bytes("&rdquo;");
) )
// Escape comment text for HTML. // Escape comment text for HTML.
...@@ -168,10 +168,10 @@ func commentEscape(w io.Writer, s []byte) { ...@@ -168,10 +168,10 @@ func commentEscape(w io.Writer, s []byte) {
var ( var (
html_p = io.StringBytes("<p>\n"); html_p = strings.Bytes("<p>\n");
html_endp = io.StringBytes("</p>\n"); html_endp = strings.Bytes("</p>\n");
html_pre = io.StringBytes("<pre>"); html_pre = strings.Bytes("<pre>");
html_endpre = io.StringBytes("</pre>\n"); html_endpre = strings.Bytes("</pre>\n");
) )
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
package parser package parser
import ( import (
"bytes";
"container/vector"; "container/vector";
"fmt"; "fmt";
"go/ast"; "go/ast";
...@@ -17,6 +18,7 @@ import ( ...@@ -17,6 +18,7 @@ import (
"go/token"; "go/token";
"io"; "io";
"os"; "os";
"strings";
) )
...@@ -1964,16 +1966,16 @@ func readSource(src interface{}) ([]byte, os.Error) { ...@@ -1964,16 +1966,16 @@ func readSource(src interface{}) ([]byte, os.Error) {
if src != nil { if src != nil {
switch s := src.(type) { switch s := src.(type) {
case string: case string:
return io.StringBytes(s), nil; return strings.Bytes(s), nil;
case []byte: case []byte:
return s, nil; return s, nil;
case *io.ByteBuffer: case *bytes.Buffer:
// is io.Read, but src is already available in []byte form // is io.Reader, but src is already available in []byte form
if s != nil { if s != nil {
return s.Data(), nil; return s.Data(), nil;
} }
case io.Reader: case io.Reader:
var buf io.ByteBuffer; var buf bytes.Buffer;
n, err := io.Copy(s, &buf); n, err := io.Copy(s, &buf);
if err != nil { if err != nil {
return nil, err; return nil, err;
...@@ -1997,7 +1999,7 @@ func scannerMode(mode uint) uint { ...@@ -1997,7 +1999,7 @@ func scannerMode(mode uint) uint {
// Parse parses a Go program. // Parse parses a Go program.
// //
// The program source src may be provided in a variety of formats. At the // The program source src may be provided in a variety of formats. At the
// moment the following types are supported: string, []byte, and io.Read. // moment the following types are supported: string, []byte, and io.Reader.
// The mode parameter controls the amount of source text parsed and other // The mode parameter controls the amount of source text parsed and other
// optional parser functionality. // optional parser functionality.
// //
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"io"; "io";
"os"; "os";
"reflect"; "reflect";
"strings";
) )
...@@ -166,9 +167,9 @@ func (p *printer) print(args ...) { ...@@ -166,9 +167,9 @@ func (p *printer) print(args ...) {
case []byte: case []byte:
p.write(x); p.write(x);
case string: case string:
p.write(io.StringBytes(x)); p.write(strings.Bytes(x));
case token.Token: case token.Token:
p.write(io.StringBytes(x.String())); p.write(strings.Bytes(x.String()));
case token.Position: case token.Position:
// set current position // set current position
p.pos = x; p.pos = x;
......
...@@ -7,7 +7,7 @@ package scanner ...@@ -7,7 +7,7 @@ package scanner
import ( import (
"go/scanner"; "go/scanner";
"go/token"; "go/token";
"io"; "strings";
"testing"; "testing";
) )
...@@ -190,7 +190,7 @@ func TestScan(t *testing.T) { ...@@ -190,7 +190,7 @@ func TestScan(t *testing.T) {
// verify scan // verify scan
index := 0; index := 0;
eloc := token.Position{0, 1, 1}; eloc := token.Position{0, 1, 1};
nerrors := scanner.Tokenize(io.StringBytes(src), &TestErrorHandler{t}, scanner.ScanComments, nerrors := scanner.Tokenize(strings.Bytes(src), &TestErrorHandler{t}, scanner.ScanComments,
func (pos token.Position, tok token.Token, litb []byte) bool { func (pos token.Position, tok token.Token, litb []byte) bool {
e := elt{token.EOF, "", special}; e := elt{token.EOF, "", special};
if index < len(tokens) { if index < len(tokens) {
...@@ -236,7 +236,7 @@ func TestInit(t *testing.T) { ...@@ -236,7 +236,7 @@ func TestInit(t *testing.T) {
var s scanner.Scanner; var s scanner.Scanner;
// 1st init // 1st init
s.Init(io.StringBytes("if true { }"), nil, 0); s.Init(strings.Bytes("if true { }"), nil, 0);
s.Scan(); // if s.Scan(); // if
s.Scan(); // true s.Scan(); // true
pos, tok, lit := s.Scan(); // { pos, tok, lit := s.Scan(); // {
...@@ -245,7 +245,7 @@ func TestInit(t *testing.T) { ...@@ -245,7 +245,7 @@ func TestInit(t *testing.T) {
} }
// 2nd init // 2nd init
s.Init(io.StringBytes("go true { ]"), nil, 0); s.Init(strings.Bytes("go true { ]"), nil, 0);
pos, tok, lit = s.Scan(); // go pos, tok, lit = s.Scan(); // go
if tok != token.GO { if tok != token.GO {
t.Errorf("bad token: got %s, expected %s", tok.String(), token.GO); t.Errorf("bad token: got %s, expected %s", tok.String(), token.GO);
...@@ -261,7 +261,7 @@ func TestIllegalChars(t *testing.T) { ...@@ -261,7 +261,7 @@ func TestIllegalChars(t *testing.T) {
var s scanner.Scanner; var s scanner.Scanner;
const src = "*?*$*@*"; const src = "*?*$*@*";
s.Init(io.StringBytes(src), &TestErrorHandler{t}, scanner.AllowIllegalChars); s.Init(strings.Bytes(src), &TestErrorHandler{t}, scanner.AllowIllegalChars);
for offs, ch := range src { for offs, ch := range src {
pos, tok, lit := s.Scan(); pos, tok, lit := s.Scan();
if pos.Offset != offs { if pos.Offset != offs {
......
...@@ -7,7 +7,6 @@ package gob ...@@ -7,7 +7,6 @@ package gob
import ( import (
"bytes"; "bytes";
"gob"; "gob";
"io";
"os"; "os";
"testing"; "testing";
) )
...@@ -36,7 +35,7 @@ var encodeT = []EncodeT { ...@@ -36,7 +35,7 @@ var encodeT = []EncodeT {
// Test basic encode/decode routines for unsigned integers // Test basic encode/decode routines for unsigned integers
func TestUintCodec(t *testing.T) { func TestUintCodec(t *testing.T) {
var b = new(io.ByteBuffer); var b = new(bytes.Buffer);
for i, tt := range encodeT { for i, tt := range encodeT {
b.Reset(); b.Reset();
err := EncodeUint(b, tt.x); err := EncodeUint(b, tt.x);
...@@ -67,7 +66,7 @@ func TestUintCodec(t *testing.T) { ...@@ -67,7 +66,7 @@ func TestUintCodec(t *testing.T) {
} }
func verifyInt(i int64, t *testing.T) { func verifyInt(i int64, t *testing.T) {
var b = new(io.ByteBuffer); var b = new(bytes.Buffer);
err := EncodeInt(b, i); err := EncodeInt(b, i);
if err != nil { if err != nil {
t.Error("EncodeInt:", i, err) t.Error("EncodeInt:", i, err)
...@@ -83,7 +82,7 @@ func verifyInt(i int64, t *testing.T) { ...@@ -83,7 +82,7 @@ func verifyInt(i int64, t *testing.T) {
// Test basic encode/decode routines for signed integers // Test basic encode/decode routines for signed integers
func TestIntCodec(t *testing.T) { func TestIntCodec(t *testing.T) {
var b = new(io.ByteBuffer); var b = new(bytes.Buffer);
for u := uint64(0); ; u = (u+1) * 7 { for u := uint64(0); ; u = (u+1) * 7 {
// Do positive and negative values // Do positive and negative values
i := int64(u); i := int64(u);
......
...@@ -359,7 +359,7 @@ func CanonicalHeaderKey(s string) string { ...@@ -359,7 +359,7 @@ func CanonicalHeaderKey(s string) string {
// and upper case after each dash. // and upper case after each dash.
// (Host, User-Agent, If-Modified-Since). // (Host, User-Agent, If-Modified-Since).
// HTTP headers are ASCII only, so no Unicode issues. // HTTP headers are ASCII only, so no Unicode issues.
a := io.StringBytes(s); a := strings.Bytes(s);
upper := true; upper := true;
for i,v := range a { for i,v := range a {
if upper && 'a' <= v && v <= 'z' { if upper && 'a' <= v && v <= 'z' {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package main package main
import ( import (
"bytes";
"bufio"; "bufio";
"exvar"; "exvar";
"flag"; "flag";
...@@ -41,7 +42,7 @@ func (ctr *Counter) ServeHTTP(c *http.Conn, req *http.Request) { ...@@ -41,7 +42,7 @@ func (ctr *Counter) ServeHTTP(c *http.Conn, req *http.Request) {
case "GET": case "GET":
ctr.n++; ctr.n++;
case "POST": case "POST":
buf := new(io.ByteBuffer); buf := new(bytes.Buffer);
io.Copy(req.Body, buf); io.Copy(req.Body, buf);
body := string(buf.Data()); body := string(buf.Data());
if n, err := strconv.Atoi(body); err != nil { if n, err := strconv.Atoi(body); err != nil {
......
...@@ -35,28 +35,22 @@ coverage: packages ...@@ -35,28 +35,22 @@ coverage: packages
O1=\ O1=\
io.$O\ io.$O\
pipe.$O\ pipe.$O\
xxx.$O\
O2=\ O2=\
bytebuffer.$O\
O3=\
utils.$O\ utils.$O\
phases: a1 a2 a3 phases: a1 a2
_obj$D/io.a: phases _obj$D/io.a: phases
a1: $(O1) a1: $(O1)
$(AR) grc _obj$D/io.a io.$O pipe.$O $(AR) grc _obj$D/io.a io.$O pipe.$O xxx.$O
rm -f $(O1) rm -f $(O1)
a2: $(O2) a2: $(O2)
$(AR) grc _obj$D/io.a bytebuffer.$O
rm -f $(O2)
a3: $(O3)
$(AR) grc _obj$D/io.a utils.$O $(AR) grc _obj$D/io.a utils.$O
rm -f $(O3) rm -f $(O2)
newpkg: clean newpkg: clean
...@@ -66,7 +60,6 @@ newpkg: clean ...@@ -66,7 +60,6 @@ newpkg: clean
$(O1): newpkg $(O1): newpkg
$(O2): a1 $(O2): a1
$(O3): a2 $(O3): a2
$(O4): a3
nuke: clean nuke: clean
rm -f $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/io.a rm -f $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/io.a
......
...@@ -12,6 +12,7 @@ package io ...@@ -12,6 +12,7 @@ package io
import ( import (
"bytes"; "bytes";
"os"; "os";
"strings";
) )
// Error represents an unexpected I/O behavior. // Error represents an unexpected I/O behavior.
...@@ -83,18 +84,9 @@ type ReadWriteCloser interface { ...@@ -83,18 +84,9 @@ type ReadWriteCloser interface {
Closer; Closer;
} }
// Convert a string to an array of bytes for easy marshaling.
func StringBytes(s string) []byte {
b := make([]byte, len(s));
for i := 0; i < len(s); i++ {
b[i] = s[i];
}
return b;
}
// WriteString writes the contents of the string s to w, which accepts an array of bytes. // WriteString writes the contents of the string s to w, which accepts an array of bytes.
func WriteString(w Writer, s string) (n int, err os.Error) { func WriteString(w Writer, s string) (n int, err os.Error) {
return w.Write(StringBytes(s)) return w.Write(strings.Bytes(s))
} }
// ReadAtLeast reads from r into buf until it has read at least min bytes. // ReadAtLeast reads from r into buf until it has read at least min bytes.
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"fmt"; "fmt";
"io"; "io";
"os"; "os";
"strings";
"testing"; "testing";
"time"; "time";
) )
...@@ -28,7 +29,7 @@ func TestPipe1(t *testing.T) { ...@@ -28,7 +29,7 @@ func TestPipe1(t *testing.T) {
c := make(chan int); c := make(chan int);
r, w := Pipe(); r, w := Pipe();
var buf = make([]byte, 64); var buf = make([]byte, 64);
go checkWrite(t, w, StringBytes("hello, world"), c); go checkWrite(t, w, strings.Bytes("hello, world"), c);
n, err := r.Read(buf); n, err := r.Read(buf);
if err != nil { if err != nil {
t.Errorf("read: %v", err); t.Errorf("read: %v", err);
......
...@@ -7,14 +7,15 @@ ...@@ -7,14 +7,15 @@
package io package io
import ( import (
"bytes";
"io"; "io";
"os"; "os";
) )
// ReadAll reads from r until an error or EOF and returns the data it read. // ReadAll reads from r until an error or EOF and returns the data it read.
func ReadAll(r Reader) ([]byte, os.Error) { func ReadAll(r Reader) ([]byte, os.Error) {
var buf ByteBuffer; var buf bytes.Buffer;
n, err := io.Copy(r, &buf); n, err := Copy(r, &buf);
return buf.Data(), err; return buf.Data(), err;
} }
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
package json package json
import ( import (
"bytes";
"fmt"; "fmt";
"io";
"math"; "math";
"strconv"; "strconv";
"strings"; "strings";
...@@ -127,7 +127,7 @@ func Unquote(s string) (t string, ok bool) { ...@@ -127,7 +127,7 @@ func Unquote(s string) (t string, ok bool) {
func Quote(s string) string { func Quote(s string) string {
chr := make([]byte, utf8.UTFMax); chr := make([]byte, utf8.UTFMax);
chr0 := chr[0:1]; chr0 := chr[0:1];
b := new(io.ByteBuffer); b := new(bytes.Buffer);
chr[0] = '"'; chr[0] = '"';
b.Write(chr0); b.Write(chr0);
for i := 0; i < len(s); i++ { for i := 0; i < len(s); i++ {
......
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"io"; "io";
"net"; "net";
"os"; "os";
"strings";
"syscall"; "syscall";
"testing"; "testing";
) )
...@@ -19,7 +20,7 @@ var ipv6 = flag.Bool("ipv6", false, "assume ipv6 tunnel is present") ...@@ -19,7 +20,7 @@ var ipv6 = flag.Bool("ipv6", false, "assume ipv6 tunnel is present")
// fd is already connected to the destination, port 80. // fd is already connected to the destination, port 80.
// Run an HTTP request to fetch the appropriate page. // Run an HTTP request to fetch the appropriate page.
func fetchGoogle(t *testing.T, fd net.Conn, network, addr string) { func fetchGoogle(t *testing.T, fd net.Conn, network, addr string) {
req := io.StringBytes("GET /intl/en/privacy.html HTTP/1.0\r\nHost: www.google.com\r\n\r\n"); req := strings.Bytes("GET /intl/en/privacy.html HTTP/1.0\r\nHost: www.google.com\r\n\r\n");
n, err := fd.Write(req); n, err := fd.Write(req);
buf := make([]byte, 1000); buf := make([]byte, 1000);
......
...@@ -52,7 +52,7 @@ func connect(t *testing.T, network, addr string) { ...@@ -52,7 +52,7 @@ func connect(t *testing.T, network, addr string) {
t.Fatalf("net.Dial(%q, %q, %q) = _, %v", network, "", addr, err); t.Fatalf("net.Dial(%q, %q, %q) = _, %v", network, "", addr, err);
} }
b := io.StringBytes("hello, world\n"); b := strings.Bytes("hello, world\n");
var b1 [100]byte; var b1 [100]byte;
n, errno := fd.Write(b); n, errno := fd.Write(b);
......
...@@ -5,9 +5,11 @@ ...@@ -5,9 +5,11 @@
package os package os
import ( import (
"bytes";
"fmt"; "fmt";
"io"; "io";
"os"; "os";
"strings";
"testing"; "testing";
) )
...@@ -322,7 +324,7 @@ func TestForkExec(t *testing.T) { ...@@ -322,7 +324,7 @@ func TestForkExec(t *testing.T) {
} }
w.Close(); w.Close();
var b io.ByteBuffer; var b bytes.Buffer;
io.Copy(r, &b); io.Copy(r, &b);
output := string(b.Data()); output := string(b.Data());
expect := "/\n"; expect := "/\n";
...@@ -443,7 +445,7 @@ func TestTruncate(t *testing.T) { ...@@ -443,7 +445,7 @@ func TestTruncate(t *testing.T) {
} }
checkSize(t, Path, 0); checkSize(t, Path, 0);
fd.Write(io.StringBytes("hello, world\n")); fd.Write(strings.Bytes("hello, world\n"));
checkSize(t, Path, 13); checkSize(t, Path, 13);
fd.Truncate(10); fd.Truncate(10);
checkSize(t, Path, 10); checkSize(t, Path, 10);
...@@ -451,7 +453,7 @@ func TestTruncate(t *testing.T) { ...@@ -451,7 +453,7 @@ func TestTruncate(t *testing.T) {
checkSize(t, Path, 1024); checkSize(t, Path, 1024);
fd.Truncate(0); fd.Truncate(0);
checkSize(t, Path, 0); checkSize(t, Path, 0);
fd.Write(io.StringBytes("surprise!")); fd.Write(strings.Bytes("surprise!"));
checkSize(t, Path, 13 + 9); // wrote at offset past where hello, world was. checkSize(t, Path, 13 + 9); // wrote at offset past where hello, world was.
fd.Close(); fd.Close();
Remove(Path); Remove(Path);
...@@ -600,7 +602,7 @@ func run(t *testing.T, cmd []string) string { ...@@ -600,7 +602,7 @@ func run(t *testing.T, cmd []string) string {
} }
w.Close(); w.Close();
var b io.ByteBuffer; var b bytes.Buffer;
io.Copy(r, &b); io.Copy(r, &b);
Wait(pid, 0); Wait(pid, 0);
output := string(b.Data()); output := string(b.Data());
...@@ -626,4 +628,3 @@ func TestHostname(t *testing.T) { ...@@ -626,4 +628,3 @@ func TestHostname(t *testing.T) {
t.Errorf("Hostname() = %q, want %q", hostname, want); t.Errorf("Hostname() = %q, want %q", hostname, want);
} }
} }
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
// slash-separated filename paths. // slash-separated filename paths.
package path package path
import "io" import "strings"
// Clean returns the shortest path name equivalent to path // Clean returns the shortest path name equivalent to path
// by purely lexical processing. It applies the following rules // by purely lexical processing. It applies the following rules
...@@ -38,7 +38,7 @@ func Clean(path string) string { ...@@ -38,7 +38,7 @@ func Clean(path string) string {
// writing to buf; w is index of next byte to write. // writing to buf; w is index of next byte to write.
// dotdot is index in buf where .. must stop, either because // dotdot is index in buf where .. must stop, either because
// it is the leading slash or it is a leading ../../.. prefix. // it is the leading slash or it is a leading ../../.. prefix.
buf := io.StringBytes(path); buf := strings.Bytes(path);
r, w, dotdot := 0, 0, 0; r, w, dotdot := 0, 0, 0;
if rooted { if rooted {
r, w, dotdot = 1, 1, 1; r, w, dotdot = 1, 1, 1;
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
package regexp package regexp
import ( import (
"bytes";
"container/vector"; "container/vector";
"io"; "io";
"os"; "os";
...@@ -770,7 +771,7 @@ func Match(pattern string, s string) (matched bool, error os.Error) { ...@@ -770,7 +771,7 @@ func Match(pattern string, s string) (matched bool, error os.Error) {
func (re *Regexp) ReplaceAll(src, repl string) string { func (re *Regexp) ReplaceAll(src, repl string) string {
lastMatchEnd := 0; // end position of the most recent match lastMatchEnd := 0; // end position of the most recent match
searchPos := 0; // position where we next look for a match searchPos := 0; // position where we next look for a match
buf := new(io.ByteBuffer); buf := new(bytes.Buffer);
for searchPos <= len(src) { for searchPos <= len(src) {
a := re.doExecute(src, searchPos); a := re.doExecute(src, searchPos);
if len(a) == 0 { if len(a) == 0 {
......
...@@ -130,6 +130,7 @@ sweepspan(MSpan *s) ...@@ -130,6 +130,7 @@ sweepspan(MSpan *s)
free(p); free(p);
break; break;
case RefSome: case RefSome:
//printf("gc-mem 1 %D\n", (uint64)s->npages<<PageShift);
s->gcref0 = RefNone; // set up for next mark phase s->gcref0 = RefNone; // set up for next mark phase
break; break;
} }
...@@ -159,6 +160,7 @@ sweepspan(MSpan *s) ...@@ -159,6 +160,7 @@ sweepspan(MSpan *s)
break; break;
} }
} }
//printf("gc-mem %d %d\n", s->ref, size);
} }
static void static void
...@@ -215,6 +217,7 @@ gc(int32 force) ...@@ -215,6 +217,7 @@ gc(int32 force)
if(gcpercent < 0) if(gcpercent < 0)
return; return;
//printf("gc...\n");
m->gcing = 1; m->gcing = 1;
semacquire(&gcsema); semacquire(&gcsema);
gosave(&g->sched); // update g's stack pointer for scanstack gosave(&g->sched); // update g's stack pointer for scanstack
......
...@@ -202,3 +202,13 @@ func TrimSpaceASCII(s string) string { ...@@ -202,3 +202,13 @@ func TrimSpaceASCII(s string) string {
} }
return s[start:end]; return s[start:end];
} }
// Bytes returns an array of the bytes in s.
func Bytes(s string) []byte {
b := make([]byte, len(s));
for i := 0; i < len(s); i++ {
b[i] = s[i];
}
return b;
}
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
package tabwriter package tabwriter
import ( import (
"bytes";
"container/vector"; "container/vector";
"io"; "io";
"os"; "os";
...@@ -69,7 +70,7 @@ type Writer struct { ...@@ -69,7 +70,7 @@ type Writer struct {
flags uint; flags uint;
// current state // current state
buf io.ByteBuffer; // collected text w/o tabs, newlines, or form feed chars buf bytes.Buffer; // collected text w/o tabs, newlines, or form feed chars
pos int; // buffer position up to which width of incomplete cell has been computed pos int; // buffer position up to which width of incomplete cell has been computed
cell cell; // current incomplete cell; cell.width is up to buf[pos] w/o ignored sections cell cell; // current incomplete cell; cell.width is up to buf[pos] w/o ignored sections
html_char byte; // terminating char of html tag/entity, or 0 ('>', ';', or 0) html_char byte; // terminating char of html tag/entity, or 0 ('>', ';', or 0)
...@@ -436,7 +437,7 @@ func (b *Writer) Write(buf []byte) (written int, err os.Error) { ...@@ -436,7 +437,7 @@ func (b *Writer) Write(buf []byte) (written int, err os.Error) {
} }
case '<', '&': case '<', '&':
// possibly an html tag/entity // possibly an html tag/entity
if b.flags & FilterHTML != 0 { if b.flags & FilterHTML != 0 {
// begin of tag/entity // begin of tag/entity
b.append(buf[i0 : i], true); b.append(buf[i0 : i], true);
......
...@@ -7,9 +7,11 @@ ...@@ -7,9 +7,11 @@
package template package template
import ( import (
"bytes";
"fmt"; "fmt";
"io"; "io";
"reflect"; "reflect";
"strings";
) )
// StringFormatter formats into the default string representation. // StringFormatter formats into the default string representation.
...@@ -21,9 +23,9 @@ func StringFormatter(w io.Writer, value interface{}, format string) { ...@@ -21,9 +23,9 @@ func StringFormatter(w io.Writer, value interface{}, format string) {
} }
var esc_amp = io.StringBytes("&amp;") var esc_amp = strings.Bytes("&amp;")
var esc_lt = io.StringBytes("&lt;") var esc_lt = strings.Bytes("&lt;")
var esc_gt = io.StringBytes("&gt;") var esc_gt = strings.Bytes("&gt;")
// HtmlEscape writes to w the properly escaped HTML equivalent // HtmlEscape writes to w the properly escaped HTML equivalent
// of the plain text data s. // of the plain text data s.
...@@ -48,7 +50,7 @@ func HtmlEscape(w io.Writer, s []byte) { ...@@ -48,7 +50,7 @@ func HtmlEscape(w io.Writer, s []byte) {
// HtmlFormatter formats arbitrary values for HTML // HtmlFormatter formats arbitrary values for HTML
func HtmlFormatter(w io.Writer, value interface{}, format string) { func HtmlFormatter(w io.Writer, value interface{}, format string) {
var b io.ByteBuffer; var b bytes.Buffer;
fmt.Fprint(&b, value); fmt.Fprint(&b, value);
HtmlEscape(w, b.Data()); HtmlEscape(w, b.Data());
} }
...@@ -762,7 +762,7 @@ func (t *Template) Parse(s string) os.Error { ...@@ -762,7 +762,7 @@ func (t *Template) Parse(s string) os.Error {
if !validDelim(t.ldelim) || !validDelim(t.rdelim) { if !validDelim(t.ldelim) || !validDelim(t.rdelim) {
return &Error{1, fmt.Sprintf("bad delimiter strings %q %q", t.ldelim, t.rdelim)} return &Error{1, fmt.Sprintf("bad delimiter strings %q %q", t.ldelim, t.rdelim)}
} }
t.buf = io.StringBytes(s); t.buf = strings.Bytes(s);
t.p = 0; t.p = 0;
t.linenum = 0; t.linenum = 0;
go func() { go func() {
...@@ -792,8 +792,8 @@ func (t *Template) Execute(data interface{}, wr io.Writer) os.Error { ...@@ -792,8 +792,8 @@ func (t *Template) Execute(data interface{}, wr io.Writer) os.Error {
// delimiters are very rarely invalid and Parse has the necessary // delimiters are very rarely invalid and Parse has the necessary
// error-handling interface already. // error-handling interface already.
func (t *Template) SetDelims(left, right string) { func (t *Template) SetDelims(left, right string) {
t.ldelim = io.StringBytes(left); t.ldelim = strings.Bytes(left);
t.rdelim = io.StringBytes(right); t.rdelim = strings.Bytes(right);
} }
// Parse creates a Template with default parameters (such as {} for // Parse creates a Template with default parameters (such as {} for
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package template package template
import ( import (
"bytes";
"fmt"; "fmt";
"io"; "io";
"os"; "os";
...@@ -236,7 +237,7 @@ func TestAll(t *testing.T) { ...@@ -236,7 +237,7 @@ func TestAll(t *testing.T) {
s.empty = []*T{ }; s.empty = []*T{ };
s.null = nil; s.null = nil;
var buf io.ByteBuffer; var buf bytes.Buffer;
for i, test := range tests { for i, test := range tests {
buf.Reset(); buf.Reset();
tmpl, err := Parse(test.in, formatters); tmpl, err := Parse(test.in, formatters);
...@@ -259,7 +260,7 @@ func TestStringDriverType(t *testing.T) { ...@@ -259,7 +260,7 @@ func TestStringDriverType(t *testing.T) {
if err != nil { if err != nil {
t.Error("unexpected parse error:", err) t.Error("unexpected parse error:", err)
} }
var b io.ByteBuffer; var b bytes.Buffer;
err = tmpl.Execute("hello", &b); err = tmpl.Execute("hello", &b);
if err != nil { if err != nil {
t.Error("unexpected execute error:", err) t.Error("unexpected execute error:", err)
...@@ -275,7 +276,7 @@ func TestTwice(t *testing.T) { ...@@ -275,7 +276,7 @@ func TestTwice(t *testing.T) {
if err != nil { if err != nil {
t.Error("unexpected parse error:", err) t.Error("unexpected parse error:", err)
} }
var b io.ByteBuffer; var b bytes.Buffer;
err = tmpl.Execute("hello", &b); err = tmpl.Execute("hello", &b);
if err != nil { if err != nil {
t.Error("unexpected parse error:", err) t.Error("unexpected parse error:", err)
...@@ -320,7 +321,7 @@ func TestCustomDelims(t *testing.T) { ...@@ -320,7 +321,7 @@ func TestCustomDelims(t *testing.T) {
t.Errorf("expected parse error for empty delimiter: %d %d %q %q", i, j, ldelim, rdelim); t.Errorf("expected parse error for empty delimiter: %d %d %q %q", i, j, ldelim, rdelim);
continue; continue;
} }
var b io.ByteBuffer; var b bytes.Buffer;
err = tmpl.Execute("hello", &b); err = tmpl.Execute("hello", &b);
s := string(b.Data()); s := string(b.Data());
if s != "template: hello" + ldelim + rdelim { if s != "template: hello" + ldelim + rdelim {
......
...@@ -7,7 +7,7 @@ package utf8 ...@@ -7,7 +7,7 @@ package utf8
import ( import (
"bytes"; "bytes";
"fmt"; "fmt";
"io"; "strings";
"testing"; "testing";
"utf8"; "utf8";
) )
...@@ -45,10 +45,10 @@ var utf8map = []Utf8Map { ...@@ -45,10 +45,10 @@ var utf8map = []Utf8Map {
Utf8Map{ 0x10ffff, "\xf4\x8f\xbf\xbf" }, Utf8Map{ 0x10ffff, "\xf4\x8f\xbf\xbf" },
} }
// io.StringBytes with one extra byte at end // strings.Bytes with one extra byte at end
func makeBytes(s string) []byte { func makeBytes(s string) []byte {
s += "\x00"; s += "\x00";
b := io.StringBytes(s); b := strings.Bytes(s);
return b[0:len(s)-1]; return b[0:len(s)-1];
} }
......
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