// Socket.C -*- C++ -*-
-// Copyright (C) 2002 Clinton Ebadi
+// Copyright (C) 2002,2005 Clinton Ebadi
// Copyright (c) 1997, 1998 Etienne BERNARD
// This program is free software; you can redistribute it and/or modify
// 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.
#include "Socket.H"
#include "Bot.H"
// that only the line that was just read is returned.
static std::string buf (512, ' ');
- int pos = 0; // pos in buffer
+ std::string::size_type pos = 0; // pos in buffer
int nb; // number of bytes read by ::read
char r; // temp var for storing output of read into
std::string::size_type length = buf.length ();
} while (r != '\n');
if (pos > 1 && buf[pos-2] == '\r')
- buf[pos-2] = '\0';
+ {
+ buf[pos-2] = '\0';
+ return String (buf.substr (0, pos - 2));
+ }
else
- buf[pos-1] = '\0';
-
- // c_str () is used because the String constructor for std::string
- // will copy the entire std::string into it when we only want it to
- // copy up to the first null.
- return String (buf.c_str ());
+ {
+ buf[pos-1] = '\0';
+ return String (buf.substr (0, pos - 1));
+ }
}
String