MCPcopy Create free account
hub / github.com/commonmark/cmark / normalize_reference

Function normalize_reference

src/references.c:22–45  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

20// Return NULL if the reference name is actually empty (i.e. composed
21// solely from whitespace)
22static 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
47void cmark_reference_create(cmark_reference_map *map, cmark_chunk *label,
48 cmark_chunk *url, cmark_chunk *title) {

Callers 2

cmark_reference_createFunction · 0.85
cmark_reference_lookupFunction · 0.85

Calls 4

cmark_utf8proc_case_foldFunction · 0.85
cmark_strbuf_trimFunction · 0.85
cmark_strbuf_detachFunction · 0.85

Tested by

no test coverage detected