Add block-based API for Node Filter

- HTMLNodeFilterBlock is a block-based class implementation conforming to HTMLNodeFilter
- HTMLNode & NodeIterator get block-based initializers
This commit is contained in:
iska
2015-06-05 18:06:23 +02:00
parent dc3de7a470
commit 40400864d8
8 changed files with 86 additions and 19 deletions
+8 -19
View File
@@ -9,23 +9,6 @@
#import <XCTest/XCTest.h>
#import "HTMLDOM.h"
@interface CommentNodeFilter : NSObject <HTMLNodeFilter>
@end
@implementation CommentNodeFilter
- (BOOL)acceptNode:(HTMLNode *)node
{
if (node.nodeType == HTMLNodeComment) {
if ([[(HTMLComment *)node data] rangeOfString:@"second"].location != NSNotFound) {
return YES;
}
}
return NO;
}
@end
@interface HTMLKitNodeIteratorTests : XCTestCase
@end
@@ -327,8 +310,14 @@
{
HTMLDocument *document = self.mixedTree;
HTMLNodeIterator *iterator = [document nodeIteratorWithShowOptions:HTMLNodeFilterShowAll
filter:[CommentNodeFilter new]];
HTMLNodeIterator *iterator = [document nodeIteratorWithShowOptions:HTMLNodeFilterShowAll filterBlock:^BOOL(HTMLNode *node) {
if (node.nodeType == HTMLNodeComment) {
if ([[(HTMLComment *)node data] rangeOfString:@"second"].location != NSNotFound) {
return YES;
}
}
return NO;
}];
NSArray *result = iterator.allObjects;
NSArray *expected = @[@"#comment"];