// Oldham, Jeffrey D. // 2000Mar13 // CS1321 // // Modified by: // Massingill, Berna L. // 2000 Apr 03 // Brain-Dead String Editor Class Implementation // uses our dll class // modified to use dll class's iterator -- see **** comments. #include "dll.h" #include class buffer { public: buffer(void) { pos = line.end(); } void backCursor(void) { if (pos != line.begin()) --pos; // ****was: pos = pos->prev return; } void forwardCursor(void) { if (pos != line.end()) ++pos; // ****was: pos = pos->next } void deleteChar(void) { if (pos != line.end()) pos = line.erase(pos); } void insertChars(const string & s) { if (s.empty()) return; else { line.insert(pos, s[0]); insertChars(s.substr(1)); return; } } // **** must remove "const" from buffer, because begin() and // end() are no longer "const" member functions -- see dll.h friend ostream& operator<<(ostream& out, buffer & b) { for (dll::iterator p = b.line.begin(); p != b.line.end(); ++p) // ****was: p = p->next out << *p; // ****was: out << p->itm return out; } // Print a line showing the cursor's position. // **** must remove "const" from buffer, because begin() and // end() are no longer "const" member functions -- see dll.h friend ostream& printCursor(ostream& out, buffer & b) { for (dll::iterator p = b.line.begin(); p != b.pos; ++p) // ****was: p = p->next out << ' '; return out << '^'; } private: dll line; // contents of line dll::iterator pos; // points to where characters inserted // and deleted // ****was: dll::link * pos };