mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:22:43 +00:00 
			
		
		
		
	 57dc179b1f
			
		
	
	
		57dc179b1f
		
	
	
	
	
		
			
			This will make it easier to support both string types at the same time while we convert code, and tracking down remaining uses. One big exception is Value::to_string() in LibJS, where the name is dictated by the ToString AO.
		
			
				
	
	
		
			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(JsonValue const& top_root) const
 | |
| {
 | |
|     auto root = top_root;
 | |
|     for (auto const& 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;
 | |
| }
 | |
| 
 | |
| DeprecatedString JsonPath::to_deprecated_string() const
 | |
| {
 | |
|     StringBuilder builder;
 | |
|     builder.append("{ ."sv);
 | |
|     for (auto const& el : *this) {
 | |
|         builder.append("sv > "sv);
 | |
|         builder.append(el.to_deprecated_string());
 | |
|     }
 | |
|     builder.append("sv }"sv);
 | |
|     return builder.to_deprecated_string();
 | |
| }
 | |
| 
 | |
| }
 |