Skip to content

Commit 1ad2458

Browse files
committed
refactor RemoveIncompatibilities to enhance iteration logic and ensure proper handling of JSON elements
1 parent 5c23d80 commit 1ad2458

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

compatibility/compatibility.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ namespace compatibility
6060

6161
void RemoveIncompatibilities(nlohmann::json& json)
6262
{
63-
64-
for (auto jsonIter = json.begin(); jsonIter != json.end(); ++jsonIter)
63+
for (auto jsonIter = json.begin(); jsonIter != json.end();)
6564
{
6665
const auto& key = jsonIter.key();
6766
auto& value = jsonIter.value();
@@ -77,23 +76,24 @@ namespace compatibility
7776
else if (value.is_object())
7877
{
7978
RemoveIncompatibilities(value);
79+
++jsonIter;
8080
}
8181
else if (value.is_array())
8282
{
83-
auto idx = 0;
8483
for (auto valueIter = value.begin(); valueIter != value.end();)
8584
{
86-
auto& item = *valueIter;
87-
88-
if (item.is_object())
89-
RemoveIncompatibilities(item);
85+
if (valueIter->is_object())
86+
RemoveIncompatibilities(*valueIter);
9087

9188
++valueIter;
9289
}
90+
91+
++jsonIter;
9392
}
9493
else if (key == "data")
9594
{
9695
json[key] = std::regex_replace(json[key].get<std::string>(), std::regex(R"(\r\n)"), "\n");
96+
++jsonIter;
9797
}
9898
else if (key == "uri")
9999
{
@@ -103,7 +103,11 @@ namespace compatibility
103103
uri = std::regex_replace(uri, std::regex(R"(\.ts$)"), ".cpp");
104104

105105
json[key] = std::filesystem::canonical(uri).string();
106+
107+
++jsonIter;
106108
}
109+
else
110+
++jsonIter;
107111
}
108112
}
109113

0 commit comments

Comments
 (0)