Commit | Line | Data |
---|---|---|
d812d165 | 1 | /* inline_invlist.c |
81e983c1 KW |
2 | * |
3 | * Copyright (C) 2012 by Larry Wall and others | |
4 | * | |
5 | * You may distribute under the terms of either the GNU General Public | |
6 | * License or the Artistic License, as specified in the README file. | |
81e983c1 KW |
7 | */ |
8 | ||
9 | #if defined(PERL_IN_UTF8_C) || defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_REGEXEC_C) | |
10 | ||
9e7f4f43 KW |
11 | /* An element is in an inversion list iff its index is even numbered: 0, 2, 4, |
12 | * etc */ | |
13 | #define ELEMENT_RANGE_MATCHES_INVLIST(i) (! ((i) & 1)) | |
14 | #define PREV_RANGE_MATCHES_INVLIST(i) (! ELEMENT_RANGE_MATCHES_INVLIST(i)) | |
15 | ||
4c60406d KW |
16 | /* This converts to/from our UVs to what the SV code is expecting: bytes. */ |
17 | #define TO_INTERNAL_SIZE(x) ((x) * sizeof(UV)) | |
18 | #define FROM_INTERNAL_SIZE(x) ((x)/ sizeof(UV)) | |
19 | ||
20 | PERL_STATIC_INLINE bool* | |
21 | S_get_invlist_offset_addr(pTHX_ SV* invlist) | |
9e7f4f43 | 22 | { |
4c60406d KW |
23 | /* Return the address of the field that says whether the inversion list is |
24 | * offset (it contains 1) or not (contains 0) */ | |
9e7f4f43 | 25 | |
4c60406d | 26 | PERL_ARGS_ASSERT_GET_INVLIST_OFFSET_ADDR; |
9e7f4f43 | 27 | |
4c60406d | 28 | return &(((XINVLIST*) SvANY(invlist))->is_offset); |
9e7f4f43 KW |
29 | } |
30 | ||
31 | PERL_STATIC_INLINE UV | |
32 | S__invlist_len(pTHX_ SV* const invlist) | |
33 | { | |
34 | /* Returns the current number of elements stored in the inversion list's | |
35 | * array */ | |
36 | ||
37 | PERL_ARGS_ASSERT__INVLIST_LEN; | |
38 | ||
4c60406d KW |
39 | return (SvCUR(invlist) == 0) |
40 | ? 0 | |
41 | : FROM_INTERNAL_SIZE(SvCUR(invlist)) - *get_invlist_offset_addr(invlist); | |
9e7f4f43 KW |
42 | } |
43 | ||
44 | PERL_STATIC_INLINE bool | |
45 | S__invlist_contains_cp(pTHX_ SV* const invlist, const UV cp) | |
46 | { | |
47 | /* Does <invlist> contain code point <cp> as part of the set? */ | |
48 | ||
49 | IV index = _invlist_search(invlist, cp); | |
50 | ||
51 | PERL_ARGS_ASSERT__INVLIST_CONTAINS_CP; | |
52 | ||
53 | return index >= 0 && ELEMENT_RANGE_MATCHES_INVLIST(index); | |
54 | } | |
55 | ||
4c60406d KW |
56 | # if defined(PERL_IN_UTF8_C) || defined(PERL_IN_REGEXEC_C) |
57 | ||
58 | /* These symbols are only needed later in regcomp.c */ | |
59 | # undef TO_INTERNAL_SIZE | |
60 | # undef FROM_INTERNAL_SIZE | |
61 | # endif | |
62 | ||
81e983c1 | 63 | #endif |