| 
									
										
										
										
											2022-04-07 17:37:33 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:55:40 +00:00
										 |  |  |  * Copyright (c) 2022-2023, Sam Atkins <atkinssj@serenityos.org> | 
					
						
							| 
									
										
										
										
											2022-04-07 17:37:33 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/Assertions.h>
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:55:40 +00:00
										 |  |  | #include <AK/String.h>
 | 
					
						
							| 
									
										
										
										
											2022-04-07 17:37:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::CSS { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // https://www.w3.org/TR/css-syntax-3/#urange-syntax
 | 
					
						
							|  |  |  | class UnicodeRange { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     UnicodeRange(u32 min_code_point, u32 max_code_point) | 
					
						
							|  |  |  |         : m_min_code_point(min_code_point) | 
					
						
							|  |  |  |         , m_max_code_point(max_code_point) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         VERIFY(min_code_point <= max_code_point); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     u32 min_code_point() const { return m_min_code_point; } | 
					
						
							|  |  |  |     u32 max_code_point() const { return m_max_code_point; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bool contains(u32 code_point) const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return m_min_code_point <= code_point && code_point <= m_max_code_point; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:55:40 +00:00
										 |  |  |     ErrorOr<String> to_string() const | 
					
						
							| 
									
										
										
										
											2022-04-07 17:37:33 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         if (m_min_code_point == m_max_code_point) | 
					
						
							| 
									
										
										
										
											2023-02-14 19:55:40 +00:00
										 |  |  |             return String::formatted("U+{:x}", m_min_code_point); | 
					
						
							|  |  |  |         return String::formatted("U+{:x}-{:x}", m_min_code_point, m_max_code_point); | 
					
						
							| 
									
										
										
										
											2022-04-07 17:37:33 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     u32 m_min_code_point; | 
					
						
							|  |  |  |     u32 m_max_code_point; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |