Root Swift package mirroring PureYAML's structure, rules, and verification gates. Includes the XML node model (Node, Element, Attribute, QualifiedName), a working emitter (Serializer) with escaping and pretty/compact options, and structural validation. The parser surface is stable; parse() raises notImplemented until the scanner lands, pinned by a test. - dependency-free, namespaced under PureXML - portability and style gates carried over (style, namespacing, forbidden patterns, swiftformat, swiftlint, linux, wasm, windows CI) - 11 tests passing
40 lines
1.4 KiB
Swift
40 lines
1.4 KiB
Swift
public extension PureXML.Model {
|
|
/// An optionally namespace-prefixed XML name such as `xs:element`.
|
|
struct QualifiedName: Equatable, Hashable, Sendable, CustomStringConvertible {
|
|
/// Namespace prefix preceding the colon, when present (`xs` in `xs:element`).
|
|
public var prefix: String?
|
|
|
|
/// The local part of the name (`element` in `xs:element`).
|
|
public var localName: String
|
|
|
|
public init(prefix: String? = nil, localName: String) {
|
|
self.prefix = prefix
|
|
self.localName = localName
|
|
}
|
|
|
|
/// Parses a raw `prefix:local` or bare `local` name.
|
|
public init(_ raw: String) {
|
|
if let colon = raw.firstIndex(of: ":") {
|
|
let head = String(raw[raw.startIndex ..< colon])
|
|
let tail = String(raw[raw.index(after: colon)...])
|
|
if head.isEmpty || tail.isEmpty {
|
|
prefix = nil
|
|
localName = raw
|
|
} else {
|
|
prefix = head
|
|
localName = tail
|
|
}
|
|
} else {
|
|
prefix = nil
|
|
localName = raw
|
|
}
|
|
}
|
|
|
|
/// The full `prefix:local` rendering used in serialized output.
|
|
public var description: String {
|
|
guard let prefix else { return localName }
|
|
return "\(prefix):\(localName)"
|
|
}
|
|
}
|
|
}
|