Removed RegexKitLite, reimplemented the only two methods used in a NSString category
This commit is contained in:
1 parent
4e61b461b5
commit
d5a1e7cfcc
11 files changed
+114
-2967
No files matched your search
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// NSString+MP42Additions.m
|
||||
// MP42Foundation
|
||||
//
|
||||
// Created by Damiano Galassi on 18/09/15.
|
||||
// Copyright © 2015 Damiano Galassi. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NSString+MP42Additions.h"
|
||||
|
||||
@implementation NSString (MP42Additions)
|
||||
|
||||
- (NSArray<NSString *> *)MP42_componentsSeparatedByRegex:(NSString *)regex {
|
||||
NSMutableArray<NSString *> *results = [NSMutableArray array];
|
||||
__block NSRange start = NSMakeRange(0, 0);
|
||||
|
||||
NSRegularExpression *r = [NSRegularExpression regularExpressionWithPattern:regex
|
||||
options:NSRegularExpressionCaseInsensitive
|
||||
error:nil];
|
||||
|
||||
[r enumerateMatchesInString:self options:0 range:NSMakeRange(0, self.length) usingBlock:^(NSTextCheckingResult *match, NSMatchingFlags flags, BOOL *stop) {
|
||||
NSRange end = match.range;
|
||||
NSRange componentRange = NSMakeRange(start.location, end.location - start.location);
|
||||
NSString *component = [self substringWithRange:componentRange];
|
||||
if (component.length) {
|
||||
[results addObject:component];
|
||||
}
|
||||
start = NSMakeRange(end.location + end.length, 0);
|
||||
}];
|
||||
|
||||
if (start.location < self.length) {
|
||||
NSRange componentRange = NSMakeRange(start.location, self.length - start.location);
|
||||
NSString *component = [self substringWithRange:componentRange];
|
||||
if (component.length) {
|
||||
[results addObject:component];
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
- (BOOL)MP42_isMatchedByRegex:(NSString *)regex {
|
||||
NSRegularExpression *r = [NSRegularExpression regularExpressionWithPattern:regex
|
||||
options:NSRegularExpressionCaseInsensitive
|
||||
error:nil];
|
||||
|
||||
return ([r matchesInString:self options:0 range:NSMakeRange(0, self.length)].count) > 0;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user