<commit_before>#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "config.h"
#include "error.h"
#include "util.h"

void util_trim(char *str)
{

    char *p = str, *q = str;

    while (isspace(*q))
        ++q;

    while (*q)
        *p++ = *q++;

    *p = '\0';

    while (p > str && isspace(*--p))
        *p = '\0';

}

void util_strip(char *str)
{

    char *dest = str;

    while (*str)
    {

        while (isspace(*str) && isspace(*(str + 1)))
            str++;

       *dest++ = *str++;

    }

    *dest = '\0';

}

unsigned int util_split(char *str)
{

    unsigned int total = 1;

    while (*str)
    {

        if (isspace(*str))
        {

            *str = '\0';
            total++;

        }

        str++;

    }

    return total;

}

char *util_nextword(char *buffer, unsigned int index, unsigned int words)
{

    if (!index)
        return buffer;

    if (index >= words)
        return NULL;

    while (*buffer != '\0')
        buffer++;

    while (*buffer == '\0')
        buffer++;

    return buffer;

}

<commit_msg>more cleanups<commit_after>#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "config.h"
#include "error.h"
#include "util.h"

void util_trim(char *str)
{

    char *dest = str;

    while (isspace(*str))
        str++;

    while (*str)
        *dest++ = *str++;

    *dest = '\0';

    while (isspace(*--dest))
        *dest = '\0';

}

void util_strip(char *str)
{

    char *dest = str;

    while (*str)
    {

        while (isspace(*str) && isspace(*(str + 1)))
            str++;

       *dest++ = *str++;

    }

    *dest = '\0';

}

unsigned int util_split(char *str)
{

    unsigned int total = 1;

    while (*str)
    {

        if (isspace(*str))
        {

            *str = '\0';
            total++;

        }

        str++;

    }

    return total;

}

char *util_nextword(char *buffer, unsigned int index, unsigned int words)
{

    if (!index)
        return buffer;

    if (index >= words)
        return NULL;

    while (*buffer != '\0')
        buffer++;

    while (*buffer == '\0')
        buffer++;

    return buffer;

}


{'fraction_non_alphanumeric': 0.17817164179104478, 'fraction_numerical': 0.007462686567164179, 'mean_word_length': 1.732484076433121, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, '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': '2412124', 'n_tokens_mistral': 797, 'n_tokens_neox': 739, 'n_words': 193}