MCPcopy Create free account
hub / github.com/bendudson/EuraliOS / rfind

Method rfind

edit/src/main.rs:167–186  ·  view source on GitHub ↗

Reverse find, starting from the given cursor If found, returns a Cursor pointing to the location, and the number of characters traversed

(&self, start: Cursor, pattern: u8)

Source from the content-addressed store, hash-verified

165 // Reverse find, starting from the given cursor
166 // If found, returns a Cursor pointing to the location, and the number of characters traversed
167 fn rfind(&self, start: Cursor, pattern: u8) -> Option<(Cursor, usize)> {
168 // Number of characters traversed
169 let mut ntraversed: usize = 0;
170 let mut cursor = start;
171 loop {
172 if let Some(c) = self.previous(cursor) {
173 cursor = c;
174 } else {
175 break None;
176 }
177
178 // Count characters. NOTE: Assumes ASCII
179 ntraversed += 1;
180
181 // Get the byte at this location
182 if self.at(cursor) == pattern {
183 break Some((cursor, ntraversed));
184 }
185 }
186 }
187}
188
189struct Buffer<'a>(&'a mut [u8], usize);

Callers 1

mainFunction · 0.80

Calls 2

previousMethod · 0.80
atMethod · 0.80

Tested by

no test coverage detected