From e968dfecdfed467e6b0af3bc74e8bbe0a71e2020 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Tue, 14 Jun 2022 08:08:40 +0300 Subject: Autocommit at 14.06.2022 @ 08:08 --- src/Models/CellFormula.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/Models/CellFormula.cpp') diff --git a/src/Models/CellFormula.cpp b/src/Models/CellFormula.cpp index 4e7449c..4b2c0f8 100644 --- a/src/Models/CellFormula.cpp +++ b/src/Models/CellFormula.cpp @@ -71,7 +71,7 @@ String CellFormula::getValueForPrint() const { // Rough implementation of the grammar // -// S -> WDS | WD.DS | WRDRDS | WOS | W +// S -> WDS | WD.DS | WRDCDS | WOS | W // O -> + | - | * | / | ^ // D -> D0 | D1 | ... | D9 | 0 | 1 | ... | 9 // W -> W | epsilon @@ -87,6 +87,11 @@ void D(const char*& str, List& buffer) { buffer.add(*(str++)); } +void O(const char*& str, List& buffer) { + if (*str == '+' || *str == '-' || *str == '*' || *str == '/' || *str == '^') + buffer.add(*(str++)); +} + void CellFormula::parseAndSetValue(const char* str) { rawFormula = String(str); @@ -94,11 +99,15 @@ void CellFormula::parseAndSetValue(const char* str) { char currOp; while (*str != '\0') { - str++; - while (*str == ' ') str++; + List buffer; + W(str); if (*str == 'R') { - int row = atoi(++str); - while (*str != 'C') str++; + D(str, buffer); + int row = atoi(buffer.raw_data()); + if (*str != 'C') throw std::logic_error("Error: Invalid character!"); + str++; + buffer.clear(); + D(str, buffer); int col = atoi(++str); while (*str != ' ' && *str != '\0') str++; while (*str == ' ') str++; -- cgit v1.3.1-23-gd82d