diff --git a/PantomimeFramework/PantomimeFramework/NSData+Extensions.h b/PantomimeFramework/PantomimeFramework/NSData+Extensions.h index b8db21e..853b3a9 100644 --- a/PantomimeFramework/PantomimeFramework/NSData+Extensions.h +++ b/PantomimeFramework/PantomimeFramework/NSData+Extensions.h @@ -158,6 +158,9 @@ */ - (NSData *) subdataToIndex: (NSUInteger) theIndex; +/// Like `subDataWithRange`, but doesn't copy bytes, and instead points to the bytes from the original. +- (NSData *)subdataUncopiedWithRange:(NSRange)range; + /** @discussion Simple method to trim the leading and trailing whitespaces (characters with no visible representation). Cahracters currently taken into accout are: diff --git a/pantomime-lib/Framework/Pantomime/NSData+Extensions.m b/pantomime-lib/Framework/Pantomime/NSData+Extensions.m index b7dbba7..00faad7 100644 --- a/pantomime-lib/Framework/Pantomime/NSData+Extensions.m +++ b/pantomime-lib/Framework/Pantomime/NSData+Extensions.m @@ -437,6 +437,13 @@ static const char *hexDigit = "0123456789ABCDEF"; return [self subdataWithRange: NSMakeRange(0, theIndex)]; } +- (NSData *)subdataUncopiedWithRange:(NSRange)range +{ + const char *theBytes = [self bytes]; + const char *newBytes = theBytes + range.location; + return [NSData dataWithBytesNoCopy:(void *) newBytes length:range.length]; +} + - (NSData *)dataByTrimmingWhiteSpaces { const char *bytes = [self bytes];