Implement stepped slicing for strings
@@ -33,12 +33,10 @@ pub fn subscript(vm: &mut VirtualMachine, value: &String, b: PyObjectRef) -> PyR
// &Some(_) => panic!("Bad stop index for string slicing"),
&None => value.len() as usize,
};
- let step2: usize = match step {
- //Some(step) => step as usize,
- &None => 1 as usize,
- _ => unimplemented!(),
- };
- Ok(vm.new_str(value[start2..stop2].to_string()))
+ Ok(vm.new_str(match step {
+ &None | &Some(1) => value[start2..stop2].to_string(),
+ &Some(num) => value[start2..stop2].chars().step_by(num as usize).collect(),
+ }))
}
_ => panic!(
"TypeError: indexing type {:?} with index {:?} is not supported (yet?)",
