From fd85bc0ae35a809d485a49b2c90cd8162573f03d Mon Sep 17 00:00:00 2001 From: coolreader18 <33094578+coolreader18@users.noreply.github.com> Date: Thu, 8 Aug 2019 03:14:26 -0500 Subject: [PATCH] Add Pattern.split --- vm/src/stdlib/re.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/vm/src/stdlib/re.rs b/vm/src/stdlib/re.rs index 209246e13..1f7dbe389 100644 --- a/vm/src/stdlib/re.rs +++ b/vm/src/stdlib/re.rs @@ -301,6 +301,16 @@ impl PyPattern { fn pattern(&self, vm: &VirtualMachine) -> PyResult { Ok(vm.ctx.new_str(self.pattern.clone())) } + + #[pymethod] + fn split(&self, text: PyStringRef, vm: &VirtualMachine) -> PyObjectRef { + let split = self + .regex + .split(text.as_str().as_bytes()) + .map(|v| vm.new_str(String::from_utf8_lossy(v).into_owned())) + .collect(); + vm.ctx.new_list(split) + } } #[pyimpl]