[libgxps] Add gxps_value_get_double() to parse double values



commit e63b13d4fce442dc4563e5e442345d2dc8e02bbe
Author: Carlos Garcia Campos <carlosgc gnome org>
Date:   Sun Nov 6 12:15:09 2011 +0100

    Add gxps_value_get_double() to parse double values

 libgxps/gxps-parse-utils.c |   20 ++++++++++++++++++++
 libgxps/gxps-parse-utils.h |    2 ++
 2 files changed, 22 insertions(+), 0 deletions(-)
---
diff --git a/libgxps/gxps-parse-utils.c b/libgxps/gxps-parse-utils.c
index b92eca2..23d048b 100644
--- a/libgxps/gxps-parse-utils.c
+++ b/libgxps/gxps-parse-utils.c
@@ -272,6 +272,26 @@ gxps_value_get_int (const gchar *value,
 	return TRUE;
 }
 
+gboolean
+gxps_value_get_double (const gchar *value,
+                       gdouble     *double_value)
+{
+        gdouble result;
+        gchar  *endptr;
+
+        if (!value)
+                return FALSE;
+
+        errno = 0;
+        result = g_ascii_strtod (value, &endptr);
+        if (errno || endptr == value)
+                return FALSE;
+
+        *double_value = result;
+
+        return TRUE;
+}
+
 gchar *
 gxps_resolve_relative_path (const gchar *source,
 			    const gchar *target)
diff --git a/libgxps/gxps-parse-utils.h b/libgxps/gxps-parse-utils.h
index 55b2037..410076e 100644
--- a/libgxps/gxps-parse-utils.h
+++ b/libgxps/gxps-parse-utils.h
@@ -36,6 +36,8 @@ void     gxps_parse_error           (GMarkupParseContext  *context,
 				     GError              **error);
 gboolean gxps_value_get_int         (const gchar          *value,
 				     gint                 *int_value);
+gboolean gxps_value_get_double      (const gchar          *value,
+                                     gdouble              *double_value);
 gchar   *gxps_resolve_relative_path (const gchar          *source,
 				     const gchar          *target);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]