The two monolithic XSD content/identity rules only satisfied the OpenAPIKit validation idiom at the wrong granularity: no per-constraint removability, no isolable failing/near-miss tests. Split them into 32 named rules, each finding tagged at its origin and cached per XSDContext so the walk still runs once per document (the #101 decision against duplicating XSD's recursive type resolution still holds). Wired the streaming path's ID/IDREF and identity checks through the same framework instead of calling the validators imperatively, and added the unwrapAndLookup combinator the rule already named as required. Also includes the mandated repo-wide swiftformat/swiftlint pass.
45 lines
1.6 KiB
Swift
45 lines
1.6 KiB
Swift
extension PureXML.XSLT.XSLTParser {
|
|
/// Parses an attribute value template: literal text with `{expr}` embedded
|
|
/// XPath expressions, where `{{` and `}}` are literal braces.
|
|
static func valueTemplate(_ string: String) -> PureXML.XSLT.ValueTemplate {
|
|
var parts: [PureXML.XSLT.ValuePart] = []
|
|
var literal = ""
|
|
let characters = Array(string)
|
|
var index = 0
|
|
while index < characters.count {
|
|
let character = characters[index]
|
|
if character == "{", index + 1 < characters.count, characters[index + 1] == "{" {
|
|
literal.append("{")
|
|
index += 2
|
|
continue
|
|
}
|
|
if character == "}", index + 1 < characters.count, characters[index + 1] == "}" {
|
|
literal.append("}")
|
|
index += 2
|
|
continue
|
|
}
|
|
if character == "{" {
|
|
if !literal.isEmpty {
|
|
parts.append(.literal(literal))
|
|
literal = ""
|
|
}
|
|
index += 1
|
|
var expression = ""
|
|
while index < characters.count, characters[index] != "}" {
|
|
expression.append(characters[index])
|
|
index += 1
|
|
}
|
|
index += 1
|
|
parts.append(.expression(expression))
|
|
continue
|
|
}
|
|
literal.append(character)
|
|
index += 1
|
|
}
|
|
if !literal.isEmpty {
|
|
parts.append(.literal(literal))
|
|
}
|
|
return parts
|
|
}
|
|
}
|