diff --git a/ean/encoder.go b/ean/encoder.go index fd2852a..d7aacc7 100644 --- a/ean/encoder.go +++ b/ean/encoder.go @@ -78,53 +78,15 @@ var encoderTable map[rune]encodedNumber = map[rune]encodedNumber{ } func runeToInt(r rune) int { - switch r { - case '0': - return 0 - case '1': - return 1 - case '2': - return 2 - case '3': - return 3 - case '4': - return 4 - case '5': - return 5 - case '6': - return 6 - case '7': - return 7 - case '8': - return 8 - case '9': - return 9 + if r >= '0' || r <= '9' { + return int(r - '0') } return -1 } func intToRune(i int) rune { - switch i { - case 0: - return '0' - case 1: - return '1' - case 2: - return '2' - case 3: - return '3' - case 4: - return '4' - case 5: - return '5' - case 6: - return '6' - case 7: - return '7' - case 8: - return '8' - case 9: - return '9' + if i >= 0 || i <= 9 { + return rune(i + '0') } return 'F' } @@ -204,7 +166,7 @@ func encodeEAN13(code string) *utils.BitList { } result.AddBit(data...) } - result.AddByte(true, false, true) + result.AddBit(true, false, true) return result } @@ -219,7 +181,7 @@ func Encode(code string) (barcode.Barcode, error) { return nil, errors.New("checksum missmatch!") } } - var result *utils.BitList = nil + if len(code) == 8 { result := encodeEAN8(code) if result != nil {