libmm-common: new helpers to parse doubles from strings or match infos

This commit is contained in:
Aleksander Morgado
2012-03-29 09:18:03 +02:00
parent ee8afd8034
commit bf42082466
2 changed files with 37 additions and 0 deletions
+32
View File
@@ -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)
+5
View File
@@ -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);