Add DOM method for computing a common ancestor of two nodes

This commit is contained in:
iska
2016-12-29 22:54:14 +01:00
parent 4d132af99f
commit fb04d49693
2 changed files with 15 additions and 4 deletions
+3 -2
View File
@@ -7,7 +7,8 @@
//
#import <Foundation/Foundation.h>
#import "HTMLDOM.h"
@interface HTMLDOMUtils : NSObject
@class HTMLNode;
@end
extern HTMLNode * GetCommonAncestorContainer(HTMLNode *nodeA, HTMLNode *nodeB);
+12 -2
View File
@@ -7,7 +7,17 @@
//
#import "HTMLDOMUtils.h"
#import "HTMLNode.h"
@implementation HTMLDOMUtils
extern HTMLNode * GetCommonAncestorContainer(HTMLNode *nodeA, HTMLNode *nodeB)
{
for (HTMLNode *parentA = nodeA; parentA != nil; parentA = parentA.parentNode) {
for (HTMLNode *parentB = nodeB; parentB != nil; parentB = parentB.parentNode) {
if (parentA == parentB) {
return parentA;
}
}
}
@end
return nil;
}