From 0b830601f5a07653730e8c55d4c7fceb278031b4 Mon Sep 17 00:00:00 2001 From: Paul Bienkowski Date: Wed, 18 Nov 2020 22:13:00 +0100 Subject: [PATCH] feat: autodetect "$ as newlines" hack in both OBSVER1 and OBSVER2 --- logic/tracks.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/logic/tracks.js b/logic/tracks.js index 2ed63f2..6f53adb 100644 --- a/logic/tracks.js +++ b/logic/tracks.js @@ -11,7 +11,18 @@ function _parseFloat(token) { return f; } +function replaceDollarNewlinesHack(body) { + // see if we are using the hack with $ as newlines, replace them for the csv parser + if (body.endsWith('$')) { + return body.replace(/\$/g, '\n'); + } + + return body; +} + function addPointsToTrack(trackInfo, body, format = null) { + body = replaceDollarNewlinesHack(body); + const detectedFormat = format != null ? format : detectFormat(body); let parser; @@ -60,10 +71,6 @@ function detectFormat(body) { } function* parseObsver1(body) { - if (body.indexOf('\n') < body.length - 1) { - body = body.replace(/\$/g, '\n'); - } - for (const record of csvParse(body, { delimiter: ';', encoding: 'utf8',