@@ -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]; @@ -80,20 +75,15 @@ return string; string = [string substringWithRange: of_range(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; } @@ -176,18 +166,17 @@ [_lines addObject: comment]; } } -- (OFString *)stringValueForKey: (OFString *)key +- (OFString *)stringForKey: (OFString *)key { - return [self stringValueForKey: key - defaultValue: nil]; + return [self stringForKey: key defaultValue: nil]; } -- (OFString *)stringValueForKey: (OFString *)key - defaultValue: (OFString *)defaultValue +- (OFString *)stringForKey: (OFString *)key + defaultValue: (OFString *)defaultValue { for (id line in _lines) { OFINICategoryPair *pair; if (![line isKindOfClass: [OFINICategoryPair class]]) @@ -200,16 +189,15 @@ } return defaultValue; } -- (long long)longLongValueForKey: (OFString *)key - defaultValue: (long long)defaultValue +- (long long)longLongForKey: (OFString *)key + defaultValue: (long long)defaultValue { void *pool = objc_autoreleasePoolPush(); - OFString *value = [self stringValueForKey: key - defaultValue: nil]; + OFString *value = [self stringForKey: key defaultValue: nil]; long long ret; if (value != nil) ret = [value longLongValueWithBase: 0]; else @@ -218,16 +206,14 @@ objc_autoreleasePoolPop(pool); return ret; } -- (bool)boolValueForKey: (OFString *)key - defaultValue: (bool)defaultValue +- (bool)boolForKey: (OFString *)key defaultValue: (bool)defaultValue { void *pool = objc_autoreleasePoolPush(); - OFString *value = [self stringValueForKey: key - defaultValue: nil]; + OFString *value = [self stringForKey: key defaultValue: nil]; bool ret; if (value != nil) { if ([value isEqual: @"true"]) ret = true; @@ -241,16 +227,14 @@ objc_autoreleasePoolPop(pool); return ret; } -- (float)floatValueForKey: (OFString *)key - defaultValue: (float)defaultValue +- (float)floatForKey: (OFString *)key defaultValue: (float)defaultValue { void *pool = objc_autoreleasePoolPush(); - OFString *value = [self stringValueForKey: key - defaultValue: nil]; + OFString *value = [self stringForKey: key defaultValue: nil]; float ret; if (value != nil) ret = value.floatValue; else @@ -259,16 +243,14 @@ objc_autoreleasePoolPop(pool); return ret; } -- (double)doubleValueForKey: (OFString *)key - defaultValue: (double)defaultValue +- (double)doubleForKey: (OFString *)key defaultValue: (double)defaultValue { void *pool = objc_autoreleasePoolPush(); - OFString *value = [self stringValueForKey: key - defaultValue: nil]; + OFString *value = [self stringForKey: key defaultValue: nil]; double ret; if (value != nil) ret = value.doubleValue; else @@ -277,11 +259,11 @@ objc_autoreleasePoolPop(pool); return ret; } -- (OFArray OF_GENERIC(OFString *) *)stringValuesForKey: (OFString *)key +- (OFArray OF_GENERIC(OFString *) *)stringArrayForKey: (OFString *)key { OFMutableArray *ret = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); for (id line in _lines) { @@ -301,12 +283,11 @@ [ret makeImmutable]; return ret; } -- (void)setStringValue: (OFString *)stringValue - forKey: (OFString *)key +- (void)setString: (OFString *)string forKey: (OFString *)key { void *pool = objc_autoreleasePoolPush(); OFINICategoryPair *pair; for (id line in _lines) { @@ -315,11 +296,11 @@ pair = line; if ([pair->_key isEqual: key]) { OFString *old = pair->_value; - pair->_value = [stringValue copy]; + pair->_value = [string copy]; [old release]; objc_autoreleasePoolPop(pool); return; @@ -330,11 +311,11 @@ pair->_key = nil; pair->_value = nil; @try { pair->_key = [key copy]; - pair->_value = [stringValue copy]; + pair->_value = [string copy]; [_lines addObject: pair]; } @catch (id e) { [pair->_key release]; [pair->_value release]; @@ -342,78 +323,72 @@ } objc_autoreleasePoolPop(pool); } -- (void)setLongLongValue: (long long)longLongValue - forKey: (OFString *)key -{ - void *pool = objc_autoreleasePoolPush(); - - [self setStringValue: [OFString stringWithFormat: @"%lld", - longLongValue] - forKey: key]; - - objc_autoreleasePoolPop(pool); -} - -- (void)setBoolValue: (bool)boolValue - forKey: (OFString *)key -{ - [self setStringValue: (boolValue ? @"true" : @"false") - forKey: key]; -} - -- (void)setFloatValue: (float)floatValue - forKey: (OFString *)key -{ - void *pool = objc_autoreleasePoolPush(); - - [self setStringValue: [OFString stringWithFormat: @"%g", floatValue] - forKey: key]; - - objc_autoreleasePoolPop(pool); -} - -- (void)setDoubleValue: (double)doubleValue - forKey: (OFString *)key -{ - void *pool = objc_autoreleasePoolPush(); - - [self setStringValue: [OFString stringWithFormat: @"%g", doubleValue] - forKey: key]; - - objc_autoreleasePoolPop(pool); -} - -- (void)setStringValues: (OFArray OF_GENERIC(OFString *) *)stringValues - forKey: (OFString *)key +- (void)setLongLong: (long long)longLong forKey: (OFString *)key +{ + void *pool = objc_autoreleasePoolPush(); + + [self setString: [OFString stringWithFormat: @"%lld", longLong] + forKey: key]; + + objc_autoreleasePoolPop(pool); +} + +- (void)setBool: (bool)bool_ forKey: (OFString *)key +{ + [self setString: (bool_ ? @"true" : @"false") forKey: 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 *pool = objc_autoreleasePoolPush(); + + [self setString: [OFString stringWithFormat: @"%g", double_] + forKey: key]; + + objc_autoreleasePoolPop(pool); +} + +- (void)setStringArray: (OFArray OF_GENERIC(OFString *) *)array + forKey: (OFString *)key { void *pool; OFMutableArray *pairs; id const *lines; size_t count; bool replaced; - if (stringValues.count == 0) { + if (array.count == 0) { [self removeValueForKey: key]; return; } pool = objc_autoreleasePoolPush(); - pairs = [OFMutableArray arrayWithCapacity: stringValues.count]; + pairs = [OFMutableArray arrayWithCapacity: array.count]; - for (OFString *stringValue in stringValues) { + for (OFString *string in array) { OFINICategoryPair *pair; - if (![stringValue isKindOfClass: [OFString class]]) + if (![string isKindOfClass: [OFString class]]) @throw [OFInvalidArgumentException exception]; pair = [[[OFINICategoryPair alloc] init] autorelease]; pair->_key = [key copy]; - pair->_value = [stringValue copy]; + pair->_value = [string copy]; [pairs addObject: pair]; } lines = _lines.objects; @@ -435,11 +410,11 @@ [_lines insertObjectsFromArray: pairs atIndex: i]; replaced = true; /* Continue after inserted pairs */ - i += stringValues.count - 1; + i += array.count - 1; } else i--; /* Continue at same position */ lines = _lines.objects; count = _lines.count;