@@ -89,11 +89,25 @@ theorem Slice.Pos.splits {s : Slice} (p : s.Pos) :
8989 eq_append := copy_eq_copy_replaceEnd
9090 offset_eq_rawEndPos := by simp
9191
92+ theorem ValidPos.Splits.bytes_left_eq {s : String} {p : s.ValidPos} {t₁ t₂}
93+ (h : p.Splits t₁ t₂) : t₁.bytes = s.bytes.extract 0 p.offset.byteIdx := by
94+ simp [h.eq_append, h.offset_eq_rawEndPos, ByteArray.extract_append_eq_left]
95+
96+ theorem ValidPos.Splits.bytes_right_eq {s : String} {p : s.ValidPos} {t₁ t₂}
97+ (h : p.Splits t₁ t₂) : t₂.bytes = s.bytes.extract p.offset.byteIdx s.utf8ByteSize := by
98+ simp [h.eq_append, h.offset_eq_rawEndPos, ByteArray.extract_append_eq_right]
99+
92100theorem ValidPos.Splits.eq_left {s : String} {p : s.ValidPos} {t₁ t₂ t₃ t₄}
93- (h₁ : p.Splits t₁ t₂) (h₂ : p.Splits t₃ t₄) : t₁ = t₃ := sorry
101+ (h₁ : p.Splits t₁ t₂) (h₂ : p.Splits t₃ t₄) : t₁ = t₃ := by
102+ rw [← String.bytes_inj, h₁.bytes_left_eq, h₂.bytes_left_eq]
94103
95104theorem ValidPos.Splits.eq_right {s : String} {p : s.ValidPos} {t₁ t₂ t₃ t₄}
96- (h₁ : p.Splits t₁ t₂) (h₂ : p.Splits t₃ t₄) : t₂ = t₄ := sorry
105+ (h₁ : p.Splits t₁ t₂) (h₂ : p.Splits t₃ t₄) : t₂ = t₄ := by
106+ rw [← String.bytes_inj, h₁.bytes_right_eq, h₂.bytes_right_eq]
107+
108+ theorem ValidPos.Splits.eq {s : String} {p : s.ValidPos} {t₁ t₂ t₃ t₄}
109+ (h₁ : p.Splits t₁ t₂) (h₂ : p.Splits t₃ t₄) : t₁ = t₃ ∧ t₂ = t₄ :=
110+ ⟨h₁.eq_left h₂, h₁.eq_right h₂⟩
97111
98112@[simp]
99113theorem splits_endValidPos (s : String) : s.endValidPos.Splits s "" where
@@ -111,9 +125,43 @@ theorem splits_startValidPos (s : String) : s.startValidPos.Splits "" s where
111125 offset_eq_rawEndPos := by simp
112126
113127theorem ValidPos.splits_next_right {s : String} (p : s.ValidPos) (hp : p ≠ s.endValidPos) :
114- p.Splits (s.replaceEnd p).copy (singleton (p.get hp) ++ (s.replaceStart (p.next hp)).copy) := sorry
128+ p.Splits (s.replaceEnd p).copy (singleton (p.get hp) ++ (s.replaceStart (p.next hp)).copy) where
129+ eq_append := by simpa [← append_assoc] using p.eq_copy_replaceEnd_append_get hp
130+ offset_eq_rawEndPos := by simp
115131
116132theorem ValidPos.splits_next {s : String} (p : s.ValidPos) (hp : p ≠ s.endValidPos) :
117- (p.next hp).Splits ((s.replaceEnd p).copy ++ singleton (p.get hp)) (s.replaceStart (p.next hp)).copy := sorry
133+ (p.next hp).Splits ((s.replaceEnd p).copy ++ singleton (p.get hp)) (s.replaceStart (p.next hp)).copy where
134+ eq_append := p.eq_copy_replaceEnd_append_get hp
135+ offset_eq_rawEndPos := by simp
136+
137+ theorem ValidPos.Splits.exists_eq_singleton_append {s : String} {p : s.ValidPos}
138+ (hp : p ≠ s.endValidPos) (h : p.Splits t₁ t₂) : ∃ t₂', t₂ = singleton (p.get hp) ++ t₂' :=
139+ ⟨(s.replaceStart (p.next hp)).copy, h.eq_right (p.splits_next_right hp)⟩
140+
141+ theorem ValidPos.Splits.exists_eq_append_singleton {s : String} {p : s.ValidPos}
142+ (hp : p ≠ s.endValidPos) (h : (p.next hp).Splits t₁ t₂) : ∃ t₁', t₁ = t₁' ++ singleton (p.get hp) :=
143+ ⟨(s.replaceEnd p).copy, h.eq_left (p.splits_next hp)⟩
144+
145+ -- TODO: move
146+ @[simp]
147+ theorem singleton_append_inj : singleton c ++ s = singleton d ++ t ↔ c = d ∧ s = t := by
148+ simp [← toList_inj]
149+
150+ -- TODO: move
151+ @[simp]
152+ theorem _root_.List.append_singleton_inj {l m : List α} : l ++ [a] = m ++ [b] ↔ l = m ∧ a = b := by
153+ rw [← List.reverse_inj, And.comm]; simp
154+
155+ -- TODO: move
156+ @[simp]
157+ theorem push_append_inj : push s c = push t d ↔ s = t ∧ c = d := by
158+ simp [← toList_inj]
159+
160+ -- TODO: `hp` actually follows from `h`.
161+ /-- You might want to invoke `ValidPos.Splits.exists_eq_singleton_append` to be able to apply this. -/
162+ theorem ValidPos.Splits.next {s : String} {p : s.ValidPos} (h : p.Splits t₁ (singleton c ++ t₂))
163+ (hp : p ≠ s.endValidPos) : (p.next hp).Splits (t₁ ++ singleton c) t₂ := by
164+ obtain ⟨rfl, rfl, rfl⟩ := by simpa using h.eq (splits_next_right p hp)
165+ exact splits_next p hp
118166
119167end String
0 commit comments