summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2020-11-24 13:42:29 -0500
committerMatthias Clasen <mclasen@redhat.com>2021-03-29 21:28:04 -0400
commit867a1adc12bbf6a6f89b1d75ec8bcfc964080393 (patch)
tree03948805543bc00ad7908d0b46236f6cd1e2557d
parentba8c18019d4258a9fb056ce84d1df8d510a7e444 (diff)
downloadgtk+-spinbutton-localized-digits-3.tar.gz
spinbutton: Interpret localized digitsspinbutton-localized-digits-3
Interpret input where the characters have numeric values. See #3387
-rw-r--r--gtk/gtkspinbutton.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c
index 9498aad33d..766c487d7f 100644
--- a/gtk/gtkspinbutton.c
+++ b/gtk/gtkspinbutton.c
@@ -1886,9 +1886,35 @@ gtk_spin_button_default_input (GtkSpinButton *spin_button,
*new_val = g_strtod (gtk_entry_get_text (GTK_ENTRY (spin_button)), &err);
if (*err)
- return GTK_INPUT_ERROR;
- else
- return FALSE;
+ {
+ /* try to convert with local digits */
+ gint64 val = 0;
+ int sign = 1;
+ const char *p;
+
+ for (p = text; *p; p = g_utf8_next_char (p))
+ {
+ gunichar ch = g_utf8_get_char (p);
+
+ if (p == text && ch == '-')
+ {
+ sign = -1;
+ continue;
+ }
+
+ if (!g_unichar_isdigit (ch))
+ break;
+
+ val = val * 10 + g_unichar_digit_value (ch);
+ }
+
+ if (*p)
+ return GTK_INPUT_ERROR;
+
+ *new_val = sign * val;
+ }
+
+ return FALSE;
}
static void