<commit_before>#include <yuni/yuni.h>
#include <yuni/io/file.h>
#include <iostream>

using namespace Yuni;



int main(int argc, char** argv)
{
	if (argc != 4)
	{
		std::cerr << "usage: <func> <nany-file> <c-file>\n";
		return 1;
	}

	AnyString funcname{argv[1]};

	Clob nanyfile;
	if (IO::errNone != IO::File::LoadFromFile(nanyfile, argv[2]))
	{
		std::cerr << "failed to load header file from '" << argv[1] << "'\n";
		return 1;
	}

	nanyfile.trim();
	Clob out;
	out.reserve(nanyfile.size() * 2);

	out << "/* !! file generated by cmake */\n";
	out << "#include <stddef.h>\n\n\n";

	out << "const char* " << funcname << "(size_t* size)\n";
	out << "{\n";
	out << "\t*size = " << nanyfile.size() << ";\n";
	out << "\treturn\n";

	String str;
	nanyfile.words("\r\n", [&](const AnyString& line) -> bool {
		str = line;
		str.replace("\"", "\\\"");
		out << "\t\t\"" << str << "\\n\" \\\n";
		return true;
	});
	out << "\t\t;\n";

	out << "}\n";

	if (not IO::File::SetContent(argv[3], out))
	{
		std::cerr << "failed to write '" << argv[3] << "'\n";
		return 1;
	}

	return 0;
}
<commit_msg>tool: file to cstring: escape '\'<commit_after>#include <yuni/yuni.h>
#include <yuni/io/file.h>
#include <iostream>

using namespace Yuni;



int main(int argc, char** argv)
{
	if (argc != 4)
	{
		std::cerr << "usage: <func> <nany-file> <c-file>\n";
		return 1;
	}

	AnyString funcname{argv[1]};

	Clob nanyfile;
	if (IO::errNone != IO::File::LoadFromFile(nanyfile, argv[2]))
	{
		std::cerr << "failed to load header file from '" << argv[1] << "'\n";
		return 1;
	}

	nanyfile.trim();
	Clob out;
	out.reserve(nanyfile.size() * 2);

	out << "/* !! file generated by cmake */\n";
	out << "#include <stddef.h>\n\n\n";

	out << "const char* " << funcname << "(size_t* size)\n";
	out << "{\n";
	out << "\t*size = " << nanyfile.size() << ";\n";
	out << "\treturn\n";

	String str;
	nanyfile.words("\r\n", [&](const AnyString& line) -> bool {
		str = line;
		str.replace("\\", "\\\\");
		str.replace("\"", "\\\"");
		out << "\t\t\"" << str << "\\n\" \\\n";
		return true;
	});
	out << "\t\t;\n";

	out << "}\n";

	if (not IO::File::SetContent(argv[3], out))
	{
		std::cerr << "failed to write '" << argv[3] << "'\n";
		return 1;
	}

	return 0;
}

{'fraction_non_alphanumeric': 0.26558995065051594, 'fraction_numerical': 0.00986989681471512, 'mean_word_length': 3.16044776119403, 'pattern_counts': {'":': 0, '<': 105, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6428950', 'n_tokens_mistral': 1009, 'n_tokens_neox': 950, 'n_words': 218}