From df9b8f8ae7a540988c20fdffaaff2442c349873a Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Fri, 20 Jun 2014 21:31:41 -0700 Subject: Moving tokenize, percentEncode and percentDecode around. Fixing a few warnings. Workarounding c-ares and pthreads compilation issue with unicode. --- src/BString.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/BString.cc') 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::tokenize(const String & delimiters, bool trimEmpty) { + std::vector 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; + } +} -- cgit v1.2.3