summaryrefslogtreecommitdiff
path: root/src/BString.cc
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2014-06-20 21:31:41 -0700
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2014-06-20 21:31:41 -0700
commitdf9b8f8ae7a540988c20fdffaaff2442c349873a (patch)
treeff9be69934b6896c8d7e91412b63dd9cd9b37341 /src/BString.cc
parentfcc66ce9f5d6db995536beab5539fd47e490bf14 (diff)
Moving tokenize, percentEncode and percentDecode around. Fixing a few warnings. Workarounding c-ares and pthreads compilation issue with unicode.
Diffstat (limited to 'src/BString.cc')
-rw-r--r--src/BString.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/BString.cc b/src/BString.cc
index 4ba3601..5f4b868 100644
--- a/src/BString.cc
+++ b/src/BString.cc
@@ -154,3 +154,25 @@ Balau::String::List Balau::String::split(char c) {
free(d);
return r;
}
+
+std::vector<Balau::String> Balau::String::tokenize(const String & delimiters, bool trimEmpty) {
+ std::vector<String> tokens;
+ size_t pos, lastPos = 0;
+ for (;;) {
+ pos = find_first_of(delimiters, lastPos);
+ if (pos == String::npos) {
+ pos = strlen();
+
+ if ((pos != lastPos) || !trimEmpty)
+ tokens.push_back(extract(lastPos, pos));
+
+ return tokens;
+ }
+ else {
+ if ((pos != lastPos) || !trimEmpty)
+ tokens.push_back(extract(lastPos, pos));
+ }
+
+ lastPos = pos + 1;
+ }
+}