Refactor "adoption agency algorithm" blocks into their corresponding wrappers
This commit is contained in:
@@ -27,6 +27,8 @@
|
||||
- (void)addMarker;
|
||||
- (void)clearUptoLastMarker;
|
||||
|
||||
- (HTMLElement *)formattingElementWithTagName:(NSString *)tagName;
|
||||
|
||||
- (NSUInteger)count;
|
||||
- (BOOL)isEmpty;
|
||||
|
||||
|
||||
@@ -88,6 +88,17 @@
|
||||
[_list removeLastObject];
|
||||
}
|
||||
|
||||
- (HTMLElement *)formattingElementWithTagName:(NSString *)tagName
|
||||
{
|
||||
for (HTMLElement *element in _list.reverseObjectEnumerator) {
|
||||
if ([element isEqual:[HTMLMarker marker]]) return nil;
|
||||
if ([element.tagName isEqualToString:tagName]) {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
#pragma mark - Count
|
||||
|
||||
- (NSUInteger)count
|
||||
|
||||
+2
-20
@@ -410,16 +410,7 @@
|
||||
|
||||
for (int outerLoopCounter = 0; outerLoopCounter < 8; outerLoopCounter++) {
|
||||
|
||||
HTMLElement *formattingElement = ^ HTMLElement * {
|
||||
for (HTMLElement *element in _listOfActiveFormattingElements.reverseObjectEnumerator) {
|
||||
if ([element isEqualTo:[HTMLMarker marker]]) return nil;
|
||||
if ([element.tagName isEqualTo:tagName]) {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}();
|
||||
|
||||
HTMLElement *formattingElement = [_listOfActiveFormattingElements formattingElementWithTagName:tagName];
|
||||
if (formattingElement == nil) {
|
||||
return YES;
|
||||
}
|
||||
@@ -440,16 +431,7 @@
|
||||
}
|
||||
|
||||
NSUInteger formattingElementIndex = [_stackOfOpenElements indexOfElement:formattingElement];
|
||||
|
||||
HTMLElement *furthestBlock = ^ HTMLElement * {
|
||||
for (NSUInteger i = formattingElementIndex; i < _stackOfOpenElements.count; i++) {
|
||||
HTMLElement *element = _stackOfOpenElements[i];
|
||||
if (IsSpecialElement(element)) {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}();
|
||||
HTMLElement *furthestBlock = [_stackOfOpenElements furthestBlockAfterIndex:formattingElementIndex];
|
||||
|
||||
if (furthestBlock == nil) {
|
||||
[_stackOfOpenElements popElementsUntilElementPopped:formattingElement];
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
- (HTMLElement *)hasElementInButtonScopeWithTagName:(NSString *)tagName;
|
||||
- (HTMLElement *)hasElementInTableScopeWithTagName:(NSString *)tagName;
|
||||
- (HTMLElement *)hasElementInSelectScopeWithTagName:(NSString *)tagName;
|
||||
- (HTMLElement *)furthestBlockAfterIndex:(NSUInteger)index;
|
||||
|
||||
- (NSUInteger)count;
|
||||
- (BOOL)isEmpy;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#import "HTMLStackOfOpenElements.h"
|
||||
#import "NSString+HTMLKit.h"
|
||||
#import "HTMLElementTypes.h"
|
||||
|
||||
@interface HTMLStackOfOpenElements ()
|
||||
{
|
||||
@@ -227,6 +228,17 @@
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (HTMLElement *)furthestBlockAfterIndex:(NSUInteger)index
|
||||
{
|
||||
for (NSUInteger i = index; i < _stack.count; i++) {
|
||||
HTMLElement *element = _stack[i];
|
||||
if (IsSpecialElement(element)) {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
#pragma mark - Count
|
||||
|
||||
- (NSUInteger)count
|
||||
|
||||
Reference in New Issue
Block a user