]> git.sur5r.net Git - glabels/commitdiff
Applied patch to correct conversion errors when reading files for many non-"C" locale...
authorJim Evins <evins@snaught.com>
Wed, 8 Oct 2003 01:11:58 +0000 (01:11 +0000)
committerJim Evins <evins@snaught.com>
Wed, 8 Oct 2003 01:11:58 +0000 (01:11 +0000)
Provided by Emmanuel Pacaud (emmanuelp@sourceforge.net).

Additionally modified, to allow locale format for in xml files to be honored and to honor spaces between value and units.

All values written by glabels are now guaranteed to be in the "C" locale.

git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@305 f5e0f49d-192f-0410-a22d-a8d8700d0965

glabels2/src/xml.c

index 8e5591bf23843725d1e1d6ac0539d25db84c8111..b8bcd7440f800064a6e27fbe7ac52c5f8e192598 100644 (file)
@@ -162,38 +162,35 @@ gl_xml_get_prop_length (xmlNodePtr   node,
                        gdouble      default_val)
 {
        gdouble  val;
-       gchar   *string, units[65];
-       gint     n, i;
+       gchar   *string, *unit;
+       gint     i;
 
        string = xmlGetProp (node, property);
        if ( string != NULL ) {
-               n = sscanf (string, "%lf%64s", &val, units);
-               g_free (string);
-
-               switch (n) {
 
-               case 1:
-                       break;
+               val = g_strtod (string, &unit);
 
-               case 2:
-                       for (i=0; unit_table[i].name != NULL; i++) {
-                               if (xmlStrcasecmp (units, unit_table[i].name) == 0) {
-                                       val *= unit_table[i].points_per_unit;
-                                       break;
+               if (unit != string) {
+                       unit = g_strchug (unit);
+                       if (strlen (unit) > 0 ) {
+                               for (i=0; unit_table[i].name != NULL; i++) {
+                                       if (xmlStrcasecmp (unit, unit_table[i].name) == 0) {
+                                               val *= unit_table[i].points_per_unit;
+                                               break;
+                                       }
+                               }
+                               if (unit_table[i].name == NULL) {
+                                       g_warning ("Line %d, Node \"%s\", Property \"%s\": Unknown unit \"%s\", assuming points",
+                                                  xmlGetLineNo (node), node->name, property,
+                                                  unit);
                                }
                        }
-                       if (unit_table[i].name == NULL) {
-                               g_warning ("Line %d, Node \"%s\", Property \"%s\": Unknown units \"%s\", assuming points",
-                                          xmlGetLineNo (node), node->name, property,
-                                          units);
-                       }
-                       break;
-
-               default:
+               }
+               else {
                        val = 0.0;
-                       break;
-
                }
+
+               g_free (string);
                return val;
        }
 
@@ -208,11 +205,12 @@ gl_xml_set_prop_double (xmlNodePtr    node,
                        const gchar  *property,
                        gdouble       val)
 {
-       gchar  *string;
+       gchar  *string, buffer[G_ASCII_DTOSTR_BUF_SIZE];
+
+       /* Guarantee "C" locale by use of g_ascii_formatd */
+       string = g_ascii_formatd (buffer, G_ASCII_DTOSTR_BUF_SIZE, "%g", val);
 
-       string = g_strdup_printf ("%g", val);
        xmlSetProp (node, property, string);
-       g_free (string);
 }
 
 /****************************************************************************/
@@ -264,10 +262,14 @@ gl_xml_set_prop_length (xmlNodePtr    node,
                        const gchar  *property,
                        gdouble       val)
 {
-       gchar  *string;
+       gchar  *string, buffer[G_ASCII_DTOSTR_BUF_SIZE];
+       gchar  *string_unit;
 
-       string = g_strdup_printf ("%gpt", val);
-       xmlSetProp (node, property, string);
-       g_free (string);
+       /* Guarantee "C" locale by use of g_ascii_formatd */
+       string = g_ascii_formatd (buffer, G_ASCII_DTOSTR_BUF_SIZE, "%g", val);
+
+       string_unit = g_strdup_printf ("%spt", string);
+       xmlSetProp (node, property, string_unit);
+        g_free (string_unit);
 }