// StringSegment03.h // tom bailey 9 mar 06 // Declare the StringSegment class. // ver 1: constructor from two string iterators // print the segment // tom bailey 17 mar 06 // ver 2: operator< // tom bailey 20 mar 06 // ver 3: matchLength #if ! defined( STRINGSEGMENT_H_ ) #define STRINGSEGMENT_H_ #include #include // Access to strings is via a constant iterator. #define StrCIt std::string::const_iterator class StringSegment { public: // post: This StringSegment represents the string between the // two string iterators begin and end. StringSegment( StrCIt begin, StrCIt end ); // post: Up to limit characters of this StringSegment have // been written to outfile. void write( std::ostream & outfile, size_t limit = -1, std::string delim = "" ) const; // post: True has been returned just if this StringSegment // lexicographically precedes other. bool operator<( const StringSegment & other ) const; // post: The length of the matching prefix of this StringSegment // and other has been returned. size_t matchLength( const StringSegment & other ) const; bool is_prefix(const StringSegment & other) const; // post: The begin iterator has been returned. StrCIt beginIter() const; // post: The end iterator has been returned. StrCIt endIter() const; private: StrCIt begin; StrCIt end; }; std::ostream & operator<<( std::ostream &, const StringSegment & ); #endif