2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "NSNull+misc.h"
25 #if LIB_FOUNDATION_LIBRARY || GNUSTEP_BASE_LIBRARY
26 # include <objc/objc-api.h>
27 # include <objc/objc.h>
28 # include <objc/encoding.h>
30 # import <extensions/objc-runtime.h>
33 # import <objc/objc-class.h>
36 @implementation NSNull(misc)
38 static int _doAbort = -1;
39 static inline BOOL doAbort(void) {
41 _doAbort = [[NSUserDefaults standardUserDefaults]
42 boolForKey:@"NSNullAbortOnMessage"] ? 1 : 0;
44 return _doAbort ? YES : NO;
55 NSLog(@"WARNING(%s): called deprecated -isNull on NSNull (use -isNotNull) !",
57 if (doAbort()) abort();
62 - (NSString *)stringValue {
64 NSLog(@"WARNING(%s): "
65 @"NSNull -stringValue returns empty string.",
67 if (doAbort()) abort();
71 - (double)doubleValue {
73 NSLog(@"WARNING(%s): "
74 @"NSNull -doubleValue returns 0.0.",
76 if (doAbort()) abort();
81 - (unsigned int)length {
83 NSLog(@"WARNING(%s): "
84 @"called NSNull -length (returns 0) !!!",
86 if (doAbort()) abort();
90 - (unsigned int)count {
92 NSLog(@"WARNING(%s): "
93 @"called NSNull -count (returns 0) !!!",
95 if (doAbort()) abort();
100 - (BOOL)isEqualToString:(NSString *)_s {
101 /* Note: I think we can keep this as a regular method */
102 return _s == (id)self || _s == nil ? YES : NO;
104 - (BOOL)hasPrefix:(NSString *)_s {
105 /* Note: I think we can keep this as a regular method */
106 return _s == (id)self || _s == nil ? YES : NO;
108 - (BOOL)hasSuffix:(NSString *)_s {
109 /* Note: I think we can keep this as a regular method */
110 return _s == (id)self || _s == nil ? YES : NO;
113 - (unichar)characterAtIndex:(unsigned int)_idx {
115 NSLog(@"WARNING(%s): "
116 @"called NSNull -characterAtIndex:%d - returning 0!",
117 __PRETTY_FUNCTION__, _idx);
118 if (doAbort()) abort();
123 /* key-value coding */
125 - (void)takeValue:(id)_value forKey:(NSString *)_key {
128 - (id)valueForKey:(NSString *)_key {
129 if ([_key isEqualToString:@"isNotNull"]) {
130 static NSNumber *noNum = nil;
133 noNum = [NSNumber numberWithBool:NO];
137 if ([_key isEqualToString:@"isNull"]) {
138 static NSNumber *yesNum = nil;
141 yesNum = [NSNumber numberWithBool:YES];
152 - (BOOL)respondsToSelector:(SEL)_sel {
153 /* fake that we have a selector */
157 - (NSString *)descriptionWithLocale:(id)_locale indent:(int)_indent {
160 - (NSString *)descriptionWithLocale:(id)_locale {
166 - (void)forwardInvocation:(NSInvocation *)_invocation {
167 NSMethodSignature *sig;
169 NSLog(@"ERROR(%s): called selector %@ on NSNull !",
171 NSStringFromSelector([_invocation selector]));
172 if (doAbort()) abort();
174 if ((sig = [_invocation methodSignature])) {
177 if ((ret = [sig methodReturnType])) {
181 [_invocation setReturnValue:&v];
186 [_invocation setReturnValue:&v];
193 [_invocation setReturnValue:&v];
198 NSLog(@" didn't set return value for type '%s'", ret);
203 NSLog(@" no method return type in signature %@", sig);
206 NSLog(@" no method signature in invocation %@", _invocation);
209 @end /* NSNull(misc) */
212 @implementation NSObject(NSNullMisc)
218 return [self isNotNull];
223 NSLog(@"%s: WARNING, called -isNull on NSObject (use -isNotNull) !",
224 __PRETTY_FUNCTION__);
229 @end /* NSObject(NSNullMisc) */
232 @implementation NSString(NSNullMisc)
237 if ((len = [self length]) == 0)
240 for (i = 0; i < len; i++) {
241 if (!isspace([self characterAtIndex:i]))
248 @end /* NSString(NSNullMisc) */
250 @implementation NSArray(NSNullMisc)
253 return [self count] == 0 ? YES : NO;
256 @end /* NSArray(NSNullMisc) */
258 @implementation NSDictionary(NSNullMisc)
261 return [self count] == 0 ? YES : NO;
264 @end /* NSDictionary(NSNullMisc) */