parsing time now

pull/2/head
Jean-Marc MEESSEN 4 years ago
parent fb41ebd2ef
commit 86e135d09e

@ -41,11 +41,14 @@ type LogLine struct {
} }
var regexpIsBand = regexp.MustCompile("m$") 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 // ParseLine cuts a FLE line into useful bits
func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg string){ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg string){
//TODO: input null protection? //TODO: input null protection?
//TODO: Make something more intelligent
logLine = previousLine logLine = previousLine
//TODO: what happens when we have <> or when there are multiple comments //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 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 //If we come here, we could not make sense of what we found
errorMsg = errorMsg + "Unable to parse " + element + " " errorMsg = errorMsg + "Unable to parse " + element + " "

@ -22,10 +22,30 @@ func TestParseLine(t *testing.T) {
args{ inputStr: "40m cw", previousLine: LogLine{ Mode: "SSB", }}, args{ inputStr: "40m cw", previousLine: LogLine{ Mode: "SSB", }},
LogLine{ Band: "40m", Mode: "CW",}, "", 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", "Parse for comment",
args{ inputStr: "4 g3noh <PSE QSL Direct>", previousLine: LogLine{ Mode: "SSB", }}, args{ inputStr: "4 g3noh <PSE QSL Direct>", 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", "Parse for QSL",

Loading…
Cancel
Save