-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
162 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import Foundation | ||
import pugixml | ||
|
||
internal struct AncestorAttributeSequence: Sequence, IteratorProtocol { | ||
private var node: pugi.xml_node | ||
private var attribute: pugi.xml_attribute | ||
private var current: pugi.xml_attribute? = nil | ||
|
||
init(target: pugi.xml_node) { | ||
node = target | ||
attribute = node.first_attribute() | ||
} | ||
|
||
init(target: Element) { | ||
self.init(target: target.node) | ||
} | ||
|
||
mutating func next() -> pugi.xml_attribute? { | ||
while attribute.empty() { | ||
node = node.parent() | ||
if node.empty() { | ||
return nil | ||
} | ||
attribute = node.first_attribute() | ||
} | ||
|
||
let result = attribute | ||
attribute = attribute.next_attribute() | ||
return result | ||
} | ||
} | ||
|
||
internal extension Element { | ||
var ancestorAttributes: AncestorAttributeSequence { | ||
AncestorAttributeSequence(target: self) | ||
} | ||
} | ||
|
||
internal extension pugi.xml_node { | ||
var ancestorAttributes: AncestorAttributeSequence { | ||
AncestorAttributeSequence(target: self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters