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
22 #include "NSObject+Values.h"
25 @implementation NSObject(NGValues)
28 // this returns always YES (the id != nil)
33 return (char)[self intValue];
35 - (unsigned char)unsignedCharValue {
36 return (unsigned char)[self intValue];
39 return (short)[self intValue];
41 - (unsigned short)unsignedShortValue {
42 return (unsigned short)[self unsignedIntValue];
46 return [[self stringValue] intValue];
48 - (unsigned int)unsignedIntValue {
49 return (unsigned int)[self intValue];
53 return (long)[self intValue];
55 - (unsigned long)unsignedLongValue {
56 return (unsigned long)[self unsignedIntValue];
59 - (long long)longLongValue {
60 return [[self stringValue] longLongValue];
62 - (unsigned long long)unsignedLongLongValue {
63 return [[self stringValue] unsignedLongLongValue];
67 return [[self stringValue] floatValue];
69 - (double)doubleValue {
70 return [[self stringValue] doubleValue];
73 - (NSString *)stringValue {
74 return [self description];
77 @end /* NSObject(Values) */
79 @implementation NSString(NGValues)
85 if ((len = [self length]) == 0)
90 c1 = [self characterAtIndex:0];
91 if (c1 == '1') return YES;
95 // NO, no (this is false in any case ;-)
99 c1 = [self characterAtIndex:0];
100 if (c1 != 'Y' && c1 != 'y')
103 if ([@"YES" isEqualToString:self]) return YES;
104 if ([@"yes" isEqualToString:self]) return YES;
108 c1 = [self characterAtIndex:0];
109 if (c1 != 'T' && c1 != 't')
112 if ([@"TRUE" isEqualToString:self]) return YES;
113 if ([@"true" isEqualToString:self]) return YES;
117 // FALSE, false (this is false in any case ;-)
124 - (NSString *)stringValue {
128 - (unsigned char)unsignedCharValue {
130 Note: this is a hack to support bool values with KVC operations. Problem
131 is, that bools in Objective-C have no own type code and the runtime
132 will use uchar to represent a bool.
134 Note: there are platforms where int as used as the BOOL base type?
136 register unsigned len;
139 if ((len = [self length]) == 0)
142 c1 = [self characterAtIndex:0];
146 // NO, no (this is false in any case ;-)
149 c1 = [self characterAtIndex:0];
150 if (c1 != 'Y' && c1 != 'y')
153 if ([@"YES" isEqualToString:self]) return YES;
154 if ([@"yes" isEqualToString:self]) return YES;
157 c1 = [self characterAtIndex:0];
158 if (c1 != 'T' && c1 != 't')
161 if ([@"TRUE" isEqualToString:self]) return YES;
162 if ([@"true" isEqualToString:self]) return YES;
167 return [self intValue];
170 @end /* NSString(Values) */
172 @implementation NSMutableString(NGValues)
174 - (NSString *)stringValue {
175 return [[self copy] autorelease];
178 @end /* NSMutableString(Values) */
180 void __link_NGExtensions_NSObjectValues(void) {
181 /* required for static linking */
182 __link_NGExtensions_NSObjectValues();