Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactoring around initialization of endMentionsRegexp

  • Loading branch information...
commit aa40ae5fee6e3a937008c87cab1bb0493840d0c1 1 parent 470bb2b
@psychs psychs authored
Showing with 11 additions and 5 deletions.
  1. +11 −5 lib/TwitterText.m
View
16 lib/TwitterText.m
@@ -301,6 +301,7 @@
@interface TwitterText ()
+ (NSArray*)hashtagsInText:(NSString*)text withURLEntities:(NSArray*)urlEntities;
+ (NSArray*)cashtagsInText:(NSString*)text withURLEntities:(NSArray*)urlEntities;
++ (NSRegularExpression*)endMentionRegexp;
@end
@implementation TwitterText
@@ -618,7 +619,7 @@ + (NSArray*)mentionsOrListsInText:(NSString*)text
NSRange allRange = matchResult.range;
NSInteger end = NSMaxRange(allRange);
- NSRange endMentionRange = [endMentionRegexp rangeOfFirstMatchInString:text options:0 range:NSMakeRange(end, len - end)];
+ NSRange endMentionRange = [[self endMentionRegexp] rangeOfFirstMatchInString:text options:0 range:NSMakeRange(end, len - end)];
if (endMentionRange.location == NSNotFound) {
NSRange atSignRange = [matchResult rangeAtIndex:2];
NSRange screenNameRange = [matchResult rangeAtIndex:3];
@@ -651,9 +652,6 @@ + (TwitterTextEntity*)repliedScreenNameInText:(NSString*)text
if (!validReplyRegexp) {
validReplyRegexp = [[NSRegularExpression alloc] initWithPattern:TWUValidReply options:NSRegularExpressionCaseInsensitive error:NULL];
}
- if (!endMentionRegexp) {
- endMentionRegexp = [[NSRegularExpression alloc] initWithPattern:TWUEndMentionMatch options:NSRegularExpressionCaseInsensitive error:NULL];
- }
NSInteger len = text.length;
@@ -665,7 +663,7 @@ + (TwitterTextEntity*)repliedScreenNameInText:(NSString*)text
NSRange replyRange = [matchResult rangeAtIndex:1];
NSInteger replyEnd = NSMaxRange(replyRange);
- NSRange endMentionRange = [endMentionRegexp rangeOfFirstMatchInString:text options:0 range:NSMakeRange(replyEnd, len - replyEnd)];
+ NSRange endMentionRange = [[self endMentionRegexp] rangeOfFirstMatchInString:text options:0 range:NSMakeRange(replyEnd, len - replyEnd)];
if (endMentionRange.location != NSNotFound) {
return nil;
}
@@ -741,4 +739,12 @@ + (NSInteger)remainingCharacterCount:(NSString*)text httpURLLength:(NSInteger)ht
return MaxTweetLength - [self tweetLength:text httpURLLength:httpURLLength httpsURLLength:httpsURLLength];
}
++ (NSRegularExpression*)endMentionRegexp
+{
+ if (!endMentionRegexp) {
+ endMentionRegexp = [[NSRegularExpression alloc] initWithPattern:TWUEndMentionMatch options:NSRegularExpressionCaseInsensitive error:NULL];
+ }
+ return endMentionRegexp;
+}
+
@end

0 comments on commit aa40ae5

Please sign in to comment.
Something went wrong with that request. Please try again.