<commit_before>#include "libguess.h"

mowgli_patricia_t *guess_impl_list = NULL;

void strcasecanon(char *str)
{
    while (*str)
    {
        *str = toupper(*str);
        str++;
    }
}

static void
guess_impl_register(const char *lang, guess_impl_f impl)
{
    return_if_fail(guess_impl_list != NULL);

    mowgli_patricia_add(guess_impl_list, lang, impl);
}

static void
guess_init(void)
{
    mowgli_init();

    /* check if already initialized */
    if (guess_impl_list != NULL)
        return;

    guess_impl_list = mowgli_patricia_create(strcasecanon);

    guess_impl_register(GUESS_REGION_JP, guess_jp);
    guess_impl_register(GUESS_REGION_TW, guess_tw);
    guess_impl_register(GUESS_REGION_CN, guess_cn);
    guess_impl_register(GUESS_REGION_KR, guess_kr);
    guess_impl_register(GUESS_REGION_RU, guess_ru);
    guess_impl_register(GUESS_REGION_AR, guess_ar);
    guess_impl_register(GUESS_REGION_TR, guess_tr);
    guess_impl_register(GUESS_REGION_GR, guess_gr);
    guess_impl_register(GUESS_REGION_HW, guess_hw);
    guess_impl_register(GUESS_REGION_PL, guess_pl);
    guess_impl_register(GUESS_REGION_BL, guess_bl);
}

const char *
libguess_determine_encoding(const char *inbuf, int buflen, const char *lang)
{
    guess_impl_f impl;

    guess_init();

    impl = mowgli_patricia_retrieve(guess_impl_list, lang);<commit_msg>Remove mowgli_init(). The last commit changed the required libmowgli to >=2.0, so this isn't required anymore.<commit_after>#include "libguess.h"

mowgli_patricia_t *guess_impl_list = NULL;

void strcasecanon(char *str)
{
    while (*str)
    {
        *str = toupper(*str);
        str++;
    }
}

static void
guess_impl_register(const char *lang, guess_impl_f impl)
{
    return_if_fail(guess_impl_list != NULL);

    mowgli_patricia_add(guess_impl_list, lang, impl);
}

static void
guess_init(void)
{
    /* check if already initialized */
    if (guess_impl_list != NULL)
        return;

    guess_impl_list = mowgli_patricia_create(strcasecanon);

    guess_impl_register(GUESS_REGION_JP, guess_jp);
    guess_impl_register(GUESS_REGION_TW, guess_tw);
    guess_impl_register(GUESS_REGION_CN, guess_cn);
    guess_impl_register(GUESS_REGION_KR, guess_kr);
    guess_impl_register(GUESS_REGION_RU, guess_ru);
    guess_impl_register(GUESS_REGION_AR, guess_ar);
    guess_impl_register(GUESS_REGION_TR, guess_tr);
    guess_impl_register(GUESS_REGION_GR, guess_gr);
    guess_impl_register(GUESS_REGION_HW, guess_hw);
    guess_impl_register(GUESS_REGION_PL, guess_pl);
    guess_impl_register(GUESS_REGION_BL, guess_bl);
}

const char *
libguess_determine_encoding(const char *inbuf, int buflen, const char *lang)
{
    guess_impl_f impl;

    guess_init();

    impl = mowgli_patricia_retrieve(guess_impl_list, lang);
{'fraction_non_alphanumeric': 0.09317443120260022, 'fraction_numerical': 0.0007222824124232575, 'mean_word_length': 5.008676789587852, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '2808457', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1075, 'n_words': 167}