From 0a784f4d2e41734268de5fd0f34ec22ff7ad7920 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Fri, 9 Aug 2013 11:50:19 +0400 Subject: [PATCH] (mc_search_regex__process_append_str): minor optimization and cosmetics. Signed-off-by: Andrew Borodin --- lib/search/regex.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/lib/search/regex.c b/lib/search/regex.c index 388a73b8e..748a52394 100644 --- a/lib/search/regex.c +++ b/lib/search/regex.c @@ -546,61 +546,59 @@ static void mc_search_regex__process_append_str (GString * dest_str, const char *from, gsize len, replace_transform_type_t * replace_flags) { - gsize loop = 0; + gsize loop; gsize char_len; - char *tmp_str; - GString *tmp_string; if (len == (gsize) (-1)) len = strlen (from); - if (*replace_flags == REPLACE_T_NO_TRANSFORM) + if ((*replace_flags == REPLACE_T_NO_TRANSFORM) != 0) { g_string_append_len (dest_str, from, len); return; } - while (loop < len) + + for (loop = 0; loop < len; loop += char_len) { + GString *tmp_string = NULL; + char *tmp_str; + tmp_str = mc_search__get_one_symbol (NULL, from + loop, len - loop, NULL); char_len = strlen (tmp_str); - if (*replace_flags & REPLACE_T_UPP_TRANSFORM_CHAR) + + if ((*replace_flags & REPLACE_T_UPP_TRANSFORM_CHAR) != 0) { *replace_flags &= ~REPLACE_T_UPP_TRANSFORM_CHAR; tmp_string = mc_search__toupper_case_str (NULL, tmp_str, char_len); - g_string_append (dest_str, tmp_string->str); + g_string_append_len (dest_str, tmp_string->str, tmp_string->len); g_string_free (tmp_string, TRUE); - } - else if (*replace_flags & REPLACE_T_LOW_TRANSFORM_CHAR) + else if ((*replace_flags & REPLACE_T_LOW_TRANSFORM_CHAR) != 0) { *replace_flags &= ~REPLACE_T_LOW_TRANSFORM_CHAR; - tmp_string = mc_search__toupper_case_str (NULL, tmp_str, char_len); - g_string_append (dest_str, tmp_string->str); + tmp_string = mc_search__tolower_case_str (NULL, tmp_str, char_len); + g_string_append_len (dest_str, tmp_string->str, tmp_string->len); g_string_free (tmp_string, TRUE); - } - else if (*replace_flags & REPLACE_T_UPP_TRANSFORM) + else if ((*replace_flags & REPLACE_T_UPP_TRANSFORM) != 0) { tmp_string = mc_search__toupper_case_str (NULL, tmp_str, char_len); - g_string_append (dest_str, tmp_string->str); + g_string_append_len (dest_str, tmp_string->str, tmp_string->len); g_string_free (tmp_string, TRUE); - } - else if (*replace_flags & REPLACE_T_LOW_TRANSFORM) + else if ((*replace_flags & REPLACE_T_LOW_TRANSFORM) != 0) { tmp_string = mc_search__tolower_case_str (NULL, tmp_str, char_len); - g_string_append (dest_str, tmp_string->str); + g_string_append_len (dest_str, tmp_string->str, tmp_string->len); g_string_free (tmp_string, TRUE); - } else { - g_string_append (dest_str, tmp_str); + g_string_append_len (dest_str, tmp_str, tmp_string->len); } - g_free (tmp_str); - loop += char_len; - } + g_free (tmp_str); + } } /* --------------------------------------------------------------------------------------------- */