summaryrefslogtreecommitdiff
path: root/src/commonmark.c
diff options
context:
space:
mode:
authorNick Wellnhofer <wellnhofer@aevum.de>2020-01-18 23:12:37 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2020-01-23 08:25:54 -0800
commitb237924585e61532ada774bf9e70eadff00666dc (patch)
tree4355e86e19736d1eeffd905cdbc2d2b6ea7a6430 /src/commonmark.c
parent3acbdf0965859c55fa36c65a4c0e17e92012687c (diff)
Use C string instead of chunk for link URL and title
Use zero-terminated C strings instead of cmark_chunks without storing the length. This introduces a few additional strlen computations, but overhead should be low. Allows to reduce size of struct cmark_node later.
Diffstat (limited to 'src/commonmark.c')
-rw-r--r--src/commonmark.c26
1 files changed, 10 insertions, 16 deletions
diff --git a/src/commonmark.c b/src/commonmark.c
index b89462b..89aef5b 100644
--- a/src/commonmark.c
+++ b/src/commonmark.c
@@ -119,24 +119,22 @@ static int shortest_unused_backtick_sequence(const char *code) {
}
static bool is_autolink(cmark_node *node) {
- cmark_chunk *title;
- cmark_chunk *url;
+ const unsigned char *title;
+ const unsigned char *url;
cmark_node *link_text;
- char *realurl;
- int realurllen;
if (node->type != CMARK_NODE_LINK) {
return false;
}
- url = &node->as.link.url;
- if (url->len == 0 || scan_scheme(url, 0) == 0) {
+ url = node->as.link.url;
+ if (url == NULL || _scan_scheme(url) == 0) {
return false;
}
- title = &node->as.link.title;
+ title = node->as.link.title;
// if it has a title, we can't treat it as an autolink:
- if (title->len > 0) {
+ if (title && title[0]) {
return false;
}
@@ -145,15 +143,11 @@ static bool is_autolink(cmark_node *node) {
return false;
}
cmark_consolidate_text_nodes(link_text);
- realurl = (char *)url->data;
- realurllen = url->len;
- if (strncmp(realurl, "mailto:", 7) == 0) {
- realurl += 7;
- realurllen -= 7;
+ if (strcmp((const char *)url, "mailto:") == 0) {
+ url += 7;
}
- return (realurllen == link_text->as.literal.len &&
- strncmp(realurl, (char *)link_text->as.literal.data,
- link_text->as.literal.len) == 0);
+ return strncmp((const char *)url, (char *)link_text->as.literal.data,
+ link_text->as.literal.len) == 0;
}
// if node is a block node, returns node.