Calculate the byte range for a token at a given index.
(tokens: &[Token<'_>], index: usize)
| 417 | |
| 418 | /// Calculate the byte range for a token at a given index. |
| 419 | pub(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 | } |