diff options
| Commit | d5f4221f7820a774fd209c7a75a8a526aeec7ee2 (patch) | |
|---|---|---|
| Author | 2022-05-30 20:23:22 +0300 | |
| Committer | 2022-05-30 20:23:22 +0300 | |
| Files | 2596e8cbe06901c95979746df028c004288be9d1 /src | |
| FMI-OOP-P2_Tables-d5f4221f7820a774fd209c7a75a8a526aeec7ee2.tar FMI-OOP-P2_Tables-d5f4221f7820a774fd209c7a75a8a526aeec7ee2.tar.gz FMI-OOP-P2_Tables-d5f4221f7820a774fd209c7a75a8a526aeec7ee2.zip | ||
| Parent | 4ae838df9d22037273fe97edc25971e6358549fb (diff) | |
Autocommit at 30.05.2022 @ 20:23
2 files changed, 36 insertions, 5 deletions
| -rw-r--r-- | src/Models/Table.cpp | 4 | ||||
| -rw-r--r-- | src/UserInterface/UserInterface.cpp | 37 |
diff --git a/src/Models/Table.cpp b/src/Models/Table.cpp index 892a05d..4aab10e 100644 --- a/src/Models/Table.cpp +++ b/src/Models/Table.cpp @@ -127,10 +127,12 @@ void Table::putCell(unsigned row, unsigned col, const char* rawValue) { newCell = (abs(doubleParse) - intPart > FLOATING_POINT_PRECISION) ? (Cell*)new CellDouble(doubleParse) : (Cell*)new CellInt(intPart); } - else { + else if (*rawValue == '"') { newCell = (*rawValue == '=') ? (Cell*)new CellFormula(rawValue, &cells) : (Cell*)new CellString(rawValue); } + else + throw std::logic_error("Error: Could not determine data type."); if (cells[row][col] != nullptr) 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 */ |
