1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

fix #1761 by changing the implementation from recursive

... to an iterative approach

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
Steffen Jaeckel 2023-03-10 14:52:54 +01:00
parent 2925e85cd6
commit 7167760bdd

View File

@ -355,33 +355,32 @@ prof_occurrences(const char* const needle, const char* const haystack, int offse
return *result; return *result;
} }
gchar* haystack_curr = g_utf8_offset_to_pointer(haystack, offset); do {
if (g_str_has_prefix(haystack_curr, needle)) { gchar* haystack_curr = g_utf8_offset_to_pointer(haystack, offset);
if (whole_word) { if (g_str_has_prefix(haystack_curr, needle)) {
gunichar before = 0; if (whole_word) {
gchar* haystack_before_ch = g_utf8_find_prev_char(haystack, haystack_curr); gunichar before = 0;
if (haystack_before_ch) { gchar* haystack_before_ch = g_utf8_find_prev_char(haystack, haystack_curr);
before = g_utf8_get_char(haystack_before_ch); if (haystack_before_ch) {
} before = g_utf8_get_char(haystack_before_ch);
}
gunichar after = 0; gunichar after = 0;
gchar* haystack_after_ch = haystack_curr + strlen(needle); gchar* haystack_after_ch = haystack_curr + strlen(needle);
if (haystack_after_ch[0] != '\0') { if (haystack_after_ch[0] != '\0') {
after = g_utf8_get_char(haystack_after_ch); after = g_utf8_get_char(haystack_after_ch);
} }
if (!g_unichar_isalnum(before) && !g_unichar_isalnum(after)) { if (!g_unichar_isalnum(before) && !g_unichar_isalnum(after)) {
*result = g_slist_append(*result, GINT_TO_POINTER(offset));
}
} else {
*result = g_slist_append(*result, GINT_TO_POINTER(offset)); *result = g_slist_append(*result, GINT_TO_POINTER(offset));
} }
} else {
*result = g_slist_append(*result, GINT_TO_POINTER(offset));
} }
}
offset++; offset++;
if (g_strcmp0(g_utf8_offset_to_pointer(haystack, offset), "\0") != 0) { } while (g_strcmp0(g_utf8_offset_to_pointer(haystack, offset), "\0") != 0);
*result = prof_occurrences(needle, haystack, offset, whole_word, result);
}
return *result; return *result;
} }