1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 00:37:35 +00:00

LibWeb: Add comparison operators to CSS numeric types (except Length)

This is to make it easier to bounds-check their values during parsing.
Length is left out because many length units are relative to the
context in which they are used, and so we cannot easily compare `10px`
and `1em`, for example.
This commit is contained in:
Sam Atkins 2023-05-31 14:55:18 +01:00 committed by Andreas Kling
parent 06617a982e
commit fbfce2e73e
6 changed files with 69 additions and 3 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2022-2023, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -82,6 +82,15 @@ public:
return m_type == other.m_type && m_value == other.m_value;
}
int operator<=>(Number const& other) const
{
if (m_value < other.m_value)
return -1;
if (m_value > other.m_value)
return 1;
return 0;
}
private:
double m_value { 0 };
Type m_type;