Ticket #3416: mc-3416-case-insensitive-search.patch

File mc-3416-case-insensitive-search.patch, 4.2 KB (added by egmont, 9 years ago)

Fix

  • lib/search/regex.c

    diff --git a/lib/search/regex.c b/lib/search/regex.c
    index 4ee3979..082fa2c 100644
    a b typedef enum 
    6161 
    6262/*** file scope functions ************************************************************************/ 
    6363 
     64#ifndef SEARCH_TYPE_GLIB 
    6465static gboolean 
    6566mc_search__regex_str_append_if_special (GString * copy_to, const GString * regex_str, 
    6667                                        gsize * offset) 
    mc_search__cond_struct_new_regex_ci_str (const char *charset, const GString * as 
    244245 
    245246    return ret_str; 
    246247} 
     248#endif /* !SEARCH_TYPE_GLIB */ 
    247249 
    248250/* --------------------------------------------------------------------------------------------- */ 
    249251 
    mc_search_regex__process_escape_sequence (GString * dest_str, const char *from, 
    717719 */ 
    718720 
    719721static GRegexCompileFlags 
    720 mc_search__regex_get_compile_flags (const char *charset) 
     722mc_search__regex_get_compile_flags (const char *charset, gboolean is_case_sensitive) 
    721723{ 
    722724    GRegexCompileFlags g_regex_options = G_REGEX_OPTIMIZE | G_REGEX_DOTALL; 
    723725 
    724726    if (!(mc_global.utf8_display && str_isutf8 (charset))) 
    725727        g_regex_options |= G_REGEX_RAW; 
    726728 
     729    if (!is_case_sensitive) 
     730        g_regex_options |= G_REGEX_CASELESS; 
     731 
    727732    return g_regex_options; 
    728733} 
    729734 
    mc_search__cond_struct_new_init_regex (const char *charset, mc_search_t * lc_mc_ 
    738743#ifdef SEARCH_TYPE_GLIB 
    739744    GError *mcerror = NULL; 
    740745 
    741     if (!lc_mc_search->is_case_sensitive) 
    742     { 
    743         GString *tmp; 
    744  
    745         tmp = mc_search_cond->str; 
    746         mc_search_cond->str = mc_search__cond_struct_new_regex_ci_str (charset, tmp); 
    747         g_string_free (tmp, TRUE); 
    748     } 
    749746    mc_search_cond->regex_handle = 
    750         g_regex_new (mc_search_cond->str->str, mc_search__regex_get_compile_flags (charset), 0, 
    751                      &mcerror); 
     747        g_regex_new (mc_search_cond->str->str, 
     748                     mc_search__regex_get_compile_flags (charset, lc_mc_search->is_case_sensitive), 
     749                     0, &mcerror); 
    752750 
    753751    if (mcerror != NULL) 
    754752    { 
  • tests/lib/search/regex_get_compile_flags.c

    diff --git a/tests/lib/search/regex_get_compile_flags.c b/tests/lib/search/regex_get_compile_flags.c
    index 9d22e1e..94257d9 100644
    a b static const struct test_regex_get_compile_flags_ds 
    3737{ 
    3838    const char *charset; 
    3939    const gboolean utf_flag; 
     40    const gboolean is_case_sensitive; 
    4041    const GRegexCompileFlags expected_result; 
    4142} test_regex_get_compile_flags_ds[] = 
    4243{ 
    4344    { 
    4445        "utf8", 
    4546        TRUE, 
     47        TRUE, 
    4648        G_REGEX_OPTIMIZE | G_REGEX_DOTALL 
    4749    }, 
    4850    { 
    4951        "utf8", 
    5052        FALSE, 
     53        TRUE, 
    5154        G_REGEX_OPTIMIZE | G_REGEX_DOTALL | G_REGEX_RAW 
    5255    }, 
    5356    { 
     57        "utf8", 
     58        TRUE, 
     59        FALSE, 
     60        G_REGEX_OPTIMIZE | G_REGEX_DOTALL | G_REGEX_CASELESS 
     61    }, 
     62    { 
     63        "utf8", 
     64        FALSE, 
     65        FALSE, 
     66        G_REGEX_OPTIMIZE | G_REGEX_DOTALL | G_REGEX_RAW | G_REGEX_CASELESS 
     67    }, 
     68    { 
    5469        "utf-8", 
    5570        TRUE, 
     71        TRUE, 
    5672        G_REGEX_OPTIMIZE | G_REGEX_DOTALL 
    5773    }, 
    5874    { 
    5975        "utf-8", 
    6076        FALSE, 
     77        TRUE, 
    6178        G_REGEX_OPTIMIZE | G_REGEX_DOTALL | G_REGEX_RAW 
    6279    }, 
    6380    { 
     81        "utf-8", 
     82        TRUE, 
     83        FALSE, 
     84        G_REGEX_OPTIMIZE | G_REGEX_DOTALL | G_REGEX_CASELESS 
     85    }, 
     86    { 
     87        "utf-8", 
     88        FALSE, 
     89        FALSE, 
     90        G_REGEX_OPTIMIZE | G_REGEX_DOTALL | G_REGEX_RAW | G_REGEX_CASELESS 
     91    }, 
     92    { 
    6493        "latin1", 
    6594        TRUE, 
     95        TRUE, 
    6696        G_REGEX_OPTIMIZE | G_REGEX_DOTALL  | G_REGEX_RAW 
    6797    }, 
    6898    { 
    6999        "latin1", 
    70100        FALSE, 
     101        TRUE, 
    71102        G_REGEX_OPTIMIZE | G_REGEX_DOTALL | G_REGEX_RAW 
    72103    }, 
    73104    { 
    74105        "blablabla", 
    75106        TRUE, 
     107        TRUE, 
    76108        G_REGEX_OPTIMIZE | G_REGEX_DOTALL  | G_REGEX_RAW 
    77109    }, 
    78110}; 
    START_PARAMETRIZED_TEST (test_regex_get_compile_flags, test_regex_get_compile_fl 
    89121    mc_global.utf8_display = data->utf_flag; 
    90122 
    91123    /* when */ 
    92     actual_result = mc_search__regex_get_compile_flags (data->charset); 
     124    actual_result = mc_search__regex_get_compile_flags (data->charset, data->is_case_sensitive); 
    93125 
    94126    /* then */ 
    95127    mctest_assert_int_eq (actual_result, data->expected_result);