summaryrefslogtreecommitdiff
path: root/src/pkg/encoding/ascii85/ascii85.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2009-12-15 15:27:16 -0800
committerRobert Griesemer <gri@golang.org>2009-12-15 15:27:16 -0800
commit881d6064d23d9da5c7ff368bc7d41d271290deff (patch)
tree44d5d948e3f27cc7eff15ec8cd7ee5165d9a7e90 /src/pkg/encoding/ascii85/ascii85.go
parentd9dfea3ebd51cea89fef8afc6b2377c2958b24f1 (diff)
downloadgolang-881d6064d23d9da5c7ff368bc7d41d271290deff.tar.gz
1) Change default gofmt default settings for
parsing and printing to new syntax. Use -oldparser to parse the old syntax, use -oldprinter to print the old syntax. 2) Change default gofmt formatting settings to use tabs for indentation only and to use spaces for alignment. This will make the code alignment insensitive to an editor's tabwidth. Use -spaces=false to use tabs for alignment. 3) Manually changed src/exp/parser/parser_test.go so that it doesn't try to parse the parser's source files using the old syntax (they have new syntax now). 4) gofmt -w src misc test/bench 2nd set of files. R=rsc CC=golang-dev http://codereview.appspot.com/179067
Diffstat (limited to 'src/pkg/encoding/ascii85/ascii85.go')
-rw-r--r--src/pkg/encoding/ascii85/ascii85.go190
1 files changed, 95 insertions, 95 deletions
diff --git a/src/pkg/encoding/ascii85/ascii85.go b/src/pkg/encoding/ascii85/ascii85.go
index ac446baf8..67d6ef7ed 100644
--- a/src/pkg/encoding/ascii85/ascii85.go
+++ b/src/pkg/encoding/ascii85/ascii85.go
@@ -7,9 +7,9 @@
package ascii85
import (
- "io";
- "os";
- "strconv";
+ "io"
+ "os"
+ "strconv"
)
/*
@@ -30,74 +30,74 @@ func Encode(dst, src []byte) int {
return 0
}
- n := 0;
+ n := 0
for len(src) > 0 {
- dst[0] = 0;
- dst[1] = 0;
- dst[2] = 0;
- dst[3] = 0;
- dst[4] = 0;
+ dst[0] = 0
+ dst[1] = 0
+ dst[2] = 0
+ dst[3] = 0
+ dst[4] = 0
// Unpack 4 bytes into uint32 to repack into base 85 5-byte.
- var v uint32;
+ var v uint32
switch len(src) {
default:
- v |= uint32(src[3]);
- fallthrough;
+ v |= uint32(src[3])
+ fallthrough
case 3:
- v |= uint32(src[2]) << 8;
- fallthrough;
+ v |= uint32(src[2]) << 8
+ fallthrough
case 2:
- v |= uint32(src[1]) << 16;
- fallthrough;
+ v |= uint32(src[1]) << 16
+ fallthrough
case 1:
v |= uint32(src[0]) << 24
}
// Special case: zero (!!!!!) shortens to z.
if v == 0 && len(src) >= 4 {
- dst[0] = 'z';
- dst = dst[1:];
- n++;
- continue;
+ dst[0] = 'z'
+ dst = dst[1:]
+ n++
+ continue
}
// Otherwise, 5 base 85 digits starting at !.
for i := 4; i >= 0; i-- {
- dst[i] = '!' + byte(v%85);
- v /= 85;
+ dst[i] = '!' + byte(v%85)
+ v /= 85
}
// If src was short, discard the low destination bytes.
- m := 5;
+ m := 5
if len(src) < 4 {
- m -= 4 - len(src);
- src = nil;
+ m -= 4 - len(src)
+ src = nil
} else {
src = src[4:]
}
- dst = dst[m:];
- n += m;
+ dst = dst[m:]
+ n += m
}
- return n;
+ return n
}
// 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.
// Ascii85 encodings operate in 32-bit blocks; when finished
// writing, the caller must Close the returned encoder to flush any
// trailing partial block.
-func NewEncoder(w io.Writer) io.WriteCloser { return &encoder{w: w} }
+func NewEncoder(w io.Writer) io.WriteCloser { return &encoder{w: w} }
type encoder struct {
- err os.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
+ err os.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) {
@@ -107,47 +107,47 @@ func (e *encoder) Write(p []byte) (n int, err os.Error) {
// Leading fringe.
if e.nbuf > 0 {
- var i int;
+ var i int
for i = 0; i < len(p) && e.nbuf < 4; i++ {
- e.buf[e.nbuf] = p[i];
- e.nbuf++;
+ e.buf[e.nbuf] = p[i]
+ e.nbuf++
}
- n += i;
- p = p[i:];
+ n += i
+ p = p[i:]
if e.nbuf < 4 {
return
}
- nout := Encode(&e.out, &e.buf);
+ nout := Encode(&e.out, &e.buf)
if _, e.err = e.w.Write(e.out[0:nout]); e.err != nil {
return n, e.err
}
- e.nbuf = 0;
+ e.nbuf = 0
}
// 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]);
+ nout := Encode(&e.out, p[0:nn])
if _, e.err = e.w.Write(e.out[0:nout]); e.err != nil {
return n, e.err
}
}
- n += nn;
- p = p[nn:];
+ n += nn
+ p = p[nn:]
}
// Trailing fringe.
for i := 0; i < len(p); i++ {
e.buf[i] = p[i]
}
- e.nbuf = len(p);
- n += len(p);
- return;
+ e.nbuf = len(p)
+ n += len(p)
+ return
}
// Close flushes any pending output from the encoder.
@@ -155,11 +155,11 @@ 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]);
- e.nbuf = 0;
- _, e.err = e.w.Write(e.out[0:nout]);
+ nout := Encode(&e.out, e.buf[0:e.nbuf])
+ e.nbuf = 0
+ _, e.err = e.w.Write(e.out[0:nout])
}
- return e.err;
+ return e.err
}
/*
@@ -187,8 +187,8 @@ 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) {
- var v uint32;
- var nb int;
+ var v uint32
+ var nb int
for i, b := range src {
if len(dst)-ndst < 4 {
return
@@ -197,27 +197,27 @@ func Decode(dst, src []byte, flush bool) (ndst, nsrc int, err os.Error) {
case b <= ' ':
continue
case b == 'z' && nb == 0:
- nb = 5;
- v = 0;
+ nb = 5
+ v = 0
case '!' <= b && b <= 'u':
- v = v*85 + uint32(b-'!');
- nb++;
+ v = v*85 + uint32(b-'!')
+ nb++
default:
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);
- dst[ndst+3] = byte(v);
- ndst += 4;
- nb = 0;
- v = 0;
+ 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
+ v = 0
}
}
if flush {
- nsrc = len(src);
+ nsrc = len(src)
if nb > 0 {
// The number of output bytes in the last fragment
// is the number of leftover input bytes - 1:
@@ -233,27 +233,27 @@ 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);
- v <<= 8;
- ndst++;
+ dst[ndst] = byte(v >> 24)
+ v <<= 8
+ ndst++
}
}
}
- return;
+ return
}
// NewDecoder constructs a new ascii85 stream decoder.
-func NewDecoder(r io.Reader) io.Reader { return &decoder{r: r} }
+func NewDecoder(r io.Reader) io.Reader { return &decoder{r: r} }
type decoder struct {
- err os.Error;
- readErr os.Error;
- r io.Reader;
- end bool; // saw end of message
- buf [1024]byte; // leftover input
- nbuf int;
- out []byte; // leftover decoded output
- outbuf [1024]byte;
+ err os.Error
+ readErr os.Error
+ r io.Reader
+ end bool // saw end of message
+ buf [1024]byte // leftover input
+ nbuf int
+ out []byte // leftover decoded output
+ outbuf [1024]byte
}
func (d *decoder) Read(p []byte) (n int, err os.Error) {
@@ -267,19 +267,19 @@ func (d *decoder) Read(p []byte) (n int, err os.Error) {
for {
// Copy leftover output from last decode.
if len(d.out) > 0 {
- n = copy(p, d.out);
- d.out = d.out[n:];
- return;
+ n = copy(p, d.out)
+ d.out = d.out[n:]
+ return
}
// Decode leftover input from last read.
- var nn, nsrc, ndst int;
+ 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 = copy(&d.buf, d.buf[nsrc:d.nbuf]);
- continue; // copy out and return
+ d.out = d.outbuf[0:ndst]
+ d.nbuf = copy(&d.buf, d.buf[nsrc:d.nbuf])
+ continue // copy out and return
}
}
@@ -288,13 +288,13 @@ func (d *decoder) Read(p []byte) (n int, err os.Error) {
return 0, d.err
}
if d.readErr != nil {
- d.err = d.readErr;
- return 0, d.err;
+ d.err = d.readErr
+ return 0, d.err
}
// Read more data.
- nn, d.readErr = d.r.Read(d.buf[d.nbuf:]);
- d.nbuf += nn;
+ nn, d.readErr = d.r.Read(d.buf[d.nbuf:])
+ d.nbuf += nn
}
- panic("unreachable");
+ panic("unreachable")
}