X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=src%2Furl.c;h=c5ffd4b72d6309a7a0b27ea57c55dc006af7d186;hb=e9663e348e5e5d36b36ec38a582df7df1fc9126b;hp=f968dae1a94fa7c6dea11b3e4ec4ac3b42609bc8;hpb=05e575979531e1f5597562e99294b0f00a8537ac;p=smdp.git diff --git a/src/url.c b/src/url.c index f968dae..c5ffd4b 100644 --- a/src/url.c +++ b/src/url.c @@ -136,3 +136,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; +}