Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Feb 26, 2022
1 parent 359a776 commit bbd900d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
12 changes: 7 additions & 5 deletions src/io/csv/write/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ pub fn serialize<A: AsRef<dyn Array>>(
row.extend_from_slice(field);
row.push(options.delimiter);
});
// replace last delimiter with new line
let last_byte = row.len() - 1;
row[last_byte] = b'\n';
rows.push(row.clone());
row.clear();
if !row.is_empty() {
// replace last delimiter with new line
let last_byte = row.len() - 1;
row[last_byte] = b'\n';
rows.push(row.clone());
row.clear();
}
Result::Ok(())
})?;

Expand Down
25 changes: 10 additions & 15 deletions src/io/csv/write/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,23 +221,18 @@ fn new_utf8_serializer<'a, O: Offset>(
// This will ensure a csv parser will not read them as missing
// in a delimited field
Some("") => buf.extend_from_slice(b"\"\""),
Some(s) => {
let bytes = s.as_bytes();
buf.reserve(bytes.len() * 2);

loop {
match ser_writer.field(s.as_bytes(), &mut local_buf) {
(WriteResult::OutputFull, _, _) => {
let additional = local_buf.len();
local_buf.extend(std::iter::repeat(0u8).take(additional))
}
(WriteResult::InputEmpty, _, n_out) => {
buf.extend_from_slice(&local_buf[..n_out]);
break;
}
Some(s) => loop {
match ser_writer.field(s.as_bytes(), &mut local_buf) {
(WriteResult::OutputFull, _, _) => {
let additional = local_buf.len();
local_buf.extend(std::iter::repeat(0u8).take(additional))
}
(WriteResult::InputEmpty, _, n_out) => {
buf.extend_from_slice(&local_buf[..n_out]);
break;
}
}
}
},
_ => {}
}
},
Expand Down

0 comments on commit bbd900d

Please sign in to comment.