Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dispatch_once to NSRegularExpression init #107

Merged
merged 1 commit into from
Jun 27, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions Source/MMSpanParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -820,9 +820,12 @@ - (MMElement *)_parseAutomaticLinkWithScanner:(MMScanner *)scanner
NSString *linkText = [scanner.string substringWithRange:linkRange];

// Make sure it looks like a link
NSRegularExpression *regex;
static NSRegularExpression *regex;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
regex = [NSRegularExpression regularExpressionWithPattern:@"^(\\w+)://" options:0 error:nil];
});
NSRange matchRange;
regex = [NSRegularExpression regularExpressionWithPattern:@"^(\\w+)://" options:0 error:nil];
matchRange = [regex rangeOfFirstMatchInString:linkText options:0 range:NSMakeRange(0, linkText.length)];
if (matchRange.location == NSNotFound)
return nil;
Expand Down Expand Up @@ -897,11 +900,14 @@ - (MMElement *)_parseAutomaticEmailLinkWithScanner:(MMScanner *)scanner
NSString *linkText = [scanner.string substringWithRange:linkRange];

// Make sure it looks like a link
NSRegularExpression *regex;
static NSRegularExpression *regex;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
regex = [NSRegularExpression regularExpressionWithPattern:@"^[-._0-9\\p{L}]+@[-\\p{L}0-9][-.\\p{L}0-9]*\\.\\p{L}+$"
options:NSRegularExpressionCaseInsensitive
error:nil];
});
NSRange matchRange;
regex = [NSRegularExpression regularExpressionWithPattern:@"^[-._0-9\\p{L}]+@[-\\p{L}0-9][-.\\p{L}0-9]*\\.\\p{L}+$"
options:NSRegularExpressionCaseInsensitive
error:nil];
matchRange = [regex rangeOfFirstMatchInString:linkText options:0 range:NSMakeRange(0, linkText.length)];
if (matchRange.location == NSNotFound)
return nil;
Expand Down