summaryrefslogtreecommitdiff
path: root/src/pkg/encoding/git85
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/encoding/git85')
-rw-r--r--src/pkg/encoding/git85/git.go46
-rw-r--r--src/pkg/encoding/git85/git_test.go26
2 files changed, 36 insertions, 36 deletions
diff --git a/src/pkg/encoding/git85/git.go b/src/pkg/encoding/git85/git.go
index e49251fb3..d9c72e83c 100644
--- a/src/pkg/encoding/git85/git.go
+++ b/src/pkg/encoding/git85/git.go
@@ -16,7 +16,7 @@ import (
type CorruptInputError int64
func (e CorruptInputError) String() string {
- return "illegal git85 data at input byte" + strconv.Itoa64(int64(e));
+ return "illegal git85 data at input byte" + strconv.Itoa64(int64(e))
}
const encode = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~"
@@ -53,18 +53,18 @@ func Encode(dst, src []byte) int {
for len(src) > 0 {
n := len(src);
if n > 52 {
- n = 52;
+ 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];
@@ -82,7 +82,7 @@ func Encode(dst, src []byte) int {
// EncodedLen returns the length of an encoding of n source bytes.
func EncodedLen(n int) int {
if n == 0 {
- return 0;
+ return 0
}
// 5 bytes per 4 bytes of input, rounded up.
// 2 extra bytes for each line of 52 src bytes, rounded up.
@@ -103,18 +103,18 @@ 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);
+ return ndst, CorruptInputError(nsrc)
}
if nsrc+1+l > len(src) {
- return ndst, CorruptInputError(nsrc);
+ return ndst, CorruptInputError(nsrc)
}
el := (l+3)/4*5; // encoded len
if nsrc+1+el+1 > len(src) || src[nsrc+1+el] != '\n' {
- return ndst, CorruptInputError(nsrc);
+ return ndst, CorruptInputError(nsrc)
}
line := src[nsrc+1 : nsrc+1+el];
for i := 0; i < el; i += 5 {
@@ -122,7 +122,7 @@ 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);
}
@@ -135,7 +135,7 @@ func Decode(dst, src []byte) (n int, err os.Error) {
// Last fragment may have run too far (but there was room in dst).
// Back up.
if l%4 != 0 {
- ndst -= 4 - l%4;
+ ndst -= 4 - l%4
}
nsrc += 1+el+1;
}
@@ -162,7 +162,7 @@ type encoder struct {
func (e *encoder) Write(p []byte) (n int, err os.Error) {
if e.err != nil {
- return 0, e.err;
+ return 0, e.err
}
// Leading fringe.
@@ -175,11 +175,11 @@ func (e *encoder) Write(p []byte) (n int, err os.Error) {
n += i;
p = p[i:len(p)];
if e.nbuf < 52 {
- return;
+ return
}
nout := Encode(&e.out, &e.buf);
if _, e.err = e.w.Write(e.out[0:nout]); e.err != nil {
- return n, e.err;
+ return n, e.err
}
e.nbuf = 0;
}
@@ -188,12 +188,12 @@ func (e *encoder) Write(p []byte) (n int, err os.Error) {
for len(p) >= 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]);
if _, e.err = e.w.Write(e.out[0:nout]); e.err != nil {
- return n, e.err;
+ return n, e.err
}
}
n += nn;
@@ -202,7 +202,7 @@ func (e *encoder) Write(p []byte) (n int, err os.Error) {
// Trailing fringe.
for i := 0; i < len(p); i++ {
- e.buf[i] = p[i];
+ e.buf[i] = p[i]
}
e.nbuf = len(p);
n += len(p);
@@ -235,7 +235,7 @@ type decoder struct {
func (d *decoder) Read(p []byte) (n int, err os.Error) {
if len(p) == 0 {
- return 0, nil;
+ return 0, nil
}
for {
@@ -248,7 +248,7 @@ func (d *decoder) Read(p []byte) (n int, err os.Error) {
// Out of decoded output. Check errors.
if d.err != nil {
- return 0, d.err;
+ return 0, d.err
}
if d.readErr != nil {
d.err = d.readErr;
@@ -263,11 +263,11 @@ func (d *decoder) Read(p []byte) (n int, err os.Error) {
// Send complete lines to Decode.
nl := bytes.LastIndex(d.buf[0 : d.nbuf], newline);
if nl < 0 {
- continue;
+ continue
}
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.err = CorruptInputError(int64(e) + d.off)
}
d.out = d.outbuf[0:nn];
d.nbuf = bytes.Copy(&d.buf, d.buf[nl+1 : d.nbuf]);
diff --git a/src/pkg/encoding/git85/git_test.go b/src/pkg/encoding/git85/git_test.go
index fbe675e81..d956ed4ae 100644
--- a/src/pkg/encoding/git85/git_test.go
+++ b/src/pkg/encoding/git85/git_test.go
@@ -32,13 +32,13 @@ func TestGitTable(t *testing.T) {
var saw [256]bool;
for i, c := range encode {
if decode[c] != uint8(i+1) {
- t.Errorf("decode['%c'] = %d, want %d", c, decode[c], i+1);
+ t.Errorf("decode['%c'] = %d, want %d", c, decode[c], i+1)
}
saw[c] = true;
}
for i, b := range saw {
if !b && decode[i] != 0 {
- t.Errorf("decode[%d] = %d, want 0", i, decode[i]);
+ t.Errorf("decode[%d] = %d, want 0", i, decode[i])
}
}
}
@@ -67,7 +67,7 @@ func TestEncode(t *testing.T) {
buf := make([]byte, EncodedLen(len(p.decoded)));
n := Encode(buf, strings.Bytes(p.decoded));
if n != len(buf) {
- t.Errorf("EncodedLen does not agree with Encode");
+ t.Errorf("EncodedLen does not agree with Encode")
}
buf = buf[0:n];
testEqual(t, "Encode(%q) = %q, want %q", p.decoded, string(buf), p.encoded);
@@ -92,7 +92,7 @@ func TestEncoderBuffering(t *testing.T) {
for pos := 0; pos < len(input); pos += bs {
end := pos+bs;
if end > len(input) {
- end = len(input);
+ 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));
@@ -119,12 +119,12 @@ func TestDecoder(t *testing.T) {
decoder := NewDecoder(bytes.NewBufferString(p.encoded));
dbuf, err := io.ReadAll(decoder);
if err != nil {
- t.Fatal("Read failed", err);
+ t.Fatal("Read failed", err)
}
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, os.EOF)
}
}
}
@@ -158,9 +158,9 @@ func TestDecodeCorrupt(t *testing.T) {
_, err := Decode(dbuf, strings.Bytes(e.e));
switch err := err.(type) {
case CorruptInputError:
- testEqual(t, "Corruption in %q at offset %v, want %v", e.e, int(err), e.p);
+ testEqual(t, "Corruption in %q at offset %v, want %v", e.e, int(err), e.p)
default:
- t.Error("Decoder failed to detect corruption in", e);
+ t.Error("Decoder failed to detect corruption in", e)
}
}
}
@@ -170,28 +170,28 @@ func TestGitBig(t *testing.T) {
raw := make([]byte, n);
const alpha = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
for i := 0; i < n; i++ {
- raw[i] = alpha[i%len(alpha)];
+ raw[i] = alpha[i%len(alpha)]
}
encoded := new(bytes.Buffer);
w := NewEncoder(encoded);
nn, err := w.Write(raw);
if nn != n || err != nil {
- t.Fatalf("Encoder.Write(raw) = %d, %v want %d, nil", nn, err, n);
+ t.Fatalf("Encoder.Write(raw) = %d, %v want %d, nil", nn, err, n)
}
err = w.Close();
if err != nil {
- t.Fatalf("Encoder.Close() = %v want nil", err);
+ t.Fatalf("Encoder.Close() = %v want nil", err)
}
decoded, err := io.ReadAll(NewDecoder(encoded));
if err != nil {
- t.Fatalf("io.ReadAll(NewDecoder(...)): %v", err);
+ 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++ {
if decoded[i] != raw[i] {
- break;
+ break
}
}
t.Errorf("Decode(Encode(%d-byte string)) failed at offset %d", n, i);