@@ -50,20 +50,15 @@ ![string containsString: @"\""]) return string; mutableString = [[string mutableCopy] autorelease]; - [mutableString replaceOccurrencesOfString: @"\\" - withString: @"\\\\"]; - [mutableString replaceOccurrencesOfString: @"\f" - withString: @"\\f"]; - [mutableString replaceOccurrencesOfString: @"\r" - withString: @"\\r"]; - [mutableString replaceOccurrencesOfString: @"\n" - withString: @"\\n"]; - [mutableString replaceOccurrencesOfString: @"\"" - withString: @"\\\""]; + [mutableString replaceOccurrencesOfString: @"\\" withString: @"\\\\"]; + [mutableString replaceOccurrencesOfString: @"\f" withString: @"\\f"]; + [mutableString replaceOccurrencesOfString: @"\r" withString: @"\\r"]; + [mutableString replaceOccurrencesOfString: @"\n" withString: @"\\n"]; + [mutableString replaceOccurrencesOfString: @"\"" withString: @"\\\""]; [mutableString prependString: @"\""]; [mutableString appendString: @"\""]; [mutableString makeImmutable]; @@ -77,23 +72,18 @@ OFMutableString *mutableString; if (![string hasPrefix: @"\""] || ![string hasSuffix: @"\""]) return string; - string = [string substringWithRange: of_range(1, string.length - 2)]; + string = [string substringWithRange: OFRangeMake(1, string.length - 2)]; mutableString = [[string mutableCopy] autorelease]; - [mutableString replaceOccurrencesOfString: @"\\f" - withString: @"\f"]; - [mutableString replaceOccurrencesOfString: @"\\r" - withString: @"\r"]; - [mutableString replaceOccurrencesOfString: @"\\n" - withString: @"\n"]; - [mutableString replaceOccurrencesOfString: @"\\\"" - withString: @"\""]; - [mutableString replaceOccurrencesOfString: @"\\\\" - withString: @"\\"]; + [mutableString replaceOccurrencesOfString: @"\\f" withString: @"\f"]; + [mutableString replaceOccurrencesOfString: @"\\r" withString: @"\r"]; + [mutableString replaceOccurrencesOfString: @"\\n" withString: @"\n"]; + [mutableString replaceOccurrencesOfString: @"\\\"" withString: @"\""]; + [mutableString replaceOccurrencesOfString: @"\\\\" withString: @"\\"]; [mutableString makeImmutable]; return mutableString; } @@ -104,19 +94,29 @@ [_key release]; [_value release]; [super dealloc]; } + +- (OFString *)description +{ + return [OFString stringWithFormat: @"%@ = %@", _key, _value]; +} @end @implementation OFINICategoryComment - (void)dealloc { [_comment release]; [super dealloc]; } + +- (OFString *)description +{ + return [[_comment copy] autorelease]; +} @end @implementation OFINICategory @synthesize name = _name; @@ -154,11 +154,11 @@ OFINICategoryPair *pair = [[[OFINICategoryPair alloc] init] autorelease]; OFString *key, *value; size_t pos; - if ((pos = [line rangeOfString: @"="].location) == OF_NOT_FOUND) + if ((pos = [line rangeOfString: @"="].location) == OFNotFound) @throw [OFInvalidFormatException exception]; key = unescapeString([line substringToIndex: pos] .stringByDeletingEnclosingWhitespaces); value = unescapeString([line substringFromIndex: pos + 1] @@ -178,12 +178,11 @@ } } - (OFString *)stringForKey: (OFString *)key { - return [self stringForKey: key - defaultValue: nil]; + return [self stringForKey: key defaultValue: nil]; } - (OFString *)stringForKey: (OFString *)key defaultValue: (OFString *)defaultValue { @@ -200,16 +199,15 @@ } return defaultValue; } -- (long long)integerForKey: (OFString *)key - defaultValue: (long long)defaultValue +- (long long)longLongForKey: (OFString *)key + defaultValue: (long long)defaultValue { void *pool = objc_autoreleasePoolPush(); - OFString *value = [self stringForKey: key - defaultValue: nil]; + OFString *value = [self stringForKey: key defaultValue: nil]; long long ret; if (value != nil) ret = [value longLongValueWithBase: 0]; else @@ -218,16 +216,14 @@ objc_autoreleasePoolPop(pool); return ret; } -- (bool)boolForKey: (OFString *)key - defaultValue: (bool)defaultValue +- (bool)boolForKey: (OFString *)key defaultValue: (bool)defaultValue { void *pool = objc_autoreleasePoolPush(); - OFString *value = [self stringForKey: key - defaultValue: nil]; + OFString *value = [self stringForKey: key defaultValue: nil]; bool ret; if (value != nil) { if ([value isEqual: @"true"]) ret = true; @@ -241,16 +237,14 @@ objc_autoreleasePoolPop(pool); return ret; } -- (float)floatForKey: (OFString *)key - defaultValue: (float)defaultValue +- (float)floatForKey: (OFString *)key defaultValue: (float)defaultValue { void *pool = objc_autoreleasePoolPush(); - OFString *value = [self stringForKey: key - defaultValue: nil]; + OFString *value = [self stringForKey: key defaultValue: nil]; float ret; if (value != nil) ret = value.floatValue; else @@ -259,16 +253,14 @@ objc_autoreleasePoolPop(pool); return ret; } -- (double)doubleForKey: (OFString *)key - defaultValue: (double)defaultValue +- (double)doubleForKey: (OFString *)key defaultValue: (double)defaultValue { void *pool = objc_autoreleasePoolPush(); - OFString *value = [self stringForKey: key - defaultValue: nil]; + OFString *value = [self stringForKey: key defaultValue: nil]; double ret; if (value != nil) ret = value.doubleValue; else @@ -277,11 +269,11 @@ objc_autoreleasePoolPop(pool); return ret; } -- (OFArray *)arrayForKey: (OFString *)key +- (OFArray OF_GENERIC(OFString *) *)stringArrayForKey: (OFString *)key { OFMutableArray *ret = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); for (id line in _lines) { @@ -301,12 +293,11 @@ [ret makeImmutable]; return ret; } -- (void)setString: (OFString *)string - forKey: (OFString *)key +- (void)setString: (OFString *)string forKey: (OFString *)key { void *pool = objc_autoreleasePoolPush(); OFINICategoryPair *pair; for (id line in _lines) { @@ -342,52 +333,47 @@ } objc_autoreleasePoolPop(pool); } -- (void)setInteger: (long long)integer - forKey: (OFString *)key +- (void)setLongLong: (long long)longLong forKey: (OFString *)key { void *pool = objc_autoreleasePoolPush(); - [self setString: [OFString stringWithFormat: @"%lld", integer] + [self setString: [OFString stringWithFormat: @"%lld", longLong] forKey: key]; objc_autoreleasePoolPop(pool); } -- (void)setBool: (bool)bool_ - forKey: (OFString *)key +- (void)setBool: (bool)bool_ forKey: (OFString *)key { - [self setString: (bool_ ? @"true" : @"false") - forKey: key]; + [self setString: (bool_ ? @"true" : @"false") forKey: key]; } -- (void)setFloat: (float)float_ - forKey: (OFString *)key +- (void)setFloat: (float)float_ forKey: (OFString *)key { void *pool = objc_autoreleasePoolPush(); [self setString: [OFString stringWithFormat: @"%g", float_] forKey: key]; objc_autoreleasePoolPop(pool); } -- (void)setDouble: (double)double_ - forKey: (OFString *)key +- (void)setDouble: (double)double_ forKey: (OFString *)key { void *pool = objc_autoreleasePoolPush(); [self setString: [OFString stringWithFormat: @"%g", double_] forKey: key]; objc_autoreleasePoolPop(pool); } -- (void)setArray: (OFArray *)array - forKey: (OFString *)key +- (void)setStringArray: (OFArray OF_GENERIC(OFString *) *)array + forKey: (OFString *)key { void *pool; OFMutableArray *pairs; id const *lines; size_t count; @@ -400,19 +386,19 @@ pool = objc_autoreleasePoolPush(); pairs = [OFMutableArray arrayWithCapacity: array.count]; - for (id object in array) { + for (OFString *string in array) { OFINICategoryPair *pair; - if (![object isKindOfClass: [OFString class]]) + if (![string isKindOfClass: [OFString class]]) @throw [OFInvalidArgumentException exception]; pair = [[[OFINICategoryPair alloc] init] autorelease]; pair->_key = [key copy]; - pair->_value = [object copy]; + pair->_value = [string copy]; [pairs addObject: pair]; } lines = _lines.objects; @@ -480,11 +466,11 @@ objc_autoreleasePoolPop(pool); } - (bool)of_writeToStream: (OFStream *)stream - encoding: (of_string_encoding_t)encoding + encoding: (OFStringEncoding)encoding first: (bool)first { if (_lines.count == 0) return false; @@ -501,15 +487,19 @@ OFINICategoryPair *pair = line; OFString *key = escapeString(pair->_key); OFString *value = escapeString(pair->_value); OFString *tmp = [OFString stringWithFormat: @"%@=%@\r\n", key, value]; - - [stream writeString: tmp - encoding: encoding]; + [stream writeString: tmp encoding: encoding]; } else @throw [OFInvalidArgumentException exception]; } return true; } + +- (OFString *)description +{ + return [OFString stringWithFormat: @"<%@ \"%@\": %@>", + self.class, _name, _lines]; +} @end