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

Method search

crates/sre_engine/src/engine.rs:148–232  ·  view source on GitHub ↗
(&mut self, mut req: Request<'_, S>)

Source from the content-addressed store, hash-verified

146 }
147
148 pub fn search<S: StrDrive>(&mut self, mut req: Request<'_, S>) -> bool {
149 self.start = req.start;
150 req.string.adjust_cursor(&mut self.cursor, self.start);
151
152 if req.start > req.end {
153 return false;
154 }
155
156 let mut end = req.end;
157
158 let mut ctx = MatchContext {
159 cursor: self.cursor,
160 code_position: 0,
161 toplevel: true,
162 jump: Jump::OpCode,
163 repeat_ctx_id: usize::MAX,
164 count: -1,
165 };
166
167 if ctx.peek_code(&req, 0) == SreOpcode::INFO as u32 {
168 /* optimization info block */
169 /* <INFO> <1=skip> <2=flags> <3=min> <4=max> <5=prefix info> */
170 let min = ctx.peek_code(&req, 3) as usize;
171
172 if ctx.remaining_chars(&req) < min {
173 return false;
174 }
175
176 if min > 1 {
177 /* adjust end point (but make sure we leave at least one
178 character in there, so literal search will work) */
179 // no overflow can happen as remaining chars >= min
180 end -= min - 1;
181
182 // adjust ctx position
183 if end < ctx.cursor.position {
184 let skip = end - self.cursor.position;
185 S::skip(&mut self.cursor, skip);
186 }
187 }
188
189 let flags = SreInfo::from_bits_truncate(ctx.peek_code(&req, 2));
190
191 if flags.contains(SreInfo::PREFIX) {
192 if flags.contains(SreInfo::LITERAL) {
193 return search_info_literal::<true, S>(&mut req, self, ctx);
194 } else {
195 return search_info_literal::<false, S>(&mut req, self, ctx);
196 }
197 } else if flags.contains(SreInfo::CHARSET) {
198 return search_info_charset(&mut req, self, ctx);
199 }
200 // fallback to general search
201 // skip OP INFO
202 ctx.skip_code_from(&req, 1);
203 }
204
205 if _match(&req, self, ctx) {

Callers 2

generate_tests.pyFile · 0.45
nextMethod · 0.45

Calls 10

skipFunction · 0.85
search_info_charsetFunction · 0.85
_matchFunction · 0.85
adjust_cursorMethod · 0.80
peek_codeMethod · 0.80
remaining_charsMethod · 0.80
skip_code_fromMethod · 0.80
containsMethod · 0.45
unwrapMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected