#ifndef STRING_H
#define STRING_H


//*****************************************************************************
//
//			STring.h
//
//*****************************************************************************
//
//      Copyright (C) 1996 
//
//                      Ronald A. MacCracken
//			Graduate Student
//                      Computer Science Department
//                      University of California
//                      Davis, CA  95616
//
//      Permission is granted to use at your own risk and 
//      distribute this software in source and binary forms 
//      provided the above copyright notice and this paragraph 
//      are preserved on all copies.  This software is provided 
//      "as is" with no express or implied warranty.
//
//*****************************************************************************

#include <iostream.h>

enum	{ FALSE = 0 , TRUE } ;


//
// The reason that the T is capitalized is that String is a typedef in IrisGL;
// so, if you plan on doing any graphics work, I advise against renaming the class.
//


class STring 
{

private :

    char*		str ;
    int			length ;


private:

    void		Copy   ( const STring& ) ;
    void		Delete ( void ) ;


public :

    enum 		{ NO_SUBSTRING = -1 } ;


			// default constructor

      			STring ( void ) ;


			// user-defined constructors

			STring ( const int     ) ;
			STring ( const char    ) ;
			STring ( const char*   ) ;
			STring ( const double& ) ;


			// copy constructor

			STring ( const STring& ) ;


			// destructor

			~STring ( void ) ;


			// assignment operator

    STring& 		operator=  ( const STring& ) ;


			// in place concatenate operator

    STring& 		operator+= ( const STring& ) ;


			// extraction operator returning substring
			// starting at index i with length n

    STring 		operator() ( const int i , const int n ) const ;


			// character index operators

    char&		operator[] ( const int ) ;
    const char&	 	operator[] ( const int ) const ;


			// implicit casting operators to a character pointer

    			operator char*       ( void ) 		{ return str ; }
    			operator const char* ( void ) const 	{ return str ; }


			// access functions

    char* 		Get_String ( void ) const ;
    int 		Get_Length ( void ) const 	     { return length ; }


			// searches for substring s in string - if found,
			// returns index of first character of s in string,
			// else returns NO_SUBSTRING

    int 		Has_Substring ( const STring& s ) const ;

    int                 Has_Suffix ( const STring& s ) ;


			// determines whether string has all numeric characters

    int 		Is_Numeric   ( void ) const ;


			// returns integer value of string if it is numeric

    int 		Int_Value    ( void ) const ;


			// returns double value of string if it is numeric

    double 		Double_Value ( void ) const ;


			// make string all lower or upper case

    void		To_Lower_Case ( void ) ;
    void		To_Upper_Case ( void ) ;


			// concatenate two strings

    friend STring 	operator+  ( const STring& , const STring& ) ;


			// string comparison operators

    friend int 		operator== ( const STring& , const STring& ) ;
    friend int 		operator!= ( const STring& , const STring& ) ;
    friend int 		operator<  ( const STring& , const STring& ) ;
    friend int 		operator<= ( const STring& , const STring& ) ;
    friend int 		operator>  ( const STring& , const STring& ) ;
    friend int 		operator>= ( const STring& , const STring& ) ;


			// string I/O operators

    friend istream& 	operator>> ( istream& , STring& ) ;
    friend ostream& 	operator<< ( ostream& , const STring& ) ;

} ;


extern const STring	NullString ;	// default string

#endif

