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
public var byteOffset: Int64The byte offset where the indexed character begins.
Initializers
public init(Int64)
public init(Int64)Wraps a pre-resolved byte offset for a character position.
Methods
public func advance(by: Int64, from: StringSlice) -> CharIndex
public func advance(by: Int64, from: StringSlice) -> CharIndexAdvances by n code points. Requires the source string to
decode UTF-8 boundaries. O(n) in chars advanced.
ImplementsEquatable
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: CharIndex) -> Bool
public func isEqual(to: CharIndex) -> 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(CharIndex) -> Ordering
public func compare(CharIndex) -> 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.
ImplementsCharsIndex
Associated Types
type CharsYield = Char
type CharsYield = CharMethods
public func readChars(from: CharsView) -> Char
public func readChars(from: CharsView) -> Charpublic func readCharsChecked(from: CharsView) -> Char?
public func readCharsChecked(from: CharsView) -> Char?Defined in lang/std/text/views.ks