mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-02 01:21:08 +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
82c85333b5
commit
5f9bfda3f5
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>
|
2015-12-29 Marcus Mueller <znek@mulle-kybernetik.com>
|
||||||
|
|
||||||
* Source/NSUserNotification.m: "NSUserNotificationDefaultSoundName"
|
* Source/NSUserNotification.m: "NSUserNotificationDefaultSoundName"
|
||||||
|
|
|
@ -1271,16 +1271,18 @@ static NSUInteger _defaultBehavior = NSNumberFormatterBehavior10_4;
|
||||||
|
|
||||||
//sort out the padding for the integer part
|
//sort out the padding for the integer part
|
||||||
intPartRange = [useFormat rangeOfCharacterFromSet: placeHolders];
|
intPartRange = [useFormat rangeOfCharacterFromSet: placeHolders];
|
||||||
if (NSMaxRange(intPartRange) < ([useFormat length] - 1))
|
if (intPartRange.location != NSNotFound)
|
||||||
{
|
{
|
||||||
|
int nextFormatCharLoc = intPartRange.location;
|
||||||
while (([placeHolders characterIsMember:
|
while (([placeHolders characterIsMember:
|
||||||
[useFormat characterAtIndex: NSMaxRange(intPartRange)]]
|
[useFormat characterAtIndex: nextFormatCharLoc]]
|
||||||
|| [[useFormat substringWithRange:
|
|| [[useFormat substringWithRange:
|
||||||
NSMakeRange(NSMaxRange(intPartRange), 1)] isEqual:
|
NSMakeRange(nextFormatCharLoc, 1)] isEqual:
|
||||||
defaultThousandsSeparator])
|
defaultThousandsSeparator])
|
||||||
&& NSMaxRange(intPartRange) < [useFormat length] - 1)
|
&& nextFormatCharLoc < [useFormat length] - 1)
|
||||||
{
|
{
|
||||||
intPartRange.length++;
|
intPartRange.length++;
|
||||||
|
nextFormatCharLoc++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
intPad = [[[useFormat substringWithRange: intPartRange]
|
intPad = [[[useFormat substringWithRange: intPartRange]
|
||||||
|
@ -1298,7 +1300,7 @@ static NSUInteger _defaultBehavior = NSNumberFormatterBehavior10_4;
|
||||||
NSRange ipRange;
|
NSRange ipRange;
|
||||||
|
|
||||||
ipRange =
|
ipRange =
|
||||||
NSMakeRange(0, [intPad length] - [intPartString length] + 1);
|
NSMakeRange(0, [intPad length] - [intPartString length]);
|
||||||
[intPartString insertString:
|
[intPartString insertString:
|
||||||
[intPad substringWithRange: ipRange] atIndex: 0];
|
[intPad substringWithRange: ipRange] atIndex: 0];
|
||||||
[intPartString replaceOccurrencesOfString: @"_"
|
[intPartString replaceOccurrencesOfString: @"_"
|
||||||
|
|
|
@ -49,6 +49,11 @@ int main()
|
||||||
PASS_EQUAL([fmt stringForObjectValue: num], @" 001234",
|
PASS_EQUAL([fmt stringForObjectValue: num], @" 001234",
|
||||||
"numeric and space padding OK")
|
"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];
|
[fmt setAllowsFloats: YES];
|
||||||
|
|
||||||
num = [[[NSNumber alloc] initWithFloat: 1234.56] autorelease];
|
num = [[[NSNumber alloc] initWithFloat: 1234.56] autorelease];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue