Skip to content

Commit 2b342cd

Browse files
committed
Merge pull request #1568 from rintaro/simplify-transcode
[stdlib] Simplify transcode implementation
2 parents 9c998d7 + 1b54593 commit 2b342cd

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

stdlib/public/core/Unicode.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -645,22 +645,20 @@ public func transcode<
645645

646646
var inputDecoder = inputEncoding.init()
647647
var hadError = false
648-
var scalar = inputDecoder.decode(&input)
649-
while !scalar.isEmptyInput() {
650-
switch scalar {
648+
loop:
649+
while true {
650+
switch inputDecoder.decode(&input) {
651651
case .Result(let us):
652652
OutputEncoding.encode(us, output: output)
653653
case .EmptyInput:
654-
_sanityCheckFailure("should not enter the loop when input becomes empty")
654+
break loop
655655
case .Error:
656+
hadError = true
656657
if stopOnError {
657-
return (hadError: true)
658-
} else {
659-
OutputEncoding.encode("\u{fffd}", output: output)
660-
hadError = true
658+
break loop
661659
}
660+
OutputEncoding.encode("\u{fffd}", output: output)
662661
}
663-
scalar = inputDecoder.decode(&input)
664662
}
665663
return hadError
666664
}

0 commit comments

Comments
 (0)