[goffice] utils: add new functions to write floating point to xml.



commit b6d3fb8a47df05f24a4faef23ff00cfb966c1ec8
Author: Morten Welinder <terra gnome org>
Date:   Sat Mar 7 11:18:56 2015 -0500

    utils: add new functions to write floating point to xml.
    
    These use go_dtoa to get shortest representation.

 goffice/utils/go-libxml-extras.c |   39 ++++++++++++++++++++++++++++++++++++++
 goffice/utils/go-libxml-extras.h |    4 +++
 2 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/goffice/utils/go-libxml-extras.c b/goffice/utils/go-libxml-extras.c
index 5121676..20b5b34 100644
--- a/goffice/utils/go-libxml-extras.c
+++ b/goffice/utils/go-libxml-extras.c
@@ -347,6 +347,45 @@ go_xml_get_child_by_name_by_lang (xmlNode const *parent, gchar const *name)
        return best_node;
 }
 
+/**
+ * go_xml_out_add_double:
+ * @output: destination
+ * @id: (allow-none): attribute name
+ * @d: value
+ *
+ * Output a representation of @d that will be read back without loss of
+ * precision.
+ */
+void
+go_xml_out_add_double (GsfXMLOut *output, char const *id, double d)
+{
+       GString *str = g_string_new (NULL);
+       go_dtoa (str, "!g", d);
+       gsf_xml_out_add_cstr (output, id, str->str);
+       g_string_free (str, TRUE);
+}
+
+#if GOFFICE_WITH_LONG_DOUBLE
+/**
+ * go_xml_out_add_long_double:
+ * @output: destination
+ * @id: (allow-none): attribute name
+ * @ld: value
+ *
+ * Output a representation of @ld that will be read back without loss of
+ * precision.
+ */
+void
+go_xml_out_add_long_double (GsfXMLOut *output, char const *id, long double ld)
+{
+       GString *str = g_string_new (NULL);
+       go_dtoa (str, "!Lg", ld);
+       gsf_xml_out_add_cstr (output, id, str->str);
+       g_string_free (str, TRUE);
+}
+#endif
+
+
 void
 go_xml_out_add_color (GsfXMLOut *output, char const *id, GOColor c)
 {
diff --git a/goffice/utils/go-libxml-extras.h b/goffice/utils/go-libxml-extras.h
index 08d9f28..987b90f 100644
--- a/goffice/utils/go-libxml-extras.h
+++ b/goffice/utils/go-libxml-extras.h
@@ -46,6 +46,10 @@ xmlNode *go_xml_get_child_by_name     (xmlNode const *tree, char const *name);
 xmlNode *go_xml_get_child_by_name_no_lang (xmlNode const *tree, char const *name);
 xmlNode *go_xml_get_child_by_name_by_lang (xmlNode const *tree, char const *name);
 
+void       go_xml_out_add_double (GsfXMLOut *output, char const *id, double d);
+#if GOFFICE_WITH_LONG_DOUBLE
+void       go_xml_out_add_long_double (GsfXMLOut *output, char const *id, long double ld);
+#endif
 void      go_xml_out_add_color (GsfXMLOut *out, char const *id, GOColor c);
 
 void       go_xml_in_doc_dispose_on_exit (GsfXMLInDoc **pdoc);


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