-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from optonaut/feature/improveTableViewPerformance
Improve table view performance
- Loading branch information
Showing
5 changed files
with
289 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// RegexParser.swift | ||
// ActiveLabel | ||
// | ||
// Created by Pol Quintana on 06/01/16. | ||
// Copyright © 2016 Optonaut. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
struct RegexParser { | ||
|
||
static let urlPattern = "(^|[\\s.:;?\\-\\]<\\(])" + | ||
"((https?://|www.|pic.)[-\\w;/?:@&=+$\\|\\_.!~*\\|'()\\[\\]%#,☺]+[\\w/#](\\(\\))?)" + | ||
"(?=$|[\\s',\\|\\(\\).:;?\\-\\[\\]>\\)])" | ||
|
||
static let hashtagRegex = try? NSRegularExpression(pattern: "(?:^|\\s|$)#[a-z0-9_]*", options: [.CaseInsensitive]) | ||
static let mentionRegex = try? NSRegularExpression(pattern: "(?:^|\\s|$|[.])@[a-z0-9_]*", options: [.CaseInsensitive]) | ||
static let urlDetector = try? NSRegularExpression(pattern: urlPattern, options: [.CaseInsensitive]) | ||
|
||
static func getMentions(fromText text: String, range: NSRange) -> [NSTextCheckingResult] { | ||
guard let mentionRegex = mentionRegex else { return [] } | ||
return mentionRegex.matchesInString(text, options: [], range: range) | ||
} | ||
|
||
static func getHashtags(fromText text: String, range: NSRange) -> [NSTextCheckingResult] { | ||
guard let hashtagRegex = hashtagRegex else { return [] } | ||
return hashtagRegex.matchesInString(text, options: [], range: range) | ||
} | ||
|
||
static func getURLs(fromText text: String, range: NSRange) -> [NSTextCheckingResult] { | ||
guard let urlDetector = urlDetector else { return [] } | ||
return urlDetector.matchesInString(text, options: [], range: range) | ||
} | ||
|
||
} |
Oops, something went wrong.