go-tinyqr

An experimental minimal QR Code generator  http://go-qrcode.appspot.com
git clone https://git.ce9e.org/go-tinyqr.git

commit
fe00d3979fbb456bbcfde6fb5ca6b3bda548652e
parent
0101a5ded8f8b5369fae3c26450909781b1ae488
Author
Tom Harwood <tfh@skip.org>
Date
2014-04-23 18:37
+= bitset comments

Diffstat

M bitset/bitset.go 22 ++++++++++++++++------
M example_test.go 2 +-

2 files changed, 17 insertions, 7 deletions


diff --git a/bitset/bitset.go b/bitset/bitset.go

@@ -47,10 +47,12 @@ func New(v ...bool) *Bitset {
   47    47 	return b
   48    48 }
   49    49 
   -1    50 // Clone returns a copy.
   50    51 func Clone(from *Bitset) *Bitset {
   51    52 	return &Bitset{numBits: from.numBits, bits: from.bits[:]}
   52    53 }
   53    54 
   -1    55 // Substr returns a substring, consisting of the bits from indexes start to end.
   54    56 func (b *Bitset) Substr(start int, end int) *Bitset {
   55    57 	if start > end || end > b.numBits {
   56    58 		log.Panicf("Out of range start=%d end=%d numBits=%d", start, end, b.numBits)
@@ -69,6 +71,12 @@ func (b *Bitset) Substr(start int, end int) *Bitset {
   69    71 	return result
   70    72 }
   71    73 
   -1    74 // NewFromBase2String constructs and returns a Bitset from a string. The string
   -1    75 // consists of '1', '0' or ' ' characters, e.g. "1010 0101". The '1' and '0'
   -1    76 // characters represent true/false bits respectively, and ' ' characters are
   -1    77 // ignored.
   -1    78 //
   -1    79 // The function panics if the input string contains other characters.
   72    80 func NewFromBase2String(b2string string) *Bitset {
   73    81 	b := &Bitset{numBits: 0, bits: make([]byte, 0)}
   74    82 
@@ -94,8 +102,8 @@ func (b *Bitset) AppendBytes(data []byte) {
   94   102 	}
   95   103 }
   96   104 
   97    -1 // AppendBytes appends the |numBits| least significant bits from |byte|.
   98    -1 func (b *Bitset) AppendByte(bits byte, numBits int) {
   -1   105 // AppendByte appends the numBits least significant bits from value.
   -1   106 func (b *Bitset) AppendByte(value byte, numBits int) {
   99   107 	b.ensureCapacity(numBits)
  100   108 
  101   109 	if numBits > 8 {
@@ -103,7 +111,7 @@ func (b *Bitset) AppendByte(bits byte, numBits int) {
  103   111 	}
  104   112 
  105   113 	for i := numBits - 1; i >= 0; i-- {
  106    -1 		if bits&(1<<uint(i)) != 0 {
   -1   114 		if value&(1<<uint(i)) != 0 {
  107   115 			b.bits[b.numBits/8] |= 0x80 >> uint(b.numBits%8)
  108   116 		}
  109   117 
@@ -111,7 +119,7 @@ func (b *Bitset) AppendByte(bits byte, numBits int) {
  111   119 	}
  112   120 }
  113   121 
  114    -1 // AppendValue appends the |numBits| least significant bits from |value|.
   -1   122 // AppendUint32 appends the numBits least significant bits from value.
  115   123 func (b *Bitset) AppendUint32(value uint32, numBits int) {
  116   124 	b.ensureCapacity(numBits)
  117   125 
@@ -173,7 +181,7 @@ func (b *Bitset) AppendBools(bits ...bool) {
  173   181 	}
  174   182 }
  175   183 
  176    -1 // AppendBools appends bits to the Bitset.
   -1   184 // AppendNumBools appends num bits of value value.
  177   185 func (b *Bitset) AppendNumBools(num int, value bool) {
  178   186 	for i := 0; i < num; i++ {
  179   187 		b.AppendBools(value)
@@ -224,6 +232,7 @@ func (b *Bitset) At(index int) bool {
  224   232 	return (b.bits[index/8] & (0x80 >> byte(index%8))) != 0
  225   233 }
  226   234 
   -1   235 // Equals returns true if the Bitset equals other.
  227   236 func (b *Bitset) Equals(other *Bitset) bool {
  228   237 	if b.numBits != other.numBits {
  229   238 		return false
@@ -245,8 +254,9 @@ func (b *Bitset) Equals(other *Bitset) bool {
  245   254 	return true
  246   255 }
  247   256 
   -1   257 // ByteAt returns a byte consisting of upto 8 bits starting at index.
  248   258 func (b *Bitset) ByteAt(index int) byte {
  249    -1 	if index >= b.numBits {
   -1   259 	if index < 0 || index >= b.numBits {
  250   260 		log.Panicf("Index %d out of range", index)
  251   261 	}
  252   262 

diff --git a/example_test.go b/example_test.go

@@ -15,7 +15,7 @@ func ExampleEncode() {
   15    15 	if err != nil {
   16    16 		fmt.Printf("Error: %s", err.Error())
   17    17 	} else {
   18    -1 		fmt.Println("PNG is %d bytes long", len(png))
   -1    18 		fmt.Printf("PNG is %d bytes long", len(png))
   19    19 	}
   20    20 }
   21    21