[gnumeric] gnm_strto: handle non-ascii digits.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] gnm_strto: handle non-ascii digits.
- Date: Fri, 23 Dec 2011 16:42:04 +0000 (UTC)
commit 3b075964a8eb12a9f9b7e52300ede23ef6f3248a
Author: Morten Welinder <terra gnome org>
Date: Fri Dec 23 11:41:46 2011 -0500
gnm_strto: handle non-ascii digits.
ChangeLog | 5 +++++
src/gutils.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
src/gutils.h | 2 ++
src/numbers.h | 4 ++--
4 files changed, 57 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index bb8e538..63d2d66 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2011-12-23 Morten Welinder <terra gnome org>
+
+ * src/gutils.c (gnm_strto): New function that handles non-ascii
+ digits.
+
2011-12-21 Andreas J. Guelzow <aguelzow pyrshep ca>
* src/wbc-gtk-edit.c (wbcg_edit_start): adjust call to
diff --git a/src/gutils.c b/src/gutils.c
index 785e96f..9fe8e86 100644
--- a/src/gutils.c
+++ b/src/gutils.c
@@ -175,6 +175,54 @@ gnm_usr_dir (gboolean versioned)
return versioned ? gnumeric_usr_dir : gnumeric_usr_dir_unversioned;
}
+static char *
+map_nonascii_digits (const char *s)
+{
+ const char *p;
+
+ for (p = s; *p; p = g_utf8_next_char (p)) {
+ gunichar uc = g_utf8_get_char (p);
+ if (uc > 127 && g_unichar_isdigit (uc)) {
+ GString *res = g_string_new (s);
+ char *d = res->str + (p - s);
+ p = d;
+
+ while (*p) {
+ gunichar uc = g_utf8_get_char (p);
+ const char *next = g_utf8_next_char (p);
+ if (uc > 127 && g_unichar_isdigit (uc)) {
+ *d++ = '0' + g_unichar_digit_value (uc);
+ } else {
+ g_memmove (d, p, next - p);
+ d += (next - p);
+ }
+ p = next;
+ }
+ g_string_truncate (res, d - res->str);
+ return g_string_free (res, FALSE);
+ }
+ }
+
+ return NULL;
+}
+
+/* Like gnm_strto_base, but handling non-ascii digits. */
+gnm_float
+gnm_strto (const char *s, char **end)
+{
+ char *s2 = map_nonascii_digits (s);
+ gnm_float res;
+ if (!s2)
+ return gnm_strto_base (s, end);
+
+ res = gnm_strto_base (s2, end);
+ if (end)
+ *end = g_utf8_offset_to_pointer (s, g_utf8_pointer_to_offset (s2, *end));
+ g_free (s2);
+ return res;
+}
+
+
int
gnm_regcomp_XL (GORegexp *preg, char const *pattern, int cflags,
gboolean full)
diff --git a/src/gutils.h b/src/gutils.h
index 5d3e84c..d233eda 100644
--- a/src/gutils.h
+++ b/src/gutils.h
@@ -19,6 +19,8 @@ char const *gnm_icon_dir (void);
char const *gnm_locale_dir (void);
char const *gnm_usr_dir (gboolean versioned);
+gnm_float gnm_strto (const char *s, char **end);
+
#define PLUGIN_SUBDIR "plugins"
int gnm_regcomp_XL (GORegexp *preg, char const *pattern,
diff --git a/src/numbers.h b/src/numbers.h
index 112f339..75381b0 100644
--- a/src/numbers.h
+++ b/src/numbers.h
@@ -100,7 +100,7 @@ gnm_float gnm_yn (int n, gnm_float x);
#define gnm_sin sinl
#define gnm_sinh sinhl
#define gnm_sqrt sqrtl
-#define gnm_strto go_strtold
+#define gnm_strto_base go_strtold
#define gnm_sub_epsilon go_sub_epsilonl
#define gnm_tan tanl
#define gnm_tanh tanhl
@@ -181,7 +181,7 @@ typedef double gnm_float;
#define gnm_sin sin
#define gnm_sinh sinh
#define gnm_sqrt sqrt
-#define gnm_strto go_strtod
+#define gnm_strto_base go_strtod
#define gnm_sub_epsilon go_sub_epsilon
#define gnm_tan tan
#define gnm_tanh tanh
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]