Added `GroupConfig` argument to `print_groups()`: Configurable group printing delimiters (default: Field delim (specified groups) <TAB>-literal, Line delim (input strings) <LF>-literal.)
letprint_delim=||first.then_some("").unwrap_or("\t");// If it's not the first iteration, print `\t`.
letprint_delim=move|to: &mutS|to.write_all(first.then_some(&[][..]).unwrap_or(&how.field_delimiter[..]).as_ref());// If it's not the first iteration, print `\t`.
//TODO: What should be the behaviour of a non-existent group index here? (NOTE: This now corresponds to the previous `g.len() > group` check in caller.) // (NOTE: The original behaviour is to just ignore groups that are out of range entirely (i.e. no printing, no delimit char, no error,) maybe treat non-existent groups as non-matched groups and *just* print the delim char?)
// (NOTE: Moved out of branch, see above ^) // None if !first => write!(to, "\t"),
@ -52,8 +128,8 @@ where S: std::io::Write,
first=false;
}
// If `first == true`, no groups were printed, so we do not print the new-line.
if!first{
to.write_all(b"\n")
if!first&&!how.line_delimiter.is_empty(){
to.write_all(how.line_delimiter.as_ref())
}else{
Ok(())
}
@ -78,21 +154,25 @@ fn main() -> eyre::Result<()>
letre=re::Regex::compile(&args[2])?;
lettext=&args[1];
letgroups=&args[3..];
letprint_cfg=GroupConfig::new();
letgroups={
letgroups=&args[3..];
ifgroups.len()<1{
eprintln!("Warning: No capture groups requested.");