summaryrefslogtreecommitdiff
path: root/helpers.c
diff options
context:
space:
mode:
authorlouis <louis.braun@gmx.de>2013-09-18 10:46:16 +0200
committerlouis <louis.braun@gmx.de>2013-09-18 10:46:16 +0200
commit150767e987edd810053fbf44d8e840eb30930c6b (patch)
treead46fd1c0e346aff4ea1565a2623123e660babf5 /helpers.c
parent8cac48f1606c6a48226141dd94a59101dd10b1e0 (diff)
downloadskin-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.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/helpers.c b/helpers.c
index 0f8d42d..8de3bf2 100644
--- a/helpers.c
+++ b/helpers.c
@@ -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