summary refs log tree commit diff
path: root/parse.c
diff options
context:
space:
mode:
authorwrmr2024-11-09 03:36:03 -0500
committerwrmr2024-11-09 03:36:03 -0500
commit71a195a0e4f603669657dd4534dbdcccafcd016c (patch)
treedf36ee098b918c43b5535bbc896b72839ed2a9fd /parse.c
parente05b80abcba62ce379de8cea23f38b0b2af68498 (diff)
fix plaintext url parsing
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/parse.c b/parse.c
index 7af7e52..b2ac019 100644
--- a/parse.c
+++ b/parse.c
@@ -9,18 +9,15 @@ int isurlch(char c) {
 	return isalpha(c) || isdigit(c) || c == '-' || c == '.' || c == '_' || c == '~' || c == '!' || c == '$' || c == '\'' || c == '(' || c == ')' || c == '*' || c == '+' || c == ',' || c == ';' || c == '=' || c == '%' || c == '@' || c == ':' || c == '/';
 }
 
-void parse_plain_url(struct doc *d, struct doc_line *l, size_t i) {
+void parse_plain_url(struct doc *d, strv_t ln, size_t i) {
 	size_t start = i - 1;
-	while (start > 0 && isalpha(l->txt[start])) start--;
-	if (!isalpha(l->txt[start])) start++;
+	while (start > 0 && isalpha(ln.s[start])) start--;
+	if (!isalpha(ln.s[start])) start++;
 	size_t end = i + 3;
-	while (end < l->len && isurlch(l->txt[end])) end++;
+	while (end < ln.n && isurlch(ln.s[end])) end++;
 	if (end == i + 3) return;
-	strv_t url = {
-		&l->txt[start],
-		end - start
-	};
-	l->link = doc_add_link(d, url);
+	strv_t url = { &ln.s[start], end - start };
+	doc_line_at(d, d->latest)->link = doc_add_link(d, url);
 }
 
 int parse_plain(struct doc *d, const str_t *b) {
@@ -28,11 +25,9 @@ int parse_plain(struct doc *d, const str_t *b) {
 	strv_t ln, buf = (strv_t) { b->buf, b->sz };
 	while (strv_split(&buf, '\n', &ln)) {
 		if (ln.n > 0 && ln.s[ln.n - 1] == '\r') ln.n--;
-		struct doc_line *l = doc_line_at(d, d->latest);
 		for (size_t j = 1; j + 2 < ln.n; j++) {
 			if (ln.s[j] == ':' && ln.s[j + 1] == '/' && ln.s[j + 2] == '/') {
-				parse_plain_url(d, l, j);
-				break;
+				parse_plain_url(d, ln, j);
 			}
 		}
 		doc_add_line(d, ln);