[dia] Chronoline serialization is locale dependent: increase tolerance



commit 0fba5786fcc0da442ecea6c0b09be86bebe818d3
Author: Hans Breuer <hans breuer org>
Date:   Fri Jan 7 14:33:49 2011 +0100

    Chronoline serialization is locale dependent: increase tolerance
    
    To get rid of related complaints and preserve the intended
    event settings across e.g. German an English locale translate
    the decimal separator from ',' to always '.' for parsing.

 objects/chronogram/chronoline_event.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)
---
diff --git a/objects/chronogram/chronoline_event.c b/objects/chronogram/chronoline_event.c
index e017e6f..1300a6a 100644
--- a/objects/chronogram/chronoline_event.c
+++ b/objects/chronogram/chronoline_event.c
@@ -178,8 +178,7 @@ parse_clevent(const gchar *events, real rise, real fall)
 	return clel;
       }
     } else { /* waitfor == LENGTH */
-      /* using g_strtod to support loacle and "C" formatted numbers */
-      dt = g_strtod(p,(char **)&p1);
+      dt = g_ascii_strtod(p,(char **)&p1);
       if (p1 == p) {
 	/* We were ready for a length argument, we got nothing.
 	   Maybe the user entered a zero-length argument ? */
@@ -258,13 +257,28 @@ reparse_clevent(const gchar *events, CLEventList **lst,
 		int *chksum,real rise, real fall,real time_end)
 {
   int newsum;
+  gchar *ps;
 
   /* XXX: it might be better to simply drop this checksumming ? */
   newsum = __chksum(events,rise,fall,time_end);
   if ((newsum == *chksum) && (*lst)) return;
 
+  /* the string might contain ',' as a decimal separtor, fix it on the fly */
+  if (strchr(events, ',') != NULL) {
+    gchar *p;
+
+    ps = g_strdup(events);
+    for (p = ps; *p != '\0'; ++p) {
+      if (*p == ',')
+        *p = '.';
+    }
+  } else {
+    ps = events;
+  }
   destroy_clevent_list(*lst);
-  *lst = parse_clevent(events,rise,fall);
+  *lst = parse_clevent(ps,rise,fall);
+  if (ps != events)
+    g_free(ps);
   *chksum = newsum;
 }
 



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