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;
52 NSLog(@"WARNING(%s): called deprecated -isNull on NSNull (use -isNotNull) !",
54 if (doAbort()) abort();
59 - (NSString *)stringValue {
61 NSLog(@"WARNING(%s): "
62 @"NSNull -stringValue returns empty string.",
64 if (doAbort()) abort();
68 - (double)doubleValue {
70 NSLog(@"WARNING(%s): "
71 @"NSNull -doubleValue returns 0.0.",
73 if (doAbort()) abort();
78 - (unsigned int)length {
80 NSLog(@"WARNING(%s): "
81 @"called NSNull -length (returns 0) !!!",
83 if (doAbort()) abort();
87 - (unsigned int)count {
89 NSLog(@"WARNING(%s): "
90 @"called NSNull -count (returns 0) !!!",
92 if (doAbort()) abort();
97 - (BOOL)isEqualToString:(NSString *)_s {
98 /* Note: I think we can keep this as a regular method */
99 return _s == (id)self || _s == nil ? YES : NO;
101 - (BOOL)hasPrefix:(NSString *)_s {
102 /* Note: I think we can keep this as a regular method */
103 return _s == (id)self || _s == nil ? YES : NO;
105 - (BOOL)hasSuffix:(NSString *)_s {
106 /* Note: I think we can keep this as a regular method */
107 return _s == (id)self || _s == nil ? YES : NO;
110 - (unichar)characterAtIndex:(unsigned int)_idx {
112 NSLog(@"WARNING(%s): "
113 @"called NSNull -characterAtIndex:%d - returning 0!",
114 __PRETTY_FUNCTION__, _idx);
115 if (doAbort()) abort();
120 /* key-value coding */
122 - (void)takeValue:(id)_value forKey:(NSString *)_key {
125 - (id)valueForKey:(NSString *)_key {
126 if ([_key isEqualToString:@"isNotNull"]) {
127 static NSNumber *noNum = nil;
130 noNum = [NSNumber numberWithBool:NO];
134 if ([_key isEqualToString:@"isNull"]) {
135 static NSNumber *yesNum = nil;
138 yesNum = [NSNumber numberWithBool:YES];
149 - (BOOL)respondsToSelector:(SEL)_sel {
150 /* fake that we have a selector */
154 - (NSString *)descriptionWithLocale:(id)_locale indent:(int)_indent {
157 - (NSString *)descriptionWithLocale:(id)_locale {
163 - (void)forwardInvocation:(NSInvocation *)_invocation {
164 NSMethodSignature *sig;
166 NSLog(@"ERROR(%s): called selector %@ on NSNull !",
168 NSStringFromSelector([_invocation selector]));
169 if (doAbort()) abort();
171 if ((sig = [_invocation methodSignature])) {
174 if ((ret = [sig methodReturnType])) {
178 [_invocation setReturnValue:&v];
183 [_invocation setReturnValue:&v];
190 [_invocation setReturnValue:&v];
195 NSLog(@" didn't set return value for type '%s'", ret);
200 NSLog(@" no method return type in signature %@", sig);
203 NSLog(@" no method signature in invocation %@", _invocation);
206 @end /* NSNull(misc) */
208 @implementation NSObject(NSNullMisc)
216 NSLog(@"%s: WARNING, called -isNull on NSObject (use -isNotNull) !",
217 __PRETTY_FUNCTION__);
222 @end /* NSObject(NSNullMisc) */