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"
|
|
|
|
#import "Foundation/NSException.h"
|
|
|
|
#import "Foundation/NSNumberFormatter.h"
|
|
|
|
#import "Foundation/NSUserDefaults.h"
|
|
|
|
#import "Foundation/NSCharacterSet.h"
|
|
|
|
|
|
|
|
#import "GNUstepBase/GSLocale.h"
|
2008-06-11 17:00:55 +00:00
|
|
|
|
2000-09-02 01:44:24 +00:00
|
|
|
@implementation NSNumberFormatter
|
|
|
|
|
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
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
NSNumberFormatter *c = (NSNumberFormatter*) NSCopyObject(self, 0, zone);
|
|
|
|
|
2009-01-12 12:48:46 +00:00
|
|
|
IF_NO_GC(RETAIN(c->_negativeFormat);)
|
|
|
|
IF_NO_GC(RETAIN(c->_positiveFormat);)
|
|
|
|
IF_NO_GC(RETAIN(c->_attributesForPositiveValues);)
|
|
|
|
IF_NO_GC(RETAIN(c->_attributesForNegativeValues);)
|
|
|
|
IF_NO_GC(RETAIN(c->_maximum);)
|
|
|
|
IF_NO_GC(RETAIN(c->_minimum);)
|
|
|
|
IF_NO_GC(RETAIN(c->_roundingBehavior);)
|
|
|
|
IF_NO_GC(RETAIN(c->_roundingBehavior);)
|
|
|
|
IF_NO_GC(RETAIN(c->_attributedStringForNil);)
|
|
|
|
IF_NO_GC(RETAIN(c->_attributedStringForNotANumber);)
|
|
|
|
IF_NO_GC(RETAIN(c->_attributedStringForZero);)
|
2001-10-19 09:10:04 +00:00
|
|
|
|
|
|
|
return c;
|
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(_roundingBehavior);
|
|
|
|
RELEASE(_attributedStringForNil);
|
|
|
|
RELEASE(_attributedStringForNotANumber);
|
|
|
|
RELEASE(_attributedStringForZero);
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) decimalSeparator
|
|
|
|
{
|
|
|
|
if (_decimalSeparator == 0)
|
|
|
|
return @"";
|
|
|
|
else
|
|
|
|
return [NSString stringWithCharacters: &_decimalSeparator length: 1];
|
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;
|
|
|
|
|
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);
|
2000-09-02 01:44:24 +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
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (BOOL) isPartialStringValid: (NSString*)partialString
|
|
|
|
newEditingString: (NSString**)newString
|
|
|
|
errorDescription: (NSString**)error
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2005-10-17 10:47:54 +00:00
|
|
|
// FIXME
|
2001-10-19 09:10:04 +00:00
|
|
|
if (newString != NULL)
|
2004-09-14 03:34:37 +00:00
|
|
|
{
|
|
|
|
*newString = partialString;
|
|
|
|
}
|
|
|
|
if (error)
|
|
|
|
{
|
2004-09-14 15:55:18 +00:00
|
|
|
*error = nil;
|
2004-09-14 03:34:37 +00:00
|
|
|
}
|
2000-09-02 01:44:24 +00:00
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
return YES;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (BOOL) localizesFormat
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
return _localizesFormat;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (NSDecimalNumber*) maximum
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
return _maximum;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (NSDecimalNumber*) minimum
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2005-02-22 11:22:44 +00:00
|
|
|
return _minimum;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (NSString*) negativeFormat
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
return _negativeFormat;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (NSString*) positiveFormat
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
return _positiveFormat;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (NSDecimalNumberHandler*) roundingBehavior
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
return _roundingBehavior;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (void) setAllowsFloats: (BOOL)flag
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
_allowsFloats = flag;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (void) setAttributedStringForNil: (NSAttributedString*)newAttributedString
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
ASSIGN(_attributedStringForNil, newAttributedString);
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (void) setAttributedStringForNotANumber:
|
|
|
|
(NSAttributedString*)newAttributedString
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
ASSIGN(_attributedStringForNotANumber, newAttributedString);
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (void) setAttributedStringForZero: (NSAttributedString*)newAttributedString
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
|
|
|
ASSIGN(_attributedStringForZero, newAttributedString);
|
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (void) setDecimalSeparator: (NSString*)newSeparator
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
if ([newSeparator length] > 0)
|
|
|
|
_decimalSeparator = [newSeparator characterAtIndex: 0];
|
|
|
|
else
|
|
|
|
_decimalSeparator = 0;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (void) setFormat: (NSString*)aFormat
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
NSRange r;
|
2000-09-02 01:44:24 +00:00
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (void) setHasThousandSeparators: (BOOL)flag
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
_hasThousandSeparators = flag;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (void) setLocalizesFormat: (BOOL)flag
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
_localizesFormat = flag;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (void) setMaximum: (NSDecimalNumber*)aMaximum
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
ASSIGN(_maximum, aMaximum);
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (void) setMinimum: (NSDecimalNumber*)aMinimum
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
ASSIGN(_minimum, aMinimum);
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (void) setNegativeFormat: (NSString*)aFormat
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2005-10-17 10:47:54 +00:00
|
|
|
// FIXME: Should extract separators and attributes
|
2001-10-19 09:10:04 +00:00
|
|
|
ASSIGN(_negativeFormat, aFormat);
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (void) setPositiveFormat: (NSString*)aFormat
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2005-10-17 10:47:54 +00:00
|
|
|
// FIXME: Should extract separators and attributes
|
2001-10-19 09:10:04 +00:00
|
|
|
ASSIGN(_positiveFormat, aFormat);
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (void) setRoundingBehavior: (NSDecimalNumberHandler*)newRoundingBehavior
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
ASSIGN(_roundingBehavior, newRoundingBehavior);
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (void) setTextAttributesForNegativeValues: (NSDictionary*)newAttributes
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
ASSIGN(_attributesForNegativeValues, newAttributes);
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (void) setTextAttributesForPositiveValues: (NSDictionary*)newAttributes
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
ASSIGN(_attributesForPositiveValues, newAttributes);
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (void) setThousandSeparator: (NSString*)newSeparator
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
if ([newSeparator length] > 0)
|
|
|
|
_thousandSeparator = [newSeparator characterAtIndex: 0];
|
|
|
|
else
|
|
|
|
_thousandSeparator = 0;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (NSString*) stringForObjectValue: (id)anObject
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2006-12-19 12:48:28 +00:00
|
|
|
NSMutableDictionary *locale;
|
|
|
|
NSCharacterSet *formattingCharacters;
|
|
|
|
NSCharacterSet *placeHolders;
|
|
|
|
NSString *prefix;
|
|
|
|
NSString *suffix;
|
|
|
|
NSString *wholeString;
|
2008-11-17 13:45:32 +00:00
|
|
|
NSString *fracPad = nil;
|
2006-12-19 12:48:28 +00:00
|
|
|
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;
|
2008-06-11 17:00:55 +00:00
|
|
|
NSString *defaultDecimalSeparator = nil;
|
|
|
|
NSString *defaultThousandsSeparator = nil;
|
|
|
|
|
|
|
|
if (_localizesFormat)
|
|
|
|
{
|
|
|
|
NSDictionary *defaultLocale = GSDomainFromDefaultLocale();
|
|
|
|
defaultDecimalSeparator
|
|
|
|
= [defaultLocale objectForKey: NSDecimalSeparator];
|
|
|
|
defaultThousandsSeparator
|
|
|
|
= [defaultLocale objectForKey: NSThousandsSeparator];
|
|
|
|
}
|
2006-12-19 12:48:28 +00:00
|
|
|
|
2008-06-11 17:00:55 +00:00
|
|
|
if (defaultDecimalSeparator == nil)
|
|
|
|
{
|
|
|
|
defaultDecimalSeparator = @".";
|
|
|
|
}
|
|
|
|
if (defaultThousandsSeparator == nil)
|
|
|
|
{
|
|
|
|
defaultThousandsSeparator = @",";
|
|
|
|
}
|
2006-12-19 12:48:28 +00:00
|
|
|
formattingCharacters = [NSCharacterSet
|
|
|
|
characterSetWithCharactersInString: @"0123456789#.,_"];
|
|
|
|
placeHolders = [NSCharacterSet
|
|
|
|
characterSetWithCharactersInString: @"0123456789#_"];
|
2005-10-17 10:47:54 +00:00
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
if (nil == anObject)
|
|
|
|
return [[self attributedStringForNil] string];
|
2006-12-15 14:57:05 +00:00
|
|
|
if (![anObject isKindOfClass: [NSNumber class]])
|
|
|
|
return [[self attributedStringForNotANumber] string];
|
|
|
|
if ([anObject isEqual: [NSDecimalNumber notANumber]])
|
|
|
|
return [[self attributedStringForNotANumber] string];
|
2008-06-11 17:00:55 +00:00
|
|
|
if (_attributedStringForZero
|
|
|
|
&& [anObject isEqual: [NSDecimalNumber zero]])
|
2006-12-15 14:57:05 +00:00
|
|
|
return [[self attributedStringForZero] string];
|
|
|
|
|
2006-12-19 12:48:28 +00:00
|
|
|
useFormat = _positiveFormat;
|
2007-04-11 05:00:26 +00:00
|
|
|
if ([(NSNumber*)anObject compare: [NSDecimalNumber zero]]
|
|
|
|
== NSOrderedAscending)
|
2006-12-15 14:57:05 +00:00
|
|
|
{
|
|
|
|
useFormat = _negativeFormat;
|
|
|
|
negativeNumber = YES;
|
|
|
|
}
|
2000-09-02 01:44:24 +00:00
|
|
|
|
2006-12-15 14:57:05 +00:00
|
|
|
// if no format specified, use the same default that Cocoa does
|
|
|
|
if (nil == useFormat)
|
2006-12-19 12:48:28 +00:00
|
|
|
{
|
2008-06-11 17:00:55 +00:00
|
|
|
useFormat = [NSString stringWithFormat: @"%@#%@###%@##",
|
|
|
|
negativeNumber ? @"-" : @"",
|
|
|
|
defaultThousandsSeparator,
|
|
|
|
defaultDecimalSeparator];
|
2006-12-19 12:48:28 +00:00
|
|
|
}
|
2006-12-15 14:57:05 +00:00
|
|
|
|
|
|
|
prefixRange = [useFormat rangeOfCharacterFromSet: formattingCharacters];
|
|
|
|
if (NSNotFound != prefixRange.location)
|
|
|
|
{
|
|
|
|
prefix = [useFormat substringToIndex: prefixRange.location];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prefix = @"";
|
|
|
|
}
|
2005-10-17 10:47:54 +00:00
|
|
|
|
|
|
|
locale = [NSMutableDictionary dictionaryWithCapacity: 3];
|
2006-12-15 14:57:05 +00:00
|
|
|
[locale setObject: @"" forKey: NSThousandsSeparator];
|
|
|
|
[locale setObject: @"" forKey: NSDecimalSeparator];
|
|
|
|
|
|
|
|
//should also set NSDecimalDigits?
|
|
|
|
|
|
|
|
if ([self hasThousandSeparators]
|
2008-06-11 17:00:55 +00:00
|
|
|
&& (0 != [useFormat rangeOfString: defaultThousandsSeparator].length))
|
2005-10-17 10:47:54 +00:00
|
|
|
{
|
2006-12-15 14:57:05 +00:00
|
|
|
displayThousandsSeparators = YES;
|
2005-10-17 10:47:54 +00:00
|
|
|
}
|
|
|
|
|
2006-12-15 14:57:05 +00:00
|
|
|
if ([self allowsFloats]
|
2008-06-11 17:00:55 +00:00
|
|
|
&& (NSNotFound
|
|
|
|
!= [useFormat rangeOfString: defaultDecimalSeparator].location))
|
2005-10-17 10:47:54 +00:00
|
|
|
{
|
2008-06-11 17:00:55 +00:00
|
|
|
decimalPlaceRange = [useFormat rangeOfString: defaultDecimalSeparator
|
2006-12-19 12:48:28 +00:00
|
|
|
options: NSBackwardsSearch];
|
2006-12-15 14:57:05 +00:00
|
|
|
if (NSMaxRange(decimalPlaceRange) == [useFormat length])
|
|
|
|
{
|
|
|
|
decimalPlaces = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while ([placeHolders characterIsMember:
|
2006-12-19 12:48:28 +00:00
|
|
|
[useFormat characterAtIndex: NSMaxRange(decimalPlaceRange)]])
|
2006-12-15 14:57:05 +00:00
|
|
|
{
|
|
|
|
decimalPlaceRange.length++;
|
|
|
|
if (NSMaxRange(decimalPlaceRange) == [useFormat length])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
decimalPlaces=decimalPlaceRange.length -= 1;
|
|
|
|
decimalPlaceRange.location += 1;
|
|
|
|
fracPad = [useFormat substringWithRange:decimalPlaceRange];
|
|
|
|
}
|
|
|
|
if (0 != decimalPlaces)
|
|
|
|
displayFractionalPart = YES;
|
2005-10-17 10:47:54 +00:00
|
|
|
}
|
|
|
|
|
2006-12-15 14:57:05 +00:00
|
|
|
representativeDecimal = [anObject decimalValue];
|
2006-12-19 12:48:28 +00:00
|
|
|
NSDecimalRound(&roundedDecimal, &representativeDecimal, decimalPlaces,
|
|
|
|
NSRoundPlain);
|
2006-12-15 14:57:05 +00:00
|
|
|
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:
|
2006-12-19 12:48:28 +00:00
|
|
|
(NSDecimalNumber*)[NSDecimalNumber numberWithInt: -1]];
|
|
|
|
intPart = (NSDecimalNumber*)
|
2010-02-18 16:18:54 +00:00
|
|
|
[NSDecimalNumber numberWithInt: (int)[roundedNumber doubleValue]];
|
2006-12-15 14:57:05 +00:00
|
|
|
fracPart = [roundedNumber decimalNumberBySubtracting: intPart];
|
2006-12-19 12:48:28 +00:00
|
|
|
intPartString
|
|
|
|
= AUTORELEASE([[intPart descriptionWithLocale: locale] mutableCopy]);
|
2006-12-15 14:57:05 +00:00
|
|
|
|
|
|
|
//sort out the padding for the integer part
|
|
|
|
intPartRange = [useFormat rangeOfCharacterFromSet: placeHolders];
|
2006-12-29 17:37:07 +00:00
|
|
|
if (NSMaxRange(intPartRange) < ([useFormat length] - 1))
|
2006-12-15 14:57:05 +00:00
|
|
|
{
|
2006-12-29 17:37:07 +00:00
|
|
|
while (([placeHolders characterIsMember:
|
|
|
|
[useFormat characterAtIndex: NSMaxRange(intPartRange)]]
|
|
|
|
|| [[useFormat substringFromRange:
|
2008-06-11 17:00:55 +00:00
|
|
|
NSMakeRange(NSMaxRange(intPartRange), 1)] isEqual:
|
|
|
|
defaultThousandsSeparator])
|
2006-12-29 17:37:07 +00:00
|
|
|
&& NSMaxRange(intPartRange) < [useFormat length] - 1)
|
|
|
|
{
|
|
|
|
intPartRange.length++;
|
|
|
|
}
|
2006-12-15 14:57:05 +00:00
|
|
|
}
|
2006-12-19 12:48:28 +00:00
|
|
|
intPad = [[useFormat substringWithRange: intPartRange] mutableCopy];
|
2008-06-11 17:00:55 +00:00
|
|
|
[intPad replaceOccurrencesOfString: defaultThousandsSeparator
|
2006-12-19 12:48:28 +00:00
|
|
|
withString: @""
|
|
|
|
options: 0
|
|
|
|
range: NSMakeRange(0, [intPad length])];
|
2006-12-15 14:57:05 +00:00
|
|
|
[intPad replaceOccurrencesOfString: @"#"
|
2006-12-19 12:48:28 +00:00
|
|
|
withString: @""
|
|
|
|
options: NSAnchoredSearch
|
|
|
|
range: NSMakeRange(0, [intPad length])];
|
2006-12-15 14:57:05 +00:00
|
|
|
if ([intPad length] > [intPartString length])
|
|
|
|
{
|
2006-12-19 12:48:28 +00:00
|
|
|
NSRange ipRange;
|
|
|
|
|
|
|
|
ipRange = NSMakeRange(0, [intPad length] - [intPartString length] + 1);
|
|
|
|
[intPartString insertString:
|
|
|
|
[intPad substringWithRange: ipRange] atIndex: 0];
|
2006-12-15 14:57:05 +00:00
|
|
|
[intPartString replaceOccurrencesOfString: @"_"
|
2006-12-19 12:48:28 +00:00
|
|
|
withString: @" "
|
|
|
|
options: 0
|
|
|
|
range: NSMakeRange(0, [intPartString length])];
|
2006-12-15 14:57:05 +00:00
|
|
|
[intPartString replaceOccurrencesOfString: @"#"
|
2006-12-19 12:48:28 +00:00
|
|
|
withString: @"0"
|
|
|
|
options: 0
|
|
|
|
range: NSMakeRange(0, [intPartString length])];
|
2006-12-15 14:57:05 +00:00
|
|
|
}
|
|
|
|
// fix the thousands separators up
|
|
|
|
if (displayThousandsSeparators && [intPartString length] > 3)
|
2006-12-19 12:48:28 +00:00
|
|
|
{
|
|
|
|
int index = [intPartString length];
|
|
|
|
|
|
|
|
while (0 < (index -= 3))
|
|
|
|
{
|
|
|
|
[intPartString insertString: [self thousandSeparator] atIndex: index];
|
|
|
|
}
|
|
|
|
}
|
2006-12-15 14:57:05 +00:00
|
|
|
|
|
|
|
formattedNumber = [intPartString mutableCopy];
|
|
|
|
|
|
|
|
//fix up the fractional part
|
|
|
|
if (displayFractionalPart)
|
|
|
|
{
|
|
|
|
if (0 != decimalPlaces)
|
|
|
|
{
|
2006-12-19 12:48:28 +00:00
|
|
|
NSMutableString *ms;
|
|
|
|
|
2006-12-15 14:57:05 +00:00
|
|
|
fracPart = [fracPart decimalNumberByMultiplyingByPowerOf10:
|
2006-12-19 12:48:28 +00:00
|
|
|
decimalPlaces];
|
|
|
|
ms = [[fracPart descriptionWithLocale: locale] mutableCopy];
|
|
|
|
[ms replaceOccurrencesOfString: @"0"
|
|
|
|
withString: @""
|
|
|
|
options: (NSBackwardsSearch | NSAnchoredSearch)
|
|
|
|
range: NSMakeRange(0, [ms length])];
|
|
|
|
if ([fracPad length] > [ms length])
|
2006-12-15 14:57:05 +00:00
|
|
|
{
|
2006-12-19 12:48:28 +00:00
|
|
|
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])];
|
2006-12-15 14:57:05 +00:00
|
|
|
}
|
2006-12-19 12:48:28 +00:00
|
|
|
fracPartString = AUTORELEASE(ms);
|
2006-12-15 14:57:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-12-19 12:48:28 +00:00
|
|
|
fracPartString = @"0";
|
2006-12-15 14:57:05 +00:00
|
|
|
}
|
2006-12-19 12:48:28 +00:00
|
|
|
[formattedNumber appendString: [self decimalSeparator]];
|
|
|
|
[formattedNumber appendString: fracPartString];
|
2006-12-15 14:57:05 +00:00
|
|
|
}
|
2006-12-19 12:48:28 +00:00
|
|
|
/*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];
|
2006-12-15 14:57:05 +00:00
|
|
|
suffix = [useFormat substringFromIndex: NSMaxRange(suffixRange)];
|
2006-12-19 12:48:28 +00:00
|
|
|
wholeString = [[prefix stringByAppendingString: formattedNumber]
|
|
|
|
stringByAppendingString: suffix];
|
2006-12-15 14:57:05 +00:00
|
|
|
[formattedNumber release];
|
|
|
|
return wholeString;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (NSDictionary*) textAttributesForNegativeValues
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
return _attributesForNegativeValues;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (NSDictionary*) textAttributesForPositiveValues
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2001-10-19 09:10:04 +00:00
|
|
|
return _attributesForPositiveValues;
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 09:10:04 +00:00
|
|
|
- (NSString*) thousandSeparator
|
2000-09-02 01:44:24 +00:00
|
|
|
{
|
2005-10-17 10:47:54 +00:00
|
|
|
if (!_thousandSeparator)
|
2001-10-19 09:10:04 +00:00
|
|
|
return @"";
|
|
|
|
else
|
|
|
|
return [NSString stringWithCharacters: &_thousandSeparator length: 1];
|
2000-09-02 01:44:24 +00:00
|
|
|
}
|
2001-05-31 22:39:16 +00:00
|
|
|
|
2008-08-25 22:57:04 +00:00
|
|
|
- (NSString *) stringFromNumber: (NSNumber *)number
|
|
|
|
{
|
|
|
|
return [self stringForObjectValue: number];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSNumber *) numberFromString: (NSString *)string
|
|
|
|
{
|
|
|
|
id number = nil;
|
|
|
|
NSString *error;
|
|
|
|
|
|
|
|
[self getObjectValue: &number
|
|
|
|
forString: string
|
|
|
|
errorDescription: &error];
|
|
|
|
|
|
|
|
return number;
|
|
|
|
}
|
2001-05-31 22:39:16 +00:00
|
|
|
@end
|