<commit_before>//SPDX-License-Identifier: LGPL-2.0-or-later
/*

  Copyright (C) 2020 <NAME> <<EMAIL>>

*/

#ifndef GP_VEC_STR_H__
#define GP_VEC_STR_H__

#include <string.h>
#include <utils/gp_vec.h>

/*
 * @return Returns newly allocated empty string vector or a NULL in a case of a
 *         failure.
 */
static inline char *gp_vec_str_new(void)
{
	return gp_vec_new(1, 1);
}

/*
 * @self A string vector.
 *
 * @return Returns string vector length.
 */
static inline size_t gp_vec_strlen(char *self)
{
	return gp_vec_len(self) - 1;
}

/*
 * @self A string vector.
 *
 * @return Returns string vector size i.e. length + 1.
 */
static inline size_t gp_vec_strsize(char *self)
{
	return gp_vec_len(self);
}

/*
 * @brief Copies a string into newly allocated string vector.
 *
 * @src A strint to duplicate.
 *
 * @return A string vector or a NULL in a case of allocation failure.
 */
static inline char *gp_vec_strdup(const char *src)
{
	char *ret = gp_vec_new(strlen(src)+1, 1);

	if (!ret)
		return NULL;

	strcpy(ret, src);

	return ret;
}

/*
 * @brief Inserts a string into a string vector at a given offset.
 *
 * @self A string vector.
 * @off  An offset in the string vector.
 * @src  A string to copy.
 *
 * @return A string vector or a NULL in a case of allocation failure.
 */
static inline char *gp_vec_strins(char *self, size_t off, const char *src)
	__attribute__((warn_unused_result));
static inline char *gp_vec_strins(char *self, size_t off, const char *src)
{
	char *ret = gp_vec_insert(self, off, strlen(src));

	if (!ret)
		return NULL;

	memcpy(ret+off, src, strlen(src));

	return ret;
}

/*
 * @brief Inserts a string into a string vector at a given offset.
 *
 * @self A string vector.
 * @off  An offset in the string vector.
 * @src  A string to copy.
 *
 * @return A string vector or a NULL in a case of allocation failure.
 */
static inline char *gp_vec_chins(char *self, size_t off, char ch)
	__attribute__((warn_unused_result));
static inline char *gp_vec_chins(char *self, size_t off, char ch)
{<commit_msg>utils: vec_str: Add append variant.<commit_after>//SPDX-License-Identifier: LGPL-2.0-or-later
/*

  Copyright (C) 2020 <NAME> <<EMAIL>>

*/

#ifndef GP_VEC_STR_H__
#define GP_VEC_STR_H__

#include <string.h>
#include <utils/gp_vec.h>

/*
 * @return Returns newly allocated empty string vector or a NULL in a case of a
 *         failure.
 */
static inline char *gp_vec_str_new(void)
{
	return gp_vec_new(1, 1);
}

/*
 * @self A string vector.
 *
 * @return Returns string vector length.
 */
static inline size_t gp_vec_strlen(char *self)
{
	return gp_vec_len(self) - 1;
}

/*
 * @self A string vector.
 *
 * @return Returns string vector size i.e. length + 1.
 */
static inline size_t gp_vec_strsize(char *self)
{
	return gp_vec_len(self);
}

/*
 * @brief Copies a string into newly allocated string vector.
 *
 * @src A strint to duplicate.
 *
 * @return A string vector or a NULL in a case of allocation failure.
 */
static inline char *gp_vec_strdup(const char *src)
{
	char *ret = gp_vec_new(strlen(src)+1, 1);

	if (!ret)
		return NULL;

	strcpy(ret, src);

	return ret;
}

/*
 * @brief Inserts a string into a string vector at a given offset.
 *
 * @self A string vector.
 * @off  An offset in the string vector.
 * @src  A string to copy.
 *
 * @return A string vector or a NULL in a case of allocation failure.
 */
static inline char *gp_vec_strins(char *self, size_t off, const char *src)
	__attribute__((warn_unused_result));
static inline char *gp_vec_strins(char *self, size_t off, const char *src)
{
	char *ret = gp_vec_insert(self, off, strlen(src));

	if (!ret)
		return NULL;

	memcpy(ret+off, src, strlen(src));

	return ret;
}

/*
 * @brief Appends a string to a string vector.
 *
 * @self A string vector.
 * @str A string to append.
 *
 * @return A string vector or a NULL in case of an allocation failure.
 */
static inline char *gp_vec_str_append(char *self, const char *str)
	__attribute__((warn_unused_result));
static inline char *gp_vec_str_append(char *self, const char *str)
{
	return gp_vec_strins(self, gp_vec_len(self)-1, str);
}

/*
 * @brief Inserts a string into a string vector at a given offset.
 *
 * @self A string vector.
 * @off  An offset in the string vector.
 * @src  A string to copy.
 *
 * @return A string vector or a NULL in a case of allocation failure.
 */
static inline char *gp_vec_chins(char *self, size_t off, char ch)
	__attribute__((warn_unused_result));
static inline char *gp_vec_chins(char *self, size_t off, char ch)
{
{'fraction_non_alphanumeric': 0.11514614703277236, 'fraction_numerical': 0.005535872453498672, 'mean_word_length': 3.7248953974895396, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '6170185', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1585, 'n_words': 565}