(string: &str, n: usize)
| 93 | /// the `n`-th codepoint boundary. Otherwise returns the total codepoint count. |
| 94 | #[inline] |
| 95 | pub(crate) fn char_count_or_boundary(string: &str, n: usize) -> StringCharLen { |
| 96 | let mut count = 0; |
| 97 | for (byte_idx, _) in string.char_indices() { |
| 98 | if count == n { |
| 99 | return StringCharLen::ByteOffset(byte_idx); |
| 100 | } |
| 101 | count += 1; |
| 102 | } |
| 103 | StringCharLen::CharCount(count) |
| 104 | } |
| 105 | |
| 106 | /// Result of [`char_count_or_boundary`]. |
| 107 | pub(crate) enum StringCharLen { |
no outgoing calls
no test coverage detected
searching dependent graphs…