From 2a96b61d31cc51611731297f936a477663871b9d Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 9 Feb 2018 11:52:53 +0100 Subject: Fail correctly on charset conversion error --- lib/charset/charset.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'lib') 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 utf32line; -- cgit v1.2.3