Skip to content

Commit 72fcfe5

Browse files
authored
Merge branch 'main' into feature/expression-plotting-helpers
2 parents 148ed51 + 0bb670c commit 72fcfe5

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/core/Core/funcs.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,33 @@ inline std::string trim(const std::string& s) {
2828
return s.substr(start, end - start + 1);
2929
}
3030

31+
// function to find top-level '=' that's not part of ==, <=, >=, !=
32+
static size_t findTopLevelEquals(const std::string& str) {
33+
int depth = 0;
34+
35+
for (size_t i = 0; i < str.size(); ++i) {
36+
char c = str[i];
37+
if (c == '(') {
38+
++depth;
39+
} else if (c == ')') {
40+
--depth;
41+
} else if (c == '=' && depth == 0) {
42+
// check it's not part of ==, <=, >=, !=
43+
bool isOperator = false;
44+
if (i > 0 && (str[i-1] == '=' || str[i-1] == '<' || str[i-1] == '>' || str[i-1] == '!')) {
45+
isOperator = true;
46+
}
47+
if (i + 1 < str.size() && str[i+1] == '=') {
48+
isOperator = true;
49+
}
50+
51+
if (!isOperator) {
52+
return i;
53+
}
54+
}
55+
}
56+
return std::string::npos;
57+
}
58+
3159
#endif // IMGRAPH_FUNCS_HPP
3260

0 commit comments

Comments
 (0)