OLD | NEW |
1 //------------------------------------------------------------------------------
--------- | 1 /* |
2 // $Id$ | 2 * Copyright (c) 2006-2015 Erik Doernenburg and contributors |
3 // Copyright (c) 2006-2009 by Mulle Kybernetik. See License file for details. | 3 * |
4 //------------------------------------------------------------------------------
--------- | 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 * not use these files except in compliance with the License. You may obtain |
| 6 * a copy of the License at |
| 7 * |
| 8 * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 * |
| 10 * Unless required by applicable law or agreed to in writing, software |
| 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 * License for the specific language governing permissions and limitations |
| 14 * under the License. |
| 15 */ |
5 | 16 |
6 #import "NSInvocation+OCMAdditions.h" | 17 #import "NSInvocation+OCMAdditions.h" |
| 18 #import "OCMFunctions.h" |
7 | 19 |
8 | 20 |
9 @implementation NSInvocation(OCMAdditions) | 21 @implementation NSInvocation(OCMAdditions) |
10 | 22 |
11 - (id)getArgumentAtIndexAsObject:(int)argIndex | 23 - (BOOL)hasCharPointerArgument |
12 { | 24 { |
13 » const char* argType; | 25 NSMethodSignature *signature = [self methodSignature]; |
14 » | 26 for(NSUInteger i = 0; i < [signature numberOfArguments]; i++) |
15 » argType = [[self methodSignature] getArgumentTypeAtIndex:argIndex]; | 27 { |
16 » while(strchr("rnNoORV", argType[0]) != NULL) | 28 const char *argType = OCMTypeWithoutQualifiers([signature getArgumentTyp
eAtIndex:i]); |
17 » » argType += 1; | 29 if(strcmp(argType, "*") == 0) |
18 » | 30 return YES; |
| 31 } |
| 32 return NO; |
| 33 } |
| 34 |
| 35 |
| 36 - (id)getArgumentAtIndexAsObject:(NSInteger)argIndex |
| 37 { |
| 38 » const char *argType = OCMTypeWithoutQualifiers([[self methodSignature] g
etArgumentTypeAtIndex:(NSUInteger)argIndex]); |
| 39 |
19 if((strlen(argType) > 1) && (strchr("{^", argType[0]) == NULL) && (strcm
p("@?", argType) != 0)) | 40 if((strlen(argType) > 1) && (strchr("{^", argType[0]) == NULL) && (strcm
p("@?", argType) != 0)) |
20 [NSException raise:NSInvalidArgumentException format:@"Cannot ha
ndle argument type '%s'.", argType]; | 41 [NSException raise:NSInvalidArgumentException format:@"Cannot ha
ndle argument type '%s'.", argType]; |
21 » | 42 |
22 » switch (argType[0]) | 43 if(OCMIsObjectType(argType)) |
| 44 { |
| 45 id value; |
| 46 » [self getArgument:&value atIndex:argIndex]; |
| 47 » return value; |
| 48 } |
| 49 |
| 50 » switch(argType[0]) |
23 { | 51 { |
24 case '#': | |
25 case '@': | |
26 { | |
27 id value; | |
28 [self getArgument:&value atIndex:argIndex]; | |
29 return value; | |
30 } | |
31 case ':': | 52 case ':': |
32 { | 53 { |
33 SEL s = (SEL)0; | 54 SEL s = (SEL)0; |
34 [self getArgument:&s atIndex:argIndex]; | 55 [self getArgument:&s atIndex:argIndex]; |
35 » » » id value = NSStringFromSelector(s); | 56 return [NSValue valueWithBytes:&s objCType:":"]; |
36 » » » return value; | |
37 } | 57 } |
38 case 'i': | 58 case 'i': |
39 { | 59 { |
40 int value; | 60 int value; |
41 [self getArgument:&value atIndex:argIndex]; | 61 [self getArgument:&value atIndex:argIndex]; |
42 » » » return [NSNumber numberWithInt:value]; | 62 » » » return @(value); |
43 } | 63 } |
44 case 's': | 64 case 's': |
45 { | 65 { |
46 short value; | 66 short value; |
47 [self getArgument:&value atIndex:argIndex]; | 67 [self getArgument:&value atIndex:argIndex]; |
48 » » » return [NSNumber numberWithShort:value]; | 68 » » » return @(value); |
49 } | 69 } |
50 case 'l': | 70 case 'l': |
51 { | 71 { |
52 long value; | 72 long value; |
53 [self getArgument:&value atIndex:argIndex]; | 73 [self getArgument:&value atIndex:argIndex]; |
54 » » » return [NSNumber numberWithLong:value]; | 74 » » » return @(value); |
55 } | 75 } |
56 case 'q': | 76 case 'q': |
57 { | 77 { |
58 long long value; | 78 long long value; |
59 [self getArgument:&value atIndex:argIndex]; | 79 [self getArgument:&value atIndex:argIndex]; |
60 » » » return [NSNumber numberWithLongLong:value]; | 80 » » » return @(value); |
61 } | 81 } |
62 case 'c': | 82 case 'c': |
63 { | 83 { |
64 char value; | 84 char value; |
65 [self getArgument:&value atIndex:argIndex]; | 85 [self getArgument:&value atIndex:argIndex]; |
66 » » » return [NSNumber numberWithChar:value]; | 86 » » » return @(value); |
67 } | 87 } |
68 case 'C': | 88 case 'C': |
69 { | 89 { |
70 unsigned char value; | 90 unsigned char value; |
71 [self getArgument:&value atIndex:argIndex]; | 91 [self getArgument:&value atIndex:argIndex]; |
72 » » » return [NSNumber numberWithUnsignedChar:value]; | 92 » » » return @(value); |
73 } | 93 } |
74 case 'I': | 94 case 'I': |
75 { | 95 { |
76 unsigned int value; | 96 unsigned int value; |
77 [self getArgument:&value atIndex:argIndex]; | 97 [self getArgument:&value atIndex:argIndex]; |
78 » » » return [NSNumber numberWithUnsignedInt:value]; | 98 » » » return @(value); |
79 } | 99 } |
80 case 'S': | 100 case 'S': |
81 { | 101 { |
82 unsigned short value; | 102 unsigned short value; |
83 [self getArgument:&value atIndex:argIndex]; | 103 [self getArgument:&value atIndex:argIndex]; |
84 » » » return [NSNumber numberWithUnsignedShort:value]; | 104 » » » return @(value); |
85 } | 105 } |
86 case 'L': | 106 case 'L': |
87 { | 107 { |
88 unsigned long value; | 108 unsigned long value; |
89 [self getArgument:&value atIndex:argIndex]; | 109 [self getArgument:&value atIndex:argIndex]; |
90 » » » return [NSNumber numberWithUnsignedLong:value]; | 110 » » » return @(value); |
91 } | 111 } |
92 case 'Q': | 112 case 'Q': |
93 { | 113 { |
94 unsigned long long value; | 114 unsigned long long value; |
95 [self getArgument:&value atIndex:argIndex]; | 115 [self getArgument:&value atIndex:argIndex]; |
96 » » » return [NSNumber numberWithUnsignedLongLong:value]; | 116 » » » return @(value); |
97 } | 117 } |
98 case 'f': | 118 case 'f': |
99 { | 119 { |
100 float value; | 120 float value; |
101 [self getArgument:&value atIndex:argIndex]; | 121 [self getArgument:&value atIndex:argIndex]; |
102 » » » return [NSNumber numberWithFloat:value]; | 122 » » » return @(value); |
103 } | 123 } |
104 case 'd': | 124 case 'd': |
105 { | 125 { |
106 double value; | 126 double value; |
107 [self getArgument:&value atIndex:argIndex]; | 127 [self getArgument:&value atIndex:argIndex]; |
108 » » » return [NSNumber numberWithDouble:value]; | 128 » » » return @(value); |
109 } | 129 } |
| 130 case 'D': |
| 131 { |
| 132 long double value; |
| 133 [self getArgument:&value atIndex:argIndex]; |
| 134 return [NSValue valueWithBytes:&value objCType:@encode(_
_typeof__(value))]; |
| 135 } |
110 case 'B': | 136 case 'B': |
111 { | 137 { |
112 bool value; | 138 bool value; |
113 [self getArgument:&value atIndex:argIndex]; | 139 [self getArgument:&value atIndex:argIndex]; |
114 » » » return [NSNumber numberWithBool:value]; | 140 » » » return @(value); |
115 } | 141 } |
116 case '^': | 142 case '^': |
| 143 case '*': |
117 { | 144 { |
118 void *value = NULL; | 145 void *value = NULL; |
119 [self getArgument:&value atIndex:argIndex]; | 146 [self getArgument:&value atIndex:argIndex]; |
120 return [NSValue valueWithPointer:value]; | 147 return [NSValue valueWithPointer:value]; |
121 } | 148 } |
122 case '{': // structure | 149 case '{': // structure |
123 { | 150 { |
124 » » » NSUInteger maxArgSize = [[self methodSignature] frameLen
gth]; | 151 » » » NSUInteger argSize; |
125 » » » NSMutableData *argumentData = [[[NSMutableData alloc] in
itWithLength:maxArgSize] autorelease]; | 152 » » » NSGetSizeAndAlignment([[self methodSignature] getArgumen
tTypeAtIndex:(NSUInteger)argIndex], &argSize, NULL); |
| 153 » » » if(argSize == 0) // TODO: Can this happen? Is frameLengt
h a good choice in that case? |
| 154 argSize = [[self methodSignature] frameLength]; |
| 155 » » » NSMutableData *argumentData = [[[NSMutableData alloc] in
itWithLength:argSize] autorelease]; |
126 [self getArgument:[argumentData mutableBytes] atIndex:ar
gIndex]; | 156 [self getArgument:[argumentData mutableBytes] atIndex:ar
gIndex]; |
127 return [NSValue valueWithBytes:[argumentData bytes] objC
Type:argType]; | 157 return [NSValue valueWithBytes:[argumentData bytes] objC
Type:argType]; |
128 } | 158 } |
129 | 159 |
130 } | 160 } |
131 [NSException raise:NSInvalidArgumentException format:@"Argument type '%s
' not supported", argType]; | 161 [NSException raise:NSInvalidArgumentException format:@"Argument type '%s
' not supported", argType]; |
132 return nil; | 162 return nil; |
133 } | 163 } |
134 | 164 |
135 - (NSString *)invocationDescription | 165 - (NSString *)invocationDescription |
136 { | 166 { |
137 NSMethodSignature *methodSignature = [self methodSignature]; | 167 NSMethodSignature *methodSignature = [self methodSignature]; |
138 NSUInteger numberOfArgs = [methodSignature numberOfArguments]; | 168 NSUInteger numberOfArgs = [methodSignature numberOfArguments]; |
139 | 169 |
140 if (numberOfArgs == 2) | 170 if (numberOfArgs == 2) |
141 return NSStringFromSelector([self selector]); | 171 return NSStringFromSelector([self selector]); |
142 | 172 |
143 NSArray *selectorParts = [NSStringFromSelector([self selector]) componen
tsSeparatedByString:@":"]; | 173 NSArray *selectorParts = [NSStringFromSelector([self selector]) componen
tsSeparatedByString:@":"]; |
144 NSMutableString *description = [[NSMutableString alloc] init]; | 174 NSMutableString *description = [[NSMutableString alloc] init]; |
145 » unsigned int i; | 175 » NSUInteger i; |
146 for(i = 2; i < numberOfArgs; i++) | 176 for(i = 2; i < numberOfArgs; i++) |
147 { | 177 { |
148 [description appendFormat:@"%@%@:", (i > 2 ? @" " : @""), [selec
torParts objectAtIndex:(i - 2)]]; | 178 [description appendFormat:@"%@%@:", (i > 2 ? @" " : @""), [selec
torParts objectAtIndex:(i - 2)]]; |
149 » » [description appendString:[self argumentDescriptionAtIndex:i]]; | 179 » » [description appendString:[self argumentDescriptionAtIndex:(NSIn
teger)i]]; |
150 } | 180 } |
151 | 181 |
152 return [description autorelease]; | 182 return [description autorelease]; |
153 } | 183 } |
154 | 184 |
155 - (NSString *)argumentDescriptionAtIndex:(int)argIndex | 185 - (NSString *)argumentDescriptionAtIndex:(NSInteger)argIndex |
156 { | 186 { |
157 » const char *argType = [[self methodSignature] getArgumentTypeAtIndex:arg
Index]; | 187 » const char *argType = OCMTypeWithoutQualifiers([[self methodSignature] g
etArgumentTypeAtIndex:(NSUInteger)argIndex]); |
158 » if(strchr("rnNoORV", argType[0]) != NULL) | |
159 » » argType += 1; | |
160 | 188 |
161 switch(*argType) | 189 switch(*argType) |
162 { | 190 { |
163 case '@': return [self objectDescriptionAtIndex:argIndex]; | 191 case '@': return [self objectDescriptionAtIndex:argIndex]; |
164 case 'B': return [self boolDescriptionAtIndex:argIndex]; | 192 case 'B': return [self boolDescriptionAtIndex:argIndex]; |
165 case 'c': return [self charDescriptionAtIndex:argIndex]; | 193 case 'c': return [self charDescriptionAtIndex:argIndex]; |
166 case 'C': return [self unsignedCharDescriptionAtIndex:argI
ndex]; | 194 case 'C': return [self unsignedCharDescriptionAtIndex:argI
ndex]; |
167 case 'i': return [self intDescriptionAtIndex:argIndex]; | 195 case 'i': return [self intDescriptionAtIndex:argIndex]; |
168 case 'I': return [self unsignedIntDescriptionAtIndex:argIn
dex]; | 196 case 'I': return [self unsignedIntDescriptionAtIndex:argIn
dex]; |
169 case 's': return [self shortDescriptionAtIndex:argIndex]; | 197 case 's': return [self shortDescriptionAtIndex:argIndex]; |
170 case 'S': return [self unsignedShortDescriptionAtIndex:arg
Index]; | 198 case 'S': return [self unsignedShortDescriptionAtIndex:arg
Index]; |
171 case 'l': return [self longDescriptionAtIndex:argIndex]; | 199 case 'l': return [self longDescriptionAtIndex:argIndex]; |
172 case 'L': return [self unsignedLongDescriptionAtIndex:argI
ndex]; | 200 case 'L': return [self unsignedLongDescriptionAtIndex:argI
ndex]; |
173 case 'q': return [self longLongDescriptionAtIndex:argIndex
]; | 201 case 'q': return [self longLongDescriptionAtIndex:argIndex
]; |
174 case 'Q': return [self unsignedLongLongDescriptionAtIndex:
argIndex]; | 202 case 'Q': return [self unsignedLongLongDescriptionAtIndex:
argIndex]; |
175 case 'd': return [self doubleDescriptionAtIndex:argIndex]; | 203 case 'd': return [self doubleDescriptionAtIndex:argIndex]; |
176 case 'f': return [self floatDescriptionAtIndex:argIndex]; | 204 case 'f': return [self floatDescriptionAtIndex:argIndex]; |
177 » » // Why does this throw EXC_BAD_ACCESS when appending the string? | 205 » » case 'D':» return [self longDoubleDescriptionAtIndex:argInd
ex]; |
178 » » //» case NSObjCStructType: return [self structDescriptionAtI
ndex:index]; | 206 » » case '{':» return [self structDescriptionAtIndex:argIndex]; |
179 case '^': return [self pointerDescriptionAtIndex:argIndex]
; | 207 case '^': return [self pointerDescriptionAtIndex:argIndex]
; |
180 case '*': return [self cStringDescriptionAtIndex:argIndex]
; | 208 case '*': return [self cStringDescriptionAtIndex:argIndex]
; |
181 case ':': return [self selectorDescriptionAtIndex:argIndex
]; | 209 case ':': return [self selectorDescriptionAtIndex:argIndex
]; |
182 default: return [@"<??" stringByAppendingString:@">"]; /
/ avoid confusion with trigraphs... | 210 default: return [@"<??" stringByAppendingString:@">"]; /
/ avoid confusion with trigraphs... |
183 } | 211 } |
184 | 212 |
185 } | 213 } |
186 | 214 |
187 | 215 |
188 - (NSString *)objectDescriptionAtIndex:(int)anInt | 216 - (NSString *)objectDescriptionAtIndex:(NSInteger)anInt |
189 { | 217 { |
190 id object; | 218 id object; |
191 | 219 |
192 [self getArgument:&object atIndex:anInt]; | 220 [self getArgument:&object atIndex:anInt]; |
193 if (object == nil) | 221 if (object == nil) |
194 return @"nil"; | 222 return @"nil"; |
195 else if(![object isProxy] && [object isKindOfClass:[NSString class]]) | 223 else if(![object isProxy] && [object isKindOfClass:[NSString class]]) |
196 return [NSString stringWithFormat:@"@\"%@\"", [object descriptio
n]]; | 224 return [NSString stringWithFormat:@"@\"%@\"", [object descriptio
n]]; |
197 else | 225 else |
198 » » return [object description]; | 226 » » // The description cannot be nil, if it is then replace it |
| 227 » » return [object description] ?: @"<nil description>"; |
199 } | 228 } |
200 | 229 |
201 - (NSString *)boolDescriptionAtIndex:(int)anInt | 230 - (NSString *)boolDescriptionAtIndex:(NSInteger)anInt |
202 { | 231 { |
203 bool value; | 232 bool value; |
204 | |
205 [self getArgument:&value atIndex:anInt]; | 233 [self getArgument:&value atIndex:anInt]; |
206 » return value ? @"YES" : @"NO"; | 234 » return value? @"YES" : @"NO"; |
207 } | 235 } |
208 | 236 |
209 - (NSString *)charDescriptionAtIndex:(int)anInt | 237 - (NSString *)charDescriptionAtIndex:(NSInteger)anInt |
210 { | 238 { |
211 unsigned char buffer[128]; | 239 unsigned char buffer[128]; |
212 memset(buffer, 0x0, 128); | 240 memset(buffer, 0x0, 128); |
213 | 241 |
214 [self getArgument:&buffer atIndex:anInt]; | 242 [self getArgument:&buffer atIndex:anInt]; |
215 | 243 |
216 // If there's only one character in the buffer, and it's 0 or 1, then we
have a BOOL | 244 // If there's only one character in the buffer, and it's 0 or 1, then we
have a BOOL |
217 if (buffer[1] == '\0' && (buffer[0] == 0 || buffer[0] == 1)) | 245 if (buffer[1] == '\0' && (buffer[0] == 0 || buffer[0] == 1)) |
218 » » return [NSString stringWithFormat:@"%@", (buffer[0] == 1 ? @"YES
" : @"NO")]; | 246 » » return (buffer[0] == 1 ? @"YES" : @"NO"); |
219 else | 247 else |
220 return [NSString stringWithFormat:@"'%c'", *buffer]; | 248 return [NSString stringWithFormat:@"'%c'", *buffer]; |
221 } | 249 } |
222 | 250 |
223 - (NSString *)unsignedCharDescriptionAtIndex:(int)anInt | 251 - (NSString *)unsignedCharDescriptionAtIndex:(NSInteger)anInt |
224 { | 252 { |
225 unsigned char buffer[128]; | 253 unsigned char buffer[128]; |
226 memset(buffer, 0x0, 128); | 254 memset(buffer, 0x0, 128); |
227 | 255 |
228 [self getArgument:&buffer atIndex:anInt]; | 256 [self getArgument:&buffer atIndex:anInt]; |
229 return [NSString stringWithFormat:@"'%c'", *buffer]; | 257 return [NSString stringWithFormat:@"'%c'", *buffer]; |
230 } | 258 } |
231 | 259 |
232 - (NSString *)intDescriptionAtIndex:(int)anInt | 260 - (NSString *)intDescriptionAtIndex:(NSInteger)anInt |
233 { | 261 { |
234 int intValue; | 262 int intValue; |
235 | 263 |
236 [self getArgument:&intValue atIndex:anInt]; | 264 [self getArgument:&intValue atIndex:anInt]; |
237 return [NSString stringWithFormat:@"%d", intValue]; | 265 return [NSString stringWithFormat:@"%d", intValue]; |
238 } | 266 } |
239 | 267 |
240 - (NSString *)unsignedIntDescriptionAtIndex:(int)anInt | 268 - (NSString *)unsignedIntDescriptionAtIndex:(NSInteger)anInt |
241 { | 269 { |
242 unsigned int intValue; | 270 unsigned int intValue; |
243 | 271 |
244 [self getArgument:&intValue atIndex:anInt]; | 272 [self getArgument:&intValue atIndex:anInt]; |
245 return [NSString stringWithFormat:@"%d", intValue]; | 273 return [NSString stringWithFormat:@"%d", intValue]; |
246 } | 274 } |
247 | 275 |
248 - (NSString *)shortDescriptionAtIndex:(int)anInt | 276 - (NSString *)shortDescriptionAtIndex:(NSInteger)anInt |
249 { | 277 { |
250 short shortValue; | 278 short shortValue; |
251 | 279 |
252 [self getArgument:&shortValue atIndex:anInt]; | 280 [self getArgument:&shortValue atIndex:anInt]; |
253 return [NSString stringWithFormat:@"%hi", shortValue]; | 281 return [NSString stringWithFormat:@"%hi", shortValue]; |
254 } | 282 } |
255 | 283 |
256 - (NSString *)unsignedShortDescriptionAtIndex:(int)anInt | 284 - (NSString *)unsignedShortDescriptionAtIndex:(NSInteger)anInt |
257 { | 285 { |
258 unsigned short shortValue; | 286 unsigned short shortValue; |
259 | 287 |
260 [self getArgument:&shortValue atIndex:anInt]; | 288 [self getArgument:&shortValue atIndex:anInt]; |
261 return [NSString stringWithFormat:@"%hu", shortValue]; | 289 return [NSString stringWithFormat:@"%hu", shortValue]; |
262 } | 290 } |
263 | 291 |
264 - (NSString *)longDescriptionAtIndex:(int)anInt | 292 - (NSString *)longDescriptionAtIndex:(NSInteger)anInt |
265 { | 293 { |
266 long longValue; | 294 long longValue; |
267 | 295 |
268 [self getArgument:&longValue atIndex:anInt]; | 296 [self getArgument:&longValue atIndex:anInt]; |
269 return [NSString stringWithFormat:@"%ld", longValue]; | 297 return [NSString stringWithFormat:@"%ld", longValue]; |
270 } | 298 } |
271 | 299 |
272 - (NSString *)unsignedLongDescriptionAtIndex:(int)anInt | 300 - (NSString *)unsignedLongDescriptionAtIndex:(NSInteger)anInt |
273 { | 301 { |
274 unsigned long longValue; | 302 unsigned long longValue; |
275 | 303 |
276 [self getArgument:&longValue atIndex:anInt]; | 304 [self getArgument:&longValue atIndex:anInt]; |
277 return [NSString stringWithFormat:@"%lu", longValue]; | 305 return [NSString stringWithFormat:@"%lu", longValue]; |
278 } | 306 } |
279 | 307 |
280 - (NSString *)longLongDescriptionAtIndex:(int)anInt | 308 - (NSString *)longLongDescriptionAtIndex:(NSInteger)anInt |
281 { | 309 { |
282 long long longLongValue; | 310 long long longLongValue; |
283 | 311 |
284 [self getArgument:&longLongValue atIndex:anInt]; | 312 [self getArgument:&longLongValue atIndex:anInt]; |
285 return [NSString stringWithFormat:@"%qi", longLongValue]; | 313 return [NSString stringWithFormat:@"%qi", longLongValue]; |
286 } | 314 } |
287 | 315 |
288 - (NSString *)unsignedLongLongDescriptionAtIndex:(int)anInt | 316 - (NSString *)unsignedLongLongDescriptionAtIndex:(NSInteger)anInt |
289 { | 317 { |
290 unsigned long long longLongValue; | 318 unsigned long long longLongValue; |
291 | 319 |
292 [self getArgument:&longLongValue atIndex:anInt]; | 320 [self getArgument:&longLongValue atIndex:anInt]; |
293 return [NSString stringWithFormat:@"%qu", longLongValue]; | 321 return [NSString stringWithFormat:@"%qu", longLongValue]; |
294 } | 322 } |
295 | 323 |
296 - (NSString *)doubleDescriptionAtIndex:(int)anInt; | 324 - (NSString *)doubleDescriptionAtIndex:(NSInteger)anInt |
297 { | 325 { |
298 double doubleValue; | 326 double doubleValue; |
299 | 327 |
300 [self getArgument:&doubleValue atIndex:anInt]; | 328 [self getArgument:&doubleValue atIndex:anInt]; |
301 return [NSString stringWithFormat:@"%f", doubleValue]; | 329 return [NSString stringWithFormat:@"%f", doubleValue]; |
302 } | 330 } |
303 | 331 |
304 - (NSString *)floatDescriptionAtIndex:(int)anInt | 332 - (NSString *)floatDescriptionAtIndex:(NSInteger)anInt |
305 { | 333 { |
306 float floatValue; | 334 float floatValue; |
307 | 335 |
308 [self getArgument:&floatValue atIndex:anInt]; | 336 [self getArgument:&floatValue atIndex:anInt]; |
309 return [NSString stringWithFormat:@"%f", floatValue]; | 337 return [NSString stringWithFormat:@"%f", floatValue]; |
310 } | 338 } |
311 | 339 |
312 - (NSString *)structDescriptionAtIndex:(int)anInt; | 340 - (NSString *)longDoubleDescriptionAtIndex:(NSInteger)anInt |
| 341 { |
| 342 » long double longDoubleValue; |
| 343 » |
| 344 » [self getArgument:&longDoubleValue atIndex:anInt]; |
| 345 » return [NSString stringWithFormat:@"%Lf", longDoubleValue]; |
| 346 } |
| 347 |
| 348 - (NSString *)structDescriptionAtIndex:(NSInteger)anInt |
| 349 { |
| 350 return [NSString stringWithFormat:@"(%@)", [[self getArgumentAtIndexAsObject
:anInt] description]]; |
| 351 } |
| 352 |
| 353 - (NSString *)pointerDescriptionAtIndex:(NSInteger)anInt |
313 { | 354 { |
314 void *buffer; | 355 void *buffer; |
315 | 356 |
316 [self getArgument:&buffer atIndex:anInt]; | |
317 return [NSString stringWithFormat:@":(struct)%p", buffer]; | |
318 } | |
319 | |
320 - (NSString *)pointerDescriptionAtIndex:(int)anInt | |
321 { | |
322 void *buffer; | |
323 | |
324 [self getArgument:&buffer atIndex:anInt]; | 357 [self getArgument:&buffer atIndex:anInt]; |
325 return [NSString stringWithFormat:@"%p", buffer]; | 358 return [NSString stringWithFormat:@"%p", buffer]; |
326 } | 359 } |
327 | 360 |
328 - (NSString *)cStringDescriptionAtIndex:(int)anInt | 361 - (NSString *)cStringDescriptionAtIndex:(NSInteger)anInt |
329 { | 362 { |
330 » char buffer[128]; | 363 » char buffer[104]; |
| 364 » char *cStringPtr; |
331 | 365 |
332 » memset(buffer, 0x0, 128); | 366 » [self getArgument:&cStringPtr atIndex:anInt]; |
333 » | 367 » strlcpy(buffer, cStringPtr, sizeof(buffer)); |
334 » [self getArgument:&buffer atIndex:anInt]; | 368 » strlcpy(buffer + 100, "...", (sizeof(buffer) - 100)); |
335 return [NSString stringWithFormat:@"\"%s\"", buffer]; | 369 return [NSString stringWithFormat:@"\"%s\"", buffer]; |
336 } | 370 } |
337 | 371 |
338 - (NSString *)selectorDescriptionAtIndex:(int)anInt | 372 - (NSString *)selectorDescriptionAtIndex:(NSInteger)anInt |
339 { | 373 { |
340 SEL selectorValue; | 374 SEL selectorValue; |
341 | 375 |
342 [self getArgument:&selectorValue atIndex:anInt]; | 376 [self getArgument:&selectorValue atIndex:anInt]; |
343 return [NSString stringWithFormat:@"@selector(%@)", NSStringFromSelector
(selectorValue)]; | 377 return [NSString stringWithFormat:@"@selector(%@)", NSStringFromSelector
(selectorValue)]; |
344 } | 378 } |
345 | 379 |
346 @end | 380 @end |
OLD | NEW |