summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2017-10-31 06:10:23 -0400
committerAndrew Gallant <jamslam@gmail.com>2017-10-31 06:10:23 -0400
commitb7f0e51ebd91639bd68ff084c789523a611972fe (patch)
treea2d3e161a439b748490d5b4eb55402b337faf5a6
parent6138e7495c4b64957919f69544fc1a9162755cca (diff)
escapes: fix handling of escapes again
We shouldn't set an escape unless explicitly specified by the end user.
-rw-r--r--src/cmd/fmt.rs2
-rw-r--r--src/cmd/input.rs2
-rw-r--r--src/config.rs10
3 files changed, 7 insertions, 7 deletions
diff --git a/src/cmd/fmt.rs b/src/cmd/fmt.rs
index 3878408..c62c26b 100644
--- a/src/cmd/fmt.rs
+++ b/src/cmd/fmt.rs
@@ -65,7 +65,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
wconfig = wconfig.quote_style(csv::QuoteStyle::Always);
}
if let Some(escape) = args.flag_escape {
- wconfig = wconfig.escape(escape.as_byte()).double_quote(false);
+ wconfig = wconfig.escape(Some(escape.as_byte())).double_quote(false);
}
wconfig = wconfig.quote(args.flag_quote.as_byte());
diff --git a/src/cmd/input.rs b/src/cmd/input.rs
index b4a62f5..c837171 100644
--- a/src/cmd/input.rs
+++ b/src/cmd/input.rs
@@ -47,7 +47,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
let wconfig = Config::new(&args.flag_output);
if let Some(escape) = args.flag_escape {
- rconfig = rconfig.escape(escape.as_byte()).double_quote(false);
+ rconfig = rconfig.escape(Some(escape.as_byte())).double_quote(false);
}
if args.flag_no_quoting {
rconfig = rconfig.quoting(false);
diff --git a/src/config.rs b/src/config.rs
index 0539bed..fc51fe0 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -65,7 +65,7 @@ pub struct Config {
quote: u8,
quote_style: csv::QuoteStyle,
double_quote: bool,
- escape: u8,
+ escape: Option<u8>,
quoting: bool,
}
@@ -96,7 +96,7 @@ impl Config {
quote: b'"',
quote_style: csv::QuoteStyle::Necessary,
double_quote: true,
- escape: b'\\',
+ escape: None,
quoting: true,
}
}
@@ -150,7 +150,7 @@ impl Config {
self
}
- pub fn escape(mut self, escape: u8) -> Config {
+ pub fn escape(mut self, escape: Option<u8>) -> Config {
self.escape = escape;
self
}
@@ -285,7 +285,7 @@ impl Config {
.has_headers(!self.no_headers)
.quote(self.quote)
.quoting(self.quoting)
- .escape(Some(self.escape))
+ .escape(self.escape)
.from_reader(rdr)
}
@@ -304,7 +304,7 @@ impl Config {
.quote(self.quote)
.quote_style(self.quote_style)
.double_quote(self.double_quote)
- .escape(self.escape)
+ .escape(self.escape.unwrap_or(b'\\'))
.buffer_capacity(32 * (1<<10))
.from_writer(wtr)
}