Skip to content

Commit

Permalink
Simplify regular expression code
Browse files Browse the repository at this point in the history
  • Loading branch information
0xced committed Nov 24, 2014
1 parent 450c89a commit d0bab52
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions XCDYouTubeKit/XCDYouTubePlayerScript.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@ - (instancetype) initWithString:(NSString *)string
if ([script hasPrefix:jsPrologue] && [script hasSuffix:jsEpilogue])
script = [script substringWithRange:NSMakeRange(jsPrologue.length, script.length - (jsPrologue.length + jsEpilogue.length))];

__block NSString *signatureFunctionName = nil;
NSRegularExpression *signatureRegularExpression = [NSRegularExpression regularExpressionWithPattern:@"[\"']signature[\"']\\s*,\\s*([^\\(]+)" options:NSRegularExpressionCaseInsensitive error:NULL];
[signatureRegularExpression enumerateMatchesInString:script options:(NSMatchingOptions)0 range:NSMakeRange(0, script.length) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop)
{
signatureFunctionName = [script substringWithRange:[result rangeAtIndex:1]];
*stop = YES;
}];
NSTextCheckingResult *result = [signatureRegularExpression firstMatchInString:script options:(NSMatchingOptions)0 range:NSMakeRange(0, script.length)];
NSString *signatureFunctionName = result.numberOfRanges > 1 ? [script substringWithRange:[result rangeAtIndex:1]] : nil;

if (!signatureFunctionName)
return nil;
Expand Down

0 comments on commit d0bab52

Please sign in to comment.