a390edf599
While the Node Iterator treats skip & reject the same way, the Tree Walker can skip over a node
and all its children if rejected.
This reverses dc3de7a470
43 lines
683 B
Objective-C
43 lines
683 B
Objective-C
//
|
|
// HTMLNodeFilter.m
|
|
// HTMLKit
|
|
//
|
|
// Created by Iska on 05/06/15.
|
|
// Copyright (c) 2015 BrainCookie. All rights reserved.
|
|
//
|
|
|
|
#import "HTMLNodeFilter.h"
|
|
|
|
@interface HTMLNodeFilterBlock ()
|
|
{
|
|
BOOL (^ _block)(HTMLNode *);
|
|
}
|
|
@end
|
|
|
|
@implementation HTMLNodeFilterBlock
|
|
|
|
+ (instancetype)filterWithBlock:(HTMLNodeFilterValue (^)(HTMLNode *))block
|
|
{
|
|
return [[self alloc] initWithBlock:block];
|
|
}
|
|
|
|
- (instancetype)initWithBlock:(HTMLNodeFilterValue (^)(HTMLNode *))block
|
|
{
|
|
self = [super init];
|
|
if (self) {
|
|
_block = [block copy];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (HTMLNodeFilterValue)acceptNode:(HTMLNode *)node
|
|
{
|
|
if (!_block) {
|
|
return HTMLNodeFilterSkip;
|
|
}
|
|
|
|
return _block(node);
|
|
}
|
|
|
|
@end
|