summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2005-07-11 17:36:43 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2005-07-11 17:36:43 +0000
commitea8801f63498c7b2dc3a92165d92157160587ee4 (patch)
treeaf129b00fecb1c0b4172ee8e0ab0213be0f9938e
parent56f04f355a1c49783f4c0b0be1914526f5d93541 (diff)
downloadmpfr-ea8801f63498c7b2dc3a92165d92157160587ee4.tar.gz
Fixed locale bug.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/mpfr-2-1-branch@3672 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--strtofr.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/strtofr.c b/strtofr.c
index f99f1dca8..d098184ad 100644
--- a/strtofr.c
+++ b/strtofr.c
@@ -186,6 +186,27 @@ digit_value_in_base (int c, int base)
return MPFR_LIKELY (digit < base) ? digit : -1;
}
+/* Compatible with any locale, but one still assumes that 'a', 'b', 'c',
+ ..., 'z', and 'A', 'B', 'C', ..., 'Z' are consecutive values (like
+ in any ASCII-based character set). */
+static int
+fast_casecmp (const char *s1, const char *s2)
+{
+ unsigned char c1, c2;
+
+ do
+ {
+ c2 = *(const unsigned char *) s2++;
+ if (c2 == '\0')
+ return 0;
+ c1 = *(const unsigned char *) s1++;
+ if (c1 >= 'A' && c1 <= 'Z')
+ c1 = c1 - 'A' + 'a';
+ }
+ while (c1 == c2);
+ return 1;
+}
+
/* Parse a string and fill pstr.
Return the advanced ptr too.
It returns:
@@ -214,12 +235,12 @@ parse_string (mpfr_t x, struct parsed_string *pstr,
while (isspace((unsigned char) *str)) str++;
/* Can be case-insensitive NAN */
- if (strncasecmp (str, "@nan@", 5) == 0)
+ if (fast_casecmp (str, "@nan@") == 0)
{
str += 5;
goto set_nan;
}
- if (base <= 16 && strncasecmp (str, "nan", 3) == 0)
+ if (base <= 16 && fast_casecmp (str, "nan") == 0)
{
str += 3;
set_nan:
@@ -249,17 +270,17 @@ parse_string (mpfr_t x, struct parsed_string *pstr,
str++;
/* Can be case-insensitive INF */
- if (strncasecmp (str, "@inf@", 5) == 0)
+ if (fast_casecmp (str, "@inf@") == 0)
{
str += 5;
goto set_inf;
}
- if (base <= 16 && strncasecmp (str, "infinity", 8) == 0)
+ if (base <= 16 && fast_casecmp (str, "infinity") == 0)
{
str += 8;
goto set_inf;
}
- if (base <= 16 && strncasecmp (str, "inf", 3) == 0)
+ if (base <= 16 && fast_casecmp (str, "inf") == 0)
{
str += 3;
set_inf: