diff options
author | Steffen Jaeckel <jaeckel-floss@eyet-services.de> | 2023-03-10 14:52:54 +0100 |
---|---|---|
committer | Steffen Jaeckel <jaeckel-floss@eyet-services.de> | 2023-03-11 15:05:03 +0100 |
commit | 7167760bdd06db79ef81b82859639498f324d033 (patch) | |
tree | 1a9e4d047be182e7a5d41b75178c83863d89a77b | |
parent | 2925e85cd6e6c63ce5ba716e5de9d24066e9aebc (diff) | |
download | profani-tty-7167760bdd06db79ef81b82859639498f324d033.tar.gz |
fix #1761 by changing the implementation from recursive
... to an iterative approach Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
-rw-r--r-- | src/common.c | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/src/common.c b/src/common.c index 7888a1dc..eabb45f3 100644 --- a/src/common.c +++ b/src/common.c @@ -355,33 +355,32 @@ prof_occurrences(const char* const needle, const char* const haystack, int offse return *result; } - gchar* haystack_curr = g_utf8_offset_to_pointer(haystack, offset); - if (g_str_has_prefix(haystack_curr, needle)) { - if (whole_word) { - gunichar before = 0; - 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 = 0; - gchar* haystack_after_ch = haystack_curr + strlen(needle); - if (haystack_after_ch[0] != '\0') { - after = g_utf8_get_char(haystack_after_ch); - } - - if (!g_unichar_isalnum(before) && !g_unichar_isalnum(after)) { + do { + gchar* haystack_curr = g_utf8_offset_to_pointer(haystack, offset); + if (g_str_has_prefix(haystack_curr, needle)) { + if (whole_word) { + gunichar before = 0; + 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 = 0; + gchar* haystack_after_ch = haystack_curr + strlen(needle); + if (haystack_after_ch[0] != '\0') { + 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)); + } + } else { *result = g_slist_append(*result, GINT_TO_POINTER(offset)); } - } else { - *result = g_slist_append(*result, GINT_TO_POINTER(offset)); } - } - offset++; - if (g_strcmp0(g_utf8_offset_to_pointer(haystack, offset), "\0") != 0) { - *result = prof_occurrences(needle, haystack, offset, whole_word, result); - } + offset++; + } while (g_strcmp0(g_utf8_offset_to_pointer(haystack, offset), "\0") != 0); return *result; } |