Improve handling of empty braces in globs

We treat empty braces as literal characters though do balance them.
This commit is contained in:
Allan Odgaard
2014-04-18 20:25:48 +07:00
parent cc02ceb963
commit 78e76f55d8
2 changed files with 26 additions and 2 deletions

View File

@@ -171,6 +171,7 @@ namespace
if(parse_char("{"))
{
bool hasComma = false;
node_t* localRoot = nullptr;
while(true)
{
@@ -179,9 +180,21 @@ namespace
{
_root = oldRoot;
_last = oldLast;
return add_node(new node_t(node_t::kGroup, localRoot));
if(hasComma)
return add_node(new node_t(node_t::kGroup, localRoot));
delete localRoot;
char const* parseTo = std::exchange(it, backtrack);
while(it != parseTo && (parse_escape() || parse_text()))
;
return it != parseTo ? ((it = backtrack), false) : true;
}
else if(!parse_char(","))
else if(parse_char(","))
{
hasComma = true;
}
else
{
break;
}

View File

@@ -250,3 +250,14 @@ void test_glob_exclusion ()
OAK_ASSERT( path::glob_t("~html/**/*" ).does_match("/path/to/page/foo/fud.txt"));
OAK_ASSERT( path::glob_t("~html/**/*.txt" ).does_match("/path/to/page/foo/fud.txt"));
}
void test_glob_brace_expansion_match ()
{
OAK_ASSERT(path::glob_t("foo{bar}.txt").does_match("foo{bar}.txt"));
OAK_ASSERT(path::glob_t("foo{,bar}.txt").does_match("foo.txt"));
OAK_ASSERT(path::glob_t("foo{,bar}.txt").does_match("foobar.txt"));
OAK_ASSERT(path::glob_t("foo{\\,bar}.txt").does_match("foo{,bar}.txt"));
OAK_ASSERT(path::glob_t("{foo,{bar},baz}.txt").does_match("foo.txt"));
OAK_ASSERT(path::glob_t("{foo,{bar},baz}.txt").does_match("{bar}.txt"));
OAK_ASSERT(path::glob_t("{foo,{bar},baz}.txt").does_match("baz.txt"));
}