MCPcopy Create free account
hub / github.com/TheRedDeveloper/ply-engine / char_index_to_byte

Function char_index_to_byte

src/text_input.rs:1360–1365  ·  view source on GitHub ↗

Convert a character index to a byte index in the string.

(s: &str, char_idx: usize)

Source from the content-addressed store, hash-verified

1358
1359/// Convert a character index to a byte index in the string.
1360pub 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.

Callers 10

selected_textMethod · 0.85
delete_selectionMethod · 0.85
insert_textMethod · 0.85
backspaceMethod · 0.85
delete_forwardMethod · 0.85
backspace_wordMethod · 0.85
delete_word_forwardMethod · 0.85
selected_text_styledMethod · 0.85
insert_at_visualFunction · 0.85
compute_char_x_positionsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected