From 9a406992a5f6f4f849e99c6fba2a6d6f07e536ea Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sun, 29 Jan 2012 18:52:16 +0300 Subject: [PATCH] Ticket #2705: the 0x prefix for hexadecimal search is optional now. Hexadecimal values like "2d f0" can be used as well as "0x2d 0xf0" in all search dialogs where hexadecimal search is supported. Signed-off-by: Andrew Borodin --- lib/search/hex.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/search/hex.c b/lib/search/hex.c index 8a2ff180e..1f9fd5fc1 100644 --- a/lib/search/hex.c +++ b/lib/search/hex.c @@ -51,12 +51,25 @@ static GString * mc_search__hex_translate_to_regex (const GString * astr) { GString *buff; - gchar *tmp_str; + gchar *tmp_str, *tmp_str2; gsize tmp_str_len; gsize loop = 0; buff = g_string_sized_new (64); tmp_str = g_strndup (astr->str, astr->len); + tmp_str2 = tmp_str; + + /* remove 0x prefices */ + while (TRUE) + { + tmp_str2 = strstr (tmp_str2, "0x"); + if (tmp_str2 == NULL) + break; + + *tmp_str2++ = ' '; + *tmp_str2++ = ' '; + } + g_strchug (tmp_str); /* trim leadind whitespaces */ tmp_str_len = strlen (tmp_str); @@ -64,7 +77,7 @@ mc_search__hex_translate_to_regex (const GString * astr) { int val, ptr; - if (sscanf (tmp_str + loop, "%i%n", &val, &ptr)) + if (sscanf (tmp_str + loop, "%x%n", &val, &ptr)) { if (val < -128 || val > 255) loop++; @@ -107,6 +120,7 @@ mc_search__cond_struct_new_init_hex (const char *charset, mc_search_t * lc_mc_se { GString *tmp; + g_string_ascii_down (mc_search_cond->str); tmp = mc_search__hex_translate_to_regex (mc_search_cond->str); g_string_free (mc_search_cond->str, TRUE); mc_search_cond->str = tmp;