Skip to content

Commit

Permalink
Merge 509bc1a into 138a0be
Browse files Browse the repository at this point in the history
  • Loading branch information
k06a committed Jun 23, 2016
2 parents 138a0be + 509bc1a commit 55b9de6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions XCDYouTubeKit/XCDYouTubePlayerScript.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ - (instancetype) initWithString:(NSString *)string
return nil; // LCOV_EXCL_LINE

NSString *script = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSRegularExpression *anonymousFunctionRegularExpression = [NSRegularExpression regularExpressionWithPattern:@"\\(function\\([^)]*\\)\\{(.*)\\}\\)\\([^)]*\\)" options:NSRegularExpressionDotMatchesLineSeparators error:NULL];
NSRegularExpression *anonymousFunctionRegularExpression = [NSRegularExpression regularExpressionWithPattern:@"\\(function\\(([^)]*)\\)\\{(.*)\\}\\)\\([^)]*\\)" options:NSRegularExpressionDotMatchesLineSeparators error:NULL];
NSTextCheckingResult *anonymousFunctionResult = [anonymousFunctionRegularExpression firstMatchInString:script options:(NSMatchingOptions)0 range:NSMakeRange(0, script.length)];
if (anonymousFunctionResult.numberOfRanges > 1)
script = [script substringWithRange:[anonymousFunctionResult rangeAtIndex:1]];
else
if (anonymousFunctionResult.numberOfRanges > 1) {
NSString *varName = [anonymousFunctionResult rangeAtIndex:1].length ? [script substringWithRange:[anonymousFunctionResult rangeAtIndex:1]] : @"anyVarName";
NSString *functionBody = [script substringWithRange:[anonymousFunctionResult rangeAtIndex:2]];
script = [NSString stringWithFormat:@"%@={};%@", varName, functionBody];
} else
XCDYouTubeLogWarning(@"Unexpected player script (no anonymous function found)");

_context = [JSContext new];
Expand Down

0 comments on commit 55b9de6

Please sign in to comment.