diff --git a/lib/search/regex.c b/lib/search/regex.c index c2c61581b..fe82c9e73 100644 --- a/lib/search/regex.c +++ b/lib/search/regex.c @@ -61,7 +61,6 @@ typedef enum /*** file scope functions ************************************************************************/ -#ifndef SEARCH_TYPE_GLIB static gboolean mc_search__regex_str_append_if_special (GString * copy_to, const GString * regex_str, gsize * offset) @@ -245,7 +244,6 @@ mc_search__cond_struct_new_regex_ci_str (const char *charset, const GString * as return ret_str; } -#endif /* !SEARCH_TYPE_GLIB */ /* --------------------------------------------------------------------------------------------- */ @@ -770,28 +768,6 @@ mc_search_regex__process_escape_sequence (GString * dest_str, const char *from, } } -/* --------------------------------------------------------------------------------------------- */ -/** - * Get regex flags for compilation of expressions. - * @param charset the charset - * - * @return regex flags - */ - -static GRegexCompileFlags -mc_search__regex_get_compile_flags (const char *charset, gboolean is_case_sensitive) -{ - GRegexCompileFlags g_regex_options = G_REGEX_OPTIMIZE | G_REGEX_DOTALL; - - if (!(mc_global.utf8_display && str_isutf8 (charset))) - g_regex_options |= G_REGEX_RAW; - - if (!is_case_sensitive) - g_regex_options |= G_REGEX_CASELESS; - - return g_regex_options; -} - /* --------------------------------------------------------------------------------------------- */ /*** public functions ****************************************************************************/ /* --------------------------------------------------------------------------------------------- */ @@ -812,12 +788,30 @@ mc_search__cond_struct_new_init_regex (const char *charset, mc_search_t * lc_mc_ { #ifdef SEARCH_TYPE_GLIB GError *mcerror = NULL; + GRegexCompileFlags g_regex_options = G_REGEX_OPTIMIZE | G_REGEX_DOTALL; + + if (str_isutf8 (charset) && mc_global.utf8_display) + { + if (!lc_mc_search->is_case_sensitive) + g_regex_options |= G_REGEX_CASELESS; + } + else + { + g_regex_options |= G_REGEX_RAW; + + if (!lc_mc_search->is_case_sensitive) + { + GString *tmp; + + tmp = mc_search_cond->str; + mc_search_cond->str = mc_search__cond_struct_new_regex_ci_str (charset, tmp); + g_string_free (tmp, TRUE); + + } + } mc_search_cond->regex_handle = - g_regex_new (mc_search_cond->str->str, - mc_search__regex_get_compile_flags (charset, - lc_mc_search->is_case_sensitive), 0, - &mcerror); + g_regex_new (mc_search_cond->str->str, g_regex_options, 0, &mcerror); if (mcerror != NULL) { diff --git a/tests/lib/search/Makefile.am b/tests/lib/search/Makefile.am index 4001aec33..d3bd2000b 100644 --- a/tests/lib/search/Makefile.am +++ b/tests/lib/search/Makefile.am @@ -11,7 +11,6 @@ LIBS = @CHECK_LIBS@ $(top_builddir)/lib/libmc.la TESTS = \ glob_prepare_replace_str \ glob_translate_to_regex \ - regex_get_compile_flags \ regex_replace_esc_seq \ regex_process_escape_sequence \ translate_replace_glob_to_regex @@ -32,6 +31,3 @@ translate_replace_glob_to_regex_SOURCES = \ glob_translate_to_regex_SOURCES = \ glob_translate_to_regex.c - -regex_get_compile_flags_SOURCES = \ - 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 deleted file mode 100644 index 742c4e9c1..000000000 --- a/tests/lib/search/regex_get_compile_flags.c +++ /dev/null @@ -1,158 +0,0 @@ -/* - libmc - checks for producing compile flags - - Copyright (C) 2011-2016 - Free Software Foundation, Inc. - - Written by: - Slava Zanko , 2015 - - This file is part of the Midnight Commander. - - The Midnight Commander is free software: you can redistribute it - and/or modify it under the terms of the GNU General Public License as - published by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - The Midnight Commander is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - */ - -#define TEST_SUITE_NAME "lib/search/glob" - -#include "tests/mctest.h" - -#include "regex.c" /* for testing static functions */ - -/* --------------------------------------------------------------------------------------------- */ - -/* @DataSource("test_glob_translate_to_regex_ds") */ -/* *INDENT-OFF* */ -static const struct test_regex_get_compile_flags_ds -{ - const char *charset; - const gboolean utf_flag; - const gboolean is_case_sensitive; - const GRegexCompileFlags expected_result; -} test_regex_get_compile_flags_ds[] = -{ - { - "utf8", - TRUE, - TRUE, - G_REGEX_OPTIMIZE | G_REGEX_DOTALL - }, - { - "utf8", - FALSE, - TRUE, - G_REGEX_OPTIMIZE | G_REGEX_DOTALL | G_REGEX_RAW - }, - { - "utf8", - TRUE, - FALSE, - G_REGEX_OPTIMIZE | G_REGEX_DOTALL | G_REGEX_CASELESS - }, - { - "utf8", - FALSE, - FALSE, - G_REGEX_OPTIMIZE | G_REGEX_DOTALL | G_REGEX_RAW | G_REGEX_CASELESS - }, - { - "utf-8", - TRUE, - TRUE, - G_REGEX_OPTIMIZE | G_REGEX_DOTALL - }, - { - "utf-8", - FALSE, - TRUE, - G_REGEX_OPTIMIZE | G_REGEX_DOTALL | G_REGEX_RAW - }, - { - "utf-8", - TRUE, - FALSE, - G_REGEX_OPTIMIZE | G_REGEX_DOTALL | G_REGEX_CASELESS - }, - { - "utf-8", - FALSE, - FALSE, - G_REGEX_OPTIMIZE | G_REGEX_DOTALL | G_REGEX_RAW | G_REGEX_CASELESS - }, - { - "latin1", - TRUE, - TRUE, - G_REGEX_OPTIMIZE | G_REGEX_DOTALL | G_REGEX_RAW - }, - { - "latin1", - FALSE, - TRUE, - G_REGEX_OPTIMIZE | G_REGEX_DOTALL | G_REGEX_RAW - }, - { - "blablabla", - TRUE, - TRUE, - G_REGEX_OPTIMIZE | G_REGEX_DOTALL | G_REGEX_RAW - }, -}; -/* *INDENT-ON* */ - -/* @Test(dataSource = "test_regex_get_compile_flags_ds") */ -/* *INDENT-OFF* */ -START_PARAMETRIZED_TEST (test_regex_get_compile_flags, test_regex_get_compile_flags_ds) -/* *INDENT-ON* */ -{ - GRegexCompileFlags actual_result; - - /* given */ - mc_global.utf8_display = data->utf_flag; - - /* when */ - actual_result = mc_search__regex_get_compile_flags (data->charset, data->is_case_sensitive); - - /* then */ - mctest_assert_int_eq (actual_result, data->expected_result); -} -/* *INDENT-OFF* */ -END_PARAMETRIZED_TEST -/* *INDENT-ON* */ - -/* --------------------------------------------------------------------------------------------- */ - -int -main (void) -{ - int number_failed; - - Suite *s = suite_create (TEST_SUITE_NAME); - TCase *tc_core = tcase_create ("Core"); - SRunner *sr; - - /* Add new tests here: *************** */ - mctest_add_parameterized_test (tc_core, test_regex_get_compile_flags, - test_regex_get_compile_flags_ds); - /* *********************************** */ - - suite_add_tcase (s, tc_core); - sr = srunner_create (s); - srunner_set_log (sr, "regex_get_compile_flags.log"); - srunner_run_all (sr, CK_ENV); - number_failed = srunner_ntests_failed (sr); - srunner_free (sr); - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; -} - -/* --------------------------------------------------------------------------------------------- */