This library performs brace expansion of strings, similar in spirit (though different in several details) to that used in shells like Bash etc.
Given the input:
text
{hello,goodbye,wonderful} world
this algorithm produces the following collection of strings:
text
hello world
goodbye world
wonderful world
Note that unlike shell brace expansion, the result is a collection of separate strings rather than a single string. Also, whitespace characters are not treated specially by the algorithm; they are on the same footing as printing characers.
Curly braces {
and }
are used to mark the start and end of an expansion
list, and commas separate the items in each list. Literal curly braces and
commas must be escaped with single backslashes:
text
this is {\{braced\},[bracketed\, nicely]}
produces:
text
this is {braced}
this is [bracketed, nicely]
If you want a literal backslash, that too must be escaped:
text
this is a backslash: \\
produces:
text
this is a backslash: \
Note that the escaping backslashes are removed from the output.
Inputs can contain multiple expansion lists, and these can be nested. For example:
text
{hello,goodbye} {world,my {friends,colleagues}}
produces:
text
hello world
goodbye world
hello my friends
hello my colleagues
goodbye my friends
goodbye my colleagues
```rust use braceexpand::braceexpand;
fn main() { let output = brace_expand("this {is,is not} a pipe");
assert_eq!(output, vec!["this is a pipe", "this is not a pipe"]);
} ```