Skip to content

Update Lexbor #16288

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
Oct 8, 2024
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
29 changes: 29 additions & 0 deletions ext/dom/lexbor/lexbor/core/swar.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,35 @@ lexbor_swar_seek4(const lxb_char_t *data, const lxb_char_t *end,
return data;
}

lxb_inline const lxb_char_t *
lexbor_swar_seek3(const lxb_char_t *data, const lxb_char_t *end,
lxb_char_t c1, lxb_char_t c2, lxb_char_t c3)
{
size_t bytes, matches, t1, t2, t3;

if (LEXBOR_SWAR_IS_LITTLE_ENDIAN) {
while (data + sizeof(size_t) <= end) {
memcpy(&bytes, data, sizeof(size_t));

t1 = bytes ^ LEXBOR_SWAR_REPEAT(c1);
t2 = bytes ^ LEXBOR_SWAR_REPEAT(c2);
t3 = bytes ^ LEXBOR_SWAR_REPEAT(c3);
matches = LEXBOR_SWAR_HAS_ZERO(t1) | LEXBOR_SWAR_HAS_ZERO(t2)
| LEXBOR_SWAR_HAS_ZERO(t3);

if (matches) {
data += ((((matches - 1) & LEXBOR_SWAR_ONES) * LEXBOR_SWAR_ONES)
>> (sizeof(size_t) * 8 - 8)) - 1;
break;
} else {
data += sizeof(size_t);
}
}
}

return data;
}


#ifdef __cplusplus
} /* extern "C" */
Expand Down
2 changes: 1 addition & 1 deletion ext/dom/lexbor/lexbor/encoding/big5.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 Alexander Borisov
* Copyright (C) 2024 Alexander Borisov
*
* Author: Alexander Borisov <[email protected]>
*/
Expand Down
71 changes: 71 additions & 0 deletions ext/dom/lexbor/lexbor/encoding/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -2955,6 +2955,77 @@ lxb_encoding_decode_valid_utf_8_single(const lxb_char_t **data,
return cp;
}

lxb_codepoint_t
lxb_encoding_decode_valid_utf_8_single_reverse(const lxb_char_t **end,
const lxb_char_t *begin)
{
lxb_codepoint_t cp;
const lxb_char_t *p = *end;

while (p > begin) {
p -= 1;

if (*p < 0x80){
cp = (lxb_codepoint_t) *p;

(*end) = p;
return cp;
}
else if ((*p & 0xe0) == 0xc0) {
/* 110xxxxx 10xxxxxx */

if (*end - p < 2) {
*end = p;
return LXB_ENCODING_DECODE_ERROR;
}

cp = (p[0] ^ (0xC0 & p[0])) << 6;
cp |= (p[1] ^ (0x80 & p[1]));

(*end) = p;
return cp;
}
else if ((*p & 0xf0) == 0xe0) {
/* 1110xxxx 10xxxxxx 10xxxxxx */

if (*end - p < 3) {
*end = p;
return LXB_ENCODING_DECODE_ERROR;
}

cp = (p[0] ^ (0xE0 & p[0])) << 12;
cp |= (p[1] ^ (0x80 & p[1])) << 6;
cp |= (p[2] ^ (0x80 & p[2]));

(*end) = p;
return cp;
}
else if ((*p & 0xf8) == 0xf0) {
/* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */

if (*end - p < 4) {
*end = p;
return LXB_ENCODING_DECODE_ERROR;
}

cp = (p[0] ^ (0xF0 & p[0])) << 18;
cp |= (p[1] ^ (0x80 & p[1])) << 12;
cp |= (p[2] ^ (0x80 & p[2])) << 6;
cp |= (p[3] ^ (0x80 & p[3]));

(*end) = p;
return cp;
}
else if (*end - p >= 4) {
break;
}
}

*end = p;

return LXB_ENCODING_DECODE_ERROR;
}

uint8_t
lxb_encoding_decode_utf_8_length(lxb_char_t data)
{
Expand Down
4 changes: 4 additions & 0 deletions ext/dom/lexbor/lexbor/encoding/decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ LXB_API lxb_codepoint_t
lxb_encoding_decode_valid_utf_8_single(const lxb_char_t **data,
const lxb_char_t *end);

LXB_API lxb_codepoint_t
lxb_encoding_decode_valid_utf_8_single_reverse(const lxb_char_t **end,
const lxb_char_t *begin);

LXB_API uint8_t
lxb_encoding_decode_utf_8_length(lxb_char_t data);

Expand Down
2 changes: 1 addition & 1 deletion ext/dom/lexbor/lexbor/encoding/euc_kr.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 Alexander Borisov
* Copyright (C) 2024 Alexander Borisov
*
* Author: Alexander Borisov <[email protected]>
*/
Expand Down
Loading