Skip to content

Commit d75b763

Browse files
committed
make URI cross-OS compatible
1 parent 5893f62 commit d75b763

File tree

1 file changed

+9
-44
lines changed

1 file changed

+9
-44
lines changed

compatibility/compatibility.cpp

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespace compatibility
5858
};
5959
}
6060

61-
void SanitizeExpectedJson(nlohmann::json& json)
61+
void RemoveIncompatibilities(nlohmann::json& json)
6262
{
6363
for (auto jsonIter = json.begin(); jsonIter != json.end();)
6464
{
@@ -75,7 +75,7 @@ namespace compatibility
7575
jsonIter = json.erase(jsonIter);
7676
else if (value.is_object())
7777
{
78-
SanitizeExpectedJson(value);
78+
RemoveIncompatibilities(value);
7979
++jsonIter;
8080
}
8181
else if (value.is_array())
@@ -86,7 +86,7 @@ namespace compatibility
8686
auto& item = *valueIter;
8787

8888
if (item.is_object())
89-
SanitizeExpectedJson(item);
89+
RemoveIncompatibilities(item);
9090

9191
++valueIter;
9292
}
@@ -95,47 +95,12 @@ namespace compatibility
9595
}
9696
else if (key == "uri")
9797
{
98-
json[key] = std::regex_replace(value.get<std::string>(), std::regex(R"(samples\/[^\/]+)"), KIT_FOLDER);
99-
json[key] = std::regex_replace(value.get<std::string>(), std::regex(R"(\.ts$)"), ".cpp");
100-
++jsonIter;
101-
}
102-
else
103-
++jsonIter;
104-
}
105-
}
106-
107-
void SanitizeActualJson(nlohmann::json& json)
108-
{
109-
for (auto jsonIter = json.begin(); jsonIter != json.end();)
110-
{
111-
auto& key = jsonIter.key();
112-
auto& value = jsonIter.value();
113-
114-
if (key == "exception")
115-
jsonIter = json.erase(jsonIter);
116-
else if (key == "message")
117-
jsonIter = json.erase(jsonIter);
118-
else if (key == "line")
119-
jsonIter = json.erase(jsonIter);
120-
else if (key == "snippets")
121-
jsonIter = json.erase(jsonIter);
122-
else if (value.is_object())
123-
{
124-
SanitizeActualJson(value);
125-
++jsonIter;
126-
}
127-
else if (value.is_array())
128-
{
129-
auto idx = 0;
130-
for (auto valueIter = value.begin(); valueIter != value.end();)
131-
{
132-
auto& item = *valueIter;
98+
auto uri = value.get<std::string>();
13399

134-
if (item.is_object())
135-
SanitizeActualJson(item);
100+
uri = std::regex_replace(uri, std::regex(R"(samples\/[^\/]+)"), KIT_FOLDER);
101+
uri = std::regex_replace(uri, std::regex(R"(\.ts$)"), ".cpp");
136102

137-
++valueIter;
138-
}
103+
json[key] = std::filesystem::path{ uri }.string();
139104

140105
++jsonIter;
141106
}
@@ -186,13 +151,13 @@ namespace compatibility
186151

187152
for (auto& json : actualEnvelopes)
188153
{
189-
SanitizeActualJson(json);
154+
RemoveIncompatibilities(json);
190155
actualOfs << json.dump() << "\n";
191156
}
192157

193158
for (auto& json : expectedEnvelopes)
194159
{
195-
SanitizeExpectedJson(json);
160+
RemoveIncompatibilities(json);
196161
expectedOfs << json.dump() << "\n";
197162
}
198163

0 commit comments

Comments
 (0)