From 2860b03f00e48264ed15c132ad90b240ebe6070b Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 6 Apr 2013 13:14:47 +0200 Subject: tagging ychat-0.7.9.5 --- src/tool/tool.cpp | 273 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 196 insertions(+), 77 deletions(-) (limited to 'src/tool/tool.cpp') diff --git a/src/tool/tool.cpp b/src/tool/tool.cpp index e2ef9ae..8a470cd 100644 --- a/src/tool/tool.cpp +++ b/src/tool/tool.cpp @@ -1,3 +1,27 @@ +/*:* + *: File: ./src/tool/tool.cpp + *: + *: yChat; Homepage: www.yChat.org; Version 0.7.9.5-RELEASE + *: + *: Copyright (C) 2003 Paul C. Buetow, Volker Richter + *: Copyright (C) 2004 Paul C. Buetow + *: Copyright (C) 2005 EXA Digital Solutions GbR + *: + *: 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 2 + *: 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *:*/ + #ifndef TOOL_CPP #define TOOL_CPP @@ -11,134 +35,229 @@ #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(); +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 ); - } + 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 ); + list_ret.push_back( s_string ); - return list_ret; + return list_ret; } string tool::trim( string s_str ) { - if(s_str.empty()) - return ""; + if( s_str.empty() ) + return s_str; - char c_cur = s_str[0]; - auto int pos=0; + char c_cur = s_str[0]; + int i_pos = 0; - // left trim - while (c_cur==' '|| c_cur == '\n' || c_cur == '\r') - { - s_str.erase(pos,1); - c_cur = s_str[++pos]; - } + // left trim + while ( c_cur == ' '|| c_cur == '\n' || c_cur == '\r' ) + { + s_str.erase(i_pos,1); + c_cur = s_str[++i_pos]; + } - // right trim - pos=s_str.size(); - c_cur = s_str[s_str.size()]; + // right trim + i_pos = s_str.size(); + c_cur = s_str[s_str.size()]; - while (c_cur==' ' || c_cur == '\n' || c_cur == '\0' || c_cur == '\r') - { - s_str.erase(pos,1); - c_cur = s_str[--pos]; - } + while ( c_cur == ' ' || c_cur == '\n' || c_cur == '\0' || c_cur == '\r' ) + { + s_str.erase(i_pos, 1); + c_cur = s_str[--i_pos]; + } - return s_str; + return s_str; } char* tool::clean_char( char* c_str ) { // Ralf: - char *c_pos; - for (c_pos = c_str; *c_pos != '\0'; ++c_pos) - if ( iscntrl(*c_pos) ) *c_pos = ' '; + for ( char* 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 int i_pos[2]; + unsigned i_pos[2]; - for ( i_pos[0] = s_string.find( s_search ); - i_pos[0] != string::npos; - i_pos[0] = s_string.find( s_search, i_pos[1] ) ) - { - s_string.replace( i_pos[0], s_search.length(), s_replace ); - i_pos[1] = i_pos[0] + s_replace.length(); - } + for ( i_pos[0] = s_string.find( s_search ); + i_pos[0] != string::npos; + i_pos[0] = s_string.find( s_search, i_pos[1] ) ) + { + s_string.replace( i_pos[0], s_search.length(), s_replace ); + i_pos[1] = i_pos[0] + s_replace.length(); + } - return s_string; + return s_string; } string tool::get_extension( string s_file ) { - int pos = s_file.find_last_of("."); - if(pos != string::npos) - { - string s_ext=s_file.substr(pos+1, s_file.size()-(pos+1)); - for(int i = 0;i