diff options
Diffstat (limited to 'lib/String.cc')
-rw-r--r-- | lib/String.cc | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/lib/String.cc b/lib/String.cc index c7cfce6..062587d 100644 --- a/lib/String.cc +++ b/lib/String.cc @@ -8,6 +8,8 @@ #include "String.h" #include "Exceptions.h" +char ** gruikptr; + #ifdef USE_DATE extern "C" { double dateCalc(char *, char *); @@ -19,21 +21,30 @@ char String::t[BUFSIZ + 1]; String::String(const String & s) : str(Base::strdup(s.str)), siz(s.siz) { #ifdef DEBUG - fprintf(stderr, "Duplicating string `%s', from %p to %p\n", str, s.str, str); + fprintf(stderr, "Duplicating string `%s', from %p to %p, from this %p to this %p\n", str, s.str, str, s, this); #endif + ostr = Base::strdup(str); } String::String(char c) : siz(1) { char * t = (char *) malloc(2); +#ifdef DEBUG + fprintf(stderr, "Creating a string with `%c' at %p, this = %p\n", c, str, this); +#endif sprintf(t, "%c", c); str = t; + ostr = Base::strdup(str); } String::String(const char * s) : str(Base::strdup(s)), siz(::strlen(str)) { + if (!strcmp(s, "testing")) { + gruikptr = &str; + } #ifdef DEBUG - fprintf(stderr, "Creating a string with `%s' at %p\n", str, str); + fprintf(stderr, "Creating a string with `%s' at %p from %p, this = %p\n", str, str, s, this); #endif + ostr = Base::strdup(str); } #if 0 @@ -52,7 +63,12 @@ String::String(const char * s, ...) { } #endif -String::String(int hs, const char * s) : str(s ? Base::strdup(s) : Base::strdup("")), siz(hs) { } +String::String(int hs, char * s) : str(Base::strdup(s ? s : "")), siz(hs) { +#ifdef DEBUG + fprintf(stderr, "Fast-Creating a string with `%s' at %p from %p, this = %p\n", str, str, s, this); +#endif + ostr = Base::strdup(str); +} String::String(int i) { char t[20]; @@ -97,6 +113,10 @@ String::String(double d) { } String::~String() { +#ifdef DEBUG + fprintf(stderr, "Destroying string @ %p, freeing %p.\n", this, str); + fprintf(stderr, "Destroying string `%s'\n", ostr); +#endif free(str); } @@ -192,14 +212,11 @@ String & String::operator=(const String & s) { String String::operator+(const String & s) const { char * t = (char *) malloc(s.siz + siz + 1), * u; - String o; strcpy((u = t), str); u += siz; strcpy(u, s.str); - o = String(siz + s.siz, t); - free(t); - return o; + return String(siz + s.siz, t); } String & String::operator+=(const String & s) { |