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

Function split_lines

src/text_input.rs:1435–1449  ·  view source on GitHub ↗

Split text into lines (by '\n'), returning each line's text and the global char index where it starts.

(text: &str)

Source from the content-addressed store, hash-verified

1433/// Split text into lines (by '\n'), returning each line's text
1434/// and the global char index where it starts.
1435pub fn split_lines(text: &str) -> Vec<(usize, &str)> {
1436 let mut result = Vec::new();
1437 let mut char_start = 0;
1438 let mut byte_start = 0;
1439 for (byte_idx, ch) in text.char_indices() {
1440 if ch == '\n' {
1441 result.push((char_start, &text[byte_start..byte_idx]));
1442 char_start += text[byte_start..byte_idx].chars().count() + 1; // +1 for '\n'
1443 byte_start = byte_idx + 1; // '\n' is 1 byte
1444 }
1445 }
1446 // Last line (after final '\n' or entire text if no '\n')
1447 result.push((char_start, &text[byte_start..]));
1448 result
1449}
1450
1451/// A single visual line after word-wrapping.
1452#[derive(Debug, Clone)]

Callers 3

wrap_linesFunction · 0.85
test_split_linesFunction · 0.85

Calls

no outgoing calls

Tested by 2

test_split_linesFunction · 0.68