From a0d0a313dfbcffa33942c0d2f1a6dd337f350ceb Mon Sep 17 00:00:00 2001 From: Garrett Berg Date: Sun, 13 Aug 2017 15:23:50 -0600 Subject: add spaces between array items and test for them --- src/ser.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ser.rs b/src/ser.rs index 13d4584..3c4c220 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -628,12 +628,25 @@ impl<'a> Serializer<'a> { } match *state { - State::Table { first, .. } | - State::Array { parent: &State::Table { first, .. }, .. } => { + State::Table { first, .. } => { if !first.get() { - self.dst.push_str("\n"); + // Newline if we are a table that is not the first + // table in the document. + self.dst.push('\n'); } - } + }, + State::Array { parent, first, .. } => { + if !first.get() { + // Always newline if we are not the first item in the + // table-array + self.dst.push('\n'); + } else if let State::Table { first, .. } = *parent { + if !first.get() { + // Newline if we are not the first item in the document + self.dst.push('\n'); + } + } + }, _ => {} } self.dst.push_str("["); -- cgit v1.2.3