File: tokenize.cpp

package info (click to toggle)
cufflinks 1.3.0-2
  • links: PTS, VCS
  • area: non-free
  • in suites: wheezy
  • size: 3,864 kB
  • sloc: cpp: 48,999; ansic: 12,297; sh: 3,381; python: 432; makefile: 209
file content (39 lines) | stat: -rw-r--r-- 1,223 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <string>
#include <vector>
#include <cassert>

using namespace std;

/**
 * Split string s according to given delimiters.  Mostly borrowed
 * from C++ Programming HOWTO 7.3.
 */
void tokenize(const string& s, const string& delims, vector<string>& ss) {
	string::size_type lastPos = s.find_first_not_of(delims, 0);
	string::size_type pos = s.find_first_of(delims, lastPos);
	while (string::npos != pos || string::npos != lastPos) {
		ss.push_back(s.substr(lastPos, pos - lastPos));
        lastPos = s.find_first_not_of(delims, pos);
        pos = s.find_first_of(delims, lastPos);
    }
}

/**
 * Split string s according to given delimiters. If two delimiters occur in
 * succession, sticks an empty string token at that position in ss
 */
void tokenize_strict(const string& s, const string& delims, vector<string>& ss) {
	string::size_type lastPos = s.find_first_not_of(delims, 0);
	string::size_type pos = s.find_first_of(delims, lastPos);
	while (lastPos < s.length() || pos < s.length()) {
		ss.push_back(s.substr(lastPos, pos - lastPos));
		if (pos == string::npos)
			break;
        lastPos = pos + 1;
        pos = s.find_first_of(delims, lastPos);
    }
}