Skip to content

Commit 4c3cdfb

Browse files
committed
Remove regex
1 parent ac09db7 commit 4c3cdfb

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/main/dumpers/schemas/metadata_stringifier.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include <fmt/format.h>
3131
#include "metadata_stringifier.h"
3232
#include <modules.h>
33-
#include <regex>
3433
#include "../../vendor/json.hpp"
3534

3635
using json = nlohmann::ordered_json;
@@ -158,7 +157,18 @@ namespace Dumpers::Schemas
158157
std::string out = buf.Get();
159158

160159
// Fix invalid JSON values produced by SaveKV3AsJson bug (e.g., -nan, nan)
161-
out = std::regex_replace(out, std::regex(R"(\s-?nan(\s|,))"), " 0.0$1");
160+
size_t pos = 0;
161+
while ((pos = out.find("nan", pos)) != std::string::npos) {
162+
bool validPrefix = (pos == 0 || out[pos - 1] == ' ' || out[pos - 1] == '\t' || out[pos - 1] == '\n' || out[pos - 1] == '-');
163+
bool validSuffix = (pos + 3 >= out.length() || out[pos + 3] == ' ' || out[pos + 3] == '\n' || out[pos + 3] == ',');
164+
165+
if (validPrefix && validSuffix) {
166+
out[pos] = '0';
167+
out[pos + 1] = '.';
168+
out[pos + 2] = '0';
169+
}
170+
++pos;
171+
}
162172

163173
try {
164174
auto jsonObj = json::parse(out);

0 commit comments

Comments
 (0)