--- smsdaemon/util.cpp 2008/06/09 18:15:53 26 +++ smsdaemon/util.cpp 2008/06/11 06:46:14 43 @@ -2,6 +2,8 @@ #include #include #include +#include + #include #include #include @@ -28,15 +30,53 @@ - void str_clean(string* str, string search, string replace) + string str_replace(string str, string search, string replace) { unsigned int pos = 0; - while ( (pos = str->find(search,pos)) != string::npos) + while ( (pos = str.find(search,pos)) != string::npos) { - str->replace(pos, search.size(), replace); + 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) @@ -61,6 +101,76 @@ return retval; } + + string str_toupper(string str) + { + for (unsigned i=0; i