Add selector initializer for creating instances with a given selector string
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user