Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Models / CellFormula.cpp
diff options
context:
space:
mode:
Commit72b920b16fc59d4d2ce4625924b832f7a679f35f (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-06-14 12:59:08 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-06-14 12:59:08 +0300
Files4013f1556ef9befb33f7a849110016ffc19ab85a /src/Models/CellFormula.cpp
FMI-OOP-P2_Tables-72b920b16fc59d4d2ce4625924b832f7a679f35f.tar
FMI-OOP-P2_Tables-72b920b16fc59d4d2ce4625924b832f7a679f35f.tar.gz
FMI-OOP-P2_Tables-72b920b16fc59d4d2ce4625924b832f7a679f35f.zip
Parent0b7357b568824d5d46b6d5ea931842e3e4bdcc00 (diff)
Autocommit at 14.06.2022 @ 12:59
1 files changed, 5 insertions, 4 deletions
-rw-r--r--src/Models/CellFormula.cpp9
diff --git a/src/Models/CellFormula.cpp b/src/Models/CellFormula.cpp
index 745c623..3c2fd26 100644
--- a/src/Models/CellFormula.cpp
+++ b/src/Models/CellFormula.cpp
@@ -88,8 +88,9 @@ void D(const char*& str, List<char>& buffer) {
}
void O(const char*& str, char& buffer) {
- if (*str == '+' || *str == '-' || *str == '*' || *str == '/' || *str == '^')
+ if (*str == '+' || *str == '-' || *str == '*' || *str == '/' || *str == '^' || *str == '\0')
buffer = *(str++);
+ else buffer = -2;
}
void CellFormula::parseAndSetValue(const char* str) {
@@ -99,7 +100,7 @@ void CellFormula::parseAndSetValue(const char* str) {
localCells.clear();
localCells.add(CellDouble(0.0));
Pair<int, int> loc;
- char currOp = 0;
+ char currOp = -2;
str++; // Removes = from the beginning
while (*str != '\0') {
@@ -114,7 +115,7 @@ void CellFormula::parseAndSetValue(const char* str) {
D(str, buffer);
loc.right = atoi(buffer.raw_data()) - 1;
if (loc.left < 0 || loc.right < 0
- || tableCells->get_count() - 1 < loc.left || tableCells[loc.left].get_count() - 1 < loc.right) {
+ || loc.left > tableCells->get_count() - 1 || loc.right > tableCells[loc.left].get_count() - 1) {
loc.left = -1;
loc.right = 0;
}
@@ -137,7 +138,7 @@ void CellFormula::parseAndSetValue(const char* str) {
W(str);
O(str, currOp);
- if (currOp == 0) throw std::logic_error("Error: Could not find operand!");
+ if (currOp == -2) throw std::logic_error("Error: Could not find operand!");
// Operator priority magic
if (currOp == '^') currOp *= -1;