mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 02:02:45 +00:00 
			
		
		
		
	 1682f0b760
			
		
	
	
		1682f0b760
		
	
	
	
	
		
			
			SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
		
			
				
	
	
		
			46 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2020, The SerenityOS developers.
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <AK/JsonObject.h>
 | |
| #include <AK/JsonPath.h>
 | |
| #include <AK/JsonValue.h>
 | |
| 
 | |
| namespace AK {
 | |
| 
 | |
| JsonPathElement JsonPathElement::any_array_element { Kind::AnyIndex };
 | |
| JsonPathElement JsonPathElement::any_object_element { Kind::AnyKey };
 | |
| 
 | |
| JsonValue JsonPath::resolve(const JsonValue& top_root) const
 | |
| {
 | |
|     auto root = top_root;
 | |
|     for (auto& element : *this) {
 | |
|         switch (element.kind()) {
 | |
|         case JsonPathElement::Kind::Key:
 | |
|             root = JsonValue { root.as_object().get(element.key()) };
 | |
|             break;
 | |
|         case JsonPathElement::Kind::Index:
 | |
|             root = JsonValue { root.as_array().at(element.index()) };
 | |
|             break;
 | |
|         default:
 | |
|             VERIFY_NOT_REACHED();
 | |
|         }
 | |
|     }
 | |
|     return root;
 | |
| }
 | |
| 
 | |
| String JsonPath::to_string() const
 | |
| {
 | |
|     StringBuilder builder;
 | |
|     builder.append("{ .");
 | |
|     for (auto& el : *this) {
 | |
|         builder.append(" > ");
 | |
|         builder.append(el.to_string());
 | |
|     }
 | |
|     builder.append(" }");
 | |
|     return builder.to_string();
 | |
| }
 | |
| 
 | |
| }
 |