Skip to content

Commit fd85bc0

Browse files
committed
Add Pattern.split
1 parent 2aea7ab commit fd85bc0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

vm/src/stdlib/re.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,16 @@ impl PyPattern {
301301
fn pattern(&self, vm: &VirtualMachine) -> PyResult {
302302
Ok(vm.ctx.new_str(self.pattern.clone()))
303303
}
304+
305+
#[pymethod]
306+
fn split(&self, text: PyStringRef, vm: &VirtualMachine) -> PyObjectRef {
307+
let split = self
308+
.regex
309+
.split(text.as_str().as_bytes())
310+
.map(|v| vm.new_str(String::from_utf8_lossy(v).into_owned()))
311+
.collect();
312+
vm.ctx.new_list(split)
313+
}
304314
}
305315

306316
#[pyimpl]

0 commit comments

Comments
 (0)