2005-02-22 11:22:44 +00:00
|
|
|
/**
|
2000-09-02 01:44:24 +00:00
|
|
|
NSNumberFormatter class
|
|
|
|
Copyright (C) 2000 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by: Fred Kiefer <FredKiefer@gmx.de>
|
|
|
|
Created: July 2000
|
2001-10-19 09:10:04 +00:00
|
|
|
Updated by: Richard Frith-Macdonald <rfm@gnu.org> Sept 2001
|
2000-09-02 01:44:24 +00:00
|
|
|
|
|
|
|
This file is part of the GNUstep Base Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-09-14 11:36:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2000-09-02 01:44:24 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-08 10:38:33 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
2000-09-02 01:44:24 +00:00
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
2007-09-14 11:36:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2000-09-02 01:44:24 +00:00
|
|
|
License along with this library; if not, write to the Free
|
2006-10-20 10:56:27 +00:00
|
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02111 USA.
|
2001-12-18 16:54:15 +00:00
|
|
|
|
|
|
|
<title>NSNumberFormatter class reference</title>
|
|
|
|
$Date$ $Revision$
|
2000-09-02 01:44:24 +00:00
|
|
|
*/
|
|
|
|
|
2010-02-19 08:12:46 +00:00
|
|
|
#import "common.h"
|
2010-02-14 10:48:10 +00:00
|
|
|
#define EXPOSE_NSNumberFormatter_IVARS 1
|
|
|
|
#import "Foundation/NSAttributedString.h"
|
|
|
|
#import "Foundation/NSDecimalNumber.h"
|
|
|
|
#import "Foundation/NSDictionary.h"
|
2011-01-08 18:05:42 +00:00
|
|
|
#import "Foundation/NSError.h"
|
2010-02-14 10:48:10 +00:00
|
|
|
#import "Foundation/NSException.h"
|
2011-01-08 18:05:42 +00:00
|
|
|
#import "Foundation/NSLocale.h"
|
|
|
|
#import "Foundation/NSValue.h"
|
2010-02-14 10:48:10 +00:00
|
|
|
#import "Foundation/NSNumberFormatter.h"
|
|
|
|
#import "Foundation/NSUserDefaults.h"
|
|
|
|
#import "Foundation/NSCharacterSet.h"
|
|
|
|
|
|
|
|
#import "GNUstepBase/GSLocale.h"
|
2008-06-11 17:00:55 +00:00
|
|
|
|
2011-01-09 20:18:51 +00:00
|
|
|
@class NSDoubleNumber;
|
|
|
|
|
2011-01-08 18:05:42 +00:00
|
|
|
#if defined(HAVE_UNICODE_UNUM_H)
|
|
|
|
# include <unicode/unum.h>
|
|
|
|
#endif
|
|
|
|
|
2011-01-09 20:18:51 +00:00
|
|
|
#define MAX_SYMBOL_SIZE 32
|
|
|
|
#define MAX_TEXT_ATTRIB_SIZE 512
|
2011-01-13 00:29:30 +00:00
|
|
|
#define MAX_BUFFER_SIZE 1024
|
2011-01-09 20:18:51 +00:00
|
|
|
|
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
static inline UNumberFormatStyle
|
|
|
|
_NSToICUFormatStyle (NSNumberFormatterStyle style)
|
|
|
|
{
|
|
|
|
UNumberFormatStyle result;
|
|
|
|
|
|
|
|
switch (style)
|
|
|
|
{
|
|
|
|
case NSNumberFormatterDecimalStyle:
|
|
|
|
result = UNUM_DECIMAL;
|
|
|
|
break;
|
|
|
|
case NSNumberFormatterCurrencyStyle:
|
|
|
|
result = UNUM_CURRENCY;
|
|
|
|
break;
|
|
|
|
case NSNumberFormatterPercentStyle:
|
|
|
|
result = UNUM_PERCENT;
|
|
|
|
break;
|
|
|
|
case NSNumberFormatterScientificStyle:
|
|
|
|
result = UNUM_SCIENTIFIC;
|
|
|
|
break;
|
|
|
|
case NSNumberFormatterSpellOutStyle:
|
|
|
|
result = UNUM_SPELLOUT;
|
|
|
|
break;
|
|
|
|
case NSNumberFormatterNoStyle:
|
|
|
|
default:
|
|
|
|
result = UNUM_IGNORE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline UNumberFormatPadPosition
|
|
|
|
_NSToICUPadPosition (NSNumberFormatterPadPosition position)
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
UNumberFormatPadPosition result = 0;
|
2011-01-09 20:18:51 +00:00
|
|
|
|
|
|
|
switch (position)
|
|
|
|
{
|
|
|
|
case NSNumberFormatterPadBeforePrefix:
|
|
|
|
result = UNUM_PAD_BEFORE_PREFIX;
|
|
|
|
break;
|
|
|
|
case NSNumberFormatterPadAfterPrefix:
|
|
|
|
result = UNUM_PAD_AFTER_PREFIX;
|
|
|
|
break;
|
|
|
|
case NSNumberFormatterPadBeforeSuffix:
|
|
|
|
result = UNUM_PAD_BEFORE_SUFFIX;
|
|
|
|
break;
|
|
|
|
case NSNumberFormatterPadAfterSuffix:
|
|
|
|
result = UNUM_PAD_AFTER_SUFFIX;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline NSNumberFormatterPadPosition
|
|
|
|
_ICUToNSPadPosition (UNumberFormatPadPosition position)
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
NSNumberFormatterPadPosition result = 0;
|
2011-01-09 20:18:51 +00:00
|
|
|
|
|
|
|
switch (position)
|
|
|
|
{
|
|
|
|
case UNUM_PAD_BEFORE_PREFIX:
|
|
|
|
result = NSNumberFormatterPadBeforePrefix;
|
|
|
|
break;
|
|
|
|
case UNUM_PAD_AFTER_PREFIX:
|
|
|
|
result = NSNumberFormatterPadAfterPrefix;
|
|
|
|
break;
|
|
|
|
case UNUM_PAD_BEFORE_SUFFIX:
|
|
|
|
result = NSNumberFormatterPadBeforeSuffix;
|
|
|
|
break;
|
|
|
|
case UNUM_PAD_AFTER_SUFFIX:
|
|
|
|
result = NSNumberFormatterPadAfterSuffix;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline UNumberFormatRoundingMode
|
|
|
|
_NSToICURoundingMode (NSNumberFormatterRoundingMode mode)
|
|
|
|
{
|
|
|
|
UNumberFormatRoundingMode result = 0;
|
|
|
|
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case NSNumberFormatterRoundCeiling:
|
|
|
|
result = UNUM_ROUND_CEILING;
|
|
|
|
break;
|
|
|
|
case NSNumberFormatterRoundFloor:
|
|
|
|
result = UNUM_ROUND_FLOOR;
|
|
|
|
break;
|
|
|
|
case NSNumberFormatterRoundDown:
|
|
|
|
result = UNUM_ROUND_DOWN;
|
|
|
|
break;
|
|
|
|
case NSNumberFormatterRoundUp:
|
|
|
|
result = UNUM_ROUND_UP;
|
|
|
|
break;
|
|
|
|
case NSNumberFormatterRoundHalfEven:
|
|
|
|
result = UNUM_ROUND_HALFEVEN;
|
|
|
|
break;
|
|
|
|
case NSNumberFormatterRoundHalfDown:
|
|
|
|
result = UNUM_ROUND_HALFDOWN;
|
|
|
|
break;
|
|
|
|
case NSNumberFormatterRoundHalfUp:
|
|
|
|
result = UNUM_ROUND_HALFUP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline NSNumberFormatterRoundingMode
|
|
|
|
_ICUToNSRoundingMode (UNumberFormatRoundingMode mode)
|
|
|
|
{
|
|
|
|
NSNumberFormatterRoundingMode result = 0;
|
|
|
|
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case UNUM_ROUND_CEILING:
|
|
|
|
result = NSNumberFormatterRoundCeiling;
|
|
|
|
break;
|
|
|
|
case UNUM_ROUND_FLOOR:
|
|
|
|
result = NSNumberFormatterRoundFloor;
|
|
|
|
break;
|
|
|
|
case UNUM_ROUND_DOWN:
|
|
|
|
result = NSNumberFormatterRoundDown;
|
|
|
|
break;
|
|
|
|
case UNUM_ROUND_UP:
|
|
|
|
result = NSNumberFormatterRoundUp;
|
|
|
|
break;
|
|
|
|
case UNUM_ROUND_HALFEVEN:
|
|
|
|
result = NSNumberFormatterRoundHalfEven;
|
|
|
|
break;
|
|
|
|
case UNUM_ROUND_HALFDOWN:
|
|
|
|
result = NSNumberFormatterRoundHalfDown;
|
|
|
|
break;
|
|
|
|
case UNUM_ROUND_HALFUP:
|
|
|
|
result = NSNumberFormatterRoundHalfUp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-02-13 22:13:04 +00:00
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
// Internal data storage
|
|
|
|
typedef struct {
|
|
|
|
NSUInteger _behavior;
|
|
|
|
BOOL _genDecimal;
|
|
|
|
NSUInteger _style;
|
|
|
|
NSLocale *_locale;
|
|
|
|
void *_formatter;
|
|
|
|
} Internal;
|
|
|
|
|
|
|
|
#define this ((Internal*)(self->_reserved))
|
|
|
|
#define inst ((Internal*)(o->_reserved))
|
|
|
|
|
|
|
|
@interface NSNumberFormatter (PrivateMethods)
|
2011-01-25 02:25:32 +00:00
|
|
|
- (void) _resetUNumberFormat;
|
2011-01-09 20:18:51 +00:00
|
|
|
- (void) _setSymbol: (NSString *) string : (NSInteger) symbol;
|
|
|
|
- (NSString *) _getSymbol: (NSInteger) symbol;
|
|
|
|
- (void) _setTextAttribute: (NSString *) string : (NSInteger) attrib;
|
|
|
|
- (NSString *) _getTextAttribute: (NSInteger) attrib;
|
|
|
|
@end
|
|
|
|
|
2000-09-02 01:44:24 +00:00
|
|
|
@implementation NSNumberFormatter
|
|
|
|
|
2011-01-09 20:18:51 +00:00
|
|
|
static NSUInteger _defaultBehavior = 0;
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (BOOL) allowsFloats
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
return _allowsFloats;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (NSAttributedString*) attributedStringForObjectValue: (id)anObject
|
|
|
|
withDefaultAttributes: (NSDictionary*)attr
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2006-12-15 14:57:05 +00:00
|
|
|
NSDecimalNumber *zeroNumber = [NSDecimalNumber zero];
|
|
|
|
NSDecimalNumber *nanNumber = [NSDecimalNumber notANumber];
|
2005-10-17 10:47:54 +00:00
|
|
|
|
|
|
|
if (anObject == nil)
|
|
|
|
{
|
|
|
|
return [self attributedStringForNil];
|
|
|
|
}
|
|
|
|
else if (![anObject isKindOfClass: [NSNumber class]])
|
|
|
|
{
|
|
|
|
return [self attributedStringForNotANumber];
|
|
|
|
}
|
2006-12-15 14:57:05 +00:00
|
|
|
else if ([anObject isEqual: nanNumber])
|
|
|
|
{
|
|
|
|
return [self attributedStringForNotANumber];
|
|
|
|
}
|
|
|
|
else if ([anObject isEqual: zeroNumber])
|
2005-10-17 10:47:54 +00:00
|
|
|
{
|
|
|
|
return [self attributedStringForZero];
|
|
|
|
}
|
|
|
|
|
2007-04-11 05:00:26 +00:00
|
|
|
if (([(NSNumber*)anObject compare: zeroNumber] == NSOrderedDescending)
|
2006-12-19 12:48:28 +00:00
|
|
|
&& (_attributesForPositiveValues))
|
2005-10-17 10:47:54 +00:00
|
|
|
{
|
|
|
|
attr = _attributesForPositiveValues;
|
|
|
|
}
|
2007-04-11 05:00:26 +00:00
|
|
|
else if (([(NSNumber*)anObject compare: zeroNumber] == NSOrderedAscending)
|
2006-12-19 12:48:28 +00:00
|
|
|
&& (_attributesForNegativeValues))
|
2005-10-17 10:47:54 +00:00
|
|
|
{
|
|
|
|
attr = _attributesForNegativeValues;
|
|
|
|
}
|
|
|
|
|
2005-02-22 11:22:44 +00:00
|
|
|
return AUTORELEASE([[NSAttributedString alloc] initWithString:
|
2005-10-17 10:47:54 +00:00
|
|
|
[self stringForObjectValue: anObject] attributes: attr]);
|
2001-10-19 09:10:04 +00:00
|
|
|
}
|
2000-09-02 01:44:24 +00:00
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (NSAttributedString*) attributedStringForNil
|
|
|
|
{
|
|
|
|
return _attributedStringForNil;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (NSAttributedString*) attributedStringForNotANumber
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
return _attributedStringForNotANumber;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (NSAttributedString*) attributedStringForZero
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
return _attributedStringForZero;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (id) copyWithZone: (NSZone *)zone
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
NSNumberFormatter *o = (NSNumberFormatter*) NSCopyObject(self, 0, zone);
|
|
|
|
|
|
|
|
IF_NO_GC(RETAIN(o->_negativeFormat);)
|
|
|
|
IF_NO_GC(RETAIN(o->_positiveFormat);)
|
|
|
|
IF_NO_GC(RETAIN(o->_attributesForPositiveValues);)
|
|
|
|
IF_NO_GC(RETAIN(o->_attributesForNegativeValues);)
|
|
|
|
IF_NO_GC(RETAIN(o->_maximum);)
|
|
|
|
IF_NO_GC(RETAIN(o->_minimum);)
|
|
|
|
IF_NO_GC(RETAIN(o->_roundingBehavior);)
|
|
|
|
IF_NO_GC(RETAIN(o->_attributedStringForNil);)
|
|
|
|
IF_NO_GC(RETAIN(o->_attributedStringForNotANumber);)
|
|
|
|
IF_NO_GC(RETAIN(o->_attributedStringForZero);)
|
|
|
|
if (0 != this)
|
|
|
|
{
|
|
|
|
o->_reserved = NSZoneCalloc([self zone], 1, sizeof(Internal));
|
|
|
|
memcpy(inst, this, sizeof(Internal));
|
|
|
|
IF_NO_GC(RETAIN(inst->_locale);)
|
|
|
|
if (inst->_formatter != NULL)
|
|
|
|
{
|
|
|
|
inst->_formatter = NULL;
|
|
|
|
[o _resetUNumberFormat];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return o;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (void) dealloc
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
RELEASE(_negativeFormat);
|
|
|
|
RELEASE(_positiveFormat);
|
|
|
|
RELEASE(_attributesForPositiveValues);
|
|
|
|
RELEASE(_attributesForNegativeValues);
|
|
|
|
RELEASE(_maximum);
|
|
|
|
RELEASE(_minimum);
|
|
|
|
RELEASE(_roundingBehavior);
|
|
|
|
RELEASE(_attributedStringForNil);
|
|
|
|
RELEASE(_attributedStringForNotANumber);
|
|
|
|
RELEASE(_attributedStringForZero);
|
2011-02-14 06:37:45 +00:00
|
|
|
if (this != 0)
|
|
|
|
{
|
|
|
|
RELEASE(this->_locale);
|
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
unum_close (this->_formatter);
|
|
|
|
#endif
|
|
|
|
NSZoneFree([self zone], this);
|
|
|
|
}
|
2001-10-19 09:10:04 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) decimalSeparator
|
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
if (this->_behavior == NSNumberFormatterBehavior10_4
|
|
|
|
|| this->_behavior == NSNumberFormatterBehaviorDefault)
|
|
|
|
{
|
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
return [self _getSymbol: UNUM_DECIMAL_SEPARATOR_SYMBOL];
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else if (this->_behavior == NSNumberFormatterBehavior10_0)
|
|
|
|
{
|
|
|
|
if (_decimalSeparator == 0)
|
|
|
|
return @"";
|
|
|
|
else
|
|
|
|
return [NSString stringWithCharacters: &_decimalSeparator length: 1];
|
|
|
|
}
|
|
|
|
return nil;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) editingStringForObjectValue: (id)anObject
|
|
|
|
{
|
|
|
|
return [self stringForObjectValue: anObject];
|
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (void) encodeWithCoder: (NSCoder*)encoder
|
|
|
|
{
|
|
|
|
[encoder encodeValueOfObjCType: @encode(BOOL) at: &_hasThousandSeparators];
|
|
|
|
[encoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsFloats];
|
|
|
|
[encoder encodeValueOfObjCType: @encode(BOOL) at: &_localizesFormat];
|
|
|
|
[encoder encodeValueOfObjCType: @encode(unichar) at: &_thousandSeparator];
|
|
|
|
[encoder encodeValueOfObjCType: @encode(unichar) at: &_decimalSeparator];
|
|
|
|
|
2001-11-23 12:37:33 +00:00
|
|
|
[encoder encodeObject: _roundingBehavior];
|
|
|
|
[encoder encodeObject: _maximum];
|
|
|
|
[encoder encodeObject: _minimum];
|
|
|
|
[encoder encodeObject: _attributedStringForNil];
|
|
|
|
[encoder encodeObject: _attributedStringForNotANumber];
|
|
|
|
[encoder encodeObject: _attributedStringForZero];
|
|
|
|
[encoder encodeObject: _negativeFormat];
|
|
|
|
[encoder encodeObject: _positiveFormat];
|
|
|
|
[encoder encodeObject: _attributesForPositiveValues];
|
|
|
|
[encoder encodeObject: _attributesForNegativeValues];
|
2001-10-19 09:10:04 +00:00
|
|
|
}
|
2004-09-14 03:34:37 +00:00
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (NSString*) format
|
|
|
|
{
|
|
|
|
if (_attributedStringForZero != nil)
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat: @"%@;%@;%@",
|
|
|
|
_positiveFormat, [_attributedStringForZero string], _negativeFormat];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat: @"%@;%@",
|
|
|
|
_positiveFormat, _negativeFormat];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-09-02 01:44:24 +00:00
|
|
|
- (BOOL) getObjectValue: (id*)anObject
|
|
|
|
forString: (NSString*)string
|
|
|
|
errorDescription: (NSString**)error
|
|
|
|
{
|
2003-06-12 03:29:35 +00:00
|
|
|
/* FIXME: This is just a quick hack implementation. */
|
2005-10-17 10:47:54 +00:00
|
|
|
NSLog(@"NSNumberFormatter-getObjectValue:forString:... not fully implemented");
|
|
|
|
|
|
|
|
/* Just assume nothing else has been setup and do a simple conversion. */
|
|
|
|
if ([self hasThousandSeparators])
|
2003-06-12 03:29:35 +00:00
|
|
|
{
|
2005-10-17 10:47:54 +00:00
|
|
|
NSRange range;
|
|
|
|
|
|
|
|
range = [string rangeOfString: [self thousandSeparator]];
|
|
|
|
if (range.length != 0)
|
|
|
|
{
|
|
|
|
string = AUTORELEASE([string mutableCopy]);
|
2006-12-19 12:48:28 +00:00
|
|
|
[(NSMutableString*)string replaceOccurrencesOfString:
|
|
|
|
[self thousandSeparator]
|
|
|
|
withString: @""
|
|
|
|
options: 0
|
|
|
|
range: NSMakeRange(0, [string length])];
|
2005-10-17 10:47:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (anObject)
|
|
|
|
{
|
|
|
|
NSDictionary *locale;
|
|
|
|
|
|
|
|
locale = [NSDictionary dictionaryWithObject: [self decimalSeparator]
|
|
|
|
forKey: NSDecimalSeparator];
|
|
|
|
*anObject = [NSDecimalNumber decimalNumberWithString: string
|
|
|
|
locale: locale];
|
|
|
|
if (*anObject)
|
|
|
|
{
|
|
|
|
return YES;
|
2004-09-14 03:34:37 +00:00
|
|
|
}
|
2003-06-12 03:29:35 +00:00
|
|
|
}
|
2005-10-17 10:47:54 +00:00
|
|
|
|
2003-06-12 03:29:35 +00:00
|
|
|
return NO;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (BOOL) hasThousandSeparators
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
return _hasThousandSeparators;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (id) init
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-12-04 08:44:42 +00:00
|
|
|
id o;
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
_reserved = NSZoneCalloc([self zone], 1, sizeof(Internal));
|
2001-10-19 09:10:04 +00:00
|
|
|
_allowsFloats = YES;
|
|
|
|
_decimalSeparator = '.';
|
|
|
|
_thousandSeparator = ',';
|
2006-12-15 14:57:05 +00:00
|
|
|
_hasThousandSeparators = YES;
|
2001-12-04 08:44:42 +00:00
|
|
|
o = [[NSAttributedString alloc] initWithString: @""];
|
|
|
|
[self setAttributedStringForNil: o];
|
|
|
|
RELEASE(o);
|
|
|
|
o = [[NSAttributedString alloc] initWithString: @"NaN"];
|
|
|
|
[self setAttributedStringForNotANumber: o];
|
|
|
|
RELEASE(o);
|
2011-01-09 20:18:51 +00:00
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
this->_behavior = _defaultBehavior;
|
|
|
|
this->_locale = RETAIN([NSLocale currentLocale]);
|
|
|
|
this->_style = NSNumberFormatterNoStyle;
|
|
|
|
[self _resetUNumberFormat];
|
|
|
|
if (this->_formatter == NULL)
|
|
|
|
{
|
|
|
|
RELEASE(self);
|
|
|
|
return nil;
|
|
|
|
}
|
2011-01-27 23:29:41 +00:00
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
return self;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (id) initWithCoder: (NSCoder*)decoder
|
|
|
|
{
|
2004-10-09 15:40:23 +00:00
|
|
|
if ([decoder allowsKeyedCoding])
|
|
|
|
{
|
|
|
|
if ([decoder containsValueForKey: @"NS.allowsfloats"])
|
|
|
|
{
|
2006-12-19 12:48:28 +00:00
|
|
|
[self setAllowsFloats:
|
|
|
|
[decoder decodeBoolForKey: @"NS.allowsfloats"]];
|
2004-10-09 15:40:23 +00:00
|
|
|
}
|
|
|
|
if ([decoder containsValueForKey: @"NS.decimal"])
|
|
|
|
{
|
2006-12-19 12:48:28 +00:00
|
|
|
[self setDecimalSeparator:
|
|
|
|
[decoder decodeObjectForKey: @"NS.decimal"]];
|
2004-10-09 15:40:23 +00:00
|
|
|
}
|
|
|
|
if ([decoder containsValueForKey: @"NS.hasthousands"])
|
|
|
|
{
|
2006-12-19 12:48:28 +00:00
|
|
|
[self setHasThousandSeparators:
|
|
|
|
[decoder decodeBoolForKey: @"NS.hasthousands"]];
|
2004-10-09 15:40:23 +00:00
|
|
|
}
|
|
|
|
if ([decoder containsValueForKey: @"NS.localized"])
|
|
|
|
{
|
2006-12-19 12:48:28 +00:00
|
|
|
[self setLocalizesFormat:
|
|
|
|
[decoder decodeBoolForKey: @"NS.localized"]];
|
2004-10-09 15:40:23 +00:00
|
|
|
}
|
|
|
|
if ([decoder containsValueForKey: @"NS.max"])
|
|
|
|
{
|
|
|
|
[self setMaximum: [decoder decodeObjectForKey: @"NS.max"]];
|
|
|
|
}
|
|
|
|
if ([decoder containsValueForKey: @"NS.min"])
|
|
|
|
{
|
|
|
|
[self setMinimum: [decoder decodeObjectForKey: @"NS.min"]];
|
|
|
|
}
|
|
|
|
if ([decoder containsValueForKey: @"NS.nan"])
|
|
|
|
{
|
2006-12-19 12:48:28 +00:00
|
|
|
[self setAttributedStringForNotANumber:
|
|
|
|
[decoder decodeObjectForKey: @"NS.nan"]];
|
2004-10-09 15:40:23 +00:00
|
|
|
}
|
|
|
|
if ([decoder containsValueForKey: @"NS.negativeattrs"])
|
|
|
|
{
|
2006-12-19 12:48:28 +00:00
|
|
|
[self setTextAttributesForNegativeValues:
|
|
|
|
[decoder decodeObjectForKey: @"NS.negativeattrs"]];
|
2004-10-09 15:40:23 +00:00
|
|
|
}
|
|
|
|
if ([decoder containsValueForKey: @"NS.negativeformat"])
|
|
|
|
{
|
2006-12-19 12:48:28 +00:00
|
|
|
[self setNegativeFormat:
|
|
|
|
[decoder decodeObjectForKey: @"NS.negativeformat"]];
|
2004-10-09 15:40:23 +00:00
|
|
|
}
|
|
|
|
if ([decoder containsValueForKey: @"NS.nil"])
|
|
|
|
{
|
2006-12-19 12:48:28 +00:00
|
|
|
[self setAttributedStringForNil:
|
|
|
|
[decoder decodeObjectForKey: @"NS.nil"]];
|
2004-10-09 15:40:23 +00:00
|
|
|
}
|
|
|
|
if ([decoder containsValueForKey: @"NS.positiveattrs"])
|
|
|
|
{
|
2006-12-19 12:48:28 +00:00
|
|
|
[self setTextAttributesForPositiveValues:
|
|
|
|
[decoder decodeObjectForKey: @"NS.positiveattrs"]];
|
2004-10-09 15:40:23 +00:00
|
|
|
}
|
|
|
|
if ([decoder containsValueForKey: @"NS.positiveformat"])
|
|
|
|
{
|
2006-12-19 12:48:28 +00:00
|
|
|
[self setPositiveFormat:
|
|
|
|
[decoder decodeObjectForKey: @"NS.positiveformat"]];
|
2004-10-09 15:40:23 +00:00
|
|
|
}
|
|
|
|
if ([decoder containsValueForKey: @"NS.rounding"])
|
|
|
|
{
|
2006-12-19 12:48:28 +00:00
|
|
|
[self setRoundingBehavior:
|
|
|
|
[decoder decodeObjectForKey: @"NS.rounding"]];
|
2004-10-09 15:40:23 +00:00
|
|
|
}
|
|
|
|
if ([decoder containsValueForKey: @"NS.thousand"])
|
|
|
|
{
|
2006-12-19 12:48:28 +00:00
|
|
|
[self setThousandSeparator:
|
|
|
|
[decoder decodeObjectForKey: @"NS.thousand"]];
|
2004-10-09 15:40:23 +00:00
|
|
|
}
|
|
|
|
if ([decoder containsValueForKey: @"NS.zero"])
|
|
|
|
{
|
2006-12-19 12:48:28 +00:00
|
|
|
[self setAttributedStringForZero:
|
|
|
|
[decoder decodeObjectForKey: @"NS.zero"]];
|
2004-10-09 15:40:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-12-19 12:48:28 +00:00
|
|
|
[decoder decodeValueOfObjCType: @encode(BOOL)
|
|
|
|
at: &_hasThousandSeparators];
|
2004-10-09 15:40:23 +00:00
|
|
|
[decoder decodeValueOfObjCType: @encode(BOOL) at: &_allowsFloats];
|
|
|
|
[decoder decodeValueOfObjCType: @encode(BOOL) at: &_localizesFormat];
|
|
|
|
[decoder decodeValueOfObjCType: @encode(unichar) at: &_thousandSeparator];
|
|
|
|
[decoder decodeValueOfObjCType: @encode(unichar) at: &_decimalSeparator];
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2004-10-09 15:40:23 +00:00
|
|
|
[decoder decodeValueOfObjCType: @encode(id) at: &_roundingBehavior];
|
|
|
|
[decoder decodeValueOfObjCType: @encode(id) at: &_maximum];
|
|
|
|
[decoder decodeValueOfObjCType: @encode(id) at: &_minimum];
|
|
|
|
[decoder decodeValueOfObjCType: @encode(id) at: &_attributedStringForNil];
|
|
|
|
[decoder decodeValueOfObjCType: @encode(id)
|
|
|
|
at: &_attributedStringForNotANumber];
|
2006-12-19 12:48:28 +00:00
|
|
|
[decoder decodeValueOfObjCType: @encode(id)
|
|
|
|
at: &_attributedStringForZero];
|
2004-10-09 15:40:23 +00:00
|
|
|
[decoder decodeValueOfObjCType: @encode(id) at: &_negativeFormat];
|
|
|
|
[decoder decodeValueOfObjCType: @encode(id) at: &_positiveFormat];
|
|
|
|
[decoder decodeValueOfObjCType: @encode(id)
|
|
|
|
at: &_attributesForPositiveValues];
|
|
|
|
[decoder decodeValueOfObjCType: @encode(id)
|
|
|
|
at: &_attributesForNegativeValues];
|
|
|
|
}
|
2001-10-19 09:10:04 +00:00
|
|
|
return self;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (BOOL) isPartialStringValid: (NSString*)partialString
|
|
|
|
newEditingString: (NSString**)newString
|
|
|
|
errorDescription: (NSString**)error
|
2011-02-13 22:13:04 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
// FIXME
|
|
|
|
if (newString != NULL)
|
|
|
|
{
|
|
|
|
*newString = partialString;
|
|
|
|
}
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
*error = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
2011-02-13 22:13:04 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (BOOL) localizesFormat
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
return _localizesFormat;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (NSDecimalNumber*) maximum
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
return _maximum;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (NSDecimalNumber*) minimum
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
return _minimum;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (NSString*) negativeFormat
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
return _negativeFormat;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (NSString*) positiveFormat
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
return _positiveFormat;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (NSDecimalNumberHandler*) roundingBehavior
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
return _roundingBehavior;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (void) setAllowsFloats: (BOOL)flag
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
_allowsFloats = flag;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (void) setAttributedStringForNil: (NSAttributedString*)newAttributedString
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
ASSIGN(_attributedStringForNil, newAttributedString);
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (void) setAttributedStringForNotANumber:
|
|
|
|
(NSAttributedString*)newAttributedString
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
ASSIGN(_attributedStringForNotANumber, newAttributedString);
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (void) setAttributedStringForZero: (NSAttributedString*)newAttributedString
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
ASSIGN(_attributedStringForZero, newAttributedString);
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (void) setDecimalSeparator: (NSString*)newSeparator
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
if (this->_behavior == NSNumberFormatterBehavior10_4
|
|
|
|
|| this->_behavior == NSNumberFormatterBehaviorDefault)
|
|
|
|
{
|
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
[self _setSymbol: newSeparator : UNUM_DECIMAL_SEPARATOR_SYMBOL];
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else if (this->_behavior == NSNumberFormatterBehavior10_0)
|
|
|
|
{
|
|
|
|
if ([newSeparator length] > 0)
|
|
|
|
_decimalSeparator = [newSeparator characterAtIndex: 0];
|
|
|
|
else
|
|
|
|
_decimalSeparator = 0;
|
|
|
|
}
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (void) setFormat: (NSString*)aFormat
|
2011-02-13 22:13:04 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
NSRange r;
|
|
|
|
|
|
|
|
r = [aFormat rangeOfString: @";"];
|
|
|
|
if (r.length == 0)
|
|
|
|
{
|
|
|
|
[self setPositiveFormat: aFormat];
|
|
|
|
[self setNegativeFormat: [@"-" stringByAppendingString: aFormat]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self setPositiveFormat: [aFormat substringToIndex: r.location]];
|
|
|
|
aFormat = [aFormat substringFromIndex: NSMaxRange(r)];
|
|
|
|
r = [aFormat rangeOfString: @";"];
|
|
|
|
if (r.length == 0)
|
|
|
|
{
|
|
|
|
[self setNegativeFormat: aFormat];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RELEASE(_attributedStringForZero);
|
|
|
|
_attributedStringForZero = [[NSAttributedString alloc] initWithString:
|
|
|
|
[aFormat substringToIndex: r.location]];
|
|
|
|
[self setNegativeFormat: [aFormat substringFromIndex: NSMaxRange(r)]];
|
|
|
|
}
|
|
|
|
}
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (void) setHasThousandSeparators: (BOOL)flag
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
_hasThousandSeparators = flag;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (void) setLocalizesFormat: (BOOL)flag
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
_localizesFormat = flag;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (void) setMaximum: (NSDecimalNumber*)aMaximum
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
// FIXME: NSNumberFormatterBehavior10_4
|
|
|
|
ASSIGN(_maximum, aMaximum);
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (void) setMinimum: (NSDecimalNumber*)aMinimum
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
// FIXME: NSNumberFormatterBehavior10_4
|
|
|
|
ASSIGN(_minimum, aMinimum);
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (void) setNegativeFormat: (NSString*)aFormat
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
// FIXME: Should extract separators and attributes
|
|
|
|
ASSIGN(_negativeFormat, aFormat);
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (void) setPositiveFormat: (NSString*)aFormat
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
// FIXME: Should extract separators and attributes
|
|
|
|
ASSIGN(_positiveFormat, aFormat);
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (void) setRoundingBehavior: (NSDecimalNumberHandler*)newRoundingBehavior
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
ASSIGN(_roundingBehavior, newRoundingBehavior);
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (void) setTextAttributesForNegativeValues: (NSDictionary*)newAttributes
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
ASSIGN(_attributesForNegativeValues, newAttributes);
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (void) setTextAttributesForPositiveValues: (NSDictionary*)newAttributes
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
ASSIGN(_attributesForPositiveValues, newAttributes);
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (void) setThousandSeparator: (NSString*)newSeparator
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
if ([newSeparator length] > 0)
|
|
|
|
_thousandSeparator = [newSeparator characterAtIndex: 0];
|
|
|
|
else
|
|
|
|
_thousandSeparator = 0;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (NSString*) stringForObjectValue: (id)anObject
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
if (this->_behavior == NSNumberFormatterBehaviorDefault
|
|
|
|
|| this->_behavior == NSNumberFormatterBehavior10_4)
|
2011-01-25 02:25:32 +00:00
|
|
|
{
|
2011-01-29 02:01:42 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2000-09-02 01:44:24 +00:00
|
|
|
|
2011-01-29 02:01:42 +00:00
|
|
|
#define STRING_FROM_NUMBER(function, number) do \
|
|
|
|
{ \
|
|
|
|
UChar *outStr = buffer; \
|
|
|
|
UErrorCode err = U_ZERO_ERROR; \
|
|
|
|
int32_t len; \
|
|
|
|
NSString *result; \
|
|
|
|
\
|
2011-02-14 06:37:45 +00:00
|
|
|
len = function (this->_formatter, number, outStr, MAX_BUFFER_SIZE, NULL, &err); \
|
2011-01-29 02:01:42 +00:00
|
|
|
if (len > MAX_BUFFER_SIZE) \
|
|
|
|
outStr = NSZoneMalloc ([self zone], len * sizeof(UChar));\
|
|
|
|
err = U_ZERO_ERROR; \
|
2011-02-14 06:37:45 +00:00
|
|
|
function (this->_formatter, number, outStr, MAX_BUFFER_SIZE, NULL, &err); \
|
2011-01-29 02:01:42 +00:00
|
|
|
result = [NSString stringWithCharacters: outStr length: len]; \
|
|
|
|
if (len > MAX_BUFFER_SIZE) \
|
|
|
|
NSZoneFree ([self zone], outStr); \
|
|
|
|
return result; \
|
|
|
|
} while (0)
|
2006-12-15 14:57:05 +00:00
|
|
|
|
2011-01-29 02:01:42 +00:00
|
|
|
// This is quite inefficient. See the GSUText stuff for how
|
|
|
|
// to use ICU 4.6 UText objects as NSStrings. This saves us from
|
|
|
|
// needing to do a load of O(n) things. In 4.6, these APIs in ICU
|
|
|
|
// haven't been updated to use UText (so we have to use the UChar buffer
|
|
|
|
// approach), but they probably will be in the future. We should
|
|
|
|
// revisit this code when they have been.
|
|
|
|
UChar buffer[MAX_BUFFER_SIZE];
|
|
|
|
|
|
|
|
// FIXME: What to do with unsigned types?
|
|
|
|
//
|
|
|
|
// The only unsigned case we actually need to worry about is unsigned
|
|
|
|
// long long - all of the others are stored as signed values. We're now
|
|
|
|
// falling through to the double case for this, which will lose us some
|
|
|
|
// precision, but hopefully not matter too much...
|
|
|
|
if (nil == anObject)
|
|
|
|
return [self nilSymbol];
|
|
|
|
if (![anObject isKindOfClass: [NSNumber class]])
|
|
|
|
return [self notANumberSymbol];
|
|
|
|
switch ([anObject objCType][0])
|
|
|
|
{
|
|
|
|
case _C_LNG_LNG:
|
|
|
|
STRING_FROM_NUMBER(unum_formatInt64, [anObject longLongValue]);
|
|
|
|
break;
|
|
|
|
case _C_INT:
|
|
|
|
STRING_FROM_NUMBER(unum_format, [anObject intValue]);
|
|
|
|
break;
|
|
|
|
// Note: This case is probably wrong: the compiler doesn't generate B
|
|
|
|
// for bool, it generates C or c (depending on the platform). I
|
|
|
|
// don't think it matters, because we don't bother with anything
|
|
|
|
// smaller than int for NSNumbers
|
|
|
|
case _C_BOOL:
|
|
|
|
STRING_FROM_NUMBER(unum_format, (int)[anObject boolValue]);
|
|
|
|
break;
|
|
|
|
// If it's not a type encoding that we recognise, let the receiver
|
|
|
|
// cast it to a double, which probably has enough precision for what
|
|
|
|
// we need. This needs testing with NSDecimalNumber though, because
|
|
|
|
// I managed to break stuff last time I did anything with NSNumber by
|
|
|
|
// forgetting that NSDecimalNumber existed...
|
|
|
|
default:
|
|
|
|
case _C_DBL:
|
|
|
|
STRING_FROM_NUMBER(unum_formatDouble, [anObject doubleValue]);
|
|
|
|
break;
|
|
|
|
case _C_FLT:
|
|
|
|
STRING_FROM_NUMBER(unum_formatDouble, (double)[anObject floatValue]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2011-01-29 15:35:22 +00:00
|
|
|
}
|
2011-02-14 06:37:45 +00:00
|
|
|
else if (this->_behavior == NSNumberFormatterBehavior10_0)
|
2011-01-25 02:25:32 +00:00
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
NSMutableDictionary *locale;
|
|
|
|
NSCharacterSet *formattingCharacters;
|
|
|
|
NSCharacterSet *placeHolders;
|
|
|
|
NSString *prefix;
|
|
|
|
NSString *suffix;
|
|
|
|
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 (_localizesFormat)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while ([placeHolders characterIsMember:
|
|
|
|
[useFormat characterAtIndex: NSMaxRange(decimalPlaceRange)]])
|
|
|
|
{
|
|
|
|
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] autorelease];
|
|
|
|
[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;
|
2006-12-15 14:57:05 +00:00
|
|
|
}
|
2011-01-29 02:01:42 +00:00
|
|
|
return nil;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
- (NSDictionary*) textAttributesForNegativeValues
|
|
|
|
{
|
|
|
|
return _attributesForNegativeValues;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary*) textAttributesForPositiveValues
|
|
|
|
{
|
|
|
|
return _attributesForPositiveValues;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) thousandSeparator
|
|
|
|
{
|
|
|
|
if (!_thousandSeparator)
|
|
|
|
return @"";
|
|
|
|
else
|
|
|
|
return [NSString stringWithCharacters: &_thousandSeparator length: 1];
|
|
|
|
}
|
|
|
|
|
2008-08-25 22:57:04 +00:00
|
|
|
- (NSString *) stringFromNumber: (NSNumber *)number
|
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
// This is a 10.4 and above method and should not work with earlier version.
|
2011-01-29 02:01:42 +00:00
|
|
|
return [self stringForObjectValue: number];
|
2008-08-25 22:57:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSNumber *) numberFromString: (NSString *)string
|
|
|
|
{
|
2011-01-25 02:25:32 +00:00
|
|
|
// This is a 10.4 and above method and should not work with earlier version.
|
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
NSNumber *result;
|
|
|
|
NSUInteger length;
|
|
|
|
NSRange range;
|
|
|
|
UErrorCode err = U_ZERO_ERROR;
|
|
|
|
unichar *ustring;
|
|
|
|
int64_t intNum;
|
|
|
|
double doubleNum;
|
|
|
|
|
|
|
|
if (string == nil)
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
length = [string length];
|
|
|
|
ustring = NSZoneMalloc ([self zone], sizeof(unichar) * length);
|
|
|
|
if (ustring == NULL)
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
[string getCharacters: ustring range: NSMakeRange(0, length)];
|
|
|
|
|
|
|
|
// FIXME: Not sure if this is correct....
|
|
|
|
range = [string rangeOfString: @"."];
|
|
|
|
if (range.location == NSNotFound)
|
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
intNum = unum_parseInt64 (this->_formatter, ustring, length, NULL, &err);
|
2011-01-25 02:25:32 +00:00
|
|
|
if (U_FAILURE(err))
|
|
|
|
return nil;
|
|
|
|
if (intNum == 0 || intNum == 1)
|
|
|
|
result = [NSNumber numberWithBool: (BOOL) intNum];
|
|
|
|
else if (intNum < INT_MAX && intNum > INT_MIN)
|
|
|
|
result = [NSNumber numberWithInt: (int32_t)intNum];
|
|
|
|
else
|
|
|
|
result = [NSNumber numberWithLongLong: intNum];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
doubleNum = unum_parseDouble (this->_formatter, ustring, length, NULL, &err);
|
2011-01-25 02:25:32 +00:00
|
|
|
if (U_FAILURE(err))
|
|
|
|
return nil;
|
|
|
|
result = [NSNumber numberWithDouble: doubleNum];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSZoneFree ([self zone], ustring);
|
|
|
|
return result;
|
|
|
|
#else
|
|
|
|
return nil;
|
|
|
|
#endif
|
2008-08-25 22:57:04 +00:00
|
|
|
}
|
2011-01-08 18:05:42 +00:00
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
|
|
|
|
|
2011-01-08 18:05:42 +00:00
|
|
|
- (void) setFormatterBehavior: (NSNumberFormatterBehavior) behavior
|
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
this->_behavior = behavior;
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSNumberFormatterBehavior) formatterBehavior
|
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
return this->_behavior;
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (void) setDefaultFormatterBehavior: (NSNumberFormatterBehavior) behavior
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
_defaultBehavior = behavior;
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSNumberFormatterBehavior) defaultFormatterBehavior
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
return _defaultBehavior;
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setNumberStyle: (NSNumberFormatterStyle) style
|
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
this->_style = style;
|
2011-01-25 02:25:32 +00:00
|
|
|
[self _resetUNumberFormat];
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSNumberFormatterStyle) numberStyle
|
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
return this->_style;
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setGeneratesDecimalNumbers: (BOOL) flag
|
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
this->_genDecimal = flag;
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) generatesDecimalNubmers
|
|
|
|
{
|
2011-01-28 00:49:16 +00:00
|
|
|
return NO; // FIXME
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) setLocale: (NSLocale *) locale
|
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
RELEASE(this->_locale);
|
2011-01-09 20:18:51 +00:00
|
|
|
|
|
|
|
if (locale == nil)
|
|
|
|
locale = [NSLocale currentLocale];
|
2011-02-14 06:37:45 +00:00
|
|
|
this->_locale = RETAIN(locale);
|
2011-01-09 20:18:51 +00:00
|
|
|
|
2011-01-25 02:25:32 +00:00
|
|
|
[self _resetUNumberFormat];
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSLocale *) locale
|
|
|
|
{
|
2011-02-14 06:37:45 +00:00
|
|
|
return this->_locale;
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) setRoundingIncrement: (NSNumber *) number
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
if ([number class] == [NSDoubleNumber class])
|
2011-02-14 06:37:45 +00:00
|
|
|
unum_setDoubleAttribute (this->_formatter, UNUM_ROUNDING_INCREMENT,
|
2011-01-09 20:18:51 +00:00
|
|
|
[number doubleValue]);
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSNumber *) roundingIncrement
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
double value = unum_getDoubleAttribute (this->_formatter, UNUM_ROUNDING_INCREMENT);
|
2011-01-09 20:18:51 +00:00
|
|
|
return [NSNumber numberWithDouble: value];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return nil;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setRoundingMode: (NSNumberFormatterRoundingMode) mode
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
unum_setAttribute (this->_formatter, UNUM_ROUNDING_MODE,
|
2011-01-09 20:18:51 +00:00
|
|
|
_NSToICURoundingMode(mode));
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSNumberFormatterRoundingMode) roundingMode
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
return _ICUToNSRoundingMode (unum_getAttribute (this->_formatter,
|
2011-01-09 20:18:51 +00:00
|
|
|
UNUM_ROUNDING_MODE));
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return 0;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) setFormatWidth: (NSUInteger) number
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
unum_setAttribute (this->_formatter, UNUM_FORMAT_WIDTH, (int32_t)number);
|
2011-01-09 20:18:51 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSUInteger) formatWidth
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
return (NSUInteger)unum_getAttribute (this->_formatter, UNUM_FORMAT_WIDTH);
|
2011-01-09 20:18:51 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return 0;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setMultiplier: (NSNumber *) number
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-01-25 02:25:32 +00:00
|
|
|
int32_t value = [number intValue];
|
2011-02-14 06:37:45 +00:00
|
|
|
unum_setAttribute (this->_formatter, UNUM_MULTIPLIER, value);
|
2011-01-09 20:18:51 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSNumber *) multiplier
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
int32_t value = unum_getAttribute (this->_formatter, UNUM_MULTIPLIER);
|
2011-01-25 02:25:32 +00:00
|
|
|
return [NSNumber numberWithInt: value];
|
2011-01-09 20:18:51 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return nil;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) setPercentSymbol: (NSString *) string
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
[self _setSymbol: string : UNUM_PERCENT_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) percentSymbol
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
return [self _getSymbol: UNUM_PERCENT_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return nil;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setPerMillSymbol: (NSString *) string
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
[self _setSymbol: string : UNUM_PERMILL_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) perMillSymbol
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
return [self _getSymbol: UNUM_PERMILL_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return nil;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setMinusSign: (NSString *) string
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
[self _setSymbol: string : UNUM_MINUS_SIGN_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) minusSign
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
return [self _getSymbol: UNUM_MINUS_SIGN_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return nil;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setPlusSign: (NSString *) string
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
[self _setSymbol: string : UNUM_PLUS_SIGN_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) plusSign
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
return [self _getSymbol: UNUM_PLUS_SIGN_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return nil;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setExponentSymbol: (NSString *) string
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
[self _setSymbol: string : UNUM_EXPONENTIAL_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) exponentSymbol
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
return [self _getSymbol: UNUM_EXPONENTIAL_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return nil;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setZeroSymbol: (NSString *) string
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
[self _setSymbol: string : UNUM_ZERO_DIGIT_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) zeroSymbol
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
return [self _getSymbol: UNUM_ZERO_DIGIT_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return nil;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setNilSymbol: (NSString *) string
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
return; // FIXME
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) nilSymbol
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
return nil; // FIXME
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setNotANumberSymbol: (NSString *) string
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
[self _setSymbol: string : UNUM_NAN_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) notANumberSymbol
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
return [self _getSymbol: UNUM_NAN_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return nil;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setNegativeInfinitySymbol: (NSString *) string
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
// FIXME: ICU doesn't differenciate between positive and negative infinity.
|
|
|
|
[self _setSymbol: string : UNUM_INFINITY_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) negativeInfinitySymbol
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
return [self _getSymbol: UNUM_INFINITY_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return nil;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setPositiveInfinitySymbol: (NSString *) string
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
// FIXME: ICU doesn't differenciate between positive and negative infinity.
|
|
|
|
[self _setSymbol: string : UNUM_INFINITY_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) positiveInfinitySymbol
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
return [self _getSymbol: UNUM_INFINITY_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return nil;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) setCurrencySymbol: (NSString *) string
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
[self _setSymbol: string : UNUM_CURRENCY_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) currencySymbol
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
return [self _getSymbol: UNUM_CURRENCY_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return nil;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setCurrencyCode: (NSString *) string
|
|
|
|
{
|
2011-01-09 21:16:20 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
[self _setTextAttribute: string : UNUM_CURRENCY_CODE];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-09 21:16:20 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) currencyCode
|
|
|
|
{
|
2011-01-09 21:16:20 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
return [self _getTextAttribute: UNUM_CURRENCY_CODE];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return nil;
|
2011-01-09 21:16:20 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setInternationalCurrencySymbol: (NSString *) string
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
[self _setSymbol: string : UNUM_INTL_CURRENCY_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) internationalCurrencySymbol
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
return [self _getSymbol: UNUM_INTL_CURRENCY_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return nil;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) setPositivePrefix: (NSString *) string
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
[self _setTextAttribute: string : UNUM_POSITIVE_PREFIX];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) positivePrefix
|
|
|
|
{
|
2011-01-09 21:16:20 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
return [self _getTextAttribute: UNUM_POSITIVE_PREFIX];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return nil;
|
2011-01-09 21:16:20 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setPositiveSuffix: (NSString *) string
|
|
|
|
{
|
2011-01-09 21:16:20 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
[self _setTextAttribute: string : UNUM_POSITIVE_SUFFIX];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-09 21:16:20 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) positiveSuffix
|
|
|
|
{
|
2011-01-09 21:16:20 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
return [self _getTextAttribute: UNUM_POSITIVE_SUFFIX];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return nil;
|
2011-01-09 21:16:20 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setNegativePrefix: (NSString *) string
|
|
|
|
{
|
2011-01-09 21:16:20 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
[self _setTextAttribute: string : UNUM_NEGATIVE_PREFIX];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-09 21:16:20 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) negativePrefix
|
|
|
|
{
|
2011-01-09 21:16:20 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
return [self _getTextAttribute: UNUM_NEGATIVE_PREFIX];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return nil;
|
2011-01-09 21:16:20 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setNegativeSuffix: (NSString *) string
|
|
|
|
{
|
2011-01-09 21:16:20 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
[self _setTextAttribute: string : UNUM_NEGATIVE_SUFFIX];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-09 21:16:20 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) negativeSuffix
|
|
|
|
{
|
2011-01-09 21:16:20 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
return [self _getTextAttribute: UNUM_NEGATIVE_SUFFIX];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return nil;
|
2011-01-09 21:16:20 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) setTextAttributesForZero: (NSDictionary *) newAttributes
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
return; // FIXME
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) textAttributesForZero
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
return nil; // FIXME
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setTextAttributesForNil: (NSDictionary *) newAttributes
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) textAttributesForNil
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
return nil; // FIXME
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setTextAttributesForNotANumber: (NSDictionary *) newAttributes
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
return; // FIXME
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) textAttributesForNotANumber
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
return nil; // FIXME
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setTextAttributesForPositiveInfinity: (NSDictionary *) newAttributes
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
return; // FIXME
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) textAttributesForPositiveInfinity
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
return nil; // FIXME
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setTextAttributesForNegativeInfinity: (NSDictionary *) newAttributes
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
return; // FIXME
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) textAttributesForNegativeInfinity
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
return nil; // FIXME
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) setGroupingSeparator: (NSString *) string
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
[self _setSymbol: string : UNUM_GROUPING_SEPARATOR_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) groupingSeparator
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
return [self _getSymbol: UNUM_GROUPING_SEPARATOR_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return nil;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setUsesGroupingSeparator: (BOOL) flag
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
|
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
unum_setAttribute (this->_formatter, UNUM_GROUPING_USED, flag);
|
2011-01-13 00:29:30 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) usesGroupingSeparator
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
return (BOOL)unum_getAttribute (this->_formatter, UNUM_GROUPING_USED);
|
2011-01-13 00:29:30 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return NO;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setAlwaysShowsDecimalSeparator: (BOOL) flag
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
unum_setAttribute (this->_formatter, UNUM_DECIMAL_ALWAYS_SHOWN, flag);
|
2011-01-13 00:29:30 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) alwaysShowsDecimalSeparator
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
return (BOOL)unum_getAttribute (this->_formatter, UNUM_DECIMAL_ALWAYS_SHOWN);
|
2011-01-13 00:29:30 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return NO;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setCurrencyDecimalSeparator: (NSString *) string
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
[self _setSymbol: string : UNUM_MONETARY_SEPARATOR_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) currencyDecimalSeparator
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
return [self _getSymbol: UNUM_MONETARY_SEPARATOR_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return nil;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setGroupingSize: (NSUInteger) number
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
unum_setAttribute (this->_formatter, UNUM_GROUPING_SIZE, number);
|
2011-01-13 00:29:30 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSUInteger) groupingSize
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
return (NSUInteger)unum_getAttribute (this->_formatter, UNUM_GROUPING_SIZE);
|
2011-01-13 00:29:30 +00:00
|
|
|
#else
|
|
|
|
return 3;
|
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setSecondaryGroupingSize: (NSUInteger) number
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
unum_setAttribute (this->_formatter, UNUM_SECONDARY_GROUPING_SIZE, number);
|
2011-01-13 00:29:30 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSUInteger) secondaryGroupingSize
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
return (NSUInteger)unum_getAttribute (this->_formatter,
|
2011-01-13 00:29:30 +00:00
|
|
|
UNUM_SECONDARY_GROUPING_SIZE);
|
|
|
|
#else
|
|
|
|
return 3;
|
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) setPaddingCharacter: (NSString *) string
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
[self _setTextAttribute: string : UNUM_PADDING_CHARACTER];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) paddingCharacter
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
return [self _getTextAttribute: UNUM_PADDING_CHARACTER];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return nil;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setPaddingPosition: (NSNumberFormatterPadPosition) position
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
unum_setAttribute (this->_formatter, UNUM_PADDING_POSITION,
|
2011-01-13 00:29:30 +00:00
|
|
|
_NSToICUPadPosition (position));
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSNumberFormatterPadPosition) paddingPosition
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
return _ICUToNSPadPosition(unum_getAttribute (this->_formatter,
|
2011-01-13 00:29:30 +00:00
|
|
|
UNUM_PADDING_POSITION));
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return 0;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) setMinimumIntegerDigits: (NSUInteger) number
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
unum_setAttribute (this->_formatter, UNUM_MIN_INTEGER_DIGITS, number);
|
2011-01-13 00:29:30 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSUInteger) minimumIntegerDigits
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
return (NSUInteger)unum_getAttribute (this->_formatter, UNUM_MIN_INTEGER_DIGITS);
|
2011-01-13 00:29:30 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return 0;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setMinimumFractionDigits: (NSUInteger) number
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
unum_setAttribute (this->_formatter, UNUM_MIN_FRACTION_DIGITS, number);
|
2011-01-13 00:29:30 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSUInteger) minimumFractionDigits
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
return (NSUInteger)unum_getAttribute (this->_formatter, UNUM_MIN_FRACTION_DIGITS);
|
2011-01-13 00:29:30 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return 0;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setMaximumIntegerDigits: (NSUInteger) number
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
unum_setAttribute (this->_formatter, UNUM_MAX_INTEGER_DIGITS, number);
|
2011-01-13 00:29:30 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSUInteger) maximumIntegerDigits
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
return (NSUInteger)unum_getAttribute (this->_formatter, UNUM_MAX_INTEGER_DIGITS);
|
2011-01-13 00:29:30 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return 0;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setMaximumFractionDigits: (NSUInteger) number
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
unum_setAttribute (this->_formatter, UNUM_MAX_FRACTION_DIGITS, number);
|
2011-01-13 00:29:30 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSUInteger) maximumFractionDigits
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
return (NSUInteger)unum_getAttribute (this->_formatter, UNUM_MAX_FRACTION_DIGITS);
|
2011-01-13 00:29:30 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return 0;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (BOOL) getObjectValue: (out id *) anObject
|
|
|
|
forString: (NSString *) aString
|
|
|
|
range: (NSRange) rangep
|
|
|
|
error: (out NSError **) error
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) setUsesSignificantDigits: (BOOL) flag
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
unum_setAttribute (this->_formatter, UNUM_SIGNIFICANT_DIGITS_USED, flag);
|
2011-01-13 00:29:30 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) usesSignificantDigits
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
return (BOOL)unum_getAttribute (this->_formatter, UNUM_SIGNIFICANT_DIGITS_USED);
|
2011-01-13 00:29:30 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return NO;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setMinimumSignificantDigits: (NSUInteger) number
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
unum_setAttribute (this->_formatter, UNUM_MIN_SIGNIFICANT_DIGITS, number);
|
2011-01-13 00:29:30 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSUInteger) minimumSignificantDigits
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
return (BOOL)unum_getAttribute (this->_formatter, UNUM_MIN_SIGNIFICANT_DIGITS);
|
2011-01-13 00:29:30 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return 0;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setMaximumSignificantDigits: (NSUInteger) number
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
unum_setAttribute (this->_formatter, UNUM_MAX_SIGNIFICANT_DIGITS, number);
|
2011-01-13 00:29:30 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSUInteger) maximumSignificantDigits
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
return (BOOL)unum_getAttribute (this->_formatter, UNUM_MAX_SIGNIFICANT_DIGITS);
|
2011-01-13 00:29:30 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return 0;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) setCurrencyGroupingSeparator: (NSString *) string
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
[self _setSymbol: string : UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) currencyGroupingSeparator
|
|
|
|
{
|
2011-01-09 20:18:51 +00:00
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
return [self _getSymbol: UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL];
|
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return nil;
|
2011-01-09 20:18:51 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) setLenient: (BOOL) flag
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
unum_setAttribute (this->_formatter, UNUM_LENIENT_PARSE, flag);
|
2011-01-13 00:29:30 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isLenient
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#if GS_USE_ICU == 1
|
2011-02-14 06:37:45 +00:00
|
|
|
return (BOOL)unum_getAttribute (this->_formatter, UNUM_LENIENT_PARSE);
|
2011-01-13 00:29:30 +00:00
|
|
|
#else
|
2011-01-08 18:05:42 +00:00
|
|
|
return NO;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) setPartialStringValidationEnabled: (BOOL) enabled
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isPartialStringValidationEnabled
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ (NSString *) localizedStringFromNumber: (NSNumber *) num
|
|
|
|
numberStyle: (NSNumberFormatterStyle) localizationStyle
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
#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
|
2011-01-08 18:05:42 +00:00
|
|
|
return nil;
|
2011-01-13 00:29:30 +00:00
|
|
|
#endif
|
2011-01-08 18:05:42 +00:00
|
|
|
}
|
2011-02-14 06:37:45 +00:00
|
|
|
|
2001-05-31 22:39:16 +00:00
|
|
|
@end
|
2011-01-09 20:18:51 +00:00
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
@implementation NSNumberFormatter (PrivateMethods)
|
2011-01-25 02:25:32 +00:00
|
|
|
- (void) _resetUNumberFormat
|
2011-01-09 20:18:51 +00:00
|
|
|
{
|
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
UNumberFormatStyle style;
|
|
|
|
UErrorCode err = U_ZERO_ERROR;
|
|
|
|
const char *cLocaleId;
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
if (this->_formatter)
|
|
|
|
unum_close(this->_formatter);
|
2011-01-25 02:25:32 +00:00
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
cLocaleId = [[this->_locale localeIdentifier] UTF8String];
|
|
|
|
style = _NSToICUFormatStyle (this->_style);
|
2011-01-09 20:18:51 +00:00
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
this->_formatter = unum_open (style, NULL, 0, cLocaleId, NULL, &err);
|
2011-01-09 20:18:51 +00:00
|
|
|
if (U_FAILURE(err))
|
2011-02-14 06:37:45 +00:00
|
|
|
this->_formatter = NULL;
|
2011-01-29 02:01:42 +00:00
|
|
|
|
|
|
|
[self setMaximumFractionDigits: 0];
|
2011-01-09 20:18:51 +00:00
|
|
|
#else
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _setSymbol: (NSString *) string : (NSInteger) symbol
|
|
|
|
{
|
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
unichar buffer[MAX_SYMBOL_SIZE];
|
|
|
|
unichar *str = buffer;
|
|
|
|
NSUInteger length;
|
|
|
|
UErrorCode err = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
length = [string length];
|
|
|
|
if (length > MAX_SYMBOL_SIZE)
|
2011-01-13 00:29:30 +00:00
|
|
|
str = (unichar *)NSZoneMalloc ([self zone], length * sizeof(unichar));
|
2011-01-09 20:18:51 +00:00
|
|
|
[string getCharacters: str range: NSMakeRange (0, length)];
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
unum_setSymbol (this->_formatter, symbol, str, length, &err);
|
2011-01-09 20:18:51 +00:00
|
|
|
|
|
|
|
if (length > MAX_SYMBOL_SIZE)
|
|
|
|
NSZoneFree ([self zone], str);
|
|
|
|
#else
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) _getSymbol: (NSInteger) symbol
|
|
|
|
{
|
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
UChar buffer[MAX_SYMBOL_SIZE];
|
|
|
|
UChar *str = buffer;
|
|
|
|
int32_t length;
|
|
|
|
UErrorCode err = U_ZERO_ERROR;
|
|
|
|
NSString *result;
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
length = unum_getSymbol (this->_formatter, symbol, str,
|
2011-01-09 20:18:51 +00:00
|
|
|
MAX_SYMBOL_SIZE, &err);
|
|
|
|
if (length > MAX_SYMBOL_SIZE)
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
str = (UChar *)NSZoneMalloc ([self zone], length * sizeof(UChar));
|
2011-02-14 06:37:45 +00:00
|
|
|
length = unum_getSymbol (this->_formatter, symbol, str,
|
2011-01-09 20:18:51 +00:00
|
|
|
length, &err);
|
|
|
|
}
|
|
|
|
|
|
|
|
result = [NSString stringWithCharacters: str length: length];
|
|
|
|
if (length > MAX_SYMBOL_SIZE)
|
|
|
|
NSZoneFree ([self zone], str);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
#else
|
|
|
|
return nil;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _setTextAttribute: (NSString *) string : (NSInteger) attrib
|
|
|
|
{
|
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
unichar buffer[MAX_TEXT_ATTRIB_SIZE];
|
|
|
|
unichar *str = buffer;
|
|
|
|
NSUInteger length;
|
|
|
|
UErrorCode err = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
length = [string length];
|
|
|
|
if (length > MAX_TEXT_ATTRIB_SIZE)
|
2011-01-13 00:29:30 +00:00
|
|
|
str = (unichar *)NSZoneMalloc ([self zone], length * sizeof(unichar));
|
2011-01-09 20:18:51 +00:00
|
|
|
[string getCharacters: str range: NSMakeRange (0, length)];
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
unum_setTextAttribute (this->_formatter, attrib, str, length, &err);
|
2011-01-09 20:18:51 +00:00
|
|
|
|
|
|
|
if (length > MAX_TEXT_ATTRIB_SIZE)
|
|
|
|
NSZoneFree ([self zone], str);
|
|
|
|
#else
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) _getTextAttribute: (NSInteger) attrib
|
|
|
|
{
|
|
|
|
#if GS_USE_ICU == 1
|
|
|
|
UChar buffer[MAX_TEXT_ATTRIB_SIZE];
|
|
|
|
UChar *str = buffer;
|
|
|
|
int32_t length;
|
|
|
|
UErrorCode err = U_ZERO_ERROR;
|
|
|
|
NSString *result;
|
|
|
|
|
2011-02-14 06:37:45 +00:00
|
|
|
length = unum_getTextAttribute (this->_formatter, attrib, str,
|
2011-01-09 20:18:51 +00:00
|
|
|
MAX_TEXT_ATTRIB_SIZE, &err);
|
|
|
|
if (length > MAX_TEXT_ATTRIB_SIZE)
|
|
|
|
{
|
2011-01-13 00:29:30 +00:00
|
|
|
str = (UChar *)NSZoneMalloc ([self zone], length * sizeof(UChar));
|
2011-02-14 06:37:45 +00:00
|
|
|
length = unum_getTextAttribute (this->_formatter, attrib, str,
|
2011-01-09 20:18:51 +00:00
|
|
|
length, &err);
|
|
|
|
}
|
|
|
|
|
|
|
|
result = [NSString stringWithCharacters: str length: length];
|
|
|
|
if (length > MAX_TEXT_ATTRIB_SIZE)
|
|
|
|
NSZoneFree ([self zone], str);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
#else
|
|
|
|
return nil;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
@end
|