Your company has been hired to generate CSV records from user input.
We need a builder for a CSV record per the standard defined in RFC 4180.
While a formal specification exists, your company only needs to implement the following functionality:
Basic escaping means:
Fields containing line breaks, double-quotes, and commas should be enclosed in double-quotes.
If double-quotes are used to enclose fields, then a double-quote appearing inside a field must be escaped by preceding it with another double-quote.
You'll need to implement the new method to create a new builder.
let mut builder = CsvRecordBuilder::new();You'll need to implement the add method to append fields to your record builder.
add takes immutable string slices, &str, as the argument.
builder.add("ant");
builder.add("ba\"t");
builder.add("cat");You'll need to implement the build method.
build consumes the builder and returns a CSV record.
let record = builder.build();
// Note that from now on we cannot use `builder`
assert_eq!(&record, r#"ant,"ba""t",cat"#);Your company has been hired to generate CSV records from user input.
We need a builder for a CSV record per the standard defined in RFC 4180.
While a formal specification exists, your company only needs to implement the following functionality:
Basic escaping means:
Fields containing line breaks, double-quotes, and commas should be enclosed in double-quotes.
If double-quotes are used to enclose fields, then a double-quote appearing inside a field must be escaped by preceding it with another double-quote.
You'll need to implement the new method to create a new builder.
let mut builder = CsvRecordBuilder::new();You'll need to implement the add method to append fields to your record builder.
add takes immutable string slices, &str, as the argument.
builder.add("ant");
builder.add("ba\"t");
builder.add("cat");You'll need to implement the build method.
build consumes the builder and returns a CSV record.
let record = builder.build();
// Note that from now on we cannot use `builder`
assert_eq!(&record, r#"ant,"ba""t",cat"#);