Search engine: development of hex search complete

src/search/glob.c: removed unneeded comment
This commit is contained in:
Slava Zanko 2009-05-06 10:27:06 +03:00
parent 9c38485130
commit 589f0b5bd8
2 changed files with 41 additions and 7 deletions

View File

@ -44,8 +44,6 @@
/*** file scope functions ************************************************************************/
//mc_search__regex_is_char_escaped (char *start, char *current)
static GString *
mc_search__glob_translate_to_regex (gchar * str, gsize * len)
{

View File

@ -27,6 +27,7 @@
#include <config.h>
#include <stdio.h>
#include "../src/global.h"
#include "../src/search/search.h"
@ -44,12 +45,46 @@
/*** file scope functions ************************************************************************/
//mc_search__regex_is_char_escaped (char *start, char *current)
static GString *
mc_search__hex_translate_to_regex (gchar * str, gsize * len)
{
GString *buff = g_string_new ("");
gchar *tmp_str = g_strndup (str, *len);
gchar *tmp_str2;
gsize loop = 0;
int val, ptr;
g_strchug (tmp_str); /* trim leadind whitespaces */
while (loop < *len) {
if (sscanf (tmp_str + loop, "%i%n", &val, &ptr)) {
if (val < -128 || val > 255) {
loop++;
continue;
}
tmp_str2 = g_strdup_printf ("\\x%02X", (unsigned char) val);
g_string_append (buff, tmp_str2);
g_free (tmp_str2);
loop += ptr;
continue;
}
if (*(tmp_str + loop) == '"') {
loop++;
gsize loop2=0;
while (loop + loop2 < *len){
if (*(tmp_str + loop + loop2) == '"' &&
!mc_search__regex_is_char_escaped(tmp_str, tmp_str + loop + loop2 - 1))
break;
loop2++;
}
g_string_append_len(buff, tmp_str + loop, loop2 - 1);
loop+=loop2;
continue;
}
loop++;
}
*len = buff->len;
return buff;
}
@ -57,9 +92,10 @@ mc_search__hex_translate_to_regex (gchar * str, gsize * len)
void
mc_search__cond_struct_new_init_hex (const char *charset, mc_search_t * mc_search,
mc_search_cond_t * mc_search_cond)
mc_search_cond_t * mc_search_cond)
{
GString *tmp = mc_search__hex_translate_to_regex (mc_search_cond->str->str, &mc_search_cond->len);
GString *tmp =
mc_search__hex_translate_to_regex (mc_search_cond->str->str, &mc_search_cond->len);
g_string_free (mc_search_cond->str, TRUE);
mc_search_cond->str = tmp;
@ -72,7 +108,7 @@ mc_search__cond_struct_new_init_hex (const char *charset, mc_search_t * mc_searc
gboolean
mc_search__run_hex (mc_search_t * mc_search, const void *user_data,
gsize start_search, gsize end_search, gsize * found_len)
gsize start_search, gsize end_search, gsize * found_len)
{
return mc_search__run_regex (mc_search, user_data, start_search, end_search, found_len);
}