Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Models / CellFormula.cpp
diff options
context:
space:
mode:
Commite968dfecdfed467e6b0af3bc74e8bbe0a71e2020 (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-06-14 08:08:40 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-06-14 08:08:40 +0300
Filesc0e2b6a3f724495edfe549c9b33825c243af11d6 /src/Models/CellFormula.cpp
FMI-OOP-P2_Tables-e968dfecdfed467e6b0af3bc74e8bbe0a71e2020.tar
FMI-OOP-P2_Tables-e968dfecdfed467e6b0af3bc74e8bbe0a71e2020.tar.gz
FMI-OOP-P2_Tables-e968dfecdfed467e6b0af3bc74e8bbe0a71e2020.zip
Parentdfe7f167c060a92aa92f5c9ae649065706494405 (diff)
Autocommit at 14.06.2022 @ 08:08
1 files changed, 14 insertions, 5 deletions
-rw-r--r--src/Models/CellFormula.cpp19
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<char>& buffer) {
buffer.add(*(str++));
}
+void O(const char*& str, List<char>& 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<char> 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++;