diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2018-02-09 11:52:53 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2018-02-09 11:52:53 +0100 |
commit | 2a96b61d31cc51611731297f936a477663871b9d (patch) | |
tree | 54753f4bf7dfbdd5fa49bcd48f0a7035fa95accc | |
parent | 6902285dbc1c816f9c16d1d63a151b2022c094dc (diff) | |
download | dabmux-2a96b61d31cc51611731297f936a477663871b9d.tar.gz dabmux-2a96b61d31cc51611731297f936a477663871b9d.tar.bz2 dabmux-2a96b61d31cc51611731297f936a477663871b9d.zip |
Fail correctly on charset conversion error
-rw-r--r-- | lib/charset/charset.h | 14 | ||||
-rw-r--r-- | src/MuxElements.cpp | 7 |
2 files changed, 15 insertions, 6 deletions
diff --git a/lib/charset/charset.h b/lib/charset/charset.h index 78dc94e..c6a3001 100644 --- a/lib/charset/charset.h +++ b/lib/charset/charset.h @@ -51,13 +51,21 @@ class CharsetConverter } } - /*! Convert a UTF-8 encoded text line into an EBU Latin encoded byte stream + /*! Convert a UTF-8 encoded text line into an EBU Latin encoded byte + * stream. If up_to_first_error is set, convert as much text as possible. + * If false, raise an exception in case of conversion errors. */ - std::string convert(std::string line_utf8) { + std::string convert(std::string line_utf8, bool up_to_first_error = true) { using namespace std; // check for invalid utf-8, we only convert up to the first error - string::iterator end_it = utf8::find_invalid(line_utf8.begin(), line_utf8.end()); + string::iterator end_it; + if (up_to_first_error) { + end_it = utf8::find_invalid(line_utf8.begin(), line_utf8.end()); + } + else { + end_it = line_utf8.end(); + } // Convert it to utf-32 vector<uint32_t> utf32line; diff --git a/src/MuxElements.cpp b/src/MuxElements.cpp index a31791a..24c81b3 100644 --- a/src/MuxElements.cpp +++ b/src/MuxElements.cpp @@ -179,7 +179,7 @@ int DabLabel::setLabel(const std::string& label) m_flag = 0xFF00; // truncate the label to the eight first characters try { - m_label = charset_converter.convert(label); + m_label = charset_converter.convert(label, false); } catch (const utf8::exception& e) { etiLog.level(warn) << "Failed to convert label '" << label << @@ -196,9 +196,10 @@ int DabLabel::setLabel(const std::string& label, const std::string& short_label) newlabel.m_flag = 0xFF00; try { - newlabel.m_label = charset_converter.convert(label); + newlabel.m_label = charset_converter.convert(label, false); - int flag = newlabel.setShortLabel(charset_converter.convert(short_label)); + int flag = newlabel.setShortLabel( + charset_converter.convert(short_label, false)); if (flag < 0) { return flag; } |