blob: 0a255e37f9a168dfbc17f337c3f1ff8c4d049faa [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/* Extended regular expression matching and search library.
2 Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
20
21#ifndef _REGEX_INTERNAL_H
22#define _REGEX_INTERNAL_H 1
23
24#include <assert.h>
25#include <ctype.h>
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29
30#if defined HAVE_LANGINFO_H || defined HAVE_LANGINFO_CODESET
31# include <langinfo.h>
32#endif
33#if defined HAVE_LOCALE_H
34# include <locale.h>
35#endif
36#if defined HAVE_WCHAR_H
37# include <wchar.h>
38#endif
39#if defined HAVE_WCTYPE_H
40# include <wctype.h>
41#endif
42#if defined HAVE_STDBOOL_H
43# include <stdbool.h>
44#endif
45#if defined HAVE_STDINT_H
46# include <stdint.h>
47#endif
48
49#ifdef __UCLIBC_HAS_THREADS__
50#include <bits/libc-lock.h>
51#else
52#define __libc_lock_define(CLASS, NAME)
53#define __libc_lock_init(NAME) do { } while (0)
54#define __libc_lock_lock(NAME) do { } while (0)
55#define __libc_lock_unlock(NAME) do { } while (0)
56#endif
57
58#undef gettext
59#undef gettext_noop
60#define gettext(msgid) (msgid)
61#define gettext_noop(String) String
62
63#if (defined MB_CUR_MAX && HAVE_LOCALE_H && HAVE_WCTYPE_H && HAVE_WCHAR_H && HAVE_WCRTOMB && HAVE_MBRTOWC && HAVE_WCSCOLL)
64# define RE_ENABLE_I18N
65#endif
66
67#if __GNUC__ >= 3
68/* uclibc: lean towards smaller size a bit:
69 * OFF: # define BE(expr, val) __builtin_expect (expr, val) */
70# define BE(expr, val) (expr)
71#else
72# define BE(expr, val) (expr)
73# define inline
74#endif
75
76/* Number of single byte character. */
77#define SBC_MAX 256
78
79#define COLL_ELEM_LEN_MAX 8
80
81/* The character which represents newline. */
82#define NEWLINE_CHAR '\n'
83#define WIDE_NEWLINE_CHAR L'\n'
84
85#ifdef __GNUC__
86# define __attribute(arg) __attribute__ (arg)
87#else
88# define __attribute(arg)
89#endif
90
91/* An integer used to represent a set of bits. It must be unsigned,
92 and must be at least as wide as unsigned int. */
93typedef unsigned long int bitset_word_t;
94/* All bits set in a bitset_word_t. */
95#define BITSET_WORD_MAX ULONG_MAX
96/* Number of bits in a bitset_word_t. */
97#define BITSET_WORD_BITS (sizeof (bitset_word_t) * CHAR_BIT)
98/* Number of bitset_word_t in a bit_set. */
99#define BITSET_WORDS (SBC_MAX / BITSET_WORD_BITS)
100typedef bitset_word_t bitset_t[BITSET_WORDS];
101typedef bitset_word_t *re_bitset_ptr_t;
102typedef const bitset_word_t *re_const_bitset_ptr_t;
103
104#define bitset_set(set,i) \
105 (set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS)
106#define bitset_clear(set,i) \
107 (set[i / BITSET_WORD_BITS] &= ~((bitset_word_t) 1 << i % BITSET_WORD_BITS))
108#define bitset_contain(set,i) \
109 (set[i / BITSET_WORD_BITS] & ((bitset_word_t) 1 << i % BITSET_WORD_BITS))
110#define bitset_empty(set) memset (set, '\0', sizeof (bitset_t))
111#define bitset_set_all(set) memset (set, '\xff', sizeof (bitset_t))
112#define bitset_copy(dest,src) memcpy (dest, src, sizeof (bitset_t))
113
114#define PREV_WORD_CONSTRAINT 0x0001
115#define PREV_NOTWORD_CONSTRAINT 0x0002
116#define NEXT_WORD_CONSTRAINT 0x0004
117#define NEXT_NOTWORD_CONSTRAINT 0x0008
118#define PREV_NEWLINE_CONSTRAINT 0x0010
119#define NEXT_NEWLINE_CONSTRAINT 0x0020
120#define PREV_BEGBUF_CONSTRAINT 0x0040
121#define NEXT_ENDBUF_CONSTRAINT 0x0080
122#define WORD_DELIM_CONSTRAINT 0x0100
123#define NOT_WORD_DELIM_CONSTRAINT 0x0200
124
125typedef enum
126{
127 INSIDE_WORD = PREV_WORD_CONSTRAINT | NEXT_WORD_CONSTRAINT,
128 WORD_FIRST = PREV_NOTWORD_CONSTRAINT | NEXT_WORD_CONSTRAINT,
129 WORD_LAST = PREV_WORD_CONSTRAINT | NEXT_NOTWORD_CONSTRAINT,
130 INSIDE_NOTWORD = PREV_NOTWORD_CONSTRAINT | NEXT_NOTWORD_CONSTRAINT,
131 LINE_FIRST = PREV_NEWLINE_CONSTRAINT,
132 LINE_LAST = NEXT_NEWLINE_CONSTRAINT,
133 BUF_FIRST = PREV_BEGBUF_CONSTRAINT,
134 BUF_LAST = NEXT_ENDBUF_CONSTRAINT,
135 WORD_DELIM = WORD_DELIM_CONSTRAINT,
136 NOT_WORD_DELIM = NOT_WORD_DELIM_CONSTRAINT
137} re_context_type;
138
139typedef struct
140{
141 int alloc;
142 int nelem;
143 int *elems;
144} re_node_set;
145
146typedef enum
147{
148 NON_TYPE = 0,
149
150 /* Node type, These are used by token, node, tree. */
151 CHARACTER = 1,
152 END_OF_RE = 2,
153 SIMPLE_BRACKET = 3,
154 OP_BACK_REF = 4,
155 OP_PERIOD = 5,
156#ifdef RE_ENABLE_I18N
157 COMPLEX_BRACKET = 6,
158 OP_UTF8_PERIOD = 7,
159#endif /* RE_ENABLE_I18N */
160
161 /* We define EPSILON_BIT as a macro so that OP_OPEN_SUBEXP is used
162 when the debugger shows values of this enum type. */
163#define EPSILON_BIT 8
164 OP_OPEN_SUBEXP = EPSILON_BIT | 0,
165 OP_CLOSE_SUBEXP = EPSILON_BIT | 1,
166 OP_ALT = EPSILON_BIT | 2,
167 OP_DUP_ASTERISK = EPSILON_BIT | 3,
168 ANCHOR = EPSILON_BIT | 4,
169
170 /* Tree type, these are used only by tree. */
171 CONCAT = 16,
172 SUBEXP = 17,
173
174 /* Token type, these are used only by token. */
175 OP_DUP_PLUS = 18,
176 OP_DUP_QUESTION,
177 OP_OPEN_BRACKET,
178 OP_CLOSE_BRACKET,
179 OP_CHARSET_RANGE,
180 OP_OPEN_DUP_NUM,
181 OP_CLOSE_DUP_NUM,
182 OP_NON_MATCH_LIST,
183 OP_OPEN_COLL_ELEM,
184 OP_CLOSE_COLL_ELEM,
185 OP_OPEN_EQUIV_CLASS,
186 OP_CLOSE_EQUIV_CLASS,
187 OP_OPEN_CHAR_CLASS,
188 OP_CLOSE_CHAR_CLASS,
189 OP_WORD,
190 OP_NOTWORD,
191 OP_SPACE,
192 OP_NOTSPACE,
193 BACK_SLASH
194
195} re_token_type_t;
196
197#ifdef RE_ENABLE_I18N
198typedef struct
199{
200 /* Multibyte characters. */
201 wchar_t *mbchars;
202
203 /* Collating symbols. */
204# if 0
205 int32_t *coll_syms;
206# endif
207
208 /* Equivalence classes. */
209# if 0
210 int32_t *equiv_classes;
211# endif
212
213 /* Range expressions. */
214# if 0
215 uint32_t *range_starts;
216 uint32_t *range_ends;
217# else
218 wchar_t *range_starts;
219 wchar_t *range_ends;
220# endif
221
222 /* Character classes. */
223 wctype_t *char_classes;
224
225 /* If this character set is the non-matching list. */
226 unsigned int non_match : 1;
227
228 /* # of multibyte characters. */
229 int nmbchars;
230
231 /* # of collating symbols. */
232 int ncoll_syms;
233
234 /* # of equivalence classes. */
235 int nequiv_classes;
236
237 /* # of range expressions. */
238 int nranges;
239
240 /* # of character classes. */
241 int nchar_classes;
242} re_charset_t;
243#endif /* RE_ENABLE_I18N */
244
245typedef struct
246{
247 union
248 {
249 unsigned char c; /* for CHARACTER */
250 re_bitset_ptr_t sbcset; /* for SIMPLE_BRACKET */
251#ifdef RE_ENABLE_I18N
252 re_charset_t *mbcset; /* for COMPLEX_BRACKET */
253#endif /* RE_ENABLE_I18N */
254 int idx; /* for BACK_REF */
255 re_context_type ctx_type; /* for ANCHOR */
256 } opr;
257#if __GNUC__ >= 2
258 re_token_type_t type : 8;
259#else
260 re_token_type_t type;
261#endif
262 unsigned int constraint : 10; /* context constraint */
263 unsigned int duplicated : 1;
264 unsigned int opt_subexp : 1;
265#ifdef RE_ENABLE_I18N
266 unsigned int accept_mb : 1;
267 /* These 2 bits can be moved into the union if needed (e.g. if running out
268 of bits; move opr.c to opr.c.c and move the flags to opr.c.flags). */
269 unsigned int mb_partial : 1;
270#endif
271 unsigned int word_char : 1;
272} re_token_t;
273
274#define IS_EPSILON_NODE(type) ((type) & EPSILON_BIT)
275
276struct re_string_t
277{
278 /* Indicate the raw buffer which is the original string passed as an
279 argument of regexec(), re_search(), etc.. */
280 const unsigned char *raw_mbs;
281 /* Store the multibyte string. In case of "case insensitive mode" like
282 REG_ICASE, upper cases of the string are stored, otherwise MBS points
283 the same address that RAW_MBS points. */
284 unsigned char *mbs;
285#ifdef RE_ENABLE_I18N
286 /* Store the wide character string which is corresponding to MBS. */
287 wint_t *wcs;
288 int *offsets;
289 mbstate_t cur_state;
290#endif
291 /* Index in RAW_MBS. Each character mbs[i] corresponds to
292 raw_mbs[raw_mbs_idx + i]. */
293 int raw_mbs_idx;
294 /* The length of the valid characters in the buffers. */
295 int valid_len;
296 /* The corresponding number of bytes in raw_mbs array. */
297 int valid_raw_len;
298 /* The length of the buffers MBS and WCS. */
299 int bufs_len;
300 /* The index in MBS, which is updated by re_string_fetch_byte. */
301 int cur_idx;
302 /* length of RAW_MBS array. */
303 int raw_len;
304 /* This is RAW_LEN - RAW_MBS_IDX + VALID_LEN - VALID_RAW_LEN. */
305 int len;
306 /* End of the buffer may be shorter than its length in the cases such
307 as re_match_2, re_search_2. Then, we use STOP for end of the buffer
308 instead of LEN. */
309 int raw_stop;
310 /* This is RAW_STOP - RAW_MBS_IDX adjusted through OFFSETS. */
311 int stop;
312
313 /* The context of mbs[0]. We store the context independently, since
314 the context of mbs[0] may be different from raw_mbs[0], which is
315 the beginning of the input string. */
316 unsigned int tip_context;
317 /* The translation passed as a part of an argument of re_compile_pattern. */
318 RE_TRANSLATE_TYPE trans;
319 /* Copy of re_dfa_t's word_char. */
320 re_const_bitset_ptr_t word_char;
321 /* 1 if REG_ICASE. */
322 unsigned char icase;
323 unsigned char is_utf8;
324 unsigned char map_notascii;
325 unsigned char mbs_allocated;
326 unsigned char offsets_needed;
327 unsigned char newline_anchor;
328 unsigned char word_ops_used;
329 int mb_cur_max;
330};
331typedef struct re_string_t re_string_t;
332
333struct re_dfa_t;
334typedef struct re_dfa_t re_dfa_t;
335
336static reg_errcode_t re_string_realloc_buffers (re_string_t *pstr,
337 int new_buf_len)
338 internal_function;
339#ifdef RE_ENABLE_I18N
340static void build_wcs_buffer (re_string_t *pstr) internal_function;
341static reg_errcode_t build_wcs_upper_buffer (re_string_t *pstr) internal_function;
342#endif /* RE_ENABLE_I18N */
343static void build_upper_buffer (re_string_t *pstr) internal_function;
344static void re_string_translate_buffer (re_string_t *pstr) internal_function;
345static unsigned int re_string_context_at (const re_string_t *input, int idx,
346 int eflags)
347 internal_function __attribute ((pure));
348#define re_string_peek_byte(pstr, offset) \
349 ((pstr)->mbs[(pstr)->cur_idx + offset])
350#define re_string_fetch_byte(pstr) \
351 ((pstr)->mbs[(pstr)->cur_idx++])
352#define re_string_first_byte(pstr, idx) \
353 ((idx) == (pstr)->valid_len || (pstr)->wcs[idx] != WEOF)
354#define re_string_is_single_byte_char(pstr, idx) \
355 ((pstr)->wcs[idx] != WEOF && ((pstr)->valid_len == (idx) + 1 \
356 || (pstr)->wcs[(idx) + 1] != WEOF))
357#define re_string_eoi(pstr) ((pstr)->stop <= (pstr)->cur_idx)
358#define re_string_cur_idx(pstr) ((pstr)->cur_idx)
359#define re_string_get_buffer(pstr) ((pstr)->mbs)
360#define re_string_length(pstr) ((pstr)->len)
361#define re_string_byte_at(pstr,idx) ((pstr)->mbs[idx])
362#define re_string_skip_bytes(pstr,idx) ((pstr)->cur_idx += (idx))
363#define re_string_set_index(pstr,idx) ((pstr)->cur_idx = (idx))
364
365#include <alloca.h>
366
367#if 1
368# ifdef HAVE_ALLOCA
369/* The OS usually guarantees only one guard page at the bottom of the stack,
370 and a page size can be as small as 4096 bytes. So we cannot safely
371 allocate anything larger than 4096 bytes. Also care for the possibility
372 of a few compiler-allocated temporary stack slots. */
373# define __libc_use_alloca(n) ((n) < 4032)
374# else
375/* alloca is implemented with malloc, so just use malloc. */
376# define __libc_use_alloca(n) 0
377# endif
378#endif
379
380#define re_malloc(t,n) ((t *) malloc ((n) * sizeof (t)))
381#define re_realloc(p,t,n) ((t *) realloc (p, (n) * sizeof (t)))
382#define re_free(p) free (p)
383
384struct bin_tree_t
385{
386 struct bin_tree_t *parent;
387 struct bin_tree_t *left;
388 struct bin_tree_t *right;
389 struct bin_tree_t *first;
390 struct bin_tree_t *next;
391
392 re_token_t token;
393
394 /* `node_idx' is the index in dfa->nodes, if `type' == 0.
395 Otherwise `type' indicate the type of this node. */
396 int node_idx;
397};
398typedef struct bin_tree_t bin_tree_t;
399
400#define BIN_TREE_STORAGE_SIZE \
401 ((1024 - sizeof (void *)) / sizeof (bin_tree_t))
402
403struct bin_tree_storage_t
404{
405 struct bin_tree_storage_t *next;
406 bin_tree_t data[BIN_TREE_STORAGE_SIZE];
407};
408typedef struct bin_tree_storage_t bin_tree_storage_t;
409
410#define CONTEXT_WORD 1
411#define CONTEXT_NEWLINE (CONTEXT_WORD << 1)
412#define CONTEXT_BEGBUF (CONTEXT_NEWLINE << 1)
413#define CONTEXT_ENDBUF (CONTEXT_BEGBUF << 1)
414
415#define IS_WORD_CONTEXT(c) ((c) & CONTEXT_WORD)
416#define IS_NEWLINE_CONTEXT(c) ((c) & CONTEXT_NEWLINE)
417#define IS_BEGBUF_CONTEXT(c) ((c) & CONTEXT_BEGBUF)
418#define IS_ENDBUF_CONTEXT(c) ((c) & CONTEXT_ENDBUF)
419#define IS_ORDINARY_CONTEXT(c) ((c) == 0)
420
421#define IS_WORD_CHAR(ch) (isalnum (ch) || (ch) == '_')
422#define IS_NEWLINE(ch) ((ch) == NEWLINE_CHAR)
423#define IS_WIDE_WORD_CHAR(ch) (iswalnum (ch) || (ch) == L'_')
424#define IS_WIDE_NEWLINE(ch) ((ch) == WIDE_NEWLINE_CHAR)
425
426#define NOT_SATISFY_PREV_CONSTRAINT(constraint,context) \
427 ((((constraint) & PREV_WORD_CONSTRAINT) && !IS_WORD_CONTEXT (context)) \
428 || ((constraint & PREV_NOTWORD_CONSTRAINT) && IS_WORD_CONTEXT (context)) \
429 || ((constraint & PREV_NEWLINE_CONSTRAINT) && !IS_NEWLINE_CONTEXT (context))\
430 || ((constraint & PREV_BEGBUF_CONSTRAINT) && !IS_BEGBUF_CONTEXT (context)))
431
432#define NOT_SATISFY_NEXT_CONSTRAINT(constraint,context) \
433 ((((constraint) & NEXT_WORD_CONSTRAINT) && !IS_WORD_CONTEXT (context)) \
434 || (((constraint) & NEXT_NOTWORD_CONSTRAINT) && IS_WORD_CONTEXT (context)) \
435 || (((constraint) & NEXT_NEWLINE_CONSTRAINT) && !IS_NEWLINE_CONTEXT (context)) \
436 || (((constraint) & NEXT_ENDBUF_CONSTRAINT) && !IS_ENDBUF_CONTEXT (context)))
437
438struct re_dfastate_t
439{
440 unsigned int hash;
441 re_node_set nodes;
442 re_node_set non_eps_nodes;
443 re_node_set inveclosure;
444 re_node_set *entrance_nodes;
445 struct re_dfastate_t **trtable, **word_trtable;
446 unsigned int context : 4;
447 unsigned int halt : 1;
448 /* If this state can accept `multi byte'.
449 Note that we refer to multibyte characters, and multi character
450 collating elements as `multi byte'. */
451 unsigned int accept_mb : 1;
452 /* If this state has backreference node(s). */
453 unsigned int has_backref : 1;
454 unsigned int has_constraint : 1;
455};
456typedef struct re_dfastate_t re_dfastate_t;
457
458struct re_state_table_entry
459{
460 int num;
461 int alloc;
462 re_dfastate_t **array;
463};
464
465/* Array type used in re_sub_match_last_t and re_sub_match_top_t. */
466
467typedef struct
468{
469 int next_idx;
470 int alloc;
471 re_dfastate_t **array;
472} state_array_t;
473
474/* Store information about the node NODE whose type is OP_CLOSE_SUBEXP. */
475
476typedef struct
477{
478 int node;
479 int str_idx; /* The position NODE match at. */
480 state_array_t path;
481} re_sub_match_last_t;
482
483/* Store information about the node NODE whose type is OP_OPEN_SUBEXP.
484 And information about the node, whose type is OP_CLOSE_SUBEXP,
485 corresponding to NODE is stored in LASTS. */
486
487typedef struct
488{
489 int str_idx;
490 int node;
491 state_array_t *path;
492 int alasts; /* Allocation size of LASTS. */
493 int nlasts; /* The number of LASTS. */
494 re_sub_match_last_t **lasts;
495} re_sub_match_top_t;
496
497struct re_backref_cache_entry
498{
499 int node;
500 int str_idx;
501 int subexp_from;
502 int subexp_to;
503 char more;
504 char unused;
505 unsigned short int eps_reachable_subexps_map;
506};
507
508typedef struct
509{
510 /* The string object corresponding to the input string. */
511 re_string_t input;
512 const re_dfa_t *dfa;
513 /* EFLAGS of the argument of regexec. */
514 int eflags;
515 /* Where the matching ends. */
516 int match_last;
517 int last_node;
518 /* The state log used by the matcher. */
519 re_dfastate_t **state_log;
520 int state_log_top;
521 /* Back reference cache. */
522 int nbkref_ents;
523 int abkref_ents;
524 struct re_backref_cache_entry *bkref_ents;
525 int max_mb_elem_len;
526 int nsub_tops;
527 int asub_tops;
528 re_sub_match_top_t **sub_tops;
529} re_match_context_t;
530
531typedef struct
532{
533 re_dfastate_t **sifted_states;
534 re_dfastate_t **limited_states;
535 int last_node;
536 int last_str_idx;
537 re_node_set limits;
538} re_sift_context_t;
539
540struct re_fail_stack_ent_t
541{
542 int idx;
543 int node;
544 regmatch_t *regs;
545 re_node_set eps_via_nodes;
546};
547
548struct re_fail_stack_t
549{
550 int num;
551 int alloc;
552 struct re_fail_stack_ent_t *stack;
553};
554
555struct re_dfa_t
556{
557 re_token_t *nodes;
558 size_t nodes_alloc;
559 size_t nodes_len;
560 int *nexts;
561 int *org_indices;
562 re_node_set *edests;
563 re_node_set *eclosures;
564 re_node_set *inveclosures;
565 struct re_state_table_entry *state_table;
566 re_dfastate_t *init_state;
567 re_dfastate_t *init_state_word;
568 re_dfastate_t *init_state_nl;
569 re_dfastate_t *init_state_begbuf;
570 bin_tree_t *str_tree;
571 bin_tree_storage_t *str_tree_storage;
572 re_bitset_ptr_t sb_char;
573 int str_tree_storage_idx;
574
575 /* number of subexpressions `re_nsub' is in regex_t. */
576 unsigned int state_hash_mask;
577 int init_node;
578 int nbackref; /* The number of backreference in this dfa. */
579
580 /* Bitmap expressing which backreference is used. */
581 bitset_word_t used_bkref_map;
582 bitset_word_t completed_bkref_map;
583
584 unsigned int has_plural_match : 1;
585 /* If this dfa has "multibyte node", which is a backreference or
586 a node which can accept multibyte character or multi character
587 collating element. */
588 unsigned int has_mb_node : 1;
589 unsigned int is_utf8 : 1;
590 unsigned int map_notascii : 1;
591 unsigned int word_ops_used : 1;
592 int mb_cur_max;
593 bitset_t word_char;
594 reg_syntax_t syntax;
595 int *subexp_map;
596#ifdef DEBUG
597 char* re_str;
598#endif
599 __libc_lock_define (, lock)
600};
601
602#define re_node_set_init_empty(set) memset (set, '\0', sizeof (re_node_set))
603#define re_node_set_remove(set,id) \
604 (re_node_set_remove_at (set, re_node_set_contains (set, id) - 1))
605#define re_node_set_empty(p) ((p)->nelem = 0)
606#define re_node_set_free(set) re_free ((set)->elems)
607
608
609typedef enum
610{
611 SB_CHAR,
612 MB_CHAR,
613 EQUIV_CLASS,
614 COLL_SYM,
615 CHAR_CLASS
616} bracket_elem_type;
617
618typedef struct
619{
620 bracket_elem_type type;
621 union
622 {
623 unsigned char ch;
624 unsigned char *name;
625#ifdef __UCLIBC_HAS_WCHAR__
626 wchar_t wch;
627#endif
628 } opr;
629} bracket_elem_t;
630
631
632/* Inline functions for bitset operation. */
633static __inline__ void
634bitset_not (bitset_t set)
635{
636 int bitset_i;
637 for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i)
638 set[bitset_i] = ~set[bitset_i];
639}
640
641static __inline__ void
642bitset_merge (bitset_t dest, const bitset_t src)
643{
644 int bitset_i;
645 for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i)
646 dest[bitset_i] |= src[bitset_i];
647}
648
649static __inline__ void
650bitset_mask (bitset_t dest, const bitset_t src)
651{
652 int bitset_i;
653 for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i)
654 dest[bitset_i] &= src[bitset_i];
655}
656
657#ifdef RE_ENABLE_I18N
658/* Inline functions for re_string. */
659static __inline__ int
660internal_function __attribute ((pure))
661re_string_char_size_at (const re_string_t *pstr, int idx)
662{
663 int byte_idx;
664 if (pstr->mb_cur_max == 1)
665 return 1;
666 for (byte_idx = 1; idx + byte_idx < pstr->valid_len; ++byte_idx)
667 if (pstr->wcs[idx + byte_idx] != WEOF)
668 break;
669 return byte_idx;
670}
671
672static __inline__ wint_t
673internal_function __attribute ((pure))
674re_string_wchar_at (const re_string_t *pstr, int idx)
675{
676 if (pstr->mb_cur_max == 1)
677 return (wint_t) pstr->mbs[idx];
678 return (wint_t) pstr->wcs[idx];
679}
680
681static int
682internal_function __attribute ((pure))
683re_string_elem_size_at (const re_string_t *pstr, int idx)
684{
685# if 0
686 const unsigned char *p, *extra;
687 const int32_t *table, *indirect;
688 int32_t tmp;
689# include <locale/weight.h>
690 uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
691
692 if (nrules != 0)
693 {
694 table = (const int32_t *) _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB);
695 extra = (const unsigned char *)
696 _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAMB);
697 indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE,
698 _NL_COLLATE_INDIRECTMB);
699 p = pstr->mbs + idx;
700 tmp = findidx (&p);
701 return p - pstr->mbs - idx;
702 }
703# endif
704 return 1;
705}
706#endif /* RE_ENABLE_I18N */
707
708#endif /* _REGEX_INTERNAL_H */