<commit_before>/* This file is part of Metallic, a runtime library for WebAssembly.
 *
 * Copyright (C) 2018 <NAME> <<EMAIL>>
 *
 * This Source Code Form is subject to the terms of the Mozilla
 * Public License v. 2.0. If a copy of the MPL was not distributed
 * with this file, You can obtain one at http://mozilla.org/MPL/2.0/
 */
#include <ctype.h>
#include <limits.h>
#include <stdint.h>
#include <errno.h>

static int _atoi(int c)
{
    if (c - '0' < 10u)
        return c - '0';

    c |= 32;

    if (c - 'a' < 26u)
        return c - 'a' + 10;

    return INT_MAX;
}

struct Conversion
{
    Unsigned value;
    const Character* tail;
    _Bool overflow;
};

static struct Conversion _convert(const Character s[static 1], int base)
{
    Unsigned threshold = (Unsigned)-1 / base;
    Unsigned value = 0;
    _Bool overflow = 0;

    for (int digit = _atoi(*s); digit < base; digit = _atoi(*++s)) {
        Unsigned result = value * base + digit;
        overflow |= threshold < value || result < digit;
        value = result;
    }

    return (struct Conversion){ value, s, overflow };
}

Integer CONVERT(const Character s[restrict static 1], Character** restrict end, int base)
{
    const Integer maximum = _Generic((Integer)0,
        long: LONG_MAX,
        long long: LLONG_MAX,
        default: _Generic((Integer)0, intmax_t: INTMAX_MAX, default: -1)
    );

    const Integer minimum = _Generic((Integer)0,
        long: LONG_MIN,
        long long: LLONG_MIN,
        default: _Generic((Integer)0, intmax_t: INTMAX_MIN, default: 0)
    );

    const Character* begin = s;
    Integer extreme = maximum;
    Unsigned threshold = extreme;
    _Bool negative = 0;

    while (isspace(*s))
        ++s;

    switch (*s) {<commit_msg>Rename _atoi to _digit, which is a better name<commit_after>/* This file is part of Metallic, a runtime library for WebAssembly.
 *
 * Copyright (C) 2018 <NAME> <<EMAIL>>
 *
 * This Source Code Form is subject to the terms of the Mozilla
 * Public License v. 2.0. If a copy of the MPL was not distributed
 * with this file, You can obtain one at http://mozilla.org/MPL/2.0/
 */
#include <ctype.h>
#include <limits.h>
#include <stdint.h>
#include <errno.h>

static int _digit(int c)
{
    if (c - '0' < 10u)
        return c - '0';

    c |= 32;

    if (c - 'a' < 26u)
        return c - 'a' + 10;

    return INT_MAX;
}

struct Conversion
{
    Unsigned value;
    const Character* tail;
    _Bool overflow;
};

static struct Conversion _convert(const Character s[static 1], int base)
{
    Unsigned threshold = (Unsigned)-1 / base;
    Unsigned value = 0;
    _Bool overflow = 0;

    for (int digit = _digit(*s); digit < base; digit = _digit(*++s)) {
        Unsigned result = value * base + digit;
        overflow |= threshold < value || result < digit;
        value = result;
    }

    return (struct Conversion){ value, s, overflow };
}

Integer CONVERT(const Character s[restrict static 1], Character** restrict end, int base)
{
    const Integer maximum = _Generic((Integer)0,
        long: LONG_MAX,
        long long: LLONG_MAX,
        default: _Generic((Integer)0, intmax_t: INTMAX_MAX, default: -1)
    );

    const Integer minimum = _Generic((Integer)0,
        long: LONG_MIN,
        long long: LLONG_MIN,
        default: _Generic((Integer)0, intmax_t: INTMAX_MIN, default: 0)
    );

    const Character* begin = s;
    Integer extreme = maximum;
    Unsigned threshold = extreme;
    _Bool negative = 0;

    while (isspace(*s))
        ++s;

    switch (*s) {
{'fraction_non_alphanumeric': 0.12039660056657224, 'fraction_numerical': 0.0169971671388102, 'mean_word_length': 2.681960375391032, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 17, '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': '7352818', 'n_tokens_mistral': 1203, 'n_tokens_neox': 1128, 'n_words': 398}