1
0
mirror of https://github.com/golang/go synced 2024-11-26 06:07:57 -07:00

Name change to improve embeddability:

io.Read->io.Reader
	io.Write,Close,etc.->io.Writer,Closer etc.

R=rsc
DELTA=190  (0 added, 0 deleted, 190 changed)
OCL=28525
CL=28535
This commit is contained in:
Rob Pike 2009-05-08 11:22:57 -07:00
parent df46b3342c
commit c8b47c6fce
20 changed files with 121 additions and 121 deletions

View File

@ -96,7 +96,7 @@ var makefileTemplate =
" cp {ObjDir}$D/{Name}.a $(GOROOT)/pkg$D/{Name}.a\n" " cp {ObjDir}$D/{Name}.a $(GOROOT)/pkg$D/{Name}.a\n"
"{.end}\n" "{.end}\n"
func argsFmt(w io.Write, x interface{}, format string) { func argsFmt(w io.Writer, x interface{}, format string) {
args := x.([]string); args := x.([]string);
fmt.Fprint(w, "#"); fmt.Fprint(w, "#");
for i, a := range args { for i, a := range args {
@ -104,17 +104,17 @@ func argsFmt(w io.Write, x interface{}, format string) {
} }
} }
func basenameFmt(w io.Write, x interface{}, format string) { func basenameFmt(w io.Writer, x interface{}, format string) {
t := fmt.Sprint(x); t := fmt.Sprint(x);
t = t[0:len(t)-len(path.Ext(t))]; t = t[0:len(t)-len(path.Ext(t))];
fmt.Fprint(w, MakeString(t)); fmt.Fprint(w, MakeString(t));
} }
func plus1Fmt(w io.Write, x interface{}, format string) { func plus1Fmt(w io.Writer, x interface{}, format string) {
fmt.Fprint(w, x.(int) + 1); fmt.Fprint(w, x.(int) + 1);
} }
func makeFmt(w io.Write, x interface{}, format string) { func makeFmt(w io.Writer, x interface{}, format string) {
fmt.Fprint(w, MakeString(fmt.Sprint(x))); fmt.Fprint(w, MakeString(fmt.Sprint(x)));
} }

View File

@ -47,17 +47,17 @@ func copySlice(dst []byte, src []byte) {
// BufRead implements buffering for an io.Read object. // BufRead implements buffering for an io.Read object.
type BufRead struct { type BufRead struct {
buf []byte; buf []byte;
rd io.Read; rd io.Reader;
r, w int; r, w int;
err os.Error; err os.Error;
lastbyte int; lastbyte int;
} }
// NewBufReadSize creates a new BufRead whose buffer has the specified size, // NewBufReadSize creates a new BufRead whose buffer has the specified size,
// which must be greater than zero. If the argument io.Read is already a // which must be greater than zero. If the argument io.Reader is already a
// BufRead with large enough size, it returns the underlying BufRead. // BufRead with large enough size, it returns the underlying BufRead.
// It returns the BufRead and any error. // It returns the BufRead and any error.
func NewBufReadSize(rd io.Read, size int) (*BufRead, os.Error) { func NewBufReadSize(rd io.Reader, size int) (*BufRead, os.Error) {
if size <= 0 { if size <= 0 {
return nil, BadBufSize return nil, BadBufSize
} }
@ -74,7 +74,7 @@ func NewBufReadSize(rd io.Read, size int) (*BufRead, os.Error) {
} }
// NewBufRead returns a new BufRead whose buffer has the default size. // NewBufRead returns a new BufRead whose buffer has the default size.
func NewBufRead(rd io.Read) *BufRead { func NewBufRead(rd io.Reader) *BufRead {
b, err := NewBufReadSize(rd, defaultBufSize); b, err := NewBufReadSize(rd, defaultBufSize);
if err != nil { if err != nil {
// cannot happen - defaultBufSize is a valid size // cannot happen - defaultBufSize is a valid size
@ -378,19 +378,19 @@ func (b *BufRead) ReadLineString(delim byte, savedelim bool) (line string, err o
// buffered output // buffered output
// BufWrite implements buffering for an io.Write object. // BufWrite implements buffering for an io.Writer object.
type BufWrite struct { type BufWrite struct {
err os.Error; err os.Error;
buf []byte; buf []byte;
n int; n int;
wr io.Write; wr io.Writer;
} }
// NewBufWriteSize creates a new BufWrite whose buffer has the specified size, // NewBufWriteSize creates a new BufWrite whose buffer has the specified size,
// which must be greater than zero. If the argument io.Write is already a // which must be greater than zero. If the argument io.Writer is already a
// BufWrite with large enough size, it returns the underlying BufWrite. // BufWrite with large enough size, it returns the underlying BufWrite.
// It returns the BufWrite and any error. // It returns the BufWrite and any error.
func NewBufWriteSize(wr io.Write, size int) (*BufWrite, os.Error) { func NewBufWriteSize(wr io.Writer, size int) (*BufWrite, os.Error) {
if size <= 0 { if size <= 0 {
return nil, BadBufSize return nil, BadBufSize
} }
@ -406,7 +406,7 @@ func NewBufWriteSize(wr io.Write, size int) (*BufWrite, os.Error) {
} }
// NewBufWrite returns a new BufWrite whose buffer has the default size. // NewBufWrite returns a new BufWrite whose buffer has the default size.
func NewBufWrite(wr io.Write) *BufWrite { func NewBufWrite(wr io.Writer) *BufWrite {
b, err := NewBufWriteSize(wr, defaultBufSize); b, err := NewBufWriteSize(wr, defaultBufSize);
if err != nil { if err != nil {
// cannot happen - defaultBufSize is valid size // cannot happen - defaultBufSize is valid size
@ -415,7 +415,7 @@ func NewBufWrite(wr io.Write) *BufWrite {
return b; return b;
} }
// Flush writes any buffered data to the underlying io.Write. // Flush writes any buffered data to the underlying io.Writer.
func (b *BufWrite) Flush() os.Error { func (b *BufWrite) Flush() os.Error {
if b.err != nil { if b.err != nil {
return b.err return b.err
@ -505,7 +505,7 @@ func (b *BufWrite) WriteByte(c byte) os.Error {
// buffered input and output // buffered input and output
// BufReadWrite stores (a pointer to) a BufRead and a BufWrite. // BufReadWrite stores (a pointer to) a BufRead and a BufWrite.
// It implements io.ReadWrite. // It implements io.ReadWriter.
type BufReadWrite struct { type BufReadWrite struct {
*BufRead; *BufRead;
*BufWrite; *BufWrite;

View File

@ -24,7 +24,7 @@ type byteReader struct {
p []byte p []byte
} }
func newByteReader(p []byte) io.Read { func newByteReader(p []byte) io.Reader {
b := new(byteReader); b := new(byteReader);
b.p = p; b.p = p;
return b return b
@ -46,7 +46,7 @@ type halfByteReader struct {
p []byte p []byte
} }
func newHalfByteReader(p []byte) io.Read { func newHalfByteReader(p []byte) io.Reader {
b := new(halfByteReader); b := new(halfByteReader);
b.p = p; b.p = p;
return b return b
@ -67,10 +67,10 @@ func (b *halfByteReader) Read(p []byte) (int, os.Error) {
// Reads from a reader and rot13s the result. // Reads from a reader and rot13s the result.
type rot13Reader struct { type rot13Reader struct {
r io.Read r io.Reader
} }
func newRot13Reader(r io.Read) *rot13Reader { func newRot13Reader(r io.Reader) *rot13Reader {
r13 := new(rot13Reader); r13 := new(rot13Reader);
r13.r = r; r13.r = r;
return r13 return r13
@ -95,11 +95,11 @@ func (r13 *rot13Reader) Read(p []byte) (int, os.Error) {
type readMaker struct { type readMaker struct {
name string; name string;
fn func([]byte) io.Read; fn func([]byte) io.Reader;
} }
var readMakers = []readMaker { var readMakers = []readMaker {
readMaker{ "full", func(p []byte) io.Read { return newByteReader(p) } }, readMaker{ "full", func(p []byte) io.Reader { return newByteReader(p) } },
readMaker{ "half", func(p []byte) io.Read { return newHalfByteReader(p) } }, readMaker{ "half", func(p []byte) io.Reader { return newHalfByteReader(p) } },
} }
// Call ReadLineString (which ends up calling everything else) // Call ReadLineString (which ends up calling everything else)

View File

@ -27,7 +27,7 @@ import (
) )
// Formatter represents the printer state passed to custom formatters. // Formatter represents the printer state passed to custom formatters.
// It provides access to the io.Write interface plus information about // It provides access to the io.Writer interface plus information about
// the flags and options for the operand's format specifier. // the flags and options for the operand's format specifier.
type Formatter interface { type Formatter interface {
// Write is the function to call to emit formatted output to be printed. // Write is the function to call to emit formatted output to be printed.
@ -52,7 +52,7 @@ type Format interface {
// returns a string, which defines the ``native'' format for that object. // returns a string, which defines the ``native'' format for that object.
// Any such object will be printed using that method if passed // Any such object will be printed using that method if passed
// as operand to a %s or %v format or to an unformatted printer such as Print. // as operand to a %s or %v format or to an unformatted printer such as Print.
type String interface { type Stringer interface {
String() string String() string
} }
@ -149,7 +149,7 @@ func (p *pp) doprint(v reflect.StructValue, addspace, addnewline bool);
// These routines end in 'f' and take a format string. // These routines end in 'f' and take a format string.
// Fprintf formats according to a format specifier and writes to w. // Fprintf formats according to a format specifier and writes to w.
func Fprintf(w io.Write, format string, a ...) (n int, error os.Error) { func Fprintf(w io.Writer, format string, a ...) (n int, error os.Error) {
v := reflect.NewValue(a).(reflect.StructValue); v := reflect.NewValue(a).(reflect.StructValue);
p := newPrinter(); p := newPrinter();
p.doprintf(format, v); p.doprintf(format, v);
@ -176,7 +176,7 @@ func Sprintf(format string, a ...) string {
// Fprint formats using the default formats for its operands and writes to w. // Fprint formats using the default formats for its operands and writes to w.
// Spaces are added between operands when neither is a string. // Spaces are added between operands when neither is a string.
func Fprint(w io.Write, a ...) (n int, error os.Error) { func Fprint(w io.Writer, a ...) (n int, error os.Error) {
v := reflect.NewValue(a).(reflect.StructValue); v := reflect.NewValue(a).(reflect.StructValue);
p := newPrinter(); p := newPrinter();
p.doprint(v, false, false); p.doprint(v, false, false);
@ -207,7 +207,7 @@ func Sprint(a ...) string {
// Fprintln formats using the default formats for its operands and writes to w. // Fprintln formats using the default formats for its operands and writes to w.
// Spaces are always added between operands and a newline is appended. // Spaces are always added between operands and a newline is appended.
func Fprintln(w io.Write, a ...) (n int, error os.Error) { func Fprintln(w io.Writer, a ...) (n int, error os.Error) {
v := reflect.NewValue(a).(reflect.StructValue); v := reflect.NewValue(a).(reflect.StructValue);
p := newPrinter(); p := newPrinter();
p.doprint(v, true, true); p.doprint(v, true, true);
@ -364,7 +364,7 @@ func parsenum(s string, start, end int) (n int, got bool, newi int) {
func (p *pp) printField(field reflect.Value) (was_string bool) { func (p *pp) printField(field reflect.Value) (was_string bool) {
inter := field.Interface(); inter := field.Interface();
if inter != nil { if inter != nil {
if stringer, ok := inter.(String); ok { if stringer, ok := inter.(Stringer); ok {
p.addstr(stringer.String()); p.addstr(stringer.String());
return false; // this value is not a string return false; // this value is not a string
} }
@ -628,7 +628,7 @@ func (p *pp) doprintf(format string, v reflect.StructValue) {
case 's': case 's':
if inter != nil { if inter != nil {
// if object implements String, use the result. // if object implements String, use the result.
if stringer, ok := inter.(String); ok { if stringer, ok := inter.(Stringer); ok {
s = p.fmt.Fmt_s(stringer.String()).Str(); s = p.fmt.Fmt_s(stringer.String()).Str();
break; break;
} }

View File

@ -1914,7 +1914,7 @@ func readSource(src interface{}, err ErrorHandler) []byte {
if s != nil { if s != nil {
return s.Data(); return s.Data();
} }
case io.Read: case io.Reader:
var buf io.ByteBuffer; var buf io.ByteBuffer;
n, os_err := io.Copy(s, &buf); n, os_err := io.Copy(s, &buf);
if os_err == nil { if os_err == nil {

View File

@ -43,7 +43,7 @@ type Conn struct {
RemoteAddr string; // network address of remote side RemoteAddr string; // network address of remote side
Req *Request; // current HTTP request Req *Request; // current HTTP request
rwc io.ReadWriteClose; // i/o connection rwc io.ReadWriteCloser; // i/o connection
buf *bufio.BufReadWrite; // buffered rwc buf *bufio.BufReadWrite; // buffered rwc
handler Handler; // request handler handler Handler; // request handler
hijacked bool; // connection has been hijacked by handler hijacked bool; // connection has been hijacked by handler
@ -56,7 +56,7 @@ type Conn struct {
} }
// Create new connection from rwc. // Create new connection from rwc.
func newConn(rwc io.ReadWriteClose, raddr string, handler Handler) (c *Conn, err os.Error) { func newConn(rwc io.ReadWriteCloser, raddr string, handler Handler) (c *Conn, err os.Error) {
c = new(Conn); c = new(Conn);
c.RemoteAddr = raddr; c.RemoteAddr = raddr;
c.handler = handler; c.handler = handler;
@ -238,7 +238,7 @@ func (c *Conn) serve() {
// will not do anything else with the connection. // will not do anything else with the connection.
// It becomes the caller's responsibility to manage // It becomes the caller's responsibility to manage
// and close the connection. // and close the connection.
func (c *Conn) Hijack() (rwc io.ReadWriteClose, buf *bufio.BufReadWrite, err os.Error) { func (c *Conn) Hijack() (rwc io.ReadWriteCloser, buf *bufio.BufReadWrite, err os.Error) {
if c.hijacked { if c.hijacked {
return nil, nil, ErrHijacked; return nil, nil, ErrHijacked;
} }

View File

@ -16,44 +16,44 @@ import (
// ErrEOF is the error returned by FullRead and Copyn when they encounter EOF. // ErrEOF is the error returned by FullRead and Copyn when they encounter EOF.
var ErrEOF = os.NewError("EOF") var ErrEOF = os.NewError("EOF")
// Read is the interface that wraps the basic Read method. // Reader is the interface that wraps the basic Read method.
type Read interface { type Reader interface {
Read(p []byte) (n int, err os.Error); Read(p []byte) (n int, err os.Error);
} }
// Write is the interface that wraps the basic Write method. // Writer is the interface that wraps the basic Write method.
type Write interface { type Writer interface {
Write(p []byte) (n int, err os.Error); Write(p []byte) (n int, err os.Error);
} }
// Close is the interface that wraps the basic Close method. // Closer is the interface that wraps the basic Close method.
type Close interface { type Closer interface {
Close() os.Error; Close() os.Error;
} }
// ReadWrite is the interface that groups the basic Read and Write methods. // ReadWrite is the interface that groups the basic Read and Write methods.
type ReadWrite interface { type ReadWriter interface {
Read; Reader;
Write; Writer;
} }
// ReadClose is the interface that groups the basic Read and Close methods. // ReadCloser is the interface that groups the basic Read and Close methods.
type ReadClose interface { type ReadCloser interface {
Read; Reader;
Close; Closer;
} }
// WriteClose is the interface that groups the basic Write and Close methods. // WriteCloser is the interface that groups the basic Write and Close methods.
type WriteClose interface { type WriteCloser interface {
Write; Writer;
Close; Closer;
} }
// ReadWriteClose is the interface that groups the basic Read, Write and Close methods. // ReadWriteCloser is the interface that groups the basic Read, Write and Close methods.
type ReadWriteClose interface { type ReadWriteCloser interface {
Read; Reader;
Write; Writer;
Close; Closer;
} }
// Convert a string to an array of bytes for easy marshaling. // Convert a string to an array of bytes for easy marshaling.
@ -66,12 +66,12 @@ func StringBytes(s string) []byte {
} }
// 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 Write, 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(StringBytes(s))
} }
// FullRead reads r until the buffer buf is full, or until EOF or error. // FullRead reads r until the buffer buf is full, or until EOF or error.
func FullRead(r Read, buf []byte) (n int, err os.Error) { func FullRead(r Reader, buf []byte) (n int, err os.Error) {
n = 0; n = 0;
for n < len(buf) { for n < len(buf) {
nn, e := r.Read(buf[n:len(buf)]); nn, e := r.Read(buf[n:len(buf)]);
@ -91,7 +91,7 @@ func FullRead(r Read, buf []byte) (n int, err os.Error) {
// Convert something that implements Read into something // Convert something that implements Read into something
// whose Reads are always FullReads // whose Reads are always FullReads
type fullRead struct { type fullRead struct {
r Read; r Reader;
} }
func (fr *fullRead) Read(p []byte) (n int, err os.Error) { func (fr *fullRead) Read(p []byte) (n int, err os.Error) {
@ -101,7 +101,7 @@ func (fr *fullRead) Read(p []byte) (n int, err os.Error) {
// MakeFullReader takes r, an implementation of Read, and returns an object // MakeFullReader takes r, an implementation of Read, and returns an object
// that still implements Read but always calls FullRead underneath. // that still implements Read but always calls FullRead underneath.
func MakeFullReader(r Read) Read { func MakeFullReader(r Reader) Reader {
if fr, ok := r.(*fullRead); ok { if fr, ok := r.(*fullRead); ok {
// already a fullRead // already a fullRead
return r return r
@ -111,7 +111,7 @@ func MakeFullReader(r Read) Read {
// Copy n copies n bytes (or until EOF is reached) from src to dst. // Copy n copies n bytes (or until EOF is reached) from src to dst.
// It returns the number of bytes copied and the error, if any. // It returns the number of bytes copied and the error, if any.
func Copyn(src Read, dst Write, n int64) (written int64, err os.Error) { func Copyn(src Reader, dst Writer, n int64) (written int64, err os.Error) {
buf := make([]byte, 32*1024); buf := make([]byte, 32*1024);
for written < n { for written < n {
l := len(buf); l := len(buf);
@ -147,7 +147,7 @@ func Copyn(src Read, dst Write, n int64) (written int64, err os.Error) {
// Copy copies from src to dst until EOF is reached. // Copy copies from src to dst until EOF is reached.
// It returns the number of bytes copied and the error, if any. // It returns the number of bytes copied and the error, if any.
func Copy(src Read, dst Write) (written int64, err os.Error) { func Copy(src Reader, dst Writer) (written int64, err os.Error) {
buf := make([]byte, 32*1024); buf := make([]byte, 32*1024);
for { for {
nr, er := src.Read(buf); nr, er := src.Read(buf);

View File

@ -170,15 +170,15 @@ func (w *pipeWrite) finish() {
} }
// Pipe creates a synchronous in-memory pipe. // Pipe creates a synchronous in-memory pipe.
// Used to connect code expecting an io.Read // Used to connect code expecting an io.Reader
// with code expecting an io.Write. // with code expecting an io.Writer.
// //
// Reads on one end are matched by writes on the other. // Reads on one end are matched by writes on the other.
// Writes don't complete until all the data has been // Writes don't complete until all the data has been
// written or the read end is closed. Reads return // written or the read end is closed. Reads return
// any available data or block until the next write // any available data or block until the next write
// or the write end is closed. // or the write end is closed.
func Pipe() (io.ReadClose, io.WriteClose) { func Pipe() (io.ReadCloser, io.WriteCloser) {
p := new(pipe); p := new(pipe);
p.cr = make(chan []byte, 1); p.cr = make(chan []byte, 1);
p.cw = make(chan pipeReturn, 1); p.cw = make(chan pipeReturn, 1);

View File

@ -11,7 +11,7 @@ import (
"time"; "time";
) )
func checkWrite(t *testing.T, w io.Write, data []byte, c chan int) { func checkWrite(t *testing.T, w Writer, data []byte, c chan int) {
n, err := w.Write(data); n, err := w.Write(data);
if err != nil { if err != nil {
t.Errorf("write: %v", err); t.Errorf("write: %v", err);
@ -25,9 +25,9 @@ func checkWrite(t *testing.T, w io.Write, data []byte, c chan int) {
// Test a single read/write pair. // Test a single read/write pair.
func TestPipe1(t *testing.T) { func TestPipe1(t *testing.T) {
c := make(chan int); c := make(chan int);
r, w := io.Pipe(); r, w := Pipe();
var buf = make([]byte, 64); var buf = make([]byte, 64);
go checkWrite(t, w, io.StringBytes("hello, world"), c); go checkWrite(t, w, StringBytes("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);
@ -40,7 +40,7 @@ func TestPipe1(t *testing.T) {
w.Close(); w.Close();
} }
func reader(t *testing.T, r io.Read, c chan int) { func reader(t *testing.T, r Reader, c chan int) {
var buf = make([]byte, 64); var buf = make([]byte, 64);
for { for {
n, err := r.Read(buf); n, err := r.Read(buf);
@ -57,7 +57,7 @@ func reader(t *testing.T, r io.Read, c chan int) {
// Test a sequence of read/write pairs. // Test a sequence of read/write pairs.
func TestPipe2(t *testing.T) { func TestPipe2(t *testing.T) {
c := make(chan int); c := make(chan int);
r, w := io.Pipe(); r, w := Pipe();
go reader(t, r, c); go reader(t, r, c);
var buf = make([]byte, 64); var buf = make([]byte, 64);
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
@ -82,7 +82,7 @@ func TestPipe2(t *testing.T) {
} }
// Test a large write that requires multiple reads to satisfy. // Test a large write that requires multiple reads to satisfy.
func writer(w io.WriteClose, buf []byte, c chan pipeReturn) { func writer(w WriteCloser, buf []byte, c chan pipeReturn) {
n, err := w.Write(buf); n, err := w.Write(buf);
w.Close(); w.Close();
c <- pipeReturn{n, err}; c <- pipeReturn{n, err};
@ -90,7 +90,7 @@ func writer(w io.WriteClose, buf []byte, c chan pipeReturn) {
func TestPipe3(t *testing.T) { func TestPipe3(t *testing.T) {
c := make(chan pipeReturn); c := make(chan pipeReturn);
r, w := io.Pipe(); r, w := Pipe();
var wdat = make([]byte, 128); var wdat = make([]byte, 128);
for i := 0; i < len(wdat); i++ { for i := 0; i < len(wdat); i++ {
wdat[i] = byte(i); wdat[i] = byte(i);
@ -132,7 +132,7 @@ func TestPipe3(t *testing.T) {
// Test read after/before writer close. // Test read after/before writer close.
func delayClose(t *testing.T, cl io.Close, ch chan int) { func delayClose(t *testing.T, cl Closer, ch chan int) {
time.Sleep(1000*1000); // 1 ms time.Sleep(1000*1000); // 1 ms
if err := cl.Close(); err != nil { if err := cl.Close(); err != nil {
t.Errorf("delayClose: %v", err); t.Errorf("delayClose: %v", err);
@ -142,7 +142,7 @@ func delayClose(t *testing.T, cl io.Close, ch chan int) {
func testPipeReadClose(t *testing.T, async bool) { func testPipeReadClose(t *testing.T, async bool) {
c := make(chan int, 1); c := make(chan int, 1);
r, w := io.Pipe(); r, w := Pipe();
if async { if async {
go delayClose(t, w, c); go delayClose(t, w, c);
} else { } else {
@ -166,13 +166,13 @@ func testPipeReadClose(t *testing.T, async bool) {
func testPipeWriteClose(t *testing.T, async bool) { func testPipeWriteClose(t *testing.T, async bool) {
c := make(chan int, 1); c := make(chan int, 1);
r, w := io.Pipe(); r, w := Pipe();
if async { if async {
go delayClose(t, r, c); go delayClose(t, r, c);
} else { } else {
delayClose(t, r, c); delayClose(t, r, c);
} }
n, err := io.WriteString(w, "hello, world"); n, err := WriteString(w, "hello, world");
<-c; <-c;
if err != os.EPIPE { if err != os.EPIPE {
t.Errorf("write on closed pipe: %v", err); t.Errorf("write on closed pipe: %v", err);

View File

@ -38,8 +38,8 @@ const (
// Logger represents an active logging object. // Logger represents an active logging object.
type Logger struct { type Logger struct {
out0 io.Write; // first destination for output out0 io.Writer; // first destination for output
out1 io.Write; // second destination for output; may be nil out1 io.Writer; // second destination for output; may be nil
prefix string; // prefix to write at beginning of each line prefix string; // prefix to write at beginning of each line
flag int; // properties flag int; // properties
} }
@ -48,7 +48,7 @@ type Logger struct {
// destinations to which log data will be written; out1 may be nil. // destinations to which log data will be written; out1 may be nil.
// The prefix appears at the beginning of each generated log line. // The prefix appears at the beginning of each generated log line.
// The flag argument defines the logging properties. // The flag argument defines the logging properties.
func NewLogger(out0, out1 io.Write, prefix string, flag int) *Logger { func NewLogger(out0, out1 io.Writer, prefix string, flag int) *Logger {
return &Logger{out0, out1, prefix, flag} return &Logger{out0, out1, prefix, flag}
} }

View File

@ -11,7 +11,7 @@ import (
"testing"; "testing";
) )
func runEcho(fd io.ReadWrite, done chan<- int) { func runEcho(fd io.ReadWriter, done chan<- int) {
var buf [1024]byte; var buf [1024]byte;
for { for {

View File

@ -95,7 +95,7 @@ func (b *byteArray) append(s []byte) {
// //
type Writer struct { type Writer struct {
// configuration // configuration
output io.Write; output io.Writer;
cellwidth int; cellwidth int;
padding int; padding int;
padbytes [8]byte; padbytes [8]byte;
@ -168,7 +168,7 @@ const (
// to the tab width in the viewer displaying the result) // to the tab width in the viewer displaying the result)
// flags formatting control // flags formatting control
// //
func (b *Writer) Init(output io.Write, cellwidth, padding int, padchar byte, flags uint) *Writer { func (b *Writer) Init(output io.Writer, cellwidth, padding int, padchar byte, flags uint) *Writer {
if cellwidth < 0 { if cellwidth < 0 {
panic("negative cellwidth"); panic("negative cellwidth");
} }
@ -485,6 +485,6 @@ func (b *Writer) Write(buf []byte) (written int, err os.Error) {
// NewWriter allocates and initializes a new tabwriter.Writer. // NewWriter allocates and initializes a new tabwriter.Writer.
// The parameters are the same as for the the Init function. // The parameters are the same as for the the Init function.
// //
func NewWriter(output io.Write, cellwidth, padding int, padchar byte, flags uint) *Writer { func NewWriter(output io.Writer, cellwidth, padding int, padchar byte, flags uint) *Writer {
return new(Writer).Init(output, cellwidth, padding, padchar, flags) return new(Writer).Init(output, cellwidth, padding, padchar, flags)
} }

View File

@ -16,7 +16,7 @@ import (
// It is stored under the name "str" and is the default formatter. // It is stored under the name "str" and is the default formatter.
// You can override the default formatter by storing your default // You can override the default formatter by storing your default
// under the name "" in your custom formatter map. // under the name "" in your custom formatter map.
func StringFormatter(w io.Write, value interface{}, format string) { func StringFormatter(w io.Writer, value interface{}, format string) {
fmt.Fprint(w, value); fmt.Fprint(w, value);
} }
@ -27,7 +27,7 @@ var esc_gt = io.StringBytes("&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.
func HtmlEscape(w io.Write, s []byte) { func HtmlEscape(w io.Writer, s []byte) {
last := 0; last := 0;
for i, c := range s { for i, c := range s {
if c == '&' || c == '<' || c == '>' { if c == '&' || c == '<' || c == '>' {
@ -47,7 +47,7 @@ func HtmlEscape(w io.Write, s []byte) {
} }
// HtmlFormatter formats arbitrary values for HTML // HtmlFormatter formats arbitrary values for HTML
func HtmlFormatter(w io.Write, value interface{}, format string) { func HtmlFormatter(w io.Writer, value interface{}, format string) {
var b io.ByteBuffer; var b io.ByteBuffer;
fmt.Fprint(&b, value); fmt.Fprint(&b, value);
HtmlEscape(w, b.Data()); HtmlEscape(w, b.Data());

View File

@ -93,7 +93,7 @@ const (
// FormatterMap is the type describing the mapping from formatter // FormatterMap is the type describing the mapping from formatter
// names to the functions that implement them. // names to the functions that implement them.
type FormatterMap map[string] func(io.Write, interface{}, string) type FormatterMap map[string] func(io.Writer, interface{}, string)
// Built-in formatters. // Built-in formatters.
var builtins = FormatterMap { var builtins = FormatterMap {
@ -158,7 +158,7 @@ type Template struct {
type state struct { type state struct {
parent *state; // parent in hierarchy parent *state; // parent in hierarchy
data reflect.Value; // the driver data for this section etc. data reflect.Value; // the driver data for this section etc.
wr io.Write; // where to send output wr io.Writer; // where to send output
errors chan os.Error; // for reporting errors during execute errors chan os.Error; // for reporting errors during execute
} }
@ -769,7 +769,7 @@ func (t *Template) Parse(s string) os.Error {
// Execute applies a parsed template to the specified data object, // Execute applies a parsed template to the specified data object,
// generating output to wr. // generating output to wr.
func (t *Template) Execute(data interface{}, wr io.Write) os.Error { func (t *Template) Execute(data interface{}, wr io.Writer) os.Error {
// Extract the driver data. // Extract the driver data.
val := reflect.NewValue(data); val := reflect.NewValue(data);
errors := make(chan os.Error); errors := make(chan os.Error);

View File

@ -54,8 +54,8 @@ func plus1(v interface{}) string {
return fmt.Sprint(i + 1); return fmt.Sprint(i + 1);
} }
func writer(f func(interface{}) string) (func(io.Write, interface{}, string)) { func writer(f func(interface{}) string) (func(io.Writer, interface{}, string)) {
return func(w io.Write, v interface{}, format string) { return func(w io.Writer, v interface{}, format string) {
io.WriteString(w, f(v)); io.WriteString(w, f(v));
} }
} }

View File

@ -69,31 +69,31 @@ func hasExportedNames(names []*ast.Ident) bool {
// initializing an AST Printer. It is used to print tokens. // initializing an AST Printer. It is used to print tokens.
// //
type TokenPrinter interface { type TokenPrinter interface {
PrintLit(w io.Write, tok token.Token, value []byte); PrintLit(w io.Writer, tok token.Token, value []byte);
PrintIdent(w io.Write, value string); PrintIdent(w io.Writer, value string);
PrintToken(w io.Write, token token.Token); PrintToken(w io.Writer, token token.Token);
PrintComment(w io.Write, value []byte); PrintComment(w io.Writer, value []byte);
} }
type defaultPrinter struct {} type defaultPrinter struct {}
func (p defaultPrinter) PrintLit(w io.Write, tok token.Token, value []byte) { func (p defaultPrinter) PrintLit(w io.Writer, tok token.Token, value []byte) {
w.Write(value); w.Write(value);
} }
func (p defaultPrinter) PrintIdent(w io.Write, value string) { func (p defaultPrinter) PrintIdent(w io.Writer, value string) {
fmt.Fprint(w, value); fmt.Fprint(w, value);
} }
func (p defaultPrinter) PrintToken(w io.Write, token token.Token) { func (p defaultPrinter) PrintToken(w io.Writer, token token.Token) {
fmt.Fprint(w, token.String()); fmt.Fprint(w, token.String());
} }
func (p defaultPrinter) PrintComment(w io.Write, value []byte) { func (p defaultPrinter) PrintComment(w io.Writer, value []byte) {
w.Write(value); w.Write(value);
} }
@ -123,7 +123,7 @@ const (
type Printer struct { type Printer struct {
// output // output
text io.Write; text io.Writer;
// token printing // token printing
tprinter TokenPrinter; tprinter TokenPrinter;
@ -171,7 +171,7 @@ func (P *Printer) nextComments() {
} }
func (P *Printer) Init(text io.Write, tprinter TokenPrinter, comments []*ast.Comment, html bool) { func (P *Printer) Init(text io.Writer, tprinter TokenPrinter, comments []*ast.Comment, html bool) {
// writers // writers
P.text = text; P.text = text;
@ -435,7 +435,7 @@ func (P *Printer) Error(pos token.Position, tok token.Token, msg string) {
} }
// An astPrinter implements io.Write. // An astPrinter implements io.Writer.
// TODO this is not yet used. // TODO this is not yet used.
func (P *Printer) Write(p []byte) (n int, err os.Error) { func (P *Printer) Write(p []byte) (n int, err os.Error) {
// TODO // TODO

View File

@ -53,7 +53,7 @@ var (
// Escape comment text for HTML. // Escape comment text for HTML.
// Also, turn `` into &ldquo; and '' into &rdquo;. // Also, turn `` into &ldquo; and '' into &rdquo;.
func commentEscape(w io.Write, s []byte) { func commentEscape(w io.Writer, s []byte) {
last := 0; last := 0;
for i := 0; i < len(s)-1; i++ { for i := 0; i < len(s)-1; i++ {
if s[i] == s[i+1] && (s[i] == '`' || s[i] == '\'') { if s[i] == s[i+1] && (s[i] == '`' || s[i] == '\'') {
@ -137,7 +137,7 @@ func unindent(block [][]byte) {
// //
// TODO(rsc): I'd like to pass in an array of variable names []string // TODO(rsc): I'd like to pass in an array of variable names []string
// and then italicize those strings when they appear as words. // and then italicize those strings when they appear as words.
func ToHtml(w io.Write, s []byte) { func ToHtml(w io.Writer, s []byte) {
inpara := false; inpara := false;
/* TODO(rsc): 6g cant generate code for these /* TODO(rsc): 6g cant generate code for these

View File

@ -44,7 +44,7 @@ var (
// Format representation // Format representation
type ( type (
Formatter func(w io.Write, value interface{}, name string) bool; Formatter func(w io.Writer, value interface{}, name string) bool;
FormatterMap map[string]Formatter; FormatterMap map[string]Formatter;
) )
@ -476,7 +476,7 @@ func readSource(src interface{}) ([]byte, os.Error) {
} }
return s.Data(), nil; return s.Data(), nil;
case io.Read: case io.Reader:
var buf io.ByteBuffer; var buf io.ByteBuffer;
n, err := io.Copy(s, &buf); n, err := io.Copy(s, &buf);
if err != nil { if err != nil {
@ -654,7 +654,7 @@ func percentCount(s []byte) int {
} }
func rawPrintf(w io.Write, format []byte, value reflect.Value) { func rawPrintf(w io.Writer, format []byte, value reflect.Value) {
// TODO find a better way to do this // TODO find a better way to do this
x := value.Interface(); x := value.Interface();
switch percentCount(format) { switch percentCount(format) {
@ -724,7 +724,7 @@ func (ps *state) outdent() {
} }
func (ps *state) printIndented(w io.Write, s []byte) { func (ps *state) printIndented(w io.Writer, s []byte) {
// replace each '\n' with the indent + '\n' // replace each '\n' with the indent + '\n'
i0 := 0; i0 := 0;
for i := 0; i < len(s); i++ { for i := 0; i < len(s); i++ {
@ -738,7 +738,7 @@ func (ps *state) printIndented(w io.Write, s []byte) {
} }
func (ps *state) printf(w io.Write, format []byte, value reflect.Value) { func (ps *state) printf(w io.Writer, format []byte, value reflect.Value) {
if len(ps.indent_widths) == 0 { if len(ps.indent_widths) == 0 {
// no indentation // no indentation
rawPrintf(w, format, value); rawPrintf(w, format, value);
@ -751,10 +751,10 @@ func (ps *state) printf(w io.Write, format []byte, value reflect.Value) {
} }
func (ps *state) print(w io.Write, fexpr expr, value reflect.Value, index, level int) bool func (ps *state) print(w io.Writer, fexpr expr, value reflect.Value, index, level int) bool
// Returns true if a non-empty field value was found. // Returns true if a non-empty field value was found.
func (ps *state) print0(w io.Write, fexpr expr, value reflect.Value, index, level int) bool { func (ps *state) print0(w io.Writer, fexpr expr, value reflect.Value, index, level int) bool {
if fexpr == nil { if fexpr == nil {
return true; return true;
} }
@ -917,7 +917,7 @@ func printTrace(indent int, format string, a ...) {
} }
func (ps *state) print(w io.Write, fexpr expr, value reflect.Value, index, level int) bool { func (ps *state) print(w io.Writer, fexpr expr, value reflect.Value, index, level int) bool {
if *trace { if *trace {
printTrace(level, "%v, %d {\n", fexpr, /*value.Interface(), */index); printTrace(level, "%v, %d {\n", fexpr, /*value.Interface(), */index);
} }
@ -936,7 +936,7 @@ func (ps *state) print(w io.Write, fexpr expr, value reflect.Value, index, level
// Fprint formats each argument according to the format f // Fprint formats each argument according to the format f
// and writes to w. // and writes to w.
// //
func (f Format) Fprint(w io.Write, args ...) { func (f Format) Fprint(w io.Writer, args ...) {
value := reflect.NewValue(args).(reflect.StructValue); value := reflect.NewValue(args).(reflect.StructValue);
for i := 0; i < value.Len(); i++ { for i := 0; i < value.Len(); i++ {
fld := value.Field(i); fld := value.Field(i);

View File

@ -97,7 +97,7 @@ func isDir(name string) bool {
} }
func makeTabwriter(writer io.Write) *tabwriter.Writer { func makeTabwriter(writer io.Writer) *tabwriter.Writer {
padchar := byte(' '); padchar := byte(' ');
if *usetabs { if *usetabs {
padchar = '\t'; padchar = '\t';
@ -255,7 +255,7 @@ func toText(x interface{}) []byte {
// Template formatter for "html" format. // Template formatter for "html" format.
func htmlFmt(w io.Write, x interface{}, format string) { func htmlFmt(w io.Writer, x interface{}, format string) {
// Can do better than text in some cases. // Can do better than text in some cases.
switch v := x.(type) { switch v := x.(type) {
case ast.Decl: case ast.Decl:
@ -277,13 +277,13 @@ func htmlFmt(w io.Write, x interface{}, format string) {
// Template formatter for "html-comment" format. // Template formatter for "html-comment" format.
func htmlCommentFmt(w io.Write, x interface{}, format string) { func htmlCommentFmt(w io.Writer, x interface{}, format string) {
comment.ToHtml(w, toText(x)); comment.ToHtml(w, toText(x));
} }
// Template formatter for "" (default) format. // Template formatter for "" (default) format.
func textFmt(w io.Write, x interface{}, format string) { func textFmt(w io.Writer, x interface{}, format string) {
w.Write(toText(x)); w.Write(toText(x));
} }
@ -292,7 +292,7 @@ func textFmt(w io.Write, x interface{}, format string) {
// Writes out "/" if the os.Dir argument is a directory. // Writes out "/" if the os.Dir argument is a directory.
var slash = io.StringBytes("/"); var slash = io.StringBytes("/");
func dirSlashFmt(w io.Write, x interface{}, format string) { func dirSlashFmt(w io.Writer, x interface{}, format string) {
d := x.(os.Dir); // TODO(rsc): want *os.Dir d := x.(os.Dir); // TODO(rsc): want *os.Dir
if d.IsDirectory() { if d.IsDirectory() {
w.Write(slash); w.Write(slash);

View File

@ -61,7 +61,7 @@ func readFile(filename string) ([]byte, os.Error) {
// TODO(gri) move this function into tabwriter.go? (also used in godoc) // TODO(gri) move this function into tabwriter.go? (also used in godoc)
func makeTabwriter(writer io.Write) *tabwriter.Writer { func makeTabwriter(writer io.Writer) *tabwriter.Writer {
padchar := byte(' '); padchar := byte(' ');
if *usetabs { if *usetabs {
padchar = '\t'; padchar = '\t';
@ -94,17 +94,17 @@ func (h *ErrorHandler) Error(pos token.Position, msg string) {
} }
func isValidPos(w io.Write, value interface{}, name string) bool { func isValidPos(w io.Writer, value interface{}, name string) bool {
return value.(token.Position).Line > 0; return value.(token.Position).Line > 0;
} }
func isSend(w io.Write, value interface{}, name string) bool { func isSend(w io.Writer, value interface{}, name string) bool {
return value.(ast.ChanDir) & ast.SEND != 0; return value.(ast.ChanDir) & ast.SEND != 0;
} }
func isRecv(w io.Write, value interface{}, name string) bool { func isRecv(w io.Writer, value interface{}, name string) bool {
return value.(ast.ChanDir) & ast.RECV != 0; return value.(ast.ChanDir) & ast.RECV != 0;
} }