7 #include <pbd/whitespace.h>
12 Tokenize string, this should work for standard
13 strings as well as Glib::ustring. This is a bit of a hack,
14 there are much better string tokenizing patterns out there.
15 If strip_whitespace is set to true, tokens will be checked to see
16 that they still have a length after stripping. If no length, they
19 template<typename StringType, typename Iter>
21 tokenize(const StringType& str,
22 const StringType& delims,
24 bool strip_whitespace=false)
26 typename StringType::size_type start_pos = 0;
27 typename StringType::size_type end_pos = 0;
28 unsigned int token_count = 0;
31 start_pos = str.find_first_not_of(delims, start_pos);
32 end_pos = str.find_first_of(delims, start_pos);
33 if (start_pos != end_pos) {
34 if (end_pos == str.npos) {
35 end_pos = str.length();
37 if (strip_whitespace) {
38 StringType stripped = str.substr(start_pos, end_pos - start_pos);
39 strip_whitespace_edges (stripped);
40 if (stripped.length()) {
44 *it++ = str.substr(start_pos, end_pos - start_pos);
47 start_pos = str.find_first_not_of(delims, end_pos + 1);
49 } while (start_pos != str.npos);
51 if (start_pos != str.npos) {
52 if (strip_whitespace) {
53 StringType stripped = str.substr(start_pos, str.length() - start_pos);
54 strip_whitespace_edges (stripped);
55 if (stripped.length()) {
59 *it++ = str.substr(start_pos, str.length() - start_pos);
69 #endif // PBD_TOKENIZER