From ba72c9e94dc246a6a460ea3ea86ed4f3c36974f1 Mon Sep 17 00:00:00 2001 From: "K.Kosako" Date: Sun, 4 Nov 2018 15:11:59 +0900 Subject: [PATCH] refactoring --- src/regcomp.c | 212 ++++++++++++++++++++++++------------------------- src/regexec.c | 22 ++--- src/regint.h | 46 +++++------ src/regparse.c | 34 ++++---- src/regparse.h | 4 +- 5 files changed, 159 insertions(+), 159 deletions(-) diff --git a/src/regcomp.c b/src/regcomp.c index 31406c2..60878c8 100644 --- a/src/regcomp.c +++ b/src/regcomp.c @@ -1316,30 +1316,30 @@ compile_length_anchor_node(AnchorNode* node, regex_t* reg) } switch (node->type) { - case ANCHOR_PREC_READ: + case ANCR_PREC_READ: len = SIZE_OP_PREC_READ_START + tlen + SIZE_OP_PREC_READ_END; break; - case ANCHOR_PREC_READ_NOT: + case ANCR_PREC_READ_NOT: len = SIZE_OP_PREC_READ_NOT_START + tlen + SIZE_OP_PREC_READ_NOT_END; break; - case ANCHOR_LOOK_BEHIND: + case ANCR_LOOK_BEHIND: len = SIZE_OP_LOOK_BEHIND + tlen; break; - case ANCHOR_LOOK_BEHIND_NOT: + case ANCR_LOOK_BEHIND_NOT: len = SIZE_OP_LOOK_BEHIND_NOT_START + tlen + SIZE_OP_LOOK_BEHIND_NOT_END; break; - case ANCHOR_WORD_BOUNDARY: - case ANCHOR_NO_WORD_BOUNDARY: + case ANCR_WORD_BOUNDARY: + case ANCR_NO_WORD_BOUNDARY: #ifdef USE_WORD_BEGIN_END - case ANCHOR_WORD_BEGIN: - case ANCHOR_WORD_END: + case ANCR_WORD_BEGIN: + case ANCR_WORD_END: #endif len = SIZE_OP_WORD_BOUNDARY; break; - case ANCHOR_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY: - case ANCHOR_NO_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY: + case ANCR_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY: + case ANCR_NO_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY: len = SIZE_OPCODE; break; @@ -1358,14 +1358,14 @@ compile_anchor_node(AnchorNode* node, regex_t* reg, ScanEnv* env) enum OpCode op; switch (node->type) { - case ANCHOR_BEGIN_BUF: r = add_opcode(reg, OP_BEGIN_BUF); break; - case ANCHOR_END_BUF: r = add_opcode(reg, OP_END_BUF); break; - case ANCHOR_BEGIN_LINE: r = add_opcode(reg, OP_BEGIN_LINE); break; - case ANCHOR_END_LINE: r = add_opcode(reg, OP_END_LINE); break; - case ANCHOR_SEMI_END_BUF: r = add_opcode(reg, OP_SEMI_END_BUF); break; - case ANCHOR_BEGIN_POSITION: r = add_opcode(reg, OP_BEGIN_POSITION); break; - - case ANCHOR_WORD_BOUNDARY: + case ANCR_BEGIN_BUF: r = add_opcode(reg, OP_BEGIN_BUF); break; + case ANCR_END_BUF: r = add_opcode(reg, OP_END_BUF); break; + case ANCR_BEGIN_LINE: r = add_opcode(reg, OP_BEGIN_LINE); break; + case ANCR_END_LINE: r = add_opcode(reg, OP_END_LINE); break; + case ANCR_SEMI_END_BUF: r = add_opcode(reg, OP_SEMI_END_BUF); break; + case ANCR_BEGIN_POSITION: r = add_opcode(reg, OP_BEGIN_POSITION); break; + + case ANCR_WORD_BOUNDARY: op = OP_WORD_BOUNDARY; word: r = add_opcode(reg, op); @@ -1373,27 +1373,27 @@ compile_anchor_node(AnchorNode* node, regex_t* reg, ScanEnv* env) r = add_mode(reg, (ModeType )node->ascii_mode); break; - case ANCHOR_NO_WORD_BOUNDARY: + case ANCR_NO_WORD_BOUNDARY: op = OP_NO_WORD_BOUNDARY; goto word; break; #ifdef USE_WORD_BEGIN_END - case ANCHOR_WORD_BEGIN: + case ANCR_WORD_BEGIN: op = OP_WORD_BEGIN; goto word; break; - case ANCHOR_WORD_END: + case ANCR_WORD_END: op = OP_WORD_END; goto word; break; #endif - case ANCHOR_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY: + case ANCR_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY: r = add_opcode(reg, OP_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY); break; - case ANCHOR_NO_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY: + case ANCR_NO_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY: r = add_opcode(reg, OP_NO_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY); break; - case ANCHOR_PREC_READ: + case ANCR_PREC_READ: r = add_opcode(reg, OP_PREC_READ_START); if (r != 0) return r; r = compile_tree(NODE_ANCHOR_BODY(node), reg, env); @@ -1401,7 +1401,7 @@ compile_anchor_node(AnchorNode* node, regex_t* reg, ScanEnv* env) r = add_opcode(reg, OP_PREC_READ_END); break; - case ANCHOR_PREC_READ_NOT: + case ANCR_PREC_READ_NOT: len = compile_length_tree(NODE_ANCHOR_BODY(node), reg); if (len < 0) return len; r = add_opcode_rel_addr(reg, OP_PREC_READ_NOT_START, len + SIZE_OP_PREC_READ_NOT_END); @@ -1411,7 +1411,7 @@ compile_anchor_node(AnchorNode* node, regex_t* reg, ScanEnv* env) r = add_opcode(reg, OP_PREC_READ_NOT_END); break; - case ANCHOR_LOOK_BEHIND: + case ANCR_LOOK_BEHIND: { int n; r = add_opcode(reg, OP_LOOK_BEHIND); @@ -1429,7 +1429,7 @@ compile_anchor_node(AnchorNode* node, regex_t* reg, ScanEnv* env) } break; - case ANCHOR_LOOK_BEHIND_NOT: + case ANCR_LOOK_BEHIND_NOT: { int n; @@ -2572,7 +2572,7 @@ get_head_value_node(Node* node, int exact, regex_t* reg) break; case NODE_ANCHOR: - if (ANCHOR_(node)->type == ANCHOR_PREC_READ) + if (ANCHOR_(node)->type == ANCR_PREC_READ) n = get_head_value_node(NODE_BODY(node), exact, reg); break; @@ -3359,7 +3359,7 @@ divide_look_behind_alternatives(Node* node) NODE_CAR(np) = insert_node; } - if (anc_type == ANCHOR_LOOK_BEHIND_NOT) { + if (anc_type == ANCR_LOOK_BEHIND_NOT) { np = node; do { NODE_SET_TYPE(np, NODE_LIST); /* alt -> list */ @@ -4182,12 +4182,12 @@ setup_called_state_call(Node* node, int state) AnchorNode* an = ANCHOR_(node); switch (an->type) { - case ANCHOR_PREC_READ_NOT: - case ANCHOR_LOOK_BEHIND_NOT: + case ANCR_PREC_READ_NOT: + case ANCR_LOOK_BEHIND_NOT: state |= IN_NOT; /* fall */ - case ANCHOR_PREC_READ: - case ANCHOR_LOOK_BEHIND: + case ANCR_PREC_READ: + case ANCR_LOOK_BEHIND: setup_called_state_call(NODE_ANCHOR_BODY(an), state); break; default: @@ -4299,12 +4299,12 @@ setup_called_state(Node* node, int state) AnchorNode* an = ANCHOR_(node); switch (an->type) { - case ANCHOR_PREC_READ_NOT: - case ANCHOR_LOOK_BEHIND_NOT: + case ANCR_PREC_READ_NOT: + case ANCR_LOOK_BEHIND_NOT: state |= IN_NOT; /* fall */ - case ANCHOR_PREC_READ: - case ANCHOR_LOOK_BEHIND: + case ANCR_PREC_READ: + case ANCR_LOOK_BEHIND: setup_called_state(NODE_ANCHOR_BODY(an), state); break; default: @@ -4344,31 +4344,31 @@ setup_anchor(Node* node, regex_t* reg, int state, ScanEnv* env) #define ALLOWED_BAG_IN_LB_NOT (1<type) { - case ANCHOR_PREC_READ: + case ANCR_PREC_READ: r = setup_tree(NODE_ANCHOR_BODY(an), reg, state, env); break; - case ANCHOR_PREC_READ_NOT: + case ANCR_PREC_READ_NOT: r = setup_tree(NODE_ANCHOR_BODY(an), reg, (state | IN_NOT), env); break; - case ANCHOR_LOOK_BEHIND: + case ANCR_LOOK_BEHIND: { r = check_type_tree(NODE_ANCHOR_BODY(an), ALLOWED_TYPE_IN_LB, ALLOWED_BAG_IN_LB, ALLOWED_ANCHOR_IN_LB); @@ -4380,7 +4380,7 @@ setup_anchor(Node* node, regex_t* reg, int state, ScanEnv* env) } break; - case ANCHOR_LOOK_BEHIND_NOT: + case ANCR_LOOK_BEHIND_NOT: { r = check_type_tree(NODE_ANCHOR_BODY(an), ALLOWED_TYPE_IN_LB, ALLOWED_BAG_IN_LB_NOT, ALLOWED_ANCHOR_IN_LB_NOT); @@ -4884,15 +4884,15 @@ concat_opt_anc_info(OptAnc* to, OptAnc* left, OptAnc* right, to->right |= left->right; } else { - to->right |= (left->right & ANCHOR_PREC_READ_NOT); + to->right |= (left->right & ANCR_PREC_READ_NOT); } } static int is_left(int a) { - if (a == ANCHOR_END_BUF || a == ANCHOR_SEMI_END_BUF || - a == ANCHOR_END_LINE || a == ANCHOR_PREC_READ || a == ANCHOR_PREC_READ_NOT) + if (a == ANCR_END_BUF || a == ANCR_SEMI_END_BUF || + a == ANCR_END_LINE || a == ANCR_PREC_READ || a == ANCR_PREC_READ_NOT) return 0; return 1; @@ -5475,18 +5475,18 @@ optimize_nodes(Node* node, OptNode* opt, OptEnv* env) case NODE_ANCHOR: switch (ANCHOR_(node)->type) { - case ANCHOR_BEGIN_BUF: - case ANCHOR_BEGIN_POSITION: - case ANCHOR_BEGIN_LINE: - case ANCHOR_END_BUF: - case ANCHOR_SEMI_END_BUF: - case ANCHOR_END_LINE: - case ANCHOR_PREC_READ_NOT: - case ANCHOR_LOOK_BEHIND: + case ANCR_BEGIN_BUF: + case ANCR_BEGIN_POSITION: + case ANCR_BEGIN_LINE: + case ANCR_END_BUF: + case ANCR_SEMI_END_BUF: + case ANCR_END_LINE: + case ANCR_PREC_READ_NOT: + case ANCR_LOOK_BEHIND: add_opt_anc_info(&opt->anc, ANCHOR_(node)->type); break; - case ANCHOR_PREC_READ: + case ANCR_PREC_READ: { r = optimize_nodes(NODE_BODY(node), &xo, env); if (r == 0) { @@ -5503,7 +5503,7 @@ optimize_nodes(Node* node, OptNode* opt, OptEnv* env) } break; - case ANCHOR_LOOK_BEHIND_NOT: + case ANCR_LOOK_BEHIND_NOT: break; } break; @@ -5577,9 +5577,9 @@ optimize_nodes(Node* node, OptNode* opt, OptEnv* env) if (env->mmd.max == 0 && NODE_IS_ANYCHAR(NODE_BODY(node)) && qn->greedy != 0) { if (IS_MULTILINE(CTYPE_OPTION(NODE_QUANT_BODY(qn), env))) - add_opt_anc_info(&opt->anc, ANCHOR_ANYCHAR_INF_ML); + add_opt_anc_info(&opt->anc, ANCR_ANYCHAR_INF_ML); else - add_opt_anc_info(&opt->anc, ANCHOR_ANYCHAR_INF); + add_opt_anc_info(&opt->anc, ANCR_ANYCHAR_INF); } max = (xo.len.max > 0 ? INFINITE_LEN : 0); @@ -5624,9 +5624,9 @@ optimize_nodes(Node* node, OptNode* opt, OptEnv* env) #endif { r = optimize_nodes(NODE_BODY(node), opt, env); - if (is_set_opt_anc_info(&opt->anc, ANCHOR_ANYCHAR_INF_MASK)) { + if (is_set_opt_anc_info(&opt->anc, ANCR_ANYCHAR_INF_MASK)) { if (MEM_STATUS_AT0(env->scan_env->backrefed_mem, en->m.regnum)) - remove_opt_anc_info(&opt->anc, ANCHOR_ANYCHAR_INF_MASK); + remove_opt_anc_info(&opt->anc, ANCR_ANYCHAR_INF_MASK); } } break; @@ -5752,8 +5752,8 @@ set_optimize_map(regex_t* reg, OptMap* m) static void set_sub_anchor(regex_t* reg, OptAnc* anc) { - reg->sub_anchor |= anc->left & ANCHOR_BEGIN_LINE; - reg->sub_anchor |= anc->right & ANCHOR_END_LINE; + reg->sub_anchor |= anc->left & ANCR_BEGIN_LINE; + reg->sub_anchor |= anc->right & ANCR_END_LINE; } #if defined(ONIG_DEBUG_COMPILE) || defined(ONIG_DEBUG_MATCH) @@ -5776,17 +5776,17 @@ set_optimize_info_from_tree(Node* node, regex_t* reg, ScanEnv* scan_env) r = optimize_nodes(node, &opt, &env); if (r != 0) return r; - reg->anchor = opt.anc.left & (ANCHOR_BEGIN_BUF | - ANCHOR_BEGIN_POSITION | ANCHOR_ANYCHAR_INF | ANCHOR_ANYCHAR_INF_ML | - ANCHOR_LOOK_BEHIND); + reg->anchor = opt.anc.left & (ANCR_BEGIN_BUF | + ANCR_BEGIN_POSITION | ANCR_ANYCHAR_INF | ANCR_ANYCHAR_INF_ML | + ANCR_LOOK_BEHIND); - if ((opt.anc.left & (ANCHOR_LOOK_BEHIND | ANCHOR_PREC_READ_NOT)) != 0) - reg->anchor &= ~ANCHOR_ANYCHAR_INF_ML; + if ((opt.anc.left & (ANCR_LOOK_BEHIND | ANCR_PREC_READ_NOT)) != 0) + reg->anchor &= ~ANCR_ANYCHAR_INF_ML; - reg->anchor |= opt.anc.right & (ANCHOR_END_BUF | ANCHOR_SEMI_END_BUF | - ANCHOR_PREC_READ_NOT); + reg->anchor |= opt.anc.right & (ANCR_END_BUF | ANCR_SEMI_END_BUF | + ANCR_PREC_READ_NOT); - if (reg->anchor & (ANCHOR_END_BUF | ANCHOR_SEMI_END_BUF)) { + if (reg->anchor & (ANCR_END_BUF | ANCR_SEMI_END_BUF)) { reg->anchor_dmin = opt.len.min; reg->anchor_dmax = opt.len.max; } @@ -5807,9 +5807,9 @@ set_optimize_info_from_tree(Node* node, regex_t* reg, ScanEnv* scan_env) set_sub_anchor(reg, &opt.map.anc); } else { - reg->sub_anchor |= opt.anc.left & ANCHOR_BEGIN_LINE; + reg->sub_anchor |= opt.anc.left & ANCR_BEGIN_LINE; if (opt.len.max == 0) - reg->sub_anchor |= opt.anc.right & ANCHOR_END_LINE; + reg->sub_anchor |= opt.anc.right & ANCR_END_LINE; } #if defined(ONIG_DEBUG_COMPILE) || defined(ONIG_DEBUG_MATCH) @@ -5896,41 +5896,41 @@ print_anchor(FILE* f, int anchor) fprintf(f, "["); - if (anchor & ANCHOR_BEGIN_BUF) { + if (anchor & ANCR_BEGIN_BUF) { fprintf(f, "begin-buf"); q = 1; } - if (anchor & ANCHOR_BEGIN_LINE) { + if (anchor & ANCR_BEGIN_LINE) { if (q) fprintf(f, ", "); q = 1; fprintf(f, "begin-line"); } - if (anchor & ANCHOR_BEGIN_POSITION) { + if (anchor & ANCR_BEGIN_POSITION) { if (q) fprintf(f, ", "); q = 1; fprintf(f, "begin-pos"); } - if (anchor & ANCHOR_END_BUF) { + if (anchor & ANCR_END_BUF) { if (q) fprintf(f, ", "); q = 1; fprintf(f, "end-buf"); } - if (anchor & ANCHOR_SEMI_END_BUF) { + if (anchor & ANCR_SEMI_END_BUF) { if (q) fprintf(f, ", "); q = 1; fprintf(f, "semi-end-buf"); } - if (anchor & ANCHOR_END_LINE) { + if (anchor & ANCR_END_LINE) { if (q) fprintf(f, ", "); q = 1; fprintf(f, "end-line"); } - if (anchor & ANCHOR_ANYCHAR_INF) { + if (anchor & ANCR_ANYCHAR_INF) { if (q) fprintf(f, ", "); q = 1; fprintf(f, "anychar-inf"); } - if (anchor & ANCHOR_ANYCHAR_INF_ML) { + if (anchor & ANCR_ANYCHAR_INF_ML) { if (q) fprintf(f, ", "); fprintf(f, "anychar-inf-ml"); } @@ -5947,7 +5947,7 @@ print_optimize_info(FILE* f, regex_t* reg) fprintf(f, "optimize: %s\n", on[reg->optimize]); fprintf(f, " anchor: "); print_anchor(f, reg->anchor); - if ((reg->anchor & ANCHOR_END_BUF_MASK) != 0) + if ((reg->anchor & ANCR_END_BUF_MASK) != 0) print_distance_range(f, reg->anchor_dmin, reg->anchor_dmax); fprintf(f, "\n"); @@ -6619,36 +6619,36 @@ print_indent_tree(FILE* f, Node* node, int indent) case NODE_ANCHOR: fprintf(f, " ", node); switch (ANCHOR_(node)->type) { - case ANCHOR_BEGIN_BUF: fputs("begin buf", f); break; - case ANCHOR_END_BUF: fputs("end buf", f); break; - case ANCHOR_BEGIN_LINE: fputs("begin line", f); break; - case ANCHOR_END_LINE: fputs("end line", f); break; - case ANCHOR_SEMI_END_BUF: fputs("semi end buf", f); break; - case ANCHOR_BEGIN_POSITION: fputs("begin position", f); break; - - case ANCHOR_WORD_BOUNDARY: fputs("word boundary", f); break; - case ANCHOR_NO_WORD_BOUNDARY: fputs("not word boundary", f); break; + case ANCR_BEGIN_BUF: fputs("begin buf", f); break; + case ANCR_END_BUF: fputs("end buf", f); break; + case ANCR_BEGIN_LINE: fputs("begin line", f); break; + case ANCR_END_LINE: fputs("end line", f); break; + case ANCR_SEMI_END_BUF: fputs("semi end buf", f); break; + case ANCR_BEGIN_POSITION: fputs("begin position", f); break; + + case ANCR_WORD_BOUNDARY: fputs("word boundary", f); break; + case ANCR_NO_WORD_BOUNDARY: fputs("not word boundary", f); break; #ifdef USE_WORD_BEGIN_END - case ANCHOR_WORD_BEGIN: fputs("word begin", f); break; - case ANCHOR_WORD_END: fputs("word end", f); break; + case ANCR_WORD_BEGIN: fputs("word begin", f); break; + case ANCR_WORD_END: fputs("word end", f); break; #endif - case ANCHOR_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY: + case ANCR_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY: fputs("extended-grapheme-cluster boundary", f); break; - case ANCHOR_NO_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY: + case ANCR_NO_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY: fputs("no-extended-grapheme-cluster boundary", f); break; - case ANCHOR_PREC_READ: + case ANCR_PREC_READ: fprintf(f, "prec read\n"); print_indent_tree(f, NODE_BODY(node), indent + add); break; - case ANCHOR_PREC_READ_NOT: + case ANCR_PREC_READ_NOT: fprintf(f, "prec read not\n"); print_indent_tree(f, NODE_BODY(node), indent + add); break; - case ANCHOR_LOOK_BEHIND: + case ANCR_LOOK_BEHIND: fprintf(f, "look behind\n"); print_indent_tree(f, NODE_BODY(node), indent + add); break; - case ANCHOR_LOOK_BEHIND_NOT: + case ANCR_LOOK_BEHIND_NOT: fprintf(f, "look behind not\n"); print_indent_tree(f, NODE_BODY(node), indent + add); break; diff --git a/src/regexec.c b/src/regexec.c index d34f0e7..43b2e2c 100644 --- a/src/regexec.c +++ b/src/regexec.c @@ -4410,7 +4410,7 @@ forward_search_range(regex_t* reg, const UChar* str, const UChar* end, UChar* s, UChar* prev; switch (reg->sub_anchor) { - case ANCHOR_BEGIN_LINE: + case ANCR_BEGIN_LINE: if (!ON_STR_BEGIN(p)) { prev = onigenc_get_prev_char_head(reg->enc, (pprev ? pprev : str), p); @@ -4419,7 +4419,7 @@ forward_search_range(regex_t* reg, const UChar* str, const UChar* end, UChar* s, } break; - case ANCHOR_END_LINE: + case ANCR_END_LINE: if (ON_STR_END(p)) { #ifndef USE_NEWLINE_AT_END_OF_STRING_HAS_EMPTY_LINE prev = (UChar* )onigenc_get_prev_char_head(reg->enc, @@ -4529,7 +4529,7 @@ backward_search_range(regex_t* reg, const UChar* str, const UChar* end, UChar* prev; switch (reg->sub_anchor) { - case ANCHOR_BEGIN_LINE: + case ANCR_BEGIN_LINE: if (!ON_STR_BEGIN(p)) { prev = onigenc_get_prev_char_head(reg->enc, str, p); if (IS_NOT_NULL(prev) && !ONIGENC_IS_MBC_NEWLINE(reg->enc, prev, end)) { @@ -4539,7 +4539,7 @@ backward_search_range(regex_t* reg, const UChar* str, const UChar* end, } break; - case ANCHOR_END_LINE: + case ANCR_END_LINE: if (ON_STR_END(p)) { #ifndef USE_NEWLINE_AT_END_OF_STRING_HAS_EMPTY_LINE prev = onigenc_get_prev_char_head(reg->enc, adjrange, p); @@ -4665,7 +4665,7 @@ onig_search_with_param(regex_t* reg, const UChar* str, const UChar* end, if (reg->anchor != 0 && str < end) { UChar *min_semi_end, *max_semi_end; - if (reg->anchor & ANCHOR_BEGIN_POSITION) { + if (reg->anchor & ANCR_BEGIN_POSITION) { /* search start-position only */ begin_position: if (range > start) @@ -4673,7 +4673,7 @@ onig_search_with_param(regex_t* reg, const UChar* str, const UChar* end, else range = start; } - else if (reg->anchor & ANCHOR_BEGIN_BUF) { + else if (reg->anchor & ANCR_BEGIN_BUF) { /* search str-position only */ if (range > start) { if (start != str) goto mismatch_no_msa; @@ -4688,7 +4688,7 @@ onig_search_with_param(regex_t* reg, const UChar* str, const UChar* end, goto mismatch_no_msa; } } - else if (reg->anchor & ANCHOR_END_BUF) { + else if (reg->anchor & ANCR_END_BUF) { min_semi_end = max_semi_end = (UChar* )end; end_buf: @@ -4720,7 +4720,7 @@ onig_search_with_param(regex_t* reg, const UChar* str, const UChar* end, if (range > start) goto mismatch_no_msa; } } - else if (reg->anchor & ANCHOR_SEMI_END_BUF) { + else if (reg->anchor & ANCR_SEMI_END_BUF) { UChar* pre_end = ONIGENC_STEP_BACK(reg->enc, str, end, 1); max_semi_end = (UChar* )end; @@ -4743,7 +4743,7 @@ onig_search_with_param(regex_t* reg, const UChar* str, const UChar* end, goto end_buf; } } - else if ((reg->anchor & ANCHOR_ANYCHAR_INF_ML)) { + else if ((reg->anchor & ANCR_ANYCHAR_INF_ML)) { goto begin_position; } } @@ -4816,13 +4816,13 @@ onig_search_with_param(regex_t* reg, const UChar* str, const UChar* end, if (! forward_search_range(reg, str, end, s, sch_range, &low, &high, (UChar** )NULL)) goto mismatch; - if ((reg->anchor & ANCHOR_ANYCHAR_INF) != 0) { + if ((reg->anchor & ANCR_ANYCHAR_INF) != 0) { do { MATCH_AND_RETURN_CHECK(orig_range); prev = s; s += enclen(reg->enc, s); - if ((reg->anchor & (ANCHOR_LOOK_BEHIND | ANCHOR_PREC_READ_NOT)) == 0) { + if ((reg->anchor & (ANCR_LOOK_BEHIND | ANCR_PREC_READ_NOT)) == 0) { while (!ONIGENC_IS_MBC_NEWLINE(reg->enc, prev, end) && s < range) { prev = s; s += enclen(reg->enc, s); diff --git a/src/regint.h b/src/regint.h index 89622c9..f0324a3 100644 --- a/src/regint.h +++ b/src/regint.h @@ -506,32 +506,32 @@ typedef struct _BBuf { /* has body */ -#define ANCHOR_PREC_READ (1<<0) -#define ANCHOR_PREC_READ_NOT (1<<1) -#define ANCHOR_LOOK_BEHIND (1<<2) -#define ANCHOR_LOOK_BEHIND_NOT (1<<3) +#define ANCR_PREC_READ (1<<0) +#define ANCR_PREC_READ_NOT (1<<1) +#define ANCR_LOOK_BEHIND (1<<2) +#define ANCR_LOOK_BEHIND_NOT (1<<3) /* no body */ -#define ANCHOR_BEGIN_BUF (1<<4) -#define ANCHOR_BEGIN_LINE (1<<5) -#define ANCHOR_BEGIN_POSITION (1<<6) -#define ANCHOR_END_BUF (1<<7) -#define ANCHOR_SEMI_END_BUF (1<<8) -#define ANCHOR_END_LINE (1<<9) -#define ANCHOR_WORD_BOUNDARY (1<<10) -#define ANCHOR_NO_WORD_BOUNDARY (1<<11) -#define ANCHOR_WORD_BEGIN (1<<12) -#define ANCHOR_WORD_END (1<<13) -#define ANCHOR_ANYCHAR_INF (1<<14) -#define ANCHOR_ANYCHAR_INF_ML (1<<15) -#define ANCHOR_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY (1<<16) -#define ANCHOR_NO_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY (1<<17) - - -#define ANCHOR_HAS_BODY(a) ((a)->type < ANCHOR_BEGIN_BUF) +#define ANCR_BEGIN_BUF (1<<4) +#define ANCR_BEGIN_LINE (1<<5) +#define ANCR_BEGIN_POSITION (1<<6) +#define ANCR_END_BUF (1<<7) +#define ANCR_SEMI_END_BUF (1<<8) +#define ANCR_END_LINE (1<<9) +#define ANCR_WORD_BOUNDARY (1<<10) +#define ANCR_NO_WORD_BOUNDARY (1<<11) +#define ANCR_WORD_BEGIN (1<<12) +#define ANCR_WORD_END (1<<13) +#define ANCR_ANYCHAR_INF (1<<14) +#define ANCR_ANYCHAR_INF_ML (1<<15) +#define ANCR_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY (1<<16) +#define ANCR_NO_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY (1<<17) + + +#define ANCHOR_HAS_BODY(a) ((a)->type < ANCR_BEGIN_BUF) #define IS_WORD_ANCHOR_TYPE(type) \ - ((type) == ANCHOR_WORD_BOUNDARY || (type) == ANCHOR_NO_WORD_BOUNDARY || \ - (type) == ANCHOR_WORD_BEGIN || (type) == ANCHOR_WORD_END) + ((type) == ANCR_WORD_BOUNDARY || (type) == ANCR_NO_WORD_BOUNDARY || \ + (type) == ANCR_WORD_BEGIN || (type) == ANCR_WORD_END) /* operation code */ enum OpCode { diff --git a/src/regparse.c b/src/regparse.c index 21a8b7c..b6769fd 100644 --- a/src/regparse.c +++ b/src/regparse.c @@ -2645,7 +2645,7 @@ make_extended_grapheme_cluster(Node** node, ScanEnv* env) ns[1] = NULL_NODE; r = ONIGERR_MEMORY; - ns[0] = onig_node_new_anchor(ANCHOR_NO_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY, 0); + ns[0] = onig_node_new_anchor(ANCR_NO_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY, 0); if (IS_NULL(ns[0])) goto err; r = node_new_true_anychar(&ns[1], env); @@ -4999,38 +4999,38 @@ fetch_token(OnigToken* tok, UChar** src, UChar* end, ScanEnv* env) case 'b': if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_B_WORD_BOUND)) break; tok->type = TK_ANCHOR; - tok->u.anchor = ANCHOR_WORD_BOUNDARY; + tok->u.anchor = ANCR_WORD_BOUNDARY; break; case 'B': if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_B_WORD_BOUND)) break; tok->type = TK_ANCHOR; - tok->u.anchor = ANCHOR_NO_WORD_BOUNDARY; + tok->u.anchor = ANCR_NO_WORD_BOUNDARY; break; case 'y': if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP2_ESC_X_Y_GRAPHEME_CLUSTER)) break; tok->type = TK_ANCHOR; - tok->u.anchor = ANCHOR_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY; + tok->u.anchor = ANCR_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY; break; case 'Y': if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP2_ESC_X_Y_GRAPHEME_CLUSTER)) break; tok->type = TK_ANCHOR; - tok->u.anchor = ANCHOR_NO_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY; + tok->u.anchor = ANCR_NO_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY; break; #ifdef USE_WORD_BEGIN_END case '<': if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END)) break; tok->type = TK_ANCHOR; - tok->u.anchor = ANCHOR_WORD_BEGIN; + tok->u.anchor = ANCR_WORD_BEGIN; break; case '>': if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END)) break; tok->type = TK_ANCHOR; - tok->u.anchor = ANCHOR_WORD_END; + tok->u.anchor = ANCR_WORD_END; break; #endif @@ -5105,26 +5105,26 @@ fetch_token(OnigToken* tok, UChar** src, UChar* end, ScanEnv* env) if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR)) break; begin_buf: tok->type = TK_ANCHOR; - tok->u.subtype = ANCHOR_BEGIN_BUF; + tok->u.subtype = ANCR_BEGIN_BUF; break; case 'Z': if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR)) break; tok->type = TK_ANCHOR; - tok->u.subtype = ANCHOR_SEMI_END_BUF; + tok->u.subtype = ANCR_SEMI_END_BUF; break; case 'z': if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR)) break; end_buf: tok->type = TK_ANCHOR; - tok->u.subtype = ANCHOR_END_BUF; + tok->u.subtype = ANCR_END_BUF; break; case 'G': if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_ESC_CAPITAL_G_BEGIN_ANCHOR)) break; tok->type = TK_ANCHOR; - tok->u.subtype = ANCHOR_BEGIN_POSITION; + tok->u.subtype = ANCR_BEGIN_POSITION; break; case '`': @@ -5619,14 +5619,14 @@ fetch_token(OnigToken* tok, UChar** src, UChar* end, ScanEnv* env) if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_LINE_ANCHOR)) break; tok->type = TK_ANCHOR; tok->u.subtype = (IS_SINGLELINE(env->options) - ? ANCHOR_BEGIN_BUF : ANCHOR_BEGIN_LINE); + ? ANCR_BEGIN_BUF : ANCR_BEGIN_LINE); break; case '$': if (! IS_SYNTAX_OP(syn, ONIG_SYN_OP_LINE_ANCHOR)) break; tok->type = TK_ANCHOR; tok->u.subtype = (IS_SINGLELINE(env->options) - ? ANCHOR_SEMI_END_BUF : ANCHOR_END_LINE); + ? ANCR_SEMI_END_BUF : ANCR_END_LINE); break; case '[': @@ -7014,10 +7014,10 @@ parse_bag(Node** np, OnigToken* tok, int term, UChar** src, UChar* end, break; case '=': - *np = onig_node_new_anchor(ANCHOR_PREC_READ, 0); + *np = onig_node_new_anchor(ANCR_PREC_READ, 0); break; case '!': /* preceding read */ - *np = onig_node_new_anchor(ANCHOR_PREC_READ_NOT, 0); + *np = onig_node_new_anchor(ANCR_PREC_READ_NOT, 0); break; case '>': /* (?>...) stop backtrack */ *np = node_new_bag(BAG_STOP_BACKTRACK); @@ -7035,9 +7035,9 @@ parse_bag(Node** np, OnigToken* tok, int term, UChar** src, UChar* end, if (PEND) return ONIGERR_END_PATTERN_WITH_UNMATCHED_PARENTHESIS; PFETCH(c); if (c == '=') - *np = onig_node_new_anchor(ANCHOR_LOOK_BEHIND, 0); + *np = onig_node_new_anchor(ANCR_LOOK_BEHIND, 0); else if (c == '!') - *np = onig_node_new_anchor(ANCHOR_LOOK_BEHIND_NOT, 0); + *np = onig_node_new_anchor(ANCR_LOOK_BEHIND_NOT, 0); else { if (IS_SYNTAX_OP2(env->syntax, ONIG_SYN_OP2_QMARK_LT_NAMED_GROUP)) { UChar *name; diff --git a/src/regparse.h b/src/regparse.h index 91095fe..bb8a6a5 100644 --- a/src/regparse.h +++ b/src/regparse.h @@ -283,8 +283,8 @@ typedef struct _Node { (NODE_IS_FIXED_OPTION(node) ? CTYPE_(node)->options : reg->options) -#define ANCHOR_ANYCHAR_INF_MASK (ANCHOR_ANYCHAR_INF | ANCHOR_ANYCHAR_INF_ML) -#define ANCHOR_END_BUF_MASK (ANCHOR_END_BUF | ANCHOR_SEMI_END_BUF) +#define ANCR_ANYCHAR_INF_MASK (ANCR_ANYCHAR_INF | ANCR_ANYCHAR_INF_ML) +#define ANCR_END_BUF_MASK (ANCR_END_BUF | ANCR_SEMI_END_BUF) #define NODE_STRING_RAW (1<<0) /* by backslashed number */ #define NODE_STRING_AMBIG (1<<1) -- 2.40.0