ObjFW  Diff

Differences From Artifact [3204259101]:

To Artifact [034710c781]:

  • File src/OFDictionary.m — part of check-in [f816d1ec7c] at 2016-06-05 15:11:04 on branch trunk — Move -[setValue:forKey:] to OFDictionary

    If this is only overridden in OFMutableDictionary, this would lead to
    inconsistent behavior, as it could be called on an OFDictionary as well
    due to the fact that -[setValue:forKey:] is defined in OFObject.
    Instead, if the dictionary is immutable, an OFUndefinedKeyException is
    thrown. (user: js, size: 16237) [annotate] [blame] [check-ins using]


25
26
27
28
29
30
31

32
33
34
35
36
37
38
#import "OFArray.h"
#import "OFString.h"
#import "OFXMLElement.h"
#import "OFDataArray.h"

#import "OFInvalidArgumentException.h"
#import "OFOutOfRangeException.h"


static struct {
	Class isa;
} placeholder;

@interface OFDictionary ()
- (OFString*)OF_JSONRepresentationWithOptions: (int)options







>







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#import "OFArray.h"
#import "OFString.h"
#import "OFXMLElement.h"
#import "OFDataArray.h"

#import "OFInvalidArgumentException.h"
#import "OFOutOfRangeException.h"
#import "OFUndefinedKeyException.h"

static struct {
	Class isa;
} placeholder;

@interface OFDictionary ()
- (OFString*)OF_JSONRepresentationWithOptions: (int)options
294
295
296
297
298
299
300























301
302
303
304
305
306
307
		objc_autoreleasePoolPop(pool);

		return [ret autorelease];
	}

	return [self objectForKey: key];
}
























- (size_t)count
{
	OF_UNRECOGNIZED_SELECTOR
}

- copy







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
		objc_autoreleasePoolPop(pool);

		return [ret autorelease];
	}

	return [self objectForKey: key];
}

- (void)setValue: (id)value
	  forKey: (OFString*)key
{
	if ([key hasPrefix: @"@"]) {
		void *pool = objc_autoreleasePoolPush();

		key = [key substringWithRange: of_range(1, [key length] - 1)];
		[super setValue: value
			 forKey: key];

		objc_autoreleasePoolPop(pool);
		return;
	}

	if (![self isKindOfClass: [OFMutableDictionary class]])
		@throw [OFUndefinedKeyException exceptionWithObject: self
								key: key
							      value: value];

	[(OFMutableDictionary*)self setObject: value
				       forKey: key];
}

- (size_t)count
{
	OF_UNRECOGNIZED_SELECTOR
}

- copy