diff options
author | Matthias Clasen <mclasen@redhat.com> | 2020-11-24 13:42:29 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2020-11-24 13:42:29 -0500 |
commit | 7c0a9fc02b0c3570cab4b3ae69695456724739ba (patch) | |
tree | 863a413b70925d98aca1120938034c208cd28fd4 | |
parent | 7b22c44b39d63cf6a1efb656921e56ac861803fc (diff) | |
download | gtk+-spinbutton-local-digits.tar.gz |
spinbutton: Interpret localized digitsspinbutton-local-digits
Interpret input where the characters have numeric values.
See #3387
-rw-r--r-- | gtk/gtkspinbutton.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c index 7ebe279677..43d898fdd2 100644 --- a/gtk/gtkspinbutton.c +++ b/gtk/gtkspinbutton.c @@ -1604,9 +1604,35 @@ gtk_spin_button_default_input (GtkSpinButton *spin_button, *new_val = g_strtod (text, &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 |