From ae6ec3b1b8a998e2852b48276c0ce119bc154dc8 Mon Sep 17 00:00:00 2001 From: Marcus Huderle Date: Sat, 22 Oct 2022 15:09:37 -0500 Subject: [PATCH] Change cleanString() to convert invalid chars to underscores --- tools/jsonproc/jsonproc.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/jsonproc/jsonproc.cpp b/tools/jsonproc/jsonproc.cpp index 099ac81af..d58e23eb9 100755 --- a/tools/jsonproc/jsonproc.cpp +++ b/tools/jsonproc/jsonproc.cpp @@ -105,11 +105,13 @@ int main(int argc, char *argv[]) }); env.add_callback("cleanString", 1, [](Arguments& args) { - string badChars = ".'{} \n\t-_\u00e9"; + string badChars = ".'{} \n\t-\u00e9"; string str = args.at(0)->get(); - str.erase(remove_if(str.begin(), str.end(), [&badChars](const char &c) { - return badChars.find(c) != std::string::npos; - }), str.end()); + for (uint i = 0; i < str.length(); i++) { + if (badChars.find(str[i]) != std::string::npos) { + str[i] = '_'; + } + } return str; });