Chameleon Applications

Chameleon Applications Svn Source Tree

Root/trunk/ChameleonPrefPane/Sources/string_util.cpp

1/*
2 * string_util.cpp
3 * ChameleonPrefPane
4 *
5 * Created by Rekursor on 1/23/10.
6 */
7
8#include "string_util.h"
9
10/*
11 * String Tokenizer
12 * In: src string and separator
13 * Out: a list of string tokens
14 */
15std::list<std::string> tokenize(const std::string& src, const std::string& sep)
16{
17std::list<std::string> ret;
18if (src.length()==0) return ret;
19
20std::string::size_type left=0, right=0;
21std::string token;
22std::string::size_type len = sep.length();
23
24for (left=0; (right = src.find(sep, left)) != std::string::npos; left = right + len )
25{
26token = src.substr (left, right-left);
27if (token.length()>0) ret.push_back (token);
28}
29token = src.substr(left);
30if (token.length()>0) ret.push_back (token);
31
32return ret;
33}
34
35

Archive Download this file

Revision: 49