[gnumeric] gnm_strtol: handle non-ascii digits.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] gnm_strtol: handle non-ascii digits.
- Date: Fri, 23 Dec 2011 19:19:45 +0000 (UTC)
commit 866959eee4488e3b75b5f0a273fb5049d2d592e9
Author: Morten Welinder <terra gnome org>
Date: Fri Dec 23 14:19:22 2011 -0500
gnm_strtol: handle non-ascii digits.
ChangeLog | 1 +
src/gutils.c | 19 +++++++++++++++++++
src/gutils.h | 1 +
src/parser.y | 3 +--
4 files changed, 22 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 63d2d66..db19aaa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
* src/gutils.c (gnm_strto): New function that handles non-ascii
digits.
+ (gnm_strtol): Ditto.
2011-12-21 Andreas J. Guelzow <aguelzow pyrshep ca>
diff --git a/src/gutils.c b/src/gutils.c
index 9fe8e86..1e67a99 100644
--- a/src/gutils.c
+++ b/src/gutils.c
@@ -222,6 +222,25 @@ gnm_strto (const char *s, char **end)
return res;
}
+/* Like strtol, but handling non-ascii digits and sane errno. */
+long
+gnm_strtol (const char *s, char **end, int base)
+{
+ char *s2 = map_nonascii_digits (s);
+ long res;
+
+ errno = 0; /* strtol doesn't clear, so we do */
+
+ if (!s2)
+ return strtol (s, end, base);
+
+ res = strtol (s2, end, base);
+ 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,
diff --git a/src/gutils.h b/src/gutils.h
index d233eda..6f56047 100644
--- a/src/gutils.h
+++ b/src/gutils.h
@@ -20,6 +20,7 @@ char const *gnm_locale_dir (void);
char const *gnm_usr_dir (gboolean versioned);
gnm_float gnm_strto (const char *s, char **end);
+long gnm_strtol (const char *s, char **end, int base);
#define PLUGIN_SUBDIR "plugins"
diff --git a/src/parser.y b/src/parser.y
index 91b5c77..b4fd362 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -1302,8 +1302,7 @@ yylex (void)
char *end;
long l;
- errno = 0;
- l = strtol (start, &end, 10);
+ l = gnm_strtol (start, &end, 10);
if (start == end) {
g_warning ("%s is not an integer, but was expected to be one", start);
} else if (errno != ERANGE && l >= INT_MIN && l <= INT_MAX) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]