diff --git a/api/dataimport/sdfToRSI/util.go b/api/dataimport/sdfToRSI/util.go index d684f810..81ff96b6 100644 --- a/api/dataimport/sdfToRSI/util.go +++ b/api/dataimport/sdfToRSI/util.go @@ -81,6 +81,7 @@ func findToken(line string, prefix string, endDelim string) (string, bool) { // Split off the first token (space separated), returns token, rest-of-line, error if any func takeToken(line string, sep string) (string, string, bool) { + line = strings.TrimLeft(line, sep) pos := strings.Index(line, sep) if pos > 0 { return line[0:pos], strings.TrimLeft(line[pos+len(sep):], " "), true @@ -102,7 +103,8 @@ func readFloat(line string) (float32, string, error) { f, err := strconv.ParseFloat(fStr, 32) if err != nil { - return 0, remainder, fmt.Errorf("Failed to parse float: %v. Error: %v", fStr, err) + // Prints: Error: strconv.ParseFloat: parsing "2.L3": invalid syntax + return 0, remainder, fmt.Errorf("Error: %v", err) } return float32(f), remainder, nil diff --git a/api/dataimport/sdfToRSI/util_test.go b/api/dataimport/sdfToRSI/util_test.go index c39d2f05..f2160e11 100644 --- a/api/dataimport/sdfToRSI/util_test.go +++ b/api/dataimport/sdfToRSI/util_test.go @@ -103,29 +103,41 @@ func Example_readFloat() { f, r, e := readFloat("-0.12470774 0.15369324 0.24655464 ") fmt.Printf("%v|%v|%v\n", f, e, strings.TrimRight(r, " ")) - f, r, e = readFloat(" -0.12470774 0.15369324 0.24655464 ") + f, r, e = readFloat("2.L3 0.15369324 0.24655464 ") fmt.Printf("%v|%v|%v\n", f, e, r) // Output: // -0.12470774||0.15369324 0.24655464 - // 0|Failed to read token| -0.12470774 0.15369324 0.24655464 + // 0|Error: strconv.ParseFloat: parsing "2.L3": invalid syntax|0.15369324 0.24655464 } func Example_takeToken() { - tok, l, err := takeToken("gv - 0x00dd40 : 00000000 00000000 00000000 00000000 :: 0 0 0 0 ", " -") - fmt.Printf("%v|%v|%v\n", tok, l, err) - tok, l, err = takeToken("gv - 0x00dd40 : 00000000 00000000 00000000 00000000 :: 0 0 0 0 ", " ") - fmt.Printf("%v|%v|%v\n", tok, l, err) + tok, l, ok := takeToken("gv - 0x00dd40 : 00000000 00000000 00000000 00000000 :: 0 0 0 0 ", " -") + fmt.Printf("%v|%v|%v\n", tok, l, ok) + tok, l, ok = takeToken("gv - 0x00dd40 : 00000000 00000000 00000000 00000000 :: 0 0 0 0 ", " ") + fmt.Printf("%v|%v|%v\n", tok, l, ok) - tok, l, err = takeToken(" 0x00dd40 : 00000000 00000000 00000000 00000000", " ") - fmt.Printf("%v|%v|%v\n", tok, l, err) + tok, l, ok = takeToken(" 0x00dd40 : 00000000 00000000 00000000 00000000", " ") + fmt.Printf("%v|%v|%v\n", tok, l, ok) - tok, l, err = takeToken(strings.TrimLeft(" 0x00dd40 : 00000000 00000000 00000000 00000000", " "), " ") - fmt.Printf("%v|%v|%v\n", tok, l, err) + tok, l, ok = takeToken(strings.TrimLeft(" 0x00dd40 : 00000000 00000000 00000000 00000000", " "), " ") + fmt.Printf("%v|%v|%v\n", tok, l, ok) + + tok, l, ok = takeToken("abc", "b") + fmt.Printf("%v|%v|%v\n", tok, l, ok) + + tok, l, ok = takeToken("abc", "a") + fmt.Printf("%v|%v|%v\n", tok, l, ok) + + tok, l, ok = takeToken("a", "a") + fmt.Printf("%v|%v|%v\n", tok, l, ok) // Output: // gv|0x00dd40 : 00000000 00000000 00000000 00000000 :: 0 0 0 0 |true // gv|- 0x00dd40 : 00000000 00000000 00000000 00000000 :: 0 0 0 0 |true - // | 0x00dd40 : 00000000 00000000 00000000 00000000|false // 0x00dd40|: 00000000 00000000 00000000 00000000|true + // 0x00dd40|: 00000000 00000000 00000000 00000000|true + // a|c|true + // bc||true + // ||false }