position

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package position provides utilities for working with source code positions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteRangeToLines

func ByteRangeToLines(content []byte, start, end int) (int, int)

ByteRangeToLines converts byte positions to line numbers. Returns (startLine, endLine) where both are 1-indexed. The end position is exclusive (past-the-end), matching Go AST conventions.

func JoinLines

func JoinLines(lines []string) string

JoinLines joins lines with newline characters.

func SplitLines

func SplitLines(content []byte) []string

SplitLines splits content into lines by newline characters.

Types

type LineIndex

type LineIndex struct {
	// contains filtered or unexported fields
}

LineIndex helps convert byte offsets to line numbers efficiently using binary search. It pre-indexes all newline positions for O(log n) line number lookups.

func NewLineIndex

func NewLineIndex(content []byte) *LineIndex

NewLineIndex creates an index from file content. It records the byte offset of each newline character.

func (*LineIndex) Line

func (li *LineIndex) Line(offset int) int

Line returns the 1-based line number for a byte offset. Uses binary search for O(log n) performance. If offset is out of bounds, returns the last line number.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL