diff options
author | Frank Zschockelt <profanity@freakysoft.de> | 2019-05-08 22:33:19 +0200 |
---|---|---|
committer | Frank Zschockelt <profanity@freakysoft.de> | 2019-05-22 19:57:52 +0200 |
commit | 56e925ed0324177d31fef9b301593557cc3e4a88 (patch) | |
tree | 9952667ffacaafc009c2987b4e3354ac617fa2d1 | |
parent | 91d17edcb495e229c8691717069ebe989ab5e805 (diff) | |
download | profani-tty-56e925ed0324177d31fef9b301593557cc3e4a88.tar.gz |
Don't call mblen() to not depend on locale
mblen will fail with return code -1 if the locale used by the unit tests isn't available on the machine. This will lead to an off by one error in some tests where the needle is at the end of the haystack. Since prof_occurrences expect null-terminated strings, the character after the needle can simply be found by incrementing the address of the found needle with strlen(needle).
-rw-r--r-- | src/common.c | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/src/common.c b/src/common.c index 5aed9295..0f84e535 100644 --- a/src/common.c +++ b/src/common.c @@ -410,9 +410,6 @@ prof_occurrences(const char *const needle, const char *const haystack, int offse gchar *haystack_curr = g_utf8_offset_to_pointer(haystack, offset); if (g_str_has_prefix(haystack_curr, needle)) { if (whole_word) { - gchar *needle_last_ch = g_utf8_offset_to_pointer(needle, g_utf8_strlen(needle, -1)- 1); - int needle_last_ch_len = mblen(needle_last_ch, MB_CUR_MAX); - gunichar before = 0; gchar *haystack_before_ch = g_utf8_find_prev_char(haystack, haystack_curr); if (haystack_before_ch) { @@ -420,8 +417,8 @@ prof_occurrences(const char *const needle, const char *const haystack, int offse } gunichar after = 0; - gchar *haystack_after_ch = g_utf8_find_next_char(haystack_curr + strlen(needle) - needle_last_ch_len, NULL); - if (haystack_after_ch) { + gchar *haystack_after_ch = haystack_curr + strlen(needle); + if (haystack_after_ch[0] != '\0') { after = g_utf8_get_char(haystack_after_ch); } |