Convert a character index to a byte index in the string.
(s: &str, char_idx: usize)
| 1358 | |
| 1359 | /// Convert a character index to a byte index in the string. |
| 1360 | pub fn char_index_to_byte(s: &str, char_idx: usize) -> usize { |
| 1361 | s.char_indices() |
| 1362 | .nth(char_idx) |
| 1363 | .map(|(byte_pos, _)| byte_pos) |
| 1364 | .unwrap_or(s.len()) |
| 1365 | } |
| 1366 | |
| 1367 | /// Find the char index of the start of the line containing `char_pos`. |
| 1368 | /// A "line" is delimited by '\n'. Returns 0 for the first line. |
no outgoing calls
no test coverage detected