lean4-htt/tests/lean/run/numChars.lean
Markus Himmel eb01aaeee4
chore: rename String.Iterator to String.Legacy.Iterator (#11152)
This PR renames `String.Iterator` to `String.Legacy.Iterator`.

From the docstring of `String.Legacy.Iterator`:

> This is a no-longer-supported legacy API that will be removed in a
future release. You should use
> `String.ValidPos` instead, which is similar, but safer. To iterate
over a string `s`, start with
> `p : s.startValidPos`, advance it using `p.next`, access the current
character using `p.get` and
> check if the position is at the end using `p = s.endValidPos` or
`p.IsAtEnd`.
2025-11-13 13:46:22 +00:00

22 lines
464 B
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

def numChars (s : String) : Nat :=
go s.iter
where
go (i : String.Legacy.Iterator) : Nat :=
if h : i.hasNext then
go i.next + 1
else
0
#guard numChars "aαc" == 3
example : numChars "aαc" = 3 := by native_decide
def numChars2 (s : String) : Nat :=
go s.iter
where
go (i : String.Legacy.Iterator) : Nat :=
match h : i.hasNext with
| true => go i.next + 1
| false => 0
example : numChars2 "aαc" = 3 := by native_decide