A region or slice of a fixed slice.
Given a Slice s, the type s.Subslice is the type of half-open regions
in s delineated by a valid position on both sides.
This type is useful to track regions of interest within some larger slice that is also of interest.
In contrast, Slice is used to track regions of interest whithin some larger string that is
not or no longer relevant.
Equality on Subslice is somewhat better behaved than on Slice, but note that there
will in general be many different representations of the empty subslice of a slice.
- startInclusive : s.Pos
The byte position of the start of the subslice.
- endExclusive : s.Pos
The byte position of the end of the subslice.
The subslice is not degenerate (but it may be empty).
Instances For
Turns a subslice into a standalone slice by "forgetting" which slice the subslice is a sublice of.
Equations
- sl.toSlice = s.slice sl.startInclusive sl.endExclusive ⋯
Instances For
Equations
Equations
Constructs a subslice of s given the bounds of the subslice and a proof that the subslice
is non-degenerate.
Equations
Instances For
Constructs a subslice of s given the bounds of the subslice. If the subslice would be
degenerate, this function panics.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Constructs a subslice of s starting at the given position and going until the end of the
slice.
Equations
- s.subsliceFrom newStart = s.subslice newStart s.endPos ⋯
Instances For
The entire slice, as a subslice of itself.
Equations
- s.toSubslice = s.subslice s.startPos s.endPos ⋯
Instances For
Given a position p within a slice s and a subslice sl of
s.sliceFrom p, reinterpret sl as a subslice of s by applying
Pos.ofSliceFrom to the endpoints.
Equations
- sl.ofSliceFrom = { startInclusive := String.Slice.Pos.ofSliceFrom sl.startInclusive, endExclusive := String.Slice.Pos.ofSliceFrom sl.endExclusive, startInclusive_le_endExclusive := ⋯ }
Instances For
Given a subslice sl of s and a position newStart that is at most the
start position of the subslice, obtain a new subslice whose start is newStart and whose
end is the end of sl.
Equations
- sl.extendLeft newStart h = { startInclusive := newStart, endExclusive := sl.endExclusive, startInclusive_le_endExclusive := ⋯ }
Instances For
Given a subslice of s and a proof that s = t, obtain the corresponding subslice of
t.
Equations
- String.Slice.Subslice.cast h sl = { startInclusive := sl.startInclusive.cast h, endExclusive := sl.endExclusive.cast h, startInclusive_le_endExclusive := ⋯ }