Convert a UTF-16 column offset to a byte offset within a single line. LSP positions use UTF-16 code units for the character offset. When a line contains multi-byte characters (e.g. `ń` is 2 bytes in UTF-8 but 1 UTF-16 code unit), the two offsets diverge. This helper walks the line counting UTF-16 code units and returns the corresponding byte position. Returns `line.len()` if `utf16_col` is pas
(line: &str, utf16_col: u32)
| 381 | /// |
| 382 | /// Returns `line.len()` if `utf16_col` is past the end of the line. |
| 383 | pub(crate) fn utf16_col_to_byte_offset(line: &str, utf16_col: u32) -> usize { |
| 384 | let mut col = 0u32; |
| 385 | for (i, ch) in line.char_indices() { |
| 386 | if col == utf16_col { |
| 387 | return i; |
| 388 | } |
| 389 | col += ch.len_utf16() as u32; |
| 390 | } |
| 391 | line.len() |
| 392 | } |
| 393 | |
| 394 | /// Convert a byte offset within a single line to a UTF-16 column offset. |
| 395 | /// |
no outgoing calls
no test coverage detected