| 243 | private: |
| 244 | |
| 245 | void flatten_and_destroy() noexcept |
| 246 | { |
| 247 | while (!elements_.empty()) |
| 248 | { |
| 249 | value_type current = std::move(elements_.back()); |
| 250 | elements_.pop_back(); |
| 251 | switch (current.storage_kind()) |
| 252 | { |
| 253 | case json_storage_kind::array: |
| 254 | { |
| 255 | for (auto&& item : current.array_range()) |
| 256 | { |
| 257 | if ((item.storage_kind() == json_storage_kind::array || item.storage_kind() == json_storage_kind::object) |
| 258 | && !item.empty()) // non-empty object or array |
| 259 | { |
| 260 | elements_.push_back(std::move(item)); |
| 261 | } |
| 262 | } |
| 263 | current.clear(); |
| 264 | break; |
| 265 | } |
| 266 | case json_storage_kind::object: |
| 267 | { |
| 268 | for (auto&& kv : current.object_range()) |
| 269 | { |
| 270 | if ((kv.value().storage_kind() == json_storage_kind::array || kv.value().storage_kind() == json_storage_kind::object) |
| 271 | && !kv.value().empty()) // non-empty object or array |
| 272 | { |
| 273 | elements_.push_back(std::move(kv.value())); |
| 274 | } |
| 275 | } |
| 276 | current.clear(); |
| 277 | break; |
| 278 | } |
| 279 | default: |
| 280 | break; |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | }; |
| 285 | |
| 286 | } // namespace jsoncons |