mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[stdlib] Add ASCII UnicodeEncoding, drop uses of legacy codecs
Preparation for new C-string interop.
This commit is contained in:
@@ -41,10 +41,10 @@ public protocol UnicodeParser {
|
||||
extension UnicodeParser {
|
||||
@inline(__always)
|
||||
@discardableResult
|
||||
public static func decode<I: IteratorProtocol>(
|
||||
public static func parse<I: IteratorProtocol>(
|
||||
_ input: inout I,
|
||||
repairingIllFormedSequences makeRepairs: Bool,
|
||||
into output: (UnicodeScalar)->Void
|
||||
repairingIllFormedSequences makeRepairs: Bool = true,
|
||||
into output: (Encoding.EncodedScalar)->Void
|
||||
) -> Int
|
||||
where I.Element == Encoding.CodeUnit
|
||||
{
|
||||
@@ -53,16 +53,30 @@ extension UnicodeParser {
|
||||
while true {
|
||||
switch d.parseScalar(from: &input) {
|
||||
case let .valid(scalarContent):
|
||||
output(Encoding.decode(scalarContent))
|
||||
output(scalarContent)
|
||||
case .invalid:
|
||||
if !makeRepairs { return 1 }
|
||||
if _slowPath(!makeRepairs) { return 1 }
|
||||
errorCount += 1
|
||||
output(UnicodeScalar(_unchecked: 0xFFFD))
|
||||
output(Encoding.encodedReplacementCharacter)
|
||||
case .emptyInput:
|
||||
return errorCount
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
@discardableResult
|
||||
public static func decode<I: IteratorProtocol>(
|
||||
_ input: inout I,
|
||||
repairingIllFormedSequences makeRepairs: Bool,
|
||||
into output: (UnicodeScalar)->Void
|
||||
) -> Int
|
||||
where I.Element == Encoding.CodeUnit
|
||||
{
|
||||
return parse(&input, repairingIllFormedSequences: makeRepairs) {
|
||||
output(Encoding.decode($0))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension _Unicode {
|
||||
|
||||
Reference in New Issue
Block a user