Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Models / CellFormula.cpp
diff options
context:
space:
mode:
Commit3082d96e3338bfb9dc8fa94039192ce1030b4d47 (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-06-14 08:28:46 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-06-14 08:28:46 +0300
Filesc67254bf5109e58687685d9f7133c0a36a1c1dfb /src/Models/CellFormula.cpp
FMI-OOP-P2_Tables-3082d96e3338bfb9dc8fa94039192ce1030b4d47.tar
FMI-OOP-P2_Tables-3082d96e3338bfb9dc8fa94039192ce1030b4d47.tar.gz
FMI-OOP-P2_Tables-3082d96e3338bfb9dc8fa94039192ce1030b4d47.zip
Parentb3a6a4936eca7f8809cf05b9324fc57e68fa9073 (diff)
Autocommit at 14.06.2022 @ 08:28
1 files changed, 15 insertions, 6 deletions
-rw-r--r--src/Models/CellFormula.cpp21
diff --git a/src/Models/CellFormula.cpp b/src/Models/CellFormula.cpp
index e2919f3..1ef0357 100644
--- a/src/Models/CellFormula.cpp
+++ b/src/Models/CellFormula.cpp
@@ -1,4 +1,5 @@
#include "CellFormula.h"
+#include "CellInt.h"
#include "CellDouble.h"
#include <cstring>
#include <iostream>
@@ -110,14 +111,17 @@ void CellFormula::parseAndSetValue(const char* str) {
D(str, buffer);
loc.right = atoi(buffer.raw_data());
W(str);
-
- O(str, currOp);
- if (currOp == 0) throw std::logic_error("Error: Could not find operand!");
- W(str);
}
else if (*str >= '0' && *str <= '9') {
- double val = atof(str);
- while ((*str >= '0' && *str <= '9') || *str == ' ' || *str == '.') str++;
+ D(str, buffer);
+ if (*str == '.') {
+ buffer.add(*str);
+ D(++str, buffer);
+ localCells.add(CellDouble(atof(buffer.raw_data())));
+ }
+ else
+ localCells.add(CellInt(atoi(buffer.raw_data())));
+ W(str);
currOp = *str;
localCells.add(CellDouble(val));
@@ -126,6 +130,11 @@ void CellFormula::parseAndSetValue(const char* str) {
else
throw std::logic_error("Error: Invalid value!");
+ O(str, currOp);
+ if (currOp == 0) throw std::logic_error("Error: Could not find operand!");
+ W(str);
+
+
if (currOp == '^') currOp *= -1;
else if ((currOp == '+' || currOp == '-') && formula.get_count() != 0) {
for (unsigned i = formula.get_count() - 1; i < formula.get_count() && (formula[i].right == '*' || formula[i].right == '/'); i--)