MCPcopy Index your code
hub / github.com/RustPython/RustPython / line_number_at

Function line_number_at

crates/vm/src/vm/compile.rs:52–58  ·  view source on GitHub ↗

Calculate 1-indexed line number at byte offset in source.

(source: &str, offset: usize)

Source from the content-addressed store, hash-verified

50
51 /// Calculate 1-indexed line number at byte offset in source.
52 fn line_number_at(source: &str, offset: usize) -> usize {
53 source[..offset.min(source.len())]
54 .bytes()
55 .filter(|&b| b == b'\n')
56 .count()
57 + 1
58 }
59
60 /// Get content bounds (start, end byte offsets) of a quoted string literal,
61 /// excluding prefix characters and quote delimiters.

Callers 1

Calls 5

countMethod · 0.45
filterMethod · 0.45
bytesMethod · 0.45
minMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected