On Thursday 14 of June 2012 10:03:20 Jiri Moskovcak wrote:
> ---
> src/gtk-helpers/hyperlinks.c | 17 ++++++++++++++++-
> 1 file changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/src/gtk-helpers/hyperlinks.c b/src/gtk-helpers/hyperlinks.c
> index 72fab15..a58bb3a 100644
> --- a/src/gtk-helpers/hyperlinks.c
> +++ b/src/gtk-helpers/hyperlinks.c
> @@ -6,9 +6,24 @@
> char *tag_url(const char* line, const char* prefix)
> {
> static const char *const known_url_prefixes[] = {"http://", "https://",
> "ftp://", "file://", NULL}; + static const char *known_url_ends =
> ",'\"\t\n ";
>
> char *result = xstrdup(line);
>
> +
> + char *find_end(const char* url_start)
> + {
> + char *url_end = strchrnul(url_start, *known_url_ends);
> + const char *curr_end = known_url_ends;
> + while(*(++curr_end) != '\0')
> + {
> + char *tmp = strchrnul(url_start, *curr_end);
> + if (tmp < url_end)
> + url_end = tmp;
> + }
> + return url_end;
> + }
> +
Please, don't use nested functions. It is a little bit confusing.
(Note: consider usage of strtok() function)
> const char *const *pfx = known_url_prefixes;
> while (*pfx != NULL)
> {
> @@ -16,7 +31,7 @@ char *tag_url(const char* line, const char* prefix)
> char *url_start;
> while ((url_start = strstr(cur_pos, *pfx)) != NULL)
> {
> - char *url_end = strchrnul(url_start, ' '); //TODO: also '.',
> ',', '\t', '\n'... + char *url_end = find_end(url_start);
> int len = url_end - url_start;
> char *hyperlink = xasprintf("%s<a href=\"%.*s\">%.*s</a>",
> prefix,
The rest is OK.
Regards,
Jakub