<commit_before>/**
 * @file
 *
 * @brief Array methods.
 *
 * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
 */

#define __STDC_FORMAT_MACROS

#include <kdb.h>
#include <kdbease.h>
#include <kdbhelper.h>
#include <kdbtypes.h>

#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/**
 * @internal
 * @brief validate array syntax
 *
 * @param key an element of an array
 *
 * @retval -1 if no array element/syntax error/no key
 * @retval 0 if start
 * @retval 1 if array element
 */
int elektraArrayValidateName (const Key * key)
{
	if (!key)
	{
		return -1;
	}

	const char * current = keyBaseName (key);

	if (!current)
	{
		return -1;
	}

	if (!strcmp (current, "#"))
	{
		return 0;
	}

	if (*current == '#')
	{
		current++;
		int underscores = 0;
		int digits = 0;

		for (; *current == '_'; current++)
		{
			underscores++;
		}

		for (; isdigit (*current); current++)
		{
			digits++;
		}

		if (underscores != digits - 1) return -1;
		if (underscores + digits > ELEKTRA_MAX_ARRAY_SIZE - 2)
		{
			return -1;
		}
	}
	else
	{
		return -1;
	}

	return 1;
}
<commit_msg>quality-improvements: fix char subscript #939<commit_after>/**
 * @file
 *
 * @brief Array methods.
 *
 * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
 */

#define __STDC_FORMAT_MACROS

#include <kdb.h>
#include <kdbease.h>
#include <kdbhelper.h>
#include <kdbtypes.h>

#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/**
 * @internal
 * @brief validate array syntax
 *
 * @param key an element of an array
 *
 * @retval -1 if no array element/syntax error/no key
 * @retval 0 if start
 * @retval 1 if array element
 */
int elektraArrayValidateName (const Key * key)
{
	if (!key)
	{
		return -1;
	}

	const char * current = keyBaseName (key);

	if (!current)
	{
		return -1;
	}

	if (!strcmp (current, "#"))
	{
		return 0;
	}

	if (*current == '#')
	{
		current++;
		int underscores = 0;
		int digits = 0;

		for (; *current == '_'; current++)
		{
			underscores++;
		}

		for (; isdigit ((unsigned char) *current); current++)
		{
			digits++;
		}

		if (underscores != digits - 1) return -1;
		if (underscores + digits > ELEKTRA_MAX_ARRAY_SIZE - 2)
		{
			return -1;
		}
	}
	else
	{
		return -1;
	}

	return 1;
}

{'fraction_non_alphanumeric': 0.16413502109704642, 'fraction_numerical': 0.013080168776371307, 'mean_word_length': 3.0323129251700682, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '881846', 'n_tokens_mistral': 1027, 'n_tokens_neox': 915, 'n_words': 250}