From 1c702a3722025a43bf238abe8ab0c7a9c870f615 Mon Sep 17 00:00:00 2001 From: Jean-Marc Meessen Date: Thu, 11 Jun 2020 09:11:04 +0200 Subject: [PATCH] Add parsing of custom QSL Message --- cmd/parse_line.go | 10 ++++++++++ cmd/parse_line_test.go | 5 +++++ todo.md | 3 ++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cmd/parse_line.go b/cmd/parse_line.go index 4933f40..843742e 100644 --- a/cmd/parse_line.go +++ b/cmd/parse_line.go @@ -49,6 +49,7 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg logLine = previousLine //TODO: what happens when we have <> or when there are multiple comments + //TODO: Refactor this! it is ugly comment := getBraketedData(inputStr, "COMMENT") if comment != "" { logLine.Comment = comment @@ -56,6 +57,14 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg fmt.Println("Cleaned input string: ", inputStr) } + comment = getBraketedData(inputStr, "QSL") + if comment != "" { + logLine.QSLmsg = comment + inputStr = strings.Replace(inputStr, "[" + comment + "]", "",1) + fmt.Println("Cleaned input string: ", inputStr) + } + + elements := strings.Fields(inputStr) for _, element := range elements { @@ -110,6 +119,7 @@ func getBraketedData(value, braketType string) (text string) { a := "" b := "" + //TODO: refactor that as a switch statement to exclude non supported bracket types if braketType == "COMMENT" { a = "<" b = ">" diff --git a/cmd/parse_line_test.go b/cmd/parse_line_test.go index 1b60bbd..060435c 100644 --- a/cmd/parse_line_test.go +++ b/cmd/parse_line_test.go @@ -27,6 +27,11 @@ func TestParseLine(t *testing.T) { args{ inputStr: "4 g3noh ", previousLine: LogLine{ Mode: "SSB", }}, LogLine{ Comment: "PSE QSL Direct", Call: "G3NOH", Time: "2"}, "", }, + { + "Parse for QSL", + args{ inputStr: "4 g3noh ", previousLine: LogLine{ Mode: "SSB", }}, + LogLine{ QSLmsg: "Custom QSL message", Call: "G3NOH", Time: "2"}, "", + }, { "Wrong mode", args{ inputStr: "cww", previousLine: LogLine{ Mode: "SSB", }}, diff --git a/todo.md b/todo.md index 8edf94c..cc4f978 100644 --- a/todo.md +++ b/todo.md @@ -14,4 +14,5 @@ * [x] Read the file into array * [x] Parse every line * [x] Load structured data -* [ ] Create structured data storage +* [X] Create structured data storage +* [ ] Create the logic to take over from the previous line