Column (UTF-16 units) of `byte_pos` on line `row`, given `line_starts`.
(src: &str, starts: &[usize], row: usize, byte_pos: usize)
| 97 | |
| 98 | /// Column (UTF-16 units) of `byte_pos` on line `row`, given `line_starts`. |
| 99 | pub fn col16(src: &str, starts: &[usize], row: usize, byte_pos: usize) -> u32 { |
| 100 | let ls = starts.get(row).copied().unwrap_or(0); |
| 101 | if byte_pos <= ls { |
| 102 | return 0; |
| 103 | } |
| 104 | utf16_len(&src[ls..byte_pos]) as u32 |
| 105 | } |
| 106 | |
| 107 | /// JS `String.prototype.slice(0, n)` in UTF-16 units, without splitting a |
| 108 | /// surrogate pair (when the cut would split one, we stop one code unit short — |
no test coverage detected