6 #define MIN(x,y) ((x) < (y) ? (x) : (y))
10 std::transform(str.begin(), str.end(), str.begin(), tolower);
16 if (a == b)
return true;
17 if (!a || !b)
return false;
18 for (
size_t i = 0; i < max_len; ++i) {
20 if (tolower(a[i]) != tolower(b[i])) {
29 if (a[i] ==
'\0')
break;
36 size_t aLen = a.size();
37 if (b.size() != aLen)
return false;
39 for (
size_t i = 0; i < aLen; ++i) {
41 if (a[i] != b[i])
return false;
44 if (tolower(a[i]) != tolower(b[i]))
return false;
52 const size_t MAX_LEN = 100;
53 const size_t len1 = strlen(s1);
54 const size_t len2 = strlen(s2);
56 if (len1 >= MAX_LEN || len2 >= MAX_LEN)
return(-1);
59 int dist[MAX_LEN][MAX_LEN] = { 0 };
60 for (
int i = 0;i <= len1;i++) {
63 for (
int j = 0;j <= len2; j++) {
67 for (
int j = 1;j <= len1; j++) {
68 for (
int i = 1;i <= len2; i++) {
70 if (s1[i - 1] == s2[j - 1]) {
73 int t =
MIN((dist[i - 1][j] + 1), (dist[i][j - 1] + 1));
74 dist[i][j] =
MIN(t, (dist[i - 1][j - 1] + track));
77 return dist[len2][len1];
82 memset(hist1, 0, 255);
83 const size_t len1 = strlen(s1);
84 for (
size_t i = 0; i < len1; i++) {
85 const char c = tolower(s1[i]);
93 for (
size_t i = 0; i < 255; i++) {
94 if (hist1[i] != 0) count++;
101 const size_t MAX_LEN = 255;
102 size_t hist1[MAX_LEN] = { 0 };
103 size_t hist2[MAX_LEN] = { 0 };
109 for (
size_t i = 0; i < MAX_LEN; i++) {
110 if (hist1[i] != 0 && hist2[i] != 0 ) sim++;
114 if (sim == uniq1 && sim == uniq2) {
123 if (param.empty() || filter.empty()) {
128 const bool sim_found = (param.find(filter) != std::string::npos) || (filter.find(param) != std::string::npos);
135 if (param.empty() || filter.empty()) {
138 bool sim_found =
false;
143 if (dist == 1 || dist <= (param.length() / 2)) {
146 if (dist >= param.length() || dist >= filter.length()) {
bool has_similar_histogram(const char s1[], const char s2[])
size_t levenshtein_distance(const char s1[], const char s2[])
stringsim_type is_string_similar(const std::string ¶m, const std::string &filter)
stringsim_type has_keyword(const std::string param, const std::string filter)
std::string to_lowercase(std::string)
bool strequals(const std::string &a, const std::string &b, bool ignoreCase=true)
bool is_cstr_equal(char const *a, char const *b, const size_t max_len, bool ignoreCase=true)
void calc_histogram(const char s1[], size_t hist1[255])
size_t calc_unique_chars(size_t hist1[255])
The set of utility functions related with string processing, and finding similarity between strings.