MCPcopy Create free account
hub / github.com/Illation/ETEngine / WriteArray

Method WriteArray

Engine/source/EtCore/FileSystem/Json/JsonWriter.cpp:244–336  ·  view source on GitHub ↗

--------------------------------- Writer::WriteArray Write an array

Source from the content-addressed store, hash-verified

242// Write an array
243//
244bool Writer::WriteArray(Array const* const jArray)
245{
246 if (jArray == nullptr)
247 {
248 LOG("JSON::Writer::WriteArray > Failed to write json array to string, array object was null", LogLevel::Warning);
249 return false;
250 }
251
252 // begin the array
253 m_JsonString += s_BeginArray;
254
255 // if the array is empty, no further processing is needed
256 if (jArray->value.size() == 0u)
257 {
258 m_JsonString += s_EndArray;
259 return true;
260 }
261
262 // if this is an array of complex types and we are not writing a compact json file write a new line per element
263 bool writeNlPerElement = false;
264 if (!m_Compact)
265 {
266 auto const foundComplexTypeIt = std::find_if(jArray->value.cbegin(), jArray->value.cend(), [](Value const* const val)
267 {
268 return val->GetType() == ValueType::JSON_Array || val->GetType() == ValueType::JSON_Object || val->GetType() == ValueType::JSON_String;
269 });
270
271 if (foundComplexTypeIt != jArray->value.cend())
272 {
273 writeNlPerElement = true;
274
275 m_JsonString += s_NewLine;
276 ++m_IndentationLevel;
277 }
278 }
279
280 // write the values
281 bool allValuesSucceeded = true;
282 size_t idx = 0;
283 while (true)
284 {
285 if (writeNlPerElement)
286 {
287 WriteIndentations();
288 }
289
290 // Write the pair
291 if (!WriteValue(jArray->value[idx]))
292 {
293 LOG("JSON::Writer::WriteArray > Failed to write value at index #" + std::to_string(idx) + std::string("!"), LogLevel::Warning);
294 allValuesSucceeded = false;
295 }
296
297 // check if there will be a successor
298 ++idx;
299 bool isNotLast = idx < jArray->value.size();
300
301 // write delimiter

Callers

nothing calls this directly

Calls 1

GetTypeMethod · 0.45

Tested by

no test coverage detected