Index: src/OFMutableData.h ================================================================== --- src/OFMutableData.h +++ src/OFMutableData.h @@ -40,10 +40,22 @@ * Modifying the returned array directly is allowed and will change the contents * of the data. */ @property (readonly, nonatomic) void *mutableItems OF_RETURNS_INNER_POINTER; +/*! + * @brief The first item of the OFMutableData or `NULL`. + */ +@property OF_NULLABLE_PROPERTY (readonly, nonatomic) void *mutableFirstItem + OF_RETURNS_INNER_POINTER; + +/*! + * @brief The last item of the OFMutableData or `NULL`. + */ +@property OF_NULLABLE_PROPERTY (readonly, nonatomic) void *mutableLastItem + OF_RETURNS_INNER_POINTER; + /*! * @brief Creates a new OFMutableData with an item size of 1. * * @return A new autoreleased OFMutableData */ Index: src/OFMutableData.m ================================================================== --- src/OFMutableData.m +++ src/OFMutableData.m @@ -152,10 +152,26 @@ if (idx >= _count) @throw [OFOutOfRangeException exception]; return _items + idx * _itemSize; } + +- (void *)mutableFirstItem +{ + if (_items == NULL || _count == 0) + return NULL; + + return _items; +} + +- (void *)mutableLastItem +{ + if (_items == NULL || _count == 0) + return NULL; + + return _items + (_count - 1) * _itemSize; +} - (OFData *)subdataWithRange: (of_range_t)range { if (range.length > SIZE_MAX - range.location || range.location + range.length > _count)