| 
									
										
										
										
											2022-04-12 11:14:12 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2020-2021, the SerenityOS developers. | 
					
						
							| 
									
										
										
										
											2023-02-14 19:04:12 +00:00
										 |  |  |  * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org> | 
					
						
							| 
									
										
										
										
											2022-04-12 11:14:12 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <LibWeb/CSS/Parser/ComponentValue.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-12 12:13:10 +01:00
										 |  |  | namespace Web::CSS::Parser { | 
					
						
							| 
									
										
										
										
											2022-04-12 11:14:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | ComponentValue::ComponentValue(Token token) | 
					
						
							|  |  |  |     : m_value(token) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-10-11 11:17:10 +01:00
										 |  |  | ComponentValue::ComponentValue(Function&& function) | 
					
						
							| 
									
										
										
										
											2022-04-12 11:14:12 +01:00
										 |  |  |     : m_value(function) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-10-11 11:17:10 +01:00
										 |  |  | ComponentValue::ComponentValue(SimpleBlock&& block) | 
					
						
							| 
									
										
										
										
											2022-04-12 11:14:12 +01:00
										 |  |  |     : m_value(block) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ComponentValue::~ComponentValue() = default; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-05 19:42:28 +01:00
										 |  |  | bool ComponentValue::is_function(StringView name) const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-10-11 11:17:10 +01:00
										 |  |  |     return is_function() && function().name.equals_ignoring_ascii_case(name); | 
					
						
							| 
									
										
										
										
											2023-09-05 19:42:28 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ComponentValue::is_ident(StringView ident) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return is(Token::Type::Ident) && token().ident().equals_ignoring_ascii_case(ident); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-22 13:00:28 +01:00
										 |  |  | String ComponentValue::to_string() const | 
					
						
							| 
									
										
										
										
											2022-04-12 11:14:12 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     return m_value.visit( | 
					
						
							| 
									
										
										
										
											2023-02-14 19:04:12 +00:00
										 |  |  |         [](Token const& token) { return token.to_string(); }, | 
					
						
							| 
									
										
										
										
											2024-10-11 11:17:10 +01:00
										 |  |  |         [](SimpleBlock const& block) { return block.to_string(); }, | 
					
						
							|  |  |  |         [](Function const& function) { return function.to_string(); }); | 
					
						
							| 
									
										
										
										
											2022-04-12 11:14:12 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-22 13:00:28 +01:00
										 |  |  | String ComponentValue::to_debug_string() const | 
					
						
							| 
									
										
										
										
											2022-04-12 11:14:12 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     return m_value.visit( | 
					
						
							| 
									
										
										
										
											2023-08-22 13:00:28 +01:00
										 |  |  |         [](Token const& token) { | 
					
						
							|  |  |  |             return MUST(String::formatted("Token: {}", token.to_debug_string())); | 
					
						
							| 
									
										
										
										
											2022-04-12 11:14:12 +01:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2024-10-11 11:17:10 +01:00
										 |  |  |         [](SimpleBlock const& block) { | 
					
						
							|  |  |  |             return MUST(String::formatted("Block: {}", block.to_string())); | 
					
						
							| 
									
										
										
										
											2022-04-12 11:14:12 +01:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2024-10-11 11:17:10 +01:00
										 |  |  |         [](Function const& function) { | 
					
						
							|  |  |  |             return MUST(String::formatted("Function: {}", function.to_string())); | 
					
						
							| 
									
										
										
										
											2022-04-12 11:14:12 +01:00
										 |  |  |         }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |