+// php.cpp
+//
+// Copyright 2010 Micke Nordin <mickewiki@gmail.com>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+// MA 02110-1301, USA.
+#include "php.hpp"
+
+vector<string> explode(string str, string separator) {
+ vector<string> results; //To hold the reslut
+ string::size_type found; //Varible to compare with
+ found = str.find_first_of(separator); //See if/where we have the separator
+ while(found != string::npos) { //While we have separators
+ if(found > 0) { //If we have a match
+ results.push_back(str.substr(0,found)); //Put it in the vector
+ }
+ str = str.substr(found+1); //Remove the part that has allready been used
+ found = str.find_first_of(separator);//Find next
+ }
+ if(str.length() > 0) { //Special case for the last bit
+ results.push_back(str);
+ }
+
+ return results;
+}
+
+string reverse(string &str) {
+ char c[str.size() + 1];
+ int j = 0;
+
+ for(int i = str.size(); i > 0; i--) {
+ c[j] = str[i];
+ j++;
+ }
+ c[str.size()] = '\0';
+ string rstr = c;
+ return rstr;
+
+}
+
+string trim(string &str, char const* sepSet) {
+ string::size_type const first = str.find_first_not_of(sepSet); //Find first char that is not the ones we want to remove
+
+ if(first==string::npos ) {
+ return string();
+ } else {
+ str = str.substr(first, str.find_last_not_of(sepSet)-first+1); //If we have chars we want to keep return those
+ str = reverse(str);
+ str.substr(first, str.find_last_not_of(sepSet)-first+1);
+ return reverse(str);
+ }
+}