Skip to content

Commit 8af0541

Browse files
refactor: extract helper function into funcs.hpp
1 parent 81033dc commit 8af0541

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

src/core/Core/Application.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,6 @@
2020

2121
namespace App {
2222

23-
// function to find top-level '=' that's not part of ==, <=, >=, !=
24-
static size_t findTopLevelEquals(const std::string& str) {
25-
int depth = 0;
26-
27-
for (size_t i = 0; i < str.size(); ++i) {
28-
char c = str[i];
29-
if (c == '(') {
30-
++depth;
31-
} else if (c == ')') {
32-
--depth;
33-
} else if (c == '=' && depth == 0) {
34-
// check it's not part of ==, <=, >=, !=
35-
bool isOperator = false;
36-
if (i > 0 && (str[i-1] == '=' || str[i-1] == '<' || str[i-1] == '>' || str[i-1] == '!')) {
37-
isOperator = true;
38-
}
39-
if (i + 1 < str.size() && str[i+1] == '=') {
40-
isOperator = true;
41-
}
42-
43-
if (!isOperator) {
44-
return i;
45-
}
46-
}
47-
}
48-
return std::string::npos;
49-
}
50-
5123
Application::Application(const std::string& title) {
5224
APP_PROFILE_FUNCTION();
5325

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)