3 // Copyright 2010 Micke Nordin <mickewiki@gmail.com>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 // MA 02110-1301, USA.
21 vector<string> explode(string str, string separator) {
22 vector<string> results; //To hold the reslut
23 string::size_type found; //Varible to compare with
24 found = str.find_first_of(separator); //See if/where we have the separator
25 while(found != string::npos) { //While we have separators
26 if(found > 0) { //If we have a match
27 results.push_back(str.substr(0,found)); //Put it in the vector
29 str = str.substr(found+1); //Remove the part that has allready been used
30 found = str.find_first_of(separator);//Find next
32 if(str.length() > 0) { //Special case for the last bit
33 results.push_back(str);
39 string reverse(string &str) {
40 char c[str.size() + 1];
43 for(int i = str.size(); i > 0; i--) {
53 string trim(string &str, char const* sepSet) {
54 string::size_type const first = str.find_first_not_of(sepSet); //Find first char that is not the ones we want to remove
56 if(first==string::npos ) {
59 str = str.substr(first, str.find_last_not_of(sepSet)-first+1); //If we have chars we want to keep return those
61 str.substr(first, str.find_last_not_of(sepSet)-first+1);