<commit_before>/* Copyright(c) <NAME> <<EMAIL>>, 2011
**
** This document is covered by the an Open Source Initiative approved license. A
** copy of the license should have been provided alongside this software package
** (see "LICENSE.txt"). If not, terms of the license are available online at
** "http://www.opensource.org/licenses/mit". */

/*!
 * @file netstring.c
 * @author <NAME> <<EMAIL>>
 * @brief Parser for netstrings (http://cr.yp.to/proto/netstrings.txt).
 */

#include "netstring.h"

#include <ctype.h>

  /* Allow definition in build script. */
#ifndef NETSTRING_MAXIMUM_LENGTH
#   define NETSTRING_MAXIMUM_LENGTH (1*1024)
#endif

static const char * netstring_error_messages[] =
{
    "so far, so good",
    "string too long",
    "expected digit",
};

static size_t netstring_min ( size_t a, size_t b )
{
    return ((a < b)? a : b);
}

static int netstring_overflow
    ( const struct netstring_limits * limits, size_t parsed )
{
    return (limits->maximum_length != 0)
        && (parsed > limits->maximum_length);
}

const char * netstring_error_message ( enum netstring_parser_error error )
{
    return (netstring_error_messages[error]);
}

void netstring_setup
    ( struct netstring_limits * limits, struct netstring_parser * parser )
{
        /* Default limits. */
    limits->maximum_length = NETSTRING_MAXIMUM_LENGTH;
        /* Default parser state. */
    parser->state = netstring_parser_size;
    parser->error = netstring_error_ok;
    parser->parsed = 0;
    parser->length = 0;
    parser->accept = 0;
    parser->object = 0;
}

void netstring_clear ( struct netstring_parser * parser )
{
    parser->state = netstring_parser_size;
    parser->error = netstring_error_ok;
    parser->parsed = 0;<commit_msg>Stops ignoring custom paser limits.<commit_after>/* Copyright(c) <NAME> <<EMAIL>>, 2011
**
** This document is covered by the an Open Source Initiative approved license. A
** copy of the license should have been provided alongside this software package
** (see "LICENSE.txt"). If not, terms of the license are available online at
** "http://www.opensource.org/licenses/mit". */

/*!
 * @file netstring.c
 * @author <NAME> <<EMAIL>>
 * @brief Parser for netstrings (http://cr.yp.to/proto/netstrings.txt).
 */

#include "netstring.h"

#include <ctype.h>

  /* Allow definition in build script. */
#ifndef NETSTRING_MAXIMUM_LENGTH
#   define NETSTRING_MAXIMUM_LENGTH 0
#endif

static const char * netstring_error_messages[] =
{
    "so far, so good",
    "string too long",
    "expected digit",
};

static size_t netstring_min ( size_t a, size_t b )
{
    return ((a < b)? a : b);
}

static int netstring_overflow
    ( const struct netstring_limits * limits, size_t parsed )
{
    return (limits->maximum_length != 0)
        && (parsed > limits->maximum_length);
}

const char * netstring_error_message ( enum netstring_parser_error error )
{
    return (netstring_error_messages[error]);
}

void netstring_setup
    ( struct netstring_limits * limits, struct netstring_parser * parser )
{
        /* Default limits. */
    if (limits->maximum_length == 0) {
        limits->maximum_length = NETSTRING_MAXIMUM_LENGTH;
    }
        /* Default parser state. */
    parser->state = netstring_parser_size;
    parser->error = netstring_error_ok;
    parser->parsed = 0;
    parser->length = 0;
    parser->accept = 0;
    parser->object = 0;
}

void netstring_clear ( struct netstring_parser * parser )
{
    parser->state = netstring_parser_size;
    parser->error = netstring_error_ok;
    parser->parsed = 0;
{'fraction_non_alphanumeric': 0.12162162162162163, 'fraction_numerical': 0.007601351351351352, 'mean_word_length': 3.608300907911803, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6670329', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1103, 'n_words': 312}