// 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
// 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"
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;
#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;
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])
{
{
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;
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++;
while (j > 0 && std::isspace (s[j]))
j--;
- return s.substr (i, j);
+ return s.substr (i, j - i + 1);
}
#ifdef USESCRIPTS
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);
SCM
Utils::str2scm (std::string s)
{
- return gh_str02scm (s.c_str ());
+ return scm_from_locale_string (s.c_str ());
}
#endif