mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
The patch does not intend to fix all Bash patterns (I believe mc never claimed to support all kinds of them), but it fixes some issues.
Namely, backslash-escaped metacharacter like {}*? will remain in the pattern (with the current code it is just stripped). Second, comma will be transformed to | only inside a group. Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
parent
0eca32a852
commit
6ca737d230
@ -54,25 +54,36 @@ mc_search__glob_translate_to_regex (const GString * astr)
|
||||
buff = g_string_sized_new (32);
|
||||
|
||||
for (loop = 0; loop < astr->len; loop++)
|
||||
{
|
||||
switch (str[loop])
|
||||
{
|
||||
case '*':
|
||||
if (!strutils_is_char_escaped (str, &(str[loop])))
|
||||
{
|
||||
g_string_append (buff, inside_group ? ".*" : "(.*)");
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case '?':
|
||||
if (!strutils_is_char_escaped (str, &(str[loop])))
|
||||
{
|
||||
g_string_append (buff, inside_group ? "." : "(.)");
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case ',':
|
||||
if (!strutils_is_char_escaped (str, &(str[loop])))
|
||||
g_string_append_c (buff, '|');
|
||||
{
|
||||
g_string_append_c (buff, inside_group ? '|' : ',');
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case '{':
|
||||
if (!strutils_is_char_escaped (str, &(str[loop])))
|
||||
{
|
||||
g_string_append_c (buff, '(');
|
||||
inside_group = TRUE;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case '}':
|
||||
@ -80,6 +91,7 @@ mc_search__glob_translate_to_regex (const GString * astr)
|
||||
{
|
||||
g_string_append_c (buff, ')');
|
||||
inside_group = FALSE;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case '+':
|
||||
@ -89,12 +101,12 @@ mc_search__glob_translate_to_regex (const GString * astr)
|
||||
case ')':
|
||||
case '^':
|
||||
g_string_append_c (buff, '\\');
|
||||
/* fall through */
|
||||
break;
|
||||
default:
|
||||
g_string_append_c (buff, str[loop]);
|
||||
break;
|
||||
}
|
||||
|
||||
g_string_append_c (buff, str[loop]);
|
||||
}
|
||||
return buff;
|
||||
}
|
||||
|
||||
|
@ -66,15 +66,15 @@ static const struct test_glob_translate_to_regex_ds
|
||||
},
|
||||
{
|
||||
"t,e.st",
|
||||
"t|e\\.st"
|
||||
"t,e\\.st"
|
||||
},
|
||||
{
|
||||
"^t,e.+st+$",
|
||||
"\\^t|e\\.\\+st\\+\\$"
|
||||
"\\^t,e\\.\\+st\\+\\$"
|
||||
},
|
||||
{
|
||||
"te!@#$%^&*()_+|\";:'{}:><?\\?\\*.,/[]|\\/st",
|
||||
"te!@#\\$%\\^&(.*)\\(\\)_\\+|\";:'():><(.)\\\\\\.|/[]|\\/st"
|
||||
"te!@#\\$%\\^&(.*)\\(\\)_\\+|\";:'():><(.)\\?\\*\\.,/[]|\\/st"
|
||||
},
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
|
Loading…
Reference in New Issue
Block a user