MCPcopy Create free account
hub / github.com/bytedance/Fastbot_Android / flatten

Function flatten

native/thirdpart/json/json.hpp:10958–11008  ·  view source on GitHub ↗

! @param[in] reference_string the reference string to the current value @param[in] value the value to consider @param[in,out] result the result object to insert values to @note Empty objects or arrays are flattened to `null`. */

Source from the content-addressed store, hash-verified

10956 @note Empty objects or arrays are flattened to `null`.
10957 */
10958 static void flatten(const std::string& reference_string,
10959 const BasicJsonType& value,
10960 BasicJsonType& result)
10961 {
10962 switch (value.type())
10963 {
10964 case detail::value_t::array:
10965 {
10966 if (value.m_value.array->empty())
10967 {
10968 // flatten empty array as null
10969 result[reference_string] = nullptr;
10970 }
10971 else
10972 {
10973 // iterate array and use index as reference string
10974 for (std::size_t i = 0; i < value.m_value.array->size(); ++i)
10975 {
10976 flatten(reference_string + "/" + std::to_string(i),
10977 value.m_value.array->operator[](i), result);
10978 }
10979 }
10980 break;
10981 }
10982
10983 case detail::value_t::object:
10984 {
10985 if (value.m_value.object->empty())
10986 {
10987 // flatten empty object as null
10988 result[reference_string] = nullptr;
10989 }
10990 else
10991 {
10992 // iterate object and use keys as reference string
10993 for (const auto& element : *value.m_value.object)
10994 {
10995 flatten(reference_string + "/" + escape(element.first), element.second, result);
10996 }
10997 }
10998 break;
10999 }
11000
11001 default:
11002 {
11003 // add primitive value with its reference string
11004 result[reference_string] = value;
11005 break;
11006 }
11007 }
11008 }
11009
11010 /*!
11011 @param[in] value flattened JSON

Callers

nothing calls this directly

Calls 5

to_stringFunction · 0.85
escapeFunction · 0.85
emptyMethod · 0.80
sizeMethod · 0.45
operator[]Method · 0.45

Tested by

no test coverage detected