#ifndef _string_h #define _string_h #include #include // // string class -- a subset of the standard C++ string class // as defined in the draft ANSI document as: // // typedef basic_string string; // // This is a proper subset. All functions are part of the draft standard // // 6/26/95 Mike Clancy, Stu Hirshfield, Chris Nevison, // Owen Astrachan, Barbara Boucher Owens, // //====================================================================== // Changes made by Rick Mercer on 25-Sep-1995 (remove 1..12 later) // // 1. renamed s parameters to str (see standard) // // 2. Changed // assign s to: // assign str to this object // // 3. Renamed s and t to lhs and rhs (see standard) // // 4. After private: Changed // mind your own business // to: // implementation dependent // // 5. Moved these functions out of the class dec. Do we need them? // int rfind(const string & s) const; // as find, from right // int rfind(char ch) const; // as find, from right // // 6. Changed wording from // concatenate string // to // append str to this object // // 7. Added these two includes // #include // #include // // 8. Added the size and empty member functions // // 9. Added string(const char * s); // // 10. Added string & operator = (const char * s); // // 11. Changed mutator to modifiers // // 12. Addded //----- for readability in string-d.cpp //====================================================================== // // class string { public: //-----constructors string(); // default constructor, "" string(const char * s); // initializer: string("chars") string(const string & str); // copy constructor //-----assignment string & operator = (const string & str); // assign str to this object string & operator = (const char * s); // assign s to this object string & operator = (char ch); // assign ch to this object //-----accessors // RETURN: int length() const; // number of chars bool empty() const; // size() == 0 char operator[int k] const; // k-th char (copy) int find(const string & str) const; // index of str's start int find(char ch) const; // index of first ch string substr(int pos, int len) const; // len chars starting at pos //-----modifiers char & operator[int k]; // return k-th char reference string & operator += (const string & str); // append str to this object string & operator += (char ch); // append char to this object private: // implementation dependent }; // end class string // The following free (non-member) functions are part of the string module: //-----relational 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); //-----stream I/O functions ostream & operator << (ostream & os, const string & str); istream & operator >> (istream & os, const string & str); istream & getline(istream & is, string & str); //-----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 // _string_h not defined