more string utilities
This commit is contained in:
parent
2358dcf30b
commit
dcd5558821
@ -193,4 +193,24 @@ namespace utils::string
|
|||||||
|
|
||||||
return str;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,4 +98,7 @@ namespace utils::string
|
|||||||
std::wstring convert(const std::string& str);
|
std::wstring convert(const std::string& str);
|
||||||
|
|
||||||
std::string replace(std::string str, const std::string& from, const std::string& to);
|
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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user