X-Git-Url: https://git.hcoop.net/clinton/bobotpp.git/blobdiff_plain/4f4c0ce6826406da17ed129877ba4a187d4f219b..46af16674dcdeaa42e8482e8ef2608bcc7156c3a:/source/Utils.C diff --git a/source/Utils.C b/source/Utils.C index 67a316d..3db5182 100644 --- a/source/Utils.C +++ b/source/Utils.C @@ -1,6 +1,6 @@ // Utils.C -*- C++ -*- // Copyright (c) 1997, 1998 Etienne BERNARD -// Copyright (c) 2005 Clinton Ebadi +// Copyright (c) 2005,2008 Clinton Ebadi // 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 @@ -14,7 +14,7 @@ // 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. +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #ifdef HAVE_CONFIG_H #include "config.h" @@ -52,7 +52,7 @@ Utils::get_key() bool Utils::IP_p (std::string host) { - for (int i = 0; i < host.length(); i++) + for (std::string::size_type i = 0; i < host.length(); i++) if (!std::isdigit (host[i]) && host[i] !='.') return false; return true; @@ -123,13 +123,13 @@ Utils::valid_channel_name_p (std::string c) #define isvalid(c) (((c) >= 'A' && (c) <= '~') || std::isdigit(c) || (c) == '-') bool -Utils::valid_nickname_p (std::string n) +Utils::valid_nickname_p (const Bot *b, std::string n) { // FIXME: make max nick length configurable - if (n[0] == '-' || std::isdigit(n[0]) || n.length() > 9) + if (n[0] == '-' || std::isdigit(n[0]) || n.length() > b->MAX_NICKLENGTH) return false; - for (int i = 0; i < n.length(); i++) + for (std::string::size_type i = 0; i < n.length(); i++) if (!isvalid(n[i]) || std::isspace (n[i])) return false; @@ -217,9 +217,9 @@ Utils::str2time(std::string str) if (!std::isdigit (str[0])) return 0; - num.reserve (512); // reverse a buffer to speed things up + num.reserve (64); // reserve a buffer to speed things up - for (int i = 0; i < str.length(); i++) + for (std::string::size_type i = 0; i < str.length(); i++) { switch (str[i]) { @@ -280,7 +280,7 @@ Utils::to_upper (std::string s) { std::string::iterator it; - for (it = s.begin (); it != s.end (); ++it) + for (it = s.begin (); it != s.end (); it++) *it = std::toupper (*it); return s; @@ -289,7 +289,7 @@ Utils::to_upper (std::string s) std::string Utils::trim_str (std::string s) { - int i = 0, j = s.length (); + int i = 0, j = s.length () - 1; while (i < j && std::isspace (s[i])) i++; @@ -297,7 +297,7 @@ Utils::trim_str (std::string s) while (j > 0 && std::isspace (s[j])) j--; - return s.substr (i, j); + return s.substr (i, j - i + 1); } #ifdef USESCRIPTS @@ -306,7 +306,7 @@ std::string Utils::scm2str (SCM s) { // FIXME: uses gh_, replace with scm_ - char *tmp = gh_scm2newstr(s, 0); + char *tmp = scm_to_locale_string (s); std::string temp (tmp); free(tmp); @@ -318,6 +318,6 @@ Utils::scm2str (SCM s) SCM Utils::str2scm (std::string s) { - return gh_str02scm (s.c_str ()); + return scm_from_locale_string (s.c_str ()); } #endif