The sink closure is called with each resulting UTF-32 code unit as the
function iterates over its input.
Parameters:input: An iterator of code units to be translated, encoded as
inputEncoding. If stopOnError is false, the entire iterator will
be exhausted. Otherwise, iteration will stop if an encoding error is
detected.
inputEncoding: The Unicode encoding of input.
outputEncoding: The destination Unicode encoding.
stopOnError: Pass true to stop translation when an encoding error is
detected in input. Otherwise, a Unicode replacement character
("\u{FFFD}") is inserted for each detected error.
processCodeUnit: A closure that processes one outputEncoding code
unit at a time.
Returns:true if the translation detected encoding errors in input;
otherwise, false.
Translates the given input from one Unicode encoding to another by calling the given closure.
The following example transcodes the UTF-8 representation of the string
"Fermata 𝄐"
into UTF-32.The
sink
closure is called with each resulting UTF-32 code unit as the function iterates over its input.Parameters: input: An iterator of code units to be translated, encoded as
inputEncoding
. IfstopOnError
isfalse
, the entire iterator will be exhausted. Otherwise, iteration will stop if an encoding error is detected. inputEncoding: The Unicode encoding ofinput
. outputEncoding: The destination Unicode encoding. stopOnError: Passtrue
to stop translation when an encoding error is detected ininput
. Otherwise, a Unicode replacement character ("\u{FFFD}"
) is inserted for each detected error. processCodeUnit: A closure that processes oneoutputEncoding
code unit at a time. Returns:true
if the translation detected encoding errors ininput
; otherwise,false
.Declaration
func
transcode
<
Input
,
InputEncoding
,
OutputEncoding
where
Input
:
IteratorProtocol
,
InputEncoding
:
UnicodeCodec
,
OutputEncoding
:
UnicodeCodec
,
InputEncoding
.
CodeUnit
==
Input
.
Element
>
(
_
input
:
Input
,
from
inputEncoding
:
InputEncoding
.
Type
,
to
outputEncoding
:
OutputEncoding
.
Type
,
stoppingOnError
stopOnError
:
Bool
,
into
processCodeUnit
: (
OutputEncoding
.
CodeUnit
) -
>
Swift
.
Void
) -
>
Bool