Nullable / Nullable{X} (optionally System.- or global::System.- * qualified) -> X. */
| 493 | /* Nullable<X> / Nullable{X} (optionally System.- or global::System.- |
| 494 | * qualified) -> X. */ |
| 495 | static void cs_unwrap_nullable(cs_str_t *t) { |
| 496 | static const char *const prefixes[] = {"global::System.Nullable", "System.Nullable", |
| 497 | "Nullable"}; |
| 498 | /* one pass: what an unwrapped group leaves at its place is looked at |
| 499 | * again (Nullable<Nullable<X>>), the text before it never is */ |
| 500 | for (size_t i = 0; i < t->len;) { |
| 501 | bool unwrapped = false; |
| 502 | bool boundary = i == 0 || !(cs_ident_char(t->s[i - SKIP_ONE]) || |
| 503 | t->s[i - SKIP_ONE] == '.' || t->s[i - SKIP_ONE] == ':'); |
| 504 | for (size_t pi = 0; boundary && !unwrapped && pi < sizeof(prefixes) / sizeof(prefixes[0]); |
| 505 | pi++) { |
| 506 | size_t pl = strlen(prefixes[pi]); |
| 507 | if (i + pl > t->len || memcmp(t->s + i, prefixes[pi], pl) != 0) { |
| 508 | continue; |
| 509 | } |
| 510 | size_t j = i + pl; |
| 511 | while (j < t->len && t->s[j] == ' ') { |
| 512 | j++; |
| 513 | } |
| 514 | if (j >= t->len || (t->s[j] != '<' && t->s[j] != '{')) { |
| 515 | continue; |
| 516 | } |
| 517 | size_t e = cs_group_end(t, j); |
| 518 | if (e > t->len || e <= j + SKIP_ONE) { |
| 519 | continue; |
| 520 | } |
| 521 | /* keep the inner text */ |
| 522 | size_t inner_len = e - j - PAIR_LEN; |
| 523 | memmove(t->s + i, t->s + j + SKIP_ONE, inner_len); |
| 524 | memmove(t->s + i + inner_len, t->s + e, t->len - e + SKIP_ONE); |
| 525 | t->len = i + inner_len + (t->len - e); |
| 526 | unwrapped = true; |
| 527 | } |
| 528 | if (!unwrapped) { |
| 529 | i++; |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | static bool cs_word_at(const cs_str_t *t, size_t i, const char *w) { |
| 535 | size_t wl = strlen(w); |
no test coverage detected