Add implementation for FastEnumeration protocol for forin-iteration

This commit is contained in:
iska
2014-11-02 13:54:21 +01:00
parent b0f27e3f2f
commit 2d6889878b
2 changed files with 22 additions and 1 deletions
+1 -1
View File
@@ -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;
+21
View File
@@ -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