<commit_before>#include "json.h"
#include <stdexcept>

namespace SleepyDiscord { namespace json {
	std::vector<std::string> getValues(const char* source, std::initializer_list<const char *const> const &names) {
		if (*source == 0) return std::vector<std::string>{};
		const unsigned int numOfValues = names.size();
		std::vector<JSON_findMuitipleStruct>values(numOfValues);
		unsigned int ii = -1;
		for (const char *const name : names)
			values[++ii] = { name, 0, strlen(name), 0 };
		JSON_find(numOfValues, source, &values[0]);
		std::vector<std::string> targets(numOfValues);
		for (unsigned int i = 0; i < numOfValues; i++) {
			if (0 < values[i].namePosition) {
				targets[i].assign(source + values[i].namePosition, values[i].valueLength);
			}
		}
		return targets;
	}

	std::string getValue(const char* source, const char * name) {
		JSON_findMuitipleStruct value = { name, 0, strlen(name), 0 };
		JSON_find(1, source, &value);
		return std::string(source + value.namePosition, value.valueLength);
	}

	std::vector<std::string> getArray(const std::string* _source) {
		const char* source = _source->c_str();
		if (source[0] != '[' && source[1] == ']') return std::vector<std::string>();

		//get size of array and change size of target array
		const unsigned int sourceLength = _source->size();
		unsigned int arraySize = 0;
		unsigned int position = 1;
		for (; position < sourceLength; position++) {
			switch (source[position]) {
			case '"': JSON_skipString(source, &position); break;
			case '{': JSON_skipObject(source, &position); break;
			case '[': JSON_skipObject(source, &position); break;
			case ',': ++arraySize; break;
			default: break;
			}
		}
		for (bool loop = true; loop;) {	//count last variable
			switch (source[--position]) {
			case '[': return std::vector<std::string>(); break;	//empty array
			case ' ': break;
			case ']': break;
			default:
				loop = false;
				++arraySize;<commit_msg>fixed crash from invalid arraies<commit_after>#include "json.h"
#include <stdexcept>

namespace SleepyDiscord { namespace json {
	std::vector<std::string> getValues(const char* source, std::initializer_list<const char *const> const &names) {
		if (*source == 0) return std::vector<std::string>{};
		const unsigned int numOfValues = names.size();
		std::vector<JSON_findMuitipleStruct>values(numOfValues);
		unsigned int ii = -1;
		for (const char *const name : names)
			values[++ii] = { name, 0, strlen(name), 0 };
		JSON_find(numOfValues, source, &values[0]);
		std::vector<std::string> targets(numOfValues);
		for (unsigned int i = 0; i < numOfValues; i++) {
			if (0 < values[i].namePosition) {
				targets[i].assign(source + values[i].namePosition, values[i].valueLength);
			}
		}
		return targets;
	}

	std::string getValue(const char* source, const char * name) {
		JSON_findMuitipleStruct value = { name, 0, strlen(name), 0 };
		JSON_find(1, source, &value);
		return std::string(source + value.namePosition, value.valueLength);
	}

	std::vector<std::string> getArray(const std::string* _source) {
		const char* source = _source->c_str();
		if (source[0] != '[' || source[1] == ']') return std::vector<std::string>();

		//get size of array and change size of target array
		const unsigned int sourceLength = _source->size();
		unsigned int arraySize = 0;
		unsigned int position = 1;
		for (; position < sourceLength; position++) {
			switch (source[position]) {
			case '"': JSON_skipString(source, &position); break;
			case '{': JSON_skipObject(source, &position); break;
			case '[': JSON_skipObject(source, &position); break;
			case ',': ++arraySize; break;
			default: break;
			}
		}
		for (bool loop = true; loop;) {	//count last variable
			switch (source[--position]) {
			case '[': return std::vector<std::string>(); break;	//empty array
			case ' ': break;
			case ']': break;
			default:
				loop = false;
				++arraySize;
{'fraction_non_alphanumeric': 0.16421378776142526, 'fraction_numerical': 0.007229537825974697, 'mean_word_length': 4.510668563300142, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 25, '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': '5502447', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1255, 'n_words': 337}