CharIndex

public struct CharIndex { /* private fields */ }

A typed wrapper for a character position within a String.

Unlike ByteIndex, CharIndex carries the byte offset of the underlying character — code-point indexing is O(n), so this pre-resolved offset is what gets stored. Construct one by walking the string yourself; the type is purely a tag for clarity.

Representation

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

Properties

public var byteOffset: Int64

The byte offset where the indexed character begins.

Initializers

public init(Int64)

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

Methods

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

Advances by n code points. Requires the source string to decode UTF-8 boundaries. O(n) in chars advanced.

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: CharIndex) -> 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(CharIndex) -> 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.

ImplementsCharsIndex

Associated Types

type CharsYield = Char

Methods

public func readChars(from: CharsView) -> Char
public func readCharsChecked(from: CharsView) -> Char?

Defined in lang/std/text/views.ks