Skip to content

Sync to lexbor/lexbor@0eac579f #18882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ext/lexbor/lexbor/core/sbst.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ extern "C" {
# define LXB_NONSTRING
#endif


typedef struct {
lxb_char_t key;

Expand Down
158 changes: 60 additions & 98 deletions ext/lexbor/lexbor/css/syntax/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,6 @@ lxb_css_syntax_state_consume_numeric(lxb_css_syntax_tokenizer_t *tkz,
const lxb_char_t *data,
const lxb_char_t *end);

static const lxb_char_t *
lxb_css_syntax_state_decimal(lxb_css_syntax_tokenizer_t *tkz,
lxb_css_syntax_token_t *token,
const lxb_char_t *data, const lxb_char_t *end,
lxb_char_t *buf, lxb_char_t *buf_p,
const lxb_char_t *buf_end);

static const lxb_char_t *
lxb_css_syntax_state_consume_numeric_name_start(lxb_css_syntax_tokenizer_t *tkz,
lxb_css_syntax_token_t *token,
Expand Down Expand Up @@ -706,8 +699,6 @@ lxb_css_syntax_state_plus(lxb_css_syntax_tokenizer_t *tkz,
lxb_css_syntax_token_t *token,
const lxb_char_t *data, const lxb_char_t *end)
{
lxb_char_t buf[128];

/* Skip U+002B PLUS SIGN (+). */
data += 1;

Expand All @@ -732,8 +723,8 @@ lxb_css_syntax_state_plus(lxb_css_syntax_tokenizer_t *tkz,
/* U+0030 DIGIT ZERO (0) and U+0039 DIGIT NINE (9) */
if (*data >= 0x30 && *data <= 0x39) {
lxb_css_syntax_token_number(token)->have_sign = true;
return lxb_css_syntax_state_decimal(tkz, token, data, end,
buf, buf, buf + sizeof(buf));
return lxb_css_syntax_state_consume_numeric(tkz, token,
data - 1, end);
}

data -= 1;
Expand Down Expand Up @@ -804,6 +795,7 @@ lxb_css_syntax_state_full_stop(lxb_css_syntax_tokenizer_t *tkz,
const lxb_char_t *data, const lxb_char_t *end)
{
if (lxb_css_syntax_state_start_number(data, end)) {
lxb_css_syntax_token_number(token)->have_sign = false;
return lxb_css_syntax_state_consume_numeric(tkz, token, data, end);
}

Expand Down Expand Up @@ -935,37 +927,26 @@ lxb_css_syntax_state_rc_bracket(lxb_css_syntax_tokenizer_t *tkz, lxb_css_syntax_
* Numeric
*/
lxb_inline void
lxb_css_syntax_consume_numeric_set_int(lxb_css_syntax_tokenizer_t *tkz,
lxb_css_syntax_token_t *token,
const lxb_char_t *start, const lxb_char_t *end)
{
double num = lexbor_strtod_internal(start, (end - start), 0);

token->type = LXB_CSS_SYNTAX_TOKEN_NUMBER;

lxb_css_syntax_token_number(token)->is_float = false;
lxb_css_syntax_token_number(token)->num = num;
}

lxb_inline void
lxb_css_syntax_consume_numeric_set_float(lxb_css_syntax_tokenizer_t *tkz,
lxb_css_syntax_token_t *token,
const lxb_char_t *start, const lxb_char_t *end,
bool e_is_negative, int exponent, int e_digit)
lxb_css_syntax_consume_numeric_set(lxb_css_syntax_tokenizer_t *tkz,
lxb_css_syntax_token_t *token,
const lxb_char_t *start, const lxb_char_t *end,
bool is_float, bool e_is_negative,
int exponent, int e_digit)
{
if (e_is_negative) {
exponent -= e_digit;
exponent = e_digit - exponent;
exponent = -exponent;
}
else {
exponent += e_digit;
exponent = e_digit + exponent;
}

double num = lexbor_strtod_internal(start, (end - start), exponent);

token->type = LXB_CSS_SYNTAX_TOKEN_NUMBER;

lxb_css_syntax_token_number(token)->is_float = is_float;
lxb_css_syntax_token_number(token)->num = num;
lxb_css_syntax_token_number(token)->is_float = true;
}

const lxb_char_t *
Expand All @@ -985,95 +966,77 @@ lxb_css_syntax_state_consume_numeric(lxb_css_syntax_tokenizer_t *tkz,
const lxb_char_t *data,
const lxb_char_t *end)
{
lxb_char_t *buf_p;
const lxb_char_t *buf_end;
bool e_is_negative, is_float;
int exponent, e_digit;
lxb_char_t ch, *buf_p;
const lxb_char_t *begin, *buf_end;
lxb_css_syntax_token_t *t_str;
lxb_css_syntax_token_string_t *str;
lxb_char_t buf[128];

buf_p = buf;
buf_end = buf + sizeof(buf);

do {
/* U+0030 DIGIT ZERO (0) and U+0039 DIGIT NINE (9) */
if (*data < 0x30 || *data > 0x39) {
break;
}
str = lxb_css_syntax_token_dimension_string(token);
t_str = (lxb_css_syntax_token_t *) (void *) str;

/* U+0030 DIGIT ZERO (0) and U+0039 DIGIT NINE (9) */
while (*data >= 0x30 && *data <= 0x39) {
if (buf_p != buf_end) {
*buf_p++ = *data;
}

data += 1;

if (data >= end) {
lxb_css_syntax_consume_numeric_set_int(tkz, token, buf, buf_p);
lxb_css_syntax_consume_numeric_set(tkz, token, buf, buf_p,
false, false, 0, 0);
return data;
}
}
while (true);

/* U+002E FULL STOP (.) */
if (*data != 0x2E) {
lxb_css_syntax_consume_numeric_set_int(tkz, token, buf, buf_p);

return lxb_css_syntax_state_consume_numeric_name_start(tkz, token,
data, end);
}

data += 1;
exponent = 0;
is_float = false;

if (data >= end || *data < 0x30 || *data > 0x39) {
lxb_css_syntax_consume_numeric_set_int(tkz, token, buf, buf_p);
return data - 1;
}

return lxb_css_syntax_state_decimal(tkz, token, data, end,
buf, buf_p, buf_end);
}
/* U+002E FULL STOP (.) */
if (*data == 0x2E) {
data += 1;

static const lxb_char_t *
lxb_css_syntax_state_decimal(lxb_css_syntax_tokenizer_t *tkz,
lxb_css_syntax_token_t *token,
const lxb_char_t *data, const lxb_char_t *end,
lxb_char_t *buf, lxb_char_t *buf_p,
const lxb_char_t *buf_end)
{
bool e_is_negative;
int exponent, e_digit;
lxb_char_t ch;
const lxb_char_t *begin;
lxb_css_syntax_token_t *t_str;
lxb_css_syntax_token_string_t *str;
/* U+0030 DIGIT ZERO (0) and U+0039 DIGIT NINE (9) */
if (data >= end || *data < 0x30 || *data > 0x39) {
lxb_css_syntax_consume_numeric_set(tkz, token, buf, buf_p,
false, false, 0, 0);
return data - 1;
}

begin = data;
begin = buf_p;

str = lxb_css_syntax_token_dimension_string(token);
t_str = (lxb_css_syntax_token_t *) (void *) str;
/* U+0030 DIGIT ZERO (0) and U+0039 DIGIT NINE (9) */
do {
if (buf_p != buf_end) {
*buf_p++ = *data;
}

/* U+0030 DIGIT ZERO (0) and U+0039 DIGIT NINE (9) */
do {
if (buf_p != buf_end) {
*buf_p++ = *data;
data += 1;
}
while (data < end && *data >= 0x30 && *data <= 0x39);

data += 1;
exponent = -(int) (buf_p - begin);
is_float = true;

if (data >= end) {
exponent = 0 - (int) (data - begin);

lxb_css_syntax_consume_numeric_set_float(tkz, token, buf,
buf_p, 0, exponent, 0);
lxb_css_syntax_consume_numeric_set(tkz, token, buf, buf_p,
true, false, exponent, 0);
return data;
}
}
while (*data >= 0x30 && *data <= 0x39);

ch = *data;
exponent = 0 - (int) (data - begin);

/* U+0045 Latin Capital Letter (E) or U+0065 Latin Small Letter (e) */
if (ch != 0x45 && ch != 0x65) {
lxb_css_syntax_consume_numeric_set_float(tkz, token, buf,
buf_p, 0, exponent, 0);
lxb_css_syntax_consume_numeric_set(tkz, token, buf, buf_p,
is_float, false, exponent, 0);

return lxb_css_syntax_state_consume_numeric_name_start(tkz, token,
data, end);
Expand All @@ -1087,11 +1050,10 @@ lxb_css_syntax_state_decimal(lxb_css_syntax_tokenizer_t *tkz,
data -= 1;

lxb_css_syntax_token_base(t_str)->length = 1;

lxb_css_syntax_buffer_append_m(tkz, data, 1);

lxb_css_syntax_consume_numeric_set_float(tkz, token, buf,
buf_p, 0, exponent, 0);
lxb_css_syntax_consume_numeric_set(tkz, token, buf, buf_p,
is_float, false, exponent, 0);

token->type = LXB_CSS_SYNTAX_TOKEN_DIMENSION;

Expand Down Expand Up @@ -1122,8 +1084,8 @@ lxb_css_syntax_state_decimal(lxb_css_syntax_tokenizer_t *tkz,
data -= 1;
}

lxb_css_syntax_consume_numeric_set_float(tkz, token, buf,
buf_p, 0, exponent, 0);
lxb_css_syntax_consume_numeric_set(tkz, token, buf, buf_p,
is_float, false, exponent, 0);

token->type = LXB_CSS_SYNTAX_TOKEN_DIMENSION;

Expand All @@ -1135,7 +1097,6 @@ lxb_css_syntax_state_decimal(lxb_css_syntax_tokenizer_t *tkz,
return begin;
}

begin = data;
e_digit = 0;

/* U+0030 DIGIT ZERO (0) and U+0039 DIGIT NINE (9) */
Expand All @@ -1145,16 +1106,17 @@ lxb_css_syntax_state_decimal(lxb_css_syntax_tokenizer_t *tkz,
data += 1;

if (data >= end) {
lxb_css_syntax_consume_numeric_set_float(tkz, token, buf, buf_p,
e_is_negative, exponent,
e_digit);
return data;
lxb_css_syntax_consume_numeric_set(tkz, token, buf, buf_p,
true, e_is_negative,
exponent, e_digit);
return data;
}
}
while(*data >= 0x30 && *data <= 0x39);

lxb_css_syntax_consume_numeric_set_float(tkz, token, buf, buf_p,
e_is_negative, exponent, e_digit);
lxb_css_syntax_consume_numeric_set(tkz, token, buf, buf_p,
true, e_is_negative,
exponent, e_digit);

return lxb_css_syntax_state_consume_numeric_name_start(tkz, token,
data, end);
Expand Down
2 changes: 1 addition & 1 deletion ext/lexbor/lexbor/css/unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ LXB_API const lxb_css_data_t *
lxb_css_unit_relative_by_name(const lxb_char_t *name, size_t length);

LXB_API const lxb_css_data_t *
lxb_css_unit_angel_by_name(const lxb_char_t *name, size_t length);
lxb_css_unit_angle_by_name(const lxb_char_t *name, size_t length);

LXB_API const lxb_css_data_t *
lxb_css_unit_frequency_by_name(const lxb_char_t *name, size_t length);
Expand Down
6 changes: 3 additions & 3 deletions ext/lexbor/lexbor/css/unit/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ typedef enum {
lxb_css_unit_relative_t;

typedef enum {
LXB_CSS_UNIT_ANGEL__BEGIN = 0x0016,
LXB_CSS_UNIT_ANGLE__BEGIN = 0x0016,
LXB_CSS_UNIT_DEG = 0x0016,
LXB_CSS_UNIT_GRAD = 0x0017,
LXB_CSS_UNIT_RAD = 0x0018,
LXB_CSS_UNIT_TURN = 0x0019,
LXB_CSS_UNIT_ANGEL__LAST_ENTRY = 0x001a
LXB_CSS_UNIT_ANGLE__LAST_ENTRY = 0x001a
}
lxb_css_unit_angel_t;
lxb_css_unit_angle_t;

typedef enum {
LXB_CSS_UNIT_FREQUENCY__BEGIN = 0x001a,
Expand Down
2 changes: 1 addition & 1 deletion ext/lexbor/lexbor/css/unit/res.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ static const lexbor_shs_entry_t lxb_css_unit_relative_shs[64] =
{NULL, NULL, 0, 0}
};

static const lexbor_shs_entry_t lxb_css_unit_angel_shs[7] =
static const lexbor_shs_entry_t lxb_css_unit_angle_shs[7] =
{
{NULL, NULL, 6, 0},
{"turn", (void *) &lxb_css_unit_data[LXB_CSS_UNIT_TURN], 4, 0},
Expand Down
2 changes: 1 addition & 1 deletion ext/lexbor/lexbor/css/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ lxb_css_value_length_percentage_type_t;
typedef struct {
double num;
bool is_float;
lxb_css_unit_angel_t unit;
lxb_css_unit_angle_t unit;
}
lxb_css_value_angle_t;

Expand Down