Index: src/OFMutableString.h ================================================================== --- src/OFMutableString.h +++ src/OFMutableString.h @@ -113,10 +113,17 @@ * This points BEHIND the last character! */ - removeCharactersFromIndex: (size_t)start toIndex: (size_t)end; +/** + * Removes the characters at the specified range. + * + * \param range The range of the characters which should be removed + */ +- removeCharactersInRange: (of_range_t)range; + /** * 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 Index: src/OFMutableString.m ================================================================== --- src/OFMutableString.m +++ src/OFMutableString.m @@ -17,13 +17,13 @@ #include #include #include #ifdef HAVE_MADVISE -#include +# include #else -#define madvise(addr, len, advise) +# define madvise(addr, len, advise) #endif #import "OFString.h" #import "OFExceptions.h" #import "macros.h" @@ -407,10 +407,16 @@ [e dealloc]; } return self; } + +- removeCharactersInRange: (of_range_t)range +{ + return [self removeCharactersFromIndex: range.start + toIndex: range.start + range.length]; +} - replaceOccurrencesOfString: (OFString*)str withString: (OFString*)repl { const char *str_c = [str cString]; Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -17,19 +17,27 @@ #import /** * A result of a comparison. */ -typedef enum { +typedef enum __of_comparison_result { /// The left object is smaller than the right OF_ORDERED_ASCENDING = -1, /// Both objects are equal OF_ORDERED_SAME = 0, /// The left object is bigger than the right OF_ORDERED_DESCENDING = 1 } of_comparison_result_t; +/** + * A range. + */ +typedef struct __of_range { + size_t start; + size_t length; +} of_range_t; + /** * The OFObject class is the base class for all other classes inside ObjFW. */ @interface OFObject { Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -244,10 +244,16 @@ * \return The substring as a new autoreleased OFString */ - (OFString*)substringFromIndex: (size_t)start toIndex: (size_t)end; +/** + * \param range The range of the substring + * \return The substring as a new autoreleased OFString + */ +- (OFString*)substringWithRange: (of_range_t)range; + /** * Creates a new string by appending another string. * * \param str The string to append * \return A new autoreleased OFString with the specified string appended Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -735,10 +735,16 @@ @throw [OFOutOfRangeException newWithClass: isa]; return [OFString stringWithCString: string + start length: end - start]; } + +- (OFString*)substringWithRange: (of_range_t)range +{ + return [self substringFromIndex: range.start + toIndex: range.start + range.length]; +} - (OFString*)stringByAppendingString: (OFString*)str { return [[OFMutableString stringWithString: self] appendString: str]; }