From 25a7658328cfb957ca4e0b88166a0ab8d3aee85a Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Tue, 6 May 2025 16:52:18 -0400 Subject: [PATCH] fixed bug where real numbers crashed app --- answer.txt | 46 ++++++++++++++++++++++++++++++++++++++++++++++ examplelist.txt | 1 + isNumeric.go | 10 ++++++++++ main.go | 5 +++++ 4 files changed, 62 insertions(+) create mode 100644 answer.txt create mode 100644 isNumeric.go diff --git a/answer.txt b/answer.txt new file mode 100644 index 0000000..88dfdec --- /dev/null +++ b/answer.txt @@ -0,0 +1,46 @@ +UPC +200033148770 +200042041350 +200042041400 +200042064910 +200047796200 +200059594110 +200059660970 +200065290180 +200065290220 +200065290310 +200065290340 +200065290370 +200066707320 +200069556670 +200072791220 +0075849385857 +200072791320 +200072791380 +200072791470 +200072950140 +200079186270 +200079343740 +200081451640 +200081630310 +200106953220 +200156488680 +200157056340 +200168095820 +200168979440 +200172490020 +200177334550 +200177780700 +200177788230 +327582805540 +337582889920 +357582840140 +357582843530 +357582850030 +477039522210 +477039522200 +482000077030 +482000077040 +482000077090 +647582802920 +647582804700 diff --git a/examplelist.txt b/examplelist.txt index 3b966dd..b0cfd11 100644 --- a/examplelist.txt +++ b/examplelist.txt @@ -14,6 +14,7 @@ UPC 2.0006670732e+11 2.0006955667e+11 2.0007279122e+11 +0075849385857 2.0007279132e+11 2.0007279138E+11 2.0007279147E+11 diff --git a/isNumeric.go b/isNumeric.go new file mode 100644 index 0000000..cb6074f --- /dev/null +++ b/isNumeric.go @@ -0,0 +1,10 @@ +package main + +import ( + "regexp" +) + +func isNumeric(s string) bool { + match, _ := regexp.MatchString("^[0-9]+$", s) + return match +} diff --git a/main.go b/main.go index 1127483..f7cd654 100644 --- a/main.go +++ b/main.go @@ -78,6 +78,11 @@ func main() { continue } + if isNumeric(upc) == true { + gtins = append(gtins, upc) + continue + } + // Lower case the E upc = strings.ToLower(upc) // Split scientific notation at the e+ point