Add implementation for FastEnumeration protocol for forin-iteration
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
* HTML Tokenizer
|
||||
* https://html.spec.whatwg.org/multipage/syntax.html#tokenization
|
||||
*/
|
||||
@interface HTMLTokenizer : NSObject
|
||||
@interface HTMLTokenizer : NSObject <NSFastEnumeration>
|
||||
|
||||
@property (nonatomic, assign) HTMLTokenizerState state;
|
||||
|
||||
|
||||
@@ -125,6 +125,27 @@
|
||||
[self switchToState:state];
|
||||
}
|
||||
|
||||
#pragma mark - Fast Enumeration
|
||||
|
||||
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(__unsafe_unretained id [])buffer count:(NSUInteger)len
|
||||
{
|
||||
if (state->state == 0) {
|
||||
state->mutationsPtr = &state->extra[0];
|
||||
state->state = 1;
|
||||
}
|
||||
|
||||
HTMLToken *nextToken = [self nextToken];
|
||||
|
||||
if (nextToken == nil) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
__unsafe_unretained const id *const_ptr = (__unsafe_unretained id *)(__bridge void *)nextToken;
|
||||
state->itemsPtr = (__typeof__(state->itemsPtr))const_ptr;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#pragma mark - Emits
|
||||
|
||||
- (void)emitToken:(HTMLToken *)token
|
||||
|
||||
Reference in New Issue
Block a user