From 539562af0181f12343f6ebe2e3ffd44c5efb2fce Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 24 Mar 2020 06:17:34 +0100 Subject: libmm-glib,helpers: skip quotes when reading numbers from match infos Useful when the regex applied to the parseable strings don't have an special ignore rule for the quotes. --- libmm-glib/mm-common-helpers.c | 39 +++++++++------------------------------ 1 file changed, 9 insertions(+), 30 deletions(-) (limited to 'libmm-glib/mm-common-helpers.c') diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c index 5bdb6df4..cdb9115c 100644 --- a/libmm-glib/mm-common-helpers.c +++ b/libmm-glib/mm-common-helpers.c @@ -1356,17 +1356,10 @@ mm_get_int_from_match_info (GMatchInfo *match_info, guint32 match_index, gint *out) { - gchar *s; - gboolean ret; + g_autofree gchar *s = NULL; - s = g_match_info_fetch (match_info, match_index); - if (!s) - return FALSE; - - ret = mm_get_int_from_str (s, out); - g_free (s); - - return ret; + s = mm_get_string_unquoted_from_match_info (match_info, match_index); + return (s ? mm_get_int_from_str (s, out) : FALSE); } gboolean @@ -1492,17 +1485,10 @@ mm_get_u64_from_match_info (GMatchInfo *match_info, guint32 match_index, guint64 *out) { - gchar *s; - gboolean ret; - - s = g_match_info_fetch (match_info, match_index); - if (!s) - return FALSE; + g_autofree gchar *s = NULL; - ret = mm_get_u64_from_str (s, out); - g_free (s); - - return ret; + s = mm_get_string_unquoted_from_match_info (match_info, match_index); + return (s ? mm_get_u64_from_str (s, out) : FALSE); } gboolean @@ -1549,17 +1535,10 @@ mm_get_double_from_match_info (GMatchInfo *match_info, guint32 match_index, gdouble *out) { - gchar *s; - gboolean ret; - - s = g_match_info_fetch (match_info, match_index); - if (!s) - return FALSE; - - ret = mm_get_double_from_str (s, out); - g_free (s); + g_autofree gchar *s = NULL; - return ret; + s = mm_get_string_unquoted_from_match_info (match_info, match_index); + return (s ? mm_get_double_from_str (s, out) : FALSE); } gchar * -- cgit v1.2.3-70-g09d2