]> granicus.if.org Git - onig/commitdiff
refactoring
authorK.Kosako <kosako@sofnec.co.jp>
Tue, 15 Oct 2019 00:31:39 +0000 (09:31 +0900)
committerK.Kosako <kosako@sofnec.co.jp>
Mon, 21 Oct 2019 00:54:06 +0000 (09:54 +0900)
src/regcomp.c
src/regparse.c
src/regparse.h

index 79e05ed886dcc70b3885da8257737e2c85deffed..95526d1b57f7b6dae17a9e0ffa97e50eaafa2bbb 100644 (file)
@@ -803,7 +803,7 @@ compile_length_string_node(Node* node, regex_t* reg)
 }
 
 static int
-compile_length_string_raw_node(StrNode* sn, regex_t* reg)
+compile_length_string_crude_node(StrNode* sn, regex_t* reg)
 {
   if (sn->end <= sn->s)
     return 0;
@@ -890,7 +890,7 @@ compile_string_node(Node* node, regex_t* reg)
 }
 
 static int
-compile_string_raw_node(StrNode* sn, regex_t* reg)
+compile_string_crude_node(StrNode* sn, regex_t* reg)
 {
   if (sn->end <= sn->s)
     return 0;
@@ -1893,8 +1893,8 @@ compile_length_tree(Node* node, regex_t* reg)
     break;
 
   case NODE_STRING:
-    if (NODE_STRING_IS_RAW(node))
-      r = compile_length_string_raw_node(STR_(node), reg);
+    if (NODE_STRING_IS_CRUDE(node))
+      r = compile_length_string_crude_node(STR_(node), reg);
     else
       r = compile_length_string_node(node, reg);
     break;
@@ -1986,8 +1986,8 @@ compile_tree(Node* node, regex_t* reg, ScanEnv* env)
     break;
 
   case NODE_STRING:
-    if (NODE_STRING_IS_RAW(node))
-      r = compile_string_raw_node(STR_(node), reg);
+    if (NODE_STRING_IS_CRUDE(node))
+      r = compile_string_crude_node(STR_(node), reg);
     else
       r = compile_string_node(node, reg);
     break;
@@ -2810,7 +2810,7 @@ get_head_value_node(Node* node, int exact, regex_t* reg)
         break;
 
       if (exact == 0 ||
-          ! IS_IGNORECASE(reg->options) || NODE_STRING_IS_RAW(node)) {
+          ! IS_IGNORECASE(reg->options) || NODE_STRING_IS_CRUDE(node)) {
         n = node;
       }
     }
@@ -4991,7 +4991,7 @@ setup_tree(Node* node, regex_t* reg, int state, ScanEnv* env)
     break;
 
   case NODE_STRING:
