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

Method next

crates/vm/src/builtins/str.rs:358–380  ·  view source on GitHub ↗
(zelf: &Py<Self>, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

356
357impl IterNext for PyStrIterator {
358 fn next(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
359 let mut internal = zelf.internal.lock();
360
361 if let IterStatus::Active(s) = &internal.0.status {
362 let value = s.as_wtf8();
363
364 if internal.1 == usize::MAX {
365 if let Some((offset, ch)) = value.code_point_indices().nth(internal.0.position) {
366 internal.0.position += 1;
367 internal.1 = offset + ch.len_wtf8();
368 return Ok(PyIterReturn::Return(ch.to_pyobject(vm)));
369 }
370 } else if let Some(value) = value.get(internal.1..)
371 && let Some(ch) = value.code_points().next()
372 {
373 internal.0.position += 1;
374 internal.1 += ch.len_wtf8();
375 return Ok(PyIterReturn::Return(ch.to_pyobject(vm)));
376 }
377 internal.0.status = Exhausted;
378 }
379 Ok(PyIterReturn::StopIteration(None))
380 }
381}
382
383#[derive(FromArgs)]

Callers 4

capitalizeMethod · 0.45
splitlinesMethod · 0.45
isidentifierMethod · 0.45
maketransMethod · 0.45

Calls 7

code_point_indicesMethod · 0.80
len_wtf8Method · 0.80
code_pointsMethod · 0.80
lockMethod · 0.45
as_wtf8Method · 0.45
to_pyobjectMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected