aboutsummaryrefslogtreecommitdiffstats
path: root/lib/charset
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2018-02-09 11:52:53 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2018-02-09 11:52:53 +0100
commit2a96b61d31cc51611731297f936a477663871b9d (patch)
tree54753f4bf7dfbdd5fa49bcd48f0a7035fa95accc /lib/charset
parent6902285dbc1c816f9c16d1d63a151b2022c094dc (diff)
downloaddabmux-2a96b61d31cc51611731297f936a477663871b9d.tar.gz
dabmux-2a96b61d31cc51611731297f936a477663871b9d.tar.bz2
dabmux-2a96b61d31cc51611731297f936a477663871b9d.zip
Fail correctly on charset conversion error
Diffstat (limited to 'lib/charset')
-rw-r--r--lib/charset/charset.h14
1 files changed, 11 insertions, 3 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;