PureXML/Sources/Parsing/StreamingDecoderEUCTW.swift
Mihaela Mihaljevic 380160cc2b refactor(validation): decompose XSD instance validation into composable rules
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.
2026-07-12 14:12:17 +02:00

28 lines
1.1 KiB
Swift

extension PureXML.Parsing.StreamingDecoder {
/// Streams one EUC-TW character: ASCII, a two-byte plane-1 pair, or a `0x8E`
/// four-byte plane selector plus a pair.
mutating func nextEUCTW() -> Character? {
guard let lead = nextByte() else {
finished = true
return nil
}
if lead <= 0x7F {
return Character(Unicode.Scalar(lead))
}
if lead == 0x8E {
guard let plane = nextByte(), let byte1 = nextByte(), let byte2 = nextByte() else {
finished = true
return Self.replacement
}
return PureXML.Parsing.ByteDecoder.EUCTW.fourByteScalar(plane, byte1, byte2).map(Character.init) ?? Self.replacement
}
guard (0xA1 ... 0xFE).contains(lead) else { return Self.replacement }
guard let trail = nextByte() else {
finished = true
return Self.replacement
}
let table = PureXML.Parsing.ByteDecoder.eucTWPlane1
return PureXML.Parsing.ByteDecoder.EUCTW.planeScalar(table, lead, trail).map(Character.init) ?? Self.replacement
}
}