mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 18:14:25 +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);
|
buff = g_string_sized_new (32);
|
||||||
|
|
||||||
for (loop = 0; loop < astr->len; loop++)
|
for (loop = 0; loop < astr->len; loop++)
|
||||||
|
{
|
||||||
switch (str[loop])
|
switch (str[loop])
|
||||||
{
|
{
|
||||||
case '*':
|
case '*':
|
||||||
if (!strutils_is_char_escaped (str, &(str[loop])))
|
if (!strutils_is_char_escaped (str, &(str[loop])))
|
||||||
|
{
|
||||||
g_string_append (buff, inside_group ? ".*" : "(.*)");
|
g_string_append (buff, inside_group ? ".*" : "(.*)");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
if (!strutils_is_char_escaped (str, &(str[loop])))
|
if (!strutils_is_char_escaped (str, &(str[loop])))
|
||||||
|
{
|
||||||
g_string_append (buff, inside_group ? "." : "(.)");
|
g_string_append (buff, inside_group ? "." : "(.)");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ',':
|
case ',':
|
||||||
if (!strutils_is_char_escaped (str, &(str[loop])))
|
if (!strutils_is_char_escaped (str, &(str[loop])))
|
||||||
g_string_append_c (buff, '|');
|
{
|
||||||
|
g_string_append_c (buff, inside_group ? '|' : ',');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case '{':
|
case '{':
|
||||||
if (!strutils_is_char_escaped (str, &(str[loop])))
|
if (!strutils_is_char_escaped (str, &(str[loop])))
|
||||||
{
|
{
|
||||||
g_string_append_c (buff, '(');
|
g_string_append_c (buff, '(');
|
||||||
inside_group = TRUE;
|
inside_group = TRUE;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '}':
|
case '}':
|
||||||
@ -80,6 +91,7 @@ mc_search__glob_translate_to_regex (const GString * astr)
|
|||||||
{
|
{
|
||||||
g_string_append_c (buff, ')');
|
g_string_append_c (buff, ')');
|
||||||
inside_group = FALSE;
|
inside_group = FALSE;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '+':
|
case '+':
|
||||||
@ -89,12 +101,12 @@ mc_search__glob_translate_to_regex (const GString * astr)
|
|||||||
case ')':
|
case ')':
|
||||||
case '^':
|
case '^':
|
||||||
g_string_append_c (buff, '\\');
|
g_string_append_c (buff, '\\');
|
||||||
/* fall through */
|
break;
|
||||||
default:
|
default:
|
||||||
g_string_append_c (buff, str[loop]);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
g_string_append_c (buff, str[loop]);
|
||||||
|
}
|
||||||
return buff;
|
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+$",
|
||||||
"\\^t|e\\.\\+st\\+\\$"
|
"\\^t,e\\.\\+st\\+\\$"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"te!@#$%^&*()_+|\";:'{}:><?\\?\\*.,/[]|\\/st",
|
"te!@#$%^&*()_+|\";:'{}:><?\\?\\*.,/[]|\\/st",
|
||||||
"te!@#\\$%\\^&(.*)\\(\\)_\\+|\";:'():><(.)\\\\\\.|/[]|\\/st"
|
"te!@#\\$%\\^&(.*)\\(\\)_\\+|\";:'():><(.)\\?\\*\\.,/[]|\\/st"
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
/* *INDENT-ON* */
|
/* *INDENT-ON* */
|
||||||
|
Loading…
Reference in New Issue
Block a user