// ---------------------------------------------------------------------------
// String.h
//
// A useful String class if the built-in string class isn't available on
// a given compiler.
//
// Paul McNamee  10/95 - 8/97
// --------------------------------------------------------------------------

#ifndef STRINGCLASS_H
#define STRINGCLASS_H

#include <string.h>
#include <iostream.h>

class String {
    friend ostream& operator<< (ostream &, const String &);
    friend class StringIter;

  private:
    int _len;         // length==string w/o NUL (i.e., like strlen())
    char * _str;

    // Optional ctor.  Useful for building efficient operator+(). Kept private
    String::String(const char*, int, const char*, int);   

  public:
    // Default Ctor
    String() {
      _len = 5;
      _str = new char [_len + 1];
      strcpy(_str, "blank");
    }

    // One argument, (char *) Ctor. -- Must copy chars (defined in String.C)
    String(const char *s);
      
    // Ctor to copy a (bad), non-nul terminated (char *) string (see String.C)
    String(const char *s, int l);

    // Copy ctor
    String(const String &s) {
      _len = s._len;
      _str = new char [_len + 1];
      strcpy(_str, s._str);
    };
    
    // Destructor
    ~String() { delete [] _str; };

    // Assignment operators.  One for Strings and one for (char *)
    //   -- These must copy chars!
    const String & operator=(const String &s);
    const String & operator=(const char *s);

    // String ops
    int len() const  { return _len; };
    ostream &print(ostream &os) const;          // Declare function  

    const String & operator+=(const char *s);   // Append contents to current string
    String operator+(const char *s) const;      // Create a new string w/ both

    int operator==(const char *s) const;        // Is string equivalent to a char *
    int operator!=(const char *s) const;        // Is string diff from a char*

    // A cast operator.  (Don't worry about this!)
    operator const char*() const     { return _str; };
};

// A non-member function
ostream & operator<<(ostream &, const String &); 


// Used to include StringIter class here as well, but don't need it for 201.

#endif
