2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo 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 OGo 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 OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include "NSObject+Values.h"
26 @implementation NSObject(NGValues)
29 // this returns always YES (the id != nil)
34 return (char)[self intValue];
36 - (unsigned char)unsignedCharValue {
37 return (unsigned char)[self intValue];
40 return (short)[self intValue];
42 - (unsigned short)unsignedShortValue {
43 return (unsigned short)[self unsignedIntValue];
47 return [[self stringValue] intValue];
49 - (unsigned int)unsignedIntValue {
50 return (unsigned int)[self intValue];
54 return (long)[self intValue];
56 - (unsigned long)unsignedLongValue {
57 return (unsigned long)[self unsignedIntValue];
60 - (long long)longLongValue {
61 return [[self stringValue] longLongValue];
63 - (unsigned long long)unsignedLongLongValue {
64 return [[self stringValue] unsignedLongLongValue];
68 return [[self stringValue] floatValue];
70 - (double)doubleValue {
71 return [[self stringValue] doubleValue];
74 - (NSString *)stringValue {
75 return [self description];
78 @end /* NSObject(Values) */
80 @implementation NSString(NGValues)
86 if ((len = [self length]) == 0)
91 c1 = [self characterAtIndex:0];
92 if (c1 == '1') return YES;
96 // NO, no (this is false in any case ;-)
100 c1 = [self characterAtIndex:0];
101 if (c1 != 'Y' && c1 != 'y')
104 if ([@"YES" isEqualToString:self]) return YES;
105 if ([@"yes" isEqualToString:self]) return YES;
109 c1 = [self characterAtIndex:0];
110 if (c1 != 'T' && c1 != 't')
113 if ([@"TRUE" isEqualToString:self]) return YES;
114 if ([@"true" isEqualToString:self]) return YES;
118 // FALSE, false (this is false in any case ;-)
125 - (NSString *)stringValue {
129 - (unsigned char)unsignedCharValue {
131 Note: this is a hack to support bool values with KVC operations. Problem
132 is, that bools in Objective-C have no own type code and the runtime
133 will use uchar to represent a bool.
135 Note: there are platforms where int as used as the BOOL base type?
137 register unsigned len;
140 if ((len = [self length]) == 0)
143 c1 = [self characterAtIndex:0];
147 // NO, no (this is false in any case ;-)
150 c1 = [self characterAtIndex:0];
151 if (c1 != 'Y' && c1 != 'y')
154 if ([@"YES" isEqualToString:self]) return YES;
155 if ([@"yes" isEqualToString:self]) return YES;
158 c1 = [self characterAtIndex:0];
159 if (c1 != 'T' && c1 != 't')
162 if ([@"TRUE" isEqualToString:self]) return YES;
163 if ([@"true" isEqualToString:self]) return YES;
168 return [self intValue];
171 @end /* NSString(Values) */
173 @implementation NSMutableString(NGValues)
175 - (NSString *)stringValue {
176 return [[self copy] autorelease];
179 @end /* NSMutableString(Values) */
181 void __link_NGExtensions_NSObjectValues(void) {
182 /* required for static linking */
183 __link_NGExtensions_NSObjectValues();