// Author: Joseph Bertolami // Email: jbertola@uci.edu #ifndef _D_STRING_H_ // may be included more than once #define _D_STRING_H_ #include #include #include class DString { friend class DFile; friend class DGFile; public: void setChar(char c, int index); // note: before the string is set/reset you cannot use any of the // string functions! b/c buffer == NULL DString() : buffer(NULL), length(0) {} DString(const DString & rhs); DString(const char *str); ~DString(); // operator = // assigns rhs to *this DString operator = (const DString & rhs); // char * operator = (DString & rhs); // operator + // cat's rhs onto *this DString operator + (DString & rhs); // operator += DString operator += (DString & rhs); DString operator += (char * rhs); // char *substr // returns a pointer to the first occurrence of // string 'token' in string 'str' char * substr(const char *token, const char *str); char operator [](unsigned int index); // do not ignore case for now, b/c input file is all same case! bool operator == (DString & rhs); // unsigned nsubstr // returns number of occurrences of substring token // in string 'str' unsigned nsubstr(const char *token, const char *str); DString substr(int start, int end); // returns 0 if no match // note, if comparisons begin coming up wrong, // slow this function down by enforcing ascii // comparison to avoid erroneous data int strcmp(DString & string2); char * data(); void clear(); unsigned size(); void print(); void set(const char *text); protected: char *buffer; unsigned length; }; #endif