Skip to content

Commit

Permalink
Accept slash-t for tab as delimiter argument (#49)
Browse files Browse the repository at this point in the history
* Accept slash-t for tab as delimiter argument

Currently to use a tab you must use:

$ csvlens -d $'\t' ...

With this change the following are also accepted:

$ csvlens -d '\t' ...
$ csvlens -d "\t" ...

* cargo fmt
  • Loading branch information
peterjc committed Jan 9, 2024
1 parent 5ffc177 commit 10235be
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/delimiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ impl Delimiter {
if s == "auto" {
return Ok(Delimiter::Auto);
}
if s == r"\t" {
return Ok(Delimiter::Character(b'\t'));
}
let mut chars = s.chars();
let c = chars.next().context("Delimiter should not be empty")?;
if !c.is_ascii() {
Expand All @@ -32,7 +35,10 @@ impl Delimiter {
);
}
if chars.next().is_some() {
bail!("Delimiter should be exactly one character, got {}", s);
bail!(
"Delimiter should be exactly one character (or \\t), got '{}'",
s
);
}
Ok(Delimiter::Character(c.try_into()?))
} else {
Expand Down

0 comments on commit 10235be

Please sign in to comment.