[gcalctool] Use gunichar for digit storage
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcalctool] Use gunichar for digit storage
- Date: Tue, 19 Oct 2010 22:37:28 +0000 (UTC)
commit 4764ea5d391ef536a73ab73c86f891a48d0b4f63
Author: Robert Ancell <robert ancell canonical com>
Date: Wed Oct 20 09:24:08 2010 +1100
Use gunichar for digit storage
src/math-buttons.c | 7 ++++++-
src/math-equation.c | 17 +++++++++++------
src/math-equation.h | 4 +---
3 files changed, 18 insertions(+), 10 deletions(-)
---
diff --git a/src/math-buttons.c b/src/math-buttons.c
index b0cd926..329bb83 100644
--- a/src/math-buttons.c
+++ b/src/math-buttons.c
@@ -940,9 +940,14 @@ load_mode(MathButtons *buttons, ButtonMode mode)
name = g_strdup_printf("calc_%d_button", i);
button = GET_WIDGET(builder, name);
if (button) {
+ gchar buffer[7];
+ gint len;
+
g_object_set_data(G_OBJECT(button), "calc_digit", GINT_TO_POINTER(i));
set_tint(button, &buttons->priv->color_numbers, 1);
- gtk_button_set_label(GTK_BUTTON(button), math_equation_get_digit_text(buttons->priv->equation, i));
+ len = g_unichar_to_utf8(math_equation_get_digit_text(buttons->priv->equation, i), buffer);
+ buffer[len] = '\0';
+ gtk_button_set_label(GTK_BUTTON(button), buffer);
}
g_free(name);
}
diff --git a/src/math-equation.c b/src/math-equation.c
index 2ba60bb..5a8a743 100644
--- a/src/math-equation.c
+++ b/src/math-equation.c
@@ -79,7 +79,7 @@ struct MathEquationPrivate
NumberMode number_mode; /* ??? */
gboolean can_super_minus; /* TRUE if entering minus can generate a superscript minus */
- const char *digits[16]; /* Localized digit values */
+ gunichar digits[16]; /* Localized digits */
GtkTextMark *ans_start, *ans_end;
@@ -387,7 +387,7 @@ math_equation_redo(MathEquation *equation)
}
-const gchar *
+gunichar
math_equation_get_digit_text(MathEquation *equation, guint digit)
{
return equation->priv->digits[digit];
@@ -779,8 +779,13 @@ math_equation_insert_digit(MathEquation *equation, guint digit)
static const char *subscript_digits[] = {"â??", "â??", "â??", "â??", "â??", "â??", "â??", "â??", "â??", "â??", NULL};
static const char *superscript_digits[] = {"�", "¹", "²", "³", "�", "�", "�", "�", "�", "�", NULL};
- if (equation->priv->number_mode == NORMAL || digit >= 10)
- math_equation_insert(equation, math_equation_get_digit_text(equation, digit));
+ if (equation->priv->number_mode == NORMAL || digit >= 10) {
+ gchar buffer[7];
+ gint len;
+ len = g_unichar_to_utf8(math_equation_get_digit_text(equation, digit), buffer);
+ buffer[len] = '\0';
+ math_equation_insert(equation, buffer);
+ }
else if (equation->priv->number_mode == SUPERSCRIPT)
math_equation_insert(equation, superscript_digits[digit]);
else if (equation->priv->number_mode == SUBSCRIPT)
@@ -1623,10 +1628,10 @@ math_equation_init(MathEquation *equation)
for (i = 0; i < 16; i++) {
if (use_default_digits || digits[i] == NULL) {
use_default_digits = TRUE;
- equation->priv->digits[i] = strdup(default_digits[i]);
+ equation->priv->digits[i] = g_utf8_get_char(default_digits[i]);
}
else
- equation->priv->digits[i] = strdup(digits[i]);
+ equation->priv->digits[i] = g_utf8_get_char(digits[i]);
}
g_strfreev(digits);
diff --git a/src/math-equation.h b/src/math-equation.h
index 2060425..066413f 100644
--- a/src/math-equation.h
+++ b/src/math-equation.h
@@ -56,9 +56,7 @@ MathEquation *math_equation_new(void);
MathVariables *math_equation_get_variables(MathEquation *equation);
-const gchar *math_equation_get_digit_text(MathEquation *equation, guint digit);
-const gchar *math_equation_get_numeric_point_text(MathEquation *equation);
-const gchar *math_equation_get_thousands_separator_text(MathEquation *equation);
+gunichar math_equation_get_digit_text(MathEquation *equation, guint digit);
void math_equation_set_status(MathEquation *equation, const gchar *status);
const gchar *math_equation_get_status(MathEquation *equation);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]