Sync tools directory
This commit is contained in:
Regular → Executable
+14
-11
@@ -1,4 +1,6 @@
|
||||
// jsonproc.cpp
|
||||
// jsonproc converts JSON data to an output file based on an Inja template.
|
||||
// https://github.com/pantor/inja
|
||||
|
||||
#include "jsonproc.h"
|
||||
|
||||
@@ -7,6 +9,9 @@
|
||||
#include <string>
|
||||
using std::string; using std::to_string;
|
||||
|
||||
#include <algorithm>
|
||||
using std::replace_if;
|
||||
|
||||
#include <inja.hpp>
|
||||
using namespace inja;
|
||||
using json = nlohmann::json;
|
||||
@@ -40,13 +45,6 @@ int main(int argc, char *argv[])
|
||||
return "//\n// DO NOT MODIFY THIS FILE! It is auto-generated from " + jsonfilepath +" and Inja template " + templateFilepath + "\n//\n";
|
||||
});
|
||||
|
||||
env.add_callback("contains", 2, [](Arguments& args) {
|
||||
string word = args.at(0)->get<string>();
|
||||
string check = args.at(1)->get<string>();
|
||||
|
||||
return word.find(check) != std::string::npos;
|
||||
});
|
||||
|
||||
env.add_callback("subtract", 2, [](Arguments& args) {
|
||||
int minuend = args.at(0)->get<int>();
|
||||
int subtrahend = args.at(1)->get<int>();
|
||||
@@ -109,11 +107,16 @@ int main(int argc, char *argv[])
|
||||
});
|
||||
|
||||
env.add_callback("cleanString", 1, [](Arguments& args) {
|
||||
string badChars = ".'{} \n\t-_\u00e9";
|
||||
string str = args.at(0)->get<string>();
|
||||
str.erase(remove_if(str.begin(), str.end(), [&badChars](const char &c) {
|
||||
return badChars.find(c) != std::string::npos;
|
||||
}), str.end());
|
||||
for (unsigned int i = 0; i < str.length(); i++) {
|
||||
// This code is not Unicode aware, so UTF-8 is not easily parsable without introducing
|
||||
// another library. Just filter out any non-alphanumeric characters for now.
|
||||
// TODO: proper Unicode string normalization
|
||||
if ((i == 0 && isdigit(str[i]))
|
||||
|| !isalnum(str[i])) {
|
||||
str[i] = '_';
|
||||
}
|
||||
}
|
||||
return str;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user