Lines Matching refs:s

118 static int dbuf_insert(DynBuf *s, int pos, int len)  in dbuf_insert()  argument
120 if (dbuf_realloc(s, s->size + len)) in dbuf_insert()
122 memmove(s->buf + pos + len, s->buf + pos, s->size - pos); in dbuf_insert()
123 s->size += len; in dbuf_insert()
228 static int cr_init_char_range(REParseState *s, CharRange *cr, uint32_t c) in cr_init_char_range() argument
237 cr_init(cr, s->mem_opaque, lre_realloc); in cr_init_char_range()
398 static void re_emit_op(REParseState *s, int op) in re_emit_op() argument
400 dbuf_putc(&s->byte_code, op); in re_emit_op()
404 static int re_emit_op_u32(REParseState *s, int op, uint32_t val) in re_emit_op_u32() argument
407 dbuf_putc(&s->byte_code, op); in re_emit_op_u32()
408 pos = s->byte_code.size; in re_emit_op_u32()
409 dbuf_put_u32(&s->byte_code, val); in re_emit_op_u32()
413 static int re_emit_goto(REParseState *s, int op, uint32_t val) in re_emit_goto() argument
416 dbuf_putc(&s->byte_code, op); in re_emit_goto()
417 pos = s->byte_code.size; in re_emit_goto()
418 dbuf_put_u32(&s->byte_code, val - (pos + 4)); in re_emit_goto()
422 static void re_emit_op_u8(REParseState *s, int op, uint32_t val) in re_emit_op_u8() argument
424 dbuf_putc(&s->byte_code, op); in re_emit_op_u8()
425 dbuf_putc(&s->byte_code, val); in re_emit_op_u8()
428 static void re_emit_op_u16(REParseState *s, int op, uint32_t val) in re_emit_op_u16() argument
430 dbuf_putc(&s->byte_code, op); in re_emit_op_u16()
431 dbuf_put_u16(&s->byte_code, val); in re_emit_op_u16()
434 static int __attribute__((format(printf, 2, 3))) re_parse_error(REParseState *s, const char *fmt, .… in re_parse_error() argument
438 vsnprintf(s->u.error_msg, sizeof(s->u.error_msg), fmt, ap); in re_parse_error()
443 static int re_parse_out_of_memory(REParseState *s) in re_parse_out_of_memory() argument
445 return re_parse_error(s, "out of memory"); in re_parse_out_of_memory()
475 static int re_parse_expect(REParseState *s, const uint8_t **pp, int c) in re_parse_expect() argument
480 return re_parse_error(s, "expecting '%c'", c); in re_parse_expect()
616 static int parse_unicode_property(REParseState *s, CharRange *cr, in parse_unicode_property() argument
627 return re_parse_error(s, "expecting '{' after \\p"); in parse_unicode_property()
641 return re_parse_error(s, "unknown unicode property value"); in parse_unicode_property()
647 return re_parse_error(s, "expecting '}'"); in parse_unicode_property()
657 cr_init(cr, s->mem_opaque, lre_realloc); in parse_unicode_property()
662 return re_parse_error(s, "unknown unicode script"); in parse_unicode_property()
667 cr_init(cr, s->mem_opaque, lre_realloc); in parse_unicode_property()
672 return re_parse_error(s, "unknown unicode general category"); in parse_unicode_property()
677 cr_init(cr, s->mem_opaque, lre_realloc); in parse_unicode_property()
695 return re_parse_error(s, "unknown unicode property name"); in parse_unicode_property()
707 return re_parse_out_of_memory(s); in parse_unicode_property()
714 static int get_class_atom(REParseState *s, CharRange *cr, in get_class_atom() argument
727 if (p >= s->buf_end) in get_class_atom()
749 if (cr_init_char_range(s, cr, c)) in get_class_atom()
758 inclass && !s->is_utf16)) { /* Annex B.1.4 */ in get_class_atom()
761 } else if (s->is_utf16) { in get_class_atom()
772 if (s->is_utf16) { in get_class_atom()
773 if (parse_unicode_property(s, cr, &p, (c == 'P'))) in get_class_atom()
782 ret = lre_parse_escape(&p, s->is_utf16 * 2); in get_class_atom()
789 } else if (s->is_utf16) { in get_class_atom()
791 return re_parse_error(s, "invalid escape sequence in regular expression"); in get_class_atom()
801 if (p >= s->buf_end) { in get_class_atom()
803 return re_parse_error(s, "unexpected end"); in get_class_atom()
811 if ((unsigned)c > 0xffff && !s->is_utf16) { in get_class_atom()
813 return re_parse_error(s, "malformed unicode char"); in get_class_atom()
824 static int re_emit_range(REParseState *s, const CharRange *cr) in re_emit_range() argument
831 return re_parse_error(s, "too many ranges"); in re_emit_range()
835 re_emit_op_u32(s, REOP_char32, -1); in re_emit_range()
843 re_emit_op_u16(s, REOP_range, len); in re_emit_range()
845 dbuf_put_u16(&s->byte_code, cr->points[i]); in re_emit_range()
849 dbuf_put_u16(&s->byte_code, high); in re_emit_range()
852 re_emit_op_u16(s, REOP_range32, len); in re_emit_range()
854 dbuf_put_u32(&s->byte_code, cr->points[i]); in re_emit_range()
855 dbuf_put_u32(&s->byte_code, cr->points[i + 1] - 1); in re_emit_range()
862 static int re_parse_char_class(REParseState *s, const uint8_t **pp) in re_parse_char_class() argument
870 cr_init(cr, s->mem_opaque, lre_realloc); in re_parse_char_class()
881 c1 = get_class_atom(s, cr1, &p, TRUE); in re_parse_char_class()
887 if (s->is_utf16) { in re_parse_char_class()
894 c2 = get_class_atom(s, cr1, &p0, TRUE); in re_parse_char_class()
899 if (s->is_utf16) { in re_parse_char_class()
908 re_parse_error(s, "invalid class range"); in re_parse_char_class()
927 if (s->ignore_case) { in re_parse_char_class()
935 if (re_emit_range(s, cr)) in re_parse_char_class()
942 re_parse_out_of_memory(s); in re_parse_char_class()
1128 static int re_parse_captures(REParseState *s, int *phas_named_captures, in re_parse_captures() argument
1137 for (p = s->buf_start; p < s->buf_end; p++) { in re_parse_captures()
1147 s->is_utf16) == 0) { in re_parse_captures()
1162 for (p += 1 + (*p == ']'); p < s->buf_end && *p != ']'; p++) { in re_parse_captures()
1175 static int re_count_captures(REParseState *s) in re_count_captures() argument
1177 if (s->total_capture_count < 0) { in re_count_captures()
1178 s->total_capture_count = re_parse_captures(s, &s->has_named_captures, in re_count_captures()
1181 return s->total_capture_count; in re_count_captures()
1184 static BOOL re_has_named_captures(REParseState *s) in re_has_named_captures() argument
1186 if (s->has_named_captures < 0) in re_has_named_captures()
1187 re_count_captures(s); in re_has_named_captures()
1188 return s->has_named_captures; in re_has_named_captures()
1191 static int find_group_name(REParseState *s, const char *name) in find_group_name() argument
1198 p = (char *)s->group_names.buf; in find_group_name()
1199 buf_end = (char *)s->group_names.buf + s->group_names.size; in find_group_name()
1211 static int re_parse_disjunction(REParseState *s, BOOL is_backward_dir);
1213 static int re_parse_term(REParseState *s, BOOL is_backward_dir) in re_parse_term() argument
1222 p = s->buf_ptr; in re_parse_term()
1227 re_emit_op(s, REOP_line_start); in re_parse_term()
1231 re_emit_op(s, REOP_line_end); in re_parse_term()
1235 last_atom_start = s->byte_code.size; in re_parse_term()
1236 last_capture_count = s->capture_count; in re_parse_term()
1238 re_emit_op(s, REOP_prev); in re_parse_term()
1239 re_emit_op(s, s->dotall ? REOP_any : REOP_dot); in re_parse_term()
1241 re_emit_op(s, REOP_prev); in re_parse_term()
1244 if (s->is_utf16) { in re_parse_term()
1245 return re_parse_error(s, "syntax error"); in re_parse_term()
1268 return re_parse_error(s, "nothing to repeat"); in re_parse_term()
1273 last_atom_start = s->byte_code.size; in re_parse_term()
1274 last_capture_count = s->capture_count; in re_parse_term()
1275 s->buf_ptr = p; in re_parse_term()
1276 if (re_parse_disjunction(s, is_backward_dir)) in re_parse_term()
1278 p = s->buf_ptr; in re_parse_term()
1279 if (re_parse_expect(s, &p, ')')) in re_parse_term()
1296 if (!s->is_utf16 && !is_backward_lookahead) { in re_parse_term()
1297 last_atom_start = s->byte_code.size; in re_parse_term()
1298 last_capture_count = s->capture_count; in re_parse_term()
1300 pos = re_emit_op_u32(s, REOP_lookahead + is_neg, 0); in re_parse_term()
1301 s->buf_ptr = p; in re_parse_term()
1302 if (re_parse_disjunction(s, is_backward_lookahead)) in re_parse_term()
1304 p = s->buf_ptr; in re_parse_term()
1305 if (re_parse_expect(s, &p, ')')) in re_parse_term()
1307 re_emit_op(s, REOP_match); in re_parse_term()
1309 if (dbuf_error(&s->byte_code)) in re_parse_term()
1311 put_u32(s->byte_code.buf + pos, s->byte_code.size - (pos + 4)); in re_parse_term()
1314 if (re_parse_group_name(s->u.tmp_buf, sizeof(s->u.tmp_buf), in re_parse_term()
1315 &p, s->is_utf16)) { in re_parse_term()
1316 return re_parse_error(s, "invalid group name"); in re_parse_term()
1318 if (find_group_name(s, s->u.tmp_buf) > 0) { in re_parse_term()
1319 return re_parse_error(s, "duplicate group name"); in re_parse_term()
1322 dbuf_put(&s->group_names, (uint8_t *)s->u.tmp_buf, in re_parse_term()
1323 strlen(s->u.tmp_buf) + 1); in re_parse_term()
1324 s->has_named_captures = 1; in re_parse_term()
1327 return re_parse_error(s, "invalid group"); in re_parse_term()
1333 dbuf_putc(&s->group_names, 0); in re_parse_term()
1335 if (s->capture_count >= CAPTURE_COUNT_MAX) in re_parse_term()
1336 return re_parse_error(s, "too many captures"); in re_parse_term()
1337 last_atom_start = s->byte_code.size; in re_parse_term()
1338 last_capture_count = s->capture_count; in re_parse_term()
1339 capture_index = s->capture_count++; in re_parse_term()
1340 re_emit_op_u8(s, REOP_save_start + is_backward_dir, in re_parse_term()
1343 s->buf_ptr = p; in re_parse_term()
1344 if (re_parse_disjunction(s, is_backward_dir)) in re_parse_term()
1346 p = s->buf_ptr; in re_parse_term()
1348 re_emit_op_u8(s, REOP_save_start + 1 - is_backward_dir, in re_parse_term()
1351 if (re_parse_expect(s, &p, ')')) in re_parse_term()
1359 re_emit_op(s, REOP_word_boundary + (p[1] != 'b')); in re_parse_term()
1372 if (s->is_utf16 || re_has_named_captures(s)) in re_parse_term()
1373 return re_parse_error(s, "expecting group name"); in re_parse_term()
1378 if (re_parse_group_name(s->u.tmp_buf, sizeof(s->u.tmp_buf), in re_parse_term()
1379 &p1, s->is_utf16)) { in re_parse_term()
1380 if (s->is_utf16 || re_has_named_captures(s)) in re_parse_term()
1381 return re_parse_error(s, "invalid group name"); in re_parse_term()
1385 c = find_group_name(s, s->u.tmp_buf); in re_parse_term()
1389 c = re_parse_captures(s, &dummy_res, s->u.tmp_buf); in re_parse_term()
1391 if (s->is_utf16 || re_has_named_captures(s)) in re_parse_term()
1392 return re_parse_error(s, "group name not defined"); in re_parse_term()
1403 if (s->is_utf16) { in re_parse_term()
1405 return re_parse_error(s, "invalid decimal escape in regular expression"); in re_parse_term()
1422 if (c < 0 || (c >= s->capture_count && c >= re_count_captures(s))) { in re_parse_term()
1423 if (!s->is_utf16) { in re_parse_term()
1441 return re_parse_error(s, "back reference out of range in reguar expression"); in re_parse_term()
1444 last_atom_start = s->byte_code.size; in re_parse_term()
1445 last_capture_count = s->capture_count; in re_parse_term()
1446 re_emit_op_u8(s, REOP_back_reference + is_backward_dir, c); in re_parse_term()
1454 last_atom_start = s->byte_code.size; in re_parse_term()
1455 last_capture_count = s->capture_count; in re_parse_term()
1457 re_emit_op(s, REOP_prev); in re_parse_term()
1458 if (re_parse_char_class(s, &p)) in re_parse_term()
1461 re_emit_op(s, REOP_prev); in re_parse_term()
1465 if (s->is_utf16) in re_parse_term()
1466 return re_parse_error(s, "syntax error"); in re_parse_term()
1470 c = get_class_atom(s, cr, &p, FALSE); in re_parse_term()
1474 last_atom_start = s->byte_code.size; in re_parse_term()
1475 last_capture_count = s->capture_count; in re_parse_term()
1477 re_emit_op(s, REOP_prev); in re_parse_term()
1481 ret = re_emit_range(s, cr); in re_parse_term()
1486 if (s->ignore_case) in re_parse_term()
1487 c = lre_canonicalize(c, s->is_utf16); in re_parse_term()
1489 re_emit_op_u16(s, REOP_char, c); in re_parse_term()
1491 re_emit_op_u32(s, REOP_char32, c); in re_parse_term()
1494 re_emit_op(s, REOP_prev); in re_parse_term()
1523 if (s->is_utf16) in re_parse_term()
1536 return re_parse_error(s, "invalid repetition count"); in re_parse_term()
1542 if (*p != '}' && !s->is_utf16) { in re_parse_term()
1547 if (re_parse_expect(s, &p, '}')) in re_parse_term()
1557 return re_parse_error(s, "nothing to repeat"); in re_parse_term()
1564 if (dbuf_error(&s->byte_code)) in re_parse_term()
1566 len = re_is_simple_quantifier(s->byte_code.buf + last_atom_start, in re_parse_term()
1567 s->byte_code.size - last_atom_start); in re_parse_term()
1569 re_emit_op(s, REOP_match); in re_parse_term()
1571 if (dbuf_insert(&s->byte_code, last_atom_start, 17)) in re_parse_term()
1574 s->byte_code.buf[pos++] = REOP_simple_greedy_quant; in re_parse_term()
1575 put_u32(&s->byte_code.buf[pos], in re_parse_term()
1576 s->byte_code.size - last_atom_start - 17); in re_parse_term()
1578 put_u32(&s->byte_code.buf[pos], quant_min); in re_parse_term()
1580 put_u32(&s->byte_code.buf[pos], quant_max); in re_parse_term()
1582 put_u32(&s->byte_code.buf[pos], len); in re_parse_term()
1588 if (dbuf_error(&s->byte_code)) in re_parse_term()
1590 add_zero_advance_check = (re_check_advance(s->byte_code.buf + last_atom_start, in re_parse_term()
1591s->byte_code.size - last_atom_start) == 0); in re_parse_term()
1598 len = s->byte_code.size - last_atom_start; in re_parse_term()
1602 if (last_capture_count != s->capture_count) { in re_parse_term()
1603 if (dbuf_insert(&s->byte_code, last_atom_start, 3)) in re_parse_term()
1605 s->byte_code.buf[last_atom_start++] = REOP_save_reset; in re_parse_term()
1606 s->byte_code.buf[last_atom_start++] = last_capture_count; in re_parse_term()
1607 s->byte_code.buf[last_atom_start++] = s->capture_count - 1; in re_parse_term()
1610 s->byte_code.size = last_atom_start; in re_parse_term()
1612 if (dbuf_insert(&s->byte_code, last_atom_start, 5)) in re_parse_term()
1614 s->byte_code.buf[last_atom_start] = REOP_split_goto_first + in re_parse_term()
1616 put_u32(s->byte_code.buf + last_atom_start + 1, len); in re_parse_term()
1618 if (dbuf_insert(&s->byte_code, last_atom_start, 5 + add_zero_advance_check)) in re_parse_term()
1620 s->byte_code.buf[last_atom_start] = REOP_split_goto_first + in re_parse_term()
1622 put_u32(s->byte_code.buf + last_atom_start + 1, in re_parse_term()
1629 s->byte_code.buf[last_atom_start + 1 + 4] = REOP_push_char_pos; in re_parse_term()
1630 re_emit_goto(s, REOP_bne_char_pos, last_atom_start); in re_parse_term()
1632 re_emit_goto(s, REOP_goto, last_atom_start); in re_parse_term()
1635 if (dbuf_insert(&s->byte_code, last_atom_start, 10)) in re_parse_term()
1638 s->byte_code.buf[pos++] = REOP_push_i32; in re_parse_term()
1639 put_u32(s->byte_code.buf + pos, quant_max); in re_parse_term()
1641 s->byte_code.buf[pos++] = REOP_split_goto_first + greedy; in re_parse_term()
1642 put_u32(s->byte_code.buf + pos, len + 5); in re_parse_term()
1643 re_emit_goto(s, REOP_loop, last_atom_start + 5); in re_parse_term()
1644 re_emit_op(s, REOP_drop); in re_parse_term()
1648 re_emit_goto(s, REOP_split_next_first - greedy, in re_parse_term()
1654 if (dbuf_insert(&s->byte_code, last_atom_start, 5)) in re_parse_term()
1656 s->byte_code.buf[last_atom_start] = REOP_push_i32; in re_parse_term()
1657 put_u32(s->byte_code.buf + last_atom_start + 1, in re_parse_term()
1660 re_emit_goto(s, REOP_loop, last_atom_start); in re_parse_term()
1661 re_emit_op(s, REOP_drop); in re_parse_term()
1664 pos = s->byte_code.size; in re_parse_term()
1665 re_emit_op_u32(s, REOP_split_goto_first + greedy, in re_parse_term()
1668 re_emit_op(s, REOP_push_char_pos); in re_parse_term()
1670 dbuf_put_self(&s->byte_code, last_atom_start, len); in re_parse_term()
1672 re_emit_goto(s, REOP_bne_char_pos, pos); in re_parse_term()
1674 re_emit_goto(s, REOP_goto, pos); in re_parse_term()
1676 re_emit_op_u32(s, REOP_push_i32, quant_max - quant_min); in re_parse_term()
1677 pos = s->byte_code.size; in re_parse_term()
1678 re_emit_op_u32(s, REOP_split_goto_first + greedy, len + 5); in re_parse_term()
1680 dbuf_put_self(&s->byte_code, last_atom_start, len); in re_parse_term()
1682 re_emit_goto(s, REOP_loop, pos); in re_parse_term()
1683 re_emit_op(s, REOP_drop); in re_parse_term()
1694 s->buf_ptr = p; in re_parse_term()
1697 return re_parse_out_of_memory(s); in re_parse_term()
1700 static int re_parse_alternative(REParseState *s, BOOL is_backward_dir) in re_parse_alternative() argument
1706 start = s->byte_code.size; in re_parse_alternative()
1708 p = s->buf_ptr; in re_parse_alternative()
1709 if (p >= s->buf_end) in re_parse_alternative()
1713 term_start = s->byte_code.size; in re_parse_alternative()
1714 ret = re_parse_term(s, is_backward_dir); in re_parse_alternative()
1720 end = s->byte_code.size; in re_parse_alternative()
1722 if (dbuf_realloc(&s->byte_code, end + term_size)) in re_parse_alternative()
1724 memmove(s->byte_code.buf + start + term_size, in re_parse_alternative()
1725 s->byte_code.buf + start, in re_parse_alternative()
1727 memcpy(s->byte_code.buf + start, s->byte_code.buf + end, in re_parse_alternative()
1734 static int re_parse_disjunction(REParseState *s, BOOL is_backward_dir) in re_parse_disjunction() argument
1738 start = s->byte_code.size; in re_parse_disjunction()
1739 if (re_parse_alternative(s, is_backward_dir)) in re_parse_disjunction()
1741 while (*s->buf_ptr == '|') { in re_parse_disjunction()
1742 s->buf_ptr++; in re_parse_disjunction()
1744 len = s->byte_code.size - start; in re_parse_disjunction()
1747 if (dbuf_insert(&s->byte_code, start, 5)) { in re_parse_disjunction()
1748 return re_parse_out_of_memory(s); in re_parse_disjunction()
1750 s->byte_code.buf[start] = REOP_split_next_first; in re_parse_disjunction()
1751 put_u32(s->byte_code.buf + start + 1, len + 5); in re_parse_disjunction()
1753 pos = re_emit_op_u32(s, REOP_goto, 0); in re_parse_disjunction()
1755 if (re_parse_alternative(s, is_backward_dir)) in re_parse_disjunction()
1759 len = s->byte_code.size - (pos + 4); in re_parse_disjunction()
1760 put_u32(s->byte_code.buf + pos, len); in re_parse_disjunction()
1818 REParseState s_s, *s = &s_s; in lre_compile() local
1822 memset(s, 0, sizeof(*s)); in lre_compile()
1823 s->mem_opaque = opaque; in lre_compile()
1824 s->buf_ptr = (const uint8_t *)buf; in lre_compile()
1825 s->buf_end = s->buf_ptr + buf_len; in lre_compile()
1826 s->buf_start = s->buf_ptr; in lre_compile()
1827 s->re_flags = re_flags; in lre_compile()
1828 s->is_utf16 = ((re_flags & LRE_FLAG_UTF16) != 0); in lre_compile()
1830 s->ignore_case = ((re_flags & LRE_FLAG_IGNORECASE) != 0); in lre_compile()
1831 s->dotall = ((re_flags & LRE_FLAG_DOTALL) != 0); in lre_compile()
1832 s->capture_count = 1; in lre_compile()
1833 s->total_capture_count = -1; in lre_compile()
1834 s->has_named_captures = -1; in lre_compile()
1836 dbuf_init2(&s->byte_code, opaque, lre_realloc); in lre_compile()
1837 dbuf_init2(&s->group_names, opaque, lre_realloc); in lre_compile()
1839 dbuf_putc(&s->byte_code, re_flags); /* first element is the flags */ in lre_compile()
1840 dbuf_putc(&s->byte_code, 0); /* second element is the number of captures */ in lre_compile()
1841 dbuf_putc(&s->byte_code, 0); /* stack size */ in lre_compile()
1842 dbuf_put_u32(&s->byte_code, 0); /* bytecode length */ in lre_compile()
1849 re_emit_op_u32(s, REOP_split_goto_first, 1 + 5); in lre_compile()
1850 re_emit_op(s, REOP_any); in lre_compile()
1851 re_emit_op_u32(s, REOP_goto, -(5 + 1 + 5)); in lre_compile()
1853 re_emit_op_u8(s, REOP_save_start, 0); in lre_compile()
1855 if (re_parse_disjunction(s, FALSE)) { in lre_compile()
1857 dbuf_free(&s->byte_code); in lre_compile()
1858 dbuf_free(&s->group_names); in lre_compile()
1859 pstrcpy(error_msg, error_msg_size, s->u.error_msg); in lre_compile()
1864 re_emit_op_u8(s, REOP_save_end, 0); in lre_compile()
1866 re_emit_op(s, REOP_match); in lre_compile()
1868 if (*s->buf_ptr != '\0') { in lre_compile()
1869 re_parse_error(s, "extraneous characters at the end"); in lre_compile()
1873 if (dbuf_error(&s->byte_code)) { in lre_compile()
1874 re_parse_out_of_memory(s); in lre_compile()
1878 stack_size = compute_stack_size(s->byte_code.buf, s->byte_code.size); in lre_compile()
1880 re_parse_error(s, "too many imbricated quantifiers"); in lre_compile()
1884 s->byte_code.buf[RE_HEADER_CAPTURE_COUNT] = s->capture_count; in lre_compile()
1885 s->byte_code.buf[RE_HEADER_STACK_SIZE] = stack_size; in lre_compile()
1886 put_u32(s->byte_code.buf + 3, s->byte_code.size - RE_HEADER_LEN); in lre_compile()
1889 if (s->group_names.size > (s->capture_count - 1)) { in lre_compile()
1890 dbuf_put(&s->byte_code, s->group_names.buf, s->group_names.size); in lre_compile()
1891 s->byte_code.buf[RE_HEADER_FLAGS] |= LRE_FLAG_NAMED_GROUPS; in lre_compile()
1893 dbuf_free(&s->group_names); in lre_compile()
1896 lre_dump_bytecode(s->byte_code.buf, s->byte_code.size); in lre_compile()
1900 *plen = s->byte_code.size; in lre_compile()
1901 return s->byte_code.buf; in lre_compile()
2043 static int push_state(REExecContext *s, in push_state() argument
2054 if (unlikely((s->state_stack_len + 1) > s->state_stack_size)) { in push_state()
2056 new_size = s->state_stack_size * 3 / 2; in push_state()
2059 new_stack = lre_realloc(s->opaque, s->state_stack, new_size * s->state_size); in push_state()
2062 s->state_stack_size = new_size; in push_state()
2063 s->state_stack = new_stack; in push_state()
2065 rs = (REExecState *)(s->state_stack + s->state_stack_len * s->state_size); in push_state()
2066 s->state_stack_len++; in push_state()
2072 n = 2 * s->capture_count; in push_state()
2082 static intptr_t lre_exec_backtrack(REExecContext *s, uint8_t **capture, in lre_exec_backtrack() argument
2092 cbuf_type = s->cbuf_type; in lre_exec_backtrack()
2093 cbuf_end = s->cbuf_end; in lre_exec_backtrack()
2112 if (s->state_stack_len == 0) in lre_exec_backtrack()
2114 rs = (REExecState *)(s->state_stack + in lre_exec_backtrack()
2115 (s->state_stack_len - 1) * s->state_size); in lre_exec_backtrack()
2120 sizeof(capture[0]) * 2 * s->capture_count); in lre_exec_backtrack()
2125 memcpy(stack, rs->buf + 2 * s->capture_count, in lre_exec_backtrack()
2127 s->state_stack_len--; in lre_exec_backtrack()
2134 sizeof(capture[0]) * 2 * s->capture_count); in lre_exec_backtrack()
2136 memcpy(stack, rs->buf + 2 * s->capture_count, in lre_exec_backtrack()
2143 PREV_CHAR(cptr, s->cbuf); in lre_exec_backtrack()
2149 s->state_stack_len--; in lre_exec_backtrack()
2164 s->state_stack_len--; in lre_exec_backtrack()
2179 if (s->ignore_case) { in lre_exec_backtrack()
2180 c = lre_canonicalize(c, s->is_utf16); in lre_exec_backtrack()
2198 ret = push_state(s, capture, stack, stack_len, in lre_exec_backtrack()
2208 ret = push_state(s, capture, stack, stack_len, in lre_exec_backtrack()
2221 if (cptr == s->cbuf) in lre_exec_backtrack()
2223 if (!s->multi_line) in lre_exec_backtrack()
2225 PEEK_PREV_CHAR(c, cptr, s->cbuf); in lre_exec_backtrack()
2232 if (!s->multi_line) in lre_exec_backtrack()
2253 assert(val < s->capture_count); in lre_exec_backtrack()
2262 assert(val2 < s->capture_count); in lre_exec_backtrack()
2299 if (cptr == s->cbuf) { in lre_exec_backtrack()
2302 PEEK_PREV_CHAR(c, cptr, s->cbuf); in lre_exec_backtrack()
2323 if (val >= s->capture_count) in lre_exec_backtrack()
2336 if (s->ignore_case) { in lre_exec_backtrack()
2337 c1 = lre_canonicalize(c1, s->is_utf16); in lre_exec_backtrack()
2338 c2 = lre_canonicalize(c2, s->is_utf16); in lre_exec_backtrack()
2346 if (cptr == s->cbuf) in lre_exec_backtrack()
2349 GET_PREV_CHAR(c2, cptr, s->cbuf); in lre_exec_backtrack()
2350 if (s->ignore_case) { in lre_exec_backtrack()
2351 c1 = lre_canonicalize(c1, s->is_utf16); in lre_exec_backtrack()
2352 c2 = lre_canonicalize(c2, s->is_utf16); in lre_exec_backtrack()
2370 if (s->ignore_case) { in lre_exec_backtrack()
2371 c = lre_canonicalize(c, s->is_utf16); in lre_exec_backtrack()
2410 if (s->ignore_case) { in lre_exec_backtrack()
2411 c = lre_canonicalize(c, s->is_utf16); in lre_exec_backtrack()
2439 if (cptr == s->cbuf) in lre_exec_backtrack()
2441 PREV_CHAR(cptr, s->cbuf); in lre_exec_backtrack()
2459 res = lre_exec_backtrack(s, capture, stack, stack_len, in lre_exec_backtrack()
2474 ret = push_state(s, capture, stack, stack_len, in lre_exec_backtrack()
2496 REExecContext s_s, *s = &s_s; in lre_exec() local
2501 s->multi_line = (re_flags & LRE_FLAG_MULTILINE) != 0; in lre_exec()
2502 s->ignore_case = (re_flags & LRE_FLAG_IGNORECASE) != 0; in lre_exec()
2503 s->is_utf16 = (re_flags & LRE_FLAG_UTF16) != 0; in lre_exec()
2504 s->capture_count = bc_buf[RE_HEADER_CAPTURE_COUNT]; in lre_exec()
2505 s->stack_size_max = bc_buf[RE_HEADER_STACK_SIZE]; in lre_exec()
2506 s->cbuf = cbuf; in lre_exec()
2507 s->cbuf_end = cbuf + (clen << cbuf_type); in lre_exec()
2508 s->cbuf_type = cbuf_type; in lre_exec()
2509 if (s->cbuf_type == 1 && s->is_utf16) in lre_exec()
2510 s->cbuf_type = 2; in lre_exec()
2511 s->opaque = opaque; in lre_exec()
2513 s->state_size = sizeof(REExecState) + in lre_exec()
2514 s->capture_count * sizeof(capture[0]) * 2 + in lre_exec()
2515 s->stack_size_max * sizeof(stack_buf[0]); in lre_exec()
2516 s->state_stack = NULL; in lre_exec()
2517 s->state_stack_len = 0; in lre_exec()
2518 s->state_stack_size = 0; in lre_exec()
2520 for(i = 0; i < s->capture_count * 2; i++) in lre_exec()
2522 alloca_size = s->stack_size_max * sizeof(stack_buf[0]); in lre_exec()
2524 ret = lre_exec_backtrack(s, capture, stack_buf, 0, bc_buf + RE_HEADER_LEN, in lre_exec()
2526 lre_realloc(s->opaque, s->state_stack, 0); in lre_exec()