Skip to content

Commit 00230c3

Browse files
chore: missing docstring + style updates for String docs
This PR adds a missing docstring and applies our style guide to parts of the String API.
1 parent 9dc1faf commit 00230c3

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

src/Init/Data/String/Basic.lean

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -914,10 +914,9 @@ theorem ValidPos.isValidUtf8_extract {s : String} (pos₁ pos₂ : s.ValidPos) :
914914
/--
915915
A region or slice of some underlying string.
916916
917-
A substring contains an string together with the start and end byte positions of a region of
917+
A slice consists of a string together with the start and end byte positions of a region of
918918
interest. Actually extracting a substring requires copying and memory allocation, while many
919-
substrings of the same underlying string may exist with very little overhead, and they are more
920-
convenient than tracking the bounds by hand.
919+
slices of the same underlying string may exist with very little overhead. While this could be achieved by tracking the bounds by hand, the slice API is much more convenient.
921920
922921
`String.Slice` bundles proofs to ensure that the start and end positions always delineate a valid
923922
string. For this reason, it should be preferred over `Substring`.
@@ -935,6 +934,9 @@ structure Slice where
935934
instance : Inhabited Slice where
936935
default := ⟨"", "".startValidPos, "".startValidPos, by simp [Pos.Raw.le_iff]⟩
937936

937+
/--
938+
Returns a slice that contains the entire string.
939+
-/
938940
@[inline, expose] -- expose for the defeq `s.toSlice.str = s`.
939941
def toSlice (s : String) : Slice where
940942
str := s

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ set_option doc.verso true
1414
/-!
1515
This module defines the notion of patterns which is central to the {name}`String.Slice` and
1616
{name}`String` API. All functions on {name}`String.Slice` and {name}`String` that
17-
"search for something" are polymorphic over a pattern instead of taking just one particular kind
17+
search for something are polymorphic over a pattern instead of taking just one particular kind
1818
of pattern such as a {name}`Char`. The key components are:
1919
- {name (scope := "Init.Data.String.Pattern.Basic")}`ToForwardSearcher`
2020
- {name (scope := "Init.Data.String.Pattern.Basic")}`ForwardPattern`
2121
- {name (scope := "Init.Data.String.Pattern.Basic")}`ToBackwardSearcher`
22-
- {name (scope := "Init.Data.String.Pattern.Basic")}`SuffixPattern`
22+
- {name (scope := "Init.Data.String.Pattern.Basic")}`BackwardPattern`
2323
-/
2424

2525
public section
@@ -41,12 +41,12 @@ inductive SearchStep (s : Slice) where
4141
deriving Inhabited
4242

4343
/--
44-
Provides a conversion from a pattern to an iterator of {name}`SearchStep` searching for matches of
45-
the pattern from the start towards the end of a {name}`Slice`.
44+
Provides a conversion from a pattern to an iterator of {name}`SearchStep` that searches for matches
45+
of the pattern from the start towards the end of a {name}`Slice`.
4646
-/
4747
class ToForwardSearcher (ρ : Type) (σ : outParam (Slice → Type)) where
4848
/--
49-
Build an iterator of {name}`SearchStep` corresponding to matches of {name}`pat` along the slice
49+
Builds an iterator of {name}`SearchStep` corresponding to matches of {name}`pat` along the slice
5050
{name}`s`. The {name}`SearchStep`s returned by this iterator must contain ranges that are
5151
adjacent, non-overlapping and cover all of {name}`s`.
5252
-/
@@ -56,8 +56,8 @@ class ToForwardSearcher (ρ : Type) (σ : outParam (Slice → Type)) where
5656
Provides simple pattern matching capabilities from the start of a {name}`Slice`.
5757
5858
While these operations can be implemented on top of {name}`ToForwardSearcher` some patterns allow
59-
for more efficient implementations so this class can be used to specialise for them. If there is no
60-
need to specialise in this fashion
59+
for more efficient implementations. This class can be used to specialize for them. If there is no
60+
need to specialize in this fashion, then
6161
{name (scope := "Init.Data.String.Pattern.Basic")}`ForwardPattern.defaultImplementation` can be used
6262
to automatically derive an instance.
6363
-/
@@ -67,8 +67,8 @@ class ForwardPattern (ρ : Type) where
6767
-/
6868
startsWith : Slice → ρ → Bool
6969
/--
70-
Checks whether the slice starts with the pattern, if it does return slice with the prefix removed,
71-
otherwise {name}`none`.
70+
Checks whether the slice starts with the pattern. If it does, the slice is returned with the
71+
prefix removed; otherwise the result is {name}`none`.
7272
-/
7373
dropPrefix? : Slice → ρ → Option Slice
7474

@@ -181,14 +181,21 @@ class ToBackwardSearcher (ρ : Type) (σ : outParam (Slice → Type)) where
181181
/--
182182
Provides simple pattern matching capabilities from the end of a {name}`Slice`.
183183
184-
While these operations can be implemented on top of {name}`ToBackwardSearcher` some patterns allow
185-
for more efficient implementations so this class can be used to specialise for them. If there is no
186-
need to specialise in this fashion
184+
While these operations can be implemented on top of {name}`ToBackwardSearcher`, some patterns allow
185+
for more efficient implementations. This class can be used to specialize for them. If there is no
186+
need to specialize in this fashion, then
187187
{name (scope := "Init.Data.String.Pattern.Basic")}`BackwardPattern.defaultImplementation` can be
188188
used to automatically derive an instance.
189189
-/
190190
class BackwardPattern (ρ : Type) where
191+
/--
192+
Checks whether the slice ends with the pattern.
193+
-/
191194
endsWith : Slice → ρ → Bool
195+
/--
196+
Checks whether the slice ends with the pattern. If it does, the slice is returned with the
197+
suffix removed; otherwise the result is {name}`none`.
198+
-/
192199
dropSuffix? : Slice → ρ → Option Slice
193200

194201
namespace ToBackwardSearcher

src/Init/Data/String/Slice.lean

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ deriving Inhabited
707707

708708
set_option doc.verso false
709709
/--
710-
Creates and iterator over all valid positions within {name}`s`.
710+
Creates an iterator over all valid positions within {name}`s`.
711711
712712
Examples
713713
* {lean}`("abc".toSlice.positions.map (fun ⟨p, h⟩ => p.get h) |>.toList) = ['a', 'b', 'c']`
@@ -776,7 +776,7 @@ docs_to_verso positions
776776
end PosIterator
777777

778778
/--
779-
Creates and iterator over all characters (Unicode code points) in {name}`s`.
779+
Creates an iterator over all characters (Unicode code points) in {name}`s`.
780780
781781
Examples:
782782
* {lean}`"abc".toSlice.chars.toList = ['a', 'b', 'c']`
@@ -792,7 +792,7 @@ deriving Inhabited
792792

793793
set_option doc.verso false
794794
/--
795-
Creates and iterator over all valid positions within {name}`s`, starting from the last valid
795+
Creates an iterator over all valid positions within {name}`s`, starting from the last valid
796796
position and iterating towards the first one.
797797
798798
Examples
@@ -863,7 +863,7 @@ docs_to_verso revPositions
863863
end RevPosIterator
864864

865865
/--
866-
Creates and iterator over all characters (Unicode code points) in {name}`s`, starting from the end
866+
Creates an iterator over all characters (Unicode code points) in {name}`s`, starting from the end
867867
of the slice and iterating towards the start.
868868
869869
Example:
@@ -881,7 +881,7 @@ deriving Inhabited
881881

882882
set_option doc.verso false
883883
/--
884-
Creates and iterator over all bytes in {name}`s`.
884+
Creates an iterator over all bytes in {name}`s`.
885885
886886
Examples:
887887
* {lean}`"abc".toSlice.bytes.toList = [97, 98, 99]`
@@ -955,7 +955,7 @@ structure RevByteIterator where
955955

956956
set_option doc.verso false
957957
/--
958-
Creates and iterator over all bytes in {name}`s`, starting from the last one and iterating towards
958+
Creates an iterator over all bytes in {name}`s`, starting from the last one and iterating towards
959959
the first one.
960960
961961
Examples:

0 commit comments

Comments
 (0)