#include #include #include #include #include #include #include #include #include "util.h" using namespace std; namespace Util { void str_dump(const string& str) { for (unsigned i=0; i(str.at(i)) << " "; } cout.width(1); cout << dec << endl; } string str_replace(string str, string search, string replace) { unsigned int pos = 0; while ( (pos = str.find(search,pos)) != string::npos) { str.replace(pos, search.size(), replace); pos += replace.size(); } return str; } std::string str_replace_char(std::string str, char search, char replace) { unsigned int pos = 0; while ( (pos = str.find(search,pos)) != string::npos) { str.replace(pos, 1, 1, replace); } return str; } string str_trim(string str) { while (str.length() > 0 && isspace(str.at(0))) str.erase(0,1); while (str.length() > 0 && isspace(str.at(str.length()-1))) str.erase(str.length()-1,1); return str; } string str_striptags(string str) { unsigned int pos=0; while ( (pos=str.find("<",pos)) != string::npos) { unsigned int endpos = str.find(">",pos); if (endpos == string::npos) break; str.erase(pos, (endpos-pos)+1); } return str; } vector str_split(string input, string delimiter) { vector retval; while ( 1 ) { unsigned int endpos = input.find(delimiter); string entry = input.substr(0,endpos); retval.push_back( entry ); if (endpos == string::npos) break; endpos += delimiter.length(); input = input.substr(endpos, input.length() - endpos); } return retval; } string str_toupper(string str) { for (unsigned i=0; i