3 * Copyright (C) 2012 by Larry Wall and others
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.
9 #if defined(PERL_IN_UTF8_C) || defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_REGEXEC_C)
11 /* An element is in an inversion list iff its index is even numbered: 0, 2, 4,
13 #define ELEMENT_RANGE_MATCHES_INVLIST(i) (! ((i) & 1))
14 #define PREV_RANGE_MATCHES_INVLIST(i) (! ELEMENT_RANGE_MATCHES_INVLIST(i))
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))
20 PERL_STATIC_INLINE bool*
21 S_get_invlist_offset_addr(pTHX_ SV* invlist)
23 /* Return the address of the field that says whether the inversion list is
24 * offset (it contains 1) or not (contains 0) */
26 PERL_ARGS_ASSERT_GET_INVLIST_OFFSET_ADDR;
28 assert(SvTYPE(invlist) == SVt_INVLIST);
30 return &(((XINVLIST*) SvANY(invlist))->is_offset);
34 S__invlist_len(pTHX_ SV* const invlist)
36 /* Returns the current number of elements stored in the inversion list's
39 PERL_ARGS_ASSERT__INVLIST_LEN;
41 assert(SvTYPE(invlist) == SVt_INVLIST);
43 return (SvCUR(invlist) == 0)
45 : FROM_INTERNAL_SIZE(SvCUR(invlist)) - *get_invlist_offset_addr(invlist);
48 PERL_STATIC_INLINE bool
49 S__invlist_contains_cp(pTHX_ SV* const invlist, const UV cp)
51 /* Does <invlist> contain code point <cp> as part of the set? */
53 IV index = _invlist_search(invlist, cp);
55 PERL_ARGS_ASSERT__INVLIST_CONTAINS_CP;
57 return index >= 0 && ELEMENT_RANGE_MATCHES_INVLIST(index);
60 # if defined(PERL_IN_UTF8_C) || defined(PERL_IN_REGEXEC_C)
62 /* These symbols are only needed later in regcomp.c */
63 # undef TO_INTERNAL_SIZE
64 # undef FROM_INTERNAL_SIZE