summaryrefslogtreecommitdiff
path: root/src/pkg/encoding
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/encoding')
-rw-r--r--src/pkg/encoding/ascii85/ascii85.go34
-rw-r--r--src/pkg/encoding/ascii85/ascii85_test.go2
-rw-r--r--src/pkg/encoding/base64/base64.go44
-rw-r--r--src/pkg/encoding/base64/base64_test.go2
-rw-r--r--src/pkg/encoding/binary/binary.go44
-rw-r--r--src/pkg/encoding/git85/git.go36
-rw-r--r--src/pkg/encoding/git85/git_test.go2
-rw-r--r--src/pkg/encoding/hex/hex.go22
-rw-r--r--src/pkg/encoding/pem/pem.go4
9 files changed, 95 insertions, 95 deletions
diff --git a/src/pkg/encoding/ascii85/ascii85.go b/src/pkg/encoding/ascii85/ascii85.go
index 819b263d0..7f6be9a15 100644
--- a/src/pkg/encoding/ascii85/ascii85.go
+++ b/src/pkg/encoding/ascii85/ascii85.go
@@ -46,13 +46,13 @@ func Encode(dst, src []byte) int {
v |= uint32(src[3]);
fallthrough;
case 3:
- v |= uint32(src[2])<<8;
+ v |= uint32(src[2]) << 8;
fallthrough;
case 2:
- v |= uint32(src[1])<<16;
+ v |= uint32(src[1]) << 16;
fallthrough;
case 1:
- v |= uint32(src[0])<<24
+ v |= uint32(src[0]) << 24
}
// Special case: zero (!!!!!) shortens to z.
@@ -65,14 +65,14 @@ func Encode(dst, src []byte) int {
// Otherwise, 5 base 85 digits starting at !.
for i := 4; i >= 0; i-- {
- dst[i] = '!'+byte(v%85);
+ dst[i] = '!' + byte(v%85);
v /= 85;
}
// If src was short, discard the low destination bytes.
m := 5;
if len(src) < 4 {
- m -= 4-len(src);
+ m -= 4 - len(src);
src = nil;
} else {
src = src[4:len(src)]
@@ -84,7 +84,7 @@ func Encode(dst, src []byte) int {
}
// MaxEncodedLen returns the maximum length of an encoding of n source bytes.
-func MaxEncodedLen(n int) int { return (n+3)/4*5 }
+func MaxEncodedLen(n int) int { return (n + 3) / 4 * 5 }
// NewEncoder returns a new ascii85 stream encoder. Data written to
// the returned writer will be encoded and then written to w.
@@ -127,11 +127,11 @@ func (e *encoder) Write(p []byte) (n int, err os.Error) {
// Large interior chunks.
for len(p) >= 4 {
- nn := len(e.out)/5*4;
+ nn := len(e.out) / 5 * 4;
if nn > len(p) {
nn = len(p)
}
- nn -= nn%4;
+ nn -= nn % 4;
if nn > 0 {
nout := Encode(&e.out, p[0:nn]);
if _, e.err = e.w.Write(e.out[0:nout]); e.err != nil {
@@ -156,7 +156,7 @@ func (e *encoder) Write(p []byte) (n int, err os.Error) {
func (e *encoder) Close() os.Error {
// If there's anything left in the buffer, flush it out
if e.err == nil && e.nbuf > 0 {
- nout := Encode(&e.out, e.buf[0 : e.nbuf]);
+ nout := Encode(&e.out, e.buf[0:e.nbuf]);
e.nbuf = 0;
_, e.err = e.w.Write(e.out[0:nout]);
}
@@ -207,10 +207,10 @@ func Decode(dst, src []byte, flush bool) (ndst, nsrc int, err os.Error) {
return 0, 0, CorruptInputError(i)
}
if nb == 5 {
- nsrc = i+1;
- dst[ndst] = byte(v>>24);
- dst[ndst+1] = byte(v>>16);
- dst[ndst+2] = byte(v>>8);
+ nsrc = i + 1;
+ dst[ndst] = byte(v >> 24);
+ dst[ndst+1] = byte(v >> 16);
+ dst[ndst+2] = byte(v >> 8);
dst[ndst+3] = byte(v);
ndst += 4;
nb = 0;
@@ -234,7 +234,7 @@ func Decode(dst, src []byte, flush bool) (ndst, nsrc int, err os.Error) {
v = v*85 + 84
}
for i := 0; i < nb-1; i++ {
- dst[ndst] = byte(v>>24);
+ dst[ndst] = byte(v >> 24);
v <<= 8;
ndst++;
}
@@ -276,10 +276,10 @@ func (d *decoder) Read(p []byte) (n int, err os.Error) {
// Decode leftover input from last read.
var nn, nsrc, ndst int;
if d.nbuf > 0 {
- ndst, nsrc, d.err = Decode(&d.outbuf, d.buf[0 : d.nbuf], d.readErr != nil);
+ ndst, nsrc, d.err = Decode(&d.outbuf, d.buf[0:d.nbuf], d.readErr != nil);
if ndst > 0 {
d.out = d.outbuf[0:ndst];
- d.nbuf = bytes.Copy(&d.buf, d.buf[nsrc : d.nbuf]);
+ d.nbuf = bytes.Copy(&d.buf, d.buf[nsrc:d.nbuf]);
continue; // copy out and return
}
}
@@ -294,7 +294,7 @@ func (d *decoder) Read(p []byte) (n int, err os.Error) {
}
// Read more data.
- nn, d.readErr = d.r.Read(d.buf[d.nbuf : len(d.buf)]);
+ nn, d.readErr = d.r.Read(d.buf[d.nbuf:len(d.buf)]);
d.nbuf += nn;
}
panic("unreachable");
diff --git a/src/pkg/encoding/ascii85/ascii85_test.go b/src/pkg/encoding/ascii85/ascii85_test.go
index 36cc019d0..40bb1a25e 100644
--- a/src/pkg/encoding/ascii85/ascii85_test.go
+++ b/src/pkg/encoding/ascii85/ascii85_test.go
@@ -83,7 +83,7 @@ func TestEncoderBuffering(t *testing.T) {
bb := &bytes.Buffer{};
encoder := NewEncoder(bb);
for pos := 0; pos < len(input); pos += bs {
- end := pos+bs;
+ end := pos + bs;
if end > len(input) {
end = len(input)
}
diff --git a/src/pkg/encoding/base64/base64.go b/src/pkg/encoding/base64/base64.go
index 83521ad45..b0f57f602 100644
--- a/src/pkg/encoding/base64/base64.go
+++ b/src/pkg/encoding/base64/base64.go
@@ -76,16 +76,16 @@ func (enc *Encoding) Encode(dst, src []byte) {
// destination quantum
switch len(src) {
default:
- dst[3] |= src[2]&0x3F;
- dst[2] |= src[2]>>6;
+ dst[3] |= src[2] & 0x3F;
+ dst[2] |= src[2] >> 6;
fallthrough;
case 2:
- dst[2] |= (src[1]<<2)&0x3F;
- dst[1] |= src[1]>>4;
+ dst[2] |= (src[1] << 2) & 0x3F;
+ dst[1] |= src[1] >> 4;
fallthrough;
case 1:
- dst[1] |= (src[0]<<4)&0x3F;
- dst[0] |= src[0]>>2;
+ dst[1] |= (src[0] << 4) & 0x3F;
+ dst[0] |= src[0] >> 2;
}
// Encode 6-bit blocks using the base64 alphabet
@@ -142,11 +142,11 @@ func (e *encoder) Write(p []byte) (n int, err os.Error) {
// Large interior chunks.
for len(p) >= 3 {
- nn := len(e.out)/4*3;
+ nn := len(e.out) / 4 * 3;
if nn > len(p) {
nn = len(p)
}
- nn -= nn%3;
+ nn -= nn % 3;
if nn > 0 {
e.enc.Encode(&e.out, p[0:nn]);
if _, e.err = e.w.Write(e.out[0 : nn/3*4]); e.err != nil {
@@ -171,7 +171,7 @@ func (e *encoder) Write(p []byte) (n int, err os.Error) {
func (e *encoder) Close() os.Error {
// If there's anything left in the buffer, flush it out
if e.err == nil && e.nbuf > 0 {
- e.enc.Encode(&e.out, e.buf[0 : e.nbuf]);
+ e.enc.Encode(&e.out, e.buf[0:e.nbuf]);
e.nbuf = 0;
_, e.err = e.w.Write(e.out[0:4]);
}
@@ -189,7 +189,7 @@ func NewEncoder(enc *Encoding, w io.Writer) io.WriteCloser {
// EncodedLen returns the length in bytes of the base64 encoding
// of an input buffer of length n.
-func (enc *Encoding) EncodedLen(n int) int { return (n+2)/3*4 }
+func (enc *Encoding) EncodedLen(n int) int { return (n + 2) / 3 * 4 }
/*
* Decoder
@@ -213,11 +213,11 @@ func (enc *Encoding) decode(dst, src []byte) (n int, end bool, err os.Error) {
dbufloop:
for j := 0; j < 4; j++ {
- in := src[i*4 + j];
- if in == '=' && j >= 2 && i == len(src)/4 - 1 {
+ in := src[i*4+j];
+ if in == '=' && j >= 2 && i == len(src)/4-1 {
// We've reached the end and there's
// padding
- if src[i*4 + 3] != '=' {
+ if src[i*4+3] != '=' {
return n, false, CorruptInputError(i*4 + 2)
}
dlen = j;
@@ -234,15 +234,15 @@ func (enc *Encoding) decode(dst, src []byte) (n int, end bool, err os.Error) {
// quantum
switch dlen {
case 4:
- dst[i*3 + 2] = dbuf[2]<<6 | dbuf[3];
+ dst[i*3+2] = dbuf[2]<<6 | dbuf[3];
fallthrough;
case 3:
- dst[i*3 + 1] = dbuf[1]<<4 | dbuf[2]>>2;
+ dst[i*3+1] = dbuf[1]<<4 | dbuf[2]>>2;
fallthrough;
case 2:
- dst[i*3 + 0] = dbuf[0]<<2 | dbuf[1]>>4
+ dst[i*3+0] = dbuf[0]<<2 | dbuf[1]>>4
}
- n += dlen-1;
+ n += dlen - 1;
}
return n, end, nil;
@@ -254,7 +254,7 @@ func (enc *Encoding) decode(dst, src []byte) (n int, end bool, err os.Error) {
// number of bytes successfully written and CorruptInputError.
func (enc *Encoding) Decode(dst, src []byte) (n int, err os.Error) {
if len(src)%4 != 0 {
- return 0, CorruptInputError(len(src)/4*4)
+ return 0, CorruptInputError(len(src) / 4 * 4)
}
n, _, err = enc.decode(dst, src);
@@ -269,7 +269,7 @@ type decoder struct {
buf [1024]byte; // leftover input
nbuf int;
out []byte; // leftover decoded output
- outbuf [1024/4*3]byte;
+ outbuf [1024 / 4 * 3]byte;
}
func (d *decoder) Read(p []byte) (n int, err os.Error) {
@@ -285,14 +285,14 @@ func (d *decoder) Read(p []byte) (n int, err os.Error) {
}
// Read a chunk.
- nn := len(p)/3*4;
+ nn := len(p) / 3 * 4;
if nn < 4 {
nn = 4
}
if nn > len(d.buf) {
nn = len(d.buf)
}
- nn, d.err = io.ReadAtLeast(d.r, d.buf[d.nbuf : nn], 4 - d.nbuf);
+ nn, d.err = io.ReadAtLeast(d.r, d.buf[d.nbuf:nn], 4-d.nbuf);
d.nbuf += nn;
if d.nbuf < 4 {
return 0, d.err
@@ -327,4 +327,4 @@ func NewDecoder(enc *Encoding, r io.Reader) io.Reader {
// DecodeLen returns the maximum length in bytes of the decoded data
// corresponding to n bytes of base64-encoded data.
-func (enc *Encoding) DecodedLen(n int) int { return n/4*3 }
+func (enc *Encoding) DecodedLen(n int) int { return n / 4 * 3 }
diff --git a/src/pkg/encoding/base64/base64_test.go b/src/pkg/encoding/base64/base64_test.go
index 2eb658bac..51e40ed7e 100644
--- a/src/pkg/encoding/base64/base64_test.go
+++ b/src/pkg/encoding/base64/base64_test.go
@@ -83,7 +83,7 @@ func TestEncoderBuffering(t *testing.T) {
bb := &bytes.Buffer{};
encoder := NewEncoder(StdEncoding, bb);
for pos := 0; pos < len(input); pos += bs {
- end := pos+bs;
+ end := pos + bs;
if end > len(input) {
end = len(input)
}
diff --git a/src/pkg/encoding/binary/binary.go b/src/pkg/encoding/binary/binary.go
index 62d42a6b8..abf2465cc 100644
--- a/src/pkg/encoding/binary/binary.go
+++ b/src/pkg/encoding/binary/binary.go
@@ -38,7 +38,7 @@ func (littleEndian) Uint16(b []byte) uint16 { return uint16(b[0]) | uint16(b[1])
func (littleEndian) PutUint16(b []byte, v uint16) {
b[0] = byte(v);
- b[1] = byte(v>>8);
+ b[1] = byte(v >> 8);
}
func (littleEndian) Uint32(b []byte) uint32 {
@@ -47,9 +47,9 @@ func (littleEndian) Uint32(b []byte) uint32 {
func (littleEndian) PutUint32(b []byte, v uint32) {
b[0] = byte(v);
- b[1] = byte(v>>8);
- b[2] = byte(v>>16);
- b[3] = byte(v>>24);
+ b[1] = byte(v >> 8);
+ b[2] = byte(v >> 16);
+ b[3] = byte(v >> 24);
}
func (littleEndian) Uint64(b []byte) uint64 {
@@ -59,13 +59,13 @@ func (littleEndian) Uint64(b []byte) uint64 {
func (littleEndian) PutUint64(b []byte, v uint64) {
b[0] = byte(v);
- b[1] = byte(v>>8);
- b[2] = byte(v>>16);
- b[3] = byte(v>>24);
- b[4] = byte(v>>32);
- b[5] = byte(v>>40);
- b[6] = byte(v>>48);
- b[7] = byte(v>>56);
+ b[1] = byte(v >> 8);
+ b[2] = byte(v >> 16);
+ b[3] = byte(v >> 24);
+ b[4] = byte(v >> 32);
+ b[5] = byte(v >> 40);
+ b[6] = byte(v >> 48);
+ b[7] = byte(v >> 56);
}
func (littleEndian) String() string { return "LittleEndian" }
@@ -77,7 +77,7 @@ type bigEndian unused
func (bigEndian) Uint16(b []byte) uint16 { return uint16(b[1]) | uint16(b[0])<<8 }
func (bigEndian) PutUint16(b []byte, v uint16) {
- b[0] = byte(v>>8);
+ b[0] = byte(v >> 8);
b[1] = byte(v);
}
@@ -86,9 +86,9 @@ func (bigEndian) Uint32(b []byte) uint32 {
}
func (bigEndian) PutUint32(b []byte, v uint32) {
- b[0] = byte(v>>24);
- b[1] = byte(v>>16);
- b[2] = byte(v>>8);
+ b[0] = byte(v >> 24);
+ b[1] = byte(v >> 16);
+ b[2] = byte(v >> 8);
b[3] = byte(v);
}
@@ -98,13 +98,13 @@ func (bigEndian) Uint64(b []byte) uint64 {
}
func (bigEndian) PutUint64(b []byte, v uint64) {
- b[0] = byte(v>>56);
- b[1] = byte(v>>48);
- b[2] = byte(v>>40);
- b[3] = byte(v>>32);
- b[4] = byte(v>>24);
- b[5] = byte(v>>16);
- b[6] = byte(v>>8);
+ b[0] = byte(v >> 56);
+ b[1] = byte(v >> 48);
+ b[2] = byte(v >> 40);
+ b[3] = byte(v >> 32);
+ b[4] = byte(v >> 24);
+ b[5] = byte(v >> 16);
+ b[6] = byte(v >> 8);
b[7] = byte(v);
}
diff --git a/src/pkg/encoding/git85/git.go b/src/pkg/encoding/git85/git.go
index d9c72e83c..cfe627566 100644
--- a/src/pkg/encoding/git85/git.go
+++ b/src/pkg/encoding/git85/git.go
@@ -56,15 +56,15 @@ func Encode(dst, src []byte) int {
n = 52
}
if n <= 27 {
- dst[ndst] = byte('A'+n-1)
+ dst[ndst] = byte('A' + n - 1)
} else {
- dst[ndst] = byte('a'+n-26-1)
+ dst[ndst] = byte('a' + n - 26 - 1)
}
ndst++;
for i := 0; i < n; i += 4 {
var v uint32;
for j := 0; j < 4 && i+j < n; j++ {
- v |= uint32(src[i+j])<<uint(24 - j*8)
+ v |= uint32(src[i+j]) << uint(24-j*8)
}
for j := 4; j >= 0; j-- {
dst[ndst+j] = encode[v%85];
@@ -103,16 +103,16 @@ func Decode(dst, src []byte) (n int, err os.Error) {
var l int;
switch ch := int(src[nsrc]); {
case 'A' <= ch && ch <= 'Z':
- l = ch-'A'+1
+ l = ch - 'A' + 1
case 'a' <= ch && ch <= 'z':
- l = ch-'a'+26+1
+ l = ch - 'a' + 26 + 1
default:
return ndst, CorruptInputError(nsrc)
}
if nsrc+1+l > len(src) {
return ndst, CorruptInputError(nsrc)
}
- el := (l+3)/4*5; // encoded len
+ el := (l + 3) / 4 * 5; // encoded len
if nsrc+1+el+1 > len(src) || src[nsrc+1+el] != '\n' {
return ndst, CorruptInputError(nsrc)
}
@@ -122,12 +122,12 @@ func Decode(dst, src []byte) (n int, err os.Error) {
for j := 0; j < 5; j++ {
ch := decode[line[i+j]];
if ch == 0 {
- return ndst, CorruptInputError(nsrc+1+i+j)
+ return ndst, CorruptInputError(nsrc + 1 + i + j)
}
v = v*85 + uint32(ch-1);
}
for j := 0; j < 4; j++ {
- dst[ndst] = byte(v>>24);
+ dst[ndst] = byte(v >> 24);
v <<= 8;
ndst++;
}
@@ -137,12 +137,12 @@ func Decode(dst, src []byte) (n int, err os.Error) {
if l%4 != 0 {
ndst -= 4 - l%4
}
- nsrc += 1+el+1;
+ nsrc += 1 + el + 1;
}
return ndst, nil;
}
-func MaxDecodedLen(n int) int { return n/5*4 }
+func MaxDecodedLen(n int) int { return n / 5 * 4 }
// NewEncoder returns a new GIT base85 stream encoder. Data written to
// the returned writer will be encoded and then written to w.
@@ -186,9 +186,9 @@ func (e *encoder) Write(p []byte) (n int, err os.Error) {
// Large interior chunks.
for len(p) >= 52 {
- nn := len(e.out)/(1 + 52/4*5 + 1)*52;
+ nn := len(e.out) / (1 + 52/4*5 + 1) * 52;
if nn > len(p) {
- nn = len(p)/52*52
+ nn = len(p) / 52 * 52
}
if nn > 0 {
nout := Encode(&e.out, p[0:nn]);
@@ -212,7 +212,7 @@ func (e *encoder) Write(p []byte) (n int, err os.Error) {
func (e *encoder) Close() os.Error {
// If there's anything left in the buffer, flush it out
if e.err == nil && e.nbuf > 0 {
- nout := Encode(&e.out, e.buf[0 : e.nbuf]);
+ nout := Encode(&e.out, e.buf[0:e.nbuf]);
e.nbuf = 0;
_, e.err = e.w.Write(e.out[0:nout]);
}
@@ -257,21 +257,21 @@ func (d *decoder) Read(p []byte) (n int, err os.Error) {
// Read and decode more input.
var nn int;
- nn, d.readErr = d.r.Read(d.buf[d.nbuf : len(d.buf)]);
+ nn, d.readErr = d.r.Read(d.buf[d.nbuf:len(d.buf)]);
d.nbuf += nn;
// Send complete lines to Decode.
- nl := bytes.LastIndex(d.buf[0 : d.nbuf], newline);
+ nl := bytes.LastIndex(d.buf[0:d.nbuf], newline);
if nl < 0 {
continue
}
- nn, d.err = Decode(&d.outbuf, d.buf[0 : nl+1]);
+ nn, d.err = Decode(&d.outbuf, d.buf[0:nl+1]);
if e, ok := d.err.(CorruptInputError); ok {
d.err = CorruptInputError(int64(e) + d.off)
}
d.out = d.outbuf[0:nn];
- d.nbuf = bytes.Copy(&d.buf, d.buf[nl+1 : d.nbuf]);
- d.off += int64(nl+1);
+ d.nbuf = bytes.Copy(&d.buf, d.buf[nl+1:d.nbuf]);
+ d.off += int64(nl + 1);
}
panic("unreacahable");
}
diff --git a/src/pkg/encoding/git85/git_test.go b/src/pkg/encoding/git85/git_test.go
index d956ed4ae..713524af2 100644
--- a/src/pkg/encoding/git85/git_test.go
+++ b/src/pkg/encoding/git85/git_test.go
@@ -90,7 +90,7 @@ func TestEncoderBuffering(t *testing.T) {
bb := &bytes.Buffer{};
encoder := NewEncoder(bb);
for pos := 0; pos < len(input); pos += bs {
- end := pos+bs;
+ end := pos + bs;
if end > len(input) {
end = len(input)
}
diff --git a/src/pkg/encoding/hex/hex.go b/src/pkg/encoding/hex/hex.go
index d97723db1..17c4ae842 100644
--- a/src/pkg/encoding/hex/hex.go
+++ b/src/pkg/encoding/hex/hex.go
@@ -14,7 +14,7 @@ import (
const hextable = "0123456789abcdef"
// EncodedLen returns the length of an encoding of n source bytes.
-func EncodedLen(n int) int { return n*2 }
+func EncodedLen(n int) int { return n * 2 }
// Encode encodes src into EncodedLen(len(src))
// bytes of dst. As a convenience, it returns the number
@@ -23,10 +23,10 @@ func EncodedLen(n int) int { return n*2 }
func Encode(dst, src []byte) int {
for i, v := range src {
dst[i*2] = hextable[v>>4];
- dst[i*2 + 1] = hextable[v&0x0f];
+ dst[i*2+1] = hextable[v&0x0f];
}
- return len(src)*2;
+ return len(src) * 2;
}
// OddLengthInputError results from decoding an odd length slice.
@@ -42,7 +42,7 @@ func (e InvalidHexCharError) String() string {
}
-func DecodedLen(x int) int { return x/2 }
+func DecodedLen(x int) int { return x / 2 }
// Decode decodes src into DecodedLen(len(src)) bytes, returning the actual
// number of bytes written to dst.
@@ -59,25 +59,25 @@ func Decode(dst, src []byte) (int, os.Error) {
if !ok {
return 0, InvalidHexCharError(src[i*2])
}
- b, ok := fromHexChar(src[i*2 + 1]);
+ b, ok := fromHexChar(src[i*2+1]);
if !ok {
- return 0, InvalidHexCharError(src[i*2 + 1])
+ return 0, InvalidHexCharError(src[i*2+1])
}
- dst[i] = (a<<4)|b;
+ dst[i] = (a << 4) | b;
}
- return len(src)/2, nil;
+ return len(src) / 2, nil;
}
// fromHexChar converts a hex character into its value and a success flag.
func fromHexChar(c byte) (byte, bool) {
switch {
case 0 <= c && c <= '9':
- return c-'0', true
+ return c - '0', true
case 'a' <= c && c <= 'f':
- return c-'a'+10, true
+ return c - 'a' + 10, true
case 'A' <= c && c <= 'F':
- return c-'A'+10, true
+ return c - 'A' + 10, true
}
return 0, false;
diff --git a/src/pkg/encoding/pem/pem.go b/src/pkg/encoding/pem/pem.go
index 640673b3e..409f07fb0 100644
--- a/src/pkg/encoding/pem/pem.go
+++ b/src/pkg/encoding/pem/pem.go
@@ -38,7 +38,7 @@ func getLine(data []byte) (line, rest []byte) {
i = len(data);
j = i;
} else {
- j = i+1;
+ j = i + 1;
if i > 0 && data[i-1] == '\r' {
i--
}
@@ -108,7 +108,7 @@ func Decode(data []byte) (p *Block, rest []byte) {
}
// TODO(agl): need to cope with values that spread across lines.
- key, val := line[0:i], line[i+1 : len(line)];
+ key, val := line[0:i], line[i+1:len(line)];
key = bytes.TrimSpace(key);
val = bytes.TrimSpace(val);
p.Headers[string(key)] = string(val);