<commit_before>// LICENSE
//
//   This software is dual-licensed to the public domain and under the following
//   license: you are granted a perpetual, irrevocable license to copy, modify,
//   publish, and distribute this file as you see fit.

// VERSION 0.1.0

#ifndef FTS_FUZZY_MATCH_H
#define FTS_FUZZY_MATCH_H

#include <ctype.h> // ::tolower, ::toupper

namespace fts {
    
    // Returns true if each character in pattern is found sequentially within str
    static bool fuzzy_match(char const * pattern, char const * str) 
    {
        while (*pattern != '\0' && *str != '\0')  {
            if (tolower(*pattern) == tolower(*str))
                ++pattern;
            ++str;
        }

        return *pattern == '\0' ? true : false;
    }

    // Returns true if each character in pattern is found sequentially within str
    // iff found then outScore is also set. Score value has no intrinsic meaning. Range varies with pattern. 
    // Can only compare scores with same search pattern.
    static bool fuzzy_match(char const * pattern, char const * str, int & outScore) 
    {
        // Score consts
        const int adjacency_bonus = 5;              // bonus for adjacent matches<commit_msg>Change name of scoring fuzzy match to differentiate from basic fuzzy match<commit_after>// LICENSE
//
//   This software is dual-licensed to the public domain and under the following
//   license: you are granted a perpetual, irrevocable license to copy, modify,
//   publish, and distribute this file as you see fit.

// VERSION 0.1.0

#ifndef FTS_FUZZY_MATCH_H
#define FTS_FUZZY_MATCH_H

#include <ctype.h> // ::tolower, ::toupper

namespace fts {
    
    // Returns true if each character in pattern is found sequentially within str
    static bool fuzzy_match(char const * pattern, char const * str) 
    {
        while (*pattern != '\0' && *str != '\0')  {
            if (tolower(*pattern) == tolower(*str))
                ++pattern;
            ++str;
        }

        return *pattern == '\0' ? true : false;
    }

    // Returns true if each character in pattern is found sequentially within str
    // iff found then outScore is also set. Score value has no intrinsic meaning. Range varies with pattern. 
    // Can only compare scores with same search pattern.
    static bool fuzzy_match_score(char const * pattern, char const * str, int & outScore) 
    {
        // Score consts
        const int adjacency_bonus = 5;              // bonus for adjacent matches
{'fraction_non_alphanumeric': 0.09152950622240064, 'fraction_numerical': 0.005620232838217583, 'mean_word_length': 2.4419889502762433, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1409284', 'n_tokens_mistral': 721, 'n_tokens_neox': 671, 'n_words': 286}