From 86e135d09edc7956ddb0bad0f0b7f96c5a7c7181 Mon Sep 17 00:00:00 2001 From: Jean-Marc MEESSEN Date: Fri, 12 Jun 2020 21:15:19 +0200 Subject: [PATCH] parsing time now --- cmd/parse_line.go | 21 +++++++++++++++++++++ cmd/parse_line_test.go | 22 +++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/cmd/parse_line.go b/cmd/parse_line.go index 665eec8..ac9dda7 100644 --- a/cmd/parse_line.go +++ b/cmd/parse_line.go @@ -41,11 +41,14 @@ type LogLine struct { } var regexpIsBand = regexp.MustCompile("m$") +var regexpIsFullTime = regexp.MustCompile("^[0-2]{1}[0-9]{3}$") +var regexpIsTimePart = regexp.MustCompile("^[0-5]{1}[0-9]{1}$|^[1-9]{1}$") // ParseLine cuts a FLE line into useful bits func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg string){ //TODO: input null protection? + //TODO: Make something more intelligent logLine = previousLine //TODO: what happens when we have <> or when there are multiple comments @@ -87,6 +90,24 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg continue } + // Is it a "full" time ? + if regexpIsFullTime.MatchString(element) { + logLine.Time = element + continue + } + + // Is it a partial time ? + if regexpIsTimePart.MatchString(element) { + if logLine.Time == "" { + logLine.Time = element + } else { + goodPart := logLine.Time[:len(logLine.Time)-len(element)] + logLine.Time = goodPart + element + } + continue + } + + //If we come here, we could not make sense of what we found errorMsg = errorMsg + "Unable to parse " + element + " " diff --git a/cmd/parse_line_test.go b/cmd/parse_line_test.go index ff96835..eaee1a7 100644 --- a/cmd/parse_line_test.go +++ b/cmd/parse_line_test.go @@ -22,10 +22,30 @@ func TestParseLine(t *testing.T) { args{ inputStr: "40m cw", previousLine: LogLine{ Mode: "SSB", }}, LogLine{ Band: "40m", Mode: "CW",}, "", }, + { + "Parse for time", + args{ inputStr: "1314 g3noh", previousLine: LogLine{ Mode: "SSB", }}, + LogLine{ Time: "1314", Call: "G3NOH", Mode: "SSB",}, "", + }, + { + "Parse partial time - 1", + args{ inputStr: "4 g3noh", previousLine: LogLine{ Time: "", Mode: "SSB", }}, + LogLine{ Time: "4", Call: "G3NOH", Mode: "SSB",}, "", + }, + { + "Parse partial time - 2", + args{ inputStr: "15 g3noh", previousLine: LogLine{ Time: "1200", Mode: "SSB", }}, + LogLine{ Time: "1215", Call: "G3NOH", Mode: "SSB",}, "", + }, + { + "Parse partial time - 3", + args{ inputStr: "4 g3noh", previousLine: LogLine{ Time: "1200", Mode: "SSB", }}, + LogLine{ Time: "1204", Call: "G3NOH", Mode: "SSB",}, "", + }, { "Parse for comment", args{ inputStr: "4 g3noh ", previousLine: LogLine{ Mode: "SSB", }}, - LogLine{ Comment: "PSE QSL Direct", Call: "G3NOH", Mode: "SSB",}, "Unable to parse 4 ", + LogLine{ Time: "4", Comment: "PSE QSL Direct", Call: "G3NOH", Mode: "SSB",}, "", }, { "Parse for QSL",