STinC++ rewrites the programs in Software Tools in Pascal using C++
I had a few minutes last night, so cracked open the laptop and implemented the insert command.
(.) i insert text before line (text follows)
Text entered with a , c and i is terminated with a line containing just a . . |
I popped another branch into the if
ladder in editor::process
…
void editor::process(std::istream& in, std::ostream& out) {
while(in.peek() != eof) {
auto line = stiX::getline(in);
if (line == "=")
out << buffer_.dot() << "\n";
else if (line == "i")
do_insert(in, buffer_);
else
out << "?\n";
}
}
... then implemented the function I’d just imagined.
void do_insert(std::istream& in, edit_buffer& buffer) {
while(in.peek() != eof) {
auto line = stiX::getline(in);
if (line == ".")
return;
buffer.insert_before(buffer.dot(), line);
}
}
I was actually a little startled, because I was expecting it to take slightly longer, but I just typed it in and it worked.