diff options
author | JP Rosevear <jpr@helixcode.com> | 2000-09-18 04:58:28 +0800 |
---|---|---|
committer | JP Rosevear <jpr@src.gnome.org> | 2000-09-18 04:58:28 +0800 |
commit | 84f3540f7b0bb6f1a1a39f769c7d17d7c27ac3fa (patch) | |
tree | fed9a1b1c71cff11e570096f819f8006d667851a /e-util/e-xml-utils.c | |
parent | db10d3ce58c3b3434266f6129887bd1215440cca (diff) | |
download | gsoc2013-evolution-84f3540f7b0bb6f1a1a39f769c7d17d7c27ac3fa.tar gsoc2013-evolution-84f3540f7b0bb6f1a1a39f769c7d17d7c27ac3fa.tar.gz gsoc2013-evolution-84f3540f7b0bb6f1a1a39f769c7d17d7c27ac3fa.tar.bz2 gsoc2013-evolution-84f3540f7b0bb6f1a1a39f769c7d17d7c27ac3fa.tar.lz gsoc2013-evolution-84f3540f7b0bb6f1a1a39f769c7d17d7c27ac3fa.tar.xz gsoc2013-evolution-84f3540f7b0bb6f1a1a39f769c7d17d7c27ac3fa.tar.zst gsoc2013-evolution-84f3540f7b0bb6f1a1a39f769c7d17d7c27ac3fa.zip |
Merging in additional type functions (e_xml_get_string_prop_by_name):
2000-09-17 JP Rosevear <jpr@helixcode.com>
* src/util/e-xml-utils.c (e_xml_set_string_prop_by_name): Merging
in additional type functions
(e_xml_get_string_prop_by_name): ditto
(e_xml_set_double_prop_by_name): ditto
(e_xml_get_double_prop_by_name): ditto
svn path=/trunk/; revision=5485
Diffstat (limited to 'e-util/e-xml-utils.c')
-rw-r--r-- | e-util/e-xml-utils.c | 80 |
1 files changed, 73 insertions, 7 deletions
diff --git a/e-util/e-xml-utils.c b/e-util/e-xml-utils.c index 89f8591e8a..88ce82310e 100644 --- a/e-util/e-xml-utils.c +++ b/e-util/e-xml-utils.c @@ -21,10 +21,10 @@ */ #include <locale.h> -#include "e-xml-utils.h" +#include <math.h> #include <gnome-xml/parser.h> #include <gnome-xml/xmlmemory.h> - +#include "e-xml-utils.h" xmlNode *e_xml_get_child_by_name(xmlNode *parent, const xmlChar *child_name) { @@ -80,10 +80,10 @@ e_xml_get_integer_prop_by_name(xmlNode *parent, const xmlChar *prop_name) g_return_val_if_fail (parent != NULL, 0); g_return_val_if_fail (prop_name != NULL, 0); - prop = xmlGetProp(parent, prop_name); + prop = xmlGetProp (parent, prop_name); if (prop) { - ret_val = atoi(prop); - xmlFree(prop); + ret_val = atoi (prop); + xmlFree (prop); } return ret_val; } @@ -96,9 +96,75 @@ e_xml_set_integer_prop_by_name(xmlNode *parent, const xmlChar *prop_name, int va g_return_if_fail (parent != NULL); g_return_if_fail (prop_name != NULL); - valuestr = g_strdup_printf("%d", value); - xmlSetProp(parent, prop_name, valuestr); + valuestr = g_strdup_printf ("%d", value); + xmlSetProp (parent, prop_name, valuestr); + g_free (valuestr); +} + +double +e_xml_get_double_prop_by_name(xmlNode *parent, const xmlChar *prop_name) +{ + xmlChar *prop; + double ret_val = 0; + + g_return_val_if_fail (parent != NULL, 0); + g_return_val_if_fail (prop_name != NULL, 0); + + prop = xmlGetProp (parent, prop_name); + if (prop) { + sscanf (prop, "%lf", &ret_val); + xmlFree (prop); + } + return ret_val; +} + +void +e_xml_set_double_prop_by_name(xmlNode *parent, const xmlChar *prop_name, double value) +{ + xmlChar *valuestr; + + g_return_if_fail (parent != NULL); + g_return_if_fail (prop_name != NULL); + + if (fabs (value) < 1e9 && fabs (value) > 1e-5) + valuestr = g_strdup_printf ("%f", value); + else + valuestr = g_strdup_printf ("%.*g", DBL_DIG, value); + xmlSetProp (parent, prop_name, valuestr); g_free (valuestr); } +char * +e_xml_get_string_prop_by_name(xmlNode *parent, const xmlChar *prop_name) +{ + xmlChar *prop; + char *ret_val = NULL; + + g_return_val_if_fail (parent != NULL, 0); + g_return_val_if_fail (prop_name != NULL, 0); + + prop = xmlGetProp (parent, prop_name); + if (prop) { + ret_val = g_strdup (prop); + xmlFree (prop); + } + return ret_val; +} + +void +e_xml_set_string_prop_by_name(xmlNode *parent, const xmlChar *prop_name, char *value) +{ + xmlChar *valuestr; + + g_return_if_fail (parent != NULL); + g_return_if_fail (prop_name != NULL); + + valuestr = g_strdup (value); + xmlSetProp (parent, prop_name, valuestr); + g_free (valuestr); +} + + + + |