Added path.cc and tokenizer.h from win32 branch.
[ardour.git] / libs / pbd3 / strsplit.cc
1 #include <pbd/strsplit.h>
2
3 using namespace std;
4
5 void
6 split (string str, vector<string>& result, char splitchar)
7 {       
8         string::size_type pos;
9         string remaining;
10         string::size_type len = str.length();
11         int cnt;
12
13         cnt = 0;
14
15         if (str.empty()) {
16                 return;
17         }
18
19         for (string::size_type n = 0; n < len; ++n) {
20                 if (str[n] == splitchar) {
21                         cnt++;
22                 }
23         }
24
25         if (cnt == 0) {
26                 result.push_back (str);
27                 return;
28         }
29
30         remaining = str;
31
32         while ((pos = remaining.find_first_of (':')) != string::npos) {
33                 result.push_back (remaining.substr (0, pos));
34                 remaining = remaining.substr (pos+1);
35         }
36
37         if (remaining.length()) {
38
39                 result.push_back (remaining);
40         }
41 }