aboutsummaryrefslogtreecommitdiff
path: root/src/cssparser.cc
diff options
context:
space:
mode:
authorRodrigo Arias Mallo <rodarima@gmail.com>2024-05-31 19:53:14 +0200
committerRodrigo Arias Mallo <rodarima@gmail.com>2024-10-05 09:46:55 +0200
commitac56aa678cfe1666b60821f342ccb7b3d3fa7a0d (patch)
tree2887de1a5a21c8550e4bd52ea8867c18a5e2bac9 /src/cssparser.cc
parentee32215fc1937e8a5e3c26b646ca8563e8de92e9 (diff)
Define CssLength as struct instead of int
The int type doesn't have a fixed size, and is only guarantee to hold 16 bits. The current implementation assumes a size of at least 32 bits, an uses three bits to encode the type of information stored in the rest. To add more types of lengths we would need to take more bits from the value itself. A simpler approach is just to use a enumeration to take care of the type of length and a union to encapsulate the different lengths values.
Diffstat (limited to 'src/cssparser.cc')
-rw-r--r--src/cssparser.cc9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/cssparser.cc b/src/cssparser.cc
index 1e5c5731..0fb240f2 100644
--- a/src/cssparser.cc
+++ b/src/cssparser.cc
@@ -3,6 +3,7 @@
*
* Copyright 2004 Sebastian Geerken <sgeerken@dillo.org>
* Copyright 2008-2009 Johannes Hofmann <Johannes.Hofmann@gmx.de>
+ * Copyright 2024 Rodrigo Arias Mallo <rodarima@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -988,7 +989,7 @@ bool CssParser::parseValue(CssPropertyName prop,
(type == CSS_TYPE_LENGTH_PERCENTAGE_NUMBER || fval == 0.0))
ret = true;
- val->intVal = CSS_CREATE_LENGTH(fval, lentype);
+ val->lenVal = CSS_CREATE_LENGTH(fval, lentype);
}
break;
@@ -1091,7 +1092,7 @@ bool CssParser::parseValue(CssPropertyName prop,
// possibilities are tested in parallel.
bool h[2], v[2];
- int pos[2];
+ CssLength pos[2];
h[0] = v[0] = h[1] = v[1] = false;
// First: collect values in pos[0] and pos[1], and determine whether
@@ -1134,10 +1135,10 @@ bool CssParser::parseValue(CssPropertyName prop,
// We can assume <length> or <percentage> here ...
CssPropertyValue valTmp;
if (parseValue(prop, CSS_TYPE_LENGTH_PERCENTAGE, &valTmp)) {
- pos[i] = valTmp.intVal;
+ pos[i] = valTmp.lenVal;
ret = true;
} else if (parseValue(prop, CSS_TYPE_SIGNED_LENGTH, &valTmp)) {
- pos[i] = valTmp.intVal;
+ pos[i] = valTmp.lenVal;
ret = true;
} else
// ... but something may still fail.