MCPcopy Index your code
hub / github.com/RustPython/RustPython / count_substring

Function count_substring

crates/vm/src/bytes_inner.rs:987–994  ·  view source on GitHub ↗
(haystack: &[u8], needle: &[u8], max_count: Option<usize>)

Source from the content-addressed store, hash-verified

985
986#[inline]
987fn count_substring(haystack: &[u8], needle: &[u8], max_count: Option<usize>) -> usize {
988 let substrings = haystack.find_iter(needle);
989 if let Some(max_count) = max_count {
990 core::cmp::min(substrings.take(max_count).count(), max_count)
991 } else {
992 substrings.count()
993 }
994}
995
996pub trait ByteOr: ToPrimitive {
997 fn byte_or(&self, vm: &VirtualMachine) -> PyResult<u8> {

Callers 2

replace_deleteMethod · 0.85
replace_generalMethod · 0.85

Calls 4

minFunction · 0.85
find_iterMethod · 0.80
countMethod · 0.45
takeMethod · 0.45

Tested by

no test coverage detected