-    if (IS_IGNORECASE(reg->options) && !NODE_STRING_IS_RAW(node)) {
+    if (IS_IGNORECASE(reg->options) && !NODE_STRING_IS_CRUDE(node)) {
       r = expand_case_fold_string(node, reg, state);
     }
     break;
@@ -5839,7 +5839,6 @@ optimize_nodes(Node* node, OptNode* opt, OptEnv* env)
     {
       StrNode* sn = STR_(node);
       int slen = (int )(sn->end - sn->s);
-      /* int is_raw = NODE_STRING_IS_RAW(node); */
 
       if (! NODE_STRING_IS_CASE_FOLD_MATCH(node)) {
         concat_opt_exact_str(&opt->sb, sn->s, sn->end, enc);
@@ -7062,8 +7061,8 @@ print_indent_tree(FILE* f, Node* node, int indent)
       char* dont;
       char* good;
 
-      if (NODE_STRING_IS_RAW(node))
-        mode = "-raw";
+      if (NODE_STRING_IS_CRUDE(node))
+        mode = "-crude";
       else if (NODE_STRING_IS_CASE_FOLD_MATCH(node))
         mode = "-case_fold_match";
       else
index 700285469ee864a4a63661abc7a8590da45fc577..932d1070042082dc8e2b7474f8daf5ed4723f261 100644 (file)
@@ -3227,11 +3227,11 @@ onig_node_new_str(const UChar* s, const UChar* end)
 }
 
 static Node*
-node_new_str_raw(UChar* s, UChar* end)
+node_new_str_crude(UChar* s, UChar* end)
 {
   Node* node = node_new_str(s, end);
   CHECK_NULL_RETURN(node);
-  NODE_STRING_SET_RAW(node);
+  NODE_STRING_SET_CRUDE(node);
   return node;
 }
 
@@ -3242,14 +3242,14 @@ node_new_empty(void)
 }
 
 static Node*
-node_new_str_raw_char(UChar c)
+node_new_str_crude_char(UChar c)
 {
   int i;
   UChar p[1];
   Node* node;
 
   p[0] = c;
-  node = node_new_str_raw(p, p + 1);
+  node = node_new_str_crude(p, p + 1);
 
   /* clear buf tail */
   for (i = 1; i < NODE_STRING_BUF_SIZE; i++)
@@ -3272,8 +3272,8 @@ str_node_split_last_char(Node* node, OnigEncoding enc)
     if (p && p > sn->s) { /* can be split. */
       rn = node_new_str(p, sn->end);
       CHECK_NULL_RETURN(rn);
-      if (NODE_STRING_IS_RAW(node))
-        NODE_STRING_SET_RAW(rn);
+      if (NODE_STRING_IS_CRUDE(node))
+        NODE_STRING_SET_CRUDE(rn);
 
       sn->end = (UChar* )p;
     }
@@ -4004,7 +4004,7 @@ node_new_general_newline(Node** node, ScanEnv* env)
   alen = ONIGENC_CODE_TO_MBC(env->enc, 0x0a, buf + dlen);
   if (alen < 0) return alen;
 
-  crnl = node_new_str_raw(buf, buf + dlen + alen);
+  crnl = node_new_str_crude(buf, buf + dlen + alen);
   CHECK_NULL_RETURN_MEMERR(crnl);
 
   ncc = node_new_cclass();
@@ -4041,7 +4041,7 @@ node_new_general_newline(Node** node, ScanEnv* env)
 
 enum TokenSyms {
   TK_EOT      = 0,   /* end of token */
-  TK_RAW_BYTE = 1,
+  TK_CRUDE_BYTE = 1,
   TK_CHAR,
   TK_STRING,
   TK_CODE_POINT,
@@ -4843,7 +4843,7 @@ fetch_token_in_cc(PToken* tok, UChar** src, UChar* end, ScanEnv* env)
         if (p == prev) {  /* can't read nothing. */
           code = 0; /* but, it's not error */
         }
-        tok->type = TK_RAW_BYTE;
+        tok->type = TK_CRUDE_BYTE;
         tok->base = 16;
         tok->u.byte = (UChar )code;
       }
@@ -4876,7 +4876,7 @@ fetch_token_in_cc(PToken* tok, UChar** src, UChar* end, ScanEnv* env)
         if (p == prev) {  /* can't read nothing. */
           code = 0; /* but, it's not error */
         }
-        tok->type = TK_RAW_BYTE;
+        tok->type = TK_CRUDE_BYTE;
         tok->base = 8;
         tok->u.byte = (UChar )code;
       }
@@ -5246,7 +5246,7 @@ fetch_token(PToken* tok, UChar** src, UChar* end, ScanEnv* env)
         if (p == prev) {  /* can't read nothing. */
           code = 0; /* but, it's not error */
         }
-        tok->type = TK_RAW_BYTE;
+        tok->type = TK_CRUDE_BYTE;
         tok->base = 16;
         tok->u.byte = (UChar )code;
       }
@@ -5311,7 +5311,7 @@ fetch_token(PToken* tok, UChar** src, UChar* end, ScanEnv* env)
         if (p == prev) {  /* can't read nothing. */
           code = 0; /* but, it's not error */
         }
-        tok->type = TK_RAW_BYTE;
+        tok->type = TK_CRUDE_BYTE;
         tok->base = 8;
         tok->u.byte = (UChar )code;
       }
