mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 18:14:25 +03:00
Merge branch '3525_search_whole_word'
* 3525_search_whole_word: Ticket #3525: fix "Whole words" search.
This commit is contained in:
commit
738a4d499a
@ -91,15 +91,6 @@ mc_search__cond_struct_new_init_normal (const char *charset, mc_search_t * lc_mc
|
|||||||
tmp = mc_search__normal_translate_to_regex (mc_search_cond->str);
|
tmp = mc_search__normal_translate_to_regex (mc_search_cond->str);
|
||||||
g_string_free (mc_search_cond->str, TRUE);
|
g_string_free (mc_search_cond->str, TRUE);
|
||||||
|
|
||||||
if (lc_mc_search->whole_words)
|
|
||||||
{
|
|
||||||
/* NOTE: \b as word boundary doesn't allow search
|
|
||||||
* whole words with non-ASCII symbols.
|
|
||||||
* Update: Is it still true nowadays? Probably not. #2396, #3524 */
|
|
||||||
g_string_prepend (tmp, "(?<![\\p{L}\\p{N}_])");
|
|
||||||
g_string_append (tmp, "(?![\\p{L}\\p{N}_])");
|
|
||||||
}
|
|
||||||
|
|
||||||
mc_search_cond->str = tmp;
|
mc_search_cond->str = tmp;
|
||||||
mc_search__cond_struct_new_init_regex (charset, lc_mc_search, mc_search_cond);
|
mc_search__cond_struct_new_init_regex (charset, lc_mc_search, mc_search_cond);
|
||||||
}
|
}
|
||||||
|
@ -740,18 +740,30 @@ void
|
|||||||
mc_search__cond_struct_new_init_regex (const char *charset, mc_search_t * lc_mc_search,
|
mc_search__cond_struct_new_init_regex (const char *charset, mc_search_t * lc_mc_search,
|
||||||
mc_search_cond_t * mc_search_cond)
|
mc_search_cond_t * mc_search_cond)
|
||||||
{
|
{
|
||||||
|
if (lc_mc_search->whole_words && !lc_mc_search->is_entire_line)
|
||||||
|
{
|
||||||
|
/* NOTE: \b as word boundary doesn't allow search
|
||||||
|
* whole words with non-ASCII symbols.
|
||||||
|
* Update: Is it still true nowadays? Probably not. #2396, #3524 */
|
||||||
|
g_string_prepend (mc_search_cond->str, "(?<![\\p{L}\\p{N}_])");
|
||||||
|
g_string_append (mc_search_cond->str, "(?![\\p{L}\\p{N}_])");
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
#ifdef SEARCH_TYPE_GLIB
|
#ifdef SEARCH_TYPE_GLIB
|
||||||
GError *mcerror = NULL;
|
GError *mcerror = NULL;
|
||||||
|
|
||||||
mc_search_cond->regex_handle =
|
mc_search_cond->regex_handle =
|
||||||
g_regex_new (mc_search_cond->str->str,
|
g_regex_new (mc_search_cond->str->str,
|
||||||
mc_search__regex_get_compile_flags (charset, lc_mc_search->is_case_sensitive),
|
mc_search__regex_get_compile_flags (charset,
|
||||||
0, &mcerror);
|
lc_mc_search->is_case_sensitive), 0,
|
||||||
|
&mcerror);
|
||||||
|
|
||||||
if (mcerror != NULL)
|
if (mcerror != NULL)
|
||||||
{
|
{
|
||||||
lc_mc_search->error = MC_SEARCH_E_REGEX_COMPILE;
|
lc_mc_search->error = MC_SEARCH_E_REGEX_COMPILE;
|
||||||
lc_mc_search->error_str = str_conv_gerror_message (mcerror, _("Regular expression error"));
|
lc_mc_search->error_str =
|
||||||
|
str_conv_gerror_message (mcerror, _("Regular expression error"));
|
||||||
g_error_free (mcerror);
|
g_error_free (mcerror);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -789,7 +801,7 @@ mc_search__cond_struct_new_init_regex (const char *charset, mc_search_t * lc_mc_
|
|||||||
lc_mc_search->regex_match_info = pcre_study (mc_search_cond->regex_handle, 0, &error);
|
lc_mc_search->regex_match_info = pcre_study (mc_search_cond->regex_handle, 0, &error);
|
||||||
if (lc_mc_search->regex_match_info == NULL)
|
if (lc_mc_search->regex_match_info == NULL)
|
||||||
{
|
{
|
||||||
if (error)
|
if (error != NULL)
|
||||||
{
|
{
|
||||||
lc_mc_search->error = MC_SEARCH_E_REGEX_COMPILE;
|
lc_mc_search->error = MC_SEARCH_E_REGEX_COMPILE;
|
||||||
lc_mc_search->error_str = g_strdup (error);
|
lc_mc_search->error_str = g_strdup (error);
|
||||||
@ -799,6 +811,8 @@ mc_search__cond_struct_new_init_regex (const char *charset, mc_search_t * lc_mc_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* SEARCH_TYPE_GLIB */
|
#endif /* SEARCH_TYPE_GLIB */
|
||||||
|
}
|
||||||
|
|
||||||
lc_mc_search->is_utf8 = str_isutf8 (charset);
|
lc_mc_search->is_utf8 = str_isutf8 (charset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user