summaryrefslogtreecommitdiffstats
path: root/src/MuxElements.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2018-02-09 11:43:10 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2018-02-09 11:43:10 +0100
commit6902285dbc1c816f9c16d1d63a151b2022c094dc (patch)
tree4ea42146ffbcb54ad27526f4659099f77d435610 /src/MuxElements.cpp
parentf4ef1284d754ecd907dd4ed3072f8be65b26f2de (diff)
downloaddabmux-6902285dbc1c816f9c16d1d63a151b2022c094dc.tar.gz
dabmux-6902285dbc1c816f9c16d1d63a151b2022c094dc.tar.bz2
dabmux-6902285dbc1c816f9c16d1d63a151b2022c094dc.zip
Convert labels from utf-8 to EBU
Diffstat (limited to 'src/MuxElements.cpp')
-rw-r--r--src/MuxElements.cpp60
1 files changed, 48 insertions, 12 deletions
diff --git a/src/MuxElements.cpp b/src/MuxElements.cpp
index cdfcc42..a31791a 100644
--- a/src/MuxElements.cpp
+++ b/src/MuxElements.cpp
@@ -30,6 +30,7 @@
#include <algorithm>
#include "MuxElements.h"
+#include "lib/charset/charset.h"
#include <boost/algorithm/string.hpp>
#include <boost/format.hpp>
@@ -44,7 +45,7 @@ const unsigned short Sub_Channel_SizeTable[64] = {
232, 280, 160, 208, 280, 192, 280, 416
};
-
+static CharsetConverter charset_converter;
using namespace std;
@@ -177,7 +178,14 @@ int DabLabel::setLabel(const std::string& label)
m_flag = 0xFF00; // truncate the label to the eight first characters
- m_label = label;
+ try {
+ m_label = charset_converter.convert(label);
+ }
+ catch (const utf8::exception& e) {
+ etiLog.level(warn) << "Failed to convert label '" << label <<
+ "' to EBU Charset";
+ m_label = label;
+ }
return 0;
}
@@ -185,20 +193,43 @@ int DabLabel::setLabel(const std::string& label)
int DabLabel::setLabel(const std::string& label, const std::string& short_label)
{
DabLabel newlabel;
+ newlabel.m_flag = 0xFF00;
+
+ try {
+ newlabel.m_label = charset_converter.convert(label);
+
+ int flag = newlabel.setShortLabel(charset_converter.convert(short_label));
+ if (flag < 0) {
+ return flag;
+ }
+
+ m_flag = flag & 0xFFFF;
+ }
+ catch (const utf8::exception& e) {
+ etiLog.level(warn) << "Failed to convert label '" << label <<
+ " or short label '" << short_label << "' to EBU Charset";
+
+ // Use label as-is
- int result = newlabel.setLabel(label);
- if (result < 0)
- return result;
+ newlabel.m_label = label;
+ newlabel.m_flag = 0xFF00;
- /* First check if we can actually create the short label */
- int flag = newlabel.setShortLabel(short_label);
- if (flag < 0)
- return flag;
+ int result = newlabel.setLabel(label);
+ if (result < 0) {
+ return result;
+ }
+
+ /* First check if we can actually create the short label */
+ int flag = newlabel.setShortLabel(short_label);
+ if (flag < 0) {
+ return flag;
+ }
+
+ m_flag = flag & 0xFFFF;
+ }
// short label is valid.
- m_flag = flag & 0xFFFF;
m_label = newlabel.m_label;
-
return 0;
}
@@ -258,6 +289,11 @@ int DabLabel::setShortLabel(const std::string& slabel)
return flag;
}
+const string DabLabel::long_label() const
+{
+ return charset_converter.convert_ebu_to_utf8(m_label);
+}
+
const string DabLabel::short_label() const
{
stringstream shortlabel;
@@ -267,7 +303,7 @@ const string DabLabel::short_label() const
}
}
- return shortlabel.str();
+ return charset_converter.convert_ebu_to_utf8(shortlabel.str());
}
void DabLabel::writeLabel(uint8_t* buf) const