From f25bb63ea08f272afe2f186b6e866228276a8428 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Mon, 24 Jan 2022 16:37:50 -0600 Subject: [PATCH] Use getline utility to automatically strip double CR from WMO header --- wxdata/source/scwx/awips/wmo_header.cpp | 42 ++++--------------------- 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/wxdata/source/scwx/awips/wmo_header.cpp b/wxdata/source/scwx/awips/wmo_header.cpp index 19bae36d..2980b085 100644 --- a/wxdata/source/scwx/awips/wmo_header.cpp +++ b/wxdata/source/scwx/awips/wmo_header.cpp @@ -130,55 +130,25 @@ bool WmoHeader::Parse(std::istream& is) if (is.peek() == 0x01) { - std::getline(is, sohLine); - std::getline(is, sequenceLine); + util::getline(is, sohLine); + util::getline(is, sequenceLine); } - std::getline(is, wmoLine); - std::getline(is, awipsLine); + util::getline(is, wmoLine); + util::getline(is, awipsLine); if (is.eof()) { BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; headerValid = false; } - else if (!sohLine.empty() && !sohLine.ends_with("\r\r")) - { - BOOST_LOG_TRIVIAL(debug) - << logPrefix_ << "Start of Heading Line is malformed"; - headerValid = false; - } - else if (!sequenceLine.empty() && !sequenceLine.ends_with("\r\r")) - { - BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Sequence Line is malformed"; - headerValid = false; - } - else if (!wmoLine.ends_with("\r\r")) - { - BOOST_LOG_TRIVIAL(debug) - << logPrefix_ << "WMO Abbreviated Heading Line is malformed"; - headerValid = false; - } - else if (!awipsLine.ends_with("\r\r")) - { - BOOST_LOG_TRIVIAL(debug) - << logPrefix_ << "AWIPS Identifier Line is malformed"; - headerValid = false; - } else { // Remove delimiters from the end of the line - if (!sequenceLine.empty()) + while (sequenceLine.ends_with(' ')) { - sequenceLine.erase(sequenceLine.length() - 2); - while (sequenceLine.ends_with(' ')) - { - sequenceLine.erase(sequenceLine.length() - 1); - } + sequenceLine.erase(sequenceLine.length() - 1); } - - wmoLine.erase(wmoLine.length() - 2); - awipsLine.erase(awipsLine.length() - 2); } // Transmission Header: