***********************
** FILE NAME : string.cpp
** SYSTEM NAME : Andromeda X-Windows Encapsulation
-** VERSION NUMBER : $Revision: 1.4 $
+** VERSION NUMBER : $Revision: 1.5 $
**
** DESCRIPTION : String class implementation.
**
********************************
** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
** CREATION DATE : Nov 17, 1997
-** LAST UPDATE : Nov 03, 2002
+** LAST UPDATE : Nov 30, 2003
** MODIFICATIONS :
**************************************************************************/
/*****************************
$Log: string.cpp,v $
- Revision 1.4 2003-03-29 07:18:54 arjen
+ Revision 1.5 2007-05-04 13:55:18 arjen
+ Dynamically allocate more memory if the string buffer runs out of space when
+ reading a String object from an input stream.
+
+ Revision 1.4 2003/03/29 07:18:54 arjen
String constructor and assignment from char * are more robust fro NULL pointers.
Revision 1.3 2002/11/03 13:18:57 arjen
*****************************/
-static const char RCSID[] = "$Id: string.cpp,v 1.4 2003-03-29 07:18:54 arjen Exp $";
+static const char RCSID[] = "$Id: string.cpp,v 1.5 2007-05-04 13:55:18 arjen Exp $";
#include <stdio.h>
#include <ctype.h>
std::istream& operator>>(std::istream& s, String& x)
{
- char buf[1024];
+ char *buf;
int i;
+ int bufsize = 1024;
+
+ buf = new char[bufsize];
+
i = -1;
do
{
+ if (i >= bufsize)
+ {
+ // Buffer is too small. Allocate some new space.
+
+ char *newbuf = new char[bufsize * 2];
+ memcpy(newbuf, buf, bufsize);
+ delete [] buf;
+ buf = newbuf;
+ bufsize *= 2;
+ }
+
i++;
s.get(buf[i]);
}
buf[i] = '\0';
}
x = buf;
+
+ delete [] buf;
+
return s;
}