Add selector initializer for creating instances with a given selector string

This commit is contained in:
iska
2015-11-29 19:53:39 +01:00
parent f3af320096
commit 991e868d14
2 changed files with 13 additions and 1 deletions
+2 -1
View File
@@ -44,6 +44,7 @@ extern NSString * _Nonnull NSStringFromNthExpression(CSSNthExpression expression
@interface CSSSelector : NSObject
- (BOOL)acceptElement:(nonnull HTMLElement *)element;
+ (nullable instancetype)selectorWithString:(NSString *)stirng;
- (BOOL)acceptElement:(HTMLElement *)element;
@end
+11
View File
@@ -8,9 +8,20 @@
#import <Foundation/Foundation.h>
#import "CSSSelector.h"
#import "CSSSelectorParser.h"
@implementation CSSSelector
+ (instancetype)selectorWithString:(NSString *)string
{
NSError *error = nil;
CSSSelector *instance = [CSSSelectorParser parseSelector:string error:&error];
if (error) {
return nil;
}
return instance;
}
- (BOOL)acceptElement:(HTMLElement *)element
{
[self doesNotRecognizeSelector:_cmd];