@@ -5464,7 +5464,6 @@ fetch_token(PToken* tok, UChar** src, UChar* end, ScanEnv* env)
         PUNFETCH;
         r = fetch_escaped_value(&p, end, env, &c2);
         if (r < 0) return r;
-        /* set_raw: */
         if (tok->u.code != c2) {
           tok->type = TK_CODE_POINT;
           tok->u.code = c2;
@@ -6297,7 +6296,7 @@ parse_cc(Node** np, PToken* tok, UChar** src, UChar* end, ScanEnv* env)
       goto val_entry2;
       break;
 
-    case TK_RAW_BYTE:
+    case TK_CRUDE_BYTE:
       /* tok->base != 0 : octal or hexadec. */
       if (! ONIGENC_IS_SINGLEBYTE(env->enc) && tok->base != 0) {
         int i, j;
@@ -6310,7 +6309,7 @@ parse_cc(Node** np, PToken* tok, UChar** src, UChar* end, ScanEnv* env)
         for (i = 1; i < ONIGENC_MBC_MAXLEN(env->enc); i++) {
           r = fetch_token_in_cc(tok, &p, end, env);
           if (r < 0) goto err;
-          if (r != TK_RAW_BYTE || tok->base != base) {
+          if (r != TK_CRUDE_BYTE || tok->base != base) {
             fetched = 1;
             break;
           }
@@ -6340,7 +6339,7 @@ parse_cc(Node** np, PToken* tok, UChar** src, UChar* end, ScanEnv* env)
 
         if (i == 1) {
           in_code = (OnigCodePoint )buf[0];
-          goto raw_single;
+          goto crude_single;
         }
         else {
           in_code = ONIGENC_MBC_TO_CODE(env->enc, buf, bufe);
@@ -6349,7 +6348,7 @@ parse_cc(Node** np, PToken* tok, UChar** src, UChar* end, ScanEnv* env)
       }
       else {
         in_code = (OnigCodePoint )tok->u.byte;
-      raw_single:
+      crude_single:
         in_type = CV_SB;
       }
       in_raw = 1;
@@ -7942,7 +7941,7 @@ parse_exp(Node** np, PToken* tok, int term, UChar** src, UChar* end,
     if (! IS_SYNTAX_BV(env->syntax, ONIG_SYN_ALLOW_UNMATCHED_CLOSE_SUBEXP))
       return ONIGERR_UNMATCHED_CLOSE_PARENTHESIS;
 
-    if (tok->escaped) goto tk_raw_byte;
+    if (tok->escaped) goto tk_crude_byte;
     else goto tk_byte;
     break;
 
@@ -7967,23 +7966,23 @@ parse_exp(Node** np, PToken* tok, int term, UChar** src, UChar* end,
     }
     break;
 
-  case TK_RAW_BYTE:
-  tk_raw_byte:
+  case TK_CRUDE_BYTE:
+  tk_crude_byte:
     {
-      *np = node_new_str_raw_char(tok->u.byte);
+      *np = node_new_str_crude_char(tok->u.byte);
       CHECK_NULL_RETURN_MEMERR(*np);
       len = 1;
       while (1) {
         if (len >= ONIGENC_MBC_MINLEN(env->enc)) {
           if (len == enclen(env->enc, STR_(*np)->s)) {
             r = fetch_token(tok, src, end, env);
-            goto tk_raw_byte_end;
+            goto tk_crude_byte_end;
           }
         }
 
         r = fetch_token(tok, src, end, env);
         if (r < 0) return r;
-        if (r != TK_RAW_BYTE)
+        if (r != TK_CRUDE_BYTE)
           return ONIGERR_TOO_SHORT_MULTI_BYTE_STRING;
 
         r = node_str_cat_char(*np, tok->u.byte);
@@ -7992,11 +7991,11 @@ parse_exp(Node** np, PToken* tok, int term, UChar** src, UChar* end,
         len++;
       }
 
-    tk_raw_byte_end:
+    tk_crude_byte_end:
       if (! ONIGENC_IS_VALID_MBC_STRING(env->enc, STR_(*np)->s, STR_(*np)->end))
         return ONIGERR_INVALID_WIDE_CHAR_VALUE;
 
-      NODE_STRING_CLEAR_RAW(*np);
+      NODE_STRING_CLEAR_CRUDE(*np);
       goto string_end;
     }
     break;
@@ -8007,7 +8006,7 @@ parse_exp(Node** np, PToken* tok, int term, UChar** src, UChar* end,
       len = ONIGENC_CODE_TO_MBC(env->enc, tok->u.code, buf);
       if (len < 0) return len;
 #ifdef NUMBERED_CHAR_IS_NOT_CASE_AMBIG
-      *np = node_new_str_raw(buf, buf + len);
+      *np = node_new_str_crude(buf, buf + len);
 #else
       *np = node_new_str(buf, buf + len);
 #endif
index 08811c240c1d9f9e6b97e6447d17c01a76875cd6..5cd07bdb6e06d9f54d63a15883d890d265b3f811 100644 (file)
@@ -293,22 +293,22 @@ typedef struct _Node {
 #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_CRUDE              (1<<0)
 #define NODE_STRING_CASE_EXPANDED      (1<<1)
 #define NODE_STRING_CASE_FOLD_MATCH    (1<<2)
 #define NODE_STRING_GOOD_AMBIG         (1<<3)
 #define NODE_STRING_DONT_GET_OPT_INFO  (1<<4)
 
 #define NODE_STRING_LEN(node)            (int )((node)->u.str.end - (node)->u.str.s)
-#define NODE_STRING_SET_RAW(node)           (node)->u.str.flag |= NODE_STRING_RAW
-#define NODE_STRING_CLEAR_RAW(node)         (node)->u.str.flag &= ~NODE_STRING_RAW
+#define NODE_STRING_SET_CRUDE(node)         (node)->u.str.flag |= NODE_STRING_CRUDE
+#define NODE_STRING_CLEAR_CRUDE(node)       (node)->u.str.flag &= ~NODE_STRING_CRUDE
 #define NODE_STRING_SET_CASE_EXPANDED(node) (node)->u.str.flag |= NODE_STRING_CASE_EXPANDED
 #define NODE_STRING_SET_CASE_FOLD_MATCH(node) (node)->u.str.flag |= NODE_STRING_CASE_FOLD_MATCH
 #define NODE_STRING_SET_GOOD_AMBIG(node) (node)->u.str.flag |= NODE_STRING_GOOD_AMBIG
 #define NODE_STRING_SET_DONT_GET_OPT_INFO(node) \
   (node)->u.str.flag |= NODE_STRING_DONT_GET_OPT_INFO
-#define NODE_STRING_IS_RAW(node) \
-  (((node)->u.str.flag & NODE_STRING_RAW) != 0)
+#define NODE_STRING_IS_CRUDE(node) \
+  (((node)->u.str.flag & NODE_STRING_CRUDE) != 0)
 #define NODE_STRING_IS_CASE_EXPANDED(node) \
   (((node)->u.str.flag & NODE_STRING_CASE_EXPANDED) != 0)
 #define NODE_STRING_IS_CASE_FOLD_MATCH(node) \
@@ -446,7 +446,7 @@ extern int    onig_strncmp P_((const UChar* s1, const UChar* s2, int n));
 extern void   onig_strcpy P_((UChar* dest, const UChar* src, const UChar* end));
 extern void   onig_scan_env_set_error_string P_((ScanEnv* env, int ecode, UChar* arg, UChar* arg_end));
 extern void   onig_reduce_nested_quantifier P_((Node* pnode, Node* cnode));
-extern void   onig_node_conv_to_str_node P_((Node* node, int raw));
+extern void   onig_node_conv_to_str_node P_((Node* node, int flag));
 extern int    onig_node_str_cat P_((Node* node, const UChar* s, const UChar* end));
 extern int    onig_node_str_set P_((Node* node, const UChar* s, const UChar* end));
 extern void   onig_node_free P_((Node* node));