diff options
author | James Booth <boothj5@gmail.com> | 2017-04-28 21:41:55 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2017-04-28 21:41:55 +0100 |
commit | 3e18aab9f38fad3cd971ec09684f7e03f299cc87 (patch) | |
tree | e0addb08a793d5bb6f63d677f487b3c1b76fd569 /src | |
parent | 2fafaec8a7dc9bc01ee894d83214590598b32914 (diff) | |
download | profani-tty-3e18aab9f38fad3cd971ec09684f7e03f299cc87.tar.gz |
Use g_utf8_find_ functions for prof_occurrences
issue #901
Diffstat (limited to 'src')
-rw-r--r-- | src/common.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/common.c b/src/common.c index d9c7d73f..c4b6ace9 100644 --- a/src/common.c +++ b/src/common.c @@ -467,11 +467,18 @@ prof_occurrences(const char *const needle, const char *const haystack, int offse 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); - gchar *haystack_before_ch = g_utf8_prev_char(haystack_curr); - gchar *haystack_after_ch = g_utf8_next_char(haystack_curr + strlen(needle) - needle_last_ch_len); + gunichar before = NULL; + gchar *haystack_before_ch = g_utf8_find_prev_char(haystack, haystack_curr); + if (haystack_before_ch) { + before = g_utf8_get_char(haystack_before_ch); + } + + gunichar after = NULL; + gchar *haystack_after_ch = g_utf8_find_next_char(haystack_curr + strlen(needle) - needle_last_ch_len, NULL); + if (haystack_after_ch) { + after = g_utf8_get_char(haystack_after_ch); + } - gunichar before = g_utf8_get_char(haystack_before_ch); - gunichar after = g_utf8_get_char(haystack_after_ch); if (!g_unichar_isalnum(before) && !g_unichar_isalnum(after)) { *result = g_slist_append(*result, GINT_TO_POINTER(offset)); } |