diff options
| author | Jan Tuomi <jan-sebastian.tuomi@aalto.fi> | 2016-10-09 14:19:46 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan-sebastian.tuomi@aalto.fi> | 2016-10-09 14:50:24 +0300 |
| commit | da5ecb5de0ca0bc099258f7b77480fbb28b31392 (patch) | |
| tree | 8fe86fc9c244cc2ec8e9603f7c444c34eb124ac0 | |
| parent | 2b77640618425c015bb8e35c06c5ad4eb290ac72 (diff) | |
Add prepend before line
| -rw-r--r-- | editor.cpp | 22 | ||||
| -rw-r--r-- | editor.h | 2 |
2 files changed, 24 insertions, 0 deletions
@@ -36,7 +36,11 @@ int Editor::run_editor() { case 'a': append_after_command(); break; + case 'b': + prepend_before_command(); + break; default: + std::cout << "Not a recognized command " << input << ".\n"; break; } } @@ -188,3 +192,21 @@ int Editor::append_after_line(int line) { return edit_line(line + 1); } +int Editor::prepend_before_command() { + std::cout << "Prepend before which line? "; + int line; + std::cin >> line; + if (std::cin.fail() || line < 0 || line >= m_contents->size()) { + std::cout << "Not a valid line number!\n"; + std::cin.clear(); + std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n'); + return 1; + } + + return prepend_before_line(line); +} + +int Editor::prepend_before_line(int line) { + m_contents->insert(m_contents->begin() + line, ""); + return edit_line(line); +} @@ -23,12 +23,14 @@ class Editor { int quit_command(); int delete_and_clamp_command(); int append_after_command(); + int prepend_before_command(); int edit_line(int line); int move_to_line(int line); int write(); int delete_and_clamp(int line); int append_after_line(int line); + int prepend_before_line(int line); }; #endif |
