//======================================================== // File: string.h // Author: Timothy A. Budd // Description: This file contains the interface of the // string class. // // Copyright (c) 1992 by Timothy A. Budd. All Rights Reserved. // may be reproduced for any non-commercial purpose //======================================================== #ifndef C_STRING_H #define C_STRING_H #include int CstringLength(const char * str); class Substring; // forward declaration //--------------------------------------------------------- // class string // better bounds checking, assignments which result // in copies, comparisons using relational operators, // high level operations such as substrings //--------------------------------------------------------- class String { public: // constructors String(); String(char); String(int); String(const char *); String(const String &); // destructor ~String(); // assignment an catenation void operator = (const String & right); void operator += (const String & right); // substring access Substring operator () (unsigned int start, unsigned int length); // input of an entire line of text istream & getline(istream &); // number of characters in the string unsigned int length() const; // access to a single character char & operator [](unsigned int) const; // compare - used in relational operators int compare(const String &) const; // conversion to ordinary C string operator const char *() const; // allow access by substring class friend class Substring; private: // data fields - character buffer and length unsigned short int bufferlength; char * buffer; }; //--------------------------------------------------------- // class substring // facilitator class to permit access to // portions of a string //--------------------------------------------------------- class Substring { public: // constructors Substring(String & base, int start, int length); Substring(const Substring & source); // assignment of string to substring void operator = (const String &) const; // conversion of substring to string operator String () const; private: // data areas String & base; const short int index; const short int count; }; // Function Prototypes: relational operators int operator < (const String &, const String &); int operator <= (const String &, const String &); int operator != (const String &, const String &); int operator == (const String &, const String &); int operator >= (const String &, const String &); int operator > (const String &, const String &); // Function Prototype: concatenate operator String operator + (const String &, const String &); // Function Prototypes: character classification int isUpperCase(char c); int isLowerCase(char c); // Function Prototypes: string conversions void toUpper(String & word); void toLower(String & word); // Function Prototype: stream input istream & operator >> (istream & in, String & str); #endif /* C_STRING_H */