genalphabet.go raw

   1  // +build generate
   2  
   3  package main
   4  
   5  import (
   6  	"bytes"
   7  	"io"
   8  	"os"
   9  	"strconv"
  10  )
  11  
  12  var (
  13  	end      = []byte(`}`)
  14  	start = []byte(`//go:generate go run -tags generate ./genalphabet/.
  15  // AUTOGENERATED by genalphabet.go; do not edit.
  16  
  17  package base58
  18  
  19  const (
  20  	// alphabet is the modified base58 alphabet used by Bitcoin.
  21  	alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
  22  	alphabetIdx0 = '1'
  23  )
  24  var b58 = [256]byte{`)
  25  	alphabet = []byte("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")
  26  	tab      = []byte("\t")
  27  	invalid  = []byte("255")
  28  	comma    = []byte(",")
  29  	space    = []byte(" ")
  30  	nl       = []byte("\n")
  31  )
  32  
  33  func write(w io.Writer, b []byte) {
  34  	_, e := w.Write(b)
  35  	if e != nil {
  36  		F.Ln(e)
  37  	}
  38  }
  39  func main() {
  40  	fi, e := os.Create("alphabet.go")
  41  	if e != nil {
  42  		F.Ln(e)
  43  	}
  44  	defer fi.Close()
  45  	write(fi, start)
  46  	write(fi, nl)
  47  	for i := byte(0); i < 32; i++ {
  48  		write(fi, tab)
  49  		for j := byte(0); j < 8; j++ {
  50  			idx := bytes.IndexByte(alphabet, i*8+j)
  51  			if idx == -1 {
  52  				write(fi, invalid)
  53  			} else {
  54  				write(fi, strconv.AppendInt(nil, int64(idx), 10))
  55  			}
  56  			write(fi, comma)
  57  			if j != 7 {
  58  				write(fi, space)
  59  			}
  60  		}
  61  		write(fi, nl)
  62  	}
  63  	write(fi, end)
  64  	write(fi, nl)
  65  }
  66