Compare commits
4 Commits
41f592ec45
...
0.3
Author | SHA1 | Date | |
---|---|---|---|
5f49a09ab4 | |||
42ccf3c812 | |||
2fa6aef836 | |||
25a7658328 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -8,6 +8,7 @@
|
|||||||
*.dll
|
*.dll
|
||||||
*.so
|
*.so
|
||||||
*.dylib
|
*.dylib
|
||||||
|
*.zip
|
||||||
|
|
||||||
# Test binary, built with `go test -c`
|
# Test binary, built with `go test -c`
|
||||||
*.test
|
*.test
|
||||||
|
@@ -14,6 +14,7 @@ UPC
|
|||||||
2.0006670732e+11
|
2.0006670732e+11
|
||||||
2.0006955667e+11
|
2.0006955667e+11
|
||||||
2.0007279122e+11
|
2.0007279122e+11
|
||||||
|
0075849385857
|
||||||
2.0007279132e+11
|
2.0007279132e+11
|
||||||
2.0007279138E+11
|
2.0007279138E+11
|
||||||
2.0007279147E+11
|
2.0007279147E+11
|
||||||
|
10
isNumeric.go
Normal file
10
isNumeric.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"regexp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func isNumeric(s string) bool {
|
||||||
|
match, _ := regexp.MatchString("^[0-9]+$", s)
|
||||||
|
return match
|
||||||
|
}
|
74
main.go
74
main.go
@@ -71,41 +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)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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),
|
||||||
|
Reference in New Issue
Block a user