diff options
author | Alan Fitton <ajf@eth0.org.uk> | 2012-03-02 10:04:41 +0000 |
---|---|---|
committer | Alan Fitton <ajf@eth0.org.uk> | 2012-03-02 10:04:41 +0000 |
commit | 9e8fed99f309cdc1381e56f7d02915aa27e9da50 (patch) | |
tree | 163d7cb148b9cf9277ed0a9aa20d7de6396dfdd0 /src/util.c | |
parent | f77e1360b5204eb3b04ac230cac7827b731470cc (diff) |
contributed improvement to the url comment patch - use a GRegex now so only the URL is linked
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -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("<a\\s.*>", 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, + "<a href='\\1'>\\1</a>", 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 |