diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-28 09:26:39 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-29 09:18:03 +0200 |
commit | bf4208246609a6b2a71d9c51696fbb9283871d55 (patch) | |
tree | 880175e3f9b60dbf96f9fd693ddded3f9d901ac6 /libmm-common/mm-common-helpers.c | |
parent | ee8afd8034f47f2f17ae042a2efe16034556dcf4 (diff) |
libmm-common: new helpers to parse doubles from strings or match infos
Diffstat (limited to 'libmm-common/mm-common-helpers.c')
-rw-r--r-- | libmm-common/mm-common-helpers.c | 32 |
1 files changed, 32 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) |