The written parameter list s[from, to) into the reference: every parameter * normalized, and all of them as one signature. false for more parameters * than a reference may have. */
| 3654 | * normalized, and all of them as one signature. false for more parameters |
| 3655 | * than a reference may have. */ |
| 3656 | static bool parse_params(cs_ref_t *r, const char *s, size_t from, size_t to) { |
| 3657 | bool any = false; |
| 3658 | for (size_t i = from; i < to && !any; i++) { |
| 3659 | any = !isspace((unsigned char)s[i]); |
| 3660 | } |
| 3661 | size_t start = from; |
| 3662 | int depth = 0; |
| 3663 | size_t w = 0; |
| 3664 | for (size_t i = from; any && i <= to; i++) { |
| 3665 | char c = i < to ? s[i] : ','; |
| 3666 | if (is_open_bracket(c)) { |
| 3667 | depth++; |
| 3668 | } else if (is_close_bracket(c)) { |
| 3669 | if (--depth < 0) { |
| 3670 | return false; /* a bracket that closes nothing */ |
| 3671 | } |
| 3672 | } else if (c == ',' && depth == 0) { |
| 3673 | if (r->nparams >= CS_MAX_PARAMS) { |
| 3674 | return false; |
| 3675 | } |
| 3676 | char *p = r->params[r->nparams++]; |
| 3677 | if (!slot_param(s + start, i - start, p, CS_PARAM_BUF)) { |
| 3678 | (void)cbm_doclink_cs_norm_type(s + start, i - start, p, CS_PARAM_BUF); |
| 3679 | } |
| 3680 | size_t pl = strlen(p); |
| 3681 | r->sig_unknown = r->sig_unknown || strchr(p, '?') != NULL; |
| 3682 | if (w > 0) { |
| 3683 | r->sig[w++] = '|'; |
| 3684 | } |
| 3685 | memcpy(r->sig + w, p, pl); |
| 3686 | w += pl; |
| 3687 | start = i + SKIP_ONE; |
| 3688 | } |
| 3689 | } |
| 3690 | r->sig[w] = '\0'; |
| 3691 | /* a bracket left open would have swallowed the last parameter: the |
| 3692 | * reference would be matched without it */ |
| 3693 | return depth == 0; |
| 3694 | } |
| 3695 | |
| 3696 | /* A written reference into its parts. false for one this code does not |
| 3697 | * understand -- and for one longer than CS_REF_BUF, which is never cut and |
no test coverage detected