MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / line_starts

Function line_starts

codegraph-kernel/src/textutil.rs:162–180  ·  view source on GitHub ↗

Byte offsets of each line start, for UTF-16 column conversion.

(src: &str)

Source from the content-addressed store, hash-verified

160
161/// Byte offsets of each line start, for UTF-16 column conversion.
162pub fn line_starts(src: &str) -> LineStarts {
163 let mut starts = vec![0usize];
164 for (i, b) in src.bytes().enumerate() {
165 if b == b'\n' {
166 starts.push(i + 1);
167 }
168 }
169 let mut wide = Vec::new();
170 if !src.is_ascii() {
171 let mut spare = 0usize;
172 for (at, c) in src.char_indices() {
173 if c.len_utf8() > 1 {
174 spare += c.len_utf8() - c.len_utf16();
175 wide.push((at, spare));
176 }
177 }
178 }
179 LineStarts { starts, wide }
180}
181
182/// UTF-16 code units in `s` — what web-tree-sitter (and JS string ops)
183/// count, so kernel-emitted columns are byte-identical to the wasm path's.

Callers 15

extractFunction · 0.70
extractFunction · 0.70
extractFunction · 0.70
extractFunction · 0.70
extractFunction · 0.70
extractFunction · 0.70
extractFunction · 0.70
extractFunction · 0.70
utf16_colsFunction · 0.70
extractFunction · 0.70
extractFunction · 0.70

Calls 2

bytesMethod · 0.80
pushMethod · 0.80

Tested by 2

utf16_colsFunction · 0.56