LineIndex

public struct LineIndex { /* private fields */ }

A typed wrapper for a line position within a string. Stores the byte offset of the line's first byte.

Properties

public var byteOffset: Int64

Initializers

public init(Int64)

Methods

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

Advances by n lines. Scans for line terminators (\n, \r\n, \r) from the current byte offset. O(n) in lines advanced.

Examples

let s = "a\nb\nc"; let idx = s.lines.startIndex; // byte 0 let second = idx.advance(by: 1, from: s.asSlice()); // second.byteOffset == 2 (past "a\n")

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: LineIndex) -> Bool
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(LineIndex) -> 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/slice.ks