Position of `name` among the ','-separated type arguments of a segment. */
| 4012 | |
| 4013 | /* Position of `name` among the ','-separated type arguments of a segment. */ |
| 4014 | static int targ_position(const cs_seg_t *seg, const char *name, size_t len) { |
| 4015 | int pos = 0; |
| 4016 | int depth = 0; |
| 4017 | size_t start = 0; |
| 4018 | for (size_t i = 0; seg->targs && i <= seg->targs_len; i++) { |
| 4019 | char ch = i < seg->targs_len ? seg->targs[i] : ','; |
| 4020 | if (is_open_bracket(ch)) { |
| 4021 | depth++; |
| 4022 | } else if (is_close_bracket(ch)) { |
| 4023 | depth--; |
| 4024 | } else if (ch == ',' && depth == 0) { |
| 4025 | const char *a = seg->targs + start; |
| 4026 | size_t al = i - start; |
| 4027 | while (al > 0 && isspace((unsigned char)*a)) { |
| 4028 | a++; |
| 4029 | al--; |
| 4030 | } |
| 4031 | while (al > 0 && isspace((unsigned char)a[al - SKIP_ONE])) { |
| 4032 | al--; |
| 4033 | } |
| 4034 | if (al == len && memcmp(a, name, len) == 0) { |
| 4035 | return pos; |
| 4036 | } |
| 4037 | pos++; |
| 4038 | start = i + SKIP_ONE; |
| 4039 | } |
| 4040 | } |
| 4041 | return CS_NONE; |
| 4042 | } |
| 4043 | |
| 4044 | /* The position a doc ID's `N (*method false) or ``N (*method true) names; |
| 4045 | * CS_NONE for any other text. */ |
no test coverage detected