Encapsulate obscure detail that lower numeric priority is higher queue priority
[clinton/bobotpp.git] / source / Socket.C
index 33a42d0..1e8b89b 100644 (file)
@@ -1,5 +1,5 @@
 // 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
@@ -14,7 +14,8 @@
 
 // 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"
@@ -263,7 +264,7 @@ Socket::readLine()
   // 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 ();
@@ -292,14 +293,15 @@ Socket::readLine()
     } 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