diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2023-01-30 20:54:37 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-01-30 21:44:03 +0100 |
commit | 69a635412d4787ccb96f6641f3b4d35b77d25072 (patch) | |
tree | dd3f6a701cf2ad780646570899c7cef99ed576bb /src/core | |
parent | 38ffac78f3bd635adf069e3c30fc62edc5e90f40 (diff) | |
download | weechat-69a635412d4787ccb96f6641f3b4d35b77d25072.zip |
core: add function string_get_common_bytes_count (issue #1877)
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/wee-string.c | 25 | ||||
-rw-r--r-- | src/core/wee-string.h | 2 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/core/wee-string.c b/src/core/wee-string.c index abe7ccd17..a6634ba7c 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -3961,6 +3961,31 @@ string_input_for_buffer (const char *string) } /* + * Returns the number of bytes in common between two strings (this function + * works with bytes and not UTF-8 chars). + */ + +int +string_get_common_bytes_count (const char *string1, const char *string2) +{ + const char *ptr_str1; + int found; + + if (!string1 || !string2) + return 0; + + found = 0; + ptr_str1 = string1; + while (ptr_str1[0]) + { + if (strchr (string2, ptr_str1[0])) + found++; + ptr_str1++; + } + return found; +} + +/* * Returns the distance between two strings using the Levenshtein algorithm. * See: https://en.wikipedia.org/wiki/Levenshtein_distance */ diff --git a/src/core/wee-string.h b/src/core/wee-string.h index 641855f7f..19c616e5e 100644 --- a/src/core/wee-string.h +++ b/src/core/wee-string.h @@ -134,6 +134,8 @@ extern char *string_hex_dump (const char *data, int data_size, const char *prefix, const char *suffix); extern int string_is_command_char (const char *string); extern const char *string_input_for_buffer (const char *string); +extern int string_get_common_bytes_count (const char *string1, + const char *string2); extern int string_levenshtein (const char *string1, const char *string2, int case_sensitive); extern char *string_replace_with_callback (const char *string, |