diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2014-12-19 12:22:34 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2014-12-19 12:22:34 +0100 |
commit | 86a0a6d93e336655b5419b233a374a5fe7161e1f (patch) | |
tree | de283e781d2c238d23f3f468289c9bfc542360ee /src/MuxElements.cpp | |
parent | 1ba143ebc338c14821a652f29a5c29f19bb8c837 (diff) | |
download | dabmux-86a0a6d93e336655b5419b233a374a5fe7161e1f.tar.gz dabmux-86a0a6d93e336655b5419b233a374a5fe7161e1f.tar.bz2 dabmux-86a0a6d93e336655b5419b233a374a5fe7161e1f.zip |
Fix shortlabel parsing when it's numeric
Short labels that were numeric were directly interpreted as a flag,
which was undocumented, inconsistent and not very useful.
Diffstat (limited to 'src/MuxElements.cpp')
-rw-r--r-- | src/MuxElements.cpp | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/MuxElements.cpp b/src/MuxElements.cpp index 6ecbcf5..93a98f4 100644 --- a/src/MuxElements.cpp +++ b/src/MuxElements.cpp @@ -98,25 +98,30 @@ int DabLabel::setLabel(const std::string& text, const std::string& short_label) */ int DabLabel::setShortLabel(const std::string& slabel) { - char* end; - const char* lab; - uint16_t flag; - flag = strtoul(slabel.c_str(), &end, 0); - if (*end != 0) { - lab = slabel.c_str(); - flag = 0; - for (int i = 0; i < 32; ++i) { - if (*lab == this->m_text[i]) { - flag |= 0x8000 >> i; - if (*(++lab) == 0) { - break; - } + const char* slab = slabel.c_str(); + uint16_t flag = 0x0; + + /* 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 == this->m_text[i]) { + flag |= 0x8000 >> i; + if (*(++slab) == 0) { + break; } } - if (*lab != 0) { - return -1; - } } + + /* If we have remaining characters in the slabel after + * we went through the whole label, the short label + * cannot be represented + */ + if (*slab != 0) { + return -1; + } + + /* Count the number of bits in the flag */ int count = 0; for (int i = 0; i < 16; ++i) { if (flag & (1 << i)) { |