[gnumeric] number match: allow plain space as a 1000s separator in FR locale.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] number match: allow plain space as a 1000s separator in FR locale.
- Date: Thu, 28 Jan 2021 16:27:43 +0000 (UTC)
commit f58a0001e1312d0ddd8e6c3acbf412c24cba97df
Author: Morten Welinder <terra gnome org>
Date: Thu Jan 28 11:26:28 2021 -0500
number match: allow plain space as a 1000s separator in FR locale.
Actually in any locale that uses a unicode whitespace character as the
1000s separator.
ChangeLog | 6 ++++++
NEWS | 1 +
src/number-match.c | 32 +++++++++++++++++++++++++++-----
3 files changed, 34 insertions(+), 5 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 8ab566404..4fbb5a4b9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2021-01-28 Morten Welinder <terra gnome org>
+
+ * src/number-match.c (format_match_decimal_number_with_locale): If
+ the thousands separator is a space character, allow plain space
+ also.
+
2021-01-19 Morten Welinder <terra gnome org>
* src/mstyle.c (gnm_style_linked_sheet_changed): Make sure to tell
diff --git a/NEWS b/NEWS
index 5f68abd42..5d329165c 100644
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,7 @@ Morten:
* Test suite improvements.
* Fix ods import problem with irregular sheet sizes.
* Fix ods import problem with crazy named expressions. [#557]
+ * Allow plain space as 1000s separator in FR locale.
--------------------------------------------------------------------------
Gnumeric 1.12.48
diff --git a/src/number-match.c b/src/number-match.c
index dfc2fc832..268647975 100644
--- a/src/number-match.c
+++ b/src/number-match.c
@@ -994,6 +994,24 @@ format_match_fraction (char const *text, int *denlen, gboolean mixed_only)
return value_new_float (f);
}
+// Are we looking at a thousands separator? (FR has a narrow space as the
+// separator. In that case we allow a plain space too. We could allow any
+// whitespace, but allowing \n, \r, \t, and \f certainly feels wrong.)
+static gboolean
+is_thousands_sep (const char *text, GString const *thousand, gboolean space1000)
+{
+ if (strncmp (thousand->str, text, thousand->len) == 0)
+ text += thousand->len;
+ else if (space1000 && *text == ' ')
+ text++;
+ else
+ return FALSE;
+
+ return (g_ascii_isdigit (text[0]) &&
+ g_ascii_isdigit (text[1]) &&
+ g_ascii_isdigit (text[2]));
+}
+
GnmValue *
format_match_decimal_number_with_locale (char const *text, GOFormatFamily *family,
@@ -1008,10 +1026,17 @@ format_match_decimal_number_with_locale (char const *text, GOFormatFamily *famil
GString *numstr = g_string_sized_new (20);
gboolean last_was_digit = FALSE;
gboolean allow1000 = (thousand != NULL) && (thousand->len != 0);
+ gboolean space1000;
g_return_val_if_fail (curr != NULL, NULL);
g_return_val_if_fail (decimal != NULL, NULL);
+ // If thousands separator is a single whitespace character, treat
+ // any whitespace character as such.
+ space1000 = allow1000 &&
+ g_utf8_strlen (thousand->str, thousand->len) == 1 &&
+ g_unichar_isspace (g_utf8_get_char (thousand->str));
+
while (*text) {
gunichar uc = g_utf8_get_char (text);
@@ -1050,11 +1075,8 @@ format_match_decimal_number_with_locale (char const *text, GOFormatFamily *famil
if (last_was_digit &&
allow1000 &&
- strncmp (thousand->str, text, thousand->len) == 0 &&
- g_ascii_isdigit (text[thousand->len]) &&
- g_ascii_isdigit (text[thousand->len + 1]) &&
- g_ascii_isdigit (text[thousand->len + 2])) {
- text += thousand->len;
+ is_thousands_sep (text, thousand, space1000)) {
+ text = g_utf8_next_char (text);
continue;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]