<commit_before>/*!
 * MPT core library
 *   convert type to string pointer/slice
 */

#include <ctype.h>
#include <string.h>
#include <errno.h>

#include <sys/uio.h>

#include "array.h"
#include "types.h"

#include "convert.h"

/*!
 * \ingroup mptConvert
 * \brief get string data
 * 
 * Convert typed data pointer to string
 * or slice of characters
 * 
 * \param[in,out] from pointer to current string position
 * \param         type convertion target type
 * \param[out]    len  string length
 * 
 * \return length of converted type
 */
extern const char *mpt_data_tostring(const void **from, int type, size_t *len)
{
	static const char def[] = "\0";
	const char *base;
	
	/* simple string pointer */
	if (type == 's') {
		const char * const *txt = *from;
		if (!txt || !(base = *txt)) {
			base = def;
		}
		if (len) {
			*len = strlen(base);
		}
		if (txt) {
			*from = txt + 1;
		}
		return base;
	}
	/* text buffer (pointer or tracked reference) */
	if (type == MPT_ENUM(TypeArray)
	 || type == MPT_ENUM(TypeBufferPtr)) {
		static const MPT_STRUCT(type_traits) *traits= 0;
		const MPT_STRUCT(array) *arr;
		const MPT_STRUCT(buffer) *b;
		
		if (!(arr = *from)) {
			errno = EINVAL;
			return 0;
		}
		if (!(b = arr->_buf)) {
			errno = ENOTSUP;
			return 0;
		}
		/* initialize traits binding */
		if (!traits || (!(traits = mpt_type_traits('c')))) {
			errno = ENOTSUP;
			return 0;
		}
		if (b->_content_traits != traits) {
			errno = EINVAL;
			return 0;
		}
		base = (const char *) (b + 1);
		if (len) {
			*len = b->_used;
		}
		else if (!b->_used) {
			base = def;
		}<commit_msg>fix: character traits init in tostring conversion<commit_after>/*!
 * MPT core library
 *   convert type to string pointer/slice
 */

#include <ctype.h>
#include <string.h>
#include <errno.h>

#include <sys/uio.h>

#include "array.h"
#include "types.h"

#include "convert.h"

/*!
 * \ingroup mptConvert
 * \brief get string data
 * 
 * Convert typed data pointer to string
 * or slice of characters
 * 
 * \param[in,out] from pointer to current string position
 * \param         type convertion target type
 * \param[out]    len  string length
 * 
 * \return length of converted type
 */
extern const char *mpt_data_tostring(const void **from, int type, size_t *len)
{
	static const char def[] = "\0";
	const char *base;
	
	/* simple string pointer */
	if (type == 's') {
		const char * const *txt = *from;
		if (!txt || !(base = *txt)) {
			base = def;
		}
		if (len) {
			*len = strlen(base);
		}
		if (txt) {
			*from = txt + 1;
		}
		return base;
	}
	/* text buffer (pointer or tracked reference) */
	if (type == MPT_ENUM(TypeArray)
	 || type == MPT_ENUM(TypeBufferPtr)) {
		static const MPT_STRUCT(type_traits) *traits= 0;
		const MPT_STRUCT(array) *arr;
		const MPT_STRUCT(buffer) *b;
		
		if (!(arr = *from)) {
			errno = EINVAL;
			return 0;
		}
		if (!(b = arr->_buf)) {
			errno = ENOTSUP;
			return 0;
		}
		/* initialize traits binding */
		if (!traits && (!(traits = mpt_type_traits('c')))) {
			errno = ENOTSUP;
			return 0;
		}
		if (b->_content_traits != traits) {
			errno = EINVAL;
			return 0;
		}
		base = (const char *) (b + 1);
		if (len) {
			*len = b->_used;
		}
		else if (!b->_used) {
			base = def;
		}
{'fraction_non_alphanumeric': 0.15673494723774054, 'fraction_numerical': 0.004965859714463066, 'mean_word_length': 2.859880239520958, 'pattern_counts': {'":': 0, '<': 11, '<?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': '5914305', 'n_tokens_mistral': 1317, 'n_tokens_neox': 1177, 'n_words': 354}