summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorGravatar Alan Fitton <ajf@eth0.org.uk>2012-03-02 10:04:41 +0000
committerGravatar Alan Fitton <ajf@eth0.org.uk>2012-03-02 10:04:41 +0000
commit9e8fed99f309cdc1381e56f7d02915aa27e9da50 (patch)
tree163d7cb148b9cf9277ed0a9aa20d7de6396dfdd0 /src/util.c
parentf77e1360b5204eb3b04ac230cac7827b731470cc (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.c17
1 files changed, 17 insertions, 0 deletions
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("<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