GraphemeIndex

public struct GraphemeIndex { /* private fields */ }

A typed wrapper for a grapheme-cluster position within a String.

Like CharIndex but ranges over UAX #29 clusters rather than code points. Stores the byte offset of the cluster's first byte; resolving requires walking the segmenter.

Representation

A single Int64 field holding the byte offset of the grapheme.

Properties

public var byteOffset: Int64

The byte offset where the indexed grapheme begins.

Initializers

public init(Int64)

Wraps a pre-resolved byte offset for a grapheme position.

Methods

public func advance(by: Int64, from: StringSlice) -> GraphemeIndex

Advances by n grapheme clusters. Requires the source slice to run the UAX #29 segmenter forward. O(n) in graphemes advanced.

Examples

let s = "héllo"; let idx = s.graphemes.startIndex; // byte 0 let next = idx.advance(by: 2, from: s.asSlice()); // Skipped 'h' (1 byte) and 'é' (2 bytes) → byte 3

ImplementsEquatable

Associated Types

type Output = Bool

Methods

public func equal(to: Self) -> Bool

Bridges Equal.equal(to:) to Equatable.isEqual(to:).

public func isEqual(to: GraphemeIndex) -> Bool

Returns true if the two indices point at the same byte offset.

public func notEqual(to: Self) -> Bool

Default !=: delegates to == so there's a single source of truth.

ImplementsComparable

Associated Types

type Output = Bool

Methods

public func compare(GraphemeIndex) -> Ordering
public func greaterThan(Self) -> Bool

> derived from compare.

public func greaterThanOrEqual(Self) -> Bool

>= derived from compare.

public func isAtLeast(Self) -> Bool

start.. lower-bound check, derived from compare.

public func isAtMost(Self) -> Bool

..=end upper-bound check, derived from compare.

public func isBelow(Self) -> Bool

..<end upper-bound check, derived from compare.

public func lessThan(Self) -> Bool

< derived from compare.

public func lessThanOrEqual(Self) -> Bool

<= derived from compare.

Defined in lang/std/text/views.ks