diff --git a/source/shared-code/utils/string.cpp b/source/shared-code/utils/string.cpp index 9f5531f..46e3fcb 100644 --- a/source/shared-code/utils/string.cpp +++ b/source/shared-code/utils/string.cpp @@ -193,4 +193,24 @@ namespace utils::string return str; } + + double 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)); + if (offset == std::string::npos) return 0.00; // mismatch + + int len_variance = text.length() - input.length(); + int match_percent = 100 - (1 + len_variance + offset); + + return ((double)match_percent / 100); + } + + bool compare(const std::string& s1, const std::string& s2, bool sensetive) + { + if (sensetive && (s1 == s2)) return true; + if (!sensetive && (to_lower(s1) == to_lower(s2))) return true; + return false; + } } diff --git a/source/shared-code/utils/string.hpp b/source/shared-code/utils/string.hpp index 2f7bde1..0da871a 100644 --- a/source/shared-code/utils/string.hpp +++ b/source/shared-code/utils/string.hpp @@ -98,4 +98,7 @@ namespace utils::string std::wstring convert(const std::string& str); std::string replace(std::string str, const std::string& from, const std::string& to); + + double match(const std::string& input, const std::string& text); + bool compare(const std::string& s1, const std::string& s2, bool sensetive = false); }