Browse Source

IOS-2794 Optimized componentsSeparatedByCString

IOS-2794
Dirk Zimmermann 1 year ago
parent
commit
977caf2398
2 changed files with 27 additions and 0 deletions
  1. +4
    -0
      PantomimeFramework/PantomimeFramework/NSData+Extensions.h
  2. +23
    -0
      pantomime-lib/Framework/Pantomime/NSData+Extensions.m

+ 4
- 0
PantomimeFramework/PantomimeFramework/NSData+Extensions.h View File

@ -260,6 +260,10 @@
*/
- (NSArray *) componentsSeparatedByCString: (const char *) theCString;
/// Like `componentsSeparatedByCString`, but calls the given block with each result and the current count.
- (void)componentsSeparatedByCString:(const char *)theCString
block:(void (^)(NSData *, NSUInteger))block;
/*!
@method asciiString
@discussion This method turns the receiver into a NSString object.


+ 23
- 0
pantomime-lib/Framework/Pantomime/NSData+Extensions.m View File

@ -776,6 +776,29 @@ static const char *hexDigit = "0123456789ABCDEF";
return AUTORELEASE(aMutableArray);
}
- (void)componentsSeparatedByCString:(const char *)theCString
block:(void (^)(NSData *, NSUInteger))block
{
NSUInteger len = [self length];
NSRange r1 = NSMakeRange(0,len);
NSRange r2 = [self rangeOfCString: theCString
options: 0
range: r1];
NSUInteger count = 0;
while (r2.length) {
block([self subdataWithRange: NSMakeRange(r1.location, r2.location - r1.location)], count);
count++;
r1.location = r2.location + r2.length;
r1.length = len - r1.location;
r2 = [self rangeOfCString: theCString options: 0 range: r1];
}
block([self subdataWithRange: NSMakeRange(r1.location, len - r1.location)], count);
}
//
//


Loading…
Cancel
Save