diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-12-03 02:17:34 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-12-03 02:17:34 +0000 |
commit | 2fd401c8f190f1fe43e51a7f726f6ed6119a1f96 (patch) | |
tree | 7f76eff391f37fe6467ff4ffbc0c582c9959ea30 /libgo/go/encoding | |
parent | 02e9018f1616b23f1276151797216717b3564202 (diff) | |
download | gcc-2fd401c8f190f1fe43e51a7f726f6ed6119a1f96.zip gcc-2fd401c8f190f1fe43e51a7f726f6ed6119a1f96.tar.gz gcc-2fd401c8f190f1fe43e51a7f726f6ed6119a1f96.tar.bz2 |
libgo: Update to weekly.2011-11-02.
From-SVN: r181964
Diffstat (limited to 'libgo/go/encoding')
-rw-r--r-- | libgo/go/encoding/ascii85/ascii85.go | 17 | ||||
-rw-r--r-- | libgo/go/encoding/ascii85/ascii85_test.go | 12 | ||||
-rw-r--r-- | libgo/go/encoding/base32/base32.go | 17 | ||||
-rw-r--r-- | libgo/go/encoding/base32/base32_test.go | 16 | ||||
-rw-r--r-- | libgo/go/encoding/base64/base64.go | 19 | ||||
-rw-r--r-- | libgo/go/encoding/base64/base64_test.go | 18 | ||||
-rw-r--r-- | libgo/go/encoding/binary/binary.go | 12 | ||||
-rw-r--r-- | libgo/go/encoding/binary/binary_test.go | 6 | ||||
-rw-r--r-- | libgo/go/encoding/binary/varint.go | 12 | ||||
-rw-r--r-- | libgo/go/encoding/binary/varint_test.go | 6 | ||||
-rw-r--r-- | libgo/go/encoding/git85/git.go | 17 | ||||
-rw-r--r-- | libgo/go/encoding/git85/git_test.go | 12 | ||||
-rw-r--r-- | libgo/go/encoding/hex/hex.go | 13 | ||||
-rw-r--r-- | libgo/go/encoding/pem/pem.go | 7 |
14 files changed, 89 insertions, 95 deletions
diff --git a/libgo/go/encoding/ascii85/ascii85.go b/libgo/go/encoding/ascii85/ascii85.go index ead0c24..6f592f3 100644 --- a/libgo/go/encoding/ascii85/ascii85.go +++ b/libgo/go/encoding/ascii85/ascii85.go @@ -8,7 +8,6 @@ package ascii85 import ( "io" - "os" "strconv" ) @@ -93,14 +92,14 @@ func MaxEncodedLen(n int) int { return (n + 3) / 4 * 5 } func NewEncoder(w io.Writer) io.WriteCloser { return &encoder{w: w} } type encoder struct { - err os.Error + err error w io.Writer buf [4]byte // buffered data waiting to be encoded nbuf int // number of bytes in buf out [1024]byte // output buffer } -func (e *encoder) Write(p []byte) (n int, err os.Error) { +func (e *encoder) Write(p []byte) (n int, err error) { if e.err != nil { return 0, e.err } @@ -152,7 +151,7 @@ func (e *encoder) Write(p []byte) (n int, err os.Error) { // Close flushes any pending output from the encoder. // It is an error to call Write after calling Close. -func (e *encoder) Close() os.Error { +func (e *encoder) Close() error { // If there's anything left in the buffer, flush it out if e.err == nil && e.nbuf > 0 { nout := Encode(e.out[0:], e.buf[0:e.nbuf]) @@ -168,7 +167,7 @@ func (e *encoder) Close() os.Error { type CorruptInputError int64 -func (e CorruptInputError) String() string { +func (e CorruptInputError) Error() string { return "illegal ascii85 data at input byte " + strconv.Itoa64(int64(e)) } @@ -186,7 +185,7 @@ func (e CorruptInputError) String() string { // // NewDecoder wraps an io.Reader interface around Decode. // -func Decode(dst, src []byte, flush bool) (ndst, nsrc int, err os.Error) { +func Decode(dst, src []byte, flush bool) (ndst, nsrc int, err error) { var v uint32 var nb int for i, b := range src { @@ -246,8 +245,8 @@ func Decode(dst, src []byte, flush bool) (ndst, nsrc int, err os.Error) { func NewDecoder(r io.Reader) io.Reader { return &decoder{r: r} } type decoder struct { - err os.Error - readErr os.Error + err error + readErr error r io.Reader end bool // saw end of message buf [1024]byte // leftover input @@ -256,7 +255,7 @@ type decoder struct { outbuf [1024]byte } -func (d *decoder) Read(p []byte) (n int, err os.Error) { +func (d *decoder) Read(p []byte) (n int, err error) { if len(p) == 0 { return 0, nil } diff --git a/libgo/go/encoding/ascii85/ascii85_test.go b/libgo/go/encoding/ascii85/ascii85_test.go index fdfeb88..70e67d8 100644 --- a/libgo/go/encoding/ascii85/ascii85_test.go +++ b/libgo/go/encoding/ascii85/ascii85_test.go @@ -6,8 +6,8 @@ package ascii85 import ( "bytes" + "io" "io/ioutil" - "os" "testing" ) @@ -83,11 +83,11 @@ func TestEncoderBuffering(t *testing.T) { end = len(input) } n, err := encoder.Write(input[pos:end]) - testEqual(t, "Write(%q) gave error %v, want %v", input[pos:end], err, os.Error(nil)) + testEqual(t, "Write(%q) gave error %v, want %v", input[pos:end], err, error(nil)) testEqual(t, "Write(%q) gave length %v, want %v", input[pos:end], n, end-pos) } err := encoder.Close() - testEqual(t, "Close gave error %v, want %v", err, os.Error(nil)) + testEqual(t, "Close gave error %v, want %v", err, error(nil)) testEqual(t, "Encoding/%d of %q = %q, want %q", bs, bigtest.decoded, strip85(bb.String()), strip85(bigtest.encoded)) } } @@ -96,7 +96,7 @@ func TestDecode(t *testing.T) { for _, p := range pairs { dbuf := make([]byte, 4*len(p.encoded)) ndst, nsrc, err := Decode(dbuf, []byte(p.encoded), true) - 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, error(nil)) testEqual(t, "Decode(%q) = nsrc %v, want %v", p.encoded, nsrc, len(p.encoded)) testEqual(t, "Decode(%q) = ndst %v, want %v", p.encoded, ndst, len(p.decoded)) testEqual(t, "Decode(%q) = %q, want %q", p.encoded, string(dbuf[0:ndst]), p.decoded) @@ -113,7 +113,7 @@ func TestDecoder(t *testing.T) { testEqual(t, "Read from %q = length %v, want %v", p.encoded, len(dbuf), len(p.decoded)) testEqual(t, "Decoding of %q = %q, want %q", p.encoded, string(dbuf), p.decoded) if err != nil { - testEqual(t, "Read from %q = %v, want %v", p.encoded, err, os.EOF) + testEqual(t, "Read from %q = %v, want %v", p.encoded, err, io.EOF) } } } @@ -125,7 +125,7 @@ func TestDecoderBuffering(t *testing.T) { var total int for total = 0; total < len(bigtest.decoded); { n, err := decoder.Read(buf[total : total+bs]) - testEqual(t, "Read from %q at pos %d = %d, %v, want _, %v", bigtest.encoded, total, n, err, os.Error(nil)) + testEqual(t, "Read from %q at pos %d = %d, %v, want _, %v", bigtest.encoded, total, n, err, error(nil)) total += n } testEqual(t, "Decoding/%d of %q = %q, want %q", bs, bigtest.encoded, string(buf[0:total]), bigtest.decoded) diff --git a/libgo/go/encoding/base32/base32.go b/libgo/go/encoding/base32/base32.go index acace30..494c760 100644 --- a/libgo/go/encoding/base32/base32.go +++ b/libgo/go/encoding/base32/base32.go @@ -7,7 +7,6 @@ package base32 import ( "io" - "os" "strconv" ) @@ -127,7 +126,7 @@ func (enc *Encoding) Encode(dst, src []byte) { } type encoder struct { - err os.Error + err error enc *Encoding w io.Writer buf [5]byte // buffered data waiting to be encoded @@ -135,7 +134,7 @@ type encoder struct { out [1024]byte // output buffer } -func (e *encoder) Write(p []byte) (n int, err os.Error) { +func (e *encoder) Write(p []byte) (n int, err error) { if e.err != nil { return 0, e.err } @@ -187,7 +186,7 @@ func (e *encoder) Write(p []byte) (n int, err os.Error) { // Close flushes any pending output from the encoder. // It is an error to call Write after calling Close. -func (e *encoder) Close() os.Error { +func (e *encoder) Close() error { // If there's anything left in the buffer, flush it out if e.err == nil && e.nbuf > 0 { e.enc.Encode(e.out[0:], e.buf[0:e.nbuf]) @@ -216,7 +215,7 @@ func (enc *Encoding) EncodedLen(n int) int { return (n + 4) / 5 * 8 } type CorruptInputError int64 -func (e CorruptInputError) String() string { +func (e CorruptInputError) Error() string { return "illegal base32 data at input byte " + strconv.Itoa64(int64(e)) } @@ -224,7 +223,7 @@ func (e CorruptInputError) String() string { // indicates if end-of-message padding was encountered and thus any // additional data is an error. decode also assumes len(src)%8==0, // since it is meant for internal use. -func (enc *Encoding) decode(dst, src []byte) (n int, end bool, err os.Error) { +func (enc *Encoding) decode(dst, src []byte) (n int, end bool, err error) { for i := 0; i < len(src)/8 && !end; i++ { // Decode quantum using the base32 alphabet var dbuf [8]byte @@ -290,7 +289,7 @@ func (enc *Encoding) decode(dst, src []byte) (n int, end bool, err os.Error) { // DecodedLen(len(src)) bytes to dst and returns the number of bytes // written. If src contains invalid base32 data, it will return the // number of bytes successfully written and CorruptInputError. -func (enc *Encoding) Decode(dst, src []byte) (n int, err os.Error) { +func (enc *Encoding) Decode(dst, src []byte) (n int, err error) { if len(src)%8 != 0 { return 0, CorruptInputError(len(src) / 8 * 8) } @@ -300,7 +299,7 @@ func (enc *Encoding) Decode(dst, src []byte) (n int, err os.Error) { } type decoder struct { - err os.Error + err error enc *Encoding r io.Reader end bool // saw end of message @@ -310,7 +309,7 @@ type decoder struct { outbuf [1024 / 8 * 5]byte } -func (d *decoder) Read(p []byte) (n int, err os.Error) { +func (d *decoder) Read(p []byte) (n int, err error) { if d.err != nil { return 0, d.err } diff --git a/libgo/go/encoding/base32/base32_test.go b/libgo/go/encoding/base32/base32_test.go index 3fa1c2b..facf5d0 100644 --- a/libgo/go/encoding/base32/base32_test.go +++ b/libgo/go/encoding/base32/base32_test.go @@ -6,8 +6,8 @@ package base32 import ( "bytes" + "io" "io/ioutil" - "os" "testing" ) @@ -78,11 +78,11 @@ func TestEncoderBuffering(t *testing.T) { end = len(input) } n, err := encoder.Write(input[pos:end]) - testEqual(t, "Write(%q) gave error %v, want %v", input[pos:end], err, os.Error(nil)) + testEqual(t, "Write(%q) gave error %v, want %v", input[pos:end], err, error(nil)) testEqual(t, "Write(%q) gave length %v, want %v", input[pos:end], n, end-pos) } err := encoder.Close() - testEqual(t, "Close gave error %v, want %v", err, os.Error(nil)) + testEqual(t, "Close gave error %v, want %v", err, error(nil)) testEqual(t, "Encoding/%d of %q = %q, want %q", bs, bigtest.decoded, bb.String(), bigtest.encoded) } } @@ -91,7 +91,7 @@ func TestDecode(t *testing.T) { for _, p := range pairs { dbuf := make([]byte, StdEncoding.DecodedLen(len(p.encoded))) count, end, err := StdEncoding.decode(dbuf, []byte(p.encoded)) - 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, error(nil)) testEqual(t, "Decode(%q) = length %v, want %v", p.encoded, count, len(p.decoded)) if len(p.encoded) > 0 { testEqual(t, "Decode(%q) = end %v, want %v", p.encoded, end, (p.encoded[len(p.encoded)-1] == '=')) @@ -107,15 +107,15 @@ func TestDecoder(t *testing.T) { decoder := NewDecoder(StdEncoding, bytes.NewBufferString(p.encoded)) dbuf := make([]byte, StdEncoding.DecodedLen(len(p.encoded))) count, err := decoder.Read(dbuf) - if err != nil && err != os.EOF { + if err != nil && err != io.EOF { t.Fatal("Read failed", err) } testEqual(t, "Read from %q = length %v, want %v", p.encoded, count, len(p.decoded)) testEqual(t, "Decoding of %q = %q, want %q", p.encoded, string(dbuf[0:count]), p.decoded) - if err != os.EOF { + if err != io.EOF { count, err = decoder.Read(dbuf) } - testEqual(t, "Read from %q = %v, want %v", p.encoded, err, os.EOF) + testEqual(t, "Read from %q = %v, want %v", p.encoded, err, io.EOF) } } @@ -126,7 +126,7 @@ func TestDecoderBuffering(t *testing.T) { var total int for total = 0; total < len(bigtest.decoded); { n, err := decoder.Read(buf[total : total+bs]) - testEqual(t, "Read from %q at pos %d = %d, %v, want _, %v", bigtest.encoded, total, n, err, os.Error(nil)) + testEqual(t, "Read from %q at pos %d = %d, %v, want _, %v", bigtest.encoded, total, n, err, error(nil)) total += n } testEqual(t, "Decoding/%d of %q = %q, want %q", bs, bigtest.encoded, string(buf[0:total]), bigtest.decoded) diff --git a/libgo/go/encoding/base64/base64.go b/libgo/go/encoding/base64/base64.go index c6b2a13e..9451289 100644 --- a/libgo/go/encoding/base64/base64.go +++ b/libgo/go/encoding/base64/base64.go @@ -7,7 +7,6 @@ package base64 import ( "io" - "os" "strconv" ) @@ -114,7 +113,7 @@ func (enc *Encoding) EncodeToString(src []byte) string { } type encoder struct { - err os.Error + err error enc *Encoding w io.Writer buf [3]byte // buffered data waiting to be encoded @@ -122,7 +121,7 @@ type encoder struct { out [1024]byte // output buffer } -func (e *encoder) Write(p []byte) (n int, err os.Error) { +func (e *encoder) Write(p []byte) (n int, err error) { if e.err != nil { return 0, e.err } @@ -174,7 +173,7 @@ func (e *encoder) Write(p []byte) (n int, err os.Error) { // Close flushes any pending output from the encoder. // It is an error to call Write after calling Close. -func (e *encoder) Close() os.Error { +func (e *encoder) Close() error { // If there's anything left in the buffer, flush it out if e.err == nil && e.nbuf > 0 { e.enc.Encode(e.out[0:], e.buf[0:e.nbuf]) @@ -203,7 +202,7 @@ func (enc *Encoding) EncodedLen(n int) int { return (n + 2) / 3 * 4 } type CorruptInputError int64 -func (e CorruptInputError) String() string { +func (e CorruptInputError) Error() string { return "illegal base64 data at input byte " + strconv.Itoa64(int64(e)) } @@ -211,7 +210,7 @@ func (e CorruptInputError) String() string { // indicates if end-of-message padding was encountered and thus any // additional data is an error. decode also assumes len(src)%4==0, // since it is meant for internal use. -func (enc *Encoding) decode(dst, src []byte) (n int, end bool, err os.Error) { +func (enc *Encoding) decode(dst, src []byte) (n int, end bool, err error) { for i := 0; i < len(src)/4 && !end; i++ { // Decode quantum using the base64 alphabet var dbuf [4]byte @@ -258,7 +257,7 @@ func (enc *Encoding) decode(dst, src []byte) (n int, end bool, err os.Error) { // DecodedLen(len(src)) bytes to dst and returns the number of bytes // written. If src contains invalid base64 data, it will return the // number of bytes successfully written and CorruptInputError. -func (enc *Encoding) Decode(dst, src []byte) (n int, err os.Error) { +func (enc *Encoding) Decode(dst, src []byte) (n int, err error) { if len(src)%4 != 0 { return 0, CorruptInputError(len(src) / 4 * 4) } @@ -268,14 +267,14 @@ func (enc *Encoding) Decode(dst, src []byte) (n int, err os.Error) { } // DecodeString returns the bytes represented by the base64 string s. -func (enc *Encoding) DecodeString(s string) ([]byte, os.Error) { +func (enc *Encoding) DecodeString(s string) ([]byte, error) { dbuf := make([]byte, enc.DecodedLen(len(s))) n, err := enc.Decode(dbuf, []byte(s)) return dbuf[:n], err } type decoder struct { - err os.Error + err error enc *Encoding r io.Reader end bool // saw end of message @@ -285,7 +284,7 @@ type decoder struct { outbuf [1024 / 4 * 3]byte } -func (d *decoder) Read(p []byte) (n int, err os.Error) { +func (d *decoder) Read(p []byte) (n int, err error) { if d.err != nil { return 0, d.err } diff --git a/libgo/go/encoding/base64/base64_test.go b/libgo/go/encoding/base64/base64_test.go index c163dae..8310d8ab 100644 --- a/libgo/go/encoding/base64/base64_test.go +++ b/libgo/go/encoding/base64/base64_test.go @@ -6,8 +6,8 @@ package base64 import ( "bytes" + "io" "io/ioutil" - "os" "testing" ) @@ -82,11 +82,11 @@ func TestEncoderBuffering(t *testing.T) { end = len(input) } n, err := encoder.Write(input[pos:end]) - testEqual(t, "Write(%q) gave error %v, want %v", input[pos:end], err, os.Error(nil)) + testEqual(t, "Write(%q) gave error %v, want %v", input[pos:end], err, error(nil)) testEqual(t, "Write(%q) gave length %v, want %v", input[pos:end], n, end-pos) } err := encoder.Close() - testEqual(t, "Close gave error %v, want %v", err, os.Error(nil)) + testEqual(t, "Close gave error %v, want %v", err, error(nil)) testEqual(t, "Encoding/%d of %q = %q, want %q", bs, bigtest.decoded, bb.String(), bigtest.encoded) } } @@ -95,7 +95,7 @@ func TestDecode(t *testing.T) { for _, p := range pairs { dbuf := make([]byte, StdEncoding.DecodedLen(len(p.encoded))) count, end, err := StdEncoding.decode(dbuf, []byte(p.encoded)) - 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, error(nil)) testEqual(t, "Decode(%q) = length %v, want %v", p.encoded, count, len(p.decoded)) if len(p.encoded) > 0 { testEqual(t, "Decode(%q) = end %v, want %v", p.encoded, end, (p.encoded[len(p.encoded)-1] == '=')) @@ -103,7 +103,7 @@ func TestDecode(t *testing.T) { testEqual(t, "Decode(%q) = %q, want %q", p.encoded, string(dbuf[0:count]), p.decoded) dbuf, err = StdEncoding.DecodeString(p.encoded) - testEqual(t, "DecodeString(%q) = error %v, want %v", p.encoded, err, os.Error(nil)) + testEqual(t, "DecodeString(%q) = error %v, want %v", p.encoded, err, error(nil)) testEqual(t, "DecodeString(%q) = %q, want %q", string(dbuf), p.decoded) } } @@ -113,15 +113,15 @@ func TestDecoder(t *testing.T) { decoder := NewDecoder(StdEncoding, bytes.NewBufferString(p.encoded)) dbuf := make([]byte, StdEncoding.DecodedLen(len(p.encoded))) count, err := decoder.Read(dbuf) - if err != nil && err != os.EOF { + if err != nil && err != io.EOF { t.Fatal("Read failed", err) } testEqual(t, "Read from %q = length %v, want %v", p.encoded, count, len(p.decoded)) testEqual(t, "Decoding of %q = %q, want %q", p.encoded, string(dbuf[0:count]), p.decoded) - if err != os.EOF { + if err != io.EOF { count, err = decoder.Read(dbuf) } - testEqual(t, "Read from %q = %v, want %v", p.encoded, err, os.EOF) + testEqual(t, "Read from %q = %v, want %v", p.encoded, err, io.EOF) } } @@ -132,7 +132,7 @@ func TestDecoderBuffering(t *testing.T) { var total int for total = 0; total < len(bigtest.decoded); { n, err := decoder.Read(buf[total : total+bs]) - testEqual(t, "Read from %q at pos %d = %d, %v, want _, %v", bigtest.encoded, total, n, err, os.Error(nil)) + testEqual(t, "Read from %q at pos %d = %d, %v, want _, %v", bigtest.encoded, total, n, err, error(nil)) total += n } testEqual(t, "Decoding/%d of %q = %q, want %q", bs, bigtest.encoded, string(buf[0:total]), bigtest.decoded) diff --git a/libgo/go/encoding/binary/binary.go b/libgo/go/encoding/binary/binary.go index c58f736..65b9f01 100644 --- a/libgo/go/encoding/binary/binary.go +++ b/libgo/go/encoding/binary/binary.go @@ -8,9 +8,9 @@ package binary import ( + "errors" "math" "io" - "os" "reflect" ) @@ -124,7 +124,7 @@ func (bigEndian) GoString() string { return "binary.BigEndian" } // or an array or struct containing only fixed-size values. // Bytes read from r are decoded using the specified byte order // and written to successive fields of the data. -func Read(r io.Reader, order ByteOrder, data interface{}) os.Error { +func Read(r io.Reader, order ByteOrder, data interface{}) error { // Fast path for basic types. if n := intDestSize(data); n != 0 { var b [8]byte @@ -161,11 +161,11 @@ func Read(r io.Reader, order ByteOrder, data interface{}) os.Error { case reflect.Slice: v = d default: - return os.NewError("binary.Read: invalid type " + d.Type().String()) + return errors.New("binary.Read: invalid type " + d.Type().String()) } size := TotalSize(v) if size < 0 { - return os.NewError("binary.Read: invalid type " + v.Type().String()) + return errors.New("binary.Read: invalid type " + v.Type().String()) } d := &decoder{order: order, buf: make([]byte, size)} if _, err := io.ReadFull(r, d.buf); err != nil { @@ -183,7 +183,7 @@ func Read(r io.Reader, order ByteOrder, data interface{}) os.Error { // or an array or struct containing only fixed-size values. // Bytes written to w are encoded using the specified byte order // and read from successive fields of the data. -func Write(w io.Writer, order ByteOrder, data interface{}) os.Error { +func Write(w io.Writer, order ByteOrder, data interface{}) error { // Fast path for basic types. var b [8]byte var bs []byte @@ -244,7 +244,7 @@ func Write(w io.Writer, order ByteOrder, data interface{}) os.Error { v := reflect.Indirect(reflect.ValueOf(data)) size := TotalSize(v) if size < 0 { - return os.NewError("binary.Write: invalid type " + v.Type().String()) + return errors.New("binary.Write: invalid type " + v.Type().String()) } buf := make([]byte, size) e := &encoder{order: order, buf: buf} diff --git a/libgo/go/encoding/binary/binary_test.go b/libgo/go/encoding/binary/binary_test.go index ef20605..e753aa0 100644 --- a/libgo/go/encoding/binary/binary_test.go +++ b/libgo/go/encoding/binary/binary_test.go @@ -7,8 +7,8 @@ package binary import ( "bytes" "io" + "bytes" "math" - "os" "reflect" "testing" ) @@ -99,7 +99,7 @@ var little = []byte{ var src = []byte{1, 2, 3, 4, 5, 6, 7, 8} var res = []int32{0x01020304, 0x05060708} -func checkResult(t *testing.T, dir string, order ByteOrder, err os.Error, have, want interface{}) { +func checkResult(t *testing.T, dir string, order ByteOrder, err error, have, want interface{}) { if err != nil { t.Errorf("%v %v: %v", dir, order, err) return @@ -166,7 +166,7 @@ type byteSliceReader struct { remain []byte } -func (br *byteSliceReader) Read(p []byte) (int, os.Error) { +func (br *byteSliceReader) Read(p []byte) (int, error) { n := copy(p, br.remain) br.remain = br.remain[n:] return n, nil diff --git a/libgo/go/encoding/binary/varint.go b/libgo/go/encoding/binary/varint.go index c98e0e2..d4872ee 100644 --- a/libgo/go/encoding/binary/varint.go +++ b/libgo/go/encoding/binary/varint.go @@ -25,8 +25,8 @@ package binary // format incompatible with a varint encoding for larger numbers (say 128-bit). import ( + "errors" "io" - "os" ) // MaxVarintLenN is the maximum length of a varint-encoded N-bit integer. @@ -99,17 +99,17 @@ func Varint(buf []byte) (int64, int) { } // WriteUvarint encodes x and writes the result to w. -func WriteUvarint(w io.Writer, x uint64) os.Error { +func WriteUvarint(w io.Writer, x uint64) error { var buf [MaxVarintLen64]byte n := PutUvarint(buf[:], x) _, err := w.Write(buf[0:n]) return err } -var overflow = os.NewError("binary: varint overflows a 64-bit integer") +var overflow = errors.New("binary: varint overflows a 64-bit integer") // ReadUvarint reads an encoded unsigned integer from r and returns it as a uint64. -func ReadUvarint(r io.ByteReader) (uint64, os.Error) { +func ReadUvarint(r io.ByteReader) (uint64, error) { var x uint64 var s uint for i := 0; ; i++ { @@ -130,7 +130,7 @@ func ReadUvarint(r io.ByteReader) (uint64, os.Error) { } // WriteVarint encodes x and writes the result to w. -func WriteVarint(w io.Writer, x int64) os.Error { +func WriteVarint(w io.Writer, x int64) error { ux := uint64(x) << 1 if x < 0 { ux = ^ux @@ -139,7 +139,7 @@ func WriteVarint(w io.Writer, x int64) os.Error { } // ReadVarint reads an encoded unsigned integer from r and returns it as a uint64. -func ReadVarint(r io.ByteReader) (int64, os.Error) { +func ReadVarint(r io.ByteReader) (int64, error) { ux, err := ReadUvarint(r) // ok to continue in presence of error x := int64(ux >> 1) if ux&1 != 0 { diff --git a/libgo/go/encoding/binary/varint_test.go b/libgo/go/encoding/binary/varint_test.go index ef51f09..b553d6d 100644 --- a/libgo/go/encoding/binary/varint_test.go +++ b/libgo/go/encoding/binary/varint_test.go @@ -6,7 +6,7 @@ package binary import ( "bytes" - "os" + "io" "testing" ) @@ -131,13 +131,13 @@ func TestBufferTooSmall(t *testing.T) { } x, err := ReadUvarint(bytes.NewBuffer(buf)) - if x != 0 || err != os.EOF { + if x != 0 || err != io.EOF { t.Errorf("ReadUvarint(%v): got x = %d, err = %s", buf, x, err) } } } -func testOverflow(t *testing.T, buf []byte, n0 int, err0 os.Error) { +func testOverflow(t *testing.T, buf []byte, n0 int, err0 error) { x, n := Uvarint(buf) if x != 0 || n != n0 { t.Errorf("Uvarint(%v): got x = %d, n = %d; want 0, %d", buf, x, n, n0) diff --git a/libgo/go/encoding/git85/git.go b/libgo/go/encoding/git85/git.go index 6bb74f4..b6ad6e2 100644 --- a/libgo/go/encoding/git85/git.go +++ b/libgo/go/encoding/git85/git.go @@ -9,13 +9,12 @@ package git85 import ( "bytes" "io" - "os" "strconv" ) type CorruptInputError int64 -func (e CorruptInputError) String() string { +func (e CorruptInputError) Error() string { return "illegal git85 data at input byte " + strconv.Itoa64(int64(e)) } @@ -96,7 +95,7 @@ var newline = []byte{'\n'} // // If Decode encounters invalid input, it returns a CorruptInputError. // -func Decode(dst, src []byte) (n int, err os.Error) { +func Decode(dst, src []byte) (n int, err error) { ndst := 0 nsrc := 0 for nsrc < len(src) { @@ -153,14 +152,14 @@ func NewEncoder(w io.Writer) io.WriteCloser { return &encoder{w: w} } type encoder struct { w io.Writer - err os.Error + err error buf [52]byte nbuf int out [1024]byte nout int } -func (e *encoder) Write(p []byte) (n int, err os.Error) { +func (e *encoder) Write(p []byte) (n int, err error) { if e.err != nil { return 0, e.err } @@ -209,7 +208,7 @@ func (e *encoder) Write(p []byte) (n int, err os.Error) { return } -func (e *encoder) Close() os.Error { +func (e *encoder) Close() error { // If there's anything left in the buffer, flush it out if e.err == nil && e.nbuf > 0 { nout := Encode(e.out[0:], e.buf[0:e.nbuf]) @@ -224,8 +223,8 @@ func NewDecoder(r io.Reader) io.Reader { return &decoder{r: r} } type decoder struct { r io.Reader - err os.Error - readErr os.Error + err error + readErr error buf [1024]byte nbuf int out []byte @@ -233,7 +232,7 @@ type decoder struct { off int64 } -func (d *decoder) Read(p []byte) (n int, err os.Error) { +func (d *decoder) Read(p []byte) (n int, err error) { if len(p) == 0 { return 0, nil } diff --git a/libgo/go/encoding/git85/git_test.go b/libgo/go/encoding/git85/git_test.go index c76385c..81f5b0e 100644 --- a/libgo/go/encoding/git85/git_test.go +++ b/libgo/go/encoding/git85/git_test.go @@ -6,8 +6,8 @@ package git85 import ( "bytes" + "io" "io/ioutil" - "os" "testing" ) @@ -90,11 +90,11 @@ func TestEncoderBuffering(t *testing.T) { end = len(input) } n, err := encoder.Write(input[pos:end]) - testEqual(t, "Write(%q) gave error %v, want %v", input[pos:end], err, os.Error(nil)) + testEqual(t, "Write(%q) gave error %v, want %v", input[pos:end], err, error(nil)) testEqual(t, "Write(%q) gave length %v, want %v", input[pos:end], n, end-pos) } err := encoder.Close() - testEqual(t, "Close gave error %v, want %v", err, os.Error(nil)) + testEqual(t, "Close gave error %v, want %v", err, error(nil)) testEqual(t, "Encoding/%d of %q = %q, want %q", bs, gitBigtest.decoded, bb.String(), gitBigtest.encoded) } } @@ -103,7 +103,7 @@ func TestDecode(t *testing.T) { for _, p := range gitPairs { dbuf := make([]byte, 4*len(p.encoded)) ndst, err := Decode(dbuf, []byte(p.encoded)) - 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, error(nil)) testEqual(t, "Decode(%q) = ndst %v, want %v", p.encoded, ndst, len(p.decoded)) testEqual(t, "Decode(%q) = %q, want %q", p.encoded, string(dbuf[0:ndst]), p.decoded) } @@ -119,7 +119,7 @@ func TestDecoder(t *testing.T) { testEqual(t, "Read from %q = length %v, want %v", p.encoded, len(dbuf), len(p.decoded)) testEqual(t, "Decoding of %q = %q, want %q", p.encoded, string(dbuf), p.decoded) if err != nil { - testEqual(t, "Read from %q = %v, want %v", p.encoded, err, os.EOF) + testEqual(t, "Read from %q = %v, want %v", p.encoded, err, io.EOF) } } } @@ -131,7 +131,7 @@ func TestDecoderBuffering(t *testing.T) { var total int for total = 0; total < len(gitBigtest.decoded); { n, err := decoder.Read(buf[total : total+bs]) - testEqual(t, "Read from %q at pos %d = %d, %v, want _, %v", gitBigtest.encoded, total, n, err, os.Error(nil)) + testEqual(t, "Read from %q at pos %d = %d, %v, want _, %v", gitBigtest.encoded, total, n, err, error(nil)) total += n } testEqual(t, "Decoding/%d of %q = %q, want %q", bs, gitBigtest.encoded, string(buf[0:total]), gitBigtest.decoded) diff --git a/libgo/go/encoding/hex/hex.go b/libgo/go/encoding/hex/hex.go index e7ea8b0..eb7e7ca 100644 --- a/libgo/go/encoding/hex/hex.go +++ b/libgo/go/encoding/hex/hex.go @@ -8,7 +8,6 @@ package hex import ( "bytes" "io" - "os" "strconv" ) @@ -33,12 +32,12 @@ func Encode(dst, src []byte) int { // OddLengthInputError results from decoding an odd length slice. type OddLengthInputError struct{} -func (OddLengthInputError) String() string { return "odd length hex string" } +func (OddLengthInputError) Error() string { return "odd length hex string" } // InvalidHexCharError results from finding an invalid character in a hex string. type InvalidHexCharError byte -func (e InvalidHexCharError) String() string { +func (e InvalidHexCharError) Error() string { return "invalid hex char: " + strconv.Itoa(int(e)) } @@ -49,7 +48,7 @@ func DecodedLen(x int) int { return x / 2 } // // If Decode encounters invalid input, it returns an OddLengthInputError or an // InvalidHexCharError. -func Decode(dst, src []byte) (int, os.Error) { +func Decode(dst, src []byte) (int, error) { if len(src)%2 == 1 { return 0, OddLengthInputError{} } @@ -91,7 +90,7 @@ func EncodeToString(src []byte) string { } // DecodeString returns the bytes represented by the hexadecimal string s. -func DecodeString(s string) ([]byte, os.Error) { +func DecodeString(s string) ([]byte, error) { src := []byte(s) dst := make([]byte, DecodedLen(len(src))) _, err := Decode(dst, src) @@ -133,7 +132,7 @@ func toChar(b byte) byte { return b } -func (h *dumper) Write(data []byte) (n int, err os.Error) { +func (h *dumper) Write(data []byte) (n int, err error) { // Output lines look like: // 00000010 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d |./0123456789:;<=| // ^ offset ^ extra space ^ ASCII of line. @@ -185,7 +184,7 @@ func (h *dumper) Write(data []byte) (n int, err os.Error) { return } -func (h *dumper) Close() (err os.Error) { +func (h *dumper) Close() (err error) { // See the comments in Write() for the details of this format. if h.used == 0 { return diff --git a/libgo/go/encoding/pem/pem.go b/libgo/go/encoding/pem/pem.go index 12689b5..3eb7c9f 100644 --- a/libgo/go/encoding/pem/pem.go +++ b/libgo/go/encoding/pem/pem.go @@ -11,7 +11,6 @@ import ( "bytes" "encoding/base64" "io" - "os" ) // A Block represents a PEM encoded structure. @@ -170,7 +169,7 @@ type lineBreaker struct { out io.Writer } -func (l *lineBreaker) Write(b []byte) (n int, err os.Error) { +func (l *lineBreaker) Write(b []byte) (n int, err error) { if l.used+len(b) < pemLineLength { copy(l.line[l.used:], b) l.used += len(b) @@ -197,7 +196,7 @@ func (l *lineBreaker) Write(b []byte) (n int, err os.Error) { return l.Write(b[excess:]) } -func (l *lineBreaker) Close() (err os.Error) { +func (l *lineBreaker) Close() (err error) { if l.used > 0 { _, err = l.out.Write(l.line[0:l.used]) if err != nil { @@ -209,7 +208,7 @@ func (l *lineBreaker) Close() (err os.Error) { return } -func Encode(out io.Writer, b *Block) (err os.Error) { +func Encode(out io.Writer, b *Block) (err error) { _, err = out.Write(pemStart[1:]) if err != nil { return |