@@ -982,7 +982,7 @@ end ByteArray.utf8DecodeChar?
982982
983983open ByteArray.utf8DecodeChar?
984984
985- /- # `utf8DecodeChar?` and `validateUtf8At ` -/
985+ /- # `utf8DecodeChar?` and `validateUTF8At ` -/
986986
987987@[inline, expose]
988988public def ByteArray.utf8DecodeChar? (bytes : ByteArray) (i : Nat) : Option Char :=
@@ -1006,7 +1006,7 @@ public def ByteArray.utf8DecodeChar? (bytes : ByteArray) (i : Nat) : Option Char
10061006 else none
10071007
10081008@[inline, expose]
1009- public def ByteArray.validateUtf8At (bytes : ByteArray) (i : Nat) : Bool :=
1009+ public def ByteArray.validateUTF8At (bytes : ByteArray) (i : Nat) : Bool :=
10101010 if h₀ : i < bytes.size then
10111011 match h : parseFirstByte bytes[i] with
10121012 | .invalid => false
@@ -1212,9 +1212,9 @@ public theorem String.toByteArray_utf8EncodeChar_of_utf8DecodeChar?_eq_some {b :
12121212 rw [← assemble₄_eq_some_iff_utf8EncodeChar_eq]
12131213 exact ⟨this, h⟩
12141214
1215- public theorem ByteArray.validateUtf8At_eq_isSome_utf8DecodeChar ? {b : ByteArray} {i : Nat} :
1216- b.validateUtf8At i = (b.utf8DecodeChar? i).isSome := by
1217- simp only [validateUtf8At , utf8DecodeChar?]
1215+ public theorem ByteArray.validateUTF8At_eq_isSome_utf8DecodeChar ? {b : ByteArray} {i : Nat} :
1216+ b.validateUTF8At i = (b.utf8DecodeChar? i).isSome := by
1217+ simp only [validateUTF8At , utf8DecodeChar?]
12181218 split
12191219 · split <;> (try split) <;> simp [verify₁_eq_isSome_assemble₁, verify₂_eq_isSome_assemble₂,
12201220 verify₃_eq_isSome_assemble₃, verify₄_eq_isSome_assemble₄]
@@ -1285,9 +1285,9 @@ public theorem ByteArray.lt_size_of_isSome_utf8DecodeChar? {b : ByteArray} {i :
12851285 have := c.utf8Size_pos
12861286 omega
12871287
1288- public theorem ByteArray.lt_size_of_validateUtf8At {b : ByteArray} {i : Nat} :
1289- validateUtf8At b i = true → i < b.size :=
1290- validateUtf8At_eq_isSome_utf8DecodeChar ? ▸ lt_size_of_isSome_utf8DecodeChar?
1288+ public theorem ByteArray.lt_size_of_validateUTF8At {b : ByteArray} {i : Nat} :
1289+ validateUTF8At b i = true → i < b.size :=
1290+ validateUTF8At_eq_isSome_utf8DecodeChar ? ▸ lt_size_of_isSome_utf8DecodeChar?
12911291
12921292public theorem ByteArray.utf8DecodeChar?_append_eq_some {b : ByteArray} {i : Nat} {c : Char} (h : utf8DecodeChar? b i = some c)
12931293 (b' : ByteArray) : utf8DecodeChar? (b ++ b') i = some c := by
@@ -1366,7 +1366,7 @@ public theorem List.utf8DecodeChar_utf8Encode_cons {l : List Char} {c : Char} {h
13661366 ByteArray.utf8DecodeChar (c::l).utf8Encode 0 h = c := by
13671367 simp [ByteArray.utf8DecodeChar]
13681368
1369- /-! # `UInt8.IsUtf8FirstByte ` -/
1369+ /-! # `UInt8.IsUTF8FirstByte ` -/
13701370
13711371namespace UInt8
13721372
@@ -1375,27 +1375,27 @@ Predicate for whether a byte can appear as the first byte of the UTF-8 encoding
13751375scalar value.
13761376-/
13771377@[expose]
1378- public def IsUtf8FirstByte (c : UInt8) : Prop :=
1378+ public def IsUTF8FirstByte (c : UInt8) : Prop :=
13791379 c &&& 0x80 = 0 ∨ c &&& 0xe0 = 0xc0 ∨ c &&& 0xf0 = 0xe0 ∨ c &&& 0xf8 = 0xf0
13801380
1381- public instance {c : UInt8} : Decidable c.IsUtf8FirstByte :=
1381+ public instance {c : UInt8} : Decidable c.IsUTF8FirstByte :=
13821382 inferInstanceAs <| Decidable (c &&& 0x80 = 0 ∨ c &&& 0xe0 = 0xc0 ∨ c &&& 0xf0 = 0xe0 ∨ c &&& 0xf8 = 0xf0 )
13831383
1384- theorem isUtf8FirstByte_iff_parseFirstByte_ne_invalid {c : UInt8} :
1385- c.IsUtf8FirstByte ↔ parseFirstByte c ≠ FirstByte.invalid := by
1386- fun_cases parseFirstByte with simp_all [IsUtf8FirstByte ]
1384+ theorem isUTF8FirstByte_iff_parseFirstByte_ne_invalid {c : UInt8} :
1385+ c.IsUTF8FirstByte ↔ parseFirstByte c ≠ FirstByte.invalid := by
1386+ fun_cases parseFirstByte with simp_all [IsUTF8FirstByte ]
13871387
13881388@[simp]
1389- public theorem isUtf8FirstByte_getElem_utf8EncodeChar {c : Char} {i : Nat} {hi : i < (String.utf8EncodeChar c).length} :
1390- (String.utf8EncodeChar c)[i].IsUtf8FirstByte ↔ i = 0 := by
1389+ public theorem isUTF8FirstByte_getElem_utf8EncodeChar {c : Char} {i : Nat} {hi : i < (String.utf8EncodeChar c).length} :
1390+ (String.utf8EncodeChar c)[i].IsUTF8FirstByte ↔ i = 0 := by
13911391 obtain (rfl|hi₀) := Nat.eq_zero_or_pos i
1392- · simp only [isUtf8FirstByte_iff_parseFirstByte_ne_invalid , iff_true]
1392+ · simp only [isUTF8FirstByte_iff_parseFirstByte_ne_invalid , iff_true]
13931393 match h : c.utf8Size, c.utf8Size_pos, c.utf8Size_le_four with
13941394 | 1 , _, _ => simp [parseFirstByte_utf8EncodeChar_eq_done h]
13951395 | 2 , _, _ => simp [parseFirstByte_utf8EncodeChar_eq_oneMore h]
13961396 | 3 , _, _ => simp [parseFirstByte_utf8EncodeChar_eq_twoMore h]
13971397 | 4 , _, _ => simp [parseFirstByte_utf8EncodeChar_eq_threeMore h]
1398- · simp only [isUtf8FirstByte_iff_parseFirstByte_ne_invalid , ne_eq, Nat.ne_of_lt' hi₀, iff_false,
1398+ · simp only [isUTF8FirstByte_iff_parseFirstByte_ne_invalid , ne_eq, Nat.ne_of_lt' hi₀, iff_false,
13991399 Classical.not_not]
14001400 apply parseFirstByte_eq_invalid_of_isInvalidContinuationByte_eq_false
14011401 simp only [String.length_utf8EncodeChar] at hi
@@ -1408,12 +1408,12 @@ public theorem isUtf8FirstByte_getElem_utf8EncodeChar {c : Char} {i : Nat} {hi :
14081408 | 4 , _, _, 2 , _, _ => simp [isInvalidContinuationByte_getElem_utf8EncodeChar_two_of_utf8Size_eq_four h]
14091409 | 4 , _, _, 3 , _, _ => simp [isInvalidContinuationByte_getElem_utf8EncodeChar_three_of_utf8Size_eq_four h]
14101410
1411- public theorem isUtf8FirstByte_getElem_zero_utf8EncodeChar {c : Char} :
1412- ((String.utf8EncodeChar c)[0 ]'(by simp [c.utf8Size_pos])).IsUtf8FirstByte := by
1411+ public theorem isUTF8FirstByte_getElem_zero_utf8EncodeChar {c : Char} :
1412+ ((String.utf8EncodeChar c)[0 ]'(by simp [c.utf8Size_pos])).IsUTF8FirstByte := by
14131413 simp
14141414
14151415@[expose]
1416- public def utf8ByteSize (c : UInt8) (_h : c.IsUtf8FirstByte ) : String.Pos.Raw :=
1416+ public def utf8ByteSize (c : UInt8) (_h : c.IsUTF8FirstByte ) : String.Pos.Raw :=
14171417 if c &&& 0x80 = 0 then
14181418 ⟨1 ⟩
14191419 else if c &&& 0xe0 = 0xc0 then
@@ -1430,7 +1430,7 @@ def _root_.ByteArray.utf8DecodeChar?.FirstByte.utf8ByteSize : FirstByte → Stri
14301430 | .twoMore => ⟨3 ⟩
14311431 | .threeMore => ⟨4 ⟩
14321432
1433- theorem utf8ByteSize_eq_utf8ByteSize_parseFirstByte {c : UInt8} {h : c.IsUtf8FirstByte } :
1433+ theorem utf8ByteSize_eq_utf8ByteSize_parseFirstByte {c : UInt8} {h : c.IsUTF8FirstByte } :
14341434 c.utf8ByteSize h = (parseFirstByte c).utf8ByteSize := by
14351435 simp only [utf8ByteSize, FirstByte.utf8ByteSize, parseFirstByte, beq_iff_eq]
14361436 split
@@ -1447,28 +1447,28 @@ theorem utf8ByteSize_eq_utf8ByteSize_parseFirstByte {c : UInt8} {h : c.IsUtf8Fir
14471447
14481448end UInt8
14491449
1450- public theorem ByteArray.isUtf8FirstByte_getElem_zero_utf8EncodeChar_append {c : Char} {b : ByteArray} :
1451- (((String.utf8EncodeChar c).toByteArray ++ b)[0 ]'(by simp; have := c.utf8Size_pos; omega)).IsUtf8FirstByte := by
1450+ public theorem ByteArray.isUTF8FirstByte_getElem_zero_utf8EncodeChar_append {c : Char} {b : ByteArray} :
1451+ (((String.utf8EncodeChar c).toByteArray ++ b)[0 ]'(by simp; have := c.utf8Size_pos; omega)).IsUTF8FirstByte := by
14521452 rw [ByteArray.getElem_append_left (by simp [c.utf8Size_pos]),
1453- List.getElem_toByteArray, UInt8.isUtf8FirstByte_getElem_utf8EncodeChar ]
1453+ List.getElem_toByteArray, UInt8.isUTF8FirstByte_getElem_utf8EncodeChar ]
14541454
1455- public theorem ByteArray.isUtf8FirstByte_of_isSome_utf8DecodeChar ? {b : ByteArray} {i : Nat}
1456- (h : (utf8DecodeChar? b i).isSome) : (b[i]'(lt_size_of_isSome_utf8DecodeChar? h)).IsUtf8FirstByte := by
1455+ public theorem ByteArray.isUTF8FirstByte_of_isSome_utf8DecodeChar ? {b : ByteArray} {i : Nat}
1456+ (h : (utf8DecodeChar? b i).isSome) : (b[i]'(lt_size_of_isSome_utf8DecodeChar? h)).IsUTF8FirstByte := by
14571457 rw [utf8DecodeChar?_eq_utf8DecodeChar?_extract] at h
1458- suffices ((b.extract i b.size)[0 ]'(lt_size_of_isSome_utf8DecodeChar? h)).IsUtf8FirstByte by
1458+ suffices ((b.extract i b.size)[0 ]'(lt_size_of_isSome_utf8DecodeChar? h)).IsUTF8FirstByte by
14591459 simpa [ByteArray.getElem_extract, Nat.add_zero] using this
14601460 obtain ⟨c, hc⟩ := Option.isSome_iff_exists.1 h
14611461 conv => congr; congr; rw [eq_of_utf8DecodeChar?_eq_some hc]
1462- exact isUtf8FirstByte_getElem_zero_utf8EncodeChar_append
1462+ exact isUTF8FirstByte_getElem_zero_utf8EncodeChar_append
14631463
1464- public theorem ByteArray.isUtf8FirstByte_of_validateUtf8At {b : ByteArray} {i : Nat} :
1465- (h : validateUtf8At b i = true ) → (b[i]'(lt_size_of_validateUtf8At h)).IsUtf8FirstByte := by
1466- simp only [validateUtf8At_eq_isSome_utf8DecodeChar ?]
1467- exact isUtf8FirstByte_of_isSome_utf8DecodeChar ?
1464+ public theorem ByteArray.isUTF8FirstByte_of_validateUTF8At {b : ByteArray} {i : Nat} :
1465+ (h : validateUTF8At b i = true ) → (b[i]'(lt_size_of_validateUTF8At h)).IsUTF8FirstByte := by
1466+ simp only [validateUTF8At_eq_isSome_utf8DecodeChar ?]
1467+ exact isUTF8FirstByte_of_isSome_utf8DecodeChar ?
14681468
14691469theorem Char.byteIdx_utf8ByteSize_getElem_utf8EncodeChar {c : Char} :
14701470 (((String.utf8EncodeChar c)[0 ]'(by simp [c.utf8Size_pos])).utf8ByteSize
1471- UInt8.isUtf8FirstByte_getElem_zero_utf8EncodeChar ).byteIdx = c.utf8Size := by
1471+ UInt8.isUTF8FirstByte_getElem_zero_utf8EncodeChar ).byteIdx = c.utf8Size := by
14721472 rw [UInt8.utf8ByteSize_eq_utf8ByteSize_parseFirstByte]
14731473 obtain (hc|hc|hc|hc) := c.utf8Size_eq
14741474 · rw [parseFirstByte_utf8EncodeChar_eq_done hc, FirstByte.utf8ByteSize, hc]
@@ -1478,7 +1478,7 @@ theorem Char.byteIdx_utf8ByteSize_getElem_utf8EncodeChar {c : Char} :
14781478
14791479public theorem ByteArray.utf8Size_utf8DecodeChar {b : ByteArray} {i} {h} :
14801480 (utf8DecodeChar b i h).utf8Size =
1481- ((b[i]'(lt_size_of_isSome_utf8DecodeChar? h)).utf8ByteSize (isUtf8FirstByte_of_isSome_utf8DecodeChar ? h)).byteIdx := by
1481+ ((b[i]'(lt_size_of_isSome_utf8DecodeChar? h)).utf8ByteSize (isUTF8FirstByte_of_isSome_utf8DecodeChar ? h)).byteIdx := by
14821482 rw [← Char.byteIdx_utf8ByteSize_getElem_utf8EncodeChar]
14831483 simp only [List.getElem_eq_getElem_toByteArray, utf8EncodeChar_utf8DecodeChar]
14841484 simp [ByteArray.getElem_extract]
0 commit comments