@@ -634,6 +634,7 @@ theorem utf8ByteSize_push {s : String} {c : Char} :
634634 (s.push c).utf8ByteSize = s.utf8ByteSize + c.utf8Size := by
635635 simp [← size_bytes, List.utf8Encode_singleton]
636636
637+ @[simp]
637638theorem rawEndPos_push {s : String} {c : Char} : (s.push c).rawEndPos = s.rawEndPos + c := by
638639 simp [Pos.Raw.ext_iff]
639640
@@ -1130,6 +1131,11 @@ theorem Slice.Pos.get_eq_utf8DecodeChar {s : Slice} (pos : s.Pos) (h : pos ≠ s
11301131 pos.get h = s.str.bytes.utf8DecodeChar (s.startInclusive.offset.byteIdx + pos.offset.byteIdx)
11311132 ((Pos.Raw.isValidForSlice_iff_isSome_utf8DecodeChar?.1 pos.isValidForSlice).elim (by simp_all [Pos.ext_iff]) (·.2 )) := (rfl)
11321133
1134+ theorem Slice.Pos.utf8Encode_get_eq_extract {s : Slice} (pos : s.Pos) (h : pos ≠ s.endPos) :
1135+ List.utf8Encode [pos.get h] = s.str.bytes.extract (s.startInclusive.offset.byteIdx + pos.offset.byteIdx)
1136+ (s.startInclusive.offset.byteIdx + pos.offset.byteIdx + (pos.get h).utf8Size) := by
1137+ rw [get_eq_utf8DecodeChar pos h, List.utf8Encode_singleton, ByteArray.utf8EncodeChar_utf8DecodeChar]
1138+
11331139/-- Returns the byte at the given position in the string, or `none` if the position is the end
11341140position. -/
11351141@[expose]
@@ -1495,6 +1501,14 @@ theorem Slice.Pos.lt_next {s : Slice} {pos : s.Pos} {h : pos ≠ s.endPos} :
14951501 pos < pos.next h := by
14961502 simp [Pos.lt_iff, Pos.Raw.lt_iff, Char.utf8Size_pos]
14971503
1504+ theorem Slice.Pos.copy_eq_copy_replaceEnd_append_get {s : Slice} {pos : s.Pos} (h : pos ≠ s.endPos) :
1505+ s.copy = (s.replaceEnd pos).copy ++ singleton (pos.get h) ++ (s.replaceStart (pos.next h)).copy := by
1506+ suffices (max (s.startInclusive.offset.byteIdx + (pos.offset.byteIdx + (pos.get h).utf8Size)) s.endExclusive.offset.byteIdx)
1507+ = s.endExclusive.offset.byteIdx by
1508+ simp [← bytes_inj, bytes_copy, utf8Encode_get_eq_extract, Nat.add_assoc, this]
1509+ rw [Nat.max_eq_right]
1510+ simpa [Pos.Raw.le_iff] using (pos.next h).offset_str_le_offset_endExclusive
1511+
14981512@[inline, expose]
14991513def Slice.Pos.prevAux {s : Slice} (pos : s.Pos) (h : pos ≠ s.startPos) : String.Pos.Raw :=
15001514 go (pos.offset.byteIdx - 1 ) (by
@@ -1861,10 +1875,13 @@ abbrev utf8SetAux (c' : Char) : List Char → Pos.Raw → Pos.Raw → List Char
18611875 Pos.Raw.utf8SetAux c'
18621876
18631877@[simp]
1864- theorem ValidPos.toSlice_get {s : String} {p : s.ValidPos} {h} :
1878+ theorem ValidPos.get_toSlice {s : String} {p : s.ValidPos} {h} :
18651879 p.toSlice.get h = p.get (ne_of_apply_ne (·.toSlice) (by simp_all)) := by
18661880 rfl
18671881
1882+ theorem ValidPos.get_eq_get_toSlice {s : String} {p : s.ValidPos} {h} :
1883+ p.get h = p.toSlice.get (ne_of_apply_ne Slice.Pos.ofSlice (by simp [h])) := rfl
1884+
18681885@[simp]
18691886theorem ValidPos.offset_next {s : String} (p : s.ValidPos) (h : p ≠ s.endValidPos) :
18701887 (p.next h).offset = p.offset + p.get h := by
@@ -1943,6 +1960,14 @@ theorem Pos.Raw.isValidForSlice_stringReplaceStart {s : String} {p : s.ValidPos}
19431960 rw [replaceStart, isValidForSlice_replaceStart, isValidForSlice_toSlice_iff,
19441961 ValidPos.offset_toSlice]
19451962
1963+ theorem ValidPos.utf8Encode_get_eq_extract {s : String} (pos : s.ValidPos) (h : pos ≠ s.endValidPos) :
1964+ List.utf8Encode [pos.get h] = s.bytes.extract pos.offset.byteIdx (pos.offset.byteIdx + (pos.get h).utf8Size) := by
1965+ rw [get_eq_get_toSlice, Slice.Pos.utf8Encode_get_eq_extract]
1966+ simp
1967+
1968+ theorem ValidPos.eq_copy_replaceEnd_append_get {s : String} {pos : s.ValidPos} (h : pos ≠ s.endValidPos) :
1969+ s = (s.replaceEnd pos).copy ++ singleton (pos.get h) ++ (s.replaceStart (pos.next h)).copy := by
1970+ simp [← bytes_inj, utf8Encode_get_eq_extract pos h, Slice.bytes_copy, ← size_bytes]
19461971
19471972/--
19481973Returns the next position in a string after position `p`. If `p` is not a valid position or
0 commit comments