X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=src%2Furl.c;h=1aa2de6c0192c61faa9ad406c08fb6b92c14544d;hb=96f4804a413b591d74505eacfa621604b56f6d5f;hp=f968dae1a94fa7c6dea11b3e4ec4ac3b42609bc8;hpb=05e575979531e1f5597562e99294b0f00a8537ac;p=smdp.git
diff --git a/src/url.c b/src/url.c
index f968dae..1aa2de6 100644
--- a/src/url.c
+++ b/src/url.c
@@ -1,3 +1,24 @@
+/*
+ * Functions necessary to handle pandoc URLs.
+ * Copyright (C) 2014 Michael Goehler
+ *
+ * This file is part of mdp.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
#include
#include
#include
@@ -136,3 +157,45 @@ static void url_print(url_t *u) {
int url_get_amount(void) {
return index_max;
}
+
+int url_count_inline(const char *line) {
+ int count = 0;
+ const char *i = line;
+
+ for (; *i; i++) {
+ if (*i == '\\') {
+ i++;
+ } else if ( *i == '[' && *(i+1) != ']') {
+ while (*i && *i != ']') i++;
+ i++;
+ if (*i == '(' && strchr(i, ')')) {
+ count ++;
+ i = strchr(i, ')');
+ }
+ }
+ }
+
+ return count;
+}
+
+int url_len_inline(const char *text) {
+ int count = 0;
+ const char *i = text;
+
+ for (; *i; i++) {
+ if (*i == '\\') {
+ i++;
+ } else if ( *i == '[' && *(i+1) != ']') {
+ while (*i && *i != ']') i++;
+ i++;
+ if (*i == '(' && strchr(i, ')')) {
+ while (*i && *i != ')') {
+ count++;
+ i++;
+ }
+ }
+ }
+ }
+
+ return count;
+}