Contents

Unicode.CanonicalCombiningClass

The classification of a scalar used in the Canonical Ordering Algorithm defined by the Unicode Standard.

Declaration

struct CanonicalCombiningClass

Overview

Canonical combining classes are used by the ordering algorithm to determine if two sequences of combining marks should be considered canonically equivalent (that is, identical in interpretation). Two sequences are canonically equivalent if they are equal when sorting the scalars in ascending order by their combining class.

For example, consider the sequence "\u{0041}\u{0301}\u{0316}" (LATIN CAPITAL LETTER A, COMBINING ACUTE ACCENT, COMBINING GRAVE ACCENT BELOW). The combining classes of these scalars have the numeric values 0, 230, and 220, respectively. Sorting these scalars by their combining classes yields "\u{0041}\u{0316}\u{0301}", so two strings that differ only by the ordering of those scalars would compare as equal:

let aboveBeforeBelow = "\u{0041}\u{0301}\u{0316}"
let belowBeforeAbove = "\u{0041}\u{0316}\u{0301}"
print(aboveBeforeBelow == belowBeforeAbove)
// Prints "true"

Named and Unnamed Combining Classes

Canonical combining classes are defined in the Unicode Standard as integers in the range 0...254. For convenience, the standard assigns symbolic names to a subset of these combining classes.

The CanonicalCombiningClass type conforms to RawRepresentable with a raw value of type UInt8. You can create instances of the type by using the static members named after the symbolic names, or by using the init(rawValue:) initializer.

let overlayClass = Unicode.CanonicalCombiningClass(rawValue: 1)
let overlayClassIsOverlay = overlayClass == .overlay
// overlayClassIsOverlay == true

Topics

Operators

Initializers

Instance Properties

Instance Methods

Type Aliases

Type Properties

Default Implementations

See Also

Unicode Scalar Classifications