@@ -37,12 +37,13 @@ } placeholder; static OFCharacterSet *URLQueryPartAllowedCharacterSet = nil; @interface OFDictionary () -- (OFString *)of_JSONRepresentationWithOptions: (int)options - depth: (size_t)depth; +- (OFString *) + of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options + depth: (size_t)depth; @end @interface OFDictionaryPlaceholder: OFDictionary @end @@ -71,19 +72,17 @@ { return (id)[[OFMapTableDictionary alloc] initWithDictionary: dictionary]; } -- (instancetype)initWithObject: (id)object - forKey: (id)key +- (instancetype)initWithObject: (id)object forKey: (id)key { return (id)[[OFMapTableDictionary alloc] initWithObject: object forKey: key]; } -- (instancetype)initWithObjects: (OFArray *)objects - forKeys: (OFArray *)keys +- (instancetype)initWithObjects: (OFArray *)objects forKeys: (OFArray *)keys { return (id)[[OFMapTableDictionary alloc] initWithObjects: objects forKeys: keys]; } @@ -171,16 +170,16 @@ { } - (unsigned int)retainCount { - return OF_RETAIN_COUNT_MAX; + return OFMaxRetainCount; } -- (bool)characterIsMember: (of_unichar_t)character +- (bool)characterIsMember: (OFUnichar)character { - if (character < CHAR_MAX && of_ascii_isalnum(character)) + if (character < CHAR_MAX && OFASCIIIsAlnum(character)) return true; switch (character) { case '-': case '.': @@ -226,15 +225,13 @@ { return [[(OFDictionary *)[self alloc] initWithDictionary: dictionary] autorelease]; } -+ (instancetype)dictionaryWithObject: (id)object - forKey: (id)key ++ (instancetype)dictionaryWithObject: (id)object forKey: (id)key { - return [[[self alloc] initWithObject: object - forKey: key] autorelease]; + return [[[self alloc] initWithObject: object forKey: key] autorelease]; } + (instancetype)dictionaryWithObjects: (OFArray *)objects forKeys: (OFArray *)keys { @@ -242,11 +239,11 @@ forKeys: keys] autorelease]; } + (instancetype)dictionaryWithObjects: (id const *)objects forKeys: (id const *)keys - count: (size_t)count + count: (size_t)count { return [[[self alloc] initWithObjects: objects forKeys: keys count: count] autorelease]; } @@ -283,21 +280,19 @@ - (instancetype)initWithDictionary: (OFDictionary *)dictionary { OF_INVALID_INIT_METHOD } -- (instancetype)initWithObject: (id)object - forKey: (id)key +- (instancetype)initWithObject: (id)object forKey: (id)key { if (key == nil || object == nil) @throw [OFInvalidArgumentException exception]; return [self initWithKeysAndObjects: key, object, nil]; } -- (instancetype)initWithObjects: (OFArray *)objects_ - forKeys: (OFArray *)keys_ +- (instancetype)initWithObjects: (OFArray *)objects_ forKeys: (OFArray *)keys_ { id const *objects, *keys; size_t count; @try { @@ -311,13 +306,11 @@ } @catch (id e) { [self release]; @throw e; } - return [self initWithObjects: objects - forKeys: keys - count: count]; + return [self initWithObjects: objects forKeys: keys count: count]; } - (instancetype)initWithObjects: (id const *)objects forKeys: (id const *)keys count: (size_t)count @@ -329,19 +322,17 @@ { id ret; va_list arguments; va_start(arguments, firstKey); - ret = [self initWithKey: firstKey - arguments: arguments]; + ret = [self initWithKey: firstKey arguments: arguments]; va_end(arguments); return ret; } -- (instancetype)initWithKey: (id)firstKey - arguments: (va_list)arguments +- (instancetype)initWithKey: (id)firstKey arguments: (va_list)arguments { OF_INVALID_INIT_METHOD } - (instancetype)initWithSerialization: (OFXMLElement *)element @@ -365,20 +356,18 @@ return [super valueForKey: @"count"]; return [self objectForKey: key]; } -- (void)setValue: (id)value - forKey: (OFString *)key +- (void)setValue: (id)value forKey: (OFString *)key { if (![self isKindOfClass: [OFMutableDictionary class]]) @throw [OFUndefinedKeyException exceptionWithObject: self key: key value: value]; - [(OFMutableDictionary *)self setObject: value - forKey: key]; + [(OFMutableDictionary *)self setObject: value forKey: key]; } - (size_t)count { OF_UNRECOGNIZED_SELECTOR @@ -517,11 +506,11 @@ { return [[[OFDictionaryObjectEnumerator alloc] initWithDictionary: self] autorelease]; } -- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t *)state +- (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count { OFEnumerator *enumerator; int i; @@ -547,12 +536,11 @@ return i; } #ifdef OF_HAVE_BLOCKS -- (void)enumerateKeysAndObjectsUsingBlock: - (of_dictionary_enumeration_block_t)block +- (void)enumerateKeysAndObjectsUsingBlock: (OFDictionaryEnumerationBlock)block { bool stop = false; for (id key in self) { block(key, [self objectForKey: key], &stop); @@ -560,35 +548,32 @@ if (stop) break; } } -- (OFDictionary *)mappedDictionaryUsingBlock: (of_dictionary_map_block_t)block +- (OFDictionary *)mappedDictionaryUsingBlock: (OFDictionaryMapBlock)block { OFMutableDictionary *new = [OFMutableDictionary dictionary]; [self enumerateKeysAndObjectsUsingBlock: ^ (id key, id object, bool *stop) { - [new setObject: block(key, object) - forKey: key]; + [new setObject: block(key, object) forKey: key]; }]; [new makeImmutable]; return new; } -- (OFDictionary *)filteredDictionaryUsingBlock: - (of_dictionary_filter_block_t)block +- (OFDictionary *)filteredDictionaryUsingBlock: (OFDictionaryFilterBlock)block { OFMutableDictionary *new = [OFMutableDictionary dictionary]; [self enumerateKeysAndObjectsUsingBlock: ^ (id key, id object, bool *stop) { if (block(key, object)) - [new setObject: object - forKey: key]; + [new setObject: object forKey: key]; }]; [new makeImmutable]; return new; @@ -642,12 +627,11 @@ if (++i < count) [ret appendString: @";\n"]; objc_autoreleasePoolPop(pool2); } - [ret replaceOccurrencesOfString: @"\n" - withString: @"\n\t"]; + [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @";\n}"]; [ret makeImmutable]; objc_autoreleasePoolPop(pool); @@ -694,14 +678,14 @@ OFEnumerator *keyEnumerator, *objectEnumerator; id key, object; if ([self isKindOfClass: [OFMutableDictionary class]]) element = [OFXMLElement elementWithName: @"OFMutableDictionary" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; else element = [OFXMLElement elementWithName: @"OFDictionary" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; keyEnumerator = [self keyEnumerator]; objectEnumerator = [self objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { @@ -708,16 +692,16 @@ void *pool2 = objc_autoreleasePoolPush(); OFXMLElement *keyElement, *objectElement; keyElement = [OFXMLElement elementWithName: @"key" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; [keyElement addChild: key.XMLElementBySerializing]; objectElement = [OFXMLElement elementWithName: @"object" - namespace: OF_SERIALIZATION_NS]; + namespace: OFSerializationNS]; [objectElement addChild: object.XMLElementBySerializing]; [element addChild: keyElement]; [element addChild: objectElement]; @@ -731,31 +715,31 @@ return [element autorelease]; } - (OFString *)JSONRepresentation { - return [self of_JSONRepresentationWithOptions: 0 - depth: 0]; -} - -- (OFString *)JSONRepresentationWithOptions: (int)options -{ - return [self of_JSONRepresentationWithOptions: options - depth: 0]; + return [self of_JSONRepresentationWithOptions: 0 depth: 0]; +} + +- (OFString *)JSONRepresentationWithOptions: + (OFJSONRepresentationOptions)options +{ + return [self of_JSONRepresentationWithOptions: options depth: 0]; } -- (OFString *)of_JSONRepresentationWithOptions: (int)options - depth: (size_t)depth +- (OFString *) + of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options + depth: (size_t)depth { OFMutableString *JSON = [OFMutableString stringWithString: @"{"]; void *pool = objc_autoreleasePoolPush(); OFEnumerator *keyEnumerator = [self keyEnumerator]; OFEnumerator *objectEnumerator = [self objectEnumerator]; size_t i, count = self.count; id key, object; - if (options & OF_JSON_REPRESENTATION_PRETTY) { + if (options & OFJSONRepresentationOptionPretty) { OFMutableString *indentation = [OFMutableString string]; for (i = 0; i < depth; i++) [indentation appendString: @"\t"]; @@ -764,11 +748,11 @@ i = 0; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { void *pool2 = objc_autoreleasePoolPush(); int identifierOptions = - options | OF_JSON_REPRESENTATION_IDENTIFIER; + options | OFJSONRepresentationOptionIsIdentifier; if (![key isKindOfClass: [OFString class]]) @throw [OFInvalidArgumentException exception]; [JSON appendString: indentation]; @@ -794,11 +778,11 @@ i = 0; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { void *pool2 = objc_autoreleasePoolPush(); int identifierOptions = - options | OF_JSON_REPRESENTATION_IDENTIFIER; + options | OFJSONRepresentationOptionIsIdentifier; if (![key isKindOfClass: [OFString class]]) @throw [OFInvalidArgumentException exception]; [JSON appendString: [key @@ -838,22 +822,20 @@ if (count <= 15) { uint8_t tmp = 0x80 | ((uint8_t)count & 0xF); [data addItem: &tmp]; } else if (count <= UINT16_MAX) { uint8_t type = 0xDE; - uint16_t tmp = OF_BSWAP16_IF_LE((uint16_t)count); + uint16_t tmp = OFToBigEndian16((uint16_t)count); [data addItem: &type]; - [data addItems: &tmp - count: sizeof(tmp)]; + [data addItems: &tmp count: sizeof(tmp)]; } else if (count <= UINT32_MAX) { uint8_t type = 0xDF; - uint32_t tmp = OF_BSWAP32_IF_LE((uint32_t)count); + uint32_t tmp = OFToBigEndian32((uint32_t)count); [data addItem: &type]; - [data addItems: &tmp - count: sizeof(tmp)]; + [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exception]; pool = objc_autoreleasePoolPush(); @@ -866,16 +848,14 @@ OFData *child; i++; child = key.messagePackRepresentation; - [data addItems: child.items - count: child.count]; + [data addItems: child.items count: child.count]; child = object.messagePackRepresentation; - [data addItems: child.items - count: child.count]; + [data addItems: child.items count: child.count]; objc_autoreleasePoolPop(pool2); } assert(i == count);