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
public var byteOffset: Int64The byte offset where the indexed grapheme begins.
Initializers
public init(Int64)
public init(Int64)Wraps a pre-resolved byte offset for a grapheme position.
Methods
public func advance(by: Int64, from: StringSlice) -> GraphemeIndex
public func advance(by: Int64, from: StringSlice) -> GraphemeIndexAdvances 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 3ImplementsEquatable
Associated Types
type Output = Bool
type Output = BoolMethods
public func equal(to: Self) -> Bool
public func equal(to: Self) -> BoolBridges Equal.equal(to:) to Equatable.isEqual(to:).
public func isEqual(to: GraphemeIndex) -> Bool
public func isEqual(to: GraphemeIndex) -> BoolReturns true if the two indices point at the same byte offset.
public func notEqual(to: Self) -> Bool
public func notEqual(to: Self) -> BoolDefault !=: delegates to == so there's a single source of truth.
ImplementsComparable
Associated Types
type Output = Bool
type Output = BoolMethods
public func compare(GraphemeIndex) -> Ordering
public func compare(GraphemeIndex) -> Orderingpublic func greaterThan(Self) -> Bool
public func greaterThan(Self) -> Bool> derived from compare.
public func greaterThanOrEqual(Self) -> Bool
public func greaterThanOrEqual(Self) -> Bool>= derived from compare.
public func isAtLeast(Self) -> Bool
public func isAtLeast(Self) -> Boolstart.. lower-bound check, derived from compare.
public func isAtMost(Self) -> Bool
public func isAtMost(Self) -> Bool..=end upper-bound check, derived from compare.
public func isBelow(Self) -> Bool
public func isBelow(Self) -> Bool..<end upper-bound check, derived from compare.
public func lessThan(Self) -> Bool
public func lessThan(Self) -> Bool< derived from compare.
public func lessThanOrEqual(Self) -> Bool
public func lessThanOrEqual(Self) -> Bool<= derived from compare.
Defined in lang/std/text/views.ks