// comment line below if bool is a built-in type #ifndef _LVPSTRING_H_ #define _LVPSTRING_H_ #include #include "cvclibdef.h" // ******************************************************************* // Last Revised: 11/24/98 corrected specification comments // // APCS string class // // string class consistent with a subset of the standard C++ string class // as defined in the draft ANSI standard // ******************************************************************* extern const int npos; // used to indicate not a position in the string class String { public: // constructors/destructor String( ); // construct empty string "" String( const char * s ); // construct from string literal String( const String & str ); // copy constructor ~String( ); // destructor // assignment const String & operator = ( const String & str ); // assign str const String & operator = ( const char * s ); // assign s const String & operator = ( char ch ); // assign ch // accessors int length( ) const; // number of chars int find( const String & str ) const; // index of first occurrence of str int find( char ch ) const; // index of first occurrence of ch String substr( int pos, int len ) const; // substring of len chars // starting at pos const char * c_str( ) const; // explicit conversion to char * // indexing char operator[ ]( int k ) const; // range-checked indexing char & operator[ ]( int k ); // range-checked indexing // modifiers const String & operator += ( const String & str );// append str const String & operator += ( char ch ); // append char private: int myLength; // length of string (# of characters) int myCapacity; // capacity of string char * myCstring; // storage for characters }; // The following free (non-member) functions operate on strings // // I/O functions ostream & operator << ( ostream & os, const String & str ); istream & operator >> ( istream & is, String & str ); istream & getline( istream & is, String & str ); // comparison operators: bool operator == ( const String & lhs, const String & rhs ); bool operator != ( const String & lhs, const String & rhs ); bool operator < ( const String & lhs, const String & rhs ); bool operator <= ( const String & lhs, const String & rhs ); bool operator > ( const String & lhs, const String & rhs ); bool operator >= ( const String & lhs, const String & rhs ); // concatenation operator + String operator + ( const String & lhs, const String & rhs ); String operator + ( char ch, const String & str ); String operator + ( const String & str, char ch ); #endif