diff options
-rw-r--r-- | libmm-common/mm-common-helpers.c | 32 | ||||
-rw-r--r-- | libmm-common/mm-common-helpers.h | 5 |
2 files changed, 37 insertions, 0 deletions
diff --git a/libmm-common/mm-common-helpers.c b/libmm-common/mm-common-helpers.c index efc86d34..1ca4f4e2 100644 --- a/libmm-common/mm-common-helpers.c +++ b/libmm-common/mm-common-helpers.c @@ -569,6 +569,38 @@ mm_get_uint_from_match_info (GMatchInfo *match_info, return ret; } +gboolean +mm_get_double_from_str (const gchar *str, + gdouble *out) +{ + gdouble num; + + errno = 0; + num = strtod (str, NULL); + if (!errno) { + *out = num; + return TRUE; + } + return FALSE; +} + +gboolean +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); + g_return_val_if_fail (s != NULL, FALSE); + + ret = mm_get_double_from_str (s, out); + g_free (s); + + return ret; +} + gchar * mm_get_string_unquoted_from_match_info (GMatchInfo *match_info, guint32 match_index) diff --git a/libmm-common/mm-common-helpers.h b/libmm-common/mm-common-helpers.h index cec65f34..98d97f41 100644 --- a/libmm-common/mm-common-helpers.h +++ b/libmm-common/mm-common-helpers.h @@ -68,6 +68,11 @@ gboolean mm_get_uint_from_str (const gchar *str, gboolean mm_get_uint_from_match_info (GMatchInfo *match_info, guint32 match_index, guint *out); +gboolean mm_get_double_from_str (const gchar *str, + gdouble *out); +gboolean mm_get_double_from_match_info (GMatchInfo *match_info, + guint32 match_index, + gdouble *out); gchar *mm_get_string_unquoted_from_match_info (GMatchInfo *match_info, guint32 match_index); |