diff options
author | Michael J. Chudobiak <mjc@avtechpulse.com> | 2012-12-11 15:33:37 -0500 |
---|---|---|
committer | Michael J. Chudobiak <mjc@avtechpulse.com> | 2012-12-11 15:33:37 -0500 |
commit | 80cf1f9fc280652ec523bd8dda1092db48e6e327 (patch) | |
tree | 839d1b33410b3b660063c9b64b7e56f310a6c28c | |
parent | 36f205a1008698be54ded3b6bb31b49a1bcec981 (diff) |
added conditional_regex_replace utility function
-rw-r--r-- | parser.c | 6 | ||||
-rw-r--r-- | string_utils.c | 15 | ||||
-rw-r--r-- | string_utils.h | 2 |
3 files changed, 18 insertions, 5 deletions
@@ -588,12 +588,10 @@ static int Parser_get_unit(char **parameter, char **units) static gchar* regex_replace (gchar* in_string, gchar* regex_string, gchar* replace_with) { - GRegex *regex = g_regex_new (regex_string, 0, 0, NULL); - gchar *out = g_regex_replace_literal (regex, in_string, -1, 0, replace_with, 0, NULL); - g_regex_unref (regex); - return out; + return conditional_regex_replace (TRUE, in_string, regex_string, replace_with); } + static gchar* filter_input (gchar *raw_in) { g_strstrip (raw_in); 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; +} diff --git a/string_utils.h b/string_utils.h index e52fc3d..96c3583 100644 --- a/string_utils.h +++ b/string_utils.h @@ -7,5 +7,5 @@ void Float_To_Text(int decimal_digits,float number_in, gchar** text_out); gboolean String_is_it_numeric(char *parameter); void String_Parameter_To_Text(float Float_To_Convert, int significant_digits, char *start_string,char *units,gchar **LCD_string,int show_plus_sign, int width_of_column); - +gchar* conditional_regex_replace (gboolean do_it, gchar* in_string, gchar* regex_string, gchar* replace_with); #endif |