diff options
Diffstat (limited to 'libs/pbd/strsplit.cc')
-rw-r--r-- | libs/pbd/strsplit.cc | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/libs/pbd/strsplit.cc b/libs/pbd/strsplit.cc index 7f29a77887..1fb6112150 100644 --- a/libs/pbd/strsplit.cc +++ b/libs/pbd/strsplit.cc @@ -1,6 +1,7 @@ #include <pbd/strsplit.h> using namespace std; +using namespace Glib; void split (string str, vector<string>& result, char splitchar) @@ -39,3 +40,41 @@ split (string str, vector<string>& result, char splitchar) result.push_back (remaining); } } + +void +split (ustring str, vector<ustring>& result, char splitchar) +{ + ustring::size_type pos; + ustring remaining; + ustring::size_type len = str.length(); + int cnt; + + cnt = 0; + + if (str.empty()) { + return; + } + + for (ustring::size_type n = 0; n < len; ++n) { + if (str[n] == gunichar(splitchar)) { + cnt++; + } + } + + if (cnt == 0) { + result.push_back (str); + return; + } + + remaining = str; + + while ((pos = remaining.find_first_of (':')) != ustring::npos) { + result.push_back (remaining.substr (0, pos)); + remaining = remaining.substr (pos+1); + } + + if (remaining.length()) { + + result.push_back (remaining); + } +} |