// © Copyright 1995, Joseph Bergin. All rights reserved.
#ifndef __Strngs__
#define __Strngs__

#include <iostream.h>
#include <string.h>

class String{
	public:
	// constructors
		String();
			// Construct an empty string.
			
		String(const char *s);
			// Construct a string from a low level string or a string literal
			// such as "These are the times"
			
		String(const String &s);
			// Construct a string from another.
			
		String(unsigned long);
			// Construct a string containing the characters in the base 10
			// representation of an integer.
			
	// destructor
		~String();
			// Destroy a string when no longer needed.  This is not called by
			// the programmer. The C++ system calls this.
			
	// assignment
		String & operator = (const String &s);
			// Called when we assign one string to another.
			
	// catenation
		String operator + (char c);
			// Append the character c to the right end of a string.
			
		String operator + (const String &s);
			// Append the string s to the end of another string.

		friend String operator + (char c, const String &s);
			// Append a character c to the beginning of s.
			
	// tests & transfers
		int operator == (const String &s)const;
			// Compare two strings for equality.
			
		int operator != (const String &s)const;
			// Compare two strings for equality.
			
		int operator < (const String &s)const;
			// Compare two strings lexicographically.
			
//		operator const char*() const;
			// Force a String to be interpreted as a low level string.
			
		char * value() const; 
			// Returns a newly allocated char*.  The user is responsible for deleting it. 
			
	// others
		int length() const;
			// The length of a string.
			
		String & strip();
			// Revoves leading and trailing spaces and tabs.
			// Returns this.  
			
		char &operator [] (unsigned int);
			// Index the characters of a string. 
			
		String sub(unsigned int start, unsigned int len);
			// Extract a substring from another, starting at start, for len
			// characters.  
			
		int search(char what, unsigned int start); // -1 if not found.
			// Search for what, starting at start.
			
	private:
		char *_elements;
		void copy(const String& s);
		void free();
		
	friend istream& operator >>(istream&, String&);
		// Input a string from a stream and return that stream. 
		
	friend ostream& operator <<(ostream&, const String&);
		// Output a string on a stream and return that stream. 
};

	
#endif
