<commit_before>/*
 * Copyright (C) <NAME>
 * Copyright (C) Vino
 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <signal.h>
#include <ctype.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "util.h"
#include "vn_error.h"

#define MIME_ENTRY(_ext, _type) { _ext, sizeof(_ext) - 1, _type }

static vn_mime_entry vn_builtin_mime_type[] = {
    MIME_ENTRY("html", "text/html"),
    MIME_ENTRY("htm", "text/html"),
    MIME_ENTRY("css", "text/css"),
    MIME_ENTRY("js", "text/javascript"),
    MIME_ENTRY("gif", "image/gif"),
    MIME_ENTRY("jpg", "image/jpeg"),
    MIME_ENTRY("jpeg", "image/jpeg"),
    MIME_ENTRY("png", "image/png"),
    MIME_ENTRY("svg", "image/svg+xml"),
    MIME_ENTRY("txt", "text/plain"),
    MIME_ENTRY("xml", "text/xml"),
    MIME_ENTRY("ttf", "application/x-font-ttf"),
    MIME_ENTRY("json", "application/json"),
    MIME_ENTRY("xslt", "application/xml"),
    MIME_ENTRY("xsl", "application/xml"),
    MIME_ENTRY("doc", "application/msword"),
    MIME_ENTRY("xls", "application/excel"),
    MIME_ENTRY("zip", "application/x-zip-compressed"),
    MIME_ENTRY("tgz", "application/x-tar-gz"),
    MIME_ENTRY("tar", "application/x-tar"),
    MIME_ENTRY("gz", "application/x-gunzip"),
    MIME_ENTRY("rar", "application/x-rar-compressed"),
    MIME_ENTRY("pdf", "application/pdf"),
    { NULL, 0, NULL }
};

int vn_get_string(vn_str_t *str, char *buf, size_t buf_len) {
    const char *s;
    unsigned int i;

    memset(buf, '\0', buf_len);

    if(!str->len) { return 0; }

    if (str->len + 1 > buf_len) { return -1; }

    s = str->p;
    i = 0;
    while (i < str->len) {
        buf[i] = s[i];
        i++;
    }
    buf[i] = '\0';
    return 0;
}

int vn_str_cmp(const vn_str_t *str1, const char *str2) {
    int i;
    const char *p1 = str1->p, *p2 = str2;
    size_t n1 = str1->len, n2 = strlen(str2);
    size_t shorter_len = n1 < n2 ? n1 : n2;
    
    for (i = 0; i < shorter_len && p1[i] == p2[i]; i++) { ; }
    
    if (i == shorter_len) {
        if (n1 == n2) { return 0; }
        if (shorter_len < n1) {
            return 1;
        } else {
            return -1;
        }
    } else {
        return (p1[i] < p2[i] ? -1 : 1); 
    }
   
}

int vn_str_atoi(const vn_str_t *str) {
    char *buf;
    int rv;

    if ((buf = (char *) malloc(sizeof(char) * (str->len + 1))) == NULL) {
        err_sys("[vn_str_atoi] malloc error");<commit_msg>Refine code style (vn_str_cmp).<commit_after>/*
 * Copyright (C) <NAME>
 * Copyright (C) Vino
 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <signal.h>
#include <ctype.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "util.h"
#include "vn_error.h"

#define MIME_ENTRY(_ext, _type) { _ext, sizeof(_ext) - 1, _type }

static vn_mime_entry vn_builtin_mime_type[] = {
    MIME_ENTRY("html", "text/html"),
    MIME_ENTRY("htm", "text/html"),
    MIME_ENTRY("css", "text/css"),
    MIME_ENTRY("js", "text/javascript"),
    MIME_ENTRY("gif", "image/gif"),
    MIME_ENTRY("jpg", "image/jpeg"),
    MIME_ENTRY("jpeg", "image/jpeg"),
    MIME_ENTRY("png", "image/png"),
    MIME_ENTRY("svg", "image/svg+xml"),
    MIME_ENTRY("txt", "text/plain"),
    MIME_ENTRY("xml", "text/xml"),
    MIME_ENTRY("ttf", "application/x-font-ttf"),
    MIME_ENTRY("json", "application/json"),
    MIME_ENTRY("xslt", "application/xml"),
    MIME_ENTRY("xsl", "application/xml"),
    MIME_ENTRY("doc", "application/msword"),
    MIME_ENTRY("xls", "application/excel"),
    MIME_ENTRY("zip", "application/x-zip-compressed"),
    MIME_ENTRY("tgz", "application/x-tar-gz"),
    MIME_ENTRY("tar", "application/x-tar"),
    MIME_ENTRY("gz", "application/x-gunzip"),
    MIME_ENTRY("rar", "application/x-rar-compressed"),
    MIME_ENTRY("pdf", "application/pdf"),
    { NULL, 0, NULL }
};

int vn_get_string(vn_str_t *str, char *buf, size_t buf_len) {
    const char *s;
    unsigned int i;

    memset(buf, '\0', buf_len);

    if(!str->len) { return 0; }

    if (str->len + 1 > buf_len) { return -1; }

    s = str->p;
    i = 0;
    while (i < str->len) {
        buf[i] = s[i];
        i++;
    }
    buf[i] = '\0';
    return 0;
}

int vn_str_cmp(const vn_str_t *str1, const char *str2) {
    int i;
    const char *p1 = str1->p, *p2 = str2;
    size_t n1 = str1->len, n2 = strlen(str2);
    size_t shorter_len = n1 < n2 ? n1 : n2;
    
    for (i = 0; i < shorter_len && p1[i] == p2[i]; i++) { ; }
    
    if (i == shorter_len) {
        if (n1 == n2) { return 0; }
        return (shorter_len < n1 ? 1 : -1);
    } else {
        return (p1[i] < p2[i] ? -1 : 1); 
    }
   
}

int vn_str_atoi(const vn_str_t *str) {
    char *buf;
    int rv;

    if ((buf = (char *) malloc(sizeof(char) * (str->len + 1))) == NULL) {
        err_sys("[vn_str_atoi] malloc error");
{'fraction_non_alphanumeric': 0.2, 'fraction_numerical': 0.015102040816326531, 'mean_word_length': 3.017213114754098, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '7263629', 'n_tokens_mistral': 2051, 'n_tokens_neox': 1985, 'n_words': 405}