UTF16

struct UTF16

A codec for UTF-16.

Inheritance UnicodeCodecType View Protocol Hierarchy →
Associated Types
CodeUnit = UInt16

A type that can hold code unit values for this encoding.

Import import Swift

Initializers

init()

Declaration

init()

Static Methods

static func encode(_:output:)

Encode a UnicodeScalar as a series of CodeUnits by calling output on each CodeUnit.

Declaration

static func encode(input: UnicodeScalar, output put: (CodeUnit) -> Void)
static func isLeadSurrogate(_:)

Declaration

static func isLeadSurrogate(x: CodeUnit) -> Bool
static func isTrailSurrogate(_:)

Declaration

static func isTrailSurrogate(x: CodeUnit) -> Bool
static func leadSurrogate(_:)

Returns the high surrogate code unit of a surrogate pair representing x.

Requires: width(x) == 2.

Declaration

static func leadSurrogate(x: UnicodeScalar) -> CodeUnit
static func measure(_:input:repairIllFormedSequences:)

Returns the number of UTF-16 code units required for the given code unit sequence when transcoded to UTF-16, and a bit describing if the sequence was found to contain only ASCII characters.

If repairIllFormedSequences is true, the function always succeeds. If it is false, nil is returned if an ill-formed code unit sequence is found in input.

Declaration

static func measure<Encoding : UnicodeCodecType, Input : GeneratorType where Encoding.CodeUnit == Input.Element>(_: Encoding.Type, input: Input, repairIllFormedSequences: Bool) -> (Int, Bool)?
static func trailSurrogate(_:)

Returns the low surrogate code unit of a surrogate pair representing x.

Requires: width(x) == 2.

Declaration

static func trailSurrogate(x: UnicodeScalar) -> CodeUnit
static func width(_:)

Returns the number of code units required to encode x.

Declaration

static func width(x: UnicodeScalar) -> Int

Instance Methods

mutating func decode(inout:)

Start or continue decoding a UTF sequence.

In order to decode a code unit sequence completely, this function should be called repeatedly until it returns UnicodeDecodingResult.EmptyInput. Checking that the generator was exhausted is not sufficient. The decoder can have an internal buffer that is pre-filled with data from the input generator.

Because of buffering, it is impossible to find the corresponding position in the generator for a given returned UnicodeScalar or an error.

next: A generator of code units to be decoded.

Declaration

mutating func decode<G : GeneratorType where G.Element == CodeUnit>(inout input: G) -> UnicodeDecodingResult