Skip to content

Commit 1ae680c

Browse files
authored
chore: minor String API improvements (#11439)
This PR performs minor maintenance on the String API - Rename `String.Pos.toCopy` to `String.Pos.copy` to adhere to the naming convention - Rename `String.Pos.extract` to `String.extract` to get sane dot notation again - Add `String.Slice.Pos.extract`
1 parent 057b70b commit 1ae680c

File tree

14 files changed

+112
-74
lines changed

14 files changed

+112
-74
lines changed

src/Init/Data/String/Basic.lean

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -824,16 +824,25 @@ The region of `s` from `b` (inclusive) to `e` (exclusive) is copied to a newly-a
824824
825825
If `b`'s offset is greater than or equal to that of `e`, then the resulting string is `""`.
826826
827+
If possible, prefer `String.slice`, which avoids the allocation.
827828
-/
828829
@[extern "lean_string_utf8_extract"]
829-
def Pos.extract {s : @& String} (b e : @& s.Pos) : String where
830+
def extract {s : @& String} (b e : @& s.Pos) : String where
830831
toByteArray := s.toByteArray.extract b.offset.byteIdx e.offset.byteIdx
831832
isValidUTF8 := b.isValidUTF8_extract e
832833

834+
@[deprecated String.extract (since := "2025-12-01")]
835+
def Pos.extract {s : String} (b e : @& s.Pos) : String :=
836+
s.extract b e
837+
838+
@[simp]
839+
theorem toByteArray_extract {s : String} {b e : s.Pos} :
840+
(s.extract b e).toByteArray = s.toByteArray.extract b.offset.byteIdx e.offset.byteIdx := (rfl)
841+
833842
/-- Creates a `String` from a `String.Slice` by copying the bytes. -/
834843
@[inline]
835844
def Slice.copy (s : Slice) : String :=
836-
s.startInclusive.extract s.endExclusive
845+
s.str.extract s.startInclusive s.endExclusive
837846

838847
theorem Slice.toByteArray_copy {s : Slice} :
839848
s.copy.toByteArray = s.str.toByteArray.extract s.startInclusive.offset.byteIdx s.endExclusive.offset.byteIdx := (rfl)
@@ -1387,54 +1396,58 @@ theorem Pos.offset_ofCopy {s : Slice} {pos : s.copy.Pos} : pos.ofCopy.offset = p
13871396

13881397
/-- Given a slice `s` and a position on `s`, obtain the corresponding position on `s.copy.` -/
13891398
@[inline]
1390-
def Slice.Pos.toCopy {s : Slice} (pos : s.Pos) : s.copy.Pos where
1399+
def Slice.Pos.copy {s : Slice} (pos : s.Pos) : s.copy.Pos where
13911400
offset := pos.offset
13921401
isValid := Pos.Raw.isValid_copy_iff.2 pos.isValidForSlice
13931402

1403+
@[deprecated Slice.Pos.copy (since := "2025-12-01")]
1404+
def Slice.Pos.toCopy {s : Slice} (pos : s.Pos) : s.copy.Pos :=
1405+
pos.copy
1406+
13941407
@[simp]
1395-
theorem Slice.Pos.offset_toCopy {s : Slice} {pos : s.Pos} : pos.toCopy.offset = pos.offset := (rfl)
1408+
theorem Slice.Pos.offset_copy {s : Slice} {pos : s.Pos} : pos.copy.offset = pos.offset := (rfl)
13961409

13971410
@[simp]
1398-
theorem Slice.Pos.ofCopy_toCopy {s : Slice} {pos : s.Pos} : pos.toCopy.ofCopy = pos :=
1411+
theorem Slice.Pos.ofCopy_copy {s : Slice} {pos : s.Pos} : pos.copy.ofCopy = pos :=
13991412
Slice.Pos.ext (by simp)
14001413

14011414
@[simp]
1402-
theorem Pos.toCopy_ofCopy {s : Slice} {pos : s.copy.Pos} : pos.ofCopy.toCopy = pos :=
1415+
theorem Pos.copy_ofCopy {s : Slice} {pos : s.copy.Pos} : pos.ofCopy.copy = pos :=
14031416
Pos.ext (by simp)
14041417

14051418
theorem Pos.ofCopy_inj {s : Slice} {pos pos' : s.copy.Pos} : pos.ofCopy = pos'.ofCopy ↔ pos = pos' :=
1406-
fun h => by simpa using congrArg Slice.Pos.toCopy h, (· ▸ rfl)⟩
1419+
fun h => by simpa using congrArg Slice.Pos.copy h, (· ▸ rfl)⟩
14071420

14081421
@[simp]
1409-
theorem Slice.startPos_copy {s : Slice} : s.copy.startPos = s.startPos.toCopy :=
1422+
theorem Slice.startPos_copy {s : Slice} : s.copy.startPos = s.startPos.copy :=
14101423
String.Pos.ext (by simp)
14111424

14121425
@[simp]
1413-
theorem Slice.endPos_copy {s : Slice} : s.copy.endPos = s.endPos.toCopy :=
1426+
theorem Slice.endPos_copy {s : Slice} : s.copy.endPos = s.endPos.copy :=
14141427
String.Pos.ext (by simp)
14151428

1416-
theorem Slice.Pos.get_toCopy {s : Slice} {pos : s.Pos} (h) :
1417-
pos.toCopy.get h = pos.get (by rintro rfl; simp at h) := by
1429+
theorem Slice.Pos.get_copy {s : Slice} {pos : s.Pos} (h) :
1430+
pos.copy.get h = pos.get (by rintro rfl; simp at h) := by
14181431
rw [String.Pos.get, Slice.Pos.get_eq_utf8DecodeChar, Slice.Pos.get_eq_utf8DecodeChar]
1419-
simp only [str_toSlice, toByteArray_copy, startInclusive_toSlice, startPos_copy, offset_toCopy,
1432+
simp only [str_toSlice, toByteArray_copy, startInclusive_toSlice, startPos_copy, offset_copy,
14201433
Slice.offset_startPos, Pos.Raw.byteIdx_zero, Pos.offset_toSlice, Nat.zero_add]
14211434
rw [ByteArray.utf8DecodeChar_eq_utf8DecodeChar_extract]
14221435
conv => lhs; congr; rw [ByteArray.extract_extract]
14231436
conv => rhs; rw [ByteArray.utf8DecodeChar_eq_utf8DecodeChar_extract]
14241437
exact ByteArray.utf8DecodeChar_extract_congr _ _ _
14251438

1426-
theorem Slice.Pos.get_eq_get_toCopy {s : Slice} {pos : s.Pos} {h} :
1427-
pos.get h = pos.toCopy.get (ne_of_apply_ne Pos.ofCopy (by simp [h])) :=
1428-
(get_toCopy _).symm
1439+
theorem Slice.Pos.get_eq_get_copy {s : Slice} {pos : s.Pos} {h} :
1440+
pos.get h = pos.copy.get (ne_of_apply_ne Pos.ofCopy (by simp [h])) :=
1441+
(get_copy _).symm
14291442

1430-
theorem Slice.Pos.byte_toCopy {s : Slice} {pos : s.Pos} (h) :
1431-
pos.toCopy.byte h = pos.byte (by rintro rfl; simp at h) := by
1443+
theorem Slice.Pos.byte_copy {s : Slice} {pos : s.Pos} (h) :
1444+
pos.copy.byte h = pos.byte (by rintro rfl; simp at h) := by
14321445
rw [String.Pos.byte, Slice.Pos.byte, Slice.Pos.byte]
14331446
simp [getUTF8Byte, String.getUTF8Byte, toByteArray_copy, ByteArray.getElem_extract]
14341447

1435-
theorem Slice.Pos.byte_eq_byte_toCopy {s : Slice} {pos : s.Pos} {h} :
1436-
pos.byte h = pos.toCopy.byte (ne_of_apply_ne Pos.ofCopy (by simp [h])) :=
1437-
(byte_toCopy _).symm
1448+
theorem Slice.Pos.byte_eq_byte_copy {s : Slice} {pos : s.Pos} {h} :
1449+
pos.byte h = pos.copy.byte (ne_of_apply_ne Pos.ofCopy (by simp [h])) :=
1450+
(byte_copy _).symm
14381451

14391452
/-- Given a position in `s.sliceFrom p₀`, obtain the corresponding position in `s`. -/
14401453
@[inline]
@@ -1521,7 +1534,7 @@ theorem Slice.Pos.copy_eq_append_get {s : Slice} {pos : s.Pos} (h : pos ≠ s.en
15211534
∃ t₁ t₂ : String, s.copy = t₁ ++ singleton (pos.get h) ++ t₂ ∧ t₁.utf8ByteSize = pos.offset.byteIdx := by
15221535
obtain ⟨t₂, ht₂⟩ := (s.sliceFrom pos).copy.eq_singleton_append (by simpa [← Pos.ofCopy_inj, ← ofSliceFrom_inj])
15231536
refine ⟨(s.sliceTo pos).copy, t₂, ?_, by simp⟩
1524-
simp only [Slice.startPos_copy, get_toCopy, get_eq_get_ofSliceFrom, ofSliceFrom_startPos] at ht₂
1537+
simp only [Slice.startPos_copy, get_copy, get_eq_get_ofSliceFrom, ofSliceFrom_startPos] at ht₂
15251538
rw [append_assoc, ← ht₂, ← copy_eq_copy_sliceTo]
15261539

15271540
theorem Slice.Pos.utf8ByteSize_byte {s : Slice} {pos : s.Pos} {h : pos ≠ s.endPos} :
@@ -1751,8 +1764,8 @@ theorem Pos.offset_cast {s t : String} {pos : s.Pos} {h : s = t} :
17511764
theorem Pos.cast_rfl {s : String} {pos : s.Pos} : pos.cast rfl = pos :=
17521765
Pos.ext (by simp)
17531766

1754-
theorem Pos.toCopy_toSlice_eq_cast {s : String} (p : s.Pos) :
1755-
p.toSlice.toCopy = p.cast copy_toSlice.symm :=
1767+
theorem Pos.copy_toSlice_eq_cast {s : String} (p : s.Pos) :
1768+
p.toSlice.copy = p.cast copy_toSlice.symm :=
17561769
Pos.ext (by simp)
17571770

17581771
/-- Given a byte position within a string slice, obtains the smallest valid position that is
@@ -2435,6 +2448,35 @@ def Pos.slice! {s : String} (pos : s.Pos) (p₀ p₁ : s.Pos) :
24352448
(s.slice! p₀ p₁).Pos :=
24362449
Slice.Pos.slice! pos.toSlice _ _
24372450

2451+
theorem extract_eq_copy_slice {s : String} (p₀ p₁ : s.Pos) (h : p₀ ≤ p₁) :
2452+
s.extract p₀ p₁ = (s.slice p₀ p₁ h).copy := by
2453+
simp [← toByteArray_inj, Slice.toByteArray_copy]
2454+
2455+
/--
2456+
Copies a region of a slice to a new string.
2457+
2458+
The region of `s` from `b` (inclusive) to `e` (exclusive) is copied to a newly-allocated `String`.
2459+
2460+
If `b`'s offset is greater than or equal to that of `e`, then the resulting string is `""`.
2461+
2462+
If possible, prefer `Slice.slice`, which avoids the allocation.
2463+
-/
2464+
@[inline]
2465+
def Slice.extract (s : Slice) (p₀ p₁ : s.Pos) : String :=
2466+
s.str.extract p₀.str p₁.str
2467+
2468+
@[simp]
2469+
theorem Slice.Pos.str_le_str_iff {s : Slice} {p q : s.Pos} : p.str ≤ q.str ↔ p ≤ q := by
2470+
simp [String.Pos.le_iff, Slice.Pos.le_iff, Pos.Raw.le_iff]
2471+
2472+
@[simp]
2473+
theorem Slice.Pos.str_lt_str_iff {s : Slice} {p q : s.Pos} : p.str < q.str ↔ p < q := by
2474+
simp [String.Pos.lt_iff, Slice.Pos.lt_iff, Pos.Raw.lt_iff]
2475+
2476+
theorem Slice.extract_eq_copy_slice {s : Slice} (p₀ p₁ : s.Pos) (h : p₀ ≤ p₁) :
2477+
s.extract p₀ p₁ = (s.slice p₀ p₁ h).copy := by
2478+
simp [← toByteArray_inj, Slice.toByteArray_copy, Slice.extract]
2479+
24382480
/--
24392481
Advances the position `p` `n` times.
24402482
@@ -2734,10 +2776,6 @@ where
27342776
| [], _, _ => []
27352777
| c::cs, i, e => if i = e then [] else c :: go₂ cs (i + c) e
27362778

2737-
@[extern "lean_string_utf8_extract", expose, deprecated Pos.Raw.extract (since := "2025-10-14")]
2738-
def extract : (@& String) → (@& Pos.Raw) → (@& Pos.Raw) → String
2739-
| s, b, e => Pos.Raw.extract s b e
2740-
27412779
def Pos.Raw.offsetOfPosAux (s : String) (pos : Pos.Raw) (i : Pos.Raw) (offset : Nat) : Nat :=
27422780
if i >= pos then offset
27432781
else if h : i.atEnd s then

src/Init/Data/String/Lemmas/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ theorem singleton_ne_empty {c : Char} : singleton c ≠ "" := by
4040
simp [singleton]
4141

4242
@[simp]
43-
theorem Slice.Pos.toCopy_inj {s : Slice} {p₁ p₂ : s.Pos} : p₁.toCopy = p₂.toCopy ↔ p₁ = p₂ := by
43+
theorem Slice.Pos.copy_inj {s : Slice} {p₁ p₂ : s.Pos} : p₁.copy = p₂.copy ↔ p₁ = p₂ := by
4444
simp [String.Pos.ext_iff, Pos.ext_iff]
4545

4646
@[simp]

src/Init/Data/String/Lemmas/Splits.lean

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,25 @@ theorem Slice.Pos.Splits.cast {s₁ s₂ : Slice} {p : s₁.Pos} {t₁ t₂ : St
5656
p.Splits t₁ t₂ → (p.cast h).Splits t₁ t₂ :=
5757
splits_cast_iff.mpr
5858

59-
theorem Slice.Pos.Splits.toCopy {s : Slice} {p : s.Pos} {t₁ t₂ : String}
60-
(h : p.Splits t₁ t₂) : p.toCopy.Splits t₁ t₂ where
59+
theorem Slice.Pos.Splits.copy {s : Slice} {p : s.Pos} {t₁ t₂ : String}
60+
(h : p.Splits t₁ t₂) : p.copy.Splits t₁ t₂ where
6161
eq_append := h.eq_append
6262
offset_eq_rawEndPos := by simpa using h.offset_eq_rawEndPos
6363

64-
theorem Slice.Pos.splits_of_splits_toCopy {s : Slice} {p : s.Pos} {t₁ t₂ : String}
65-
(h : p.toCopy.Splits t₁ t₂) : p.Splits t₁ t₂ where
64+
theorem Slice.Pos.splits_of_splits_copy {s : Slice} {p : s.Pos} {t₁ t₂ : String}
65+
(h : p.copy.Splits t₁ t₂) : p.Splits t₁ t₂ where
6666
eq_append := h.eq_append
6767
offset_eq_rawEndPos := by simpa using h.offset_eq_rawEndPos
6868

6969
@[simp]
70-
theorem Slice.Pos.splits_toCopy_iff {s : Slice} {p : s.Pos} {t₁ t₂ : String} :
71-
p.toCopy.Splits t₁ t₂ ↔ p.Splits t₁ t₂ :=
72-
splits_of_splits_toCopy, (·.toCopy)⟩
70+
theorem Slice.Pos.splits_copy_iff {s : Slice} {p : s.Pos} {t₁ t₂ : String} :
71+
p.copy.Splits t₁ t₂ ↔ p.Splits t₁ t₂ :=
72+
splits_of_splits_copy, (·.copy)⟩
7373

7474
@[simp]
7575
theorem Pos.splits_toSlice_iff {s : String} {p : s.Pos} {t₁ t₂ : String} :
7676
p.toSlice.Splits t₁ t₂ ↔ p.Splits t₁ t₂ := by
77-
rw [← Slice.Pos.splits_toCopy_iff, p.toCopy_toSlice_eq_cast, splits_cast_iff]
77+
rw [← Slice.Pos.splits_copy_iff, p.copy_toSlice_eq_cast, splits_cast_iff]
7878

7979
theorem Pos.Splits.toSlice {s : String} {p : s.Pos} {t₁ t₂ : String}
8080
(h : p.Splits t₁ t₂) : p.toSlice.Splits t₁ t₂ :=
@@ -112,15 +112,15 @@ theorem Pos.Splits.eq {s : String} {p : s.Pos} {t₁ t₂ t₃ t₄}
112112

113113
theorem Slice.Pos.Splits.eq_left {s : Slice} {p : s.Pos} {t₁ t₂ t₃ t₄}
114114
(h₁ : p.Splits t₁ t₂) (h₂ : p.Splits t₃ t₄) : t₁ = t₃ :=
115-
(splits_toCopy_iff.2 h₁).eq_left (splits_toCopy_iff.2 h₂)
115+
(splits_copy_iff.2 h₁).eq_left (splits_copy_iff.2 h₂)
116116

117117
theorem Slice.Pos.Splits.eq_right {s : Slice} {p : s.Pos} {t₁ t₂ t₃ t₄}
118118
(h₁ : p.Splits t₁ t₂) (h₂ : p.Splits t₃ t₄) : t₂ = t₄ :=
119-
(splits_toCopy_iff.2 h₁).eq_right (splits_toCopy_iff.2 h₂)
119+
(splits_copy_iff.2 h₁).eq_right (splits_copy_iff.2 h₂)
120120

121121
theorem Slice.Pos.Splits.eq {s : Slice} {p : s.Pos} {t₁ t₂ t₃ t₄}
122122
(h₁ : p.Splits t₁ t₂) (h₂ : p.Splits t₃ t₄) : t₁ = t₃ ∧ t₂ = t₄ :=
123-
(splits_toCopy_iff.2 h₁).eq (splits_toCopy_iff.2 h₂)
123+
(splits_copy_iff.2 h₁).eq (splits_copy_iff.2 h₂)
124124

125125
@[simp]
126126
theorem splits_endPos (s : String) : s.endPos.Splits s "" where
@@ -161,11 +161,11 @@ theorem Slice.splits_endPos (s : Slice) : s.endPos.Splits s.copy "" where
161161
@[simp]
162162
theorem Slice.splits_endPos_iff {s : Slice} :
163163
s.endPos.Splits t₁ t₂ ↔ t₁ = s.copy ∧ t₂ = "" := by
164-
rw [← Pos.splits_toCopy_iff, ← endPos_copy, String.splits_endPos_iff]
164+
rw [← Pos.splits_copy_iff, ← endPos_copy, String.splits_endPos_iff]
165165

166166
theorem Slice.Pos.Splits.eq_endPos_iff {s : Slice} {p : s.Pos} (h : p.Splits t₁ t₂) :
167167
p = s.endPos ↔ t₂ = "" := by
168-
rw [← toCopy_inj, ← endPos_copy, h.toCopy.eq_endPos_iff]
168+
rw [← copy_inj, ← endPos_copy, h.copy.eq_endPos_iff]
169169

170170
@[simp]
171171
theorem Slice.splits_startPos (s : Slice) : s.startPos.Splits "" s.copy where
@@ -175,11 +175,11 @@ theorem Slice.splits_startPos (s : Slice) : s.startPos.Splits "" s.copy where
175175
@[simp]
176176
theorem Slice.splits_startPos_iff {s : Slice} :
177177
s.startPos.Splits t₁ t₂ ↔ t₁ = "" ∧ t₂ = s.copy := by
178-
rw [← Pos.splits_toCopy_iff, ← startPos_copy, String.splits_startPos_iff]
178+
rw [← Pos.splits_copy_iff, ← startPos_copy, String.splits_startPos_iff]
179179

180180
theorem Slice.Pos.Splits.eq_startPos_iff {s : Slice} {p : s.Pos} (h : p.Splits t₁ t₂) :
181181
p = s.startPos ↔ t₁ = "" := by
182-
rw [← toCopy_inj, ← startPos_copy, h.toCopy.eq_startPos_iff]
182+
rw [← copy_inj, ← startPos_copy, h.copy.eq_startPos_iff]
183183

184184
theorem Pos.splits_next_right {s : String} (p : s.Pos) (hp : p ≠ s.endPos) :
185185
p.Splits (s.sliceTo p).copy (singleton (p.get hp) ++ (s.sliceFrom (p.next hp)).copy) where

src/Init/Data/String/Termination.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,13 @@ end Pos
223223
namespace Slice.Pos
224224

225225
@[simp]
226-
theorem remainingBytes_toCopy {s : Slice} {p : s.Pos} :
227-
p.toCopy.remainingBytes = p.remainingBytes := by
226+
theorem remainingBytes_copy {s : Slice} {p : s.Pos} :
227+
p.copy.remainingBytes = p.remainingBytes := by
228228
simp [remainingBytes_eq, String.Pos.remainingBytes_eq, Slice.utf8ByteSize_eq]
229229

230230
theorem Splits.remainingBytes_eq {s : Slice} {p : s.Pos} {t₁ t₂} (h : p.Splits t₁ t₂) :
231231
p.remainingBytes = t₂.utf8ByteSize := by
232-
simpa using h.toCopy.remainingBytes_eq
232+
simpa using h.copy.remainingBytes_eq
233233

234234
end Slice.Pos
235235

src/Lean/DocString/Links.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def rewriteManualLinksCore (s : String) : Id (Array (Lean.Syntax.Range × String
124124
iter' := iter'.next h'
125125
if urlChar c' && ¬iter'.IsAtEnd then
126126
continue
127-
match rw (start.extract pre') with
127+
match rw (s.extract start pre') with
128128
| .error err =>
129129
errors := errors.push (⟨pre.offset, pre'.offset⟩, err)
130130
out := out.push c

src/Lean/Server/FileWorker/ExampleHover.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ private def lines (s : String) : Array String := Id.run do
5959
let c := iter.get h
6060
iter := iter.next h
6161
if c == '\n' then
62-
result := result.push <| lineStart.extract iter
62+
result := result.push <| s.extract lineStart iter
6363
lineStart := iter
6464

6565
if iter != lineStart then
66-
result := result.push <| lineStart.extract iter
66+
result := result.push <| s.extract lineStart iter
6767
return result
6868

6969
private inductive RWState where

src/lake/Lake/CLI/Main.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def setConfigOpt (kvPair : String) : CliM PUnit :=
196196
if h : pos.IsAtEnd then
197197
(kvPair.toName, "")
198198
else
199-
(kvPair.startPos.extract pos |>.toName, (pos.next h).extract kvPair.endPos)
199+
(kvPair.extract kvPair.startPos pos |>.toName, kvPair.extract (pos.next h) kvPair.endPos)
200200
modifyThe LakeOptions fun opts =>
201201
{opts with configOpts := opts.configOpts.insert key val}
202202

src/lake/Lake/Config/Artifact.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public def ofFilePath? (path : FilePath) : Except String ArtifactDescr := do
5656
| throw "expected artifact file name to be a content hash"
5757
return {hash, ext := ""}
5858
else
59-
let some hash := Hash.ofString? <| s.startPos.extract pos
59+
let some hash := Hash.ofString? <| s.extract s.startPos pos
6060
| throw "expected artifact file name to be a content hash"
61-
let ext := (pos.next h).extract s.endPos
61+
let ext := s.extract (pos.next h) s.endPos
6262
return {hash, ext}
6363

6464
public protected def fromJson? (data : Json) : Except String ArtifactDescr := do

src/lake/Lake/Util/Cli.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,17 @@ variable [Monad m] [MonadStateOf ArgList m]
102102
if h : pos = opt.endPos then
103103
handle opt
104104
else do
105-
consArg <| (pos.next h).extract opt.endPos
106-
handle <| opt.startPos.extract pos
105+
consArg <| opt.extract (pos.next h) opt.endPos
106+
handle <| opt.extract opt.startPos pos
107107

108108
/-- Splits a long option of the form `--long=arg` into `--long` and `arg`. -/
109109
@[inline] public def longOptionOrEq (handle : String → m α) (opt : String) : m α :=
110110
let pos := opt.find '='
111111
if h : pos = opt.endPos then
112112
handle opt
113113
else do
114-
consArg <| (pos.next h).extract opt.endPos
115-
handle <| opt.startPos.extract pos
114+
consArg <| opt.extract (pos.next h) opt.endPos
115+
handle <| opt.extract opt.startPos pos
116116

117117
/-- Process a long option of the form `--long`, `--long=arg`, `"--long arg"`. -/
118118
@[inline] public def longOption (handle : String → m α) : String → m α :=

src/lake/Lake/Util/Version.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def parseSpecialDescr? (s : String) : EStateM String s.Pos (Option String) := do
8888
let p := p.next h
8989
let p' := nextUntilWhitespace p
9090
set p'
91-
let specialDescr := p.extract p'
91+
let specialDescr := s.extract p p'
9292
return some specialDescr
9393
else
9494
return none
@@ -256,7 +256,7 @@ public def ofString (ver : String) : ToolchainVer := Id.run do
256256
let (origin, tag) :=
257257
if h : ¬colonPos.IsAtEnd then
258258
let pos := colonPos.next h
259-
(ver.startPos.extract colonPos, pos.extract ver.endPos)
259+
(ver.extract ver.startPos colonPos, ver.extract pos ver.endPos)
260260
else
261261
("", ver)
262262
let noOrigin := origin.isEmpty

0 commit comments

Comments
 (0)