From: Gabriel Caruso Date: Thu, 13 Sep 2018 00:45:46 +0000 (-0300) Subject: Simplify returns and ternary expressions X-Git-Tag: v6.9.1~26^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=577ed49a154675a01e6ea180680e998f2afd0e01;p=onig Simplify returns and ternary expressions --- diff --git a/src/regcomp.c b/src/regcomp.c index 6405541..4512feb 100644 --- a/src/regcomp.c +++ b/src/regcomp.c @@ -2466,7 +2466,7 @@ is_exclusive(Node* x, Node* y, regex_t* reg) code = ONIGENC_MBC_TO_CODE(reg->enc, xs->s, xs->s + ONIGENC_MBC_MAXLEN(reg->enc)); - return (onig_is_code_in_cc(reg->enc, code, cc) != 0 ? 0 : 1); + return onig_is_code_in_cc(reg->enc, code, cc) == 0; } break; @@ -4698,7 +4698,7 @@ comp_distance_value(MinMax* d1, MinMax* d2, int v1, int v2) static int is_equal_mml(MinMax* a, MinMax* b) { - return (a->min == b->min && a->max == b->max) ? 1 : 0; + return a->min == b->min && a->max == b->max; } static void @@ -4820,7 +4820,7 @@ alt_merge_opt_anc_info(OptAnc* to, OptAnc* add) static int is_full_opt_exact(OptExact* e) { - return (e->len >= OPT_EXACT_MAXLEN ? 1 : 0); + return e->len >= OPT_EXACT_MAXLEN; } static void @@ -6323,11 +6323,11 @@ onig_is_code_in_cc_len(int elen, OnigCodePoint code, /* CClassNode* */ void* cc_ found = 0; } else { - found = (onig_is_in_code_range(cc->mbuf->p, code) != 0 ? 1 : 0); + found = onig_is_in_code_range(cc->mbuf->p, code) != 0; } } else { - found = (BITSET_AT(cc->bs, code) == 0 ? 0 : 1); + found = BITSET_AT(cc->bs, code) != 0; } if (IS_NCCLASS_NOT(cc)) diff --git a/src/regerror.c b/src/regerror.c index 53bd80d..2f3a27e 100644 --- a/src/regerror.c +++ b/src/regerror.c @@ -247,7 +247,7 @@ static int to_ascii(OnigEncoding enc, UChar *s, UChar *end, if (len >= buf_size) break; } - *is_over = ((p < end) ? 1 : 0); + *is_over = p < end; } else { len = MIN((int )(end - s), buf_size); diff --git a/src/regparse.c b/src/regparse.c index edca44e..597a163 100644 --- a/src/regparse.c +++ b/src/regparse.c @@ -1761,7 +1761,7 @@ onig_callout_tag_is_exist_at_callout_num(regex_t* reg, int callout_num) if (callout_num > ext->callout_num) return 0; return (ext->callout_list[callout_num].flag & - CALLOUT_TAG_LIST_FLAG_TAG_EXIST) != 0 ? 1 : 0; + CALLOUT_TAG_LIST_FLAG_TAG_EXIST) != 0; } static int @@ -4690,12 +4690,12 @@ fetch_token_in_cc(OnigToken* tok, UChar** src, UChar* end, ScanEnv* env) IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY)) { PINC; tok->type = TK_CHAR_PROPERTY; - tok->u.prop.not = (c == 'P' ? 1 : 0); + tok->u.prop.not = c == 'P'; if (!PEND && IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_P_BRACE_CIRCUMFLEX_NOT)) { PFETCH(c2); if (c2 == '^') { - tok->u.prop.not = (tok->u.prop.not == 0 ? 1 : 0); + tok->u.prop.not = tok->u.prop.not == 0; } else PUNFETCH; @@ -5371,13 +5371,13 @@ fetch_token(OnigToken* tok, UChar** src, UChar* end, ScanEnv* env) IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY)) { PINC; tok->type = TK_CHAR_PROPERTY; - tok->u.prop.not = (c == 'P' ? 1 : 0); + tok->u.prop.not = c == 'P'; if (!PEND && IS_SYNTAX_OP2(syn, ONIG_SYN_OP2_ESC_P_BRACE_CIRCUMFLEX_NOT)) { PFETCH(c); if (c == '^') { - tok->u.prop.not = (tok->u.prop.not == 0 ? 1 : 0); + tok->u.prop.not = tok->u.prop.not == 0; } else PUNFETCH; @@ -8016,7 +8016,7 @@ parse_exp(Node** np, OnigToken* tok, int term, UChar** src, UChar* end, return ONIGERR_TARGET_OF_REPEAT_OPERATOR_INVALID; qn = node_new_quantifier(tok->u.repeat.lower, tok->u.repeat.upper, - (r == TK_INTERVAL ? 1 : 0)); + r == TK_INTERVAL); CHECK_NULL_RETURN_MEMERR(qn); QUANT_(qn)->greedy = tok->u.repeat.greedy; r = set_quantifier(qn, *targetp, group, env); diff --git a/src/sjis.c b/src/sjis.c index d337bf0..f3cca2e 100644 --- a/src/sjis.c +++ b/src/sjis.c @@ -113,10 +113,7 @@ static int code_to_mbclen(OnigCodePoint code) { if (code < 256) { - if (EncLen_SJIS[(int )code] == 1) - return 1; - else - return 0; + return EncLen_SJIS[(int )code] == 1; } else if (code <= 0xffff) { return 2; diff --git a/src/unicode.c b/src/unicode.c index 56026f1..d438992 100644 --- a/src/unicode.c +++ b/src/unicode.c @@ -657,8 +657,7 @@ onigenc_egcb_is_break_position(OnigEncoding enc, UChar* p, UChar* prev, #ifdef USE_UNICODE_EXTENDED_GRAPHEME_CLUSTER if (! ONIGENC_IS_UNICODE_ENCODING(enc)) { - if (from == 0x000d && to == 0x000a) return 0; - else return 1; + return from != 0x000d || to != 0x000a; } btype = unicode_egcb_is_break_2code(from, to); @@ -701,8 +700,7 @@ onigenc_egcb_is_break_position(OnigEncoding enc, UChar* p, UChar* prev, return 1; #else - if (from == 0x000d && to == 0x000a) return 0; - else return 1; + return from != 0x000d || to != 0x000a; #endif /* USE_UNICODE_EXTENDED_GRAPHEME_CLUSTER */ }