// string2.h -- Declarations for the String library
// Coded by Ben Greear

// Everyone is free to use this code, just leave my name intact.
// This has not been tested very much, so use at your own risk!! :)

// Any questions, write me at:  greear@pollux.cs.uga.edu

 
#ifndef String2Include
#define String2Include

#define TRUE 	1
#define FALSE 	0

#include <stdio.h> 
#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <unistd.h>

extern void log(const char* msg);

class String {
   private:

      char *string;
      int max_len;
      int cur_len;
 
   public:
 
      String  (); //default constructor
      String  (const char* S);
      String  (const String& S);
      String  (const int m_len);
      ~String ();
 

   
     ///*********************  OPERATORS  ******************************///

      String& operator+= (const String &S);
      String& operator+= (const char* S);
      String& operator+= (const char s);
      String& operator= (const String &S);
      String& operator= (const char* S);
      char& operator[] (const unsigned int i) const;
      String operator+ (const char* S) const;
      String operator+ (const String& S) const;
      int operator== (const char* S) const;
      int operator!= (const char* S) const;
      int operator> (const char* S) const;
      int operator< (const char* S) const;
      int operator> (const String& S) const;
      int operator< (const String& S) const;
      int operator>= (const char* S) const;
      int operator<= (const char* S) const;
      operator const char* () const;


///********************  FRIEND OVERLOADS  **************************///

      friend ostream& operator<< (ostream& stream, const String& str);
      friend istream& operator>> (istream& stream, String& str);
      friend void Sprintf(String& targ, const char* string, ...);
      friend int Strncompare(const String& a, const String& b);

///**********************  MEMBER FUNCTIONS  ************************///

      void Clear();
      void Prepend(const int source);
      void Prepend(const long source);
      void Prepend(const char* source);
      void Prepend(const String& source);
      void Append(const int source);
      void Append(const long source);
      void Append(const char* source);
      void Append(const String& source);
      void Append(const char source);
      void Getline(istream& stream, int max_len);
      void Cap();
      void Tolower(); //makes total string lowercase
      void Vclear(); //virtually clears it, (copies '\0' into first posn)
      int  Strlen() const;
      void Report() const; //logs vital stats, for debugging.
      int  Write(const int desc, const int max_to_write);
           //writes to a descriptor, deletes what it writes
      int  Read(const int desc, const int max_to_read); //reads from a desc
      void Termed_Read(ifstream& da_file);
      short Contains(const char ch) const;
      void  Refigure_strlen();			//bletcherous hack!
      void parse_show(short posn);  //specific to ScryMUD program
      void InsertAfter(char a, int posn);
      void InsertBefore(char a, int posn);

    	/* Both of these next two delete what they grab from the string. */

      String Get_Command(short& eos, short& term_by_period);	
				//grabs first word or number deliminated
				//by space, a '.' or null char

      String Get_Rest(short destruct = TRUE);	//grabs phrase, deliminated 
			//by a newline or null char

      String Look_Command() const; //grabs first word or number deliminated
				//by space, a '.' or null char, does not 
				//delete it from the string.

};
#endif

