MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / token_byte_range

Function token_byte_range

atomic-core/src/diff/semantic/diff_impl.rs:419–430  ·  view source on GitHub ↗

Calculate the byte range for a token at a given index.

(tokens: &[Token<'_>], index: usize)

Source from the content-addressed store, hash-verified

417
418/// Calculate the byte range for a token at a given index.
419pub(super) fn token_byte_range(tokens: &[Token<'_>], index: usize) -> Range<usize> {
420 let mut offset = 0;
421 for (i, token) in tokens.iter().enumerate() {
422 let len = token.content().len();
423 if i == index {
424 return offset..(offset + len);
425 }
426 offset += len;
427 }
428 // Fallback (shouldn't happen with valid indices)
429 offset..offset
430}

Callers 2

test_token_byte_rangeFunction · 0.85

Calls 3

iterMethod · 0.45
lenMethod · 0.45
contentMethod · 0.45

Tested by 1

test_token_byte_rangeFunction · 0.68