This commit is contained in:
Ahrimdon
2024-12-31 07:33:23 -05:00
29 changed files with 1278 additions and 680 deletions

View File

@ -262,17 +262,17 @@ namespace utilities::string
return StringMatch::Mismatch;
}
double match(const std::string& input, const std::string& text)
float match(const std::string& input, const std::string& text)
{
if (text == input) return 1.00; // identical
size_t offset = to_lower(text).find(to_lower(input));
auto offset = to_lower(text).find(to_lower(input));
if (offset == std::string::npos) return 0.00; // mismatch
int len_variance = text.length() - input.length();
int match_percent = 100 - (1 + len_variance + offset);
auto len_variance = text.length() - input.length();
size_t match_percent = 100 - (1 + len_variance + offset);
return ((double)match_percent / 100);
return (static_cast<float>(match_percent) / 100);
}
bool contains(std::string text, std::string substr, bool sensetive)
@ -285,4 +285,4 @@ namespace utilities::string
if (text.find(substr) != std::string::npos) return true;
return false;
}
}
}

View File

@ -122,6 +122,6 @@ namespace utilities::string
};
StringMatch compare(const std::string& s1, const std::string& s2);
double match(const std::string& input, const std::string& text);
float match(const std::string& input, const std::string& text);
bool contains(std::string text, std::string substr, bool sensetive = false);
}
}