mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-23 04:46:55 +03:00
(mc_search__cond_struct_new_regex_hex_add): refactoring to get rid of extra memory allocation.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
bb2f5d35f3
commit
00f6272364
@ -119,12 +119,12 @@ mc_search__regex_str_append_if_special (GString * copy_to, const GString * regex
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mc_search__cond_struct_new_regex_hex_add (const char *charset, GString * str_to,
|
mc_search__cond_struct_new_regex_hex_add (const char *charset, GString * str_to,
|
||||||
const char *one_char, gsize str_len)
|
const char *one_char, gsize str_len)
|
||||||
{
|
{
|
||||||
GString *upp, *low;
|
GString *upp, *low;
|
||||||
gchar *tmp_str;
|
|
||||||
gsize loop;
|
gsize loop;
|
||||||
|
|
||||||
upp = mc_search__toupper_case_str (charset, one_char, str_len);
|
upp = mc_search__toupper_case_str (charset, one_char, str_len);
|
||||||
@ -132,23 +132,20 @@ mc_search__cond_struct_new_regex_hex_add (const char *charset, GString * str_to,
|
|||||||
|
|
||||||
for (loop = 0; loop < upp->len; loop++)
|
for (loop = 0; loop < upp->len; loop++)
|
||||||
{
|
{
|
||||||
|
gchar tmp_str[10 + 1]; /* longest content is "[\\x%02X\\x%02X]" */
|
||||||
|
gint tmp_len;
|
||||||
|
|
||||||
if (loop < low->len)
|
if (loop >= low->len || upp->str[loop] == low->str[loop])
|
||||||
{
|
tmp_len =
|
||||||
if (upp->str[loop] == low->str[loop])
|
g_snprintf (tmp_str, sizeof (tmp_str), "\\x%02X", (unsigned char) upp->str[loop]);
|
||||||
tmp_str = g_strdup_printf ("\\x%02X", (unsigned char) upp->str[loop]);
|
|
||||||
else
|
else
|
||||||
tmp_str =
|
tmp_len =
|
||||||
g_strdup_printf ("[\\x%02X\\x%02X]", (unsigned char) upp->str[loop],
|
g_snprintf (tmp_str, sizeof (tmp_str), "[\\x%02X\\x%02X]",
|
||||||
(unsigned char) low->str[loop]);
|
(unsigned char) upp->str[loop], (unsigned char) low->str[loop]);
|
||||||
}
|
|
||||||
else
|
g_string_append_len (str_to, tmp_str, tmp_len);
|
||||||
{
|
|
||||||
tmp_str = g_strdup_printf ("\\x%02X", (unsigned char) upp->str[loop]);
|
|
||||||
}
|
|
||||||
g_string_append (str_to, tmp_str);
|
|
||||||
g_free (tmp_str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_string_free (upp, TRUE);
|
g_string_free (upp, TRUE);
|
||||||
g_string_free (low, TRUE);
|
g_string_free (low, TRUE);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user