normalize reference: collapse internal whitespace to single space, remove leading/trailing whitespace, case fold Return NULL if the reference name is actually empty (i.e. composed solely from whitespace)
| 20 | // Return NULL if the reference name is actually empty (i.e. composed |
| 21 | // solely from whitespace) |
| 22 | static unsigned char *normalize_reference(cmark_mem *mem, cmark_chunk *ref) { |
| 23 | cmark_strbuf normalized = CMARK_BUF_INIT(mem); |
| 24 | unsigned char *result; |
| 25 | |
| 26 | if (ref == NULL) |
| 27 | return NULL; |
| 28 | |
| 29 | if (ref->len == 0) |
| 30 | return NULL; |
| 31 | |
| 32 | cmark_utf8proc_case_fold(&normalized, ref->data, ref->len); |
| 33 | cmark_strbuf_trim(&normalized); |
| 34 | cmark_strbuf_normalize_whitespace(&normalized); |
| 35 | |
| 36 | result = cmark_strbuf_detach(&normalized); |
| 37 | assert(result); |
| 38 | |
| 39 | if (result[0] == '\0') { |
| 40 | mem->free(result); |
| 41 | return NULL; |
| 42 | } |
| 43 | |
| 44 | return result; |
| 45 | } |
| 46 | |
| 47 | void cmark_reference_create(cmark_reference_map *map, cmark_chunk *label, |
| 48 | cmark_chunk *url, cmark_chunk *title) { |
no test coverage detected