gchar * g_strstr_lv (gchar *haystack, gchar *needle, gsize lv_distance) { gint needle_len = 0, haystack_len = 0, count = 0; gchar *needle_buf = NULL, *rv = NULL; haystack_len = g_utf8_strlen(haystack, -1); needle_len = g_utf8_strlen(needle, -1); /* UTF-8 bytes are 4 bytes length in the worst case */ needle_buf = g_malloc0(needle_len * 4 + 1); do { g_utf8_strncpy(needle_buf, haystack, needle_len); if (needle_len > 3 && lv_distance != 0) { if(levenshtein_safe_strcmp(needle_buf, needle) <= lv_distance) { rv = haystack; break; } } else { if(g_ascii_strcasecmp(needle_buf, needle) == 0) { rv = haystack; break; } } haystack = g_utf8_next_char(haystack); } while(needle_len + count++ < haystack_len); g_free(needle_buf); return rv; }
size_t glyr_levenshtein_strcmp(const char * string, const char * other) { return levenshtein_safe_strcmp(string,other); }