Ticket #3589: regex.patch

File regex.patch, 3.7 KB (added by phelum, 8 years ago)
  • regex.c

    old new  
    124124mc_search__cond_struct_new_regex_hex_add (const char *charset, GString * str_to, 
    125125                                          const char *one_char, gsize str_len) 
    126126{ 
    127 //  GString *upp, *low; 
     127    GString *upp, *low; 
    128128    gsize loop; 
    129129 
    130 //  upp = mc_search__toupper_case_str (charset, one_char, str_len); 
    131 //  low = mc_search__tolower_case_str (charset, one_char, str_len); 
     130    upp = mc_search__toupper_case_str (charset, one_char, str_len); 
     131    low = mc_search__tolower_case_str (charset, one_char, str_len); 
    132132 
    133 //  for (loop = 0; loop < upp->len; loop++) 
    134     for (loop = 0; loop < str_len; loop++) 
     133    for (loop = 0; loop < upp->len; loop++) 
    135134    { 
    136135        gchar tmp_str[10 + 1];  /* longest content is "[\\x%02X\\x%02X]" */ 
    137136        gint tmp_len; 
    138137 
    139 //      if (loop >= low->len || upp->str[loop] == low->str[loop]) 
    140 //          tmp_len = 
    141 //              g_snprintf (tmp_str, sizeof (tmp_str), "\\x%02X", (unsigned char) upp->str[loop]); 
    142 //      else 
    143 //          tmp_len = 
    144 //              g_snprintf (tmp_str, sizeof (tmp_str), "[\\x%02X\\x%02X]", 
    145 //                          (unsigned char) upp->str[loop], (unsigned char) low->str[loop]); 
     138        if (loop >= low->len || upp->str[loop] == low->str[loop]) 
    146139            tmp_len = 
    147                 g_snprintf (tmp_str, sizeof (tmp_str), "\\x%02X", one_char [loop]); 
     140                g_snprintf (tmp_str, sizeof (tmp_str), "\\x%02X", (unsigned char) upp->str[loop]); 
     141        else 
     142            tmp_len = 
     143                g_snprintf (tmp_str, sizeof (tmp_str), "[\\x%02X\\x%02X]", 
     144                            (unsigned char) upp->str[loop], (unsigned char) low->str[loop]); 
    148145 
    149146        g_string_append_len (str_to, tmp_str, tmp_len); 
    150147    } 
    151148 
    152 //  g_string_free (upp, TRUE); 
    153 //  g_string_free (low, TRUE); 
     149    g_string_free (upp, TRUE); 
     150    g_string_free (low, TRUE); 
    154151} 
    155152 
    156153/* --------------------------------------------------------------------------------------------- */ 
     
    209206    spec_char = g_string_sized_new (64); 
    210207    loop = 0; 
    211208 
    212 //  while (loop <= astr->len) 
    213     while (loop < astr->len) 
     209    while (loop <= astr->len) 
    214210    { 
    215211        if (mc_search__regex_str_append_if_special (spec_char, astr, &loop)) 
    216212        { 
     
    269265    char *string_safe, *p, *end; 
    270266    gboolean ret; 
    271267 
    272 //      The processing below causes problems when 0x00 in hex arguments. 
    273 //      So we always just call the match function with the input argument. 
    274  
    275 //  if ((g_regex_get_compile_flags (regex) & G_REGEX_RAW) 
    276 //      || g_utf8_validate (string, string_len, NULL)) 
     268    if ((g_regex_get_compile_flags (regex) & G_REGEX_RAW) 
     269        || g_utf8_validate (string, string_len, NULL)) 
    277270    { 
    278271        return g_regex_match_full (regex, string, string_len, start_position, match_options, 
    279272                                   match_info, error); 
     
    820813#ifdef SEARCH_TYPE_GLIB 
    821814        GError *mcerror = NULL; 
    822815 
    823         GRegexCompileFlags  CompileFlags; 
    824  
    825         CompileFlags = mc_search__regex_get_compile_flags (charset, lc_mc_search->is_case_sensitive); 
    826         if (lc_mc_search->search_type == MC_SEARCH_T_HEX)           // if hex mode search, 
    827           CompileFlags |= G_REGEX_RAW;                              // use raw mode here 
    828  
    829816        mc_search_cond->regex_handle = 
    830817            g_regex_new (mc_search_cond->str->str, 
    831                          CompileFlags, 
    832                          0, 
     818                         mc_search__regex_get_compile_flags (charset, 
     819                                                             lc_mc_search->is_case_sensitive), 0, 
    833820                         &mcerror); 
    834821 
    835822        if (mcerror != NULL)