Skip to content

Commit 5fe4ba4

Browse files
committed
Change json strings to use tab character rather than spaces (processor still allows spaces, but stringifier will always use tab character for indentation)
1 parent d8c0025 commit 5fe4ba4

File tree

21 files changed

+453
-449
lines changed

21 files changed

+453
-449
lines changed

src/main/java/core/JSONStringifier.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ public static String stringifyEscape(String escape) {
124124
public static List<String> expandJson(String json) {
125125
List<String> result = new ArrayList<>();
126126
int indentation = 0;
127-
String tab = " ";
128-
127+
String tab = " ";
129128
StringBuilder currentLine = new StringBuilder();
130129

131130
for (int i = 0; i < json.length(); i++) {
@@ -153,7 +152,12 @@ public static List<String> expandJson(String json) {
153152
currentLine = new StringBuilder();
154153
}
155154
indentation--;
156-
result.add(tab.repeat(indentation) + c);
155+
if (i + 1 < json.length() && json.charAt(i + 1) == ',') {
156+
result.add(tab.repeat(indentation) + c + ",");
157+
i++;
158+
}
159+
else
160+
result.add(tab.repeat(indentation) + c);
157161
break;
158162
case ',' :
159163
currentLine.append(c);
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
"test1" : {
2-
"numbers" : {
3-
"zero" : 0,
4-
"negative_zero" : 0,
5-
"small_int" : 42,
6-
"negative_int" : -42,
7-
"max_int" : 2147483647,
8-
"min_int" : -2147483648,
9-
"just_over_max_int" : 2147483648,
10-
"just_under_min_int" : -2147483649,
11-
"max_long" : 9223372036854775807,
12-
"min_long" : -9223372036854775808,
13-
"regular_double" : 3.14159,
14-
"negative_double" : -3.14159,
15-
"exponential_positive" : 1.2E10,
16-
"exponential_negative" : -4.5E-5,
17-
"double_max" : 1.7976931348623157E308,
18-
"double_min" : 2.2250738585072014E-308
19-
}
2+
"numbers" : {
3+
"zero" : 0,
4+
"negative_zero" : 0,
5+
"small_int" : 42,
6+
"negative_int" : -42,
7+
"max_int" : 2147483647,
8+
"min_int" : -2147483648,
9+
"just_over_max_int" : 2147483648,
10+
"just_under_min_int" : -2147483649,
11+
"max_long" : 9223372036854775807,
12+
"min_long" : -9223372036854775808,
13+
"regular_double" : 3.14159,
14+
"negative_double" : -3.14159,
15+
"exponential_positive" : 1.2E10,
16+
"exponential_negative" : -4.5E-5,
17+
"double_max" : 1.7976931348623157E308,
18+
"double_min" : 2.2250738585072014E-308
19+
}
2020
}

src/tests/java/data/test1/test1.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
2-
"numbers" : {
3-
"zero" : 0,
4-
"negative_zero" : -0,
5-
"small_int" : 42,
6-
"negative_int" : -42,
7-
"max_int" : 2147483647,
8-
"min_int" : -2147483648,
9-
"just_over_max_int" : 2147483648,
10-
"just_under_min_int" : -2147483649,
11-
"max_long" : 9223372036854775807,
12-
"min_long" : -9223372036854775808,
13-
"regular_double" : 3.14159,
14-
"negative_double" : -3.14159,
15-
"exponential_positive" : 1.2E10,
16-
"exponential_negative" : -4.5E-5,
17-
"double_max" : 1.7976931348623157E308,
18-
"double_min" : 2.2250738585072014E-308
19-
}
20-
}
2+
"numbers" : {
3+
"zero" : 0,
4+
"negative_zero" : -0,
5+
"small_int" : 42,
6+
"negative_int" : -42,
7+
"max_int" : 2147483647,
8+
"min_int" : -2147483648,
9+
"just_over_max_int" : 2147483648,
10+
"just_under_min_int" : -2147483649,
11+
"max_long" : 9223372036854775807,
12+
"min_long" : -9223372036854775808,
13+
"regular_double" : 3.14159,
14+
"negative_double" : -3.14159,
15+
"exponential_positive" : 1.2E10,
16+
"exponential_negative" : -4.5E-5,
17+
"double_max" : 1.7976931348623157E308,
18+
"double_min" : 2.2250738585072014E-308
19+
}
20+
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"test2" : {
2-
"single_values" : {
3-
"null" : null,
4-
"booleans" : {
5-
"true" : true,
6-
"false" : false
7-
}
8-
}
2+
"single_values" : {
3+
"null" : null,
4+
"booleans" : {
5+
"true" : true,
6+
"false" : false
7+
}
8+
}
99
}

src/tests/java/data/test2/test2.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"single_values" : {
3-
"null" : null,
4-
"booleans" : {
5-
"true" : true,
6-
"false" : false
7-
}
8-
}
2+
"single_values" : {
3+
"null" : null,
4+
"booleans" : {
5+
"true" : true,
6+
"false" : false
7+
}
8+
}
99
}
Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
"test3" : {
2-
"strings" : {
3-
"empty" : "",
4-
"whitespace" : " spaces ",
5-
"whitespace key" : "whitespace value",
6-
"integer_as_string" : "123",
7-
"float_as_string" : "2.71828",
8-
"special_characters" : "!@#$%^&*()",
9-
"key_containing_:_colon" : "value containing : colon",
10-
"key_containing_{_openbrace" : "value containing { openbrace",
11-
"key_containing_}_closebrace" : "value containing } closebrace",
12-
"key_containing_{}_braces" : "value containing {} braces",
13-
"key_looks_like_object :\" {}" : {
14-
"actual_object" : "value looks like object \", {\"key\" : \"value\"}"
15-
},
16-
"unicode_strings" : {
17-
"emojis" : "😀 🎉 🌟 🚀",
18-
"mixed" : "Hello 👋 World 🌍",
19-
"complex_emoji" : "👨‍👩‍👧‍👦",
20-
"emoji_with_modifiers" : "👍🏽 👨🏻‍💻",
21-
"international" : "Hello, 世界, مرحبًا, โลก, xin chào thế giới, Café"
22-
}
23-
},
24-
"escape_sequences" : {
25-
"newline" : "line1\nline2",
26-
"tab" : "column1\tcolumn2",
27-
"carriage_return" : "return\rline",
28-
"form_feed" : "page1\fpage2",
29-
"backspace" : "text\bmore",
30-
"back_slash" : "back\\slash",
31-
"forward_slash" : "forward\/slash",
32-
"unicode" : "unicode: \u00A9 \u00AE",
33-
"quotes" : "\"quotated text\""
34-
}
2+
"strings" : {
3+
"empty" : "",
4+
"whitespace" : " spaces ",
5+
"whitespace key" : "whitespace value",
6+
"integer_as_string" : "123",
7+
"float_as_string" : "2.71828",
8+
"special_characters" : "!@#$%^&*()",
9+
"key_containing_:_colon" : "value containing : colon",
10+
"key_containing_{_openbrace" : "value containing { openbrace",
11+
"key_containing_}_closebrace" : "value containing } closebrace",
12+
"key_containing_{}_braces" : "value containing {} braces",
13+
"key_looks_like_object :\" {}" : {
14+
"actual_object" : "value looks like object \", {\"key\" : \"value\"}"
15+
},
16+
"unicode_strings" : {
17+
"emojis" : "😀 🎉 🌟 🚀",
18+
"mixed" : "Hello 👋 World 🌍",
19+
"complex_emoji" : "👨‍👩‍👧‍👦",
20+
"emoji_with_modifiers" : "👍🏽 👨🏻‍💻",
21+
"international" : "Hello, 世界, مرحبًا, โลก, xin chào thế giới, Café"
22+
}
23+
},
24+
"escape_sequences" : {
25+
"newline" : "line1\nline2",
26+
"tab" : "column1\tcolumn2",
27+
"carriage_return" : "return\rline",
28+
"form_feed" : "page1\fpage2",
29+
"backspace" : "text\bmore",
30+
"back_slash" : "back\\slash",
31+
"forward_slash" : "forward\/slash",
32+
"unicode" : "unicode: \u00A9 \u00AE",
33+
"quotes" : "\"quotated text\""
34+
}
3535
}

src/tests/java/data/test3/test3.json

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
{
2-
"strings" : {
3-
"empty" : "",
4-
"whitespace" : " spaces ",
5-
"whitespace key" : "whitespace value",
6-
"integer_as_string" : "123",
7-
"float_as_string" : "2.71828",
8-
"special_characters" : "!@#$%^&*()",
9-
"key_containing_:_colon" : "value containing : colon",
10-
"key_containing_{_openbrace" : "value containing { openbrace",
11-
"key_containing_}_closebrace" : "value containing } closebrace",
12-
"key_containing_{}_braces" : "value containing {} braces",
13-
"key_looks_like_object :\" {}" : {"actual_object" : "value looks like object \", {\"key\" : \"value\"}"},
14-
"unicode_strings" : {
15-
"emojis" : "😀 🎉 🌟 🚀",
16-
"mixed" : "Hello 👋 World 🌍",
17-
"complex_emoji" : "👨‍👩‍👧‍👦",
18-
"emoji_with_modifiers" : "👍🏽 👨🏻‍💻",
19-
"international" : "Hello, 世界, مرحبًا, โลก, xin chào thế giới, Café"
20-
}
21-
},
22-
"escape_sequences" : {
23-
"newline" : "line1\nline2",
24-
"tab" : "column1\tcolumn2",
25-
"carriage_return" : "return\rline",
26-
"form_feed" : "page1\fpage2",
27-
"backspace" : "text\bmore",
28-
"back_slash" : "back\\slash",
29-
"forward_slash" : "forward\/slash",
30-
"unicode" : "unicode: \u00A9 \u00AE",
31-
"quotes" : "\"quotated text\""
32-
}
2+
"strings" : {
3+
"empty" : "",
4+
"whitespace" : " spaces ",
5+
"whitespace key" : "whitespace value",
6+
"integer_as_string" : "123",
7+
"float_as_string" : "2.71828",
8+
"special_characters" : "!@#$%^&*()",
9+
"key_containing_:_colon" : "value containing : colon",
10+
"key_containing_{_openbrace" : "value containing { openbrace",
11+
"key_containing_}_closebrace" : "value containing } closebrace",
12+
"key_containing_{}_braces" : "value containing {} braces",
13+
"key_looks_like_object :\" {}" : {"actual_object" : "value looks like object \", {\"key\" : \"value\"}"},
14+
"unicode_strings" : {
15+
"emojis" : "😀 🎉 🌟 🚀",
16+
"mixed" : "Hello 👋 World 🌍",
17+
"complex_emoji" : "👨‍👩‍👧‍👦",
18+
"emoji_with_modifiers" : "👍🏽 👨🏻‍💻",
19+
"international" : "Hello, 世界, مرحبًا, โลก, xin chào thế giới, Café"
20+
}
21+
},
22+
"escape_sequences" : {
23+
"newline" : "line1\nline2",
24+
"tab" : "column1\tcolumn2",
25+
"carriage_return" : "return\rline",
26+
"form_feed" : "page1\fpage2",
27+
"backspace" : "text\bmore",
28+
"back_slash" : "back\\slash",
29+
"forward_slash" : "forward\/slash",
30+
"unicode" : "unicode: \u00A9 \u00AE",
31+
"quotes" : "\"quotated text\""
32+
}
3333
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"test4" : {
2-
"nested_arrays" : [
3-
[1, 2],
4-
[3, [4, 5]],
5-
[6, [7]],
6-
[],
7-
[[]],
8-
[[]]
9-
]
2+
"nested_arrays" : [
3+
[1, 2],
4+
[3, [4, 5]],
5+
[6, [7]],
6+
[],
7+
[[]],
8+
[[]]
9+
]
1010
}

src/tests/java/data/test4/test4.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"nested_arrays" : [
3-
[1, 2],
4-
[3, [4, 5]],
5-
[6,
6-
[7]],
7-
[],
8-
[[]],
9-
[
10-
[]
11-
]
12-
]
2+
"nested_arrays" : [
3+
[1, 2],
4+
[3, [4, 5]],
5+
[6,
6+
[7]],
7+
[],
8+
[[]],
9+
[
10+
[]
11+
]
12+
]
1313
}

0 commit comments

Comments
 (0)