[libcroco] cr-tknzr: Handle signed units
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libcroco] cr-tknzr: Handle signed units
- Date: Tue, 16 Oct 2012 18:06:31 +0000 (UTC)
commit 1c3a1096307e68113f3f22dd93bd3c2421c81953
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Tue Oct 16 12:35:54 2012 -0400
cr-tknzr: Handle signed units
Parse something like '-20px' correctly.
https://bugzilla.gnome.org/show_bug.cgi?id=686239
src/cr-tknzr.c | 24 ++++++++++++++++++++++--
tests/test-inputs/test1.css | 4 +++-
tests/test-output-refs/test1.css.out | 4 +++-
3 files changed, 28 insertions(+), 4 deletions(-)
---
diff --git a/src/cr-tknzr.c b/src/cr-tknzr.c
index 64924ed..6512c98 100644
--- a/src/cr-tknzr.c
+++ b/src/cr-tknzr.c
@@ -1465,6 +1465,12 @@ cr_tknzr_parse_important (CRTknzr * a_this,
* param a_num out parameter. The parsed number.
* return CR_OK upon successfull completion,
*an error code otherwise.
+ *
+ *The CSS specification says that numbers may be
+ *preceeded by '+' or '-' to indicate the sign.
+ *Technically, the "num" construction as defined
+ *by the tokenizer doesn't allow this, but we parse
+ *it here for simplicity.
*/
static enum CRStatus
cr_tknzr_parse_num (CRTknzr * a_this,
@@ -1480,13 +1486,22 @@ cr_tknzr_parse_num (CRTknzr * a_this,
gdouble numerator, denominator = 1;
CRInputPos init_pos;
CRParsingLocation location = {0} ;
+ int sign = 1;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->input,
CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
- READ_NEXT_CHAR (a_this, &cur_char);
+ READ_NEXT_CHAR (a_this, &cur_char);
+
+ if (cur_char == '+' || cur_char == '-') {
+ if (cur_char == '-') {
+ sign = -1;
+ }
+ READ_NEXT_CHAR (a_this, &cur_char);
+ }
+
if (IS_NUM (cur_char)) {
numerator = (cur_char - '0');
parsing_dec = FALSE;
@@ -1539,7 +1554,7 @@ cr_tknzr_parse_num (CRTknzr * a_this,
*Now, set the output param values.
*/
if (status == CR_OK) {
- gdouble val = numerator / denominator;
+ gdouble val = (numerator / denominator) * sign;
if (*a_num == NULL) {
*a_num = cr_num_new_with_val (val, val_type);
@@ -2160,6 +2175,8 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
&str->location) ;
}
goto done;
+ } else {
+ goto parse_number;
}
}
break;
@@ -2353,6 +2370,9 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
case '8':
case '9':
case '.':
+ case '+':
+ /* '-' case is handled separately above for --> comments */
+ parse_number:
{
CRNum *num = NULL;
diff --git a/tests/test-inputs/test1.css b/tests/test-inputs/test1.css
index d432405..b03c8a4 100644
--- a/tests/test-inputs/test1.css
+++ b/tests/test-inputs/test1.css
@@ -309,6 +309,8 @@ border-left-width : 1px;
.postbody { line-height: 18px}
-
+.magic {
+ margin-left: -20px;
+}
/* END of formIE.css */
diff --git a/tests/test-output-refs/test1.css.out b/tests/test-output-refs/test1.css.out
index d432405..b03c8a4 100644
--- a/tests/test-output-refs/test1.css.out
+++ b/tests/test-output-refs/test1.css.out
@@ -309,6 +309,8 @@ border-left-width : 1px;
.postbody { line-height: 18px}
-
+.magic {
+ margin-left: -20px;
+}
/* END of formIE.css */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]