From b47bc9be5b214c007060d5f924f7d31b84d6583d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaarlo=20R=C3=A4ih=C3=A4?= Date: Sat, 18 Aug 2018 13:50:14 +0300 Subject: [PATCH] Only add commas between array elements when needed This fixes at least following tests: ArrayValuesTest MultipleArrayValuesTest NestedArraysTest EmptyStringSpaceTest --- Json5/Json5Array.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Json5/Json5Array.cs b/Json5/Json5Array.cs index bab4676..7835fb7 100644 --- a/Json5/Json5Array.cs +++ b/Json5/Json5Array.cs @@ -115,10 +115,24 @@ internal override string ToJson5String(string space, string indent) { string newLine = string.IsNullOrEmpty(space) ? "" : "\n"; + // TODO: Use string builder instead of string string s = "[" + newLine; + bool isFirstValue = true; + foreach (Json5Value value in this) - s += (value ?? Null).ToJson5String(space, indent + space) + "," + newLine; + { + if (isFirstValue) + { + isFirstValue = false; + } + else + { + s += "," + newLine; + } + + s += (value ?? Null).ToJson5String(space, indent + space); + } s += indent + "]";