From 0b647385bb6e379c253099b32692f867fe1bd428 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Mon, 25 May 2015 19:04:57 +0200 Subject: Simplify DAB label handling The DabLabel object only save the label in the unpadded form, and handle padding with spaces at the time of usage. --- src/MuxElements.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/MuxElements.cpp') diff --git a/src/MuxElements.cpp b/src/MuxElements.cpp index 65045db..a452220 100644 --- a/src/MuxElements.cpp +++ b/src/MuxElements.cpp @@ -24,6 +24,7 @@ */ #include +#include #include "MuxElements.h" #include @@ -46,12 +47,9 @@ using namespace std; int DabLabel::setLabel(const std::string& label) { size_t len = label.length(); - if (len > sizeof(m_text)) + if (len > DABLABEL_LENGTH) return -3; - memcpy(m_text, label.c_str(), len); - memset(m_text + len, 0x20, sizeof(m_text) - len); - m_flag = 0xFF00; // truncate the label to the eight first characters m_label = label; @@ -73,7 +71,6 @@ int DabLabel::setLabel(const std::string& label, const std::string& short_label) return flag; // short label is valid. - memcpy(m_text, newlabel.m_text, sizeof(m_text)); m_flag = flag & 0xFFFF; m_label = newlabel.m_label; @@ -105,8 +102,8 @@ int DabLabel::setShortLabel(const std::string& slabel) /* Iterate over the label and set the bits in the flag * according to the characters in the slabel */ - for (int i = 0; i < 32; ++i) { - if (*slab == m_text[i]) { + for (size_t i = 0; i < m_label.size(); ++i) { + if (*slab == m_label[i]) { flag |= 0x8000 >> i; if (*(++slab) == 0) { break; @@ -118,7 +115,7 @@ int DabLabel::setShortLabel(const std::string& slabel) * we went through the whole label, the short label * cannot be represented */ - if (*slab != 0) { + if (*slab != '\0') { return -1; } @@ -139,15 +136,22 @@ int DabLabel::setShortLabel(const std::string& slabel) const string DabLabel::short_label() const { stringstream shortlabel; - for (int i = 0; i < 32; ++i) { + for (size_t i = 0; i < m_label.size(); ++i) { if (m_flag & 0x8000 >> i) { - shortlabel << m_text[i]; + shortlabel << m_label[i]; } } return shortlabel.str(); } +void DabLabel::writeLabel(uint8_t* buf) const +{ + memset(buf, ' ', DABLABEL_LENGTH); + if (m_label.size() <= DABLABEL_LENGTH) { + std::copy(m_label.begin(), m_label.end(), (char*)buf); + } +} vector::iterator getSubchannel( vector& subchannels, int id) -- cgit v1.2.3