[gcalctool/vala] Fix thousands separators



commit 53205c4331c000ff87631c458642a9350f448d3e
Author: Robert Ancell <robert ancell canonical com>
Date:   Sat Oct 13 13:26:00 2012 +1300

    Fix thousands separators

 src/config.vapi        |    8 ++++++++
 src/math-equation.vala |   16 +++++++++++-----
 src/serializer.vala    |   14 ++------------
 3 files changed, 21 insertions(+), 17 deletions(-)
---
diff --git a/src/config.vapi b/src/config.vapi
index e9f4270..af5d8cd 100644
--- a/src/config.vapi
+++ b/src/config.vapi
@@ -3,4 +3,12 @@ public const string GETTEXT_PACKAGE;
 public const string LOCALE_DIR;
 public const string UI_DIR;
 
+[CCode (cheader_filename = "langinfo.h", cprefix = "")]
+public enum NLItem
+{
+    RADIXCHAR,
+    THOUSEP
+}
 
+[CCode (cheader_filename = "langinfo.h")]
+public unowned string nl_langinfo (NLItem item);
diff --git a/src/math-equation.vala b/src/math-equation.vala
index fb71326..8088422 100644
--- a/src/math-equation.vala
+++ b/src/math-equation.vala
@@ -252,11 +252,13 @@ public class MathEquation : Gtk.TextBuffer
         var text = display;
         int ans_start, ans_end;
         get_ans_offsets (out ans_start, out ans_end);
-        var offset = 0;
+        var offset = -1;
         var index = 0;
         unichar c;
         while (text.get_next_char (ref index, out c))
         {
+            offset++;
+
             var expect_tsep = number_base == 10 &&
                               serializer.get_show_thousands_separators () &&
                               in_number && !in_radix && !last_is_tsep &&
@@ -264,7 +266,7 @@ public class MathEquation : Gtk.TextBuffer
             last_is_tsep = false;
 
             /* Don't mess with ans */
-            if (index >= ans_start && offset <= ans_end)
+            if (offset >= ans_start && offset <= ans_end)
             {
                 in_number = in_radix = false;
                 continue;
@@ -272,7 +274,7 @@ public class MathEquation : Gtk.TextBuffer
             if (c.isdigit ())
             {
                 if (!in_number)
-                    digit_offset = count_digits (text, index);
+                    digit_offset = count_digits (text, index) + 1;
                 in_number = true;
 
                 /* Expected a thousands separator between these digits - insert it */
@@ -288,7 +290,10 @@ public class MathEquation : Gtk.TextBuffer
                 digit_offset--;
             }
             else if (c == serializer.get_radix ())
-                in_number = in_radix = true;
+            {
+                in_number = true;
+                in_radix = true;
+            }
             else if (c == serializer.get_thousands_separator ())
             {
                 /* Didn't expect thousands separator - delete it */
@@ -305,7 +310,8 @@ public class MathEquation : Gtk.TextBuffer
             }
             else
             {
-                in_number = in_radix = false;
+                in_number = false;
+                in_radix = false;
             }
         }
 
diff --git a/src/serializer.vala b/src/serializer.vala
index 8f9fc91..fc389df 100644
--- a/src/serializer.vala
+++ b/src/serializer.vala
@@ -17,16 +17,6 @@ public enum DisplayFormat
     ENGINEERING
 }
 
-[CCode (cheader_filename = "langinfo.h")]
-public enum NLItem
-{
-    RADIXCHAR,
-    THOUSEP
-}
-
-[CCode (cheader_filename = "langinfo.h")]
-extern unowned string nl_langinfo (NLItem item);
-
 public class Serializer : Object
 {
     private int leading_digits;      /* Number of digits to show before radix */
@@ -45,12 +35,12 @@ public class Serializer : Object
     {
         var radix_string = nl_langinfo (NLItem.RADIXCHAR);
         if (radix_string != null && radix_string != "")
-            radix = radix_string.get_char (0);
+            radix = radix_string.locale_to_utf8 (-1, null, null).get_char (0);
         else
             radix = '.';
         var tsep_string = nl_langinfo (NLItem.THOUSEP);
         if (tsep_string != null && tsep_string != "")
-            tsep = tsep_string.get_char (0);
+            tsep = tsep_string.locale_to_utf8 (-1, null, null).get_char (0);
         else
             tsep = ' ';
         tsep_count = 3;



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