fixed bug where empty line would crash program

This commit is contained in:
2025-08-13 09:14:42 -04:00
parent 2fa6aef836
commit 42ccf3c812

79
main.go
View File

@@ -71,46 +71,51 @@ func main() {
})) }))
for _, upc := range upcs { for _, upc := range upcs {
checkForNonStartingNumber := regex.MatchString(upc) if len(upc) > 0 {
checkForNonStartingNumber := regex.MatchString(upc)
if checkForNonStartingNumber {
gtins = append(gtins, upc)
continue
}
if isNumeric(upc) {
gtins = append(gtins, upc)
continue
}
// Lower case the E
upc = strings.ToLower(upc)
// Split scientific notation at the e+ point
upcArray := strings.Split(upc, "e+")
fmt.Println(upcArray)
// Create separate variables for the split values
workingUpc := upcArray[0]
upcENumber := upcArray[1]
// At one to the scientific notation length to allow for the decimal point to be removed
upcLength, err := strconv.Atoi(upcENumber)
Error(err)
upcLength = upcLength + 1
// Remove the decimal point
workingUpc = strings.ReplaceAll(workingUpc, ".", "")
// Append 0 to UPC to match notation length
for len(workingUpc) < upcLength {
workingUpc = workingUpc + "0"
}
upc = workingUpc
if checkForNonStartingNumber {
gtins = append(gtins, upc) gtins = append(gtins, upc)
continue checkBar.Add(1)
} else {
gtins = append(gtins, "")
checkBar.Add(1)
} }
if isNumeric(upc) == true {
gtins = append(gtins, upc)
continue
}
// Lower case the E
upc = strings.ToLower(upc)
// Split scientific notation at the e+ point
upcArray := strings.Split(upc, "e+")
fmt.Println(upcArray)
// Create separate variables for the split values
workingUpc := upcArray[0]
upcENumber := upcArray[1]
// At one to the scientific notation length to allow for the decimal point to be removed
upcLength, err := strconv.Atoi(upcENumber)
Error(err)
upcLength = upcLength + 1
// Remove the decimal point
workingUpc = strings.ReplaceAll(workingUpc, ".", "")
// Append 0 to UPC to match notation length
for len(workingUpc) < upcLength {
workingUpc = workingUpc + "0"
}
upc = workingUpc
gtins = append(gtins, upc)
checkBar.Add(1)
} }
answerBar := progressbar.NewOptions(len(gtins), answerBar := progressbar.NewOptions(len(gtins),