SnapmaticJson: fix indent of empty array and objects
This commit is contained in:
		
							parent
							
								
									7e13f01d6d
								
							
						
					
					
						commit
						a10d259db1
					
				
					 1 changed files with 28 additions and 24 deletions
				
			
		|  | @ -27,14 +27,14 @@ void serializer(std::ostream &os, const boost::json::value &jv, std::string *ind | ||||||
|         indent = &indent_; |         indent = &indent_; | ||||||
|     switch (jv.kind()) { |     switch (jv.kind()) { | ||||||
|     case boost::json::kind::object: { |     case boost::json::kind::object: { | ||||||
|         if (do_indent) { |  | ||||||
|             os << "{\n"; |  | ||||||
|             indent->append(4, ' '); |  | ||||||
|         } |  | ||||||
|         else |  | ||||||
|             os << "{"; |  | ||||||
|         auto const &obj = jv.get_object(); |         auto const &obj = jv.get_object(); | ||||||
|         if (!obj.empty()) { |         if (!obj.empty()) { | ||||||
|  |             if (do_indent) { | ||||||
|  |                 os << "{\n"; | ||||||
|  |                 indent->append(4, ' '); | ||||||
|  |             } | ||||||
|  |             else | ||||||
|  |                 os << "{"; | ||||||
|             auto it = obj.begin(); |             auto it = obj.begin(); | ||||||
|             for (;;) { |             for (;;) { | ||||||
|                 if (do_indent) |                 if (do_indent) | ||||||
|  | @ -49,25 +49,27 @@ void serializer(std::ostream &os, const boost::json::value &jv, std::string *ind | ||||||
|                 else |                 else | ||||||
|                     os << ","; |                     os << ","; | ||||||
|             } |             } | ||||||
|         } |             if (do_indent) { | ||||||
|         if (do_indent) { |                 os << "\n"; | ||||||
|             os << "\n"; |                 indent->resize(indent->size() - 4); | ||||||
|             indent->resize(indent->size() - 4); |                 os << *indent << "}"; | ||||||
|             os << *indent << "}"; |             } | ||||||
|  |             else | ||||||
|  |                 os << "}"; | ||||||
|         } |         } | ||||||
|         else |         else | ||||||
|             os << "}"; |             os << "{}"; | ||||||
|         break; |         break; | ||||||
|     } |     } | ||||||
|     case boost::json::kind::array: { |     case boost::json::kind::array: { | ||||||
|         if (do_indent) { |  | ||||||
|             os << "[\n"; |  | ||||||
|             indent->append(4, ' '); |  | ||||||
|         } |  | ||||||
|         else |  | ||||||
|             os << "["; |  | ||||||
|         auto const &arr = jv.get_array(); |         auto const &arr = jv.get_array(); | ||||||
|         if (!arr.empty()) { |         if (!arr.empty()) { | ||||||
|  |             if (do_indent) { | ||||||
|  |                 os << "[\n"; | ||||||
|  |                 indent->append(4, ' '); | ||||||
|  |             } | ||||||
|  |             else | ||||||
|  |                 os << "["; | ||||||
|             auto it = arr.begin(); |             auto it = arr.begin(); | ||||||
|             for (;;) { |             for (;;) { | ||||||
|                 if (do_indent) |                 if (do_indent) | ||||||
|  | @ -80,14 +82,16 @@ void serializer(std::ostream &os, const boost::json::value &jv, std::string *ind | ||||||
|                 else |                 else | ||||||
|                     os << ","; |                     os << ","; | ||||||
|             } |             } | ||||||
|         } |             if (do_indent) { | ||||||
|         if (do_indent) { |                 os << "\n"; | ||||||
|             os << "\n"; |                 indent->resize(indent->size() - 4); | ||||||
|             indent->resize(indent->size() - 4); |                 os << *indent << "]"; | ||||||
|             os << *indent << "]"; |             } | ||||||
|  |             else | ||||||
|  |                 os << "]"; | ||||||
|         } |         } | ||||||
|         else |         else | ||||||
|             os << "]"; |             os << "[]"; | ||||||
|         break; |         break; | ||||||
|     } |     } | ||||||
|     case boost::json::kind::string: { |     case boost::json::kind::string: { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue