From 1c2f96f13e6e5abbf114af0192dbdd53de3c9a25 Mon Sep 17 00:00:00 2001 From: Stefan Pöschel Date: Mon, 22 Jul 2019 17:11:35 +0200 Subject: DLS: move label parsing to separate function --- src/dls.cpp | 14 ++++++++++---- src/dls.h | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/dls.cpp b/src/dls.cpp index f55c141..4e106e0 100644 --- a/src/dls.cpp +++ b/src/dls.cpp @@ -189,14 +189,13 @@ void DLSEncoder::parse_dl_params(std::ifstream &dls_fstream, DL_STATE &dl_state) } -void DLSEncoder::encodeLabel(const std::string& dls_file, const DL_PARAMS& dl_params) { - DL_STATE dl_state; +bool DLSEncoder::parseLabel(const std::string& dls_file, const DL_PARAMS& dl_params, DL_STATE& dl_state) { std::vector dls_lines; std::ifstream dls_fstream(dls_file); if (!dls_fstream.is_open()) { std::cerr << "Could not open " << dls_file << std::endl; - return; + return false; } std::string line; @@ -241,12 +240,19 @@ void DLSEncoder::encodeLabel(const std::string& dls_file, const DL_PARAMS& dl_pa dl_state.dl_text.resize(MAXDLS); } + return true; +} + + +void DLSEncoder::encodeLabel(const std::string& dls_file, const DL_PARAMS& dl_params) { + DL_STATE dl_state; + if (!parseLabel(dls_file, dl_params, dl_state)) + return; // if DL Plus enabled, but no DL Plus tags were added, add the required DUMMY tag if (dl_state.dl_plus_enabled && dl_state.dl_plus_tags.empty()) dl_state.dl_plus_tags.emplace_back(); - // toggle the toggle bit only on new DL state bool dl_state_is_new = dl_state != dl_state_prev; if (verbose) { diff --git a/src/dls.h b/src/dls.h index 3b7387d..0142565 100644 --- a/src/dls.h +++ b/src/dls.h @@ -148,6 +148,8 @@ private: CharsetConverter charset_converter; bool dls_toggle; DL_STATE dl_state_prev; + + bool parseLabel(const std::string& dls_file, const DL_PARAMS& dl_params, DL_STATE& dl_state); public: static const int APPTYPE_START; static const int APPTYPE_CONT; -- cgit v1.2.3