chore: simplify String.utf8ByteSize reference implementation
This commit is contained in:
parent
14ed473777
commit
bbe6bd4e72
1 changed files with 5 additions and 5 deletions
|
|
@ -1151,13 +1151,13 @@ instance : Inhabited Substring where
|
|||
def String.csize (c : Char) : Nat :=
|
||||
c.utf8Size.toNat
|
||||
|
||||
private def String.utf8ByteSizeAux : List Char → Nat → Nat
|
||||
| List.nil, r => r
|
||||
| List.cons c cs, r => utf8ByteSizeAux cs (hAdd r (csize c))
|
||||
|
||||
@[extern "lean_string_utf8_byte_size"]
|
||||
def String.utf8ByteSize : (@& String) → Nat
|
||||
| ⟨s⟩ => utf8ByteSizeAux s 0
|
||||
| ⟨s⟩ => go s
|
||||
where
|
||||
go : List Char → Nat
|
||||
| .nil => 0
|
||||
| .cons c cs => hAdd (go cs) (csize c)
|
||||
|
||||
@[inline] def String.bsize (s : String) : Nat :=
|
||||
utf8ByteSize s
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue