Parse the interval body that starts at p[i], just past the opening brace * (`{` in extended syntax, `\{` in basic). On success stores the number of * copies the compiler will make (the upper bound, or the lower bound for * `{m,}`, at least 1) and the index just past the closing brace. Anything that * is not an interval leaves the brace to be counted as a literal, which is what * the backends
| 125 | * is not an interval leaves the brace to be counted as a literal, which is what |
| 126 | * the backends that accept it do; the others reject the pattern. */ |
| 127 | static bool regex_parse_interval(const char *p, size_t i, bool extended, uint64_t *copies, |
| 128 | size_t *end) { |
| 129 | uint64_t lower = 0; |
| 130 | uint64_t upper = 0; |
| 131 | bool has_lower = regex_parse_digits(p, &i, &lower); |
| 132 | bool has_upper = false; |
| 133 | if (p[i] == ',') { |
| 134 | i++; |
| 135 | has_upper = regex_parse_digits(p, &i, &upper); |
| 136 | } else { |
| 137 | if (!has_lower) { |
| 138 | return false; |
| 139 | } |
| 140 | upper = lower; |
| 141 | has_upper = true; |
| 142 | } |
| 143 | if (extended) { |
| 144 | if (p[i] != '}') { |
| 145 | return false; |
| 146 | } |
| 147 | i++; |
| 148 | } else { |
| 149 | if (p[i] != '\\' || p[i + 1] != '}') { |
| 150 | return false; |
| 151 | } |
| 152 | i += 2; |
| 153 | } |
| 154 | uint64_t n = has_upper ? upper : lower; |
| 155 | if (has_upper && lower > upper) { |
| 156 | n = lower; /* `{5,3}` is rejected by the backends; count the larger bound */ |
| 157 | } |
| 158 | *copies = n ? n : 1; |
| 159 | *end = i; |
| 160 | return true; |
| 161 | } |
| 162 | |
| 163 | uint64_t cbm_regcomp_estimate_units(const char *pattern, int flags) { |
| 164 | const bool extended = (flags & CBM_REG_EXTENDED) != 0; |
no test coverage detected