From 6a44551dc40da1a1c1fac33d0abb98553410f105 Mon Sep 17 00:00:00 2001 From: boombuler Date: Mon, 16 Dec 2013 21:12:46 +0100 Subject: [PATCH] fixed bugs + code cleanup --- ean/encoder.go | 50 ++++++-------------------------------------------- 1 file changed, 6 insertions(+), 44 deletions(-) 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 {