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`.
22 lines
464 B
Text
22 lines
464 B
Text
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
|