Skip to content
This repository was archived by the owner on Mar 22, 2024. It is now read-only.

Commit f05f6cb

Browse files
committed
impl Pattern.sub
1 parent 36433a9 commit f05f6cb

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

interp.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,27 @@ pub(crate) fn pymatch(
142142
}
143143
}
144144

145+
pub(crate) fn search(
146+
string: PyStrRef,
147+
start: usize,
148+
end: usize,
149+
pattern: PyRef<Pattern>,
150+
) -> Option<Match> {
151+
// TODO: optimize by op info and skip prefix
152+
let end = std::cmp::min(end, string.char_len());
153+
for i in start..end {
154+
if let Some(m) = pymatch(
155+
string.clone(),
156+
i,
157+
end,
158+
pattern.clone(),
159+
) {
160+
return Some(m);
161+
}
162+
}
163+
None
164+
}
165+
145166
#[derive(Debug, Copy, Clone)]
146167
struct MatchContext {
147168
string_position: usize,
@@ -750,7 +771,8 @@ fn charset(set: &[u32], c: char) -> bool {
750771
let (_, blockindices, _) = unsafe { set.align_to::<u8>() };
751772
let blocks = &set[64..];
752773
let block = blockindices[block_index as usize];
753-
if blocks[((block as u32 * 256 + (ch & 255)) / 32) as usize] & (1u32 << (ch & 31))
774+
if blocks[((block as u32 * 256 + (ch & 255)) / 32) as usize]
775+
& (1u32 << (ch & 31))
754776
!= 0
755777
{
756778
return ok;

0 commit comments

Comments
 (0)