From 9e8fed99f309cdc1381e56f7d02915aa27e9da50 Mon Sep 17 00:00:00 2001 From: Alan Fitton Date: Fri, 2 Mar 2012 10:04:41 +0000 Subject: contributed improvement to the url comment patch - use a GRegex now so only the URL is linked --- src/util.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/util.c') diff --git a/src/util.c b/src/util.c index a67a5db..613ed50 100644 --- a/src/util.c +++ b/src/util.c @@ -506,6 +506,23 @@ gchar *epoch_to_string(gint64 epoch) #endif } +/* wrap a link in text with a hyperlink, for use in pango markup. + * with or without any links - a newly allocated string is returned. */ + +gchar *add_links_to_text(const gchar *original) { + /* only perform replacement if string doesn't contains links */ + if (!g_regex_match_simple("", original, 0, 0)) { + GRegex *regex = g_regex_new("(https?://[a-zA-Z0-9_\\-\\./?=]+)", 0, 0, + NULL); + gchar *newText = g_regex_replace(regex, original, -1, 0, + "\\1", 0, NULL); + g_regex_unref(regex); + return newText; + } else { + return g_strdup(original); + } +} + size_t tr_strlcpy(char *dst, const void *src, size_t siz) { #ifdef HAVE_STRLCPY -- cgit v1.2.3