Add DOM method for computing a common ancestor of two nodes
This commit is contained in:
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user