From d4c9f10efe815af146438cafb694d16da0e5650a Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 6 Apr 2013 13:14:47 +0200 Subject: tagging ychat-0.7.0 --- src/tool/tool.cpp | 161 +++++++++--------------------------------------------- 1 file changed, 26 insertions(+), 135 deletions(-) (limited to 'src/tool/tool.cpp') diff --git a/src/tool/tool.cpp b/src/tool/tool.cpp index dec9bdb..1da4a12 100644 --- a/src/tool/tool.cpp +++ b/src/tool/tool.cpp @@ -11,135 +11,30 @@ #include "tool.h" -bool -tool::is_alpha_numeric( string &s_digit ) -{ - const char *p_digit = s_digit.c_str(); - int i_len = strlen( p_digit ); - - for( int i=0; i= '0' && *p_digit <='9') - { - i_res = (i_res * 10) + (*p_digit - '0'); - p_digit++; - } - - // Check that there were no non-digits at end. - if (*p_digit != 0) - { - return -1; - } - - return i_res; -} - -string -tool::to_lower( string s_str ) -{ - string s_tmp(""); - - for( int i = 0; i < s_str.size() ;i++ ) - s_tmp = s_tmp + (char) tolower( s_str.at(i) ); - - return s_tmp; -} - -void -tool::strip_html( string *p_str) -{ - int i_pos; - - if( (i_pos=p_str->find("<", 0)) == string::npos ) - return; - - while(true) - { - p_str->replace(i_pos, 1, "<"); - - if( (i_pos = p_str->find("<", 0)) == string::npos ) - return; - } -} - -string -tool::ychat_version() -{ - return "yChat " + string(VERSION) - + "-" + string(BRANCH) - + " Build " + int2string(BUILDNR); -} - -list -tool::split_string(string s_string, string s_split) { - list list_ret; - unsigned i_pos, i_len = s_split.length(); - - while ( (i_pos = s_string.find(s_split)) != string::npos ) - { - list_ret.push_back( s_string.substr(0, i_pos) ); - s_string = s_string.substr( i_pos + i_len ); - } - - list_ret.push_back( s_string ); - - return list_ret; -} - string tool::trim( string s_str ) { - if( s_str.empty() ) - return s_str; + if(s_str.empty()) + return ""; char c_cur = s_str[0]; - int i_pos = 0; + auto int pos=0; // left trim - while ( c_cur == ' '|| c_cur == '\n' || c_cur == '\r' ) + while (c_cur==' '|| c_cur == '\n' || c_cur == '\r') { - s_str.erase(i_pos,1); - c_cur = s_str[++i_pos]; + s_str.erase(pos,1); + c_cur = s_str[++pos]; } // right trim - i_pos = s_str.size(); + pos=s_str.size(); c_cur = s_str[s_str.size()]; - while ( c_cur == ' ' || c_cur == '\n' || c_cur == '\0' || c_cur == '\r' ) + while (c_cur==' ' || c_cur == '\n' || c_cur == '\0' || c_cur == '\r') { - s_str.erase(i_pos, 1); - c_cur = s_str[--i_pos]; + s_str.erase(pos,1); + c_cur = s_str[--pos]; } return s_str; @@ -149,16 +44,16 @@ char* tool::clean_char( char* c_str ) { // Ralf: - for ( char* c_pos = c_str; *c_pos != '\0'; ++c_pos ) + char *c_pos; + for (c_pos = c_str; *c_pos != '\0'; ++c_pos) if ( iscntrl(*c_pos) ) *c_pos = ' '; - return c_str; } string tool::replace( string s_string, string s_search, string s_replace ) { - unsigned i_pos[2]; + unsigned int i_pos[2]; for ( i_pos[0] = s_string.find( s_search ); i_pos[0] != string::npos; @@ -174,34 +69,32 @@ tool::replace( string s_string, string s_search, string s_replace ) string tool::get_extension( string s_file ) { - int i_pos = s_file.find_last_of("."); - - if( i_pos != string::npos ) + int pos = s_file.find_last_of("."); + if(pos != string::npos) { - string s_ext = s_file.substr(i_pos+1, s_file.size()-i_pos-1 ); - for( int i = 0; i < s_ext.size(); ++i ) - s_ext[i] = tolower(s_ext[i]); + string s_ext=s_file.substr(pos+1, s_file.size()-(pos+1)); + for(int i = 0;i