The closing bracket of a node shape opened at s[i]: the shape's text in * *label, the position after it. */
| 366 | /* The closing bracket of a node shape opened at s[i]: the shape's text in |
| 367 | * *label, the position after it. */ |
| 368 | static size_t dg_shape(dg_str_t s, size_t i, dg_str_t *label) { |
| 369 | static const char *const opens[] = {"(((", "([", "[[", "[(", "((", "{{", "[/", |
| 370 | "[\\", "[", "(", "{", ">", NULL}; |
| 371 | static const char *const closes[] = {")))", "])", "]]", ")]", "))", "}}", "/]", |
| 372 | "\\]", "]", ")", "}", "]", NULL}; |
| 373 | for (int k = 0; opens[k]; k++) { |
| 374 | size_t ol = strlen(opens[k]); |
| 375 | if (i + ol > s.n || memcmp(s.p + i, opens[k], ol) != 0) { |
| 376 | continue; |
| 377 | } |
| 378 | size_t cl = strlen(closes[k]); |
| 379 | bool quoted = false; |
| 380 | for (size_t j = i + ol; j + cl <= s.n; j++) { |
| 381 | if (s.p[j] == '"') { |
| 382 | quoted = !quoted; |
| 383 | } |
| 384 | if (!quoted && memcmp(s.p + j, closes[k], cl) == 0) { |
| 385 | *label = dg_s(s.p + i + ol, j - i - ol); |
| 386 | return j + cl; |
| 387 | } |
| 388 | } |
| 389 | /* `[/text\]` and `[\text/]` close with the other slash */ |
| 390 | if (k == CBM_SZ_6 || k == CBM_SZ_7) { |
| 391 | const char *alt = k == CBM_SZ_6 ? "\\]" : "/]"; |
| 392 | for (size_t j = i + ol; j + PAIR_LEN <= s.n; j++) { |
| 393 | if (memcmp(s.p + j, alt, PAIR_LEN) == 0) { |
| 394 | *label = dg_s(s.p + i + ol, j - i - ol); |
| 395 | return j + PAIR_LEN; |
| 396 | } |
| 397 | } |
| 398 | } |
| 399 | return i; |
| 400 | } |
| 401 | return i; |
| 402 | } |
| 403 | |
| 404 | /* A node at s[i]: its id and label; the position after it (i when none). */ |
| 405 | static size_t dg_flow_node(dg_str_t s, size_t i, dg_str_t *id, dg_str_t *label) { |
no test coverage detected