<commit_before>
//
// Copyright (C) 2008, Regents of the University of Colorado.
//


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

#include <glib.h>

#include "bionet-util.h"




int bionet_is_valid_name_component(const char *str) {
    if (str == NULL) {
        g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "bionet_is_valid_name_component(): NULL string passed in!");
        return 0;
    }

    // zero-length string is NOT valid
    if (*str == '\0') return 0;

    // too long?
    if (strlen(str) > BIONET_NAME_COMPONENT_MAX_LEN) return 0;

    while (*str != '\0') {
        if (!isalnum(*str) && (*str != '-')) return 0;
        str ++;
    }

    return 1;
}


int bionet_is_valid_name_component_or_wildcard(const char *str) {
    if (str == NULL) {
        g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "bionet_is_valid_name_component_or_wildcard(): NULL string passed in!");
        return 0;
    }

    // zero-length string is NOT valid
    if (*str == '\0') return 0;

    // too long?
    if (strlen(str) > BIONET_NAME_COMPONENT_MAX_LEN) return 0;

    if (strcmp(str, "*") == 0) {
        return 1;
    }

    while (*str != '\0') {
        if (!isalnum(*str) && (*str != '-')) return 0;
        str ++;
    }

    return 1;
}


int bionet_name_component_matches(const char *name_component, const char *pattern) {
    if (!bionet_is_valid_name_component(name_component)) {
        g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "bionet_name_component_matches(): invalid name-component passed in!");
        return 0;
    }

    if (!bionet_is_valid_name_component_or_wildcard(pattern)) {
        g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "bionet_name_component_matches(): invalid pattern passed in!");
        return 0;
    }

    if (strcmp(pattern, "*") == 0) return 1;
    if (strcmp(pattern, name_component) == 0) return 1;
<commit_msg>better warning messages on insane arguments<commit_after>
//
// Copyright (C) 2008, Regents of the University of Colorado.
//


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

#include <glib.h>

#include "bionet-util.h"




int bionet_is_valid_name_component(const char *str) {
    if (str == NULL) {
        g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "bionet_is_valid_name_component(): NULL string passed in!");
        return 0;
    }

    // zero-length string is NOT valid
    if (*str == '\0') return 0;

    // too long?
    if (strlen(str) > BIONET_NAME_COMPONENT_MAX_LEN) return 0;

    while (*str != '\0') {
        if (!isalnum(*str) && (*str != '-')) return 0;
        str ++;
    }

    return 1;
}


int bionet_is_valid_name_component_or_wildcard(const char *str) {
    if (str == NULL) {
        g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "bionet_is_valid_name_component_or_wildcard(): NULL string passed in!");
        return 0;
    }

    // zero-length string is NOT valid
    if (*str == '\0') return 0;

    // too long?
    if (strlen(str) > BIONET_NAME_COMPONENT_MAX_LEN) return 0;

    if (strcmp(str, "*") == 0) {
        return 1;
    }

    while (*str != '\0') {
        if (!isalnum(*str) && (*str != '-')) return 0;
        str ++;
    }

    return 1;
}


int bionet_name_component_matches(const char *name_component, const char *pattern) {
    if (!bionet_is_valid_name_component(name_component)) {
        g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "bionet_name_component_matches(): invalid name-component '%s' passed in!", name_component);
        return 0;
    }

    if (!bionet_is_valid_name_component_or_wildcard(pattern)) {
        g_log(BIONET_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "bionet_name_component_matches(): invalid name-component-pattern '%s' passed in!", pattern);
        return 0;
    }

    if (strcmp(pattern, "*") == 0) return 1;
    if (strcmp(pattern, name_component) == 0) return 1;

{'fraction_non_alphanumeric': 0.13890339425587467, 'fraction_numerical': 0.013577023498694517, 'mean_word_length': 3.101713062098501, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '220981', 'n_tokens_mistral': 1441, 'n_tokens_neox': 1361, 'n_words': 315}