Documentation

Init.Data.String.Subslice

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.

  • startInclusive_le_endExclusive : self.startInclusive self.endExclusive

    The subslice is not degenerate (but it may be empty).

Instances For
    theorem String.Slice.Subslice.ext {s : Slice} {x y : s.Subslice} (startInclusive : x.startInclusive = y.startInclusive) (endExclusive : x.endExclusive = y.endExclusive) :
    x = y
    @[instance_reducible]
    Equations
    @[inline]

    Turns a subslice into a standalone slice by "forgetting" which slice the subslice is a sublice of.

    Equations
    Instances For
      @[inline]

      Creates a String from a Subslice by copying out the bytes.

      Equations
      Instances For
        @[inline]

        Creates a String from a Subslice by copying out the bytes.

        Equations
        Instances For
          @[inline]
          def String.Slice.subslice (s : Slice) (newStart newEnd : s.Pos) (h : newStart newEnd) :

          Constructs a subslice of s given the bounds of the subslice and a proof that the subslice is non-degenerate.

          Equations
          • s.subslice newStart newEnd h = { startInclusive := newStart, endExclusive := newEnd, startInclusive_le_endExclusive := h }
          Instances For
            @[simp]
            theorem String.Slice.toSlice_subslice {s : Slice} {newStart newEnd : s.Pos} {h : newStart newEnd} :
            (s.subslice newStart newEnd h).toSlice = s.slice newStart newEnd h
            @[simp]
            theorem String.Slice.startInclusive_subslice {s : Slice} {newStart newEnd : s.Pos} {h : newStart newEnd} :
            (s.subslice newStart newEnd h).startInclusive = newStart
            @[simp]
            theorem String.Slice.endExclusive_subslice {s : Slice} {newStart newEnd : s.Pos} {h : newStart newEnd} :
            (s.subslice newStart newEnd h).endExclusive = newEnd
            def String.Slice.subslice! (s : Slice) (newStart newEnd : s.Pos) :

            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
              theorem String.Slice.subslice!_eq_subslice {s : Slice} {newStart newEnd : s.Pos} (h : newStart newEnd) :
              s.subslice! newStart newEnd = s.subslice newStart newEnd h
              @[inline]
              def String.Slice.subsliceFrom (s : Slice) (newStart : s.Pos) :

              Constructs a subslice of s starting at the given position and going until the end of the slice.

              Equations
              Instances For
                @[simp]
                theorem String.Slice.startInclusive_subsliceFrom {s : Slice} {newStart : s.Pos} :
                (s.subsliceFrom newStart).startInclusive = newStart
                @[simp]
                @[inline]

                The entire slice, as a subslice of itself.

                Equations
                Instances For
                  @[inline]

                  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
                  Instances For
                    @[inline]
                    def String.Slice.Subslice.extendLeft {s : Slice} (sl : s.Subslice) (newStart : s.Pos) (h : newStart sl.startInclusive) :

                    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
                      @[simp]
                      theorem String.Slice.Subslice.startInclusive_extendLeft {s : Slice} {sl : s.Subslice} {newStart : s.Pos} {h : newStart sl.startInclusive} :
                      (sl.extendLeft newStart h).startInclusive = newStart
                      @[simp]
                      theorem String.Slice.Subslice.endExclusive_extendLeft {s : Slice} {sl : s.Subslice} {newStart : s.Pos} {h : newStart sl.startInclusive} :
                      @[simp]
                      theorem String.Slice.Subslice.extendLeft_extendLeft {s : Slice} {sl : s.Subslice} (p₁ p₂ : s.Pos) (h₂ : p₂ sl.startInclusive) (h₁ : p₁ (sl.extendLeft p₂ h₂).startInclusive) :
                      (sl.extendLeft p₂ h₂).extendLeft p₁ h₁ = sl.extendLeft p₁
                      @[inline]
                      def String.Slice.Subslice.cast {s t : Slice} (h : s = t) (sl : s.Subslice) :

                      Given a subslice of s and a proof that s = t, obtain the corresponding subslice of t.

                      Equations
                      Instances For
                        @[simp]