From 0703b948dd63eb281df5dc531abdf66818becdf7 Mon Sep 17 00:00:00 2001 From: mrwastl Date: Sat, 17 Sep 2011 21:28:10 +0200 Subject: 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' --- common.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'common.c') diff --git a/common.c b/common.c index 439540d..1b73d13 100644 --- a/common.c +++ b/common.c @@ -1,10 +1,13 @@ #include #include +#include #include #include +#include "strfct.h" + #if APIVERSNUM < 10503 #include @@ -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; +} -- cgit v1.2.3