***********************
** FILE NAME : string.cpp
** SYSTEM NAME : Andromeda X-Windows Encapsulation
-** VERSION NUMBER : $Revision: 1.3 $
+** VERSION NUMBER : $Revision: 1.4 $
**
** DESCRIPTION : String class implementation.
**
/*****************************
$Log: string.cpp,v $
- Revision 1.3 2002-11-03 13:18:57 arjen
+ 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
New functions - String::escape() and String::unescape()
Revision 1.2 2002/09/28 06:42:11 arjen
*****************************/
-static const char RCSID[] = "$Id: string.cpp,v 1.3 2002-11-03 13:18:57 arjen Exp $";
+static const char RCSID[] = "$Id: string.cpp,v 1.4 2003-03-29 07:18:54 arjen Exp $";
#include <stdio.h>
#include <ctype.h>
String::String(const char *s) // Create a String from a char *
{
p = new srep;
- p->s = new char[strlen(s)+1];
- strcpy(p->s, s);
+
+ p->s = 0;
p->n = 1;
+
+ if (s != 0)
+ {
+ p->s = new char[strlen(s)+1];
+ strcpy(p->s, s);
+ p->n = 1;
+ }
}
String::String(const String& x) // Create a String from another String
else if (p->n == 1)
delete p->s;
- p->s = new char[strlen(s)+1];
- strcpy(p->s, s);
- p->n = 1;
+ if (s != 0)
+ {
+ p->s = new char[strlen(s)+1];
+ strcpy(p->s, s);
+ p->n = 1;
+ }
return *this;
}