// Returns reference if refmap contains a reference with matching // label, otherwise NULL. reference* reference_lookup(reference_map *map, chunk *label) { reference *ref = NULL; unsigned char *norm; unsigned int hash; if (map == NULL) return NULL; norm = normalize_reference(label); if (norm == NULL) return NULL; hash = refhash(norm); ref = map->table[hash % REFMAP_SIZE]; while (ref) { if (ref->hash == hash && !strcmp((char *)ref->label, (char *)norm)) break; ref = ref->next; } free(norm); return ref; }
// Returns reference if refmap contains a reference with matching // label, otherwise NULL. cmark_reference *cmark_reference_lookup(cmark_reference_map *map, cmark_chunk *label) { cmark_reference *ref = NULL; unsigned char *norm; unsigned int hash; if (label->len > MAX_LINK_LABEL_LENGTH) return NULL; if (map == NULL) return NULL; norm = normalize_reference(map->mem, label); if (norm == NULL) return NULL; hash = refhash(norm); ref = map->table[hash % REFMAP_SIZE]; while (ref) { if (ref->hash == hash && !strcmp((char *)ref->label, (char *)norm)) break; ref = ref->next; } free(norm); return ref; }
void cmark_reference_create(cmark_reference_map *map, cmark_chunk *label, cmark_chunk *url, cmark_chunk *title) { cmark_reference *ref; unsigned char *reflabel = normalize_reference(map->mem, label); /* empty reference name, or composed from only whitespace */ if (reflabel == NULL) return; ref = (cmark_reference *)map->mem->calloc(1, sizeof(*ref)); ref->label = reflabel; ref->hash = refhash(ref->label); ref->url = cmark_clean_url(map->mem, url); ref->title = cmark_clean_title(map->mem, title); ref->next = NULL; add_reference(map, ref); }
extern void reference_create(reference_map *map, chunk *label, chunk *url, chunk *title) { reference *ref; unsigned char *reflabel = normalize_reference(label); /* empty reference name, or composed from only whitespace */ if (reflabel == NULL) return; ref = calloc(1, sizeof(*ref)); if(ref != NULL) { ref->label = reflabel; ref->hash = refhash(ref->label); ref->url = clean_url(url); ref->title = clean_title(title); ref->next = NULL; add_reference(map, ref); } }