Skip to content

Source: Implement line/column lookup from Span #5

@pdaxt

Description

@pdaxt

Component

Foundation / Source

Task

Implement line/column lookup from byte offset.

Acceptance Criteria

  • line_col(offset: u32) -> (u32, u32) returns 1-indexed line and column
  • line_start(line: u32) -> u32 returns byte offset of line start
  • line_content(line: u32) -> &str returns the line content
  • Cache line offsets for O(log n) lookups

Verify

let src = Source::new("test", "line1\nline2\nline3");
assert_eq!(src.line_col(6), (2, 1)); // start of line2
assert_eq!(src.line_content(2), "line2");

Security Testing (REQUIRED)

  • Test with various line endings (\n, \r\n, \r)
  • Test empty lines and trailing newlines
  • Test offset at exact line boundaries
  • Test out-of-bounds offsets
  • Test with single-line files (no newlines)
  • Verify binary search correctness

Ref: FOUNDATION.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    foundationFoundation tier componentssourceSource component

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions