package main
import (
+ "bytes";
"container/vector";
"flag";
"fmt";
// Return text for an AST node.
func nodeText(node interface{}, mode uint) []byte {
- var buf io.ByteBuffer;
+ var buf bytes.Buffer;
tw := makeTabwriter(&buf);
printer.Fprint(tw, node, mode);
tw.Flush();
case []byte:
return v;
case string:
- return io.StringBytes(v);
+ return strings.Bytes(v);
case String:
- return io.StringBytes(v.String());
+ return strings.Bytes(v.String());
case ast.Decl:
return nodeText(v, printer.ExportsOnly);
case ast.Expr:
return nodeText(v, printer.ExportsOnly);
}
- var buf io.ByteBuffer;
+ var buf bytes.Buffer;
fmt.Fprint(&buf, x);
return buf.Data();
}
func serveParseErrors(c *http.Conn, errors *parseErrors) {
// format errors
- var buf io.ByteBuffer;
+ var buf bytes.Buffer;
parseerrorHtml.Execute(errors, &buf);
servePage(c, errors.filename + " - Parse Errors", buf.Data());
}
return;
}
- var buf io.ByteBuffer;
+ var buf bytes.Buffer;
fmt.Fprintln(&buf, "<pre>");
template.HtmlEscape(&buf, nodeText(prog, printer.DocComments));
fmt.Fprintln(&buf, "</pre>");
return;
}
- var buf io.ByteBuffer;
+ var buf bytes.Buffer;
if false { // TODO req.Params["format"] == "text"
err := packageText.Execute(PageInfo{pdoc, dirs}, &buf);
if err != nil {
return false;
}
- var buf io.ByteBuffer;
+ var buf bytes.Buffer;
io.Copy(r, &buf);
wait, err := os.Wait(pid, 0);
if err != nil {
base64.install: bytes.install io.install os.install strconv.install
bignum.install: fmt.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/gzip.install: bufio.install compress/flate.install hash.install hash/crc32.install io.install os.install
container/list.install:
crypto/hmac.install: crypto/md5.install crypto/sha1.install hash.install os.install
crypto/md5.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
-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
fmt.install: io.install os.install reflect.install strconv.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/parser.install: container/vector.install fmt.install go/ast.install go/scanner.install go/token.install io.install os.install
-go/printer.install: fmt.install go/ast.install go/token.install io.install os.install reflect.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 strings.install
go/scanner.install: go/token.install strconv.install unicode.install utf8.install
go/token.install: strconv.install
hash.install: io.install
hash/adler32.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
-io.install: bytes.install os.install sync.install
-json.install: container/vector.install fmt.install io.install math.install reflect.install strconv.install strings.install utf8.install
+io.install: bytes.install os.install strings.install sync.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
malloc.install:
math.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
os.install: once.install syscall.install
-path.install: io.install
+path.install: strings.install
rand.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:
sort.install:
strconv.install: bytes.install math.install os.install utf8.install
strings.install: utf8.install
sync.install:
syscall.install: sync.install
-tabwriter.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
+tabwriter.install: bytes.install container/vector.install io.install os.install utf8.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/iotest.install: io.install log.install os.install
time.install: io.install once.install os.install syscall.install
"io";
"os";
"reflect";
+ "strings";
"testing";
)
if n, err := io.ReadFull(tr, buf); err != nil {
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);
}
if n, err := io.ReadFull(tr, buf); err != nil {
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);
}
}
"io";
"os";
"reflect";
+ "strings";
"testing";
)
func TestEncode(t *testing.T) {
for _, p := range pairs {
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);
}
}
func TestEncoder(t *testing.T) {
for _, p := range pairs {
- bb := &io.ByteBuffer{};
+ bb := &bytes.Buffer{};
encoder := NewEncoder(StdEncoding, bb);
- encoder.Write(io.StringBytes(p.decoded));
+ encoder.Write(strings.Bytes(p.decoded));
encoder.Close();
testEqual(t, "Encode(%q) = %q, want %q", p.decoded, string(bb.Data()), p.encoded);
}
}
func TestEncoderBuffering(t *testing.T) {
- input := io.StringBytes(bigtest.decoded);
+ input := strings.Bytes(bigtest.decoded);
for bs := 1; bs <= 12; bs++ {
buf := make([]byte, bs);
- bb := &io.ByteBuffer{};
+ bb := &bytes.Buffer{};
encoder := NewEncoder(StdEncoding, bb);
for pos := 0; pos < len(input); pos += bs {
end := pos+bs;
func TestDecode(t *testing.T) {
for _, p := range pairs {
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) = length %v, want %v", p.encoded, count, len(p.decoded));
if len(p.encoded) > 0 {
func TestDecoder(t *testing.T) {
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)));
count, err := decoder.Read(dbuf);
if err != nil && err != os.EOF {
}
func TestDecoderBuffering(t *testing.T) {
- input := io.StringBytes(bigtest.encoded);
+ input := strings.Bytes(bigtest.encoded);
for bs := 1; bs <= 12; bs++ {
decoder := NewDecoder(StdEncoding, io.NewByteReader(input));
buf := make([]byte, len(bigtest.decoded) + 12);
for _, e := range examples {
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) {
case CorruptInputError:
testEqual(t, "Corruption in %q at offset %v, want %v", e.e, int(err), e.p);
for i := 0; i < n; i++ {
raw[i] = alpha[i%len(alpha)];
}
- encoded := new(io.ByteBuffer);
+ encoded := new(bytes.Buffer);
w := NewEncoder(StdEncoding, encoded);
nn, err := w.Write(raw);
if nn != n || err != nil {
if err != nil {
t.Fatalf("io.ReadAll(NewDecoder(...)): %v", err);
}
-
+
if !bytes.Equal(raw, decoded) {
var i int;
for i = 0; i < len(decoded) && i < len(raw); i++ {
package bufio
import (
+ "bytes";
"bufio";
"fmt";
"io";
"os";
+ "strings";
"testing";
"testing/iotest";
)
}
func TestReaderSimple(t *testing.T) {
- data := io.StringBytes("hello world");
+ data := strings.Bytes("hello world");
b := NewReader(io.NewByteReader(data));
if s := readBytes(b); s != "hello world" {
t.Errorf("simple hello world test failed: got %q", s);
for h := 0; h < len(texts); h++ {
text := texts[h];
- textbytes := io.StringBytes(text);
+ textbytes := strings.Bytes(text);
for i := 0; i < len(readMakers); i++ {
for j := 0; j < len(bufreaders); j++ {
for k := 0; k < len(bufsizes); k++ {
for i := 0; i < len(data); i++ {
data[i] = byte(' '+ i%('~'-' '));
}
- w := new(io.ByteBuffer);
+ w := new(bytes.Buffer);
for i := 0; i < len(bufsizes); i++ {
for j := 0; j < len(bufsizes); j++ {
nwrite := bufsizes[i];
func TestWriteErrors(t *testing.T) {
for i, w := range errorWriterTests {
buf := NewWriter(w);
- n, e := buf.Write(io.StringBytes("hello world"));
+ n, e := buf.Write(strings.Bytes("hello world"));
if e != nil {
t.Errorf("Write hello to %v: %v", w, e);
continue;
func TestNewReaderSizeIdempotent(t *testing.T) {
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 {
t.Error("NewReaderSize create fail", err);
}
func TestNewWriterSizeIdempotent(t *testing.T) {
const BufSize = 1000;
- b, err := NewWriterSize(new(io.ByteBuffer), BufSize);
+ b, err := NewWriterSize(new(bytes.Buffer), BufSize);
if err != nil {
t.Error("NewWriterSize create fail", err);
}
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
+
# DO NOT EDIT. Automatically generated by gobuild.
# gobuild -m >Makefile
coverage: packages
gotest
- 6cov -g `pwd` | grep -v '_test\.go:'
+ 6cov -g $$(pwd) | grep -v '_test\.go:'
%.$O: %.go
$(GC) -I_obj $*.go
$(AS) $*.s
O1=\
+ buffer.$O\
bytes.$O\
_obj$D/bytes.a: phases
a1: $(O1)
- $(AR) grc _obj$D/bytes.a bytes.$O
+ $(AR) grc _obj$D/bytes.a buffer.$O bytes.$O
rm -f $(O1)
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-package io
+package bytes
// Simple byte buffer for marshaling data.
import (
- "io";
+ "bytes";
"os";
)
}
}
-// A ByteBuffer is a simple implementation of the io.Read and io.Write interfaces
-// connected to a buffer of bytes.
-// The zero value for ByteBuffer is an empty buffer ready to use.
-type ByteBuffer struct {
+// A Buffer is a variable-sized buffer of bytes
+// with Read and Write methods.
+// The zero value for Buffer is an empty buffer ready to use.
+type Buffer struct {
buf []byte; // contents are the bytes buf[off : len(buf)]
off int; // read at &buf[off], write at &buf[len(buf)]
}
// Data returns the contents of the unread portion of the buffer;
// len(b.Data()) == b.Len().
-func (b *ByteBuffer) Data() []byte {
+func (b *Buffer) Data() []byte {
return b.buf[b.off : len(b.buf)]
}
// Len returns the number of bytes of the unread portion of the buffer;
// b.Len() == len(b.Data()).
-func (b *ByteBuffer) Len() int {
+func (b *Buffer) Len() int {
return len(b.buf) - b.off
}
// 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().
-func (b *ByteBuffer) Truncate(n int) {
+func (b *Buffer) Truncate(n int) {
if n == 0 {
// Reuse buffer space.
b.off = 0;
// Reset resets the buffer so it has no content.
// b.Reset() is the same as b.Truncate(0).
-func (b *ByteBuffer) Reset() {
+func (b *Buffer) Reset() {
b.Truncate(0);
}
// Write appends the contents of p to the buffer. The return
// 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();
n = len(p);
// WriteByte appends the byte c to the buffer.
// The returned error is always nil, but is included
// 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});
return nil;
}
// 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;
// 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) {
return 0, os.EOF
}
// ReadByte reads and returns the next byte from the buffer.
// 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) {
return 0, os.EOF;
}
return c, nil;
}
-// NewByteBufferFromArray creates and initializes a new ByteBuffer
-// with buf as its initial contents.
-func NewByteBufferFromArray(buf []byte) *ByteBuffer {
- return &ByteBuffer{buf, 0};
+// NewBuffer creates and initializes a new Buffer
+// using buf as its initial contents.
+func NewBuffer(buf []byte) *Buffer {
+ return &Buffer{buf, 0};
}
import (
"bytes";
- "io";
+ "strings";
"testing";
)
func TestCompare(t *testing.T) {
for i := 0; i < len(comparetests); i++ {
tt := comparetests[i];
- a := io.StringBytes(tt.a);
- b := io.StringBytes(tt.b);
+ a := strings.Bytes(tt.a);
+ b := strings.Bytes(tt.b);
cmp := Compare(a, b);
eql := Equal(a, b);
if cmp != tt.cmp {
}
func TestExplode(t *testing.T) {
for _, tt := range(explodetests) {
- a := explode(io.StringBytes(tt.s), tt.n);
+ a := explode(strings.Bytes(tt.s), tt.n);
result := arrayOfString(a);
if !eq(result, tt.a) {
t.Errorf(`Explode("%s", %d) = %v; want %v`, tt.s, tt.n, result, tt.a);
}
func TestSplit(t *testing.T) {
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);
if !eq(result, tt.a) {
t.Errorf(`Split(%q, %q, %d) = %v; want %v`, tt.s, tt.sep, tt.n, result, tt.a);
continue;
}
- s := Join(a, io.StringBytes(tt.sep));
+ s := Join(a, strings.Bytes(tt.sep));
if string(s) != tt.s {
t.Errorf(`Join(Split(%q, %q, %d), %q) = %q`, tt.s, tt.sep, tt.n, tt.sep, s);
}
func TestCopy(t *testing.T) {
for i := 0; i < len(copytests); i++ {
tt := copytests[i];
- dst := io.StringBytes(tt.a);
- n := Copy(dst, io.StringBytes(tt.b));
+ dst := strings.Bytes(tt.a);
+ n := Copy(dst, strings.Bytes(tt.b));
result := string(dst);
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);
package gzip
import (
+ "bytes";
"compress/gzip";
"fmt";
"io";
}
func TestGzipInflater(t *testing.T) {
- b := new(io.ByteBuffer);
+ b := new(bytes.Buffer);
for i, tt := range gzipTests {
in := io.NewByteReader(tt.gzip);
gzip, err := NewGzipInflater(in);
// gobuild: $GC ecb_aes_test.go
import (
+ "bytes";
"crypto/aes";
"crypto/block";
"io";
continue;
}
- var crypt io.ByteBuffer;
+ var crypt bytes.Buffer;
w := NewCBCEncrypter(c, tt.iv, &crypt);
var r io.Reader = io.NewByteReader(tt.in);
n, err := io.Copy(r, w);
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));
w = &plain;
n, err = io.Copy(r, w);
// gobuild: $GC ecb_aes_test.go
import (
+ "bytes";
"crypto/aes";
"crypto/block";
"io";
continue;
}
- var crypt io.ByteBuffer;
+ var crypt bytes.Buffer;
w := NewCFBEncrypter(c, tt.s, tt.iv, &crypt);
var r io.Reader = io.NewByteReader(tt.in);
n, err := io.Copy(r, w);
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));
w = &plain;
n, err = io.Copy(r, w);
package block
import (
+ "bytes";
"crypto/aes";
"crypto/block";
"io";
}
for j := 0; j <= 5; j += 5 {
- var crypt io.ByteBuffer;
+ var crypt bytes.Buffer;
in := tt.in[0:len(tt.in) - j];
w := block.NewCTRWriter(c, tt.iv, &crypt);
var r io.Reader = io.NewByteReader(in);
}
for j := 0; j <= 7; j += 7 {
- var plain io.ByteBuffer;
+ var plain bytes.Buffer;
out := tt.out[0:len(tt.out) - j];
r := block.NewCTRReader(c, tt.iv, io.NewByteReader(out));
w := &plain;
package block
import (
+ "bytes";
"crypto/aes";
"crypto/block";
"fmt";
}
func TestEAXEncrypt_AES(t *testing.T) {
- b := new(io.ByteBuffer);
+ b := new(bytes.Buffer);
for i, tt := range eaxAESTests {
test := fmt.Sprintf("test %d", i);
c, err := aes.NewCipher(tt.key);
}
func TestEAXDecrypt_AES(t *testing.T) {
- b := new(io.ByteBuffer);
+ b := new(bytes.Buffer);
for i, tt := range eaxAESTests {
test := fmt.Sprintf("test %d", i);
c, err := aes.NewCipher(tt.key);
package block
import (
+ "bytes";
"crypto/aes";
"crypto/block";
"io";
continue;
}
- var crypt io.ByteBuffer;
+ var crypt bytes.Buffer;
w := NewECBEncrypter(c, &crypt);
var r io.Reader = io.NewByteReader(tt.in);
n, err := io.Copy(r, w);
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));
w = &plain;
n, err = io.Copy(r, w);
package block
import (
+ "bytes";
"crypto/block";
"fmt";
"io";
for i := 0; i < len(plain); i++ {
plain[i] = byte(i);
}
- b := new(io.ByteBuffer);
+ b := new(bytes.Buffer);
for block := 1; block <= 64; block *= 2 {
// compute encrypted version
delta := byte(0);
for i := 0; i < len(plain); i++ {
plain[i] = byte(255 - i);
}
- b := new(io.ByteBuffer);
+ b := new(bytes.Buffer);
for block := 1; block <= 64 && block <= maxio; block *= 2 {
// compute encrypted version
delta := byte(0);
// gotest: $GC ecb_aes_test.go
import (
+ "bytes";
"crypto/aes";
"crypto/block";
"io";
}
for j := 0; j <= 5; j += 5 {
- var crypt io.ByteBuffer;
+ var crypt bytes.Buffer;
in := tt.in[0:len(tt.in) - j];
w := NewOFBWriter(c, tt.iv, &crypt);
var r io.Reader = io.NewByteReader(in);
}
for j := 0; j <= 7; j += 7 {
- var plain io.ByteBuffer;
+ var plain bytes.Buffer;
out := tt.out[0:len(tt.out) - j];
r := NewOFBReader(c, tt.iv, io.NewByteReader(out));
w := &plain;
package block
import (
+ "bytes";
"crypto/block";
"fmt";
"io";
for i := 0; i < len(plain); i++ {
plain[i] = byte(i);
}
- b := new(io.ByteBuffer);
+ b := new(bytes.Buffer);
for block := 1; block <= 64 && block <= maxio; block *= 2 {
// compute encrypted version
n := byte(0);
for i := 0; i < len(plain); i++ {
plain[i] = byte(255 - i);
}
- b := new(io.ByteBuffer);
+ b := new(bytes.Buffer);
for block := 1; block <= 64 && block <= maxio; block *= 2 {
// compute encrypted version
n := byte(0);
import (
"hash";
"crypto/hmac";
- "io";
"fmt";
+ "strings";
"testing";
)
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
},
- io.StringBytes("Sample #1"),
+ strings.Bytes("Sample #1"),
"4f4ca3d5d68ba7cc0a1208c9c61e9c5da0403c0a",
},
hmacTest {
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0x40, 0x41, 0x42, 0x43,
},
- io.StringBytes("Sample #2"),
+ strings.Bytes("Sample #2"),
"0922d3405faa3d194f82a45830737d5cc6c75d24",
},
hmacTest {
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
0xb0, 0xb1, 0xb2, 0xb3,
},
- io.StringBytes("Sample #3"),
+ strings.Bytes("Sample #3"),
"bcf41eab8bb2d802f3d05caf7cb092ecf8d1a3aa",
},
// Test from Plan 9.
hmacTest {
NewMD5,
- io.StringBytes("Jefe"),
- io.StringBytes("what do ya want for nothing?"),
+ strings.Bytes("Jefe"),
+ strings.Bytes("what do ya want for nothing?"),
"750c783e6ab0b503eaa86e310a5db738",
}
}
A format specification is a set of package declarations and format rules:
Format = [ Entry { ";" Entry } [ ";" ] ] .
- Entry = PackageDecl | FormatRule .
+ Entry = PackageDecl | FormatRule .
(The syntax of a format specification is presented in the same EBNF
notation as used in the Go language specification. The syntax of white
The following example shows a complete format specification for a
struct 'myPackage.Point'. Assume the package
-
+
package myPackage // in directory myDir/myPackage
type Point struct {
name string;
Repetition = "{" Body [ "/" Separator ] "}" .
Separator = Expression .
-
+
A repeated expression is evaluated as follows: The body is evaluated
repeatedly and its results are concatenated until the body evaluates
to nil. The result of the repetition is the (possibly empty) concatenation,
package datafmt
import (
+ "bytes";
"container/vector";
"fmt";
"go/token";
env Environment; // user-supplied environment
errors chan os.Error; // not chan *Error (errors <- nil would be wrong!)
hasOutput bool; // true after the first literal has been written
- indent io.ByteBuffer; // current indentation
- output io.ByteBuffer; // format output
+ indent bytes.Buffer; // current indentation
+ output bytes.Buffer; // format output
linePos token.Position; // position of line beginning (Column == 0)
default_ expr; // possibly nil
separator expr; // possibly nil
if val.Kind() != reflect.StructKind {
return nil, 0;
}
-
+
sval, styp := val.(reflect.StructValue), val.Type().(reflect.StructType);
// look for field at the top level
}
}
}
-
+
return field, level + 1;
}
s.restore(mark);
b = false;
}
-
+
// reset indentation
s.indent.Truncate(indentLen);
return b;
// partially formatted result followed by an error message.
//
func (f Format) Sprint(args ...) string {
- var buf io.ByteBuffer;
+ var buf bytes.Buffer;
n, err := f.Fprint(&buf, nil, args);
if err != nil {
fmt.Fprintf(&buf, "--- Sprint(%s) failed: %v", fmt.Sprint(args), err);
import (
"fmt";
"datafmt";
- "io";
"os";
+ "strings";
"testing";
)
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 {
t.Errorf("Parse(%s): %v", form, err);
return nil;
case "nil":
return false;
case "testing.T":
- s.Write(io.StringBytes("testing.T"));
+ s.Write(strings.Bytes("testing.T"));
return true;
}
panic("unreachable");
check(t, ``, ``);
check(t, `bool=":%v"`, `:true:false`, true, false);
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);
`string = "%s";`
`ptr = *;`
`datafmt.T2 = s ["-" p "-"];`
-
+
const F2b =
F1 +
`string = "%s";`
`ptr = *;`
`datafmt.T2 = s ("-" p "-" | "empty");`;
-
+
func TestStruct2(t *testing.T) {
check(t, F2a, "foo", T2{"foo", nil});
check(t, F2a, "bar-<17>-", T2{"bar", &T1{17}});
const FSlice =
`int = "%b";`
`array = { * / ", " }`
-
+
func TestSlice(t *testing.T) {
check(t, FSlice, "10, 11, 101, 111", []int{2, 3, 5, 7});
}
"fmt";
"go/scanner";
"go/token";
- "io";
"os";
"strconv";
"strings";
func (p *parser) parseLiteral() literal {
- s := io.StringBytes(p.parseString());
+ s := strings.Bytes(p.parseString());
// A string literal may contain %-format specifiers. To simplify
// and speed up printing of the literal, split it into segments
package exvar
import (
+ "bytes";
"fmt";
"http";
"io";
func (v *Map) String() string {
v.mu.Lock();
defer v.mu.Unlock();
- b := new(io.ByteBuffer);
+ b := new(bytes.Buffer);
fmt.Fprintf(b, "{");
first := true;
for key, val := range v.m {
"fmt";
"io";
"math";
+ "strings";
"testing";
)
fmtTest{ "%q", "abc", `"abc"` },
// basic bytes
- fmtTest{ "%s", io.StringBytes("abc"), "abc" },
- fmtTest{ "%x", io.StringBytes("abc"), "616263" },
- fmtTest{ "% x", io.StringBytes("abc"), "61 62 63" },
- fmtTest{ "%x", io.StringBytes("xyz"), "78797a" },
- fmtTest{ "%X", io.StringBytes("xyz"), "78797A" },
- fmtTest{ "%q", io.StringBytes("abc"), `"abc"` },
+ fmtTest{ "%s", strings.Bytes("abc"), "abc" },
+ fmtTest{ "%x", strings.Bytes("abc"), "616263" },
+ fmtTest{ "% x", strings.Bytes("abc"), "61 62 63" },
+ fmtTest{ "%x", strings.Bytes("xyz"), "78797a" },
+ fmtTest{ "%X", strings.Bytes("xyz"), "78797A" },
+ fmtTest{ "%q", strings.Bytes("abc"), `"abc"` },
// escaped strings
fmtTest{ "%#q", `abc`, "`abc`" },
var (
- ldquo = io.StringBytes("“");
- rdquo = io.StringBytes("”");
+ ldquo = strings.Bytes("“");
+ rdquo = strings.Bytes("”");
)
// Escape comment text for HTML.
var (
- html_p = io.StringBytes("<p>\n");
- html_endp = io.StringBytes("</p>\n");
- html_pre = io.StringBytes("<pre>");
- html_endpre = io.StringBytes("</pre>\n");
+ html_p = strings.Bytes("<p>\n");
+ html_endp = strings.Bytes("</p>\n");
+ html_pre = strings.Bytes("<pre>");
+ html_endpre = strings.Bytes("</pre>\n");
)
package parser
import (
+ "bytes";
"container/vector";
"fmt";
"go/ast";
"go/token";
"io";
"os";
+ "strings";
)
if src != nil {
switch s := src.(type) {
case string:
- return io.StringBytes(s), nil;
+ return strings.Bytes(s), nil;
case []byte:
return s, nil;
- case *io.ByteBuffer:
- // is io.Read, but src is already available in []byte form
+ case *bytes.Buffer:
+ // is io.Reader, but src is already available in []byte form
if s != nil {
return s.Data(), nil;
}
case io.Reader:
- var buf io.ByteBuffer;
+ var buf bytes.Buffer;
n, err := io.Copy(s, &buf);
if err != nil {
return nil, err;
// Parse parses a Go program.
//
// 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
// optional parser functionality.
//
"io";
"os";
"reflect";
+ "strings";
)
case []byte:
p.write(x);
case string:
- p.write(io.StringBytes(x));
+ p.write(strings.Bytes(x));
case token.Token:
- p.write(io.StringBytes(x.String()));
+ p.write(strings.Bytes(x.String()));
case token.Position:
// set current position
p.pos = x;
import (
"go/scanner";
"go/token";
- "io";
+ "strings";
"testing";
)
// verify scan
index := 0;
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 {
e := elt{token.EOF, "", special};
if index < len(tokens) {
var s scanner.Scanner;
// 1st init
- s.Init(io.StringBytes("if true { }"), nil, 0);
+ s.Init(strings.Bytes("if true { }"), nil, 0);
s.Scan(); // if
s.Scan(); // true
pos, tok, lit := s.Scan(); // {
}
// 2nd init
- s.Init(io.StringBytes("go true { ]"), nil, 0);
+ s.Init(strings.Bytes("go true { ]"), nil, 0);
pos, tok, lit = s.Scan(); // go
if tok != token.GO {
t.Errorf("bad token: got %s, expected %s", tok.String(), token.GO);
var s scanner.Scanner;
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 {
pos, tok, lit := s.Scan();
if pos.Offset != offs {
import (
"bytes";
"gob";
- "io";
"os";
"testing";
)
// Test basic encode/decode routines for unsigned integers
func TestUintCodec(t *testing.T) {
- var b = new(io.ByteBuffer);
+ var b = new(bytes.Buffer);
for i, tt := range encodeT {
b.Reset();
err := EncodeUint(b, tt.x);
}
func verifyInt(i int64, t *testing.T) {
- var b = new(io.ByteBuffer);
+ var b = new(bytes.Buffer);
err := EncodeInt(b, i);
if err != nil {
t.Error("EncodeInt:", i, err)
// Test basic encode/decode routines for signed integers
func TestIntCodec(t *testing.T) {
- var b = new(io.ByteBuffer);
+ var b = new(bytes.Buffer);
for u := uint64(0); ; u = (u+1) * 7 {
// Do positive and negative values
i := int64(u);
// and upper case after each dash.
// (Host, User-Agent, If-Modified-Since).
// HTTP headers are ASCII only, so no Unicode issues.
- a := io.StringBytes(s);
+ a := strings.Bytes(s);
upper := true;
for i,v := range a {
if upper && 'a' <= v && v <= 'z' {
package main
import (
+ "bytes";
"bufio";
"exvar";
"flag";
case "GET":
ctr.n++;
case "POST":
- buf := new(io.ByteBuffer);
+ buf := new(bytes.Buffer);
io.Copy(req.Body, buf);
body := string(buf.Data());
if n, err := strconv.Atoi(body); err != nil {
O1=\
io.$O\
pipe.$O\
+ xxx.$O\
O2=\
- bytebuffer.$O\
-
-O3=\
utils.$O\
-phases: a1 a2 a3
+phases: a1 a2
_obj$D/io.a: phases
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)
a2: $(O2)
- $(AR) grc _obj$D/io.a bytebuffer.$O
- rm -f $(O2)
-
-a3: $(O3)
$(AR) grc _obj$D/io.a utils.$O
- rm -f $(O3)
+ rm -f $(O2)
newpkg: clean
$(O1): newpkg
$(O2): a1
$(O3): a2
-$(O4): a3
nuke: clean
rm -f $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/io.a
import (
"bytes";
"os";
+ "strings";
)
// Error represents an unexpected I/O behavior.
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.
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.
"fmt";
"io";
"os";
+ "strings";
"testing";
"time";
)
c := make(chan int);
r, w := Pipe();
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);
if err != nil {
t.Errorf("read: %v", err);
package io
import (
+ "bytes";
"io";
"os";
)
// ReadAll reads from r until an error or EOF and returns the data it read.
func ReadAll(r Reader) ([]byte, os.Error) {
- var buf ByteBuffer;
- n, err := io.Copy(r, &buf);
+ var buf bytes.Buffer;
+ n, err := Copy(r, &buf);
return buf.Data(), err;
}
package json
import (
+ "bytes";
"fmt";
- "io";
"math";
"strconv";
"strings";
func Quote(s string) string {
chr := make([]byte, utf8.UTFMax);
chr0 := chr[0:1];
- b := new(io.ByteBuffer);
+ b := new(bytes.Buffer);
chr[0] = '"';
b.Write(chr0);
for i := 0; i < len(s); i++ {
"io";
"net";
"os";
+ "strings";
"syscall";
"testing";
)
// fd is already connected to the destination, port 80.
// Run an HTTP request to fetch the appropriate page.
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);
buf := make([]byte, 1000);
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;
n, errno := fd.Write(b);
package os
import (
+ "bytes";
"fmt";
"io";
"os";
+ "strings";
"testing";
)
}
w.Close();
- var b io.ByteBuffer;
+ var b bytes.Buffer;
io.Copy(r, &b);
output := string(b.Data());
expect := "/\n";
}
checkSize(t, Path, 0);
- fd.Write(io.StringBytes("hello, world\n"));
+ fd.Write(strings.Bytes("hello, world\n"));
checkSize(t, Path, 13);
fd.Truncate(10);
checkSize(t, Path, 10);
checkSize(t, Path, 1024);
fd.Truncate(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.
fd.Close();
Remove(Path);
}
w.Close();
- var b io.ByteBuffer;
+ var b bytes.Buffer;
io.Copy(r, &b);
Wait(pid, 0);
output := string(b.Data());
t.Errorf("Hostname() = %q, want %q", hostname, want);
}
}
-
// slash-separated filename paths.
package path
-import "io"
+import "strings"
// Clean returns the shortest path name equivalent to path
// by purely lexical processing. It applies the following rules
// writing to buf; w is index of next byte to write.
// dotdot is index in buf where .. must stop, either because
// 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;
if rooted {
r, w, dotdot = 1, 1, 1;
package regexp
import (
+ "bytes";
"container/vector";
"io";
"os";
func (re *Regexp) ReplaceAll(src, repl string) string {
lastMatchEnd := 0; // end position of the most recent match
searchPos := 0; // position where we next look for a match
- buf := new(io.ByteBuffer);
+ buf := new(bytes.Buffer);
for searchPos <= len(src) {
a := re.doExecute(src, searchPos);
if len(a) == 0 {
free(p);
break;
case RefSome:
+//printf("gc-mem 1 %D\n", (uint64)s->npages<<PageShift);
s->gcref0 = RefNone; // set up for next mark phase
break;
}
break;
}
}
+//printf("gc-mem %d %d\n", s->ref, size);
}
static void
if(gcpercent < 0)
return;
+//printf("gc...\n");
m->gcing = 1;
semacquire(&gcsema);
gosave(&g->sched); // update g's stack pointer for scanstack
}
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;
+}
+
package tabwriter
import (
+ "bytes";
"container/vector";
"io";
"os";
flags uint;
// 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
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)
}
case '<', '&':
- // possibly an html tag/entity
+ // possibly an html tag/entity
if b.flags & FilterHTML != 0 {
// begin of tag/entity
b.append(buf[i0 : i], true);
package template
import (
+ "bytes";
"fmt";
"io";
"reflect";
+ "strings";
)
// StringFormatter formats into the default string representation.
}
-var esc_amp = io.StringBytes("&")
-var esc_lt = io.StringBytes("<")
-var esc_gt = io.StringBytes(">")
+var esc_amp = strings.Bytes("&")
+var esc_lt = strings.Bytes("<")
+var esc_gt = strings.Bytes(">")
// HtmlEscape writes to w the properly escaped HTML equivalent
// of the plain text data s.
// HtmlFormatter formats arbitrary values for HTML
func HtmlFormatter(w io.Writer, value interface{}, format string) {
- var b io.ByteBuffer;
+ var b bytes.Buffer;
fmt.Fprint(&b, value);
HtmlEscape(w, b.Data());
}
if !validDelim(t.ldelim) || !validDelim(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.linenum = 0;
go func() {
// delimiters are very rarely invalid and Parse has the necessary
// error-handling interface already.
func (t *Template) SetDelims(left, right string) {
- t.ldelim = io.StringBytes(left);
- t.rdelim = io.StringBytes(right);
+ t.ldelim = strings.Bytes(left);
+ t.rdelim = strings.Bytes(right);
}
// Parse creates a Template with default parameters (such as {} for
package template
import (
+ "bytes";
"fmt";
"io";
"os";
s.empty = []*T{ };
s.null = nil;
- var buf io.ByteBuffer;
+ var buf bytes.Buffer;
for i, test := range tests {
buf.Reset();
tmpl, err := Parse(test.in, formatters);
if err != nil {
t.Error("unexpected parse error:", err)
}
- var b io.ByteBuffer;
+ var b bytes.Buffer;
err = tmpl.Execute("hello", &b);
if err != nil {
t.Error("unexpected execute error:", err)
if err != nil {
t.Error("unexpected parse error:", err)
}
- var b io.ByteBuffer;
+ var b bytes.Buffer;
err = tmpl.Execute("hello", &b);
if err != nil {
t.Error("unexpected parse error:", err)
t.Errorf("expected parse error for empty delimiter: %d %d %q %q", i, j, ldelim, rdelim);
continue;
}
- var b io.ByteBuffer;
+ var b bytes.Buffer;
err = tmpl.Execute("hello", &b);
s := string(b.Data());
if s != "template: hello" + ldelim + rdelim {
import (
"bytes";
"fmt";
- "io";
+ "strings";
"testing";
"utf8";
)
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 {
s += "\x00";
- b := io.StringBytes(s);
+ b := strings.Bytes(s);
return b[0:len(s)-1];
}