-
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
12 changed files
with
541 additions
and
389 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import Foundation | ||
import pugixml | ||
|
||
public protocol ElementName: Sendable { | ||
func requestQualifiedName(for node: Node) -> String | ||
func matches(node: pugi.xml_node, in document: Document) -> Bool | ||
} | ||
|
||
extension String: ElementName { | ||
public func requestQualifiedName(for node: Node) -> String { | ||
self | ||
} | ||
public func matches(node: pugi.xml_node, in document: Document) -> Bool { | ||
String(cString: node.name()) == self | ||
} | ||
} | ||
|
||
extension ExpandedName: ElementName { | ||
public func requestQualifiedName(for node: Node) -> String { | ||
requestQualifiedElementName(for: node) | ||
} | ||
|
||
public func matches(node: pugi.xml_node, in document: Document) -> Bool { | ||
String(cString: node.name()).hasSuffix(localName) && document.expandedName(for: node) == self | ||
} | ||
} | ||
|
||
|
||
public protocol AttributeName: Sendable { | ||
func requestQualifiedName(in node: Node) -> String | ||
func qualifiedName(in: Node) -> String? | ||
} | ||
|
||
extension String: AttributeName { | ||
public func requestQualifiedName(in node: Node) -> String { | ||
self | ||
} | ||
|
||
public func qualifiedName(in: Node) -> String? { | ||
self | ||
} | ||
} | ||
|
||
extension ExpandedName: AttributeName { | ||
public func requestQualifiedName(in node: Node) -> String { | ||
requestQualifiedAttributeName(for: node) | ||
} | ||
|
||
public func qualifiedName(in node: Node) -> String? { | ||
if let match = qualifiedAttributeName(in: node) { | ||
return match | ||
} else if let placeholder = node.pendingNameRecord?.attributes[self] { | ||
// Namespace not in scope; try pending placeholder | ||
return placeholder | ||
} else { | ||
return nil | ||
} | ||
} | ||
} |
Oops, something went wrong.