The type parameters written at src[*pos] (` `): their names * ','-joined, "" when there are none. *pos moves past the list. NULL when the * list cannot be read. Nothing at or past `stop` is read. */
| 1965 | * ','-joined, "" when there are none. *pos moves past the list. NULL when the |
| 1966 | * list cannot be read. Nothing at or past `stop` is read. */ |
| 1967 | static const char *cs_text_tparams(cs_scan_t *s, uint32_t *pos, uint32_t stop) { |
| 1968 | const char *src = s->ctx->source; |
| 1969 | uint32_t n = s->root_end_byte; |
| 1970 | uint32_t i = cs_skip_space(src, *pos, n); |
| 1971 | if (i >= n || src[i] != '<') { |
| 1972 | return ""; |
| 1973 | } |
| 1974 | if (i >= stop) { |
| 1975 | return NULL; /* the list is the next declaration's */ |
| 1976 | } |
| 1977 | uint32_t limit = stop - i > CS_TPARAMS_SCAN_MAX ? i + CS_TPARAMS_SCAN_MAX : stop; |
| 1978 | char *out = (char *)cs_tmp_alloc(s, (size_t)(limit - i) + SKIP_ONE); |
| 1979 | if (!out) { |
| 1980 | return NULL; |
| 1981 | } |
| 1982 | size_t w = 0; |
| 1983 | int square = 0; |
| 1984 | uint32_t word_s = 0; |
| 1985 | uint32_t word_e = 0; /* the last identifier of the current parameter */ |
| 1986 | for (uint32_t k = i + SKIP_ONE; k < limit; k++) { |
| 1987 | char c = src[k]; |
| 1988 | s->cost_steps++; |
| 1989 | if (c == '[') { |
| 1990 | square++; |
| 1991 | } else if (c == ']') { |
| 1992 | square--; |
| 1993 | } else if (square > 0) { |
| 1994 | continue; /* an attribute on the parameter */ |
| 1995 | } else if (c == ',' || c == '>') { |
| 1996 | if (word_e == word_s) { |
| 1997 | return NULL; |
| 1998 | } |
| 1999 | if (w > 0) { |
| 2000 | out[w++] = ','; |
| 2001 | } |
| 2002 | memcpy(out + w, src + word_s, word_e - word_s); |
| 2003 | w += word_e - word_s; |
| 2004 | word_s = word_e = 0; |
| 2005 | if (c == '>') { |
| 2006 | out[w] = '\0'; |
| 2007 | *pos = k + SKIP_ONE; |
| 2008 | return cs_utf8_ok(out, w) ? out : NULL; /* names that cannot be written */ |
| 2009 | } |
| 2010 | } else if (cs_word_char((unsigned char)c)) { |
| 2011 | uint32_t e = cs_ident_end(src, k, limit, false); |
| 2012 | if (e == k) { |
| 2013 | return NULL; |
| 2014 | } |
| 2015 | word_s = k; |
| 2016 | word_e = e; |
| 2017 | k = e - SKIP_ONE; |
| 2018 | } else if (!isspace((unsigned char)c)) { |
| 2019 | return NULL; |
| 2020 | } |
| 2021 | } |
| 2022 | return NULL; |
| 2023 | } |
| 2024 |
no test coverage detected