@@ -142,10 +142,6 @@ theorem String.bytes_push {s : String} {c : Char} : (s.push c).bytes = s.bytes +
142142
143143namespace String
144144
145- @[deprecated rawEndPos (since := "2025-10-20")]
146- def endPos (s : String) : String.Pos.Raw :=
147- s.rawEndPos
148-
149145/-- The start position of the string, as a `String.Pos.Raw.` -/
150146def rawStartPos (_s : String) : String.Pos.Raw :=
151147 0
@@ -341,55 +337,55 @@ theorem Pos.Raw.isValid_empty_iff {p : Pos.Raw} : p.IsValid "" ↔ p = 0 := by
341337 simp
342338
343339/--
344- A `ValidPos s` is a byte offset in `s` together with a proof that this position is at a UTF-8
340+ A `Pos s` is a byte offset in `s` together with a proof that this position is at a UTF-8
345341character boundary.
346342-/
347343@[ext]
348- structure ValidPos (s : String) where
349- /-- The underlying byte offset of the `ValidPos `. -/
344+ structure Pos (s : String) where
345+ /-- The underlying byte offset of the `Pos `. -/
350346 offset : Pos.Raw
351347 /-- The proof that `offset` is valid for the string `s`. -/
352348 isValid : offset.IsValid s
353349deriving @[expose] DecidableEq
354350
355- /-- The start position of `s`, as an `s.ValidPos `. -/
351+ /-- The start position of `s`, as an `s.Pos `. -/
356352@[inline, expose]
357- def startValidPos (s : String) : s.ValidPos where
353+ def startPos (s : String) : s.Pos where
358354 offset := 0
359355 isValid := by simp
360356
361357@[simp]
362- theorem offset_startValidPos {s : String} : s.startValidPos .offset = 0 := (rfl)
358+ theorem offset_startPos {s : String} : s.startPos .offset = 0 := (rfl)
363359
364- instance {s : String} : Inhabited s.ValidPos where
365- default := s.startValidPos
360+ instance {s : String} : Inhabited s.Pos where
361+ default := s.startPos
366362
367- /-- The past-the-end position of `s`, as an `s.ValidPos `. -/
363+ /-- The past-the-end position of `s`, as an `s.Pos `. -/
368364@[inline, expose]
369- def endValidPos (s : String) : s.ValidPos where
365+ def endPos (s : String) : s.Pos where
370366 offset := s.rawEndPos
371367 isValid := by simp
372368
373369@[simp]
374- theorem offset_endValidPos {s : String} : s.endValidPos .offset = s.rawEndPos := (rfl)
370+ theorem offset_endPos {s : String} : s.endPos .offset = s.rawEndPos := (rfl)
375371
376- instance {s : String} : LE s.ValidPos where
372+ instance {s : String} : LE s.Pos where
377373 le l r := l.offset ≤ r.offset
378374
379- instance {s : String} : LT s.ValidPos where
375+ instance {s : String} : LT s.Pos where
380376 lt l r := l.offset < r.offset
381377
382- theorem ValidPos .le_iff {s : String} {l r : s.ValidPos } : l ≤ r ↔ l.offset ≤ r.offset :=
378+ theorem Pos .le_iff {s : String} {l r : s.Pos } : l ≤ r ↔ l.offset ≤ r.offset :=
383379 Iff.rfl
384380
385- theorem ValidPos .lt_iff {s : String} {l r : s.ValidPos } : l < r ↔ l.offset < r.offset :=
381+ theorem Pos .lt_iff {s : String} {l r : s.Pos } : l < r ↔ l.offset < r.offset :=
386382 Iff.rfl
387383
388- instance {s : String} (l r : s.ValidPos ) : Decidable (l ≤ r) :=
389- decidable_of_iff' _ ValidPos .le_iff
384+ instance {s : String} (l r : s.Pos ) : Decidable (l ≤ r) :=
385+ decidable_of_iff' _ Pos .le_iff
390386
391- instance {s : String} (l r : s.ValidPos ) : Decidable (l < r) :=
392- decidable_of_iff' _ ValidPos .lt_iff
387+ instance {s : String} (l r : s.Pos ) : Decidable (l < r) :=
388+ decidable_of_iff' _ Pos .lt_iff
393389
394390/--
395391A region or slice of some underlying string.
@@ -406,30 +402,30 @@ structure Slice where
406402 /-- The underlying strings. -/
407403 str : String
408404 /-- The byte position of the start of the string slice. -/
409- startInclusive : str.ValidPos
405+ startInclusive : str.Pos
410406 /-- The byte position of the end of the string slice. -/
411- endExclusive : str.ValidPos
407+ endExclusive : str.Pos
412408 /-- The slice is not degenerate (but it may be empty). -/
413409 startInclusive_le_endExclusive : startInclusive ≤ endExclusive
414410
415411instance : Inhabited Slice where
416- default := ⟨"" , "" .startValidPos , "" .startValidPos , by simp [ValidPos .le_iff]⟩
412+ default := ⟨"" , "" .startPos , "" .startPos , by simp [Pos .le_iff]⟩
417413
418414/--
419415Returns a slice that contains the entire string.
420416-/
421417@[inline, expose] -- expose for the defeq `s.toSlice.str = s`.
422418def toSlice (s : String) : Slice where
423419 str := s
424- startInclusive := s.startValidPos
425- endExclusive := s.endValidPos
426- startInclusive_le_endExclusive := by simp [ValidPos .le_iff, Pos.Raw.le_iff]
420+ startInclusive := s.startPos
421+ endExclusive := s.endPos
422+ startInclusive_le_endExclusive := by simp [Pos .le_iff, Pos.Raw.le_iff]
427423
428424@[simp]
429- theorem startInclusive_toSlice {s : String} : s.toSlice.startInclusive = s.startValidPos := rfl
425+ theorem startInclusive_toSlice {s : String} : s.toSlice.startInclusive = s.startPos := rfl
430426
431427@[simp]
432- theorem endExclusive_toSlice {s : String} : s.toSlice.endExclusive = s.endValidPos := rfl
428+ theorem endExclusive_toSlice {s : String} : s.toSlice.endExclusive = s.endPos := rfl
433429
434430@[simp]
435431theorem str_toSlice {s : String} : s.toSlice.str = s := rfl
@@ -532,7 +528,7 @@ instance {s : Slice} : Inhabited s.Pos where
532528theorem Slice.offset_startInclusive_add_self {s : Slice} :
533529 s.startInclusive.offset + s = s.endExclusive.offset := by
534530 have := s.startInclusive_le_endExclusive
535- simp_all [String.Pos.Raw.ext_iff, ValidPos .le_iff, Pos.Raw.le_iff, utf8ByteSize_eq]
531+ simp_all [String.Pos.Raw.ext_iff, Pos .le_iff, Pos.Raw.le_iff, utf8ByteSize_eq]
536532
537533@[simp]
538534theorem Pos.Raw.offsetBy_rawEndPos_left {p : Pos.Raw} {s : String} :
@@ -591,18 +587,18 @@ instance {s : Slice} (l r : s.Pos) : Decidable (l < r) :=
591587 decidable_of_iff' _ Slice.Pos.lt_iff
592588
593589/--
594- `pos.IsAtEnd` is just shorthand for `pos = s.endValidPos ` that is easier to write if `s` is long.
590+ `pos.IsAtEnd` is just shorthand for `pos = s.endPos ` that is easier to write if `s` is long.
595591-/
596- abbrev ValidPos .IsAtEnd {s : String} (pos : s.ValidPos ) : Prop :=
597- pos = s.endValidPos
592+ abbrev Pos .IsAtEnd {s : String} (pos : s.Pos ) : Prop :=
593+ pos = s.endPos
598594
599595@[simp]
600- theorem ValidPos .isAtEnd_iff {s : String} {pos : s.ValidPos } :
601- pos.IsAtEnd ↔ pos = s.endValidPos := Iff.rfl
596+ theorem Pos .isAtEnd_iff {s : String} {pos : s.Pos } :
597+ pos.IsAtEnd ↔ pos = s.endPos := Iff.rfl
602598
603599@[inline]
604- instance {s : String} {pos : s.ValidPos } : Decidable pos.IsAtEnd :=
605- decidable_of_iff _ ValidPos .isAtEnd_iff
600+ instance {s : String} {pos : s.Pos } : Decidable pos.IsAtEnd :=
601+ decidable_of_iff _ Pos .isAtEnd_iff
606602
607603/--
608604`pos.IsAtEnd` is just shorthand for `pos = s.endPos` that is easier to write if `s` is long.
@@ -639,4 +635,16 @@ def toSubstring (s : String) : Substring.Raw :=
639635def toSubstring' (s : String) : Substring.Raw :=
640636 s.toRawSubstring'
641637
638+ @[deprecated String.Pos (since := "2025-11-24")]
639+ abbrev ValidPos (s : String) : Type :=
640+ s.Pos
641+
642+ @[deprecated String.startPos (since := "2025-11-24")]
643+ abbrev startValidPos (s : String) : s.Pos :=
644+ s.startPos
645+
646+ @[deprecated String.endPos (since := "2025-11-24")]
647+ abbrev endValidPos (s : String) : s.Pos :=
648+ s.endPos
649+
642650end String
0 commit comments