MCPcopy Index your code
hub / github.com/endbasic/endbasic / byte_index_to_char_index

Function byte_index_to_char_index

std/src/strings.rs:82–84  ·  view source on GitHub ↗

Returns the number of characters before the given byte offset within `s`.

(s: &str, byte_index: usize)

Source from the content-addressed store, hash-verified

80
81/// Returns the number of characters before the given byte offset within `s`.
82fn byte_index_to_char_index(s: &str, byte_index: usize) -> usize {
83 s[..byte_index].chars().count()
84}
85
86/// Returns the number of characters in `s`.
87fn char_len(s: &str) -> usize {

Callers 1

execMethod · 0.85

Calls 1

charsMethod · 0.80

Tested by

no test coverage detected