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:
Boris Savelev 2015-02-23 17:07:40 +03:00 committed by Slava Zanko
parent 0eca32a852
commit 6ca737d230
2 changed files with 19 additions and 7 deletions

View File

@ -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;
}

View File

@ -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* */