diff options
author | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2014-06-20 21:31:41 -0700 |
---|---|---|
committer | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2014-06-20 21:31:41 -0700 |
commit | df9b8f8ae7a540988c20fdffaaff2442c349873a (patch) | |
tree | ff9be69934b6896c8d7e91412b63dd9cd9b37341 /src/BString.cc | |
parent | fcc66ce9f5d6db995536beab5539fd47e490bf14 (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.cc | 22 |
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; + } +} |