From afc7c42eca36750d2c33ac008d85783baad81c39 Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Thu, 22 Aug 2013 20:03:02 +0000 Subject: [PATCH] GSScanDouble() OSX compatibility fix. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@37010 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 8 ++++++++ Source/NSScanner.m | 23 +++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index fb6ba857a..9bafb35e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2013-08-22 Richard Frith-Macdonald + + * Source/NSScanner.m: GSScanDouble() permit overlong mantissa (more + digits than can be represented in a double) and ignore excess digits + for compatibility with OSX. Inspired by testplant branch r37004 + which tries to allow more digits at the cost of breaking parsing + in locales where the decimal point is a comma rather than a dot. + 2013-08-22 Richard Frith-Macdonald * Source/NSIndexPath.m: diff --git a/Source/NSScanner.m b/Source/NSScanner.m index 7edba57d0..72f4bf578 100644 --- a/Source/NSScanner.m +++ b/Source/NSScanner.m @@ -1289,19 +1289,26 @@ GSScanDouble(unichar *buf, unsigned length, double *result) mantissaLength++; } } - if (dotPos < 0) - { - dotPos = mantissaLength; - } - if (0 == mantissaLength) { return NO; // No mantissa ... not a double } - if (19 == mantissaLength - || (18 == mantissaLength && pos < length && isdigit(buf[pos]))) + if (mantissaLength > 18) { - return NO; // Mantissa is too long. + /* Mantissa too long ... ignore excess. + */ + if (19 == mantissaLength && (dotPos < 0 || dotPos >= mantissaLength)) + { + mantissaLength--; + } + else + { + mantissaLength = 19; + } + } + if (dotPos < 0) + { + dotPos = mantissaLength; } dotPos -= mantissaLength; // Exponent offset for decimal point