Implmented a few more methods requiring ICU. Added code in -stringForObjectValue: to handle NSNumberFormatterBehavior10_4... need to test this code against OS X, I'm not sure I caught every case.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31885 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
stefanbidi 2011-01-13 00:29:30 +00:00
parent 6d4636d593
commit 87e42ac634
2 changed files with 450 additions and 260 deletions

View file

@ -1,3 +1,8 @@
2011-01-12 Stefan Bidigaray <stefanbidi@gmail.com>
* Source/NSNumberFormatter.m: Implemented more methods.
([-stringForObjectValue:]): Add code for NSNumberFormatterBehavior10_4.
2011-01-11 Stefan Bidigaray <stefanbidi@gmail.com> 2011-01-11 Stefan Bidigaray <stefanbidi@gmail.com>
* Source/NSLocale.m: Removed NSLog used for debugging. * Source/NSLocale.m: Removed NSLog used for debugging.

View file

@ -50,6 +50,7 @@
#define MAX_SYMBOL_SIZE 32 #define MAX_SYMBOL_SIZE 32
#define MAX_TEXT_ATTRIB_SIZE 512 #define MAX_TEXT_ATTRIB_SIZE 512
#define MAX_BUFFER_SIZE 1024
#if GS_USE_ICU == 1 #if GS_USE_ICU == 1
static inline UNumberFormatStyle static inline UNumberFormatStyle
@ -85,7 +86,7 @@ _NSToICUFormatStyle (NSNumberFormatterStyle style)
static inline UNumberFormatPadPosition static inline UNumberFormatPadPosition
_NSToICUPadPosition (NSNumberFormatterPadPosition position) _NSToICUPadPosition (NSNumberFormatterPadPosition position)
{ {
UNumberFormatPadPosition result; UNumberFormatPadPosition result = 0;
switch (position) switch (position)
{ {
@ -109,7 +110,7 @@ _NSToICUPadPosition (NSNumberFormatterPadPosition position)
static inline NSNumberFormatterPadPosition static inline NSNumberFormatterPadPosition
_ICUToNSPadPosition (UNumberFormatPadPosition position) _ICUToNSPadPosition (UNumberFormatPadPosition position)
{ {
NSNumberFormatterPadPosition result; NSNumberFormatterPadPosition result = 0;
switch (position) switch (position)
{ {
@ -613,7 +614,7 @@ static NSUInteger _defaultBehavior = 0;
{ {
if (_behavior == NSNumberFormatterBehavior10_4 if (_behavior == NSNumberFormatterBehavior10_4
#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST) #if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
|| NSNumberFormatterBehaviorDefault) || _behavior == NSNumberFormatterBehaviorDefault)
#endif #endif
{ {
#if GS_USE_ICU == 1 #if GS_USE_ICU == 1
@ -622,7 +623,7 @@ static NSUInteger _defaultBehavior = 0;
} }
else if (_behavior == NSNumberFormatterBehavior10_0 else if (_behavior == NSNumberFormatterBehavior10_0
#if OS_API_VERSION(GS_OPENSTEP_V, MAC_OS_X_VERSION_10_3) #if OS_API_VERSION(GS_OPENSTEP_V, MAC_OS_X_VERSION_10_3)
|| NSNumberFormatterBehaviorDefault) || _behavior == NSNumberFormatterBehaviorDefault)
#endif #endif
{ {
if ([newSeparator length] > 0) if ([newSeparator length] > 0)
@ -718,258 +719,313 @@ static NSUInteger _defaultBehavior = 0;
- (NSString*) stringForObjectValue: (id)anObject - (NSString*) stringForObjectValue: (id)anObject
{ {
NSMutableDictionary *locale; if (_behavior == NSNumberFormatterBehavior10_4
NSCharacterSet *formattingCharacters; #if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
NSCharacterSet *placeHolders; || _behavior == NSNumberFormatterBehaviorDefault)
NSString *prefix; #endif
NSString *suffix; {
NSString *wholeString; #if GS_USE_ICU == 1
NSString *fracPad = nil;
NSString *fracPartString;
NSMutableString *intPartString;
NSMutableString *formattedNumber;
NSMutableString *intPad;
NSRange prefixRange;
NSRange decimalPlaceRange;
NSRange suffixRange;
NSRange intPartRange;
NSDecimal representativeDecimal;
NSDecimal roundedDecimal;
NSDecimalNumber *roundedNumber;
NSDecimalNumber *intPart;
NSDecimalNumber *fracPart;
int decimalPlaces = 0;
BOOL displayThousandsSeparators = NO;
BOOL displayFractionalPart = NO;
BOOL negativeNumber = NO;
NSString *useFormat;
NSString *defaultDecimalSeparator = nil;
NSString *defaultThousandsSeparator = nil;
if (_localizesFormat) #define STRING_FROM_NUMBER(function, number) do \
{ { \
NSDictionary *defaultLocale = GSDomainFromDefaultLocale(); UChar *outStr = buffer; \
defaultDecimalSeparator UErrorCode err = U_ZERO_ERROR; \
= [defaultLocale objectForKey: NSDecimalSeparator]; int32_t len; \
defaultThousandsSeparator NSString *result; \
= [defaultLocale objectForKey: NSThousandsSeparator]; \
} len = function (_formatter, number, outStr, MAX_BUFFER_SIZE, NULL, &err); \
if (len > MAX_BUFFER_SIZE) \
outStr = NSZoneMalloc ([self zone], len * sizeof(UChar));\
err = U_ZERO_ERROR; \
function (_formatter, number, outStr, MAX_BUFFER_SIZE, NULL, &err); \
result = [NSString stringWithCharacters: outStr length: len]; \
if (len > MAX_BUFFER_SIZE) \
NSZoneFree ([self zone], outStr); \
return result; \
} while (0)
if (defaultDecimalSeparator == nil) UChar buffer[MAX_BUFFER_SIZE];
{
defaultDecimalSeparator = @"."; // FIXME: What to do with unsigned types?
if (nil == anObject)
return [self nilSymbol];
else if (![anObject isKindOfClass: [NSNumber class]])
return [self notANumberSymbol];
else if ([anObject objCType] == @encode(int))
STRING_FROM_NUMBER(unum_format, [anObject intValue]);
else if ([anObject objCType] == @encode(long long))
STRING_FROM_NUMBER(unum_formatInt64, [anObject longLongValue]);
else if ([anObject objCType] == @encode(BOOL))
STRING_FROM_NUMBER(unum_format, (int)[anObject boolValue]);
else if ([anObject objCType] == @encode(double))
STRING_FROM_NUMBER(unum_formatDouble, [anObject doubleValue]);
else if ([anObject objCType] == @encode(float))
STRING_FROM_NUMBER(unum_formatDouble, (double)[anObject floatValue]);
#endif
} }
if (defaultThousandsSeparator == nil) else if (_behavior == NSNumberFormatterBehavior10_0
#if OS_API_VERSION(GS_OPENSTEP_V, MAC_OS_X_VERSION_10_3)
|| _behavior == NSNumberFormatterBehaviorDefault)
#endif
// FIXME: Should this method even work for OS X < 10.4?
{ {
defaultThousandsSeparator = @","; NSMutableDictionary *locale;
} NSCharacterSet *formattingCharacters;
formattingCharacters = [NSCharacterSet NSCharacterSet *placeHolders;
characterSetWithCharactersInString: @"0123456789#.,_"]; NSString *prefix;
placeHolders = [NSCharacterSet NSString *suffix;
characterSetWithCharactersInString: @"0123456789#_"]; NSString *wholeString;
NSString *fracPad = nil;
NSString *fracPartString;
NSMutableString *intPartString;
NSMutableString *formattedNumber;
NSMutableString *intPad;
NSRange prefixRange;
NSRange decimalPlaceRange;
NSRange suffixRange;
NSRange intPartRange;
NSDecimal representativeDecimal;
NSDecimal roundedDecimal;
NSDecimalNumber *roundedNumber;
NSDecimalNumber *intPart;
NSDecimalNumber *fracPart;
int decimalPlaces = 0;
BOOL displayThousandsSeparators = NO;
BOOL displayFractionalPart = NO;
BOOL negativeNumber = NO;
NSString *useFormat;
NSString *defaultDecimalSeparator = nil;
NSString *defaultThousandsSeparator = nil;
if (nil == anObject) if (_localizesFormat)
return [[self attributedStringForNil] string];
if (![anObject isKindOfClass: [NSNumber class]])
return [[self attributedStringForNotANumber] string];
if ([anObject isEqual: [NSDecimalNumber notANumber]])
return [[self attributedStringForNotANumber] string];
if (_attributedStringForZero
&& [anObject isEqual: [NSDecimalNumber zero]])
return [[self attributedStringForZero] string];
useFormat = _positiveFormat;
if ([(NSNumber*)anObject compare: [NSDecimalNumber zero]]
== NSOrderedAscending)
{
useFormat = _negativeFormat;
negativeNumber = YES;
}
// if no format specified, use the same default that Cocoa does
if (nil == useFormat)
{
useFormat = [NSString stringWithFormat: @"%@#%@###%@##",
negativeNumber ? @"-" : @"",
defaultThousandsSeparator,
defaultDecimalSeparator];
}
prefixRange = [useFormat rangeOfCharacterFromSet: formattingCharacters];
if (NSNotFound != prefixRange.location)
{
prefix = [useFormat substringToIndex: prefixRange.location];
}
else
{
prefix = @"";
}
locale = [NSMutableDictionary dictionaryWithCapacity: 3];
[locale setObject: @"" forKey: NSThousandsSeparator];
[locale setObject: @"" forKey: NSDecimalSeparator];
//should also set NSDecimalDigits?
if ([self hasThousandSeparators]
&& (0 != [useFormat rangeOfString: defaultThousandsSeparator].length))
{
displayThousandsSeparators = YES;
}
if ([self allowsFloats]
&& (NSNotFound
!= [useFormat rangeOfString: defaultDecimalSeparator].location))
{
decimalPlaceRange = [useFormat rangeOfString: defaultDecimalSeparator
options: NSBackwardsSearch];
if (NSMaxRange(decimalPlaceRange) == [useFormat length])
{ {
decimalPlaces = 0; NSDictionary *defaultLocale = GSDomainFromDefaultLocale();
defaultDecimalSeparator
= [defaultLocale objectForKey: NSDecimalSeparator];
defaultThousandsSeparator
= [defaultLocale objectForKey: NSThousandsSeparator];
}
if (defaultDecimalSeparator == nil)
{
defaultDecimalSeparator = @".";
}
if (defaultThousandsSeparator == nil)
{
defaultThousandsSeparator = @",";
}
formattingCharacters = [NSCharacterSet
characterSetWithCharactersInString: @"0123456789#.,_"];
placeHolders = [NSCharacterSet
characterSetWithCharactersInString: @"0123456789#_"];
if (nil == anObject)
return [[self attributedStringForNil] string];
if (![anObject isKindOfClass: [NSNumber class]])
return [[self attributedStringForNotANumber] string];
if ([anObject isEqual: [NSDecimalNumber notANumber]])
return [[self attributedStringForNotANumber] string];
if (_attributedStringForZero
&& [anObject isEqual: [NSDecimalNumber zero]])
return [[self attributedStringForZero] string];
useFormat = _positiveFormat;
if ([(NSNumber*)anObject compare: [NSDecimalNumber zero]]
== NSOrderedAscending)
{
useFormat = _negativeFormat;
negativeNumber = YES;
}
// if no format specified, use the same default that Cocoa does
if (nil == useFormat)
{
useFormat = [NSString stringWithFormat: @"%@#%@###%@##",
negativeNumber ? @"-" : @"",
defaultThousandsSeparator,
defaultDecimalSeparator];
}
prefixRange = [useFormat rangeOfCharacterFromSet: formattingCharacters];
if (NSNotFound != prefixRange.location)
{
prefix = [useFormat substringToIndex: prefixRange.location];
} }
else else
{ {
while ([placeHolders characterIsMember: prefix = @"";
[useFormat characterAtIndex: NSMaxRange(decimalPlaceRange)]]) }
locale = [NSMutableDictionary dictionaryWithCapacity: 3];
[locale setObject: @"" forKey: NSThousandsSeparator];
[locale setObject: @"" forKey: NSDecimalSeparator];
//should also set NSDecimalDigits?
if ([self hasThousandSeparators]
&& (0 != [useFormat rangeOfString: defaultThousandsSeparator].length))
{
displayThousandsSeparators = YES;
}
if ([self allowsFloats]
&& (NSNotFound
!= [useFormat rangeOfString: defaultDecimalSeparator].location))
{
decimalPlaceRange = [useFormat rangeOfString: defaultDecimalSeparator
options: NSBackwardsSearch];
if (NSMaxRange(decimalPlaceRange) == [useFormat length])
{ {
decimalPlaceRange.length++; decimalPlaces = 0;
if (NSMaxRange(decimalPlaceRange) == [useFormat length])
break;
} }
decimalPlaces=decimalPlaceRange.length -= 1; else
decimalPlaceRange.location += 1; {
fracPad = [useFormat substringWithRange:decimalPlaceRange]; while ([placeHolders characterIsMember:
} [useFormat characterAtIndex: NSMaxRange(decimalPlaceRange)]])
if (0 != decimalPlaces) {
displayFractionalPart = YES; decimalPlaceRange.length++;
if (NSMaxRange(decimalPlaceRange) == [useFormat length])
break;
}
decimalPlaces=decimalPlaceRange.length -= 1;
decimalPlaceRange.location += 1;
fracPad = [useFormat substringWithRange:decimalPlaceRange];
}
if (0 != decimalPlaces)
displayFractionalPart = YES;
}
representativeDecimal = [anObject decimalValue];
NSDecimalRound(&roundedDecimal, &representativeDecimal, decimalPlaces,
NSRoundPlain);
roundedNumber =
[NSDecimalNumber decimalNumberWithDecimal: roundedDecimal];
/* Arguably this fiddling could be done by GSDecimalString() but I
* thought better to leave that behaviour as it is and provide the
* desired prettification here
*/
if (negativeNumber)
roundedNumber = [roundedNumber decimalNumberByMultiplyingBy:
(NSDecimalNumber*)[NSDecimalNumber numberWithInt: -1]];
intPart = (NSDecimalNumber*)
[NSDecimalNumber numberWithInt: (int)[roundedNumber doubleValue]];
fracPart = [roundedNumber decimalNumberBySubtracting: intPart];
intPartString
= AUTORELEASE([[intPart descriptionWithLocale: locale] mutableCopy]);
//sort out the padding for the integer part
intPartRange = [useFormat rangeOfCharacterFromSet: placeHolders];
if (NSMaxRange(intPartRange) < ([useFormat length] - 1))
{
while (([placeHolders characterIsMember:
[useFormat characterAtIndex: NSMaxRange(intPartRange)]]
|| [[useFormat substringFromRange:
NSMakeRange(NSMaxRange(intPartRange), 1)] isEqual:
defaultThousandsSeparator])
&& NSMaxRange(intPartRange) < [useFormat length] - 1)
{
intPartRange.length++;
}
}
intPad = [[useFormat substringWithRange: intPartRange] mutableCopy];
[intPad replaceOccurrencesOfString: defaultThousandsSeparator
withString: @""
options: 0
range: NSMakeRange(0, [intPad length])];
[intPad replaceOccurrencesOfString: @"#"
withString: @""
options: NSAnchoredSearch
range: NSMakeRange(0, [intPad length])];
if ([intPad length] > [intPartString length])
{
NSRange ipRange;
ipRange =
NSMakeRange(0, [intPad length] - [intPartString length] + 1);
[intPartString insertString:
[intPad substringWithRange: ipRange] atIndex: 0];
[intPartString replaceOccurrencesOfString: @"_"
withString: @" "
options: 0
range: NSMakeRange(0, [intPartString length])];
[intPartString replaceOccurrencesOfString: @"#"
withString: @"0"
options: 0
range: NSMakeRange(0, [intPartString length])];
}
// fix the thousands separators up
if (displayThousandsSeparators && [intPartString length] > 3)
{
int index = [intPartString length];
while (0 < (index -= 3))
{
[intPartString insertString: [self thousandSeparator] atIndex: index];
}
}
formattedNumber = [intPartString mutableCopy];
//fix up the fractional part
if (displayFractionalPart)
{
if (0 != decimalPlaces)
{
NSMutableString *ms;
fracPart = [fracPart decimalNumberByMultiplyingByPowerOf10:
decimalPlaces];
ms = [[fracPart descriptionWithLocale: locale] mutableCopy];
[ms replaceOccurrencesOfString: @"0"
withString: @""
options: (NSBackwardsSearch | NSAnchoredSearch)
range: NSMakeRange(0, [ms length])];
if ([fracPad length] > [ms length])
{
NSRange fpRange;
fpRange = NSMakeRange([ms length],
([fracPad length] - [ms length]));
[ms appendString:
[fracPad substringWithRange: fpRange]];
[ms replaceOccurrencesOfString: @"#"
withString: @""
options: (NSBackwardsSearch | NSAnchoredSearch)
range: NSMakeRange(0, [ms length])];
[ms replaceOccurrencesOfString: @"#"
withString: @"0"
options: 0
range: NSMakeRange(0, [ms length])];
[ms replaceOccurrencesOfString: @"_"
withString: @" "
options: 0
range: NSMakeRange(0, [ms length])];
}
fracPartString = AUTORELEASE(ms);
}
else
{
fracPartString = @"0";
}
[formattedNumber appendString: [self decimalSeparator]];
[formattedNumber appendString: fracPartString];
}
/*FIXME - the suffix doesn't behave the same as on Mac OS X.
* Our suffix is everything which follows the final formatting
* character. Cocoa's suffix is everything which isn't a
* formatting character nor in the prefix
*/
suffixRange = [useFormat rangeOfCharacterFromSet: formattingCharacters
options: NSBackwardsSearch];
suffix = [useFormat substringFromIndex: NSMaxRange(suffixRange)];
wholeString = [[prefix stringByAppendingString: formattedNumber]
stringByAppendingString: suffix];
[formattedNumber release];
return wholeString;
} }
representativeDecimal = [anObject decimalValue];
NSDecimalRound(&roundedDecimal, &representativeDecimal, decimalPlaces,
NSRoundPlain);
roundedNumber = [NSDecimalNumber decimalNumberWithDecimal: roundedDecimal];
/* Arguably this fiddling could be done by GSDecimalString() but I
* thought better to leave that behaviour as it is and provide the
* desired prettification here
*/
if (negativeNumber)
roundedNumber = [roundedNumber decimalNumberByMultiplyingBy:
(NSDecimalNumber*)[NSDecimalNumber numberWithInt: -1]];
intPart = (NSDecimalNumber*)
[NSDecimalNumber numberWithInt: (int)[roundedNumber doubleValue]];
fracPart = [roundedNumber decimalNumberBySubtracting: intPart];
intPartString
= AUTORELEASE([[intPart descriptionWithLocale: locale] mutableCopy]);
//sort out the padding for the integer part return nil;
intPartRange = [useFormat rangeOfCharacterFromSet: placeHolders];
if (NSMaxRange(intPartRange) < ([useFormat length] - 1))
{
while (([placeHolders characterIsMember:
[useFormat characterAtIndex: NSMaxRange(intPartRange)]]
|| [[useFormat substringFromRange:
NSMakeRange(NSMaxRange(intPartRange), 1)] isEqual:
defaultThousandsSeparator])
&& NSMaxRange(intPartRange) < [useFormat length] - 1)
{
intPartRange.length++;
}
}
intPad = [[useFormat substringWithRange: intPartRange] mutableCopy];
[intPad replaceOccurrencesOfString: defaultThousandsSeparator
withString: @""
options: 0
range: NSMakeRange(0, [intPad length])];
[intPad replaceOccurrencesOfString: @"#"
withString: @""
options: NSAnchoredSearch
range: NSMakeRange(0, [intPad length])];
if ([intPad length] > [intPartString length])
{
NSRange ipRange;
ipRange = NSMakeRange(0, [intPad length] - [intPartString length] + 1);
[intPartString insertString:
[intPad substringWithRange: ipRange] atIndex: 0];
[intPartString replaceOccurrencesOfString: @"_"
withString: @" "
options: 0
range: NSMakeRange(0, [intPartString length])];
[intPartString replaceOccurrencesOfString: @"#"
withString: @"0"
options: 0
range: NSMakeRange(0, [intPartString length])];
}
// fix the thousands separators up
if (displayThousandsSeparators && [intPartString length] > 3)
{
int index = [intPartString length];
while (0 < (index -= 3))
{
[intPartString insertString: [self thousandSeparator] atIndex: index];
}
}
formattedNumber = [intPartString mutableCopy];
//fix up the fractional part
if (displayFractionalPart)
{
if (0 != decimalPlaces)
{
NSMutableString *ms;
fracPart = [fracPart decimalNumberByMultiplyingByPowerOf10:
decimalPlaces];
ms = [[fracPart descriptionWithLocale: locale] mutableCopy];
[ms replaceOccurrencesOfString: @"0"
withString: @""
options: (NSBackwardsSearch | NSAnchoredSearch)
range: NSMakeRange(0, [ms length])];
if ([fracPad length] > [ms length])
{
NSRange fpRange;
fpRange = NSMakeRange([ms length],
([fracPad length] - [ms length]));
[ms appendString:
[fracPad substringWithRange: fpRange]];
[ms replaceOccurrencesOfString: @"#"
withString: @""
options: (NSBackwardsSearch | NSAnchoredSearch)
range: NSMakeRange(0, [ms length])];
[ms replaceOccurrencesOfString: @"#"
withString: @"0"
options: 0
range: NSMakeRange(0, [ms length])];
[ms replaceOccurrencesOfString: @"_"
withString: @" "
options: 0
range: NSMakeRange(0, [ms length])];
}
fracPartString = AUTORELEASE(ms);
}
else
{
fracPartString = @"0";
}
[formattedNumber appendString: [self decimalSeparator]];
[formattedNumber appendString: fracPartString];
}
/*FIXME - the suffix doesn't behave the same as on Mac OS X.
* Our suffix is everything which follows the final formatting
* character. Cocoa's suffix is everything which isn't a
* formatting character nor in the prefix
*/
suffixRange = [useFormat rangeOfCharacterFromSet: formattingCharacters
options: NSBackwardsSearch];
suffix = [useFormat substringFromIndex: NSMaxRange(suffixRange)];
wholeString = [[prefix stringByAppendingString: formattedNumber]
stringByAppendingString: suffix];
[formattedNumber release];
return wholeString;
} }
- (NSDictionary*) textAttributesForNegativeValues - (NSDictionary*) textAttributesForNegativeValues
@ -1261,12 +1317,12 @@ static NSUInteger _defaultBehavior = 0;
- (void) setNilSymbol: (NSString *) string - (void) setNilSymbol: (NSString *) string
{ {
return; return; // FIXME
} }
- (NSString *) nilSymbol - (NSString *) nilSymbol
{ {
return nil; return nil; // FIXME
} }
- (void) setNotANumberSymbol: (NSString *) string - (void) setNotANumberSymbol: (NSString *) string
@ -1456,12 +1512,12 @@ static NSUInteger _defaultBehavior = 0;
- (void) setTextAttributesForZero: (NSDictionary *) newAttributes - (void) setTextAttributesForZero: (NSDictionary *) newAttributes
{ {
return; return; // FIXME
} }
- (NSDictionary *) textAttributesForZero - (NSDictionary *) textAttributesForZero
{ {
return nil; return nil; // FIXME
} }
- (void) setTextAttributesForNil: (NSDictionary *) newAttributes - (void) setTextAttributesForNil: (NSDictionary *) newAttributes
@ -1471,37 +1527,37 @@ static NSUInteger _defaultBehavior = 0;
- (NSDictionary *) textAttributesForNil - (NSDictionary *) textAttributesForNil
{ {
return nil; return nil; // FIXME
} }
- (void) setTextAttributesForNotANumber: (NSDictionary *) newAttributes - (void) setTextAttributesForNotANumber: (NSDictionary *) newAttributes
{ {
return; return; // FIXME
} }
- (NSDictionary *) textAttributesForNotANumber - (NSDictionary *) textAttributesForNotANumber
{ {
return nil; return nil; // FIXME
} }
- (void) setTextAttributesForPositiveInfinity: (NSDictionary *) newAttributes - (void) setTextAttributesForPositiveInfinity: (NSDictionary *) newAttributes
{ {
return; return; // FIXME
} }
- (NSDictionary *) textAttributesForPositiveInfinity - (NSDictionary *) textAttributesForPositiveInfinity
{ {
return nil; return nil; // FIXME
} }
- (void) setTextAttributesForNegativeInfinity: (NSDictionary *) newAttributes - (void) setTextAttributesForNegativeInfinity: (NSDictionary *) newAttributes
{ {
return; return; // FIXME
} }
- (NSDictionary *) textAttributesForNegativeInfinity - (NSDictionary *) textAttributesForNegativeInfinity
{ {
return nil; return nil; // FIXME
} }
@ -1525,22 +1581,39 @@ static NSUInteger _defaultBehavior = 0;
- (void) setUsesGroupingSeparator: (BOOL) flag - (void) setUsesGroupingSeparator: (BOOL) flag
{ {
#if GS_USE_ICU == 1
unum_setAttribute (_formatter, UNUM_GROUPING_USED, flag);
#else
return; return;
#endif
} }
- (BOOL) usesGroupingSeparator - (BOOL) usesGroupingSeparator
{ {
#if GS_USE_ICU == 1
return (BOOL)unum_getAttribute (_formatter, UNUM_GROUPING_USED);
#else
return NO; return NO;
#endif
} }
- (void) setAlwaysShowsDecimalSeparator: (BOOL) flag - (void) setAlwaysShowsDecimalSeparator: (BOOL) flag
{ {
#if GS_USE_ICU == 1
unum_setAttribute (_formatter, UNUM_DECIMAL_ALWAYS_SHOWN, flag);
#else
return; return;
#endif
} }
- (BOOL) alwaysShowsDecimalSeparator - (BOOL) alwaysShowsDecimalSeparator
{ {
#if GS_USE_ICU == 1
return (BOOL)unum_getAttribute (_formatter, UNUM_DECIMAL_ALWAYS_SHOWN);
#else
return NO; return NO;
#endif
} }
- (void) setCurrencyDecimalSeparator: (NSString *) string - (void) setCurrencyDecimalSeparator: (NSString *) string
@ -1563,84 +1636,151 @@ static NSUInteger _defaultBehavior = 0;
- (void) setGroupingSize: (NSUInteger) number - (void) setGroupingSize: (NSUInteger) number
{ {
#if GS_USE_ICU == 1
unum_setAttribute (_formatter, UNUM_GROUPING_SIZE, number);
#else
return; return;
#endif
} }
- (NSUInteger) groupingSize - (NSUInteger) groupingSize
{ {
return 0; #if GS_USE_ICU == 1
return (NSUInteger)unum_getAttribute (_formatter, UNUM_GROUPING_SIZE);
#else
return 3;
#endif
} }
- (void) setSecondaryGroupingSize: (NSUInteger) number - (void) setSecondaryGroupingSize: (NSUInteger) number
{ {
#if GS_USE_ICU == 1
unum_setAttribute (_formatter, UNUM_SECONDARY_GROUPING_SIZE, number);
#else
return; return;
#endif
} }
- (NSUInteger) secondaryGroupingSize - (NSUInteger) secondaryGroupingSize
{ {
return 0; #if GS_USE_ICU == 1
return (NSUInteger)unum_getAttribute (_formatter,
UNUM_SECONDARY_GROUPING_SIZE);
#else
return 3;
#endif
} }
- (void) setPaddingCharacter: (NSString *) string - (void) setPaddingCharacter: (NSString *) string
{ {
#if GS_USE_ICU == 1
[self _setTextAttribute: string : UNUM_PADDING_CHARACTER];
#else
return; return;
#endif
} }
- (NSString *) paddingCharacter - (NSString *) paddingCharacter
{ {
#if GS_USE_ICU == 1
return [self _getTextAttribute: UNUM_PADDING_CHARACTER];
#else
return nil; return nil;
#endif
} }
- (void) setPaddingPosition: (NSNumberFormatterPadPosition) position - (void) setPaddingPosition: (NSNumberFormatterPadPosition) position
{ {
#if GS_USE_ICU == 1
unum_setAttribute (_formatter, UNUM_PADDING_POSITION,
_NSToICUPadPosition (position));
#else
return; return;
#endif
} }
- (NSNumberFormatterPadPosition) paddingPosition - (NSNumberFormatterPadPosition) paddingPosition
{ {
#if GS_USE_ICU == 1
return _ICUToNSPadPosition(unum_getAttribute (_formatter,
UNUM_PADDING_POSITION));
#else
return 0; return 0;
#endif
} }
- (void) setMinimumIntegerDigits: (NSUInteger) number - (void) setMinimumIntegerDigits: (NSUInteger) number
{ {
#if GS_USE_ICU == 1
unum_setAttribute (_formatter, UNUM_MIN_INTEGER_DIGITS, number);
#else
return; return;
#endif
} }
- (NSUInteger) minimumIntegerDigits - (NSUInteger) minimumIntegerDigits
{ {
#if GS_USE_ICU == 1
return (NSUInteger)unum_getAttribute (_formatter, UNUM_MIN_INTEGER_DIGITS);
#else
return 0; return 0;
#endif
} }
- (void) setMinimumFractionDigits: (NSUInteger) number - (void) setMinimumFractionDigits: (NSUInteger) number
{ {
#if GS_USE_ICU == 1
unum_setAttribute (_formatter, UNUM_MIN_FRACTION_DIGITS, number);
#else
return; return;
#endif
} }
- (NSUInteger) minimumFractionDigits - (NSUInteger) minimumFractionDigits
{ {
#if GS_USE_ICU == 1
return (NSUInteger)unum_getAttribute (_formatter, UNUM_MIN_FRACTION_DIGITS);
#else
return 0; return 0;
#endif
} }
- (void) setMaximumIntegerDigits: (NSUInteger) number - (void) setMaximumIntegerDigits: (NSUInteger) number
{ {
#if GS_USE_ICU == 1
unum_setAttribute (_formatter, UNUM_MAX_INTEGER_DIGITS, number);
#else
return; return;
#endif
} }
- (NSUInteger) maximumIntegerDigits - (NSUInteger) maximumIntegerDigits
{ {
#if GS_USE_ICU == 1
return (NSUInteger)unum_getAttribute (_formatter, UNUM_MAX_INTEGER_DIGITS);
#else
return 0; return 0;
#endif
} }
- (void) setMaximumFractionDigits: (NSUInteger) number - (void) setMaximumFractionDigits: (NSUInteger) number
{ {
#if GS_USE_ICU == 1
unum_setAttribute (_formatter, UNUM_MAX_FRACTION_DIGITS, number);
#else
return; return;
#endif
} }
- (NSUInteger) maximumFractionDigits - (NSUInteger) maximumFractionDigits
{ {
#if GS_USE_ICU == 1
return (NSUInteger)unum_getAttribute (_formatter, UNUM_MAX_FRACTION_DIGITS);
#else
return 0; return 0;
#endif
} }
@ -1655,32 +1795,56 @@ static NSUInteger _defaultBehavior = 0;
- (void) setUsesSignificantDigits: (BOOL) flag - (void) setUsesSignificantDigits: (BOOL) flag
{ {
#if GS_USE_ICU == 1
unum_setAttribute (_formatter, UNUM_SIGNIFICANT_DIGITS_USED, flag);
#else
return; return;
#endif
} }
- (BOOL) usesSignificantDigits - (BOOL) usesSignificantDigits
{ {
#if GS_USE_ICU == 1
return (BOOL)unum_getAttribute (_formatter, UNUM_SIGNIFICANT_DIGITS_USED);
#else
return NO; return NO;
#endif
} }
- (void) setMinimumSignificantDigits: (NSUInteger) number - (void) setMinimumSignificantDigits: (NSUInteger) number
{ {
#if GS_USE_ICU == 1
unum_setAttribute (_formatter, UNUM_MIN_SIGNIFICANT_DIGITS, number);
#else
return; return;
#endif
} }
- (NSUInteger) minimumSignificantDigits - (NSUInteger) minimumSignificantDigits
{ {
#if GS_USE_ICU == 1
return (BOOL)unum_getAttribute (_formatter, UNUM_MIN_SIGNIFICANT_DIGITS);
#else
return 0; return 0;
#endif
} }
- (void) setMaximumSignificantDigits: (NSUInteger) number - (void) setMaximumSignificantDigits: (NSUInteger) number
{ {
#if GS_USE_ICU == 1
unum_setAttribute (_formatter, UNUM_MAX_SIGNIFICANT_DIGITS, number);
#else
return; return;
#endif
} }
- (NSUInteger) maximumSignificantDigits - (NSUInteger) maximumSignificantDigits
{ {
#if GS_USE_ICU == 1
return (BOOL)unum_getAttribute (_formatter, UNUM_MAX_SIGNIFICANT_DIGITS);
#else
return 0; return 0;
#endif
} }
@ -1705,12 +1869,20 @@ static NSUInteger _defaultBehavior = 0;
- (void) setLenient: (BOOL) flag - (void) setLenient: (BOOL) flag
{ {
#if GS_USE_ICU == 1
unum_setAttribute (_formatter, UNUM_LENIENT_PARSE, flag);
#else
return; return;
#endif
} }
- (BOOL) isLenient - (BOOL) isLenient
{ {
#if GS_USE_ICU == 1
return (BOOL)unum_getAttribute (_formatter, UNUM_LENIENT_PARSE);
#else
return NO; return NO;
#endif
} }
@ -1728,7 +1900,20 @@ static NSUInteger _defaultBehavior = 0;
+ (NSString *) localizedStringFromNumber: (NSNumber *) num + (NSString *) localizedStringFromNumber: (NSNumber *) num
numberStyle: (NSNumberFormatterStyle) localizationStyle numberStyle: (NSNumberFormatterStyle) localizationStyle
{ {
#if GS_USE_ICU == 1
NSNumberFormatter *fmt;
NSString *result;
fmt = [[NSNumberFormatter alloc] init];
[fmt setLocale: [NSLocale currentLocale]];
[fmt setNumberStyle: localizationStyle];
result = [fmt stringFromNumber: num];
RELEASE(fmt);
return result;
#else
return nil; return nil;
#endif
} }
@end @end
@ -1771,7 +1956,7 @@ static NSUInteger _defaultBehavior = 0;
length = [string length]; length = [string length];
if (length > MAX_SYMBOL_SIZE) if (length > MAX_SYMBOL_SIZE)
str = (unichar *)NSZoneMalloc ([self zone], length); str = (unichar *)NSZoneMalloc ([self zone], length * sizeof(unichar));
[string getCharacters: str range: NSMakeRange (0, length)]; [string getCharacters: str range: NSMakeRange (0, length)];
unum_setSymbol (_formatter, symbol, str, length, &err); unum_setSymbol (_formatter, symbol, str, length, &err);
@ -1796,7 +1981,7 @@ static NSUInteger _defaultBehavior = 0;
MAX_SYMBOL_SIZE, &err); MAX_SYMBOL_SIZE, &err);
if (length > MAX_SYMBOL_SIZE) if (length > MAX_SYMBOL_SIZE)
{ {
str = (UChar *)NSZoneMalloc ([self zone], length); str = (UChar *)NSZoneMalloc ([self zone], length * sizeof(UChar));
length = unum_getSymbol (_formatter, symbol, str, length = unum_getSymbol (_formatter, symbol, str,
length, &err); length, &err);
} }
@ -1821,7 +2006,7 @@ static NSUInteger _defaultBehavior = 0;
length = [string length]; length = [string length];
if (length > MAX_TEXT_ATTRIB_SIZE) if (length > MAX_TEXT_ATTRIB_SIZE)
str = (unichar *)NSZoneMalloc ([self zone], length); str = (unichar *)NSZoneMalloc ([self zone], length * sizeof(unichar));
[string getCharacters: str range: NSMakeRange (0, length)]; [string getCharacters: str range: NSMakeRange (0, length)];
unum_setTextAttribute (_formatter, attrib, str, length, &err); unum_setTextAttribute (_formatter, attrib, str, length, &err);
@ -1846,7 +2031,7 @@ static NSUInteger _defaultBehavior = 0;
MAX_TEXT_ATTRIB_SIZE, &err); MAX_TEXT_ATTRIB_SIZE, &err);
if (length > MAX_TEXT_ATTRIB_SIZE) if (length > MAX_TEXT_ATTRIB_SIZE)
{ {
str = (UChar *)NSZoneMalloc ([self zone], length); str = (UChar *)NSZoneMalloc ([self zone], length * sizeof(UChar));
length = unum_getTextAttribute (_formatter, attrib, str, length = unum_getTextAttribute (_formatter, attrib, str,
length, &err); length, &err);
} }