MCPcopy Create free account
hub / github.com/git/git / re_search_internal

Function re_search_internal

compat/regex/regexec.c:615–937  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

613 Return REG_NOERROR if we find a match, and REG_NOMATCH if not,
614 otherwise return the error code.
615 Note: We assume front end functions already check ranges.
616 (START + RANGE >= 0 && START + RANGE <= LENGTH) */
617
618static reg_errcode_t
619re_search_internal (const regex_t *preg,
620 const char *string,
621 int length, int start, int range, int stop,
622 size_t nmatch, regmatch_t pmatch[],
623 int eflags)
624{
625 reg_errcode_t err;
626 const re_dfa_t *dfa = (const re_dfa_t *) preg->buffer;
627 int left_lim, right_lim, incr;
628 int fl_longest_match, match_first, match_kind, match_last = -1;
629 int extra_nmatch;
630 int sb, ch;
631#if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
632 re_match_context_t mctx = { .dfa = dfa };
633#else
634 re_match_context_t mctx;
635#endif
636 char *fastmap = (preg->fastmap != NULL && preg->fastmap_accurate
637 && range && !preg->can_be_null) ? preg->fastmap : NULL;
638 RE_TRANSLATE_TYPE t = preg->translate;
639
640#if !(defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
641 memset (&mctx, '\0', sizeof (re_match_context_t));
642 mctx.dfa = dfa;
643#endif
644
645 extra_nmatch = (nmatch > preg->re_nsub) ? nmatch - (preg->re_nsub + 1) : 0;
646 nmatch -= extra_nmatch;
647
648 /* Check if the DFA haven't been compiled. */
649 if (BE (preg->used == 0 || dfa->init_state == NULL
650 || dfa->init_state_word == NULL || dfa->init_state_nl == NULL
651 || dfa->init_state_begbuf == NULL, 0))
652 return REG_NOMATCH;
653
654#ifdef DEBUG
655 /* We assume front-end functions already check them. */
656 assert (start + range >= 0 && start + range <= length);
657#endif
658
659 /* If initial states with non-begbuf contexts have no elements,
660 the regex must be anchored. If preg->newline_anchor is set,
661 we'll never use init_state_nl, so do not check it. */
662 if (dfa->init_state->nodes.nelem == 0
663 && dfa->init_state_word->nodes.nelem == 0
664 && (dfa->init_state_nl->nodes.nelem == 0
665 || !preg->newline_anchor))
666 {
667 if (start != 0 && start + range != 0)
668 return REG_NOMATCH;
669 start = range = 0;
670 }
671
672 /* We must check the longest matching, if nmatch > 0. */

Callers 2

check_halt_state_context (const re_match_context_t *mctx, const re_dfastate_t *state, int idx) internal_function; static void update_regs (const re_dfa_t *dfa, regmatch_t *pmatch, regmatch_t *prev_idx_match, int cur_node, int cur_idx, int nmatch) internal_function; static reg_errcode_t push_fail_stack (struct re_fail_stack_t *fs, int str_idx, int dest_node, int nregs, regmatch_t *regs, re_node_set *eps_via_nodes) internal_function; static reg_errcode_t set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch, regmatch_t *pmatch, int fl_backtrack) internal_function; static reg_errcode_t free_fail_stack_return (struct re_fail_stack_t *fs) internal_function; #ifdef RE_ENABLE_I18N static int sift_states_iter_mb (const re_match_context_t *mctx, re_sift_context_t *sctx, int node_idx, int str_idx, int max_str_idx) internal_function; #endif /* RE_ENABLE_I18N */ static reg_errcode_t sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx) internal_function; static reg_errcode_t build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx, int str_idx, re_node_set *cur_dest) internal_function; static reg_errcode_t update_cur_sifted_state (const re_match_context_t *mctx, re_sift_context_t *sctx, int str_idx, re_node_set *dest_nodes) internal_function; static reg_errcode_t add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes, const re_node_set *candidates) internal_function; static int check_dst_limits (const re_match_context_t *mctx, re_node_set *limits, int dst_node, int dst_idx, int src_node, int src_idx) internal_function; static int check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries, int subexp_idx, int from_node, int bkref_idx) internal_function; static int check_dst_limits_calc_pos (const re_match_context_t *mctx, int limit, int subexp_idx, int node, int str_idx, int bkref_idx) internal_function; static reg_errcode_t check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes, const re_node_set *candidates, re_node_set *limits, struct re_backref_cache_entry *bkref_ents, int str_idx) internal_function; static reg_errcode_t sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx, int str_idx, const re_node_set *candidates) internal_function; static reg_errcode_t merge_state_array (const re_dfa_t *dfa, re_dfastate_t **dst, re_dfastate_t **src, int num) internal_function; static re_dfastate_t *find_recover_state (reg_errcode_t *err, re_match_context_t *mctx) internal_function; static re_dfastate_t *transit_state (reg_errcode_t *err, re_match_context_t *mctx, re_dfastate_t *state) internal_function; static re_dfastate_t *merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx, re_dfastate_t *next_state) internal_function; static reg_errcode_t check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes, int str_idx) internal_function; #if 0 static re_dfastate_t *transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx, re_dfastate_t *pstate) internal_function; #endif #ifdef RE_ENABLE_I18N static reg_errcode_t transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate) internal_function; #endif /* RE_ENABLE_I18N */ static reg_errcode_t transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes) internal_function; static reg_errcode_t get_subexp (re_match_context_t *mctx, int bkref_node, int bkref_str_idx) internal_function; static reg_errcode_t get_subexp_sub (re_match_context_t *mctx, const re_sub_match_top_t *sub_top, re_sub_match_last_t *sub_last, int bkref_node, int bkref_str) internal_function; static int find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes, int subexp_idx, int type) internal_function; static reg_errcode_t check_arrival (re_match_context_t *mctx, state_array_t *path, int top_node, int top_str, int last_node, int last_str, int type) internal_function; static reg_errcode_t check_arrival_add_next_nodes (re_match_context_t *mctx, int str_idx, re_node_set *cur_nodes, re_node_set *next_nodes) internal_function; static reg_errcode_t check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes, int ex_subexp, int type) internal_function; static reg_errcode_t check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes, int target, int ex_subexp, int type) internal_function; static reg_errcode_t expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes, int cur_str, int subexp_num, int type) internal_function; static int build_trtable (const re_dfa_t *dfa, re_dfastate_t *state) internal_function; #ifdef RE_ENABLE_I18N static int check_node_accept_bytes (const re_dfa_t *dfa, int node_idx, const re_string_t *input, int idx) internal_function; # ifdef _LIBC static unsigned int find_collation_sequence_value (const unsigned char *mbs, size_t name_len) internal_function; # endif /* _LIBC */ #endif /* RE_ENABLE_I18N */ static int group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state, re_node_set *states_node, bitset_t *states_ch) internal_function; static int check_node_accept (const re_match_context_t *mctx, const re_token_t *node, int idx) internal_function; static reg_errcode_t extend_buffers (re_match_context_t *mctx) internal_functionFunction · 0.85
re_search_stubFunction · 0.85

Calls 5

re_string_allocateFunction · 0.85
re_string_reconstructFunction · 0.85
check_halt_state_contextFunction · 0.85
prune_impossible_nodesFunction · 0.85
re_string_destructFunction · 0.85

Tested by

no test coverage detected