fixed bugs + code cleanup

This commit is contained in:
boombuler 2013-12-16 21:12:46 +01:00
parent 9741f0ff8d
commit 6a44551dc4
1 changed files with 6 additions and 44 deletions

View File

@ -78,53 +78,15 @@ var encoderTable map[rune]encodedNumber = map[rune]encodedNumber{
} }
func runeToInt(r rune) int { func runeToInt(r rune) int {
switch r { if r >= '0' || r <= '9' {
case '0': return int(r - '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
} }
return -1 return -1
} }
func intToRune(i int) rune { func intToRune(i int) rune {
switch i { if i >= 0 || i <= 9 {
case 0: return rune(i + '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'
} }
return 'F' return 'F'
} }
@ -204,7 +166,7 @@ func encodeEAN13(code string) *utils.BitList {
} }
result.AddBit(data...) result.AddBit(data...)
} }
result.AddByte(true, false, true) result.AddBit(true, false, true)
return result return result
} }
@ -219,7 +181,7 @@ func Encode(code string) (barcode.Barcode, error) {
return nil, errors.New("checksum missmatch!") return nil, errors.New("checksum missmatch!")
} }
} }
var result *utils.BitList = nil
if len(code) == 8 { if len(code) == 8 {
result := encodeEAN8(code) result := encodeEAN8(code)
if result != nil { if result != nil {