@@ -19,85 +19,60 @@ void JsonFormatter::StartObject(_In_ Console& console, _In_opt_ const wstring& n
1919{
2020 if (m_requiresSep.top ())
2121 {
22- console.WriteLine (L" ," );
22+ console.Write (L" ," );
2323 }
2424 else
2525 {
2626 // Do not write new line when starting subsequent object immediately after previous object.
2727 if (m_objects.empty ())
2828 {
29- console. WriteLine () ;
29+ m_requiresSep. top () = true ;
3030 }
31-
32- m_requiresSep.top () = true ;
3331 }
3432
3533 m_requiresSep.push (false );
36- m_objects.push (name);
3734
38- if (! name.empty ())
35+ if (name.empty ())
3936 {
40- console.WriteLine (L" %ls\" %ls\" : {" , m_padding.c_str (), name.c_str ());
37+ m_objects.push (JsonScope (m_padding, JsonScope::empty, true ));
38+ m_objects.top ().WriteStart (console);
4139 }
4240 else
4341 {
44- console. WriteLine ( L" %ls{ " , m_padding. c_str ( ));
42+ m_objects. push ( JsonScope (m_padding, name ));
4543 }
4644
4745 Push ();
4846}
4947
5048void JsonFormatter::WriteProperty (_In_ Console& console, _In_ const wstring& name, _In_ const wstring& value)
5149{
52- if (m_requiresSep.top ())
53- {
54- console.WriteLine (L" ," );
55- }
56- else
57- {
58- m_requiresSep.top () = true ;
59- }
50+ StartProperty (console);
6051
6152 auto escaped = replace_all (value, L" \\ " , L" \\\\ " );
62- console.Write (L" %ls\" %ls\" : \" %ls\" " , m_padding.c_str (), name.c_str (), escaped.c_str ());
53+ console.Write (L" \n %ls\" %ls\" : \" %ls\" " , m_padding.c_str (), name.c_str (), escaped.c_str ());
6354}
6455
6556void JsonFormatter::WriteProperty (_In_ Console& console, _In_ const wstring& name, _In_ bool value)
6657{
67- if (m_requiresSep.top ())
68- {
69- console.WriteLine (L" ," );
70- }
71- else
72- {
73- m_requiresSep.top () = true ;
74- }
75-
76- console.Write (L" %ls\" %ls\" : %ls" , m_padding.c_str (), name.c_str (), (value ? L" true" : L" false" ));
58+ StartProperty (console);
59+ console.Write (L" \n %ls\" %ls\" : %ls" , m_padding.c_str (), name.c_str (), (value ? L" true" : L" false" ));
7760}
7861
7962void JsonFormatter::WriteProperty (_In_ Console& console, _In_ const wstring& name, _In_ long long value)
8063{
81- if (m_requiresSep.top ())
82- {
83- console.WriteLine (L" ," );
84- }
85- else
86- {
87- m_requiresSep.top () = true ;
88- }
89-
90- console.Write (L" %ls\" %ls\" : %d" , m_padding.c_str (), name.c_str (), value);
64+ StartProperty (console);
65+ console.Write (L" \n %ls\" %ls\" : %d" , m_padding.c_str (), name.c_str (), value);
9166}
9267
9368void JsonFormatter::EndObject (_In_ Console& console)
9469{
9570 Pop ();
9671
9772 m_requiresSep.pop ();
98- m_objects.pop ();
9973
100- console.Write (L" \n %ls}" , m_padding.c_str ());
74+ m_objects.top ().WriteEnd (console);
75+ m_objects.pop ();
10176}
10277
10378void JsonFormatter::EndArray (_In_ Console& console)
@@ -123,3 +98,17 @@ wstring JsonFormatter::FormatDate(_In_ const FILETIME& value)
12398{
12499 return FormatDateISO8601 (value);
125100}
101+
102+ void JsonFormatter::StartProperty (_In_ Console& console)
103+ {
104+ m_objects.top ().WriteStart (console);
105+
106+ if (m_requiresSep.top ())
107+ {
108+ console.Write (L" ," );
109+ }
110+ else
111+ {
112+ m_requiresSep.top () = true ;
113+ }
114+ }
0 commit comments