Invert Pan-Azimuth (up means left)
[ardour.git] / libs / pbd / strsplit.cc
1 /*
2  * Copyright (C) 2000-2015 Paul Davis <paul@linuxaudiosystems.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18
19 #include "pbd/strsplit.h"
20
21 using namespace std;
22 using namespace Glib;
23
24 void
25 split (string str, vector<string>& result, char splitchar)
26 {
27         string::size_type pos;
28         string remaining;
29         string::size_type len = str.length();
30         int cnt;
31
32         cnt = 0;
33
34         if (str.empty()) {
35                 return;
36         }
37
38         for (string::size_type n = 0; n < len; ++n) {
39                 if (str[n] == splitchar) {
40                         cnt++;
41                 }
42         }
43
44         if (cnt == 0) {
45                 result.push_back (str);
46                 return;
47         }
48
49         remaining = str;
50
51         while ((pos = remaining.find_first_of (splitchar)) != string::npos) {
52                 if (pos != 0) {
53                         result.push_back (remaining.substr (0, pos));
54                 }
55                 remaining = remaining.substr (pos+1);
56         }
57
58         if (remaining.length()) {
59
60                 result.push_back (remaining);
61         }
62 }
63
64 void
65 split (ustring str, vector<ustring>& result, char splitchar)
66 {
67         ustring::size_type pos;
68         ustring remaining;
69         ustring::size_type len = str.length();
70         int cnt;
71
72         cnt = 0;
73
74         if (str.empty()) {
75                 return;
76         }
77
78         for (ustring::size_type n = 0; n < len; ++n) {
79                 if (str[n] == gunichar(splitchar)) {
80                         cnt++;
81                 }
82         }
83
84         if (cnt == 0) {
85                 result.push_back (str);
86                 return;
87         }
88
89         remaining = str;
90
91         while ((pos = remaining.find_first_of (splitchar)) != ustring::npos) {
92                 result.push_back (remaining.substr (0, pos));
93                 remaining = remaining.substr (pos+1);
94         }
95
96         if (remaining.length()) {
97
98                 result.push_back (remaining);
99         }
100 }