diff options
Autocommit at 30.05.2022 @ 20:23
1 files changed, 33 insertions, 4 deletions
| -rw-r--r-- | src/UserInterface/UserInterface.cpp | 37 |
diff --git a/src/UserInterface/UserInterface.cpp b/src/UserInterface/UserInterface.cpp index d2de4f3..190bb54 100644 --- a/src/UserInterface/UserInterface.cpp +++ b/src/UserInterface/UserInterface.cpp @@ -77,6 +77,8 @@ void UserInterface::com_print(const char* params) { printTable(cells, table->get_cols()); } +#define isDigit(a) (a >= '0' && a <= '9') + void UserInterface::com_edit(const char* params) { if (*params != 'R') { printLine("Error: Invalid cell position format! Expected R<number>C<number>"); @@ -84,12 +86,39 @@ void UserInterface::com_edit(const char* params) { } unsigned row = atoi(++params); - while (*params != 'C') params++; + while (*params != 'C') { + if (*params == '\0') { + printLine("Error: End of line reached. Expected row number."); + return; + } + if (!isDigit(*params)) { + printLine("Error: Found a non-digit character. Exptected row number."); + return; + } + + params++; + } unsigned col = atoi(++params); - while (*params != ' ') params++; + while (*params != ' ') { + if (*params == '\0') { + printLine("Error: End of line reached. Expected columns number."); + return; + } + if (!isDigit(*params)) { + printLine("Error: Found a non-digit character. Exptected column number."); + return; + } + + params++; + } - table->putCell(row, col, params); - saved = false; + try { + table->putCell(row, col, params); + saved = false; + } + catch (std::logic_error err) { + printLine(err.what()); + } } /* Public */ |
