MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / find_in

Method find_in

atomic-core/src/diff/split.rs:112–133  ·  view source on GitHub ↗

Find the next occurrence of this separator in the given bytes. Returns the index of the start of the separator, or None if not found.

(&self, haystack: &[u8])

Source from the content-addressed store, hash-verified

110 ///
111 /// Returns the index of the start of the separator, or None if not found.
112 fn find_in(&self, haystack: &[u8]) -> Option<usize> {
113 match self {
114 Separator::Newline => haystack.iter().position(|&b| b == b'\n'),
115 Separator::Byte(b) => haystack.iter().position(|&x| x == *b),
116 Separator::CrLf => {
117 // Find \r\n sequence
118 if haystack.len() < 2 {
119 return None;
120 }
121 haystack.windows(2).position(|window| window == b"\r\n")
122 }
123 Separator::Custom(needle) => {
124 if needle.is_empty() || needle.len() > haystack.len() {
125 return None;
126 }
127 // Simple substring search
128 haystack
129 .windows(needle.len())
130 .position(|window| window == needle.as_slice())
131 }
132 }
133 }
134}
135
136/// An iterator that splits content into lines based on a separator.

Callers 1

nextMethod · 0.80

Calls 5

positionMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45
is_emptyMethod · 0.45
as_sliceMethod · 0.45

Tested by

no test coverage detected