Index: src/OFINICategory.h ================================================================== --- src/OFINICategory.h +++ src/OFINICategory.h @@ -42,97 +42,97 @@ /** * @brief Returns the string for the specified key, or `nil` if it does not * exist. * - * If the specified key is a multi-key (see @ref stringArrayForKey:), the value + * If the specified key is a multi-key (see @ref arrayValueForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the string should be returned * @return The string for the specified key, or `nil` if it does not exist */ -- (nullable OFString *)stringForKey: (OFString *)key; +- (nullable OFString *)stringValueForKey: (OFString *)key; /** * @brief Returns the string for the specified key or the specified default * value if it does not exist. * - * If the specified key is a multi-key (see @ref stringArrayForKey:), the value + * If the specified key is a multi-key (see @ref arrayValueForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the string should be returned * @param defaultValue The value to return if the key does not exist * @return The string for the specified key or the specified default value if * it does not exist */ -- (nullable OFString *)stringForKey: (OFString *)key - defaultValue: (nullable OFString *)defaultValue; +- (nullable OFString *)stringValueForKey: (OFString *)key + defaultValue: (nullable OFString *)defaultValue; /** - * @brief Returns the long long for the specified key or the specified default - * value if it does not exist. + * @brief Returns the long long value for the specified key or the specified + * default value if it does not exist. * - * If the specified key is a multi-key (see @ref stringArrayForKey:), the value + * If the specified key is a multi-key (see @ref arrayValueForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the long long should be returned * @param defaultValue The value to return if the key does not exist * @return The long long for the specified key or the specified default value * if it does not exist * @throw OFInvalidFormatException The specified key is not in the correct * format for a long long */ -- (long long)longLongForKey: (OFString *)key - defaultValue: (long long)defaultValue; +- (long long)longLongValueForKey: (OFString *)key + defaultValue: (long long)defaultValue; /** - * @brief Returns the bool for the specified key or the specified default value - * if it does not exist. + * @brief Returns the bool value for the specified key or the specified default + * value if it does not exist. * - * If the specified key is a multi-key (see @ref stringArrayForKey:), the value + * If the specified key is a multi-key (see @ref arrayValueForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the bool should be returned * @param defaultValue The value to return if the key does not exist * @return The bool for the specified key or the specified default value if it * does not exist * @throw OFInvalidFormatException The specified key is not in the correct * format for a bool */ -- (bool)boolForKey: (OFString *)key defaultValue: (bool)defaultValue; +- (bool)boolValueForKey: (OFString *)key defaultValue: (bool)defaultValue; /** - * @brief Returns the float for the specified key or the specified default + * @brief Returns the float value for the specified key or the specified default * value if it does not exist. * - * If the specified key is a multi-key (see @ref stringArrayForKey:), the value + * If the specified key is a multi-key (see @ref arrayValueForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the float should be returned * @param defaultValue The value to return if the key does not exist * @return The float for the specified key or the specified default value if it * does not exist * @throw OFInvalidFormatException The specified key is not in the correct * format for a float */ -- (float)floatForKey: (OFString *)key defaultValue: (float)defaultValue; +- (float)floatValueForKey: (OFString *)key defaultValue: (float)defaultValue; /** - * @brief Returns the double for the specified key or the specified default - * value if it does not exist. + * @brief Returns the double value for the specified key or the specified + * default value if it does not exist. * - * If the specified key is a multi-key (see @ref stringArrayForKey:), the value + * If the specified key is a multi-key (see @ref arrayValueForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the double should be returned * @param defaultValue The value to return if the key does not exist * @return The double for the specified key or the specified default value if * it does not exist * @throw OFInvalidFormatException The specified key is not in the correct * format for a double */ -- (double)doubleForKey: (OFString *)key defaultValue: (double)defaultValue; +- (double)doubleValueForKey: (OFString *)key defaultValue: (double)defaultValue; /** * @brief Returns an array of strings for the specified multi-key, or an empty * array if the key does not exist. * @@ -141,89 +141,89 @@ * * @param key The multi-key for which the array should be returned * @return The array for the specified key, or an empty array if it does not * exist */ -- (OFArray OF_GENERIC(OFString *) *)stringArrayForKey: (OFString *)key; +- (OFArray OF_GENERIC(OFString *) *)arrayValueForKey: (OFString *)key; /** * @brief Sets the value of the specified key to the specified string. * - * If the specified key is a multi-key (see @ref stringArrayForKey:), the value + * If the specified key is a multi-key (see @ref arrayValueForKey:), the value * of the first key/value pair found is changed. * - * @param string The string to which the key should be set + * @param stringValue The string to which the key should be set * @param key The key for which the new value should be set */ -- (void)setString: (OFString *)string forKey: (OFString *)key; +- (void)setStringValue: (OFString *)stringValue forKey: (OFString *)key; /** * @brief Sets the value of the specified key to the specified long long. * - * If the specified key is a multi-key (see @ref stringArrayForKey:), the value + * If the specified key is a multi-key (see @ref arrayValueForKey:), the value * of the first key/value pair found is changed. * - * @param longLong The long long to which the key should be set + * @param longLongValue The long long to which the key should be set * @param key The key for which the new value should be set */ -- (void)setLongLong: (long long)longLong forKey: (OFString *)key; +- (void)setLongLongValue: (long long)longLongValue forKey: (OFString *)key; /** * @brief Sets the value of the specified key to the specified bool. * - * If the specified key is a multi-key (see @ref stringArrayForKey:), the value + * If the specified key is a multi-key (see @ref arrayValueForKey:), the value * of the first key/value pair found is changed. * - * @param bool_ The bool to which the key should be set + * @param boolValue The bool to which the key should be set * @param key The key for which the new value should be set */ -- (void)setBool: (bool)bool_ forKey: (OFString *)key; +- (void)setBoolValue: (bool)boolValue forKey: (OFString *)key; /** * @brief Sets the value of the specified key to the specified float. * - * If the specified key is a multi-key (see @ref stringArrayForKey:), the value + * If the specified key is a multi-key (see @ref arrayValueForKey:), the value * of the first key/value pair found is changed. * - * @param float_ The float to which the key should be set + * @param floatValue The float to which the key should be set * @param key The key for which the new value should be set */ -- (void)setFloat: (float)float_ forKey: (OFString *)key; +- (void)setFloatValue: (float)floatValue forKey: (OFString *)key; /** * @brief Sets the value of the specified key to the specified double. * - * If the specified key is a multi-key (see @ref stringArrayForKey:), the value + * If the specified key is a multi-key (see @ref arrayValueForKey:), the value * of the first key/value pair found is changed. * - * @param double_ The double to which the key should be set + * @param doubleValue The double to which the key should be set * @param key The key for which the new value should be set */ -- (void)setDouble: (double)double_ forKey: (OFString *)key; +- (void)setDoubleValue: (double)doubleValue forKey: (OFString *)key; /** * @brief Sets the specified multi-key to the specified array of strings. * * It replaces the first occurrence of the multi-key with several key/value * pairs and removes all following occurrences. If the multi-key does not exist * yet, it is appended to the section. * - * See also @ref stringArrayForKey: for more information about multi-keys. + * See also @ref arrayValueForKey: for more information about multi-keys. * - * @param array The array of strings to which the multi-key should be set + * @param arrayValue The array of strings to which the multi-key should be set * @param key The multi-key for which the new values should be set */ -- (void)setStringArray: (OFArray OF_GENERIC(OFString *) *)array - forKey: (OFString *)key; +- (void)setArrayValue: (OFArray OF_GENERIC(OFString *) *)arrayValue + forKey: (OFString *)key; /** * @brief Removes the value for the specified key * - * If the specified key is a multi-key (see @ref stringArrayForKey:), all + * If the specified key is a multi-key (see @ref arrayValueForKey:), all * key/value pairs matching the specified key are removed. * * @param key The key of the value to remove */ - (void)removeValueForKey: (OFString *)key; @end OF_ASSUME_NONNULL_END Index: src/OFINICategory.m ================================================================== --- src/OFINICategory.m +++ src/OFINICategory.m @@ -176,17 +176,17 @@ [_lines addObject: comment]; } } -- (OFString *)stringForKey: (OFString *)key +- (OFString *)stringValueForKey: (OFString *)key { - return [self stringForKey: key defaultValue: nil]; + return [self stringValueForKey: key defaultValue: nil]; } -- (OFString *)stringForKey: (OFString *)key - defaultValue: (OFString *)defaultValue +- (OFString *)stringValueForKey: (OFString *)key + defaultValue: (OFString *)defaultValue { for (id line in _lines) { OFINICategoryPair *pair; if (![line isKindOfClass: [OFINICategoryPair class]]) @@ -199,15 +199,15 @@ } return defaultValue; } -- (long long)longLongForKey: (OFString *)key - defaultValue: (long long)defaultValue +- (long long)longLongValueForKey: (OFString *)key + defaultValue: (long long)defaultValue { void *pool = objc_autoreleasePoolPush(); - OFString *value = [self stringForKey: key defaultValue: nil]; + OFString *value = [self stringValueForKey: key defaultValue: nil]; long long ret; if (value != nil) ret = [value longLongValueWithBase: 0]; else @@ -216,14 +216,14 @@ objc_autoreleasePoolPop(pool); return ret; } -- (bool)boolForKey: (OFString *)key defaultValue: (bool)defaultValue +- (bool)boolValueForKey: (OFString *)key defaultValue: (bool)defaultValue { void *pool = objc_autoreleasePoolPush(); - OFString *value = [self stringForKey: key defaultValue: nil]; + OFString *value = [self stringValueForKey: key defaultValue: nil]; bool ret; if (value != nil) { if ([value isEqual: @"true"]) ret = true; @@ -237,14 +237,14 @@ objc_autoreleasePoolPop(pool); return ret; } -- (float)floatForKey: (OFString *)key defaultValue: (float)defaultValue +- (float)floatValueForKey: (OFString *)key defaultValue: (float)defaultValue { void *pool = objc_autoreleasePoolPush(); - OFString *value = [self stringForKey: key defaultValue: nil]; + OFString *value = [self stringValueForKey: key defaultValue: nil]; float ret; if (value != nil) ret = value.floatValue; else @@ -253,14 +253,14 @@ objc_autoreleasePoolPop(pool); return ret; } -- (double)doubleForKey: (OFString *)key defaultValue: (double)defaultValue +- (double)doubleValueForKey: (OFString *)key defaultValue: (double)defaultValue { void *pool = objc_autoreleasePoolPush(); - OFString *value = [self stringForKey: key defaultValue: nil]; + OFString *value = [self stringValueForKey: key defaultValue: nil]; double ret; if (value != nil) ret = value.doubleValue; else @@ -269,11 +269,11 @@ objc_autoreleasePoolPop(pool); return ret; } -- (OFArray OF_GENERIC(OFString *) *)stringArrayForKey: (OFString *)key +- (OFArray OF_GENERIC(OFString *) *)arrayValueForKey: (OFString *)key { OFMutableArray *ret = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); for (id line in _lines) { @@ -293,11 +293,11 @@ [ret makeImmutable]; return ret; } -- (void)setString: (OFString *)string forKey: (OFString *)key +- (void)setStringValue: (OFString *)string forKey: (OFString *)key { void *pool = objc_autoreleasePoolPush(); OFINICategoryPair *pair; for (id line in _lines) { @@ -333,64 +333,65 @@ } objc_autoreleasePoolPop(pool); } -- (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)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)setArrayValue: (OFArray OF_GENERIC(OFString *) *)arrayValue + forKey: (OFString *)key { void *pool; OFMutableArray *pairs; id const *lines; size_t count; bool replaced; - if (array.count == 0) { + if (arrayValue.count == 0) { [self removeValueForKey: key]; return; } pool = objc_autoreleasePoolPush(); - pairs = [OFMutableArray arrayWithCapacity: array.count]; + pairs = [OFMutableArray arrayWithCapacity: arrayValue.count]; - for (OFString *string in array) { + for (OFString *string in arrayValue) { OFINICategoryPair *pair; if (![string isKindOfClass: [OFString class]]) @throw [OFInvalidArgumentException exception]; @@ -420,11 +421,11 @@ [_lines insertObjectsFromArray: pairs atIndex: i]; replaced = true; /* Continue after inserted pairs */ - i += array.count - 1; + i += arrayValue.count - 1; } else i--; /* Continue at same position */ lines = _lines.objects; count = _lines.count; Index: src/OFINIFileSettings.m ================================================================== --- src/OFINIFileSettings.m +++ src/OFINIFileSettings.m @@ -74,11 +74,12 @@ { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; [self of_getCategory: &category andKey: &key forPath: path]; - [[_INIFile categoryForName: category] setString: string forKey: key]; + [[_INIFile categoryForName: category] setStringValue: string + forKey: key]; objc_autoreleasePoolPop(pool); } - (void)setLongLong: (long long)longLong forPath: (OFString *)path @@ -85,12 +86,12 @@ { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; [self of_getCategory: &category andKey: &key forPath: path]; - [[_INIFile categoryForName: category] setLongLong: longLong - forKey: key]; + [[_INIFile categoryForName: category] setLongLongValue: longLong + forKey: key]; objc_autoreleasePoolPop(pool); } - (void)setBool: (bool)bool_ forPath: (OFString *)path @@ -97,11 +98,11 @@ { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; [self of_getCategory: &category andKey: &key forPath: path]; - [[_INIFile categoryForName: category] setBool: bool_ forKey: key]; + [[_INIFile categoryForName: category] setBoolValue: bool_ forKey: key]; objc_autoreleasePoolPop(pool); } - (void)setFloat: (float)float_ forPath: (OFString *)path @@ -108,11 +109,12 @@ { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; [self of_getCategory: &category andKey: &key forPath: path]; - [[_INIFile categoryForName: category] setFloat: float_ forKey: key]; + [[_INIFile categoryForName: category] setFloatValue: float_ + forKey: key]; objc_autoreleasePoolPop(pool); } - (void)setDouble: (double)double_ forPath: (OFString *)path @@ -119,11 +121,12 @@ { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; [self of_getCategory: &category andKey: &key forPath: path]; - [[_INIFile categoryForName: category] setDouble: double_ forKey: key]; + [[_INIFile categoryForName: category] setDoubleValue: double_ + forKey: key]; objc_autoreleasePoolPop(pool); } - (void)setStringArray: (OFArray OF_GENERIC(OFString *) *)array @@ -131,12 +134,12 @@ { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; [self of_getCategory: &category andKey: &key forPath: path]; - [[_INIFile categoryForName: category] setStringArray: array - forKey: key]; + [[_INIFile categoryForName: category] setArrayValue: array + forKey: key]; objc_autoreleasePoolPop(pool); } - (OFString *)stringForPath: (OFString *)path @@ -144,12 +147,13 @@ { void *pool = objc_autoreleasePoolPush(); OFString *category, *key, *ret; [self of_getCategory: &category andKey: &key forPath: path]; - ret = [[_INIFile categoryForName: category] stringForKey: key - defaultValue: defaultValue]; + ret = [[_INIFile categoryForName: category] + stringValueForKey: key + defaultValue: defaultValue]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @@ -161,12 +165,12 @@ OFString *category, *key; long long ret; [self of_getCategory: &category andKey: &key forPath: path]; ret = [[_INIFile categoryForName: category] - longLongForKey: key - defaultValue: defaultValue]; + longLongValueForKey: key + defaultValue: defaultValue]; objc_autoreleasePoolPop(pool); return ret; } @@ -176,12 +180,13 @@ void *pool = objc_autoreleasePoolPush(); OFString *category, *key; bool ret; [self of_getCategory: &category andKey: &key forPath: path]; - ret = [[_INIFile categoryForName: category] boolForKey: key - defaultValue: defaultValue]; + ret = [[_INIFile categoryForName: category] + boolValueForKey: key + defaultValue: defaultValue]; objc_autoreleasePoolPop(pool); return ret; } @@ -191,12 +196,13 @@ void *pool = objc_autoreleasePoolPush(); OFString *category, *key; float ret; [self of_getCategory: &category andKey: &key forPath: path]; - ret = [[_INIFile categoryForName: category] floatForKey: key - defaultValue: defaultValue]; + ret = [[_INIFile categoryForName: category] + floatValueForKey: key + defaultValue: defaultValue]; objc_autoreleasePoolPop(pool); return ret; } @@ -206,12 +212,13 @@ void *pool = objc_autoreleasePoolPush(); OFString *category, *key; double ret; [self of_getCategory: &category andKey: &key forPath: path]; - ret = [[_INIFile categoryForName: category] doubleForKey: key - defaultValue: defaultValue]; + ret = [[_INIFile categoryForName: category] + doubleValueForKey: key + defaultValue: defaultValue]; objc_autoreleasePoolPop(pool); return ret; } @@ -221,11 +228,11 @@ void *pool = objc_autoreleasePoolPush(); OFString *category, *key; OFArray *ret; [self of_getCategory: &category andKey: &key forPath: path]; - ret = [[_INIFile categoryForName: category] stringArrayForKey: key]; + ret = [[_INIFile categoryForName: category] arrayValueForKey: key]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } Index: tests/OFINIFileTests.m ================================================================== --- tests/OFINIFileTests.m +++ tests/OFINIFileTests.m @@ -64,51 +64,52 @@ TEST(@"-[categoryForName:]", tests != nil && foobar != nil && types != nil) module = @"OFINICategory"; - TEST(@"-[stringForKey:]", - [[tests stringForKey: @"foo"] isEqual: @"bar"] && - [[foobar stringForKey: @"quxquxqux"] isEqual: @"hello\"wörld"]) - - TEST(@"-[setString:forKey:]", - R([tests setString: @"baz" forKey: @"foo"]) && - R([tests setString: @"new" forKey: @"new"]) && - R([foobar setString: @"a\fb" forKey: @"qux3"])) - - TEST(@"-[longLongForKey:defaultValue:]", - [types longLongForKey: @"integer" defaultValue: 2] == 0x20) - - TEST(@"-[setLongLong:forKey:]", - R([types setLongLong: 0x10 forKey: @"integer"])) - - TEST(@"-[boolForKey:defaultValue:]", - [types boolForKey: @"bool" defaultValue: false] == true) - - TEST(@"-[setBool:forKey:]", R([types setBool: false forKey: @"bool"])) - - TEST(@"-[floatForKey:defaultValue:]", - [types floatForKey: @"float" defaultValue: 1] == 0.5f) - - TEST(@"-[setFloat:forKey:]", - R([types setFloat: 0.25f forKey: @"float"])) - - TEST(@"-[doubleForKey:defaultValue:]", - [types doubleForKey: @"double" defaultValue: 3] == 0.25) - - TEST(@"-[setDouble:forKey:]", - R([types setDouble: 0.75 forKey: @"double"])) + TEST(@"-[stringValueForKey:]", + [[tests stringValueForKey: @"foo"] isEqual: @"bar"] && + [[foobar stringValueForKey: @"quxquxqux"] isEqual: @"hello\"wörld"]) + + TEST(@"-[setStringValue:forKey:]", + R([tests setStringValue: @"baz" forKey: @"foo"]) && + R([tests setStringValue: @"new" forKey: @"new"]) && + R([foobar setStringValue: @"a\fb" forKey: @"qux3"])) + + TEST(@"-[longLongValueForKey:defaultValue:]", + [types longLongValueForKey: @"integer" defaultValue: 2] == 0x20) + + TEST(@"-[setLongLongValue:forKey:]", + R([types setLongLongValue: 0x10 forKey: @"integer"])) + + TEST(@"-[boolValueForKey:defaultValue:]", + [types boolValueForKey: @"bool" defaultValue: false] == true) + + TEST(@"-[setBoolValue:forKey:]", + R([types setBoolValue: false forKey: @"bool"])) + + TEST(@"-[floatValueForKey:defaultValue:]", + [types floatValueForKey: @"float" defaultValue: 1] == 0.5f) + + TEST(@"-[setFloatValue:forKey:]", + R([types setFloatValue: 0.25f forKey: @"float"])) + + TEST(@"-[doubleValueForKey:defaultValue:]", + [types doubleValueForKey: @"double" defaultValue: 3] == 0.25) + + TEST(@"-[setDoubleValue:forKey:]", + R([types setDoubleValue: 0.75 forKey: @"double"])) array = [OFArray arrayWithObjects: @"1", @"2", nil]; - TEST(@"-[stringArrayForKey:]", - [[types stringArrayForKey: @"array1"] isEqual: array] && - [[types stringArrayForKey: @"array2"] isEqual: array] && - [[types stringArrayForKey: @"array3"] isEqual: [OFArray array]]) + TEST(@"-[arrayValueForKey:]", + [[types arrayValueForKey: @"array1"] isEqual: array] && + [[types arrayValueForKey: @"array2"] isEqual: array] && + [[types arrayValueForKey: @"array3"] isEqual: [OFArray array]]) array = [OFArray arrayWithObjects: @"foo", @"bar", nil]; - TEST(@"-[setStringArray:forKey:]", - R([types setStringArray: array forKey: @"array1"])) + TEST(@"-[setArrayValue:forKey:]", + R([types setArrayValue: array forKey: @"array1"])) TEST(@"-[removeValueForKey:]", R([foobar removeValueForKey: @"quxqux "]) && R([types removeValueForKey: @"array2"]))