diff options
author | louis <louis.braun@gmx.de> | 2013-09-18 10:46:16 +0200 |
---|---|---|
committer | louis <louis.braun@gmx.de> | 2013-09-18 10:46:16 +0200 |
commit | 150767e987edd810053fbf44d8e840eb30930c6b (patch) | |
tree | ad46fd1c0e346aff4ea1565a2623123e660babf5 /helpers.c | |
parent | 8cac48f1606c6a48226141dd94a59101dd10b1e0 (diff) | |
download | skin-nopacity-150767e987edd810053fbf44d8e840eb30930c6b.tar.gz skin-nopacity-150767e987edd810053fbf44d8e840eb30930c6b.tar.bz2 |
improved function to float text around poster in textwindow
Diffstat (limited to 'helpers.c')
-rw-r--r-- | helpers.c | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -108,4 +108,35 @@ static std::string CutText(std::string text, int width, const cFont *font) { } } return cuttedText; +} + +class splitstring : public std::string { + std::vector<std::string> flds; +public: + splitstring(const char *s) : std::string(s) { }; + std::vector<std::string>& split(char delim, int rep=0); +}; + +// split: receives a char delimiter; returns a vector of strings +// By default ignores repeated delimiters, unless argument rep == 1. +std::vector<std::string>& splitstring::split(char delim, int rep) { + if (!flds.empty()) flds.clear(); // empty vector if necessary + std::string work = data(); + std::string buf = ""; + int i = 0; + while (i < work.length()) { + if (work[i] != delim) + buf += work[i]; + else if (rep == 1) { + flds.push_back(buf); + buf = ""; + } else if (buf.length() > 0) { + flds.push_back(buf); + buf = ""; + } + i++; + } + if (!buf.empty()) + flds.push_back(buf); + return flds; }
\ No newline at end of file |