From 80cf1f9fc280652ec523bd8dda1092db48e6e327 Mon Sep 17 00:00:00 2001 From: "Michael J. Chudobiak" Date: Tue, 11 Dec 2012 15:33:37 -0500 Subject: added conditional_regex_replace utility function --- string_utils.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'string_utils.c') diff --git a/string_utils.c b/string_utils.c index 7b60792..77765d2 100644 --- a/string_utils.c +++ b/string_utils.c @@ -149,3 +149,18 @@ void String_Parameter_To_Text(float Float_To_Convert, int significant_digits, g_free (unit_mult); } + +gchar* conditional_regex_replace (gboolean do_it, gchar* in_string, gchar* regex_string, gchar* replace_with) +{ + gchar *out; + + if (do_it) { + GRegex *regex = g_regex_new (regex_string, 0, 0, NULL); + out = g_regex_replace_literal (regex, in_string, -1, 0, replace_with, 0, NULL); + g_regex_unref (regex); + } else { + out = g_strdup (in_string); + } + + return out; +} -- cgit