Index: src/OFArray.h ================================================================== --- src/OFArray.h +++ src/OFArray.h @@ -100,21 +100,10 @@ /** * \return The last object of the OFDataArray */ - (id)lastObject; -/** - * Adds an object to the OFDataArray. - * - * \param obj An object to add - */ - addObject: (OFObject*)obj; - -/** - * Removes the specified amount of object from the end of the OFDataArray. - * - * \param nobjects The number of objects to remove - */ - removeNObjects: (size_t)nobjects; @end #import "OFMutableArray.h" Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -198,22 +198,10 @@ return NO; return YES; } -- addObject: (OFObject*)obj -{ - @throw [OFNotImplementedException newWithClass: isa - andSelector: _cmd]; -} - -- removeNObjects: (size_t)nobjects -{ - @throw [OFNotImplementedException newWithClass: isa - andSelector: _cmd]; -} - - (void)dealloc { OFObject **objs; size_t len, i; @@ -227,6 +215,18 @@ [array release]; } [super dealloc]; } + +- addObject: (OFObject*)obj +{ + @throw [OFNotImplementedException newWithClass: isa + andSelector: _cmd]; +} + +- removeNObjects: (size_t)nobjects +{ + @throw [OFNotImplementedException newWithClass: isa + andSelector: _cmd]; +} @end Index: src/OFDictionary.h ================================================================== --- src/OFDictionary.h +++ src/OFDictionary.h @@ -134,31 +134,13 @@ * \param key The key whose object should be returned * \return The object for the given key or nil if the key was not found */ - (id)objectForKey: (OFObject*)key; -/** - * Sets a key to an object. A key can be any object. - * - * \param key The key to set - * \param obj The object to set the key to - */ - setObject: (OFObject*)obj forKey: (OFObject *)key; - -/** - * Remove the object with the given key from the dictionary. - * - * \param key The key whose object should be removed - */ - removeObjectForKey: (OFObject*)key; - -/** - * Changes the hash size of the dictionary. - * - * \param hashsize The new hash size for the dictionary - */ - changeHashSize: (int)hashsize; @end #import "OFIterator.h" #import "OFMutableDictionary.h" Index: src/OFDictionary.m ================================================================== --- src/OFDictionary.m +++ src/OFDictionary.m @@ -334,29 +334,10 @@ return iter->next->object; return nil; } -- setObject: (OFObject*)obj - forKey: (OFObject *)key -{ - @throw [OFNotImplementedException newWithClass: isa - andSelector: _cmd]; -} - -- removeObjectForKey: (OFObject*)key -{ - @throw [OFNotImplementedException newWithClass: isa - andSelector: _cmd]; -} - -- changeHashSize: (int)hashsize -{ - @throw [OFNotImplementedException newWithClass: isa - andSelector: _cmd]; -} - /* FIXME: Implement this! */ /* - (BOOL)isEqual { } @@ -378,6 +359,25 @@ if (data[i] != nil) [data[i] release]; [super dealloc]; } + +- setObject: (OFObject*)obj + forKey: (OFObject *)key +{ + @throw [OFNotImplementedException newWithClass: isa + andSelector: _cmd]; +} + +- removeObjectForKey: (OFObject*)key +{ + @throw [OFNotImplementedException newWithClass: isa + andSelector: _cmd]; +} + +- changeHashSize: (int)hashsize +{ + @throw [OFNotImplementedException newWithClass: isa + andSelector: _cmd]; +} @end Index: src/OFMutableArray.h ================================================================== --- src/OFMutableArray.h +++ src/OFMutableArray.h @@ -14,6 +14,19 @@ /** * The OFMutableArray class provides a class for storing, adding and removing * objects in an array. */ @interface OFMutableArray: OFArray +/** + * Adds an object to the OFDataArray. + * + * \param obj An object to add + */ +- addObject: (OFObject*)obj; + +/** + * Removes the specified amount of objects from the end of the OFDataArray. + * + * \param nobjects The number of objects to remove + */ +- removeNObjects: (size_t)nobjects; @end Index: src/OFMutableDictionary.h ================================================================== --- src/OFMutableDictionary.h +++ src/OFMutableDictionary.h @@ -13,6 +13,28 @@ /** * The OFMutableDictionary class provides a class for using mutable hash tables. */ @interface OFMutableDictionary: OFDictionary +/** + * Sets a key to an object. A key can be any object. + * + * \param key The key to set + * \param obj The object to set the key to + */ +- setObject: (OFObject*)obj + forKey: (OFObject *)key; + +/** + * Remove the object with the given key from the dictionary. + * + * \param key The key whose object should be removed + */ +- removeObjectForKey: (OFObject*)key; + +/** + * Changes the hash size of the dictionary. + * + * \param hashsize The new hash size for the dictionary + */ +- changeHashSize: (int)hashsize; @end Index: src/OFMutableString.h ================================================================== --- src/OFMutableString.h +++ src/OFMutableString.h @@ -16,6 +16,83 @@ /** * A class for storing and modifying strings. */ @interface OFMutableString: OFString +/** + * Sets the OFString to the specified OFString. + * + * \param str An OFString to set the OFString to. + */ +- setToCString: (const char*)str; + +/** + * Appends another OFString to the OFString. + * + * \param str An OFString to append + */ +- append: (OFString*)str; + +/** + * Appends a C string to the OFString. + * + * \param str A C string to append + */ +- appendCString: (const char*)str; + +/** + * Appends a formatted C string to the OFString. + * See printf for the format syntax. + * + * \param fmt A format string which generates the string to append + */ +- appendWithFormat: (OFString*)fmt, ...; + +/** + * Appends a formatted C string to the OFString. + * See printf for the format syntax. + * + * \param fmt A format string which generates the string to append + * \param args The arguments used in the format string + */ +- appendWithFormat: (OFString*)fmt + andArguments: (va_list)args; + +/** + * Reverse the OFString. + */ +- reverse; + +/** + * Upper the OFString. + */ +- upper; + +/** + * Lower the OFString. + */ +- lower; + +/** + * Replaces all occurrences of a string with another string. + * + * \param str The string to replace + * \param repl The string with which it should be replaced + */ +- replaceOccurrencesOfString: (OFString*)str + withString: (OFString*)repl; + +/** + * Removes all whitespaces at the beginning of a string. + */ +- removeLeadingWhitespaces; + +/** + * Removes all whitespaces at the end of a string. + */ +- removeTrailingWhitespaces; + +/** + * Removes all whitespaces at the beginning and the end of a string. + */ +- removeLeadingAndTrailingWhitespaces; @end Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -124,95 +124,32 @@ * \return An integer which is the result of the comparison, see for example * strcmp */ - (int)compare: (id)obj; -/** - * Sets the OFString to the specified OFString. - * - * \param str An OFString to set the OFString to. - */ -- setToCString: (const char*)str; - -/** - * Appends another OFString to the OFString. - * - * \param str An OFString to append - */ -- append: (OFString*)str; - -/** - * Appends a C string to the OFString. - * - * \param str A C string to append - */ -- appendCString: (const char*)str; - -/** - * Appends a formatted C string to the OFString. - * See printf for the format syntax. - * - * \param fmt A format string which generates the string to append - */ -- appendWithFormat: (OFString*)fmt, ...; - -/** - * Appends a formatted C string to the OFString. - * See printf for the format syntax. - * - * \param fmt A format string which generates the string to append - * \param args The arguments used in the format string - */ -- appendWithFormat: (OFString*)fmt - andArguments: (va_list)args; - -/** - * Reverse the OFString. - */ -- reverse; - -/** - * Upper the OFString. - */ -- upper; - -/** - * Lower the OFString. - */ -- lower; - -/** - * Replaces all occurrences of a string with another string. - * - * \param str The string to replace - * \param repl The string with which it should be replaced - */ -- replaceOccurrencesOfString: (OFString*)str - withString: (OFString*)repl; - -/** - * Removes all whitespaces at the beginning of a string. - */ -- removeLeadingWhitespaces; - -/** - * Removes all whitespaces at the end of a string. - */ -- removeTrailingWhitespaces; - -/** - * Removes all whitespaces at the beginning and the end of a string. - */ -- removeLeadingAndTrailingWhitespaces; - /** * Splits an OFString into an OFArray of OFStrings. * * \param delimiter The delimiter for splitting * \return An autoreleased OFArray with the splitted string */ - (OFArray*)splitWithDelimiter: (OFString*)delimiter; + +- setToCString: (const char*)str; +- append: (OFString*)str; +- appendCString: (const char*)str; +- appendWithFormat: (OFString*)fmt, ...; +- appendWithFormat: (OFString*)fmt + andArguments: (va_list)args; +- reverse; +- upper; +- lower; +- replaceOccurrencesOfString: (OFString*)str + withString: (OFString*)repl; +- removeLeadingWhitespaces; +- removeTrailingWhitespaces; +- removeLeadingAndTrailingWhitespaces; @end #import "OFConstString.h" #import "OFMutableString.h" #import "OFURLEncoding.h" Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -306,10 +306,68 @@ OF_HASH_ADD(hash, string[i]); OF_HASH_FINALIZE(hash); return hash; } + +- (OFArray*)splitWithDelimiter: (OFString*)delimiter +{ + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + OFArray *array = nil; + OFString *str; + const char *delim = [delimiter cString]; + size_t delim_len = [delimiter length]; + size_t i, last; + + array = [OFMutableArray array]; + + if (delim_len > length) { + str = [[self copy] autorelease]; + [array addObject: str]; + + [array retain]; + [pool release]; + + return array; + } + + for (i = 0, last = 0; i <= length - delim_len; i++) { + char *tmp; + + if (memcmp(string + i, delim, delim_len)) + continue; + + /* + * We can't use [self allocMemoryWithSize:] here as self might + * be a @""-literal. + */ + if ((tmp = malloc(i - last + 1)) == NULL) + @throw [OFOutOfMemoryException + newWithClass: isa + andSize: i - last + 1]; + memcpy(tmp, string + last, i - last); + tmp[i - last] = '\0'; + @try { + str = [OFString stringWithCString: tmp]; + } @finally { + free(tmp); + } + + [array addObject: str]; + [array retain]; + [pool releaseObjects]; + + i += delim_len - 1; + last = i + 1; + } + [array addObject: [OFString stringWithCString: string + last]]; + + [array retain]; + [pool release]; + + return array; +} - setToCString: (const char*)str { @throw [OFNotImplementedException newWithClass: isa andSelector: _cmd]; @@ -380,64 +438,6 @@ - removeLeadingAndTrailingWhitespaces { @throw [OFNotImplementedException newWithClass: isa andSelector: _cmd]; } - -- (OFArray*)splitWithDelimiter: (OFString*)delimiter -{ - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFArray *array = nil; - OFString *str; - const char *delim = [delimiter cString]; - size_t delim_len = [delimiter length]; - size_t i, last; - - array = [OFMutableArray array]; - - if (delim_len > length) { - str = [[self copy] autorelease]; - [array addObject: str]; - - [array retain]; - [pool release]; - - return array; - } - - for (i = 0, last = 0; i <= length - delim_len; i++) { - char *tmp; - - if (memcmp(string + i, delim, delim_len)) - continue; - - /* - * We can't use [self allocMemoryWithSize:] here as self might - * be a @""-literal. - */ - if ((tmp = malloc(i - last + 1)) == NULL) - @throw [OFOutOfMemoryException - newWithClass: isa - andSize: i - last + 1]; - memcpy(tmp, string + last, i - last); - tmp[i - last] = '\0'; - @try { - str = [OFString stringWithCString: tmp]; - } @finally { - free(tmp); - } - - [array addObject: str]; - [array retain]; - [pool releaseObjects]; - - i += delim_len - 1; - last = i + 1; - } - [array addObject: [OFString stringWithCString: string + last]]; - - [array retain]; - [pool release]; - - return array; -} @end