* sysdeps/unix/sysv/linux/m68k/clone.S: Make inline syscall to
[glibc.git] / posix / regex_internal.h
blob50867878ed00f3182ccc816a29516af24415559f
1 /* Extended regular expression matching and search library.
2 Copyright (C) 2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
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.
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.
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. */
21 #ifndef _REGEX_INTERNAL_H
22 #define _REGEX_INTERNAL_H 1
24 /* Number of bits in a byte. */
25 #define BYTE_BITS 8
26 /* Number of single byte character. */
27 #define SBC_MAX 256
29 #define COLL_ELEM_LEN_MAX 8
31 /* The character which represents newline. */
32 #define NEWLINE_CHAR '\n'
33 #define WIDE_NEWLINE_CHAR L'\n'
35 /* Rename to standard API for using out of glibc. */
36 #ifndef _LIBC
37 # define __wctype wctype
38 # define __iswctype iswctype
39 # define __btowc btowc
40 # define __mempcpy memcpy
41 # define attribute_hidden
42 #endif /* not _LIBC */
44 extern const char __re_error_msgid[] attribute_hidden;
45 extern const size_t __re_error_msgid_idx[] attribute_hidden;
47 /* Number of bits in an unsinged int. */
48 #define UINT_BITS (sizeof (unsigned int) * BYTE_BITS)
49 /* Number of unsigned int in an bit_set. */
50 #define BITSET_UINTS ((SBC_MAX + UINT_BITS - 1) / UINT_BITS)
51 typedef unsigned int bitset[BITSET_UINTS];
52 typedef unsigned int *re_bitset_ptr_t;
54 #define bitset_set(set,i) (set[i / UINT_BITS] |= 1 << i % UINT_BITS)
55 #define bitset_clear(set,i) (set[i / UINT_BITS] &= ~(1 << i % UINT_BITS))
56 #define bitset_contain(set,i) (set[i / UINT_BITS] & (1 << i % UINT_BITS))
57 #define bitset_empty(set) memset (set, 0, sizeof (unsigned int) * BITSET_UINTS)
58 #define bitset_set_all(set) \
59 memset (set, 255, sizeof (unsigned int) * BITSET_UINTS)
60 #define bitset_copy(dest,src) \
61 memcpy (dest, src, sizeof (unsigned int) * BITSET_UINTS)
62 static inline void bitset_not (bitset set);
63 static inline void bitset_merge (bitset dest, const bitset src);
64 static inline void bitset_not_merge (bitset dest, const bitset src);
66 #define PREV_WORD_CONSTRAINT 0x0001
67 #define PREV_NOTWORD_CONSTRAINT 0x0002
68 #define NEXT_WORD_CONSTRAINT 0x0004
69 #define NEXT_NOTWORD_CONSTRAINT 0x0008
70 #define PREV_NEWLINE_CONSTRAINT 0x0010
71 #define NEXT_NEWLINE_CONSTRAINT 0x0020
72 #define PREV_BEGBUF_CONSTRAINT 0x0040
73 #define NEXT_ENDBUF_CONSTRAINT 0x0080
74 #define DUMMY_CONSTRAINT 0x0100
76 typedef enum
78 INSIDE_WORD = PREV_WORD_CONSTRAINT | NEXT_WORD_CONSTRAINT,
79 WORD_FIRST = PREV_NOTWORD_CONSTRAINT | NEXT_WORD_CONSTRAINT,
80 WORD_LAST = PREV_WORD_CONSTRAINT | NEXT_NOTWORD_CONSTRAINT,
81 LINE_FIRST = PREV_NEWLINE_CONSTRAINT,
82 LINE_LAST = NEXT_NEWLINE_CONSTRAINT,
83 BUF_FIRST = PREV_BEGBUF_CONSTRAINT,
84 BUF_LAST = NEXT_ENDBUF_CONSTRAINT,
85 WORD_DELIM = DUMMY_CONSTRAINT
86 } re_context_type;
88 typedef struct
90 int alloc;
91 int nelem;
92 int *elems;
93 } re_node_set;
95 typedef enum
97 NON_TYPE = 0,
99 /* Token type, these are used only by token. */
100 OP_OPEN_BRACKET,
101 OP_CLOSE_BRACKET,
102 OP_CHARSET_RANGE,
103 OP_OPEN_DUP_NUM,
104 OP_CLOSE_DUP_NUM,
105 OP_NON_MATCH_LIST,
106 OP_OPEN_COLL_ELEM,
107 OP_CLOSE_COLL_ELEM,
108 OP_OPEN_EQUIV_CLASS,
109 OP_CLOSE_EQUIV_CLASS,
110 OP_OPEN_CHAR_CLASS,
111 OP_CLOSE_CHAR_CLASS,
112 OP_WORD,
113 OP_NOTWORD,
114 BACK_SLASH,
116 /* Tree type, these are used only by tree. */
117 CONCAT,
118 ALT,
119 SUBEXP,
120 SIMPLE_BRACKET,
121 #ifdef RE_ENABLE_I18N
122 COMPLEX_BRACKET,
123 #endif /* RE_ENABLE_I18N */
125 /* Node type, These are used by token, node, tree. */
126 OP_OPEN_SUBEXP,
127 OP_CLOSE_SUBEXP,
128 OP_PERIOD,
129 CHARACTER,
130 END_OF_RE,
131 OP_ALT,
132 OP_DUP_ASTERISK,
133 OP_DUP_PLUS,
134 OP_DUP_QUESTION,
135 OP_BACK_REF,
136 ANCHOR,
138 /* Dummy marker. */
139 END_OF_RE_TOKEN_T
140 } re_token_type_t;
142 #ifdef RE_ENABLE_I18N
143 typedef struct
145 /* Multibyte characters. */
146 wchar_t *mbchars;
148 /* Collating symbols. */
149 # ifdef _LIBC
150 int32_t *coll_syms;
151 # endif
153 /* Equivalence classes. */
154 # ifdef _LIBC
155 int32_t *equiv_classes;
156 # endif
158 /* Range expressions. */
159 # ifdef _LIBC
160 uint32_t *range_starts;
161 uint32_t *range_ends;
162 # else /* not _LIBC */
163 wchar_t *range_starts;
164 wchar_t *range_ends;
165 # endif /* not _LIBC */
167 /* Character classes. */
168 wctype_t *char_classes;
170 /* If this character set is the non-matching list. */
171 unsigned int non_match : 1;
173 /* # of multibyte characters. */
174 int nmbchars;
176 /* # of collating symbols. */
177 int ncoll_syms;
179 /* # of equivalence classes. */
180 int nequiv_classes;
182 /* # of range expressions. */
183 int nranges;
185 /* # of character classes. */
186 int nchar_classes;
187 } re_charset_t;
188 #endif /* RE_ENABLE_I18N */
190 typedef struct
192 union
194 unsigned char c; /* for CHARACTER */
195 re_bitset_ptr_t sbcset; /* for SIMPLE_BRACKET */
196 #ifdef RE_ENABLE_I18N
197 re_charset_t *mbcset; /* for COMPLEX_BRACKET */
198 #endif /* RE_ENABLE_I18N */
199 int idx; /* for BACK_REF */
200 re_context_type ctx_type; /* for ANCHOR */
201 } opr;
202 #if __GNUC__ >= 2
203 re_token_type_t type : 8;
204 #else
205 re_token_type_t type;
206 #endif
207 unsigned int constraint : 10; /* context constraint */
208 unsigned int duplicated : 1;
209 #ifdef RE_ENABLE_I18N
210 unsigned int mb_partial : 1;
211 #endif
212 } re_token_t;
214 #define IS_EPSILON_NODE(type) \
215 ((type) == OP_ALT || (type) == OP_DUP_ASTERISK || (type) == OP_DUP_PLUS \
216 || (type) == OP_DUP_QUESTION || (type) == ANCHOR \
217 || (type) == OP_OPEN_SUBEXP || (type) == OP_CLOSE_SUBEXP)
219 #define ACCEPT_MB_NODE(type) \
220 ((type) == COMPLEX_BRACKET || (type) == OP_PERIOD)
222 struct re_string_t
224 /* Indicate the raw buffer which is the original string passed as an
225 argument of regexec(), re_search(), etc.. */
226 const unsigned char *raw_mbs;
227 /* Store the multibyte string. In case of "case insensitive mode" like
228 REG_ICASE, upper cases of the string are stored, otherwise MBS points
229 the same address that RAW_MBS points. */
230 unsigned char *mbs;
231 /* Store the case sensitive multibyte string. In case of
232 "case insensitive mode", the original string are stored,
233 otherwise MBS_CASE points the same address that MBS points. */
234 unsigned char *mbs_case;
235 #ifdef RE_ENABLE_I18N
236 /* Store the wide character string which is corresponding to MBS. */
237 wint_t *wcs;
238 mbstate_t cur_state;
239 #endif
240 /* Index in RAW_MBS. Each character mbs[i] corresponds to
241 raw_mbs[raw_mbs_idx + i]. */
242 int raw_mbs_idx;
243 /* The length of the valid characters in the buffers. */
244 int valid_len;
245 /* The length of the buffers MBS, MBS_CASE, and WCS. */
246 int bufs_len;
247 /* The index in MBS, which is updated by re_string_fetch_byte. */
248 int cur_idx;
249 /* This is length_of_RAW_MBS - RAW_MBS_IDX. */
250 int len;
251 /* End of the buffer may be shorter than its length in the cases such
252 as re_match_2, re_search_2. Then, we use STOP for end of the buffer
253 instead of LEN. */
254 int stop;
256 /* The context of mbs[0]. We store the context independently, since
257 the context of mbs[0] may be different from raw_mbs[0], which is
258 the beginning of the input string. */
259 unsigned int tip_context;
260 /* The translation passed as a part of an argument of re_compile_pattern. */
261 RE_TRANSLATE_TYPE trans;
262 /* 1 if REG_ICASE. */
263 unsigned int icase : 1;
265 typedef struct re_string_t re_string_t;
266 /* In case of REG_ICASE, we allocate the buffer dynamically for mbs. */
267 #define MBS_ALLOCATED(pstr) (pstr->icase)
268 /* In case that we need translation, we allocate the buffer dynamically
269 for mbs_case. Note that mbs == mbs_case if not REG_ICASE. */
270 #define MBS_CASE_ALLOCATED(pstr) (pstr->trans != NULL)
273 static reg_errcode_t re_string_allocate (re_string_t *pstr, const char *str,
274 int len, int init_len,
275 RE_TRANSLATE_TYPE trans, int icase);
276 static reg_errcode_t re_string_construct (re_string_t *pstr, const char *str,
277 int len, RE_TRANSLATE_TYPE trans,
278 int icase);
279 static reg_errcode_t re_string_reconstruct (re_string_t *pstr, int idx,
280 int eflags, int newline);
281 static reg_errcode_t re_string_realloc_buffers (re_string_t *pstr,
282 int new_buf_len);
283 #ifdef RE_ENABLE_I18N
284 static void build_wcs_buffer (re_string_t *pstr);
285 static void build_wcs_upper_buffer (re_string_t *pstr);
286 #endif /* RE_ENABLE_I18N */
287 static void build_upper_buffer (re_string_t *pstr);
288 static void re_string_translate_buffer (re_string_t *pstr);
289 static void re_string_destruct (re_string_t *pstr);
290 #ifdef RE_ENABLE_I18N
291 static int re_string_elem_size_at (const re_string_t *pstr, int idx);
292 static inline int re_string_char_size_at (const re_string_t *pstr, int idx);
293 static inline wint_t re_string_wchar_at (const re_string_t *pstr, int idx);
294 #endif /* RE_ENABLE_I18N */
295 static unsigned int re_string_context_at (const re_string_t *input, int idx,
296 int eflags, int newline_anchor);
297 #define re_string_peek_byte(pstr, offset) \
298 ((pstr)->mbs[(pstr)->cur_idx + offset])
299 #define re_string_peek_byte_case(pstr, offset) \
300 ((pstr)->mbs_case[(pstr)->cur_idx + offset])
301 #define re_string_fetch_byte(pstr) \
302 ((pstr)->mbs[(pstr)->cur_idx++])
303 #define re_string_fetch_byte_case(pstr) \
304 ((pstr)->mbs_case[(pstr)->cur_idx++])
305 #define re_string_first_byte(pstr, idx) \
306 ((idx) == (pstr)->len || (pstr)->wcs[idx] != WEOF)
307 #define re_string_is_single_byte_char(pstr, idx) \
308 ((pstr)->wcs[idx] != WEOF && ((pstr)->len == (idx) \
309 || (pstr)->wcs[(idx) + 1] != WEOF))
310 #define re_string_eoi(pstr) ((pstr)->stop <= (pstr)->cur_idx)
311 #define re_string_cur_idx(pstr) ((pstr)->cur_idx)
312 #define re_string_get_buffer(pstr) ((pstr)->mbs)
313 #define re_string_length(pstr) ((pstr)->len)
314 #define re_string_byte_at(pstr,idx) ((pstr)->mbs[idx])
315 #define re_string_skip_bytes(pstr,idx) ((pstr)->cur_idx += (idx))
316 #define re_string_set_index(pstr,idx) ((pstr)->cur_idx = (idx))
318 #define re_malloc(t,n) ((t *) malloc ((n) * sizeof (t)))
319 #define re_realloc(p,t,n) ((t *) realloc (p, (n) * sizeof (t)))
320 #define re_free(p) free (p)
322 struct bin_tree_t
324 struct bin_tree_t *parent;
325 struct bin_tree_t *left;
326 struct bin_tree_t *right;
328 /* `node_idx' is the index in dfa->nodes, if `type' == 0.
329 Otherwise `type' indicate the type of this node. */
330 re_token_type_t type;
331 int node_idx;
333 int first;
334 int next;
335 re_node_set eclosure;
337 typedef struct bin_tree_t bin_tree_t;
340 #define CONTEXT_WORD 1
341 #define CONTEXT_NEWLINE (CONTEXT_WORD << 1)
342 #define CONTEXT_BEGBUF (CONTEXT_NEWLINE << 1)
343 #define CONTEXT_ENDBUF (CONTEXT_BEGBUF << 1)
345 #define IS_WORD_CONTEXT(c) ((c) & CONTEXT_WORD)
346 #define IS_NEWLINE_CONTEXT(c) ((c) & CONTEXT_NEWLINE)
347 #define IS_BEGBUF_CONTEXT(c) ((c) & CONTEXT_BEGBUF)
348 #define IS_ENDBUF_CONTEXT(c) ((c) & CONTEXT_ENDBUF)
349 #define IS_ORDINARY_CONTEXT(c) ((c) == 0)
351 #define IS_WORD_CHAR(ch) (isalnum (ch) || (ch) == '_')
352 #define IS_NEWLINE(ch) ((ch) == NEWLINE_CHAR)
353 #define IS_WIDE_WORD_CHAR(ch) (iswalnum (ch) || (ch) == L'_')
354 #define IS_WIDE_NEWLINE(ch) ((ch) == WIDE_NEWLINE_CHAR)
356 #define NOT_SATISFY_PREV_CONSTRAINT(constraint,context) \
357 ((((constraint) & PREV_WORD_CONSTRAINT) && !IS_WORD_CONTEXT (context)) \
358 || ((constraint & PREV_NOTWORD_CONSTRAINT) && IS_WORD_CONTEXT (context)) \
359 || ((constraint & PREV_NEWLINE_CONSTRAINT) && !IS_NEWLINE_CONTEXT (context))\
360 || ((constraint & PREV_BEGBUF_CONSTRAINT) && !IS_BEGBUF_CONTEXT (context)))
362 #define NOT_SATISFY_NEXT_CONSTRAINT(constraint,context) \
363 ((((constraint) & NEXT_WORD_CONSTRAINT) && !IS_WORD_CONTEXT (context)) \
364 || (((constraint) & NEXT_NOTWORD_CONSTRAINT) && IS_WORD_CONTEXT (context)) \
365 || (((constraint) & NEXT_NEWLINE_CONSTRAINT) && !IS_NEWLINE_CONTEXT (context)) \
366 || (((constraint) & NEXT_ENDBUF_CONSTRAINT) && !IS_ENDBUF_CONTEXT (context)))
368 struct re_dfastate_t
370 unsigned int hash;
371 re_node_set nodes;
372 re_node_set *entrance_nodes;
373 struct re_dfastate_t **trtable;
374 struct re_dfastate_t **trtable_search;
375 /* If this state is a special state.
376 A state is a special state if the state is the halt state, or
377 a anchor. */
378 unsigned int context : 2;
379 unsigned int halt : 1;
380 /* If this state can accept `multi byte'.
381 Note that we refer to multibyte characters, and multi character
382 collating elements as `multi byte'. */
383 unsigned int accept_mb : 1;
384 /* If this state has backreference node(s). */
385 unsigned int has_backref : 1;
386 unsigned int has_constraint : 1;
388 typedef struct re_dfastate_t re_dfastate_t;
390 typedef struct
392 /* start <= node < end */
393 int start;
394 int end;
395 } re_subexp_t;
397 struct re_state_table_entry
399 int num;
400 int alloc;
401 re_dfastate_t **array;
404 /* Array type used in re_sub_match_last_t and re_sub_match_top_t. */
406 typedef struct
408 int next_idx;
409 int alloc;
410 re_dfastate_t **array;
411 } state_array_t;
413 /* Store information about the node NODE whose type is OP_CLOSE_SUBEXP. */
415 typedef struct
417 int node;
418 int str_idx; /* The position NODE match at. */
419 state_array_t path;
420 } re_sub_match_last_t;
422 /* Store information about the node NODE whose type is OP_OPEN_SUBEXP.
423 And information about the node, whose type is OP_CLOSE_SUBEXP,
424 corresponding to NODE is stored in LASTS. */
426 typedef struct
428 int str_idx;
429 int node;
430 int next_last_offset;
431 state_array_t *path;
432 int alasts; /* Allocation size of LASTS. */
433 int nlasts; /* The number of LASTS. */
434 re_sub_match_last_t **lasts;
435 } re_sub_match_top_t;
437 struct re_backref_cache_entry
439 int node;
440 int str_idx;
441 int subexp_from;
442 int subexp_to;
443 int flag;
446 typedef struct
448 /* EFLAGS of the argument of regexec. */
449 int eflags;
450 /* Where the matching ends. */
451 int match_last;
452 int last_node;
453 /* The string object corresponding to the input string. */
454 re_string_t *input;
455 /* The state log used by the matcher. */
456 re_dfastate_t **state_log;
457 int state_log_top;
458 /* Back reference cache. */
459 int nbkref_ents;
460 int abkref_ents;
461 struct re_backref_cache_entry *bkref_ents;
462 int max_mb_elem_len;
463 int nsub_tops;
464 int asub_tops;
465 re_sub_match_top_t **sub_tops;
466 } re_match_context_t;
468 typedef struct
470 int cur_bkref;
471 int cls_subexp_idx;
473 re_dfastate_t **sifted_states;
474 re_dfastate_t **limited_states;
476 re_node_set limits;
478 int last_node;
479 int last_str_idx;
480 int check_subexp;
481 } re_sift_context_t;
483 struct re_fail_stack_ent_t
485 int idx;
486 int node;
487 regmatch_t *regs;
488 re_node_set eps_via_nodes;
491 struct re_fail_stack_t
493 int num;
494 int alloc;
495 struct re_fail_stack_ent_t *stack;
498 struct re_dfa_t
500 re_bitset_ptr_t word_char;
502 /* number of subexpressions `re_nsub' is in regex_t. */
503 int subexps_alloc;
504 re_subexp_t *subexps;
506 re_token_t *nodes;
507 int nodes_alloc;
508 int nodes_len;
509 bin_tree_t *str_tree;
510 int *nexts;
511 re_node_set *edests;
512 re_node_set *eclosures;
513 re_node_set *inveclosures;
514 struct re_state_table_entry *state_table;
515 unsigned int state_hash_mask;
516 re_dfastate_t *init_state;
517 re_dfastate_t *init_state_word;
518 re_dfastate_t *init_state_nl;
519 re_dfastate_t *init_state_begbuf;
520 int states_alloc;
521 int init_node;
522 int nbackref; /* The number of backreference in this dfa. */
523 /* Bitmap expressing which backreference is used. */
524 unsigned int used_bkref_map;
525 #ifdef DEBUG
526 char* re_str;
527 #endif
528 unsigned int has_plural_match : 1;
529 /* If this dfa has "multibyte node", which is a backreference or
530 a node which can accept multibyte character or multi character
531 collating element. */
532 unsigned int has_mb_node : 1;
534 typedef struct re_dfa_t re_dfa_t;
536 static reg_errcode_t re_node_set_alloc (re_node_set *set, int size);
537 static reg_errcode_t re_node_set_init_1 (re_node_set *set, int elem);
538 static reg_errcode_t re_node_set_init_2 (re_node_set *set, int elem1,
539 int elem2);
540 #define re_node_set_init_empty(set) memset (set, '\0', sizeof (re_node_set))
541 static reg_errcode_t re_node_set_init_copy (re_node_set *dest,
542 const re_node_set *src);
543 static reg_errcode_t re_node_set_add_intersect (re_node_set *dest,
544 const re_node_set *src1,
545 const re_node_set *src2);
546 static reg_errcode_t re_node_set_init_union (re_node_set *dest,
547 const re_node_set *src1,
548 const re_node_set *src2);
549 static reg_errcode_t re_node_set_merge (re_node_set *dest,
550 const re_node_set *src);
551 static int re_node_set_insert (re_node_set *set, int elem);
552 static int re_node_set_compare (const re_node_set *set1,
553 const re_node_set *set2);
554 static int re_node_set_contains (const re_node_set *set, int elem);
555 static void re_node_set_remove_at (re_node_set *set, int idx);
556 #define re_node_set_remove(set,id) \
557 (re_node_set_remove_at (set, re_node_set_contains (set, id) - 1))
558 #define re_node_set_empty(p) ((p)->nelem = 0)
559 #define re_node_set_free(set) re_free ((set)->elems)
560 static int re_dfa_add_node (re_dfa_t *dfa, re_token_t token, int mode);
561 static re_dfastate_t *re_acquire_state (reg_errcode_t *err, re_dfa_t *dfa,
562 const re_node_set *nodes);
563 static re_dfastate_t *re_acquire_state_context (reg_errcode_t *err,
564 re_dfa_t *dfa,
565 const re_node_set *nodes,
566 unsigned int context);
567 static void free_state (re_dfastate_t *state);
570 typedef enum
572 SB_CHAR,
573 MB_CHAR,
574 EQUIV_CLASS,
575 COLL_SYM,
576 CHAR_CLASS
577 } bracket_elem_type;
579 typedef struct
581 bracket_elem_type type;
582 union
584 unsigned char ch;
585 unsigned char *name;
586 wchar_t wch;
587 } opr;
588 } bracket_elem_t;
591 /* Inline functions for bitset operation. */
592 static inline void
593 bitset_not (set)
594 bitset set;
596 int bitset_i;
597 for (bitset_i = 0; bitset_i < BITSET_UINTS; ++bitset_i)
598 set[bitset_i] = ~set[bitset_i];
601 static inline void
602 bitset_merge (dest, src)
603 bitset dest;
604 const bitset src;
606 int bitset_i;
607 for (bitset_i = 0; bitset_i < BITSET_UINTS; ++bitset_i)
608 dest[bitset_i] |= src[bitset_i];
611 static inline void
612 bitset_not_merge (dest, src)
613 bitset dest;
614 const bitset src;
616 int i;
617 for (i = 0; i < BITSET_UINTS; ++i)
618 dest[i] |= ~src[i];
621 #ifdef RE_ENABLE_I18N
622 /* Inline functions for re_string. */
623 static inline int
624 re_string_char_size_at (pstr, idx)
625 const re_string_t *pstr;
626 int idx;
628 int byte_idx;
629 if (MB_CUR_MAX == 1)
630 return 1;
631 for (byte_idx = 1; idx + byte_idx < pstr->len; ++byte_idx)
632 if (pstr->wcs[idx + byte_idx] != WEOF)
633 break;
634 return byte_idx;
637 static inline wint_t
638 re_string_wchar_at (pstr, idx)
639 const re_string_t *pstr;
640 int idx;
642 if (MB_CUR_MAX == 1)
643 return (wint_t) pstr->mbs[idx];
644 return (wint_t) pstr->wcs[idx];
647 static int
648 re_string_elem_size_at (pstr, idx)
649 const re_string_t *pstr;
650 int idx;
652 #ifdef _LIBC
653 const unsigned char *p, *extra;
654 const int32_t *table, *indirect;
655 int32_t tmp;
656 # include <locale/weight.h>
657 uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
659 if (nrules != 0)
661 table = (const int32_t *) _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB);
662 extra = (const unsigned char *)
663 _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAMB);
664 indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE,
665 _NL_COLLATE_INDIRECTMB);
666 p = pstr->mbs + idx;
667 tmp = findidx (&p);
668 return p - pstr->mbs - idx;
670 else
671 #endif /* _LIBC */
672 return 1;
674 #endif /* RE_ENABLE_I18N */
676 #endif /* _REGEX_INTERNAL_H */