diff --git a/ChangeLog b/ChangeLog index 35423d61a..a1fa66dd4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,49 @@ +2011-02-14 Richard Frith-Macdonald + + * Headers/Foundation/NSPortCoder.h: + * Headers/Foundation/NSCache.h: + * Headers/Foundation/NSSpellServer.h: + * Headers/Foundation/NSDecimalNumber.h: + * Headers/Foundation/NSBundle.h: + * Headers/Foundation/NSTimer.h: + * Headers/Foundation/NSScanner.h: + * Headers/Foundation/NSDistributedNotificationCenter.h: + * Headers/Foundation/NSComparisonPredicate.h: + * Headers/Foundation/NSUndoManager.h: + * Headers/Foundation/NSDateFormatter.h: + * Headers/Foundation/NSAutoreleasePool.h: + * Headers/Foundation/NSUserDefaults.h: + * Headers/Foundation/NSXMLNode.h: + * Headers/Foundation/NSThread.h: + * Headers/Foundation/NSHost.h: + * Headers/Foundation/NSRegularExpression.h: + * Headers/Foundation/NSKeyedArchiver.h: + * Headers/Foundation/NSProtocolChecker.h: + * Headers/Foundation/NSError.h: + * Headers/Foundation/NSPortMessage.h: + * Headers/Foundation/NSFileHandle.h: + * Headers/Foundation/NSDistributedLock.h: + * Headers/Foundation/NSPort.h: + * Headers/Foundation/NSSortDescriptor.h: + * Headers/Foundation/NSLocale.h: + * Headers/Foundation/NSTask.h: + * Headers/Foundation/NSArchiver.h: + * Headers/Foundation/NSInvocation.h: + * Headers/Foundation/NSFileManager.h: + * Headers/Foundation/NSNumberFormatter.h: + * Headers/Foundation/NSPortNameServer.h: + * Headers/Foundation/NSXMLParser.h: + * Headers/Foundation/NSIndexPath.h: + * Headers/Additions/GNUstepBase/GSMime.h: + * Headers/Additions/GNUstepBase/GSVersionMacros.h: + Make the presence of the pointer for reserved/private data clearer + and more explicit to try to ensure we actually remember to use it + to prevent ABI breakage. + * Source/NSNumberFormatter.m: + Modified to store new/extra ivars via the _reserved pointer so that + NSNumberFormatter can be safely subclassed by code outside the + library. + 2011-02-13 Stefan Bidigaray * Source/NSNumberFormatter.m: Moved 10.4+ functionality to a subclass. diff --git a/Headers/Additions/GNUstepBase/GSMime.h b/Headers/Additions/GNUstepBase/GSMime.h index e12f5b94f..215231a3d 100644 --- a/Headers/Additions/GNUstepBase/GSMime.h +++ b/Headers/Additions/GNUstepBase/GSMime.h @@ -75,7 +75,12 @@ extern "C" { NSMutableDictionary *objects; NSMutableDictionary *params; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } + (NSString*) makeQuoted: (NSString*)v always: (BOOL)flag; + (NSString*) makeToken: (NSString*)t preservingCase: (BOOL)preserve; @@ -288,8 +293,8 @@ typedef enum { @interface GSMimeSMTPClient : NSObject { #if GS_NONFRAGILE -# if defined(GS_GSMimeSMTPClient_IVARS) -@public GS_GSMimeSMTPClient_IVARS +# if defined(GSMimeSMTPClient_IVARS) +@public GSMimeSMTPClient_IVARS # endif #else @private id _internal; diff --git a/Headers/Additions/GNUstepBase/GSVersionMacros.h b/Headers/Additions/GNUstepBase/GSVersionMacros.h index ea43b256a..7c9f01fce 100644 --- a/Headers/Additions/GNUstepBase/GSVersionMacros.h +++ b/Headers/Additions/GNUstepBase/GSVersionMacros.h @@ -228,16 +228,6 @@ #define GS_EXPOSE(X) (!GS_NONFRAGILE || defined(EXPOSE_##X##_IVARS)) -#ifdef GS_NONFRAGILE -# define GS_PADDING_IVAR -#else -# ifdef __clang__ -# define GS_PADDING_IVAR __attribute__((unused)) void *gs_unused; -# else -# define GS_PADDING_IVAR void *gs_unused; -# endif -#endif - /* Static analyser macros: Provide annotations to help the analyser */ // TODO: Make this more sensible when GCC supports __attribute__((unused)) on // ivars diff --git a/Headers/Foundation/NSArchiver.h b/Headers/Foundation/NSArchiver.h index c896bf097..0eaca738d 100644 --- a/Headers/Foundation/NSArchiver.h +++ b/Headers/Foundation/NSArchiver.h @@ -70,7 +70,12 @@ extern "C" { BOOL _encodingRoot; BOOL _initialPass; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } /* Initializing an archiver */ @@ -176,7 +181,12 @@ extern "C" { NSMutableDictionary *objDict; /* Class information store. */ NSMutableArray *objSave; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } /* Initializing an unarchiver */ diff --git a/Headers/Foundation/NSAutoreleasePool.h b/Headers/Foundation/NSAutoreleasePool.h index 79f048d66..15a581ae4 100644 --- a/Headers/Foundation/NSAutoreleasePool.h +++ b/Headers/Foundation/NSAutoreleasePool.h @@ -194,7 +194,12 @@ typedef struct autorelease_array_list /* The method to add an object to this pool */ void (*_addImp)(id, SEL, id); #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } /** diff --git a/Headers/Foundation/NSBundle.h b/Headers/Foundation/NSBundle.h index 3242b8754..cdd24f1f0 100644 --- a/Headers/Foundation/NSBundle.h +++ b/Headers/Foundation/NSBundle.h @@ -119,7 +119,12 @@ GS_EXPORT NSString* const NSLoadedClasses; unsigned _version; NSString *_frameworkVersion; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } /** Return an array enumerating all the bundles in the application. This diff --git a/Headers/Foundation/NSCache.h b/Headers/Foundation/NSCache.h index 80edc80c9..75ac2c4c4 100644 --- a/Headers/Foundation/NSCache.h +++ b/Headers/Foundation/NSCache.h @@ -61,7 +61,12 @@ extern "C" { /** Total number of accesses to objects */ int64_t _totalAccesses; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } /** * Returns the maximum number of objects that are supported by this cache. diff --git a/Headers/Foundation/NSComparisonPredicate.h b/Headers/Foundation/NSComparisonPredicate.h index 2d4f96ef9..9c993d6f6 100644 --- a/Headers/Foundation/NSComparisonPredicate.h +++ b/Headers/Foundation/NSComparisonPredicate.h @@ -77,7 +77,12 @@ typedef enum _NSPredicateOperatorType NSUInteger _options; NSPredicateOperatorType _type; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif @public NSExpression *_left; NSExpression *_right; diff --git a/Headers/Foundation/NSDateFormatter.h b/Headers/Foundation/NSDateFormatter.h index 3ea487fe9..44ebee109 100644 --- a/Headers/Foundation/NSDateFormatter.h +++ b/Headers/Foundation/NSDateFormatter.h @@ -134,7 +134,12 @@ typedef NSUInteger NSDateFormatterBehavior; NSDateFormatterStyle _dateStyle; void *_formatter; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } /* Initializing an NSDateFormatter */ diff --git a/Headers/Foundation/NSDecimalNumber.h b/Headers/Foundation/NSDecimalNumber.h index 89d02a404..2814c50bf 100644 --- a/Headers/Foundation/NSDecimalNumber.h +++ b/Headers/Foundation/NSDecimalNumber.h @@ -129,7 +129,12 @@ extern "C" { BOOL _raiseOnUnderflow; BOOL _raiseOnDivideByZero; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } /** diff --git a/Headers/Foundation/NSDistributedLock.h b/Headers/Foundation/NSDistributedLock.h index 326def35f..12a8d9d09 100644 --- a/Headers/Foundation/NSDistributedLock.h +++ b/Headers/Foundation/NSDistributedLock.h @@ -40,7 +40,12 @@ extern "C" { NSString *_lockPath; NSDate *_lockTime; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } + (NSDistributedLock*) lockWithPath: (NSString*)aPath; diff --git a/Headers/Foundation/NSDistributedNotificationCenter.h b/Headers/Foundation/NSDistributedNotificationCenter.h index ab8ec2ba0..8713d2b9d 100644 --- a/Headers/Foundation/NSDistributedNotificationCenter.h +++ b/Headers/Foundation/NSDistributedNotificationCenter.h @@ -86,7 +86,12 @@ GS_EXPORT NSString* const GSNetworkNotificationCenterType; id _remote; /* Proxy for center. */ BOOL _suspended; /* Is delivery suspended? */ #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } + (NSNotificationCenter*) defaultCenter; + (NSNotificationCenter*) notificationCenterForType: (NSString*)type; diff --git a/Headers/Foundation/NSError.h b/Headers/Foundation/NSError.h index 59c9e29ca..2fb2775b9 100644 --- a/Headers/Foundation/NSError.h +++ b/Headers/Foundation/NSError.h @@ -121,7 +121,12 @@ GS_EXPORT NSString* const NSCocoaErrorDomain; NSString *_domain; NSDictionary *_userInfo; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } /** diff --git a/Headers/Foundation/NSFileHandle.h b/Headers/Foundation/NSFileHandle.h index 2595571d1..037f6cfef 100644 --- a/Headers/Foundation/NSFileHandle.h +++ b/Headers/Foundation/NSFileHandle.h @@ -162,7 +162,12 @@ GS_EXPORT NSString * const NSFileHandleOperationException; NSFileHandle *_readHandle; NSFileHandle *_writeHandle; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } + (id) pipe; - (NSFileHandle*) fileHandleForReading; diff --git a/Headers/Foundation/NSFileManager.h b/Headers/Foundation/NSFileManager.h index 33c50f006..d4b2ee200 100644 --- a/Headers/Foundation/NSFileManager.h +++ b/Headers/Foundation/NSFileManager.h @@ -203,7 +203,12 @@ typedef uint32_t OSType; @private NSString *_lastError; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } + (NSFileManager*) defaultManager; @@ -387,7 +392,12 @@ typedef uint32_t OSType; BOOL justContents: 1; } _flags; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } - (NSDictionary*) directoryAttributes; - (NSDictionary*) fileAttributes; diff --git a/Headers/Foundation/NSHost.h b/Headers/Foundation/NSHost.h index 7ed9da185..22bd05815 100644 --- a/Headers/Foundation/NSHost.h +++ b/Headers/Foundation/NSHost.h @@ -44,7 +44,12 @@ extern "C" { NSSet *_names; NSSet *_addresses; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } /** diff --git a/Headers/Foundation/NSIndexPath.h b/Headers/Foundation/NSIndexPath.h index 94d41e185..127d35cfa 100644 --- a/Headers/Foundation/NSIndexPath.h +++ b/Headers/Foundation/NSIndexPath.h @@ -50,7 +50,12 @@ extern "C" { NSUInteger _length; NSUInteger *_indexes; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } /** diff --git a/Headers/Foundation/NSInvocation.h b/Headers/Foundation/NSInvocation.h index b96b57e3d..98f99a62c 100644 --- a/Headers/Foundation/NSInvocation.h +++ b/Headers/Foundation/NSInvocation.h @@ -50,7 +50,12 @@ extern "C" { BOOL _sendToSuper; void *_retptr; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } /* diff --git a/Headers/Foundation/NSKeyedArchiver.h b/Headers/Foundation/NSKeyedArchiver.h index 0a05872dd..2b797a29e 100644 --- a/Headers/Foundation/NSKeyedArchiver.h +++ b/Headers/Foundation/NSKeyedArchiver.h @@ -71,7 +71,12 @@ extern "C" { NSMutableArray *_obj; /* Array of objects. */ NSPropertyListFormat _format; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } /** @@ -238,7 +243,12 @@ extern "C" { #endif NSZone *_zone; /* Zone for allocating objs. */ #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } /** diff --git a/Headers/Foundation/NSLocale.h b/Headers/Foundation/NSLocale.h index ac8e55a5b..8ec92e7ce 100644 --- a/Headers/Foundation/NSLocale.h +++ b/Headers/Foundation/NSLocale.h @@ -104,7 +104,12 @@ GS_EXPORT NSString * const NSISO8601Calendar; NSString *_localeId; NSMutableDictionary *_components; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } #if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST) diff --git a/Headers/Foundation/NSNumberFormatter.h b/Headers/Foundation/NSNumberFormatter.h index 99e0e34d3..6fba88078 100644 --- a/Headers/Foundation/NSNumberFormatter.h +++ b/Headers/Foundation/NSNumberFormatter.h @@ -137,10 +137,12 @@ typedef NSUInteger NSNumberFormatterRoundingMode; NSString *_positiveFormat; NSDictionary *_attributesForPositiveValues; NSDictionary *_attributesForNegativeValues; - - // 10.4 variable -@protected - NSUInteger _behavior; +#endif +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; #endif } diff --git a/Headers/Foundation/NSPort.h b/Headers/Foundation/NSPort.h index e0a4ce2b0..9ce96df03 100644 --- a/Headers/Foundation/NSPort.h +++ b/Headers/Foundation/NSPort.h @@ -211,7 +211,12 @@ typedef SOCKET NSSocketNativeHandle; NSMapTable *events; #endif #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } /** diff --git a/Headers/Foundation/NSPortCoder.h b/Headers/Foundation/NSPortCoder.h index 9e705a40c..fdfde9c16 100644 --- a/Headers/Foundation/NSPortCoder.h +++ b/Headers/Foundation/NSPortCoder.h @@ -94,7 +94,12 @@ extern "C" { unsigned _version; /* Version of archiver used. */ NSZone *_zone; /* Zone for allocating objs. */ #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } /** diff --git a/Headers/Foundation/NSPortMessage.h b/Headers/Foundation/NSPortMessage.h index 72e5fdf69..eb794c2c2 100644 --- a/Headers/Foundation/NSPortMessage.h +++ b/Headers/Foundation/NSPortMessage.h @@ -51,7 +51,12 @@ extern "C" { NSPort *_send; NSMutableArray *_components; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } /** * OpenStep compatibility. diff --git a/Headers/Foundation/NSPortNameServer.h b/Headers/Foundation/NSPortNameServer.h index 9033f258f..5b6c3f628 100644 --- a/Headers/Foundation/NSPortNameServer.h +++ b/Headers/Foundation/NSPortNameServer.h @@ -60,7 +60,12 @@ extern "C" { NSMapTable *_portMap; /* Registered ports information. */ NSMapTable *_nameMap; /* Registered names information. */ #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } + (id) sharedInstance; - (NSPort*) portForName: (NSString*)name diff --git a/Headers/Foundation/NSProtocolChecker.h b/Headers/Foundation/NSProtocolChecker.h index 068d4eab2..fa31905e4 100644 --- a/Headers/Foundation/NSProtocolChecker.h +++ b/Headers/Foundation/NSProtocolChecker.h @@ -42,7 +42,12 @@ extern "C" { Protocol *_myProtocol; NSObject *_myTarget; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } // Creating a checker diff --git a/Headers/Foundation/NSRegularExpression.h b/Headers/Foundation/NSRegularExpression.h index 75b45780a..5634c8231 100644 --- a/Headers/Foundation/NSRegularExpression.h +++ b/Headers/Foundation/NSRegularExpression.h @@ -34,10 +34,17 @@ DEFINE_BLOCK_TYPE(GSRegexBlock, void, NSTextCheckingResult*, NSMatchingFlags, BO @interface NSRegularExpression : NSObject { - @private - GSREGEXTYPE *regex; - NSRegularExpressionOptions options; - GS_PADDING_IVAR; +#if GS_EXPOSE(NSRegularExpression) + @private + GSREGEXTYPE *regex; + NSRegularExpressionOptions options; +#endif +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } + (NSRegularExpression*)regularExpressionWithPattern: (NSString*)aPattern options: (NSRegularExpressionOptions)opts diff --git a/Headers/Foundation/NSScanner.h b/Headers/Foundation/NSScanner.h index 569726d2e..2f302f2b3 100644 --- a/Headers/Foundation/NSScanner.h +++ b/Headers/Foundation/NSScanner.h @@ -50,7 +50,12 @@ extern "C" { BOOL _caseSensitive; BOOL _isUnicode; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } /* diff --git a/Headers/Foundation/NSSortDescriptor.h b/Headers/Foundation/NSSortDescriptor.h index a3bd91293..08210d841 100644 --- a/Headers/Foundation/NSSortDescriptor.h +++ b/Headers/Foundation/NSSortDescriptor.h @@ -50,7 +50,12 @@ extern "C" { BOOL _ascending; SEL _selector; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } /** Returns a flag indicating whether the sort descriptor sorts objects diff --git a/Headers/Foundation/NSSpellServer.h b/Headers/Foundation/NSSpellServer.h index 6f843d988..e27e730fe 100644 --- a/Headers/Foundation/NSSpellServer.h +++ b/Headers/Foundation/NSSpellServer.h @@ -64,7 +64,12 @@ GS_EXPORT NSString *const NSGrammarUserDescription; NSString *_currentLanguage; NSArray *_ignoredWords; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } // Checking in Your Service diff --git a/Headers/Foundation/NSTask.h b/Headers/Foundation/NSTask.h index 834d43e19..bde340499 100644 --- a/Headers/Foundation/NSTask.h +++ b/Headers/Foundation/NSTask.h @@ -54,7 +54,12 @@ extern "C" { BOOL _hasCollected; BOOL _hasNotified; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } + (NSTask*) launchedTaskWithLaunchPath: (NSString*)path diff --git a/Headers/Foundation/NSThread.h b/Headers/Foundation/NSThread.h index ba6dbe974..fc9a345cd 100644 --- a/Headers/Foundation/NSThread.h +++ b/Headers/Foundation/NSThread.h @@ -72,7 +72,12 @@ extern "C" { id _gcontext; void *_runLoopInfo; // Per-thread runloop related info. #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } /** diff --git a/Headers/Foundation/NSTimer.h b/Headers/Foundation/NSTimer.h index 22273d950..8ed2d236d 100644 --- a/Headers/Foundation/NSTimer.h +++ b/Headers/Foundation/NSTimer.h @@ -51,7 +51,12 @@ extern "C" { SEL _selector; id _info; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } /* Creating timer objects. */ diff --git a/Headers/Foundation/NSUndoManager.h b/Headers/Foundation/NSUndoManager.h index 488fb9f6f..51835ea32 100644 --- a/Headers/Foundation/NSUndoManager.h +++ b/Headers/Foundation/NSUndoManager.h @@ -98,7 +98,12 @@ GS_EXPORT NSString* const NSUndoManagerWillUndoChangeNotification; unsigned _disableCount; unsigned _levelsOfUndo; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } - (void) beginUndoGrouping; diff --git a/Headers/Foundation/NSUserDefaults.h b/Headers/Foundation/NSUserDefaults.h index c7f4aa736..b92594954 100644 --- a/Headers/Foundation/NSUserDefaults.h +++ b/Headers/Foundation/NSUserDefaults.h @@ -228,7 +228,12 @@ GS_EXPORT NSString* const GSLocale; NSRecursiveLock *_lock; NSDistributedLock *_fileLock; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } /** diff --git a/Headers/Foundation/NSXMLNode.h b/Headers/Foundation/NSXMLNode.h index fbd7bf7e6..86442f2cf 100644 --- a/Headers/Foundation/NSXMLNode.h +++ b/Headers/Foundation/NSXMLNode.h @@ -88,7 +88,12 @@ typedef NSUInteger NSXMLNodeKind; NSUInteger _index; id _objectValue; #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } /** diff --git a/Headers/Foundation/NSXMLParser.h b/Headers/Foundation/NSXMLParser.h index fd679a1f6..bac91d8a3 100644 --- a/Headers/Foundation/NSXMLParser.h +++ b/Headers/Foundation/NSXMLParser.h @@ -74,7 +74,12 @@ GS_EXPORT NSString* const NSXMLParserErrorDomain; void *_parser; // GSXMLParser void *_handler; // SAXHandler #endif - GS_PADDING_IVAR; +#if !GS_NONFRAGILE + /* Pointer to private additional data used to avoid breaking ABI + * when we don't have the non-fragile ABI available. + */ + void *_reserved; +#endif } /** diff --git a/Source/NSNumberFormatter.m b/Source/NSNumberFormatter.m index 2e3f2146d..3a3b39d5c 100644 --- a/Source/NSNumberFormatter.m +++ b/Source/NSNumberFormatter.m @@ -198,16 +198,20 @@ _ICUToNSRoundingMode (UNumberFormatRoundingMode mode) } #endif -@interface NSNumberFormatter10_4 : NSNumberFormatter -{ - BOOL _genDecimal; - NSUInteger _style; - NSLocale *_locale; - void *_formatter; -} -@end -@interface NSNumberFormatter10_4 (PrivateMethods) +// 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) - (void) _resetUNumberFormat; - (void) _setSymbol: (NSString *) string : (NSInteger) symbol; - (NSString *) _getSymbol: (NSInteger) symbol; @@ -219,12 +223,6 @@ _ICUToNSRoundingMode (UNumberFormatRoundingMode mode) static NSUInteger _defaultBehavior = 0; -+ (id) allocWithZone: (NSZone *) z -{ -// Always return the subclass... - return [NSNumberFormatter10_4 allocWithZone: z]; -} - - (BOOL) allowsFloats { return _allowsFloats; @@ -285,20 +283,30 @@ static NSUInteger _defaultBehavior = 0; - (id) copyWithZone: (NSZone *)zone { - NSNumberFormatter *c = (NSNumberFormatter*) NSCopyObject(self, 0, zone); + NSNumberFormatter *o = (NSNumberFormatter*) NSCopyObject(self, 0, zone); - 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->_attributedStringForNil);) - IF_NO_GC(RETAIN(c->_attributedStringForNotANumber);) - IF_NO_GC(RETAIN(c->_attributedStringForZero);) - - return c; + 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; } - (void) dealloc @@ -313,15 +321,34 @@ static NSUInteger _defaultBehavior = 0; RELEASE(_attributedStringForNil); RELEASE(_attributedStringForNotANumber); RELEASE(_attributedStringForZero); + if (this != 0) + { + RELEASE(this->_locale); +#if GS_USE_ICU == 1 + unum_close (this->_formatter); +#endif + NSZoneFree([self zone], this); + } [super dealloc]; } - (NSString*) decimalSeparator { - if (_decimalSeparator == 0) - return @""; - else - return [NSString stringWithCharacters: &_decimalSeparator length: 1]; + 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; } - (NSString*) editingStringForObjectValue: (id)anObject @@ -413,6 +440,7 @@ static NSUInteger _defaultBehavior = 0; { id o; + _reserved = NSZoneCalloc([self zone], 1, sizeof(Internal)); _allowsFloats = YES; _decimalSeparator = '.'; _thousandSeparator = ','; @@ -424,7 +452,15 @@ static NSUInteger _defaultBehavior = 0; [self setAttributedStringForNotANumber: o]; RELEASE(o); - _behavior = _defaultBehavior; + this->_behavior = _defaultBehavior; + this->_locale = RETAIN([NSLocale currentLocale]); + this->_style = NSNumberFormatterNoStyle; + [self _resetUNumberFormat]; + if (this->_formatter == NULL) + { + RELEASE(self); + return nil; + } return self; } @@ -604,10 +640,20 @@ static NSUInteger _defaultBehavior = 0; - (void) setDecimalSeparator: (NSString*)newSeparator { - if ([newSeparator length] > 0) - _decimalSeparator = [newSeparator characterAtIndex: 0]; - else - _decimalSeparator = 0; + 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; + } } - (void) setFormat: (NSString*)aFormat @@ -698,870 +744,8 @@ static NSUInteger _defaultBehavior = 0; - (NSString*) stringForObjectValue: (id)anObject { - 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; -} - -- (NSDictionary*) textAttributesForNegativeValues -{ - return _attributesForNegativeValues; -} - -- (NSDictionary*) textAttributesForPositiveValues -{ - return _attributesForPositiveValues; -} - -- (NSString*) thousandSeparator -{ - if (!_thousandSeparator) - return @""; - else - return [NSString stringWithCharacters: &_thousandSeparator length: 1]; -} - -- (NSString *) stringFromNumber: (NSNumber *)number -{ - return [self stringForObjectValue: number]; -} - -- (NSNumber *) numberFromString: (NSString *)string -{ - return nil; -} - -- (void) setFormatterBehavior: (NSNumberFormatterBehavior) behavior -{ - _behavior = behavior; -} - -- (NSNumberFormatterBehavior) formatterBehavior -{ - return _behavior; -} - -+ (void) setDefaultFormatterBehavior: (NSNumberFormatterBehavior) behavior -{ - _defaultBehavior = behavior; -} - -+ (NSNumberFormatterBehavior) defaultFormatterBehavior -{ - return _defaultBehavior; -} - -- (void) setNumberStyle: (NSNumberFormatterStyle) style -{ - return; -} - -- (NSNumberFormatterStyle) numberStyle -{ - return 0; -} - -- (void) setGeneratesDecimalNumbers: (BOOL) flag -{ - return; -} - -- (BOOL) generatesDecimalNubmers -{ - return NO; -} - - -- (void) setLocale: (NSLocale *) locale -{ - return; -} - -- (NSLocale *) locale -{ - return nil; -} - - -- (void) setRoundingIncrement: (NSNumber *) number -{ - return; -} - -- (NSNumber *) roundingIncrement -{ - return nil; -} - -- (void) setRoundingMode: (NSNumberFormatterRoundingMode) mode -{ - return; -} - -- (NSNumberFormatterRoundingMode) roundingMode -{ - return 0; -} - -- (void) setFormatWidth: (NSUInteger) number -{ - return; -} - -- (NSUInteger) formatWidth -{ - return 0; -} - -- (void) setMultiplier: (NSNumber *) number -{ - return; -} - -- (NSNumber *) multiplier -{ - return nil; -} - - -- (void) setPercentSymbol: (NSString *) string -{ - return; -} - -- (NSString *) percentSymbol -{ - return nil; -} - -- (void) setPerMillSymbol: (NSString *) string -{ - return; -} - -- (NSString *) perMillSymbol -{ - return nil; -} - -- (void) setMinusSign: (NSString *) string -{ - return; -} - -- (NSString *) minusSign -{ - return nil; -} - -- (void) setPlusSign: (NSString *) string -{ - return; -} - -- (NSString *) plusSign -{ - return nil; -} - -- (void) setExponentSymbol: (NSString *) string -{ - return; -} - -- (NSString *) exponentSymbol -{ - return nil; -} - -- (void) setZeroSymbol: (NSString *) string -{ - return; -} - -- (NSString *) zeroSymbol -{ - return nil; -} - -- (void) setNilSymbol: (NSString *) string -{ - return; // FIXME -} - -- (NSString *) nilSymbol -{ - return nil; // FIXME -} - -- (void) setNotANumberSymbol: (NSString *) string -{ - return; -} - -- (NSString *) notANumberSymbol -{ - return nil; -} - -- (void) setNegativeInfinitySymbol: (NSString *) string -{ - return; -} - -- (NSString *) negativeInfinitySymbol -{ - return nil; -} - -- (void) setPositiveInfinitySymbol: (NSString *) string -{ - return; -} - -- (NSString *) positiveInfinitySymbol -{ - return nil; -} - - -- (void) setCurrencySymbol: (NSString *) string -{ - return; -} - -- (NSString *) currencySymbol -{ - return nil; -} - -- (void) setCurrencyCode: (NSString *) string -{ - return; -} - -- (NSString *) currencyCode -{ - return nil; -} - -- (void) setInternationalCurrencySymbol: (NSString *) string -{ - return; -} - -- (NSString *) internationalCurrencySymbol -{ - return nil; -} - - -- (void) setPositivePrefix: (NSString *) string -{ - return; -} - -- (NSString *) positivePrefix -{ - return nil; -} - -- (void) setPositiveSuffix: (NSString *) string -{ - return; -} - -- (NSString *) positiveSuffix -{ - return nil; -} - -- (void) setNegativePrefix: (NSString *) string -{ - return; -} - -- (NSString *) negativePrefix -{ - return nil; -} - -- (void) setNegativeSuffix: (NSString *) string -{ - return; -} - -- (NSString *) negativeSuffix -{ - return nil; -} - - -- (void) setTextAttributesForZero: (NSDictionary *) newAttributes -{ - return; // FIXME -} - -- (NSDictionary *) textAttributesForZero -{ - return nil; // FIXME -} - -- (void) setTextAttributesForNil: (NSDictionary *) newAttributes -{ - return; -} - -- (NSDictionary *) textAttributesForNil -{ - return nil; // FIXME -} - -- (void) setTextAttributesForNotANumber: (NSDictionary *) newAttributes -{ - return; // FIXME -} - -- (NSDictionary *) textAttributesForNotANumber -{ - return nil; // FIXME -} - -- (void) setTextAttributesForPositiveInfinity: (NSDictionary *) newAttributes -{ - return; // FIXME -} - -- (NSDictionary *) textAttributesForPositiveInfinity -{ - return nil; // FIXME -} - -- (void) setTextAttributesForNegativeInfinity: (NSDictionary *) newAttributes -{ - return; // FIXME -} - -- (NSDictionary *) textAttributesForNegativeInfinity -{ - return nil; // FIXME -} - - -- (void) setGroupingSeparator: (NSString *) string -{ - return; -} - -- (NSString *) groupingSeparator -{ - return nil; -} - -- (void) setUsesGroupingSeparator: (BOOL) flag -{ - return; -} - -- (BOOL) usesGroupingSeparator -{ - return NO; -} - -- (void) setAlwaysShowsDecimalSeparator: (BOOL) flag -{ - return; -} - -- (BOOL) alwaysShowsDecimalSeparator -{ - return NO; -} - -- (void) setCurrencyDecimalSeparator: (NSString *) string -{ - return; -} - -- (NSString *) currencyDecimalSeparator -{ - return nil; -} - -- (void) setGroupingSize: (NSUInteger) number -{ - return; -} - -- (NSUInteger) groupingSize -{ - return 3; -} - -- (void) setSecondaryGroupingSize: (NSUInteger) number -{ - return; -} - -- (NSUInteger) secondaryGroupingSize -{ - return 0; -} - - -- (void) setPaddingCharacter: (NSString *) string -{ - return; -} - -- (NSString *) paddingCharacter -{ - return nil; -} - -- (void) setPaddingPosition: (NSNumberFormatterPadPosition) position -{ - return; -} - -- (NSNumberFormatterPadPosition) paddingPosition -{ - return 0; -} - - -- (void) setMinimumIntegerDigits: (NSUInteger) number -{ - return; -} - -- (NSUInteger) minimumIntegerDigits -{ - return 0; -} - -- (void) setMinimumFractionDigits: (NSUInteger) number -{ - return; -} - -- (NSUInteger) minimumFractionDigits -{ - return 0; -} - -- (void) setMaximumIntegerDigits: (NSUInteger) number -{ - return; -} - -- (NSUInteger) maximumIntegerDigits -{ - return 0; -} - -- (void) setMaximumFractionDigits: (NSUInteger) number -{ - return; -} - -- (NSUInteger) maximumFractionDigits -{ - return 0; -} - - -- (BOOL) getObjectValue: (out id *) anObject - forString: (NSString *) aString - range: (NSRange) rangep - error: (out NSError **) error -{ - return NO; -} - - -- (void) setUsesSignificantDigits: (BOOL) flag -{ - return; -} - -- (BOOL) usesSignificantDigits -{ - return NO; -} - -- (void) setMinimumSignificantDigits: (NSUInteger) number -{ - return; -} - -- (NSUInteger) minimumSignificantDigits -{ - return 0; -} - -- (void) setMaximumSignificantDigits: (NSUInteger) number -{ - return; -} - -- (NSUInteger) maximumSignificantDigits -{ - return 0; -} - - -- (void) setCurrencyGroupingSeparator: (NSString *) string -{ - return; -} - -- (NSString *) currencyGroupingSeparator -{ - return nil; -} - - -- (void) setLenient: (BOOL) flag -{ - return; -} - -- (BOOL) isLenient -{ - return NO; -} - - -- (void) setPartialStringValidationEnabled: (BOOL) enabled -{ - return; -} - -- (BOOL) isPartialStringValidationEnabled -{ - return NO; -} - -+ (NSString *) localizedStringFromNumber: (NSNumber *) num - numberStyle: (NSNumberFormatterStyle) localizationStyle -{ - return nil; -} -@end - -@implementation NSNumberFormatter10_4 -+ (id) allocWithZone: (NSZone *) z -{ - return NSAllocateObject (self, 0, z); -} - -- (id) init -{ - self = [super init]; - if (self == nil) - return nil; - - _locale = RETAIN([NSLocale currentLocale]); - _style = NSNumberFormatterNoStyle; - [self _resetUNumberFormat]; - if (_formatter == NULL) - { - RELEASE(self); - return nil; - } - - return self; -} - -- (NSString*) decimalSeparator -{ - if (_behavior == NSNumberFormatterBehavior10_4 - || _behavior == NSNumberFormatterBehaviorDefault) - { -#if GS_USE_ICU == 1 - return [self _getSymbol: UNUM_DECIMAL_SEPARATOR_SYMBOL]; -#endif - } - else if (_behavior == NSNumberFormatterBehavior10_0) - { - return [super decimalSeparator]; - } - return nil; -} - -- (void) setDecimalSeparator: (NSString*)newSeparator -{ - if (_behavior == NSNumberFormatterBehavior10_4 - || _behavior == NSNumberFormatterBehaviorDefault) - { -#if GS_USE_ICU == 1 - [self _setSymbol: newSeparator : UNUM_DECIMAL_SEPARATOR_SYMBOL]; -#endif - } - else if (_behavior == NSNumberFormatterBehavior10_0) - { - [super setDecimalSeparator: newSeparator]; - } -} - -- (NSString *) stringForObjectValue: (id)anObject -{ - if (_behavior == NSNumberFormatterBehaviorDefault - || _behavior == NSNumberFormatterBehavior10_4) + if (this->_behavior == NSNumberFormatterBehaviorDefault + || this->_behavior == NSNumberFormatterBehavior10_4) { #if GS_USE_ICU == 1 @@ -1572,11 +756,11 @@ range: NSMakeRange(0, [ms length])]; int32_t len; \ NSString *result; \ \ - len = function (_formatter, number, outStr, MAX_BUFFER_SIZE, NULL, &err); \ + len = function (this->_formatter, number, outStr, MAX_BUFFER_SIZE, NULL, &err); \ if (len > MAX_BUFFER_SIZE) \ outStr = NSZoneMalloc ([self zone], len * sizeof(UChar));\ err = U_ZERO_ERROR; \ - function (_formatter, number, outStr, MAX_BUFFER_SIZE, NULL, &err); \ + function (this->_formatter, number, outStr, MAX_BUFFER_SIZE, NULL, &err); \ result = [NSString stringWithCharacters: outStr length: len]; \ if (len > MAX_BUFFER_SIZE) \ NSZoneFree ([self zone], outStr); \ @@ -1631,15 +815,289 @@ range: NSMakeRange(0, [ms length])]; } #endif } - else if (_behavior == NSNumberFormatterBehavior10_0) + else if (this->_behavior == NSNumberFormatterBehavior10_0) { - return [super stringForObjectValue: anObject]; + 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; } return nil; } +- (NSDictionary*) textAttributesForNegativeValues +{ + return _attributesForNegativeValues; +} + +- (NSDictionary*) textAttributesForPositiveValues +{ + return _attributesForPositiveValues; +} + +- (NSString*) thousandSeparator +{ + if (!_thousandSeparator) + return @""; + else + return [NSString stringWithCharacters: &_thousandSeparator length: 1]; +} + - (NSString *) stringFromNumber: (NSNumber *)number { +// This is a 10.4 and above method and should not work with earlier version. return [self stringForObjectValue: number]; } @@ -1669,7 +1127,7 @@ range: NSMakeRange(0, [ms length])]; range = [string rangeOfString: @"."]; if (range.location == NSNotFound) { - intNum = unum_parseInt64 (_formatter, ustring, length, NULL, &err); + intNum = unum_parseInt64 (this->_formatter, ustring, length, NULL, &err); if (U_FAILURE(err)) return nil; if (intNum == 0 || intNum == 1) @@ -1681,7 +1139,7 @@ range: NSMakeRange(0, [ms length])]; } else { - doubleNum = unum_parseDouble (_formatter, ustring, length, NULL, &err); + doubleNum = unum_parseDouble (this->_formatter, ustring, length, NULL, &err); if (U_FAILURE(err)) return nil; result = [NSNumber numberWithDouble: doubleNum]; @@ -1694,14 +1152,16 @@ range: NSMakeRange(0, [ms length])]; #endif } + + - (void) setFormatterBehavior: (NSNumberFormatterBehavior) behavior { - _behavior = behavior; + this->_behavior = behavior; } - (NSNumberFormatterBehavior) formatterBehavior { - return _behavior; + return this->_behavior; } + (void) setDefaultFormatterBehavior: (NSNumberFormatterBehavior) behavior @@ -1716,18 +1176,18 @@ range: NSMakeRange(0, [ms length])]; - (void) setNumberStyle: (NSNumberFormatterStyle) style { - _style = style; + this->_style = style; [self _resetUNumberFormat]; } - (NSNumberFormatterStyle) numberStyle { - return _style; + return this->_style; } - (void) setGeneratesDecimalNumbers: (BOOL) flag { - _genDecimal = flag; + this->_genDecimal = flag; } - (BOOL) generatesDecimalNubmers @@ -1738,18 +1198,18 @@ range: NSMakeRange(0, [ms length])]; - (void) setLocale: (NSLocale *) locale { - RELEASE(_locale); + RELEASE(this->_locale); if (locale == nil) locale = [NSLocale currentLocale]; - _locale = RETAIN(locale); + this->_locale = RETAIN(locale); [self _resetUNumberFormat]; } - (NSLocale *) locale { - return _locale; + return this->_locale; } @@ -1757,7 +1217,7 @@ range: NSMakeRange(0, [ms length])]; { #if GS_USE_ICU == 1 if ([number class] == [NSDoubleNumber class]) - unum_setDoubleAttribute (_formatter, UNUM_ROUNDING_INCREMENT, + unum_setDoubleAttribute (this->_formatter, UNUM_ROUNDING_INCREMENT, [number doubleValue]); #else return; @@ -1767,7 +1227,7 @@ range: NSMakeRange(0, [ms length])]; - (NSNumber *) roundingIncrement { #if GS_USE_ICU == 1 - double value = unum_getDoubleAttribute (_formatter, UNUM_ROUNDING_INCREMENT); + double value = unum_getDoubleAttribute (this->_formatter, UNUM_ROUNDING_INCREMENT); return [NSNumber numberWithDouble: value]; #else return nil; @@ -1777,7 +1237,7 @@ range: NSMakeRange(0, [ms length])]; - (void) setRoundingMode: (NSNumberFormatterRoundingMode) mode { #if GS_USE_ICU == 1 - unum_setAttribute (_formatter, UNUM_ROUNDING_MODE, + unum_setAttribute (this->_formatter, UNUM_ROUNDING_MODE, _NSToICURoundingMode(mode)); #else return; @@ -1787,7 +1247,7 @@ range: NSMakeRange(0, [ms length])]; - (NSNumberFormatterRoundingMode) roundingMode { #if GS_USE_ICU == 1 - return _ICUToNSRoundingMode (unum_getAttribute (_formatter, + return _ICUToNSRoundingMode (unum_getAttribute (this->_formatter, UNUM_ROUNDING_MODE)); #else return 0; @@ -1798,7 +1258,7 @@ range: NSMakeRange(0, [ms length])]; - (void) setFormatWidth: (NSUInteger) number { #if GS_USE_ICU == 1 - unum_setAttribute (_formatter, UNUM_FORMAT_WIDTH, (int32_t)number); + unum_setAttribute (this->_formatter, UNUM_FORMAT_WIDTH, (int32_t)number); #else return; #endif @@ -1807,7 +1267,7 @@ range: NSMakeRange(0, [ms length])]; - (NSUInteger) formatWidth { #if GS_USE_ICU == 1 - return (NSUInteger)unum_getAttribute (_formatter, UNUM_FORMAT_WIDTH); + return (NSUInteger)unum_getAttribute (this->_formatter, UNUM_FORMAT_WIDTH); #else return 0; #endif @@ -1817,7 +1277,7 @@ range: NSMakeRange(0, [ms length])]; { #if GS_USE_ICU == 1 int32_t value = [number intValue]; - unum_setAttribute (_formatter, UNUM_MULTIPLIER, value); + unum_setAttribute (this->_formatter, UNUM_MULTIPLIER, value); #else return; #endif @@ -1826,7 +1286,7 @@ range: NSMakeRange(0, [ms length])]; - (NSNumber *) multiplier { #if GS_USE_ICU == 1 - int32_t value = unum_getAttribute (_formatter, UNUM_MULTIPLIER); + int32_t value = unum_getAttribute (this->_formatter, UNUM_MULTIPLIER); return [NSNumber numberWithInt: value]; #else return nil; @@ -2210,7 +1670,7 @@ range: NSMakeRange(0, [ms length])]; { #if GS_USE_ICU == 1 - unum_setAttribute (_formatter, UNUM_GROUPING_USED, flag); + unum_setAttribute (this->_formatter, UNUM_GROUPING_USED, flag); #else return; #endif @@ -2219,7 +1679,7 @@ range: NSMakeRange(0, [ms length])]; - (BOOL) usesGroupingSeparator { #if GS_USE_ICU == 1 - return (BOOL)unum_getAttribute (_formatter, UNUM_GROUPING_USED); + return (BOOL)unum_getAttribute (this->_formatter, UNUM_GROUPING_USED); #else return NO; #endif @@ -2228,7 +1688,7 @@ range: NSMakeRange(0, [ms length])]; - (void) setAlwaysShowsDecimalSeparator: (BOOL) flag { #if GS_USE_ICU == 1 - unum_setAttribute (_formatter, UNUM_DECIMAL_ALWAYS_SHOWN, flag); + unum_setAttribute (this->_formatter, UNUM_DECIMAL_ALWAYS_SHOWN, flag); #else return; #endif @@ -2237,7 +1697,7 @@ range: NSMakeRange(0, [ms length])]; - (BOOL) alwaysShowsDecimalSeparator { #if GS_USE_ICU == 1 - return (BOOL)unum_getAttribute (_formatter, UNUM_DECIMAL_ALWAYS_SHOWN); + return (BOOL)unum_getAttribute (this->_formatter, UNUM_DECIMAL_ALWAYS_SHOWN); #else return NO; #endif @@ -2264,7 +1724,7 @@ range: NSMakeRange(0, [ms length])]; - (void) setGroupingSize: (NSUInteger) number { #if GS_USE_ICU == 1 - unum_setAttribute (_formatter, UNUM_GROUPING_SIZE, number); + unum_setAttribute (this->_formatter, UNUM_GROUPING_SIZE, number); #else return; #endif @@ -2273,7 +1733,7 @@ range: NSMakeRange(0, [ms length])]; - (NSUInteger) groupingSize { #if GS_USE_ICU == 1 - return (NSUInteger)unum_getAttribute (_formatter, UNUM_GROUPING_SIZE); + return (NSUInteger)unum_getAttribute (this->_formatter, UNUM_GROUPING_SIZE); #else return 3; #endif @@ -2282,7 +1742,7 @@ range: NSMakeRange(0, [ms length])]; - (void) setSecondaryGroupingSize: (NSUInteger) number { #if GS_USE_ICU == 1 - unum_setAttribute (_formatter, UNUM_SECONDARY_GROUPING_SIZE, number); + unum_setAttribute (this->_formatter, UNUM_SECONDARY_GROUPING_SIZE, number); #else return; #endif @@ -2291,7 +1751,7 @@ range: NSMakeRange(0, [ms length])]; - (NSUInteger) secondaryGroupingSize { #if GS_USE_ICU == 1 - return (NSUInteger)unum_getAttribute (_formatter, + return (NSUInteger)unum_getAttribute (this->_formatter, UNUM_SECONDARY_GROUPING_SIZE); #else return 3; @@ -2320,7 +1780,7 @@ range: NSMakeRange(0, [ms length])]; - (void) setPaddingPosition: (NSNumberFormatterPadPosition) position { #if GS_USE_ICU == 1 - unum_setAttribute (_formatter, UNUM_PADDING_POSITION, + unum_setAttribute (this->_formatter, UNUM_PADDING_POSITION, _NSToICUPadPosition (position)); #else return; @@ -2330,7 +1790,7 @@ range: NSMakeRange(0, [ms length])]; - (NSNumberFormatterPadPosition) paddingPosition { #if GS_USE_ICU == 1 - return _ICUToNSPadPosition(unum_getAttribute (_formatter, + return _ICUToNSPadPosition(unum_getAttribute (this->_formatter, UNUM_PADDING_POSITION)); #else return 0; @@ -2341,7 +1801,7 @@ range: NSMakeRange(0, [ms length])]; - (void) setMinimumIntegerDigits: (NSUInteger) number { #if GS_USE_ICU == 1 - unum_setAttribute (_formatter, UNUM_MIN_INTEGER_DIGITS, number); + unum_setAttribute (this->_formatter, UNUM_MIN_INTEGER_DIGITS, number); #else return; #endif @@ -2350,7 +1810,7 @@ range: NSMakeRange(0, [ms length])]; - (NSUInteger) minimumIntegerDigits { #if GS_USE_ICU == 1 - return (NSUInteger)unum_getAttribute (_formatter, UNUM_MIN_INTEGER_DIGITS); + return (NSUInteger)unum_getAttribute (this->_formatter, UNUM_MIN_INTEGER_DIGITS); #else return 0; #endif @@ -2359,7 +1819,7 @@ range: NSMakeRange(0, [ms length])]; - (void) setMinimumFractionDigits: (NSUInteger) number { #if GS_USE_ICU == 1 - unum_setAttribute (_formatter, UNUM_MIN_FRACTION_DIGITS, number); + unum_setAttribute (this->_formatter, UNUM_MIN_FRACTION_DIGITS, number); #else return; #endif @@ -2368,7 +1828,7 @@ range: NSMakeRange(0, [ms length])]; - (NSUInteger) minimumFractionDigits { #if GS_USE_ICU == 1 - return (NSUInteger)unum_getAttribute (_formatter, UNUM_MIN_FRACTION_DIGITS); + return (NSUInteger)unum_getAttribute (this->_formatter, UNUM_MIN_FRACTION_DIGITS); #else return 0; #endif @@ -2377,7 +1837,7 @@ range: NSMakeRange(0, [ms length])]; - (void) setMaximumIntegerDigits: (NSUInteger) number { #if GS_USE_ICU == 1 - unum_setAttribute (_formatter, UNUM_MAX_INTEGER_DIGITS, number); + unum_setAttribute (this->_formatter, UNUM_MAX_INTEGER_DIGITS, number); #else return; #endif @@ -2386,7 +1846,7 @@ range: NSMakeRange(0, [ms length])]; - (NSUInteger) maximumIntegerDigits { #if GS_USE_ICU == 1 - return (NSUInteger)unum_getAttribute (_formatter, UNUM_MAX_INTEGER_DIGITS); + return (NSUInteger)unum_getAttribute (this->_formatter, UNUM_MAX_INTEGER_DIGITS); #else return 0; #endif @@ -2395,7 +1855,7 @@ range: NSMakeRange(0, [ms length])]; - (void) setMaximumFractionDigits: (NSUInteger) number { #if GS_USE_ICU == 1 - unum_setAttribute (_formatter, UNUM_MAX_FRACTION_DIGITS, number); + unum_setAttribute (this->_formatter, UNUM_MAX_FRACTION_DIGITS, number); #else return; #endif @@ -2404,7 +1864,7 @@ range: NSMakeRange(0, [ms length])]; - (NSUInteger) maximumFractionDigits { #if GS_USE_ICU == 1 - return (NSUInteger)unum_getAttribute (_formatter, UNUM_MAX_FRACTION_DIGITS); + return (NSUInteger)unum_getAttribute (this->_formatter, UNUM_MAX_FRACTION_DIGITS); #else return 0; #endif @@ -2423,7 +1883,7 @@ range: NSMakeRange(0, [ms length])]; - (void) setUsesSignificantDigits: (BOOL) flag { #if GS_USE_ICU == 1 - unum_setAttribute (_formatter, UNUM_SIGNIFICANT_DIGITS_USED, flag); + unum_setAttribute (this->_formatter, UNUM_SIGNIFICANT_DIGITS_USED, flag); #else return; #endif @@ -2432,7 +1892,7 @@ range: NSMakeRange(0, [ms length])]; - (BOOL) usesSignificantDigits { #if GS_USE_ICU == 1 - return (BOOL)unum_getAttribute (_formatter, UNUM_SIGNIFICANT_DIGITS_USED); + return (BOOL)unum_getAttribute (this->_formatter, UNUM_SIGNIFICANT_DIGITS_USED); #else return NO; #endif @@ -2441,7 +1901,7 @@ range: NSMakeRange(0, [ms length])]; - (void) setMinimumSignificantDigits: (NSUInteger) number { #if GS_USE_ICU == 1 - unum_setAttribute (_formatter, UNUM_MIN_SIGNIFICANT_DIGITS, number); + unum_setAttribute (this->_formatter, UNUM_MIN_SIGNIFICANT_DIGITS, number); #else return; #endif @@ -2450,7 +1910,7 @@ range: NSMakeRange(0, [ms length])]; - (NSUInteger) minimumSignificantDigits { #if GS_USE_ICU == 1 - return (BOOL)unum_getAttribute (_formatter, UNUM_MIN_SIGNIFICANT_DIGITS); + return (BOOL)unum_getAttribute (this->_formatter, UNUM_MIN_SIGNIFICANT_DIGITS); #else return 0; #endif @@ -2459,7 +1919,7 @@ range: NSMakeRange(0, [ms length])]; - (void) setMaximumSignificantDigits: (NSUInteger) number { #if GS_USE_ICU == 1 - unum_setAttribute (_formatter, UNUM_MAX_SIGNIFICANT_DIGITS, number); + unum_setAttribute (this->_formatter, UNUM_MAX_SIGNIFICANT_DIGITS, number); #else return; #endif @@ -2468,7 +1928,7 @@ range: NSMakeRange(0, [ms length])]; - (NSUInteger) maximumSignificantDigits { #if GS_USE_ICU == 1 - return (BOOL)unum_getAttribute (_formatter, UNUM_MAX_SIGNIFICANT_DIGITS); + return (BOOL)unum_getAttribute (this->_formatter, UNUM_MAX_SIGNIFICANT_DIGITS); #else return 0; #endif @@ -2497,7 +1957,7 @@ range: NSMakeRange(0, [ms length])]; - (void) setLenient: (BOOL) flag { #if GS_USE_ICU == 1 - unum_setAttribute (_formatter, UNUM_LENIENT_PARSE, flag); + unum_setAttribute (this->_formatter, UNUM_LENIENT_PARSE, flag); #else return; #endif @@ -2506,7 +1966,7 @@ range: NSMakeRange(0, [ms length])]; - (BOOL) isLenient { #if GS_USE_ICU == 1 - return (BOOL)unum_getAttribute (_formatter, UNUM_LENIENT_PARSE); + return (BOOL)unum_getAttribute (this->_formatter, UNUM_LENIENT_PARSE); #else return NO; #endif @@ -2542,9 +2002,10 @@ range: NSMakeRange(0, [ms length])]; return nil; #endif } + @end -@implementation NSNumberFormatter10_4 (PrivateMethods) +@implementation NSNumberFormatter (PrivateMethods) - (void) _resetUNumberFormat { #if GS_USE_ICU == 1 @@ -2552,15 +2013,15 @@ range: NSMakeRange(0, [ms length])]; UErrorCode err = U_ZERO_ERROR; const char *cLocaleId; - if (_formatter) - unum_close(_formatter); + if (this->_formatter) + unum_close(this->_formatter); - cLocaleId = [[_locale localeIdentifier] UTF8String]; - style = _NSToICUFormatStyle (_style); + cLocaleId = [[this->_locale localeIdentifier] UTF8String]; + style = _NSToICUFormatStyle (this->_style); - _formatter = unum_open (style, NULL, 0, cLocaleId, NULL, &err); + this->_formatter = unum_open (style, NULL, 0, cLocaleId, NULL, &err); if (U_FAILURE(err)) - _formatter = NULL; + this->_formatter = NULL; [self setMaximumFractionDigits: 0]; #else @@ -2581,7 +2042,7 @@ range: NSMakeRange(0, [ms length])]; str = (unichar *)NSZoneMalloc ([self zone], length * sizeof(unichar)); [string getCharacters: str range: NSMakeRange (0, length)]; - unum_setSymbol (_formatter, symbol, str, length, &err); + unum_setSymbol (this->_formatter, symbol, str, length, &err); if (length > MAX_SYMBOL_SIZE) NSZoneFree ([self zone], str); @@ -2599,12 +2060,12 @@ range: NSMakeRange(0, [ms length])]; UErrorCode err = U_ZERO_ERROR; NSString *result; - length = unum_getSymbol (_formatter, symbol, str, + length = unum_getSymbol (this->_formatter, symbol, str, MAX_SYMBOL_SIZE, &err); if (length > MAX_SYMBOL_SIZE) { str = (UChar *)NSZoneMalloc ([self zone], length * sizeof(UChar)); - length = unum_getSymbol (_formatter, symbol, str, + length = unum_getSymbol (this->_formatter, symbol, str, length, &err); } @@ -2631,7 +2092,7 @@ range: NSMakeRange(0, [ms length])]; str = (unichar *)NSZoneMalloc ([self zone], length * sizeof(unichar)); [string getCharacters: str range: NSMakeRange (0, length)]; - unum_setTextAttribute (_formatter, attrib, str, length, &err); + unum_setTextAttribute (this->_formatter, attrib, str, length, &err); if (length > MAX_TEXT_ATTRIB_SIZE) NSZoneFree ([self zone], str); @@ -2649,12 +2110,12 @@ range: NSMakeRange(0, [ms length])]; UErrorCode err = U_ZERO_ERROR; NSString *result; - length = unum_getTextAttribute (_formatter, attrib, str, + length = unum_getTextAttribute (this->_formatter, attrib, str, MAX_TEXT_ATTRIB_SIZE, &err); if (length > MAX_TEXT_ATTRIB_SIZE) { str = (UChar *)NSZoneMalloc ([self zone], length * sizeof(UChar)); - length = unum_getTextAttribute (_formatter, attrib, str, + length = unum_getTextAttribute (this->_formatter, attrib, str, length, &err); } @@ -2667,13 +2128,4 @@ range: NSMakeRange(0, [ms length])]; return nil; #endif } - -- (void) dealloc -{ - RELEASE(_locale); -#if GS_USE_ICU == 1 - unum_close (_formatter); -#endif - [super dealloc]; -} @end