|
|
@@ -6,11 +6,6 @@ import (
|
|
|
"github.com/boombuler/barcode"
|
|
|
)
|
|
|
|
|
|
-type alphaNumericEncoding struct {
|
|
|
-}
|
|
|
-
|
|
|
-var AlphaNumeric Encoding = alphaNumericEncoding{}
|
|
|
-
|
|
|
var alphaNumericTable map[byte]int = map[byte]int{
|
|
|
'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9,
|
|
|
'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15, 'G': 16, 'H': 17, 'I': 18, 'J': 19,
|
|
|
@@ -19,11 +14,7 @@ var alphaNumericTable map[byte]int = map[byte]int{
|
|
|
'+': 40, '-': 41, '.': 42, '/': 43, ':': 44,
|
|
|
}
|
|
|
|
|
|
-func (ane alphaNumericEncoding) String() string {
|
|
|
- return "AlphaNumeric"
|
|
|
-}
|
|
|
-
|
|
|
-func (ane alphaNumericEncoding) encode(content string, ecl ErrorCorrectionLevel) (*barcode.BitList, *versionInfo, error) {
|
|
|
+func encodeAlphaNumeric(content string, ecl ErrorCorrectionLevel) (*barcode.BitList, *versionInfo, error) {
|
|
|
|
|
|
contentLenIsOdd := len(content)%2 == 1
|
|
|
contentBitCount := (len(content) / 2) * 11
|
|
|
@@ -43,14 +34,14 @@ func (ane alphaNumericEncoding) encode(content string, ecl ErrorCorrectionLevel)
|
|
|
c1, ok1 := alphaNumericTable[content[idx*2]]
|
|
|
c2, ok2 := alphaNumericTable[content[(idx*2)+1]]
|
|
|
if !ok1 || !ok2 {
|
|
|
- return nil, nil, fmt.Errorf("\"%s\" can not be encoded as %s", content, ane)
|
|
|
+ return nil, nil, fmt.Errorf("\"%s\" can not be encoded as %s", content, AlphaNumeric)
|
|
|
}
|
|
|
res.AddBits(c1*45+c2, 11)
|
|
|
}
|
|
|
if contentLenIsOdd {
|
|
|
c1, ok := alphaNumericTable[content[len(content)-1]]
|
|
|
if !ok {
|
|
|
- return nil, nil, fmt.Errorf("\"%s\" can not be encoded as %s", content, ane)
|
|
|
+ return nil, nil, fmt.Errorf("\"%s\" can not be encoded as %s", content, AlphaNumeric)
|
|
|
}
|
|
|
res.AddBits(c1, 6)
|
|
|
}
|