// File: astring1.C
//
// Implementation of a silly string class

#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <string.h>
#include "astring1.h"

AString::AString() {
   str = NULL ;
   length = -1 ;
}

AString::AString(const char * s) {
   length = -1 ;

   if (s == NULL) {
      str = NULL ;
      return ;
   }

   str = strdup(s) ;
   if (str == NULL) {
      cerr << "Oops" << endl ;
      exit(1) ;
   }
}

AString::AString(const AString& as) {
   length = -1 ;
   if (as.str == NULL){
      str = NULL ;
      return ;
   }

   length = as.len() ;
   str = strdup(as.str) ;
   if (str == NULL) {
      cerr << "Oops" << endl ;
      exit(1) ;
   }
}

int AString::len() {
   if (length >= 0) return length ;

   if (str == NULL) {
      length = 0 ;
      return 0 ;
   }

   length = strlen(str) ;
   return length ;
}
