mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Fixed a long standing NSNumberFormatter bug in conjunction with zero padding
and (old) NSNumberFormatterBehavior10_0 git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@39245 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
2b6f8a27f9
commit
2bef5cf85d
3 changed files with 20 additions and 5 deletions
|
@ -1,3 +1,11 @@
|
|||
2015-12-30 Marcus Mueller <znek@mulle-kybernetik.com>
|
||||
|
||||
* Source/NSNumberFormatter.m: fixed a subtle off-by-one formatter
|
||||
bug in conjunction with zero padding and NSNumberFormatterBehavior10_0.
|
||||
|
||||
* Tests/base/NSNumberFormatter/basic.m: added a test for this
|
||||
particular issue
|
||||
|
||||
2015-12-29 Marcus Mueller <znek@mulle-kybernetik.com>
|
||||
|
||||
* Source/NSUserNotification.m: "NSUserNotificationDefaultSoundName"
|
||||
|
|
|
@ -1271,16 +1271,18 @@ static NSUInteger _defaultBehavior = NSNumberFormatterBehavior10_4;
|
|||
|
||||
//sort out the padding for the integer part
|
||||
intPartRange = [useFormat rangeOfCharacterFromSet: placeHolders];
|
||||
if (NSMaxRange(intPartRange) < ([useFormat length] - 1))
|
||||
if (intPartRange.location != NSNotFound)
|
||||
{
|
||||
int nextFormatCharLoc = intPartRange.location;
|
||||
while (([placeHolders characterIsMember:
|
||||
[useFormat characterAtIndex: NSMaxRange(intPartRange)]]
|
||||
[useFormat characterAtIndex: nextFormatCharLoc]]
|
||||
|| [[useFormat substringWithRange:
|
||||
NSMakeRange(NSMaxRange(intPartRange), 1)] isEqual:
|
||||
NSMakeRange(nextFormatCharLoc, 1)] isEqual:
|
||||
defaultThousandsSeparator])
|
||||
&& NSMaxRange(intPartRange) < [useFormat length] - 1)
|
||||
&& nextFormatCharLoc < [useFormat length] - 1)
|
||||
{
|
||||
intPartRange.length++;
|
||||
nextFormatCharLoc++;
|
||||
}
|
||||
}
|
||||
intPad = [[[useFormat substringWithRange: intPartRange]
|
||||
|
@ -1298,7 +1300,7 @@ static NSUInteger _defaultBehavior = NSNumberFormatterBehavior10_4;
|
|||
NSRange ipRange;
|
||||
|
||||
ipRange =
|
||||
NSMakeRange(0, [intPad length] - [intPartString length] + 1);
|
||||
NSMakeRange(0, [intPad length] - [intPartString length]);
|
||||
[intPartString insertString:
|
||||
[intPad substringWithRange: ipRange] atIndex: 0];
|
||||
[intPartString replaceOccurrencesOfString: @"_"
|
||||
|
|
|
@ -49,6 +49,11 @@ int main()
|
|||
PASS_EQUAL([fmt stringForObjectValue: num], @" 001234",
|
||||
"numeric and space padding OK")
|
||||
|
||||
[fmt setFormat: @"000"];
|
||||
num = [[[NSNumber alloc] initWithInt: 10] autorelease];
|
||||
PASS_EQUAL([fmt stringForObjectValue: num], @"010",
|
||||
"numeric padding OK")
|
||||
|
||||
[fmt setAllowsFloats: YES];
|
||||
|
||||
num = [[[NSNumber alloc] initWithFloat: 1234.56] autorelease];
|
||||
|
|
Loading…
Reference in a new issue