diff options
author | mrwastl <mrwastl@users.sourceforge.net> | 2011-09-17 21:28:10 +0200 |
---|---|---|
committer | mrwastl <mrwastl@users.sourceforge.net> | 2011-09-17 21:28:10 +0200 |
commit | 0703b948dd63eb281df5dc531abdf66818becdf7 (patch) | |
tree | b76b3ba4634a95ed71c0dd2ab1e1a4354109870d /common.c | |
parent | 9e0f177243221e2123758d196315cb63d0f8902b (diff) | |
download | vdr-plugin-graphlcd-0703b948dd63eb281df5dc531abdf66818becdf7.tar.gz vdr-plugin-graphlcd-0703b948dd63eb281df5dc531abdf66818becdf7.tar.bz2 |
cExtData is now a singleton class, thus its content survives a DISCONN/CONNECT of a display; trans() now works as expected; three new tokens: 'IsMenuList', 'MenuText', 'MenuTextScroll'; support added for ':clean' and ':rest' for tokens 'MenuTitle', 'MenuCurrent', and 'MenuText'
Diffstat (limited to 'common.c')
-rw-r--r-- | common.c | 61 |
1 files changed, 61 insertions, 0 deletions
@@ -1,10 +1,13 @@ #include <time.h> #include <glcdskin/type.h> +#include <glcdskin/string.h> #include <vdr/plugin.h> #include <string.h> +#include "strfct.h" + #if APIVERSNUM < 10503 #include <locale.h> @@ -157,3 +160,61 @@ int ParanoiaStrcmp(const char *s1, const char *s2) else return rv; } + +const std::string SplitText(const std::string &Text, const std::string &Delim, bool firstPart = true) { + size_t found = Text.find(Delim); + + if (found != std::string::npos) { + return (firstPart) ? Text.substr(0, found) : Text.substr(found + Delim.size()); + } + return (firstPart) ? Text : NULL; +} + +const std::string SplitToken(const std::string &Token, const struct GLCD::tSkinAttrib Attrib, bool extSplit) { + if (Attrib.Type == GLCD::aClean) { + if (extSplit) { + std::string Text = SplitText(Token, " - ", true); + + // also cut leading index numbers, eg: "1 Menu" -> "Menu" + size_t pos = 0; + bool exitw = false; + bool valid = true; + + while (!exitw && valid && pos < Text.size()-1) { + if (Text[pos] == ' ') { + pos++; + } else { + valid = (isdigit(Text[pos]) || Text[pos] == ' ' || Text[pos] == '\t') ? true : false; + exitw = true; + } + } + + exitw = false; + while (!exitw && valid && pos < Text.size()-1) { + if (isdigit(Text[pos])) { + pos++; + } else { + valid = (Text[pos] == ' ' || Text[pos] == '\t') ? true : false; + exitw = true; + } + } + + exitw = false; + while (!exitw && valid && pos < Text.size()-1) { + if (Text[pos] == ' ') { + pos++; + } else { + exitw = true; + } + } + + if (valid && Text[pos] == '\t') + pos++; + return trim( (valid) ? Text.substr(pos) : Text ); + } + return SplitText(Token, " - ", true); + } else if (Attrib.Type == GLCD::aRest) { + return SplitText(Token, " - ", false); + } + return Token; +} |