Documentation

Init.Data.String.Basic

@[simp]
@[inline]

Decodes a sequence of characters from their UTF-8 representation. Returns none if the bytes are not a sequence of Unicode scalar values.

Equations
Instances For
    def ByteArray.utf8Decode?.go (b : ByteArray) (fuel i : Nat) (acc : Array Char) (hi : i b.size) (hf : b.size - i < fuel) :
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      @[extern lean_string_validate_utf8]
      Equations
      Instances For
        def ByteArray.validateUTF8.go (b : ByteArray) (fuel i : Nat) (hi : i b.size) (hf : b.size - i < fuel) :
        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          theorem ByteArray.isSome_utf8Decode?Go_eq_validateUTF8Go {b : ByteArray} {fuel i : Nat} {acc : Array Char} {hi : i b.size} {hf : b.size - i < fuel} :
          (utf8Decode?.go b fuel i acc hi hf).isSome = validateUTF8.go b fuel i hi hf
          theorem ByteArray.utf8Decode?.go.congr {b b' : ByteArray} {fuel fuel' i i' : Nat} {acc acc' : Array Char} {hi : i b.size} {hi' : i' b'.size} {hf : b.size - i < fuel} {hf' : b'.size - i' < fuel'} (hbb' : b = b') (hii' : i = i') (hacc : acc = acc') :
          go b fuel i acc hi hf = go b' fuel' i' acc' hi' hf'
          @[inline]

          Decodes an array of bytes that encode a string as UTF-8 into the corresponding string.

          Equations
          Instances For
            @[inline]

            Decodes an array of bytes that encode a string as UTF-8 into the corresponding string, or returns none if the array is not a valid UTF-8 encoding of a string.

            Equations
            Instances For
              @[inline]

              Decodes an array of bytes that encode a string as UTF-8 into the corresponding string, or panics if the array is not a valid UTF-8 encoding of a string.

              Equations
              Instances For
                @[extern lean_string_to_utf8]

                Encodes a string in UTF-8 as an array of bytes.

                Equations
                Instances For
                  @[simp]
                  @[extern lean_string_append]

                  Appends two strings. Usually accessed via the ++ operator.

                  The internal implementation will perform destructive updates if the string is not shared.

                  Examples:

                  • "abc".append "def" = "abcdef"
                  • "abc" ++ "def" = "abcdef"
                  • "" ++ "" = ""
                  Equations
                  Instances For
                    Equations
                    @[simp]
                    theorem String.bytes_append {s t : String} :
                    (s ++ t).bytes = s.bytes ++ t.bytes
                    theorem String.bytes_inj {s t : String} :
                    s.bytes = t.bytes s = t
                    @[simp]
                    theorem String.empty_append {s : String} :
                    "" ++ s = s
                    @[simp]
                    theorem String.append_empty {s : String} :
                    s ++ "" = s
                    @[simp]
                    @[simp]
                    theorem List.asString_append {l₁ l₂ : List Char} :
                    (l₁ ++ l₂).asString = l₁.asString ++ l₂.asString
                    @[extern lean_string_data]
                    Equations
                    Instances For
                      @[simp]
                      @[extern lean_string_length]

                      Returns the length of a string in Unicode code points.

                      Examples:

                      Equations
                      Instances For
                        @[simp]
                        @[simp]
                        @[simp]
                        theorem List.asString_injective {l₁ l₂ : List Char} (h : l₁.asString = l₂.asString) :
                        l₁ = l₂
                        theorem List.asString_inj {l₁ l₂ : List Char} :
                        l₁.asString = l₂.asString l₁ = l₂
                        theorem String.data_injective {s₁ s₂ : String} (h : s₁.data = s₂.data) :
                        s₁ = s₂
                        theorem String.data_inj {s₁ s₂ : String} :
                        s₁.data = s₂.data s₁ = s₂
                        @[simp]
                        theorem String.data_append {l₁ l₂ : String} :
                        (l₁ ++ l₂).data = l₁.data ++ l₂.data
                        @[simp]
                        theorem String.bytes_push {s : String} {c : Char} :
                        Equations
                        Equations
                        @[export lean_string_pos_sub]
                        Equations
                        Instances For
                          Equations
                          Equations
                          Equations
                          Equations
                          Equations
                          instance String.instDecidableLeRaw (p₁ p₂ : Pos.Raw) :
                          Decidable (p₁ p₂)
                          Equations
                          instance String.instDecidableLtRaw (p₁ p₂ : Pos.Raw) :
                          Decidable (p₁ < p₂)
                          Equations
                          theorem String.Pos.Raw.le_iff {i₁ i₂ : Raw} :
                          i₁ i₂ i₁.byteIdx i₂.byteIdx
                          theorem String.Pos.Raw.lt_iff {i₁ i₂ : Raw} :
                          i₁ < i₂ i₁.byteIdx < i₂.byteIdx
                          @[simp]
                          theorem String.utf8ByteSize_ofByteArray {b : ByteArray} {h : b.IsValidUTF8} :
                          { bytes := b, isValidUTF8 := h }.utf8ByteSize = b.size
                          theorem String.Pos.Raw.ext {x y : Raw} (byteIdx : x.byteIdx = y.byteIdx) :
                          x = y
                          Equations
                          @[extern lean_string_dec_lt]
                          instance String.decidableLT (s₁ s₂ : String) :
                          Decidable (s₁ < s₂)
                          Equations
                          @[reducible]
                          def String.le (a b : String) :

                          Non-strict inequality on strings, typically used via the operator.

                          a ≤ b is defined to mean ¬ b < a.

                          Equations
                          Instances For
                            instance String.decLE (s₁ s₂ : String) :
                            Decidable (s₁ s₂)
                            Equations
                            @[inline]

                            Converts a string to a list of characters.

                            Since strings are represented as dynamic arrays of bytes containing the string encoded using UTF-8, this operation takes time and space linear in the length of the string.

                            Examples:

                            Equations
                            Instances For
                              structure String.Pos.Raw.IsValid (s : String) (off : Raw) :

                              Predicate for validity of positions inside a String.

                              There are multiple equivalent definitions for validity.

                              We say that a position is valid if the string obtained by taking all of the bytes up to, but excluding, the given position, is valid UTF-8; see Pos.isValid_iff_isValidUTF8_extract_zero.

                              Similarly, a position is valid if the string obtained by taking all of the bytes starting at the given position is valid UTF-8; see Pos.isValid_iff_isValidUTF8_extract_utf8ByteSize.

                              An equivalent condition is that the position is the length of the UTF-8 encoding of some prefix of the characters of the string; see Pos.isValid_iff_exists_append and Pos.isValid_iff_exists_take_data.

                              Another equivalent condition that can be checked efficiently is that the position is either the end position or strictly smaller than the end position and the byte at the position satisfies UInt8.IsUTF8FirstByte; see Pos.isValid_iff_isUTF8FirstByte.

                              Examples:

                              • String.Pos.IsValid "abc" ⟨0⟩
                              • String.Pos.IsValid "abc" ⟨1⟩
                              • String.Pos.IsValid "abc" ⟨3⟩
                              • ¬ String.Pos.IsValid "abc" ⟨4⟩
                              • String.Pos.IsValid "𝒫(A)" ⟨0⟩
                              • ¬ String.Pos.IsValid "𝒫(A)" ⟨1⟩
                              • ¬ String.Pos.IsValid "𝒫(A)" ⟨2⟩
                              • ¬ String.Pos.IsValid "𝒫(A)" ⟨3⟩
                              • String.Pos.IsValid "𝒫(A)" ⟨4⟩
                              Instances For
                                theorem String.Pos.Raw.IsValid.exists {s : String} {p : Raw} (h : IsValid s p) :
                                (m₁ : List Char), (m₂ : List Char), m₁.utf8Encode = s.bytes.extract 0 p.byteIdx (m₁ ++ m₂).asString = s
                                @[simp]
                                @[inline]

                                Returns the size of the byte slice delineated by the positions lo and hi.

                                Equations
                                Instances For
                                  @[simp]
                                  @[simp]
                                  @[simp]
                                  theorem String.Pos.Raw.isValid_append {s t : String} {p : Raw} :
                                  IsValid (s ++ t) p IsValid s p s.endPos p IsValid t (p - s)
                                  theorem String.Pos.Raw.IsValid.append_left {t : String} {p : Raw} (h : IsValid t p) (s : String) :
                                  IsValid (s ++ t) (s + p)
                                  theorem String.Pos.Raw.IsValid.append_right {s : String} {p : Raw} (h : IsValid s p) (t : String) :
                                  IsValid (s ++ t) p
                                  @[simp]
                                  theorem String.append_singleton {s : String} {c : Char} :
                                  s ++ singleton c = s.push c
                                  theorem String.Pos.Raw.isValid_push {s : String} {c : Char} {p : Raw} :
                                  IsValid (s.push c) p IsValid s p p = s.endPos + c
                                  theorem String.endPos_push {s : String} {c : Char} :
                                  (s.push c).endPos = s.endPos + c
                                  theorem String.push_induction (s : String) (motive : StringProp) (empty : motive "") (push : ∀ (b : String) (c : Char), motive bmotive (b.push c)) :
                                  motive s
                                  @[extern lean_string_get_byte_fast]
                                  def String.getUTF8Byte (s : String) (p : Pos.Raw) (h : p < s.endPos) :

                                  Accesses the indicated byte in the UTF-8 encoding of a string.

                                  At runtime, this function is implemented by efficient, constant-time code.

                                  Equations
                                  Instances For
                                    @[reducible, inline, extern lean_string_get_byte_fast, deprecated String.getUTF8Byte (since := "2025-10-01")]
                                    abbrev String.getUtf8Byte (s : String) (p : Pos.Raw) (h : p < s.endPos) :
                                    Equations
                                    Instances For
                                      @[simp]
                                      @[extern lean_string_is_valid_pos]

                                      Returns true if p is a valid UTF-8 position in the string s.

                                      This means that p ≤ s.endPos and p lies on a UTF-8 character boundary. At runtime, this operation takes constant time.

                                      Examples:

                                      • String.Pos.isValid "abc" ⟨0⟩ = true
                                      • String.Pos.isValid "abc" ⟨1⟩ = true
                                      • String.Pos.isValid "abc" ⟨3⟩ = true
                                      • String.Pos.isValid "abc" ⟨4⟩ = false
                                      • String.Pos.isValid "𝒫(A)" ⟨0⟩ = true
                                      • String.Pos.isValid "𝒫(A)" ⟨1⟩ = false
                                      • String.Pos.isValid "𝒫(A)" ⟨2⟩ = false
                                      • String.Pos.isValid "𝒫(A)" ⟨3⟩ = false
                                      • String.Pos.isValid "𝒫(A)" ⟨4⟩ = true
                                      Equations
                                      Instances For
                                        theorem String.Pos.Raw.le_trans {a b c : Raw} :
                                        a bb ca c
                                        theorem String.Pos.Raw.lt_of_lt_of_le {a b c : Raw} :
                                        a < bb ca < c
                                        theorem String.Pos.Raw.isValidUTF8_extract_iff {s : String} (p₁ p₂ : Raw) (hle : p₁ p₂) (hle' : p₂ s.endPos) :
                                        (s.bytes.extract p₁.byteIdx p₂.byteIdx).IsValidUTF8 p₁ = p₂ IsValid s p₁ IsValid s p₂
                                        structure String.ValidPos (s : String) :

                                        A ValidPos s is a byte offset in s together with a proof that this position is at a UTF-8 character boundary.

                                        Instances For
                                          theorem String.ValidPos.ext_iff {s : String} {x y : s.ValidPos} :
                                          x = y x.offset = y.offset
                                          theorem String.ValidPos.ext {s : String} {x y : s.ValidPos} (offset : x.offset = y.offset) :
                                          x = y
                                          def String.instDecidableEqValidPos.decEq {s✝ : String} (x✝ x✝¹ : s✝.ValidPos) :
                                          Decidable (x✝ = x✝¹)
                                          Equations
                                          • One or more equations did not get rendered due to their size.
                                          Instances For
                                            @[inline]

                                            The start position of s, as an s.ValidPos.

                                            Equations
                                            Instances For
                                              @[inline]

                                              The past-the-end position of s, as an s.ValidPos.

                                              Equations
                                              Instances For
                                                Equations
                                                Equations
                                                theorem String.ValidPos.lt_iff {s : String} {l r : s.ValidPos} :
                                                l < r l.offset < r.offset
                                                structure String.Slice :

                                                A region or slice of some underlying string.

                                                A slice consists of a string together with the start and end byte positions of a region of interest. Actually extracting a substring requires copying and memory allocation, while many 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.

                                                String.Slice bundles proofs to ensure that the start and end positions always delineate a valid string. For this reason, it should be preferred over Substring.

                                                • str : String

                                                  The underlying strings.

                                                • startInclusive : self.str.ValidPos

                                                  The byte position of the start of the string slice.

                                                • endExclusive : self.str.ValidPos

                                                  The byte position of the end of the string slice.

                                                • startInclusive_le_endExclusive : self.startInclusive self.endExclusive

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

                                                Instances For
                                                  Equations
                                                  • One or more equations did not get rendered due to their size.
                                                  @[inline]

                                                  Returns a slice that contains the entire string.

                                                  Equations
                                                  Instances For

                                                    The number of bytes of the UTF-8 encoding of the string slice.

                                                    Equations
                                                    Instances For

                                                      The end position of a slice, as a Pos.Raw.

                                                      Equations
                                                      Instances For
                                                        @[inline]
                                                        def String.Pos.Raw.offsetBy (p offset : Raw) :

                                                        Offsets p by offset on the left. This is not an HAdd instance because it should be a relatively rare operation, so we use a name to make accidental use less likely. To offset a position by the size of a character character c or string s, you can use c + p resp. s + p.

                                                        This should be seen as an operation that converts relative positions into absolute positions.

                                                        See also Pos.Raw.increaseBy, which is an "advancing" operation.

                                                        Equations
                                                        Instances For
                                                          @[simp]
                                                          theorem String.Pos.Raw.byteIdx_offsetBy {p offset : Raw} :
                                                          (p.offsetBy offset).byteIdx = offset.byteIdx + p.byteIdx
                                                          @[inline]

                                                          Decreases p by offset. This is not an HSub instance because it should be a relatively rare operation, so we use a name to make accidental use less likely. To unoffset a position by the size of a character c or string s, you can use p - c resp. p - s.

                                                          This should be seen as an operation that converts absolute positions into relative positions.

                                                          See also Pos.Raw.decreaseBy, which is an "unadvancing" operation.

                                                          Equations
                                                          Instances For
                                                            @[simp]
                                                            theorem String.Pos.Raw.byteIdx_unoffsetBy {p offset : Raw} :
                                                            (p.unoffsetBy offset).byteIdx = p.byteIdx - offset.byteIdx

                                                            Criterion for validity of positions in string slices.

                                                            Instances For
                                                              @[inline]

                                                              Accesses the indicated byte in the UTF-8 encoding of a string slice.

                                                              At runtime, this function is implemented by efficient, constant-time code.

                                                              Equations
                                                              Instances For

                                                                Accesses the indicated byte in the UTF-8 encoding of the string slice, or panics if the position is out-of-bounds.

                                                                Equations
                                                                • One or more equations did not get rendered due to their size.
                                                                Instances For
                                                                  @[extern lean_string_utf8_extract]
                                                                  Equations
                                                                  Instances For
                                                                    @[inline]

                                                                    Creates a String from a String.Slice by copying the bytes.

                                                                    Equations
                                                                    Instances For
                                                                      structure String.Slice.Pos (s : Slice) :

                                                                      A Slice.Pos s is a byte offset in s together with a proof that this position is at a UTF-8 character boundary.

                                                                      Instances For
                                                                        theorem String.Slice.Pos.ext {s : Slice} {x y : s.Pos} (offset : x.offset = y.offset) :
                                                                        x = y
                                                                        theorem String.Slice.Pos.ext_iff {s : Slice} {x y : s.Pos} :
                                                                        x = y x.offset = y.offset
                                                                        def String.Slice.instDecidableEqPos.decEq {s✝ : Slice} (x✝ x✝¹ : s✝.Pos) :
                                                                        Decidable (x✝ = x✝¹)
                                                                        Equations
                                                                        • One or more equations did not get rendered due to their size.
                                                                        Instances For
                                                                          @[inline]

                                                                          The start position of s, as an s.Pos.

                                                                          Equations
                                                                          Instances For
                                                                            @[inline]

                                                                            The past-the-end position of s, as an s.Pos.

                                                                            Equations
                                                                            Instances For
                                                                              instance String.instLEPos {s : Slice} :
                                                                              Equations
                                                                              instance String.instLTPos {s : Slice} :
                                                                              Equations
                                                                              theorem String.Slice.Pos.le_iff {s : Slice} {l r : s.Pos} :
                                                                              theorem String.Slice.Pos.lt_iff {s : Slice} {l r : s.Pos} :
                                                                              l < r l.offset < r.offset

                                                                              Efficiently checks whether a position is at a UTF-8 character boundary of the slice s.

                                                                              Equations
                                                                              Instances For
                                                                                @[inline]
                                                                                def String.Slice.Pos.byte {s : Slice} (pos : s.Pos) (h : pos s.endPos) :

                                                                                Returns the byte at a position in a slice that is not the end position.

                                                                                Equations
                                                                                Instances For
                                                                                  @[inline]
                                                                                  def String.Slice.Pos.str {s : Slice} (pos : s.Pos) :

                                                                                  Given a valid position on a slice s, obtains the corresponding valid position on the underlying string s.str.

                                                                                  Equations
                                                                                  Instances For
                                                                                    @[inline]

                                                                                    Given a slice and a valid position within the slice, obtain a new slice on the same underlying string by replacing the start of the slice with the given position.

                                                                                    Equations
                                                                                    Instances For
                                                                                      @[simp]
                                                                                      theorem String.Slice.str_replaceStart {s : Slice} {pos : s.Pos} :
                                                                                      (s.replaceStart pos).str = s.str
                                                                                      @[inline]
                                                                                      def String.Slice.replaceEnd (s : Slice) (pos : s.Pos) :

                                                                                      Given a slice and a valid position within the slice, obtain a new slice on the same underlying string by replacing the end of the slice with the given position.

                                                                                      Equations
                                                                                      Instances For
                                                                                        @[simp]
                                                                                        theorem String.Slice.str_replaceEnd {s : Slice} {pos : s.Pos} :
                                                                                        (s.replaceEnd pos).str = s.str
                                                                                        @[simp]
                                                                                        @[inline]
                                                                                        def String.Slice.replaceStartEnd (s : Slice) (newStart newEnd : s.Pos) (h : newStart.offset newEnd.offset) :

                                                                                        Given a slice and two valid positions within the slice, obtain a new slice on the same underlying string formed by the new bounds.

                                                                                        Equations
                                                                                        • s.replaceStartEnd newStart newEnd h = { str := s.str, startInclusive := newStart.str, endExclusive := newEnd.str, startInclusive_le_endExclusive := }
                                                                                        Instances For
                                                                                          @[simp]
                                                                                          theorem String.Slice.str_replaceStartEnd {s : Slice} {newStart newEnd : s.Pos} {h : newStart.offset newEnd.offset} :
                                                                                          (s.replaceStartEnd newStart newEnd h).str = s.str
                                                                                          @[simp]
                                                                                          theorem String.Slice.startInclusive_replaceStartEnd {s : Slice} {newStart newEnd : s.Pos} {h : newStart.offset newEnd.offset} :
                                                                                          (s.replaceStartEnd newStart newEnd h).startInclusive = newStart.str
                                                                                          @[simp]
                                                                                          theorem String.Slice.endExclusive_replaceStartEnd {s : Slice} {newStart newEnd : s.Pos} {h : newStart.offset newEnd.offset} :
                                                                                          (s.replaceStartEnd newStart newEnd h).endExclusive = newEnd.str
                                                                                          def String.Slice.replaceStartEnd! (s : Slice) (newStart newEnd : s.Pos) :

                                                                                          Given a slice and two valid positions within the slice, obtain a new slice on the same underlying string formed by the new bounds, or panic if the given end is strictly less than the given start.

                                                                                          Equations
                                                                                          • One or more equations did not get rendered due to their size.
                                                                                          Instances For
                                                                                            @[simp]
                                                                                            @[simp]
                                                                                            theorem String.Slice.utf8ByteSize_replaceStartEnd {s : Slice} {newStart newEnd : s.Pos} {h : newStart.offset newEnd.offset} :
                                                                                            (s.replaceStartEnd newStart newEnd h).utf8ByteSize = newStart.offset.byteDistance newEnd.offset
                                                                                            @[extern lean_string_utf8_get]
                                                                                            def String.decodeChar (s : String) (byteIdx : Nat) (h : (s.bytes.utf8DecodeChar? byteIdx).isSome = true) :
                                                                                            Equations
                                                                                            Instances For
                                                                                              @[inline]
                                                                                              def String.Slice.Pos.get {s : Slice} (pos : s.Pos) (h : pos s.endPos) :

                                                                                              Obtains the character at the given position in the string.

                                                                                              Equations
                                                                                              Instances For

                                                                                                Returns the byte at the given position in the string, or none if the position is the end position.

                                                                                                Equations
                                                                                                Instances For
                                                                                                  def String.Slice.Pos.get! {s : Slice} (pos : s.Pos) :

                                                                                                  Returns the byte at the given position in the string, or panicks if the position is the end position.

                                                                                                  Equations
                                                                                                  Instances For
                                                                                                    @[simp]
                                                                                                    @[simp]
                                                                                                    @[inline]

                                                                                                    Turns a valid position on the string s into a valid position on the slice s.toSlice.

                                                                                                    Equations
                                                                                                    Instances For
                                                                                                      @[simp]
                                                                                                      @[inline]

                                                                                                      Given a string s, turns a valid position on the slice s.toSlice into a valid position on the string s.

                                                                                                      Equations
                                                                                                      Instances For
                                                                                                        @[simp]
                                                                                                        @[simp]
                                                                                                        @[simp]
                                                                                                        @[inline]
                                                                                                        def String.ValidPos.get {s : String} (pos : s.ValidPos) (h : pos s.endValidPos) :

                                                                                                        Returns the character at the position pos of a string, taking a proof that p is not the past-the-end position.

                                                                                                        This function is overridden with an efficient implementation in runtime code.

                                                                                                        Examples:

                                                                                                        • ("abc".pos ⟨1⟩ (by decide)).get (by decide) = 'b'
                                                                                                        • ("L∃∀N".pos ⟨1⟩ (by decide)).get (by decide) = '∃'
                                                                                                        Equations
                                                                                                        Instances For
                                                                                                          @[inline]

                                                                                                          Returns the character at the position pos of a string, or none if the position is the past-the-end position.

                                                                                                          This function is overridden with an efficient implementation in runtime code.

                                                                                                          Equations
                                                                                                          Instances For
                                                                                                            @[inline]

                                                                                                            Returns the character at the position pos of a string, or panics if the position is the past-the-end position.

                                                                                                            This function is overridden with an efficient implementation in runtime code.

                                                                                                            Equations
                                                                                                            Instances For
                                                                                                              @[inline]
                                                                                                              def String.ValidPos.byte {s : String} (pos : s.ValidPos) (h : pos s.endValidPos) :

                                                                                                              Returns the byte at the position pos of a string.

                                                                                                              Equations
                                                                                                              Instances For
                                                                                                                @[simp]
                                                                                                                theorem String.append_left_inj {s₁ s₂ : String} (t : String) :
                                                                                                                s₁ ++ t = s₂ ++ t s₁ = s₂
                                                                                                                theorem String.append_assoc {s₁ s₂ s₃ : String} :
                                                                                                                s₁ ++ s₂ ++ s₃ = s₁ ++ (s₂ ++ s₃)
                                                                                                                @[simp]
                                                                                                                theorem String.Pos.Raw.eq_zero_iff {p : Raw} :
                                                                                                                p = 0 p.byteIdx = 0
                                                                                                                @[simp]
                                                                                                                theorem String.data_eq_nil_iff {b : String} :
                                                                                                                b.data = [] b = ""
                                                                                                                @[simp]
                                                                                                                theorem String.head_data {b : String} {h : b.data []} :
                                                                                                                @[inline]

                                                                                                                Given a slice s and a position on s.copy, obtain the corresponding position on s.

                                                                                                                Equations
                                                                                                                Instances For
                                                                                                                  @[simp]
                                                                                                                  @[inline]

                                                                                                                  Given a slice s and a position on s, obtain the corresponding position on s.copy.

                                                                                                                  Equations
                                                                                                                  Instances For
                                                                                                                    @[simp]
                                                                                                                    theorem String.Slice.Pos.offset_toCopy {s : Slice} {pos : s.Pos} :
                                                                                                                    @[simp]
                                                                                                                    theorem String.Slice.Pos.ofCopy_toCopy {s : Slice} {pos : s.Pos} :
                                                                                                                    pos.toCopy.ofCopy = pos
                                                                                                                    @[simp]
                                                                                                                    theorem String.ValidPos.ofCopy_inj {s : Slice} {pos pos' : s.copy.ValidPos} :
                                                                                                                    pos.ofCopy = pos'.ofCopy pos = pos'
                                                                                                                    theorem String.Slice.Pos.get_toCopy {s : Slice} {pos : s.Pos} (h : pos.toCopy s.copy.endValidPos) :
                                                                                                                    pos.toCopy.get h = pos.get
                                                                                                                    theorem String.Slice.Pos.get_eq_get_toCopy {s : Slice} {pos : s.Pos} {h : pos s.endPos} :
                                                                                                                    pos.get h = pos.toCopy.get
                                                                                                                    theorem String.Slice.Pos.byte_toCopy {s : Slice} {pos : s.Pos} (h : pos.toCopy s.copy.endValidPos) :
                                                                                                                    pos.toCopy.byte h = pos.byte
                                                                                                                    theorem String.Slice.Pos.byte_eq_byte_toCopy {s : Slice} {pos : s.Pos} {h : pos s.endPos} :
                                                                                                                    pos.byte h = pos.toCopy.byte
                                                                                                                    @[inline]
                                                                                                                    def String.Slice.Pos.ofReplaceStart {s : Slice} {p₀ : s.Pos} (pos : (s.replaceStart p₀).Pos) :
                                                                                                                    s.Pos

                                                                                                                    Given a position in s.replaceStart p₀, obtain the corresponding position in s.

                                                                                                                    Equations
                                                                                                                    Instances For
                                                                                                                      @[simp]
                                                                                                                      theorem String.Slice.Pos.offset_ofReplaceStart {s : Slice} {p₀ : s.Pos} {pos : (s.replaceStart p₀).Pos} :
                                                                                                                      @[inline]
                                                                                                                      def String.Slice.Pos.toReplaceStart {s : Slice} (p₀ pos : s.Pos) (h : p₀ pos) :
                                                                                                                      (s.replaceStart p₀).Pos

                                                                                                                      Given a position in s that is at least p₀, obtain the corresponding position in s.replaceStart p₀.

                                                                                                                      Equations
                                                                                                                      Instances For
                                                                                                                        @[simp]
                                                                                                                        theorem String.Slice.Pos.offset_toReplaceStart {s : Slice} {p₀ pos : s.Pos} {h : p₀ pos} :
                                                                                                                        theorem String.Slice.Pos.ofReplaceStart_inj {s : Slice} {p₀ : s.Pos} {pos pos' : (s.replaceStart p₀).Pos} :
                                                                                                                        ofReplaceStart pos = ofReplaceStart pos' pos = pos'
                                                                                                                        theorem String.Slice.Pos.get_eq_get_ofReplaceStart {s : Slice} {p₀ : s.Pos} {pos : (s.replaceStart p₀).Pos} {h : pos (s.replaceStart p₀).endPos} :
                                                                                                                        pos.get h = (ofReplaceStart pos).get
                                                                                                                        @[inline]
                                                                                                                        def String.Slice.Pos.ofReplaceEnd {s : Slice} {p₀ : s.Pos} (pos : (s.replaceEnd p₀).Pos) :
                                                                                                                        s.Pos

                                                                                                                        Given a position in s.replaceEnd p₀, obtain the corresponding position in s.

                                                                                                                        Equations
                                                                                                                        Instances For
                                                                                                                          @[simp]
                                                                                                                          theorem String.Slice.Pos.offset_ofReplaceEnd {s : Slice} {p₀ : s.Pos} {pos : (s.replaceEnd p₀).Pos} :
                                                                                                                          @[inline]
                                                                                                                          def String.Slice.Pos.toReplaceEnd {s : Slice} (p₀ pos : s.Pos) (h : pos p₀) :
                                                                                                                          (s.replaceEnd p₀).Pos

                                                                                                                          Given a position in s that is at most p₀, obtain the corresponding position in s.replaceEnd p₀.

                                                                                                                          Equations
                                                                                                                          Instances For
                                                                                                                            @[simp]
                                                                                                                            theorem String.Slice.Pos.offset_toReplaceEnd {s : Slice} {p₀ pos : s.Pos} {h : pos p₀} :
                                                                                                                            (p₀.toReplaceEnd pos h).offset = pos.offset
                                                                                                                            theorem String.Slice.Pos.copy_eq_append_get {s : Slice} {pos : s.Pos} (h : pos s.endPos) :
                                                                                                                            (t₁ : String), (t₂ : String), s.copy = t₁ ++ singleton (pos.get h) ++ t₂ t₁.utf8ByteSize = pos.offset.byteIdx
                                                                                                                            theorem String.Slice.Pos.utf8ByteSize_byte {s : Slice} {pos : s.Pos} {h : pos s.endPos} :
                                                                                                                            (pos.byte h).utf8ByteSize = (pos.get h).utf8Size
                                                                                                                            theorem String.ValidPos.utf8ByteSize_byte {s : String} {pos : s.ValidPos} {h : pos s.endValidPos} :
                                                                                                                            (pos.byte h).utf8ByteSize = (pos.get h).utf8Size
                                                                                                                            @[inline]

                                                                                                                            Advances p by n bytes. This is not an HAdd instance because it should be a relatively rare operation, so we use a name to make accidental use less likely. To add the size of a character c or string s to a raw position p, you can use p + c resp. p + s.

                                                                                                                            This should be seen as an "advance" or "skip".

                                                                                                                            See also Pos.Raw.offsetBy, which turns relative positions into absolute positions.

                                                                                                                            Equations
                                                                                                                            Instances For
                                                                                                                              @[inline]

                                                                                                                              Move the position p back by n bytes. This is not an HSub instance because it should be a relatively rare operation, so we use a name to make accidental use less likely. To remove the size of a character c or string s from a raw position p, you can use p - c resp. p - s.

                                                                                                                              This should be seen as the inverse of an "advance" or "skip".

                                                                                                                              See also Pos.Raw.unoffsetBy, which turns absolute positions into relative positions.

                                                                                                                              Equations
                                                                                                                              Instances For
                                                                                                                                def String.Slice.Pos.next {s : Slice} (pos : s.Pos) (h : pos s.endPos) :
                                                                                                                                s.Pos

                                                                                                                                Advances a valid position on a slice to the next valid position, given a proof that the position is not the past-the-end position, which guarantees that such a position exists.

                                                                                                                                Equations
                                                                                                                                Instances For
                                                                                                                                  def String.Slice.Pos.next? {s : Slice} (pos : s.Pos) :

                                                                                                                                  Advances a valid position on a slice to the next valid position, or returns none if the given position is the past-the-end position.

                                                                                                                                  Equations
                                                                                                                                  Instances For
                                                                                                                                    def String.Slice.Pos.next! {s : Slice} (pos : s.Pos) :
                                                                                                                                    s.Pos

                                                                                                                                    Advances a valid position on a slice to the next valid position, or panics if the given position is the past-the-end position.

                                                                                                                                    Equations
                                                                                                                                    Instances For
                                                                                                                                      @[simp]
                                                                                                                                      theorem String.Slice.Pos.offset_next {s : Slice} {pos : s.Pos} {h : pos s.endPos} :
                                                                                                                                      (pos.next h).offset = pos.offset + pos.get h
                                                                                                                                      theorem String.Slice.Pos.byteIdx_offset_next {s : Slice} {pos : s.Pos} {h : pos s.endPos} :
                                                                                                                                      @[simp]
                                                                                                                                      theorem String.Slice.Pos.lt_next {s : Slice} {pos : s.Pos} {h : pos s.endPos} :
                                                                                                                                      pos < pos.next h
                                                                                                                                      @[inline]

                                                                                                                                      Increases the byte offset of the position by 1. Not to be confused with ValidPos.next.

                                                                                                                                      Equations
                                                                                                                                      Instances For
                                                                                                                                        @[inline]

                                                                                                                                        Decreases the byte offset of the position by 1. Not to be confused with ValidPos.prev.

                                                                                                                                        Equations
                                                                                                                                        Instances For
                                                                                                                                          @[inline]
                                                                                                                                          def String.Slice.Pos.prevAux {s : Slice} (pos : s.Pos) (h : pos s.startPos) :
                                                                                                                                          Equations
                                                                                                                                          Instances For
                                                                                                                                            def String.Slice.Pos.prevAux.go {s : Slice} (off : Nat) (h₁ : off < s.utf8ByteSize) :
                                                                                                                                            Equations
                                                                                                                                            • One or more equations did not get rendered due to their size.
                                                                                                                                            Instances For
                                                                                                                                              @[inline]
                                                                                                                                              def String.Slice.Pos.prev {s : Slice} (pos : s.Pos) (h : pos s.startPos) :
                                                                                                                                              s.Pos

                                                                                                                                              Returns the previous valid position before the given position, given a proof that the position is not the start position, which guarantees that such a position exists.

                                                                                                                                              Equations
                                                                                                                                              Instances For
                                                                                                                                                def String.Slice.Pos.prev? {s : Slice} (pos : s.Pos) :

                                                                                                                                                Returns the previous valid position before the given position, or none if the position is the start position.

                                                                                                                                                Equations
                                                                                                                                                Instances For
                                                                                                                                                  def String.Slice.Pos.prev! {s : Slice} (pos : s.Pos) :
                                                                                                                                                  s.Pos

                                                                                                                                                  Returns the previous valid position before the given position, or panics if the position is the start position.

                                                                                                                                                  Equations
                                                                                                                                                  Instances For
                                                                                                                                                    @[inline]
                                                                                                                                                    def String.Slice.pos (s : Slice) (off : Pos.Raw) (h : Pos.Raw.IsValidForSlice s off) :
                                                                                                                                                    s.Pos

                                                                                                                                                    Constructs a valid position on s from a position and a proof that it is valid.

                                                                                                                                                    Equations
                                                                                                                                                    • s.pos off h = { offset := off, isValidForSlice := h }
                                                                                                                                                    Instances For
                                                                                                                                                      @[simp]
                                                                                                                                                      theorem String.Slice.offset_pos {s : Slice} {off : Pos.Raw} {h : Pos.Raw.IsValidForSlice s off} :
                                                                                                                                                      (s.pos off h).offset = off

                                                                                                                                                      Constructs a valid position on s from a position, returning none if the position is not valid.

                                                                                                                                                      Equations
                                                                                                                                                      Instances For
                                                                                                                                                        def String.Slice.pos! (s : Slice) (off : Pos.Raw) :
                                                                                                                                                        s.Pos

                                                                                                                                                        Constructs a valid position s from a position, panicking if the position is not valid.

                                                                                                                                                        Equations
                                                                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                                                                        Instances For
                                                                                                                                                          @[inline]
                                                                                                                                                          def String.ValidPos.next {s : String} (pos : s.ValidPos) (h : pos s.endValidPos) :

                                                                                                                                                          Advances a valid position on a string to the next valid position, given a proof that the position is not the past-the-end position, which guarantees that such a position exists.

                                                                                                                                                          Equations
                                                                                                                                                          Instances For
                                                                                                                                                            @[inline]

                                                                                                                                                            Advances a valid position on a string to the next valid position, or returns none if the given position is the past-the-end position.

                                                                                                                                                            Equations
                                                                                                                                                            Instances For
                                                                                                                                                              @[inline]

                                                                                                                                                              Advances a valid position on a string to the next valid position, or panics if the given position is the past-the-end position.

                                                                                                                                                              Equations
                                                                                                                                                              Instances For
                                                                                                                                                                @[inline]
                                                                                                                                                                def String.ValidPos.prev {s : String} (pos : s.ValidPos) (h : pos s.startValidPos) :

                                                                                                                                                                Returns the previous valid position before the given position, given a proof that the position is not the start position, which guarantees that such a position exists.

                                                                                                                                                                Equations
                                                                                                                                                                Instances For
                                                                                                                                                                  @[inline]

                                                                                                                                                                  Returns the previous valid position before the given position, or none if the position is the start position.

                                                                                                                                                                  Equations
                                                                                                                                                                  Instances For
                                                                                                                                                                    @[inline]

                                                                                                                                                                    Returns the previous valid position before the given position, or panics if the position is the start position.

                                                                                                                                                                    Equations
                                                                                                                                                                    Instances For
                                                                                                                                                                      @[inline]
                                                                                                                                                                      def String.pos (s : String) (off : Pos.Raw) (h : Pos.Raw.IsValid s off) :

                                                                                                                                                                      Constructs a valid position on s from a position and a proof that it is valid.

                                                                                                                                                                      Equations
                                                                                                                                                                      Instances For
                                                                                                                                                                        @[inline]

                                                                                                                                                                        Constructs a valid position on s from a position, returning none if the position is not valid.

                                                                                                                                                                        Equations
                                                                                                                                                                        Instances For
                                                                                                                                                                          @[inline]
                                                                                                                                                                          def String.pos! (s : String) (off : Pos.Raw) :

                                                                                                                                                                          Constructs a valid position s from a position, panicking if the position is not valid.

                                                                                                                                                                          Equations
                                                                                                                                                                          Instances For
                                                                                                                                                                            @[inline]
                                                                                                                                                                            def String.Slice.Pos.cast {s t : Slice} (pos : s.Pos) (h : s = t) :
                                                                                                                                                                            t.Pos

                                                                                                                                                                            Constructs a valid position on t from a valid position on s and a proof that s = t.

                                                                                                                                                                            Equations
                                                                                                                                                                            Instances For
                                                                                                                                                                              @[simp]
                                                                                                                                                                              theorem String.Slice.Pos.offset_cast {s t : Slice} {pos : s.Pos} {h : s = t} :
                                                                                                                                                                              (pos.cast h).offset = pos.offset
                                                                                                                                                                              @[simp]
                                                                                                                                                                              theorem String.Slice.Pos.cast_rfl {s : Slice} {pos : s.Pos} :
                                                                                                                                                                              pos.cast = pos
                                                                                                                                                                              @[inline]
                                                                                                                                                                              def String.ValidPos.cast {s t : String} (pos : s.ValidPos) (h : s = t) :

                                                                                                                                                                              Constructs a valid position on t from a valid position on s and a proof that s = t.

                                                                                                                                                                              Equations
                                                                                                                                                                              Instances For
                                                                                                                                                                                @[simp]
                                                                                                                                                                                theorem String.ValidPos.offset_cast {s t : String} {pos : s.ValidPos} {h : s = t} :
                                                                                                                                                                                (pos.cast h).offset = pos.offset
                                                                                                                                                                                @[simp]
                                                                                                                                                                                theorem String.ValidPos.cast_rfl {s : String} {pos : s.ValidPos} :
                                                                                                                                                                                pos.cast = pos
                                                                                                                                                                                @[inline]
                                                                                                                                                                                def String.Slice.findNextPos (offset : Pos.Raw) (s : Slice) (_h : offset < s.rawEndPos) :
                                                                                                                                                                                s.Pos

                                                                                                                                                                                Given a byte position within a string slice, obtains the smallest valid position that is strictly greater than the given byte position.

                                                                                                                                                                                Equations
                                                                                                                                                                                Instances For
                                                                                                                                                                                  @[simp]
                                                                                                                                                                                  theorem String.Pos.Raw.le_refl {p : Raw} :
                                                                                                                                                                                  p p
                                                                                                                                                                                  theorem String.Pos.Raw.le_of_lt {p q : Raw} :
                                                                                                                                                                                  p < qp q
                                                                                                                                                                                  theorem String.Pos.Raw.inc_le {p q : Raw} :
                                                                                                                                                                                  p.inc q p < q
                                                                                                                                                                                  theorem String.Slice.Pos.prevAuxGo_le_self {s : Slice} {p : Nat} {h : p < s.utf8ByteSize} :
                                                                                                                                                                                  prevAux.go p h { byteIdx := p }
                                                                                                                                                                                  theorem String.Pos.Raw.lt_of_le_of_lt {a b c : Raw} :
                                                                                                                                                                                  a bb < ca < c
                                                                                                                                                                                  theorem String.Pos.Raw.ne_of_lt {a b : Raw} :
                                                                                                                                                                                  a < ba b
                                                                                                                                                                                  theorem String.Slice.Pos.prev_ne_endPos {s : Slice} {p : s.Pos} {h : p s.startPos} :
                                                                                                                                                                                  @[simp]
                                                                                                                                                                                  theorem String.Slice.Pos.prev_lt {s : Slice} {p : s.Pos} {h : p s.startPos} :
                                                                                                                                                                                  p.prev h < p
                                                                                                                                                                                  def String.Slice.Pos.nextn {s : Slice} (p : s.Pos) (n : Nat) :
                                                                                                                                                                                  s.Pos

                                                                                                                                                                                  Advances the position p n times, saturating at s.endPos if necessary.

                                                                                                                                                                                  Equations
                                                                                                                                                                                  Instances For
                                                                                                                                                                                    def String.Slice.Pos.prevn {s : Slice} (p : s.Pos) (n : Nat) :
                                                                                                                                                                                    s.Pos

                                                                                                                                                                                    Iterates p.prev n times, saturating at s.startPos if necessary.

                                                                                                                                                                                    Equations
                                                                                                                                                                                    Instances For
                                                                                                                                                                                      Equations
                                                                                                                                                                                      Instances For
                                                                                                                                                                                        @[reducible, inline, deprecated String.Pos.Raw.utf8GetAux (since := "2025-10-09")]
                                                                                                                                                                                        Equations
                                                                                                                                                                                        Instances For
                                                                                                                                                                                          @[extern lean_string_utf8_get]

                                                                                                                                                                                          Returns the character at position p of a string. If p is not a valid position, returns the fallback value (default : Char), which is 'A', but does not panic.

                                                                                                                                                                                          This function is overridden with an efficient implementation in runtime code. See String.Pos.Raw.utf8GetAux for the reference implementation.

                                                                                                                                                                                          This is a legacy function. The recommended alternative is String.ValidPos.get, combined with String.pos or another means of obtaining a String.ValidPos.

                                                                                                                                                                                          Examples:

                                                                                                                                                                                          • "abc".get ⟨1⟩ = 'b'
                                                                                                                                                                                          • "abc".get ⟨3⟩ = (default : Char) because byte 3 is at the end of the string.
                                                                                                                                                                                          • "L∃∀N".get ⟨2⟩ = (default : Char) because byte 2 is in the middle of '∃'.
                                                                                                                                                                                          Equations
                                                                                                                                                                                          Instances For
                                                                                                                                                                                            @[extern lean_string_utf8_get, deprecated String.Pos.Raw.get (since := "2025-10-14")]
                                                                                                                                                                                            def String.get (s : String) (p : Pos.Raw) :
                                                                                                                                                                                            Equations
                                                                                                                                                                                            Instances For
                                                                                                                                                                                              Equations
                                                                                                                                                                                              Instances For
                                                                                                                                                                                                @[reducible, inline, deprecated String.Pos.Raw.utf8GetAux (since := "2025-10-09")]
                                                                                                                                                                                                Equations
                                                                                                                                                                                                Instances For
                                                                                                                                                                                                  @[extern lean_string_utf8_get_opt]

                                                                                                                                                                                                  Returns the character at position p of a string. If p is not a valid position, returns none.

                                                                                                                                                                                                  This function is overridden with an efficient implementation in runtime code. See String.utf8GetAux? for the reference implementation.

                                                                                                                                                                                                  This is a legacy function. The recommended alternative is String.ValidPos.get, combined with String.pos? or another means of obtaining a String.ValidPos.

                                                                                                                                                                                                  Examples:

                                                                                                                                                                                                  • "abc".get? ⟨1⟩ = some 'b'
                                                                                                                                                                                                  • "abc".get? ⟨3⟩ = none
                                                                                                                                                                                                  • "L∃∀N".get? ⟨1⟩ = some '∃'
                                                                                                                                                                                                  • "L∃∀N".get? ⟨2⟩ = none
                                                                                                                                                                                                  Equations
                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                    @[extern lean_string_utf8_get_opt, deprecated String.Pos.Raw.get? (since := "2025-10-14")]
                                                                                                                                                                                                    Equations
                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                      @[extern lean_string_utf8_get_bang]

                                                                                                                                                                                                      Returns the character at position p of a string. Panics if p is not a valid position.

                                                                                                                                                                                                      See String.pos? and String.ValidPos.get for a safer alternative.

                                                                                                                                                                                                      This function is overridden with an efficient implementation in runtime code. See String.utf8GetAux for the reference implementation.

                                                                                                                                                                                                      This is a legacy function. The recommended alternative is String.ValidPos.get, combined with String.pos! or another means of obtaining a String.ValidPos.

                                                                                                                                                                                                      Examples

                                                                                                                                                                                                      • "abc".get! ⟨1⟩ = 'b'
                                                                                                                                                                                                      Equations
                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                        @[extern lean_string_utf8_get_bang, deprecated String.Pos.Raw.get! (since := "2025-10-14")]
                                                                                                                                                                                                        def String.get! (s : String) (p : Pos.Raw) :
                                                                                                                                                                                                        Equations
                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                          Equations
                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                            @[reducible, inline, deprecated String.Pos.Raw.utf8SetAux (since := "2025-10-09")]
                                                                                                                                                                                                            abbrev String.utf8SetAux (c' : Char) :
                                                                                                                                                                                                            Equations
                                                                                                                                                                                                            Instances For
                                                                                                                                                                                                              @[simp]
                                                                                                                                                                                                              theorem String.ValidPos.toSlice_get {s : String} {p : s.ValidPos} {h : p.toSlice s.toSlice.endPos} :
                                                                                                                                                                                                              p.toSlice.get h = p.get
                                                                                                                                                                                                              @[simp]
                                                                                                                                                                                                              theorem String.ValidPos.offset_next {s : String} (p : s.ValidPos) (h : p s.endValidPos) :
                                                                                                                                                                                                              (p.next h).offset = p.offset + p.get h
                                                                                                                                                                                                              @[simp]
                                                                                                                                                                                                              @[inline]

                                                                                                                                                                                                              The slice from the beginning of s up to p (exclusive).

                                                                                                                                                                                                              Equations
                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                @[simp]
                                                                                                                                                                                                                theorem String.str_replaceEnd {s : String} {p : s.ValidPos} :
                                                                                                                                                                                                                (s.replaceEnd p).str = s
                                                                                                                                                                                                                @[inline]

                                                                                                                                                                                                                The slice from p (inclusive) up to the end of s.

                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                  @[simp]
                                                                                                                                                                                                                  theorem String.str_replaceStart {s : String} {p : s.ValidPos} :
                                                                                                                                                                                                                  @[extern lean_string_utf8_set]
                                                                                                                                                                                                                  def String.ValidPos.set {s : String} (p : s.ValidPos) (c : Char) (hp : p s.endValidPos) :

                                                                                                                                                                                                                  Replaces the character at a specified position in a string with a new character.

                                                                                                                                                                                                                  If both the replacement character and the replaced character are 7-bit ASCII characters and the string is not shared, then it is updated in-place and not copied.

                                                                                                                                                                                                                  Examples:

                                                                                                                                                                                                                  • ("abc".pos ⟨1⟩ (by decide)).set 'B' (by decide) = "aBc"
                                                                                                                                                                                                                  • ("L∃∀N".pos ⟨4⟩ (by decide)).set 'X' (by decide) = "L∃XN"
                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                    theorem String.ValidPos.set_eq_append {s : String} {p : s.ValidPos} {c : Char} {hp : p s.endValidPos} :
                                                                                                                                                                                                                    p.set c hp = (s.replaceEnd p).copy ++ singleton c ++ (s.replaceStart (p.next hp)).copy
                                                                                                                                                                                                                    theorem String.Pos.Raw.IsValid.set_of_le {s : String} {p : s.ValidPos} {c : Char} {hp : p s.endValidPos} {q : Raw} (hq : IsValid s q) (hpq : q p.offset) :
                                                                                                                                                                                                                    IsValid (p.set c hp) q
                                                                                                                                                                                                                    @[inline]
                                                                                                                                                                                                                    def String.ValidPos.setOfLE {s : String} (q p : s.ValidPos) (c : Char) (hp : p s.endValidPos) (hpq : q p) :
                                                                                                                                                                                                                    (p.set c hp).ValidPos

                                                                                                                                                                                                                    Given a valid position in a string, obtain the corresponding position after setting a character on that string, provided that the position was before the changed position.

                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                      @[simp]
                                                                                                                                                                                                                      theorem String.ValidPos.offset_setOfLE {s : String} {q p : s.ValidPos} {c : Char} {hp : p s.endValidPos} {hpq : q p} :
                                                                                                                                                                                                                      (q.setOfLE p c hp hpq).offset = q.offset
                                                                                                                                                                                                                      def String.ValidPos.modify {s : String} (p : s.ValidPos) (f : CharChar) (hp : p s.endValidPos) :

                                                                                                                                                                                                                      Replaces the character at position p in the string s with the result of applying f to that character.

                                                                                                                                                                                                                      If both the replacement character and the replaced character are 7-bit ASCII characters and the string is not shared, then it is updated in-place and not copied.

                                                                                                                                                                                                                      Examples:

                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                        theorem String.Pos.Raw.IsValid.modify_of_le {s : String} {p : s.ValidPos} {f : CharChar} {hp : p s.endValidPos} {q : Raw} (hq : IsValid s q) (hpq : q p.offset) :
                                                                                                                                                                                                                        IsValid (p.modify f hp) q
                                                                                                                                                                                                                        def String.ValidPos.modifyOfLE {s : String} (q p : s.ValidPos) (f : CharChar) (hp : p s.endValidPos) (hpq : q p) :
                                                                                                                                                                                                                        (p.modify f hp).ValidPos

                                                                                                                                                                                                                        Given a valid position in a string, obtain the corresponding position after modifying a character in that string, provided that the position was before the changed position.

                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                                          @[simp]
                                                                                                                                                                                                                          theorem String.ValidPos.offset_modifyOfLE {s : String} {q p : s.ValidPos} {f : CharChar} {hp : p s.endValidPos} {hpq : q p} :
                                                                                                                                                                                                                          (q.modifyOfLE p f hp hpq).offset = q.offset
                                                                                                                                                                                                                          @[extern lean_string_utf8_set]

                                                                                                                                                                                                                          Replaces the character at a specified position in a string with a new character. If the position is invalid, the string is returned unchanged.

                                                                                                                                                                                                                          If both the replacement character and the replaced character are 7-bit ASCII characters and the string is not shared, then it is updated in-place and not copied.

                                                                                                                                                                                                                          This is a legacy function. The recommended alternative is String.ValidPos.set, combined with String.pos or another means of obtaining a String.ValidPos.

                                                                                                                                                                                                                          Examples:

                                                                                                                                                                                                                          • "abc".set ⟨1⟩ 'B' = "aBc"
                                                                                                                                                                                                                          • "abc".set ⟨3⟩ 'D' = "abc"
                                                                                                                                                                                                                          • "L∃∀N".set ⟨4⟩ 'X' = "L∃XN"
                                                                                                                                                                                                                          • "L∃∀N".set ⟨2⟩ 'X' = "L∃∀N" because '∃' is a multi-byte character, so the byte index 2 is an invalid position.
                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                                            @[extern lean_string_utf8_set, deprecated String.Pos.Raw.set (since := "2025-10-14")]
                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                            Instances For
                                                                                                                                                                                                                              def String.Pos.Raw.modify (s : String) (i : Raw) (f : CharChar) :

                                                                                                                                                                                                                              Replaces the character at position p in the string s with the result of applying f to that character. If p is an invalid position, the string is returned unchanged.

                                                                                                                                                                                                                              If both the replacement character and the replaced character are 7-bit ASCII characters and the string is not shared, then it is updated in-place and not copied.

                                                                                                                                                                                                                              This is a legacy function. The recommended alternative is String.ValidPos.set, combined with String.pos or another means of obtaining a String.ValidPos.

                                                                                                                                                                                                                              Examples:

                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                @[deprecated String.Pos.Raw.modify (since := "2025-10-10")]
                                                                                                                                                                                                                                def String.modify (s : String) (i : Pos.Raw) (f : CharChar) :

                                                                                                                                                                                                                                Replaces the character at position p in the string s with the result of applying f to that character. If p is an invalid position, the string is returned unchanged.

                                                                                                                                                                                                                                If both the replacement character and the replaced character are 7-bit ASCII characters and the string is not shared, then it is updated in-place and not copied.

                                                                                                                                                                                                                                This is a legacy function. The recommended alternative is String.ValidPos.set, combined with String.pos or another means of obtaining a String.ValidPos.

                                                                                                                                                                                                                                Examples:

                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                                  @[extern lean_string_utf8_next]

                                                                                                                                                                                                                                  Returns the next position in a string after position p. If p is not a valid position or p = s.endPos, returns the position one byte after p.

                                                                                                                                                                                                                                  A run-time bounds check is performed to determine whether p is at the end of the string. If a bounds check has already been performed, use String.next' to avoid a repeated check.

                                                                                                                                                                                                                                  This is a legacy function. The recommended alternative is String.ValidPos.next or one of its variants like String.ValidPos.next?, combined with String.pos or another means of obtaining a String.ValisPos.

                                                                                                                                                                                                                                  Some examples of edge cases:

                                                                                                                                                                                                                                  • "abc".next ⟨3⟩ = ⟨4⟩, since 3 = "abc".endPos
                                                                                                                                                                                                                                  • "L∃∀N".next ⟨2⟩ = ⟨3⟩, since 2 points into the middle of a multi-byte UTF-8 character

                                                                                                                                                                                                                                  Examples:

                                                                                                                                                                                                                                  • "abc".get ("abc".next 0) = 'b'
                                                                                                                                                                                                                                  • "L∃∀N".get (0 |> "L∃∀N".next |> "L∃∀N".next) = '∀'
                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                                    @[extern lean_string_utf8_next, deprecated String.Pos.Raw.next (since := "2025-10-14")]
                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                                        @[reducible, inline, deprecated String.Pos.Raw.utf8PrevAux (since := "2025-10-10")]
                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                                                          @[extern lean_string_utf8_prev]

                                                                                                                                                                                                                                          Returns the position in a string before a specified position, p. If p = ⟨0⟩, returns 0. If p is greater than endPos, returns the position one byte before p. Otherwise, if p occurs in the middle of a multi-byte character, returns the beginning position of that character.

                                                                                                                                                                                                                                          For example, "L∃∀N".prev ⟨3⟩ is ⟨1⟩, since byte 3 occurs in the middle of the multi-byte character '∃' that starts at byte 1.

                                                                                                                                                                                                                                          This is a legacy function. The recommended alternative is String.ValidPos.prev or one of its variants like String.ValidPos.prev?, combined with String.pos or another means of obtaining a String.ValidPos.

                                                                                                                                                                                                                                          Examples:

                                                                                                                                                                                                                                          • "abc".get ("abc".endPos |> "abc".prev) = 'c'
                                                                                                                                                                                                                                          • "L∃∀N".get ("L∃∀N".endPos |> "L∃∀N".prev |> "L∃∀N".prev |> "L∃∀N".prev) = '∃'
                                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                                                            @[extern lean_string_utf8_prev, deprecated String.Pos.Raw.prev (since := "2025-10-14")]
                                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                                            Instances For
                                                                                                                                                                                                                                              @[inline]

                                                                                                                                                                                                                                              Returns the first character in s. If s = "", returns (default : Char).

                                                                                                                                                                                                                                              Examples:

                                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                                @[export lean_string_front]
                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                                                  @[inline]

                                                                                                                                                                                                                                                  Returns the last character in s. If s = "", returns (default : Char).

                                                                                                                                                                                                                                                  Examples:

                                                                                                                                                                                                                                                  • "abc".back = 'c'
                                                                                                                                                                                                                                                  • "".back = (default : Char)
                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                                                    @[extern lean_string_utf8_at_end]

                                                                                                                                                                                                                                                    Returns true if a specified byte position is greater than or equal to the position which points to the end of a string. Otherwise, returns false.

                                                                                                                                                                                                                                                    Examples:

                                                                                                                                                                                                                                                    • (0 |> "abc".next |> "abc".next |> "abc".atEnd) = false
                                                                                                                                                                                                                                                    • (0 |> "abc".next |> "abc".next |> "abc".next |> "abc".next |> "abc".atEnd) = true
                                                                                                                                                                                                                                                    • (0 |> "L∃∀N".next |> "L∃∀N".next |> "L∃∀N".next |> "L∃∀N".atEnd) = false
                                                                                                                                                                                                                                                    • (0 |> "L∃∀N".next |> "L∃∀N".next |> "L∃∀N".next |> "L∃∀N".next |> "L∃∀N".atEnd) = true
                                                                                                                                                                                                                                                    • "abc".atEnd ⟨4⟩ = true
                                                                                                                                                                                                                                                    • "L∃∀N".atEnd ⟨7⟩ = false
                                                                                                                                                                                                                                                    • "L∃∀N".atEnd ⟨8⟩ = true
                                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                                                      @[extern lean_string_utf8_at_end, deprecated String.Pos.Raw.atEnd (since := "2025-10-14")]
                                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                                                        @[extern lean_string_utf8_get_fast]
                                                                                                                                                                                                                                                        def String.Pos.Raw.get' (s : String) (p : Raw) (h : ¬atEnd s p = true) :

                                                                                                                                                                                                                                                        Returns the character at position p of a string. Returns (default : Char), which is 'A', if p is not a valid position.

                                                                                                                                                                                                                                                        Requires evidence, h, that p is within bounds instead of performing a run-time bounds check as in String.get.

                                                                                                                                                                                                                                                        A typical pattern combines get' with a dependent if-expression to avoid the overhead of an additional bounds check. For example:

                                                                                                                                                                                                                                                        def getInBounds? (s : String) (p : String.Pos) : Option Char :=
                                                                                                                                                                                                                                                          if h : s.atEnd p then none else some (s.get' p h)
                                                                                                                                                                                                                                                        

                                                                                                                                                                                                                                                        Even with evidence of ¬ s.atEnd p, p may be invalid if a byte index points into the middle of a multi-byte UTF-8 character. For example, "L∃∀N".get' ⟨2⟩ (by decide) = (default : Char).

                                                                                                                                                                                                                                                        This is a legacy function. The recommended alternative is String.ValidPos.get, combined with String.pos or another means of obtaining a String.ValidPos.

                                                                                                                                                                                                                                                        Examples:

                                                                                                                                                                                                                                                        • "abc".get' 0 (by decide) = 'a'
                                                                                                                                                                                                                                                        • let lean := "L∃∀N"; lean.get' (0 |> lean.next |> lean.next) (by decide) = '∀'
                                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                                                                          @[extern lean_string_utf8_get_fast, deprecated String.Pos.Raw.get' (since := "2025-10-14")]
                                                                                                                                                                                                                                                          def String.get' (s : String) (p : Pos.Raw) (h : ¬Pos.Raw.atEnd s p = true) :
                                                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                                                                            @[extern lean_string_utf8_next_fast]
                                                                                                                                                                                                                                                            def String.Pos.Raw.next' (s : String) (p : Raw) (h : ¬atEnd s p = true) :

                                                                                                                                                                                                                                                            Returns the next position in a string after position p. The result is unspecified if p is not a valid position.

                                                                                                                                                                                                                                                            Requires evidence, h, that p is within bounds. No run-time bounds check is performed, as in String.next.

                                                                                                                                                                                                                                                            A typical pattern combines String.next' with a dependent if-expression to avoid the overhead of an additional bounds check. For example:

                                                                                                                                                                                                                                                            def next? (s : String) (p : String.Pos) : Option Char :=
                                                                                                                                                                                                                                                              if h : s.atEnd p then none else s.get (s.next' p h)
                                                                                                                                                                                                                                                            

                                                                                                                                                                                                                                                            This is a legacy function. The recommended alternative is String.ValidPos.next, combined with String.pos or another means of obtaining a String.ValidPos.

                                                                                                                                                                                                                                                            Example:

                                                                                                                                                                                                                                                            • let abc := "abc"; abc.get (abc.next' 0 (by decide)) = 'b'
                                                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                                                            Instances For
                                                                                                                                                                                                                                                              @[extern lean_string_utf8_next_fast, deprecated String.Pos.Raw.next' (since := "2025-10-14")]
                                                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                                                @[deprecated String.Pos.Raw.lt_iff (since := "2025-10-10")]
                                                                                                                                                                                                                                                                theorem String.pos_lt_eq (p₁ p₂ : Pos.Raw) :
                                                                                                                                                                                                                                                                (p₁ < p₂) = (p₁.byteIdx < p₂.byteIdx)
                                                                                                                                                                                                                                                                @[deprecated String.Pos.Raw.byteIdx_add_char (since := "2025-10-10")]
                                                                                                                                                                                                                                                                theorem String.pos_add_char (p : Pos.Raw) (c : Char) :
                                                                                                                                                                                                                                                                theorem String.Pos.Raw.ne_zero_of_lt {a b : Raw} :
                                                                                                                                                                                                                                                                a < bb 0
                                                                                                                                                                                                                                                                theorem String.Pos.Raw.lt_next (s : String) (i : Raw) :
                                                                                                                                                                                                                                                                i < next s i
                                                                                                                                                                                                                                                                @[deprecated String.Pos.Raw.byteIdx_lt_byteIdx_next (since := "2025-10-10")]
                                                                                                                                                                                                                                                                theorem String.Pos.Raw.utf8PrevAux_lt_of_pos (cs : List Char) (i p : Raw) :
                                                                                                                                                                                                                                                                i < pp 0(utf8PrevAux cs i p).byteIdx < p.byteIdx
                                                                                                                                                                                                                                                                theorem String.Pos.Raw.prev_lt_of_pos (s : String) (i : Raw) (h : i 0) :
                                                                                                                                                                                                                                                                @[deprecated String.Pos.Raw.prev_lt_of_pos (since := "2025-10-10")]
                                                                                                                                                                                                                                                                theorem String.prev_lt_of_pos (s : String) (i : Pos.Raw) (h : i 0) :
                                                                                                                                                                                                                                                                @[irreducible]
                                                                                                                                                                                                                                                                def String.posOfAux (s : String) (c : Char) (stopPos pos : Pos.Raw) :
                                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                                                                  @[inline]
                                                                                                                                                                                                                                                                  def String.posOf (s : String) (c : Char) :

                                                                                                                                                                                                                                                                  Returns the position of the first occurrence of a character, c, in a string s. If s does not contain c, returns s.endPos.

                                                                                                                                                                                                                                                                  Examples:

                                                                                                                                                                                                                                                                  • "abcba".posOf 'a' = ⟨0⟩
                                                                                                                                                                                                                                                                  • "abcba".posOf 'z' = ⟨5⟩
                                                                                                                                                                                                                                                                  • "L∃∀N".posOf '∀' = ⟨4⟩
                                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                                                                    @[export lean_string_posof]
                                                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                                                                      @[irreducible]
                                                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                                                                        @[inline]

                                                                                                                                                                                                                                                                        Returns the position of the last occurrence of a character, c, in a string s. If s does not contain c, returns none.

                                                                                                                                                                                                                                                                        Examples:

                                                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                                                                                          @[irreducible]
                                                                                                                                                                                                                                                                          def String.findAux (s : String) (p : CharBool) (stopPos pos : Pos.Raw) :
                                                                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                                                                                            @[inline]
                                                                                                                                                                                                                                                                            def String.find (s : String) (p : CharBool) :

                                                                                                                                                                                                                                                                            Finds the position of the first character in a string for which the Boolean predicate p returns true. If there is no such character in the string, then the end position of the string is returned.

                                                                                                                                                                                                                                                                            Examples:

                                                                                                                                                                                                                                                                            • "coffee tea water".find (·.isWhitespace) = ⟨6⟩
                                                                                                                                                                                                                                                                            • "tea".find (· == 'X') = ⟨3⟩
                                                                                                                                                                                                                                                                            • "".find (· == 'X') = ⟨0⟩
                                                                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                                                                            Instances For
                                                                                                                                                                                                                                                                              @[irreducible]
                                                                                                                                                                                                                                                                              def String.revFindAux (s : String) (p : CharBool) (pos : Pos.Raw) :
                                                                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                                                                @[inline]

                                                                                                                                                                                                                                                                                Finds the position of the last character in a string for which the Boolean predicate p returns true. If there is no such character in the string, then none is returned.

                                                                                                                                                                                                                                                                                Examples:

                                                                                                                                                                                                                                                                                • "coffee tea water".revFind (·.isWhitespace) = some ⟨10⟩
                                                                                                                                                                                                                                                                                • "tea".revFind (· == 'X') = none
                                                                                                                                                                                                                                                                                • "".revFind (· == 'X') = none
                                                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                                                                                  @[reducible, inline]
                                                                                                                                                                                                                                                                                  abbrev String.Pos.Raw.min (p₁ p₂ : Raw) :

                                                                                                                                                                                                                                                                                  Returns either p₁ or p₂, whichever has the least byte index.

                                                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                                                                                    @[export lean_string_pos_min]
                                                                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                                                                    Instances For

                                                                                                                                                                                                                                                                                      Returns the first position where the two strings differ.

                                                                                                                                                                                                                                                                                      If one string is a prefix of the other, then the returned position is the end position of the shorter string. If the strings are identical, then their end position is returned.

                                                                                                                                                                                                                                                                                      Examples:

                                                                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                                                                                        @[irreducible]
                                                                                                                                                                                                                                                                                        def String.firstDiffPos.loop (a b : String) (stopPos i : Pos.Raw) :
                                                                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                                                                                                          @[extern lean_string_utf8_extract]

                                                                                                                                                                                                                                                                                          Creates a new string that consists of the region of the input string delimited by the two positions.

                                                                                                                                                                                                                                                                                          The result is "" if the start position is greater than or equal to the end position or if the start position is at the end of the string. If either position is invalid (that is, if either points at the middle of a multi-byte UTF-8 character) then the result is unspecified.

                                                                                                                                                                                                                                                                                          This is a legacy function. The recommended alternative is String.ValidPos.extract, but usually it is even better to operate on String.Slice instead and call String.Slice.copy (only) if required.

                                                                                                                                                                                                                                                                                          Examples:

                                                                                                                                                                                                                                                                                          • "red green blue".extract ⟨0⟩ ⟨3⟩ = "red"
                                                                                                                                                                                                                                                                                          • "red green blue".extract ⟨3⟩ ⟨0⟩ = ""
                                                                                                                                                                                                                                                                                          • "red green blue".extract ⟨0⟩ ⟨100⟩ = "red green blue"
                                                                                                                                                                                                                                                                                          • "red green blue".extract ⟨4⟩ ⟨100⟩ = "green blue"
                                                                                                                                                                                                                                                                                          • "L∃∀N".extract ⟨1⟩ ⟨2⟩ = "∃∀N"
                                                                                                                                                                                                                                                                                          • "L∃∀N".extract ⟨2⟩ ⟨100⟩ = ""
                                                                                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                                                                                            Instances For
                                                                                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                                                                                @[extern lean_string_utf8_extract, deprecated String.Pos.Raw.extract (since := "2025-10-14")]
                                                                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                                                                                                  @[irreducible, specialize #[]]
                                                                                                                                                                                                                                                                                                  def String.splitAux (s : String) (p : CharBool) (b i : Pos.Raw) (r : List String) :
                                                                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                                                                                                    @[inline]

                                                                                                                                                                                                                                                                                                    Splits a string at each character for which p returns true.

                                                                                                                                                                                                                                                                                                    The characters that satisfy p are not included in any of the resulting strings. If multiple characters in a row satisfy p, then the resulting list will contain empty strings.

                                                                                                                                                                                                                                                                                                    Examples:

                                                                                                                                                                                                                                                                                                    • "coffee tea water".split (·.isWhitespace) = ["coffee", "tea", "water"]
                                                                                                                                                                                                                                                                                                    • "coffee tea water".split (·.isWhitespace) = ["coffee", "", "tea", "", "water"]
                                                                                                                                                                                                                                                                                                    • "fun x =>\n x + 1\n".split (· == '\n') = ["fun x =>", " x + 1", ""]
                                                                                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                                                                                                      @[inline, deprecated String.splitToList (since := "2025-10-17")]
                                                                                                                                                                                                                                                                                                      def String.split (s : String) (p : CharBool) :
                                                                                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                                                                                                        @[irreducible]
                                                                                                                                                                                                                                                                                                        def String.splitOnAux (s sep : String) (b i j : Pos.Raw) (r : List String) :

                                                                                                                                                                                                                                                                                                        Auxiliary for splitOn. Preconditions:

                                                                                                                                                                                                                                                                                                        • sep is not empty
                                                                                                                                                                                                                                                                                                        • b <= i are indexes into s
                                                                                                                                                                                                                                                                                                        • j is an index into sep, and not at the end

                                                                                                                                                                                                                                                                                                        It represents the state where we have currently parsed some split parts into r (in reverse order), b is the beginning of the string / the end of the previous match of sep, and the first j bytes of sep match the bytes i-j .. i of s.

                                                                                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                                                                                                                          @[inline]
                                                                                                                                                                                                                                                                                                          def String.splitOn (s : String) (sep : String := " ") :

                                                                                                                                                                                                                                                                                                          Splits a string s on occurrences of the separator string sep. The default separator is " ".

                                                                                                                                                                                                                                                                                                          When sep is empty, the result is [s]. When sep occurs in overlapping patterns, the first match is taken. There will always be exactly n+1 elements in the returned list if there were n non-overlapping matches of sep in the string. The separators are not included in the returned substrings.

                                                                                                                                                                                                                                                                                                          Examples:

                                                                                                                                                                                                                                                                                                          • "here is some text ".splitOn = ["here", "is", "some", "text", ""]
                                                                                                                                                                                                                                                                                                          • "here is some text ".splitOn "some" = ["here is ", " text "]
                                                                                                                                                                                                                                                                                                          • "here is some text ".splitOn "" = ["here is some text "]
                                                                                                                                                                                                                                                                                                          • "ababacabac".splitOn "aba" = ["", "bac", "c"]
                                                                                                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                                                                                                                            @[inline]
                                                                                                                                                                                                                                                                                                            def String.pushn (s : String) (c : Char) (n : Nat) :

                                                                                                                                                                                                                                                                                                            Adds multiple repetitions of a character to the end of a string.

                                                                                                                                                                                                                                                                                                            Returns s, with n repetitions of c at the end. Internally, the implementation repeatedly calls String.push, so the string is modified in-place if there is a unique reference to it.

                                                                                                                                                                                                                                                                                                            Examples:

                                                                                                                                                                                                                                                                                                            • "indeed".pushn '!' 2 = "indeed!!"
                                                                                                                                                                                                                                                                                                            • "indeed".pushn '!' 0 = "indeed"
                                                                                                                                                                                                                                                                                                            • "".pushn ' ' 4 = " "
                                                                                                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                                                                                                            Instances For
                                                                                                                                                                                                                                                                                                              @[export lean_string_pushn]
                                                                                                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                                                                                                @[inline]

                                                                                                                                                                                                                                                                                                                Checks whether a string is empty.

                                                                                                                                                                                                                                                                                                                Empty strings are equal to "" and have length and end position 0.

                                                                                                                                                                                                                                                                                                                Examples:

                                                                                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                                                                                                                  @[export lean_string_isempty]
                                                                                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                                                                                                                    @[inline]

                                                                                                                                                                                                                                                                                                                    Appends all the strings in a list of strings, in order.

                                                                                                                                                                                                                                                                                                                    Use String.intercalate to place a separator string between the strings in a list.

                                                                                                                                                                                                                                                                                                                    Examples:

                                                                                                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                                                                                                    Instances For

                                                                                                                                                                                                                                                                                                                      Appends the strings in a list of strings, placing the separator s between each pair.

                                                                                                                                                                                                                                                                                                                      Examples:

                                                                                                                                                                                                                                                                                                                      • ", ".intercalate ["red", "green", "blue"] = "red, green, blue"
                                                                                                                                                                                                                                                                                                                      • " and ".intercalate ["tea", "coffee"] = "tea and coffee"
                                                                                                                                                                                                                                                                                                                      • " | ".intercalate ["M", "", "N"] = "M | | N"
                                                                                                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                                                                                                                        @[export lean_string_intercalate]
                                                                                                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                                                                                                        Instances For

                                                                                                                                                                                                                                                                                                                          An iterator over the characters (Unicode code points) in a String. Typically created by String.iter.

                                                                                                                                                                                                                                                                                                                          String iterators pair a string with a valid byte index. This allows efficient character-by-character processing of strings while avoiding the need to manually ensure that byte indices are used with the correct strings.

                                                                                                                                                                                                                                                                                                                          An iterator is valid if the position i is valid for the string s, meaning 0 ≤ i ≤ s.endPos and i lies on a UTF8 byte boundary. If i = s.endPos, the iterator is at the end of the string.

                                                                                                                                                                                                                                                                                                                          Most operations on iterators return unspecified values if the iterator is not valid. The functions in the String.Iterator API rule out the creation of invalid iterators, with two exceptions:

                                                                                                                                                                                                                                                                                                                          • s : String

                                                                                                                                                                                                                                                                                                                            The string being iterated over.

                                                                                                                                                                                                                                                                                                                          • The current UTF-8 byte position in the string s.

                                                                                                                                                                                                                                                                                                                            This position is not guaranteed to be valid for the string. If the position is not valid, then the current character is (default : Char), similar to String.get on an invalid position.

                                                                                                                                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                                                                                                                                            def String.instDecidableEqIterator.decEq (x✝ x✝¹ : Iterator) :
                                                                                                                                                                                                                                                                                                                            Decidable (x✝ = x✝¹)
                                                                                                                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                                                                                                                            Instances For
                                                                                                                                                                                                                                                                                                                              @[inline]

                                                                                                                                                                                                                                                                                                                              Creates an iterator at the beginning of the string.

                                                                                                                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                                                                                                                @[reducible, inline]

                                                                                                                                                                                                                                                                                                                                Creates an iterator at the beginning of the string.

                                                                                                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                                                                                                Instances For

                                                                                                                                                                                                                                                                                                                                  The size of a string iterator is the number of bytes remaining.

                                                                                                                                                                                                                                                                                                                                  Recursive functions that iterate towards the end of a string will typically decrease this measure.

                                                                                                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                                                                                                  @[inline]

                                                                                                                                                                                                                                                                                                                                  The string being iterated over.

                                                                                                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                                                                                                                                    @[inline]

                                                                                                                                                                                                                                                                                                                                    The number of UTF-8 bytes remaining in the iterator.

                                                                                                                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                                                                                                                                      @[inline]

                                                                                                                                                                                                                                                                                                                                      The current UTF-8 byte position in the string s.

                                                                                                                                                                                                                                                                                                                                      This position is not guaranteed to be valid for the string. If the position is not valid, then the current character is (default : Char), similar to String.get on an invalid position.

                                                                                                                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                                                                                                                                        @[inline]

                                                                                                                                                                                                                                                                                                                                        Gets the character at the iterator's current position.

                                                                                                                                                                                                                                                                                                                                        A run-time bounds check is performed. Use String.Iterator.curr' to avoid redundant bounds checks.

                                                                                                                                                                                                                                                                                                                                        If the position is invalid, returns (default : Char).

                                                                                                                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                                                                                                                                                          @[inline]

                                                                                                                                                                                                                                                                                                                                          Moves the iterator's position forward by one character, unconditionally.

                                                                                                                                                                                                                                                                                                                                          It is only valid to call this function if the iterator is not at the end of the string (i.e. if Iterator.atEnd is false); otherwise, the resulting iterator will be invalid.

                                                                                                                                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                                                                                                                                                            @[inline]

                                                                                                                                                                                                                                                                                                                                            Moves the iterator's position backward by one character, unconditionally.

                                                                                                                                                                                                                                                                                                                                            The position is not changed if the iterator is at the beginning of the string.

                                                                                                                                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                                                                                                                                            Instances For
                                                                                                                                                                                                                                                                                                                                              @[inline]

                                                                                                                                                                                                                                                                                                                                              Checks whether the iterator is past its string's last character.

                                                                                                                                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                                                                                                                                @[inline]

                                                                                                                                                                                                                                                                                                                                                Checks whether the iterator is at or before the string's last character.

                                                                                                                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                                                                                                                                                  @[inline]

                                                                                                                                                                                                                                                                                                                                                  Checks whether the iterator is after the beginning of the string.

                                                                                                                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                                                                                                                                                    @[inline]

                                                                                                                                                                                                                                                                                                                                                    Gets the character at the iterator's current position.

                                                                                                                                                                                                                                                                                                                                                    The proof of it.hasNext ensures that there is, in fact, a character at the current position. This function is faster that String.Iterator.curr due to avoiding a run-time bounds check.

                                                                                                                                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                                                                                                                                                      @[inline]

                                                                                                                                                                                                                                                                                                                                                      Moves the iterator's position forward by one character, unconditionally.

                                                                                                                                                                                                                                                                                                                                                      The proof of it.hasNext ensures that there is, in fact, a position that's one character forwards. This function is faster that String.Iterator.next due to avoiding a run-time bounds check.

                                                                                                                                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                                                                                                                                                        @[inline]

                                                                                                                                                                                                                                                                                                                                                        Replaces the current character in the string.

                                                                                                                                                                                                                                                                                                                                                        Does nothing if the iterator is at the end of the string. If both the replacement character and the replaced character are 7-bit ASCII characters and the string is not shared, then it is updated in-place and not copied.

                                                                                                                                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                                                                                                                                                                          @[inline]

                                                                                                                                                                                                                                                                                                                                                          Moves the iterator's position to the end of the string, just past the last character.

                                                                                                                                                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                                                                                                                                                                            @[inline]

                                                                                                                                                                                                                                                                                                                                                            Extracts the substring between the positions of two iterators. The first iterator's position is the start of the substring, and the second iterator's position is the end.

                                                                                                                                                                                                                                                                                                                                                            Returns the empty string if the iterators are for different strings, or if the position of the first iterator is past the position of the second iterator.

                                                                                                                                                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                                                                                                                                                            Instances For

                                                                                                                                                                                                                                                                                                                                                              Moves the iterator's position forward by the specified number of characters.

                                                                                                                                                                                                                                                                                                                                                              The resulting iterator is only valid if the number of characters to skip is less than or equal to the number of characters left in the iterator.

                                                                                                                                                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                                                                                                                                                @[inline]

                                                                                                                                                                                                                                                                                                                                                                The remaining characters in an iterator, as a string.

                                                                                                                                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                                                                                                                                Instances For

                                                                                                                                                                                                                                                                                                                                                                  Moves the iterator's position forward by the specified number of characters.

                                                                                                                                                                                                                                                                                                                                                                  The resulting iterator is only valid if the number of characters to skip is less than or equal to the number of characters left in the iterator.

                                                                                                                                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                                                                                                                                  Instances For

                                                                                                                                                                                                                                                                                                                                                                    Moves the iterator's position back by the specified number of characters, stopping at the beginning of the string.

                                                                                                                                                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                                                                                                                                                                      @[irreducible]
                                                                                                                                                                                                                                                                                                                                                                      def String.offsetOfPosAux (s : String) (pos i : Pos.Raw) (offset : Nat) :
                                                                                                                                                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                                                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                                                                                                                                                                        @[inline]

                                                                                                                                                                                                                                                                                                                                                                        Returns the character index that corresponds to the provided position (i.e. UTF-8 byte index) in a string.

                                                                                                                                                                                                                                                                                                                                                                        If the position is at the end of the string, then the string's length in characters is returned. If the position is invalid due to pointing at the middle of a UTF-8 byte sequence, then the character index of the next character after the position is returned.

                                                                                                                                                                                                                                                                                                                                                                        Examples:

                                                                                                                                                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                                                                                                                                                                                          @[export lean_string_offsetofpos]
                                                                                                                                                                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                                                                                                                                                                                            @[irreducible, specialize #[]]
                                                                                                                                                                                                                                                                                                                                                                            def String.foldlAux {α : Type u} (f : αCharα) (s : String) (stopPos i : Pos.Raw) (a : α) :
                                                                                                                                                                                                                                                                                                                                                                            α
                                                                                                                                                                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                                                                                                                                                                            Instances For
                                                                                                                                                                                                                                                                                                                                                                              @[inline]
                                                                                                                                                                                                                                                                                                                                                                              def String.foldl {α : Type u} (f : αCharα) (init : α) (s : String) :
                                                                                                                                                                                                                                                                                                                                                                              α

                                                                                                                                                                                                                                                                                                                                                                              Folds a function over a string from the left, accumulating a value starting with init. The accumulated value is combined with each character in order, using f.

                                                                                                                                                                                                                                                                                                                                                                              Examples:

                                                                                                                                                                                                                                                                                                                                                                              • "coffee tea water".foldl (fun n c => if c.isWhitespace then n + 1 else n) 0 = 2
                                                                                                                                                                                                                                                                                                                                                                              • "coffee tea and water".foldl (fun n c => if c.isWhitespace then n + 1 else n) 0 = 3
                                                                                                                                                                                                                                                                                                                                                                              • "coffee tea water".foldl (·.push ·) "" = "coffee tea water"
                                                                                                                                                                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                                                                                                                                                                @[export lean_string_foldl]
                                                                                                                                                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                                                                                                                                                                                  @[irreducible, specialize #[]]
                                                                                                                                                                                                                                                                                                                                                                                  def String.foldrAux {α : Type u} (f : Charαα) (a : α) (s : String) (i begPos : Pos.Raw) :
                                                                                                                                                                                                                                                                                                                                                                                  α
                                                                                                                                                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                                                                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                                                                                                                                                                                    @[inline]
                                                                                                                                                                                                                                                                                                                                                                                    def String.foldr {α : Type u} (f : Charαα) (init : α) (s : String) :
                                                                                                                                                                                                                                                                                                                                                                                    α

                                                                                                                                                                                                                                                                                                                                                                                    Folds a function over a string from the right, accumulating a value starting with init. The accumulated value is combined with each character in reverse order, using f.

                                                                                                                                                                                                                                                                                                                                                                                    Examples:

                                                                                                                                                                                                                                                                                                                                                                                    • "coffee tea water".foldr (fun c n => if c.isWhitespace then n + 1 else n) 0 = 2
                                                                                                                                                                                                                                                                                                                                                                                    • "coffee tea and water".foldr (fun c n => if c.isWhitespace then n + 1 else n) 0 = 3
                                                                                                                                                                                                                                                                                                                                                                                    • "coffee tea water".foldr (fun c s => c.push s) "" = "retaw dna aet eeffoc"
                                                                                                                                                                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                                                                                                                                                                                      @[irreducible, specialize #[]]
                                                                                                                                                                                                                                                                                                                                                                                      def String.anyAux (s : String) (stopPos : Pos.Raw) (p : CharBool) (i : Pos.Raw) :
                                                                                                                                                                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                                                                                                                                                                                        @[inline]
                                                                                                                                                                                                                                                                                                                                                                                        def String.any (s : String) (p : CharBool) :

                                                                                                                                                                                                                                                                                                                                                                                        Checks whether there is a character in a string for which the Boolean predicate p returns true.

                                                                                                                                                                                                                                                                                                                                                                                        Short-circuits at the first character for which p returns true.

                                                                                                                                                                                                                                                                                                                                                                                        Examples:

                                                                                                                                                                                                                                                                                                                                                                                        • "brown".any (·.isLetter) = true
                                                                                                                                                                                                                                                                                                                                                                                        • "brown".any (·.isWhitespace) = false
                                                                                                                                                                                                                                                                                                                                                                                        • "brown and orange".any (·.isLetter) = true
                                                                                                                                                                                                                                                                                                                                                                                        • "".any (fun _ => false) = false
                                                                                                                                                                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                                                                                                                                                                                                          @[export lean_string_any]
                                                                                                                                                                                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                                                                                                                                                                                                            @[inline]
                                                                                                                                                                                                                                                                                                                                                                                            def String.all (s : String) (p : CharBool) :

                                                                                                                                                                                                                                                                                                                                                                                            Checks whether the Boolean predicate p returns true for every character in a string.

                                                                                                                                                                                                                                                                                                                                                                                            Short-circuits at the first character for which p returns false.

                                                                                                                                                                                                                                                                                                                                                                                            Examples:

                                                                                                                                                                                                                                                                                                                                                                                            • "brown".all (·.isLetter) = true
                                                                                                                                                                                                                                                                                                                                                                                            • "brown and orange".all (·.isLetter) = false
                                                                                                                                                                                                                                                                                                                                                                                            • "".all (fun _ => false) = true
                                                                                                                                                                                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                                                                                                                                                                                            Instances For
                                                                                                                                                                                                                                                                                                                                                                                              @[inline]
                                                                                                                                                                                                                                                                                                                                                                                              def String.contains (s : String) (c : Char) :

                                                                                                                                                                                                                                                                                                                                                                                              Checks whether a string contains the specified character.

                                                                                                                                                                                                                                                                                                                                                                                              Examples:

                                                                                                                                                                                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                                                                                                                                                                                @[export lean_string_contains]
                                                                                                                                                                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                                                                                                                                                                                                  theorem String.Pos.Raw.utf8SetAux_of_gt (c' : Char) (cs : List Char) {i p : Raw} :
                                                                                                                                                                                                                                                                                                                                                                                                  i > putf8SetAux c' cs i p = cs
                                                                                                                                                                                                                                                                                                                                                                                                  theorem String.set_next_add (s : String) (i : Pos.Raw) (c : Char) (b₁ b₂ : Nat) (h : (Pos.Raw.next s i).byteIdx + b₁ = s.endPos.byteIdx + b₂) :
                                                                                                                                                                                                                                                                                                                                                                                                  (Pos.Raw.next (Pos.Raw.set s i c) i).byteIdx + b₁ = (Pos.Raw.set s i c).endPos.byteIdx + b₂
                                                                                                                                                                                                                                                                                                                                                                                                  @[irreducible, specialize #[]]
                                                                                                                                                                                                                                                                                                                                                                                                  def String.mapAux (f : CharChar) (i : Pos.Raw) (s : String) :
                                                                                                                                                                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                                                                                                                                                                  • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                                                                                                                                                                                                    @[inline]
                                                                                                                                                                                                                                                                                                                                                                                                    def String.map (f : CharChar) (s : String) :

                                                                                                                                                                                                                                                                                                                                                                                                    Applies the function f to every character in a string, returning a string that contains the resulting characters.

                                                                                                                                                                                                                                                                                                                                                                                                    Examples:

                                                                                                                                                                                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                                                                                                                                                                                                      @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                      Checks whether the string can be interpreted as the decimal representation of a natural number.

                                                                                                                                                                                                                                                                                                                                                                                                      A string can be interpreted as a decimal natural number if it is not empty and all the characters in it are digits.

                                                                                                                                                                                                                                                                                                                                                                                                      Use String.toNat? or String.toNat! to convert such a string to a natural number.

                                                                                                                                                                                                                                                                                                                                                                                                      Examples:

                                                                                                                                                                                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                                                                                                                                                                                      Instances For

                                                                                                                                                                                                                                                                                                                                                                                                        Interprets a string as the decimal representation of a natural number, returning it. Returns none if the string does not contain a decimal natural number.

                                                                                                                                                                                                                                                                                                                                                                                                        A string can be interpreted as a decimal natural number if it is not empty and all the characters in it are digits.

                                                                                                                                                                                                                                                                                                                                                                                                        Use String.isNat to check whether String.toNat? would return some. String.toNat! is an alternative that panics instead of returning none when the string is not a natural number.

                                                                                                                                                                                                                                                                                                                                                                                                        Examples:

                                                                                                                                                                                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                                                                                                                                                                                                                          def String.Pos.Raw.substrEq (s1 : String) (pos1 : Raw) (s2 : String) (pos2 : Raw) (sz : Nat) :

                                                                                                                                                                                                                                                                                                                                                                                                          Checks whether substrings of two strings are equal. Substrings are indicated by their starting positions and a size in UTF-8 bytes. Returns false if the indicated substring does not exist in either string.

                                                                                                                                                                                                                                                                                                                                                                                                          This is a legacy function. The recommended alternative is to construct slices representing the strings to be compared and use the BEq instance of String.Slice.

                                                                                                                                                                                                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                                                                                                                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                                                                                                                                                                                                                            @[deprecated String.Pos.Raw.substrEq (since := "2025-10-10")]
                                                                                                                                                                                                                                                                                                                                                                                                            def String.substrEq (s1 : String) (pos1 : Pos.Raw) (s2 : String) (pos2 : Pos.Raw) (sz : Nat) :
                                                                                                                                                                                                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                                                                                                                                                                                                            Instances For

                                                                                                                                                                                                                                                                                                                                                                                                              Checks whether the first string (p) is a prefix of the second (s).

                                                                                                                                                                                                                                                                                                                                                                                                              String.startsWith is a version that takes the potential prefix after the string.

                                                                                                                                                                                                                                                                                                                                                                                                              Examples:

                                                                                                                                                                                                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                @[export lean_string_isprefixof]
                                                                                                                                                                                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                  def String.replace (s pattern replacement : String) :

                                                                                                                                                                                                                                                                                                                                                                                                                  In the string s, replaces all occurrences of pattern with replacement.

                                                                                                                                                                                                                                                                                                                                                                                                                  Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                  • "red green blue".replace "e" "" = "rd grn blu"
                                                                                                                                                                                                                                                                                                                                                                                                                  • "red green blue".replace "ee" "E" = "red grEn blue"
                                                                                                                                                                                                                                                                                                                                                                                                                  • "red green blue".replace "e" "E" = "rEd grEEn bluE"
                                                                                                                                                                                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                                                                                                                                                                                  Instances For

                                                                                                                                                                                                                                                                                                                                                                                                                    Returns the position of the beginning of the line that contains the position pos.

                                                                                                                                                                                                                                                                                                                                                                                                                    Lines are ended by '\n', and the returned position is either 0 : String.Pos or immediately after a '\n' character.

                                                                                                                                                                                                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                      @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                      Checks whether a substring is empty.

                                                                                                                                                                                                                                                                                                                                                                                                                      A substring is empty if its start and end positions are the same.

                                                                                                                                                                                                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                        @[export lean_substring_isempty]
                                                                                                                                                                                                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                          @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                          Copies the region of the underlying string pointed to by a substring into a fresh string.

                                                                                                                                                                                                                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                            @[export lean_substring_tostring]
                                                                                                                                                                                                                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                                                                                                                                                                                                                            Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                              @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                              Returns an iterator into the underlying string, at the substring's starting position. The ending position is discarded, so the iterator alone cannot be used to determine whether its current position is within the original substring.

                                                                                                                                                                                                                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                Returns the character at the given position in the substring.

                                                                                                                                                                                                                                                                                                                                                                                                                                The position is relative to the substring, rather than the underlying string, and no bounds checking is performed with respect to the substring's end position. If the relative position is not a valid position in the underlying string, the fallback value (default : Char), which is 'A', is returned. Does not panic.

                                                                                                                                                                                                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                  @[export lean_substring_get]
                                                                                                                                                                                                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                    @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                    Returns the next position in a substring after the given position. If the position is at the end of the substring, it is returned unmodified.

                                                                                                                                                                                                                                                                                                                                                                                                                                    Both the input position and the returned position are interpreted relative to the substring's start position, not the underlying string.

                                                                                                                                                                                                                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                      @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                      Returns the previous position in a substring, just prior to the given position. If the position is at the beginning of the substring, it is returned unmodified.

                                                                                                                                                                                                                                                                                                                                                                                                                                      Both the input position and the returned position are interpreted relative to the substring's start position, not the underlying string.

                                                                                                                                                                                                                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                      Instances For

                                                                                                                                                                                                                                                                                                                                                                                                                                        Returns the position that's the specified number of characters forward from the given position in a substring. If the end position of the substring is reached, it is returned.

                                                                                                                                                                                                                                                                                                                                                                                                                                        Both the input position and the returned position are interpreted relative to the substring's start position, not the underlying string.

                                                                                                                                                                                                                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                        Instances For

                                                                                                                                                                                                                                                                                                                                                                                                                                          Returns the position that's the specified number of characters prior to the given position in a substring. If the start position of the substring is reached, it is returned.

                                                                                                                                                                                                                                                                                                                                                                                                                                          Both the input position and the returned position are interpreted relative to the substring's start position, not the underlying string.

                                                                                                                                                                                                                                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                            @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                            Returns the first character in the substring.

                                                                                                                                                                                                                                                                                                                                                                                                                                            If the substring is empty, but the substring's start position is a valid position in the underlying string, then the character at the start position is returned. If the substring's start position is not a valid position in the string, the fallback value (default : Char), which is 'A', is returned. Does not panic.

                                                                                                                                                                                                                                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                            Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                              @[export lean_substring_front]
                                                                                                                                                                                                                                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                Returns the substring-relative position of the first occurrence of c in s, or s.bsize if c doesn't occur.

                                                                                                                                                                                                                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                  Removes the specified number of characters (Unicode code points) from the beginning of a substring by advancing its start position.

                                                                                                                                                                                                                                                                                                                                                                                                                                                  If the substring's end position is reached, the start position is not advanced past it.

                                                                                                                                                                                                                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                  • { str := s, startPos := b, stopPos := e }.drop x✝ = { str := s, startPos := ({ str := s, startPos := b, stopPos := e }.nextn x✝ 0).offsetBy b, stopPos := e }
                                                                                                                                                                                                                                                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                    @[export lean_substring_drop]
                                                                                                                                                                                                                                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                      @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                      Removes the specified number of characters (Unicode code points) from the end of a substring by moving its end position towards its start position.

                                                                                                                                                                                                                                                                                                                                                                                                                                                      If the substring's start position is reached, the end position is not retracted past it.

                                                                                                                                                                                                                                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                        @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                        Retains only the specified number of characters (Unicode code points) at the beginning of a substring, by moving its end position towards its start position.

                                                                                                                                                                                                                                                                                                                                                                                                                                                        If the substring's start position is reached, the end position is not retracted past it.

                                                                                                                                                                                                                                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                        • { str := s, startPos := b, stopPos := e }.take x✝ = { str := s, startPos := b, stopPos := ({ str := s, startPos := b, stopPos := e }.nextn x✝ 0).offsetBy b }
                                                                                                                                                                                                                                                                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                          @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                          Retains only the specified number of characters (Unicode code points) at the end of a substring, by moving its start position towards its end position.

                                                                                                                                                                                                                                                                                                                                                                                                                                                          If the substring's end position is reached, the start position is not advanced past it.

                                                                                                                                                                                                                                                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                            @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                            Checks whether a position in a substring is precisely equal to its ending position.

                                                                                                                                                                                                                                                                                                                                                                                                                                                            The position is understood relative to the substring's starting position, rather than the underlying string's starting position.

                                                                                                                                                                                                                                                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                            Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                              @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                              Returns the region of the substring delimited by the provided start and stop positions, as a substring. The positions are interpreted with respect to the substring's start position, rather than the underlying string.

                                                                                                                                                                                                                                                                                                                                                                                                                                                              If the resulting substring is empty, then the resulting substring is a substring of the empty string "". Otherwise, the underlying string is that of the input substring with the beginning and end positions adjusted.

                                                                                                                                                                                                                                                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                              • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                def Substring.splitOn (s : Substring) (sep : String := " ") :

                                                                                                                                                                                                                                                                                                                                                                                                                                                                Splits a substring s on occurrences of the separator string sep. The default separator is " ".

                                                                                                                                                                                                                                                                                                                                                                                                                                                                When sep is empty, the result is [s]. When sep occurs in overlapping patterns, the first match is taken. There will always be exactly n+1 elements in the returned list if there were n non-overlapping matches of sep in the string. The separators are not included in the returned substrings, which are all substrings of s's string.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[inline]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                  def Substring.foldl {α : Type u} (f : αCharα) (init : α) (s : Substring) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                  α

                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Folds a function over a substring from the left, accumulating a value starting with init. The accumulated value is combined with each character in order, using f.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                    @[inline]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                    def Substring.foldr {α : Type u} (f : Charαα) (init : α) (s : Substring) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                    α

                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Folds a function over a substring from the right, accumulating a value starting with init. The accumulated value is combined with each character in reverse order, using f.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                      @[inline]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                      def Substring.any (s : Substring) (p : CharBool) :

                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Checks whether the Boolean predicate p returns true for any character in a substring.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Short-circuits at the first character for which p returns true.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                      • { str := s_1, startPos := b, stopPos := e }.any p = s_1.anyAux e p b
                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        @[inline]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        def Substring.all (s : Substring) (p : CharBool) :

                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Checks whether the Boolean predicate p returns true for every character in a substring.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Short-circuits at the first character for which p returns false.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                          @[export lean_substring_all]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                            @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Checks whether a substring contains the specified character.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                              @[irreducible, specialize #[]]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                              • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Retains only the longest prefix of a substring in which a Boolean predicate returns true for all characters by moving the substring's end position towards its start position.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[export lean_substring_takewhile]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Removes the longest prefix of a substring in which a Boolean predicate returns true for all characters by moving the substring's start position. The start position is moved to the position of the first character for which the predicate returns false, or to the substring's end position if the predicate always returns true.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      @[irreducible, specialize #[]]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Retains only the longest suffix of a substring in which a Boolean predicate returns true for all characters by moving the substring's start position towards its end position.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Removes the longest suffix of a substring in which a Boolean predicate returns true for all characters by moving the substring's end position. The end position is moved just after the position of the last character for which the predicate returns false, or to the substring's start position if the predicate always returns true.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Removes leading whitespace from a substring by moving its start position to the first non-whitespace character, or to its end position if there is no non-whitespace character.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            “Whitespace” is defined as characters for which Char.isWhitespace returns true.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Removes trailing whitespace from a substring by moving its end position to the last non-whitespace character, or to its start position if there is no non-whitespace character.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              “Whitespace” is defined as characters for which Char.isWhitespace returns true.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Removes leading and trailing whitespace from a substring by first moving its start position to the first non-whitespace character, and then moving its end position to the last non-whitespace character.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                If the substring consists only of whitespace, then the resulting substring's start position is moved to its end position.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                “Whitespace” is defined as characters for which Char.isWhitespace returns true.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                • " red green blue ".toSubstring.trim.toString = "red green blue"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                • " red green blue ".toSubstring.trim.startPos = ⟨1⟩
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                • " red green blue ".toSubstring.trim.stopPos = ⟨15⟩
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                • " ".toSubstring.trim.startPos = ⟨5⟩
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Checks whether the substring can be interpreted as the decimal representation of a natural number.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  A substring can be interpreted as a decimal natural number if it is not empty and all the characters in it are digits.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Use Substring.toNat? to convert such a substring to a natural number.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Instances For

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Checks whether the substring can be interpreted as the decimal representation of a natural number, returning the number if it can.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    A substring can be interpreted as a decimal natural number if it is not empty and all the characters in it are digits.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Use Substring.isNat to check whether the substring is such a substring.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Instances For

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Given a Substring, returns another one which has valid endpoints and represents the same substring according to Substring.toString. (Note, the substring may still be inverted, i.e. beginning greater than end.)

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      • One or more equations did not get rendered due to their size.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        def Substring.beq (ss1 ss2 : Substring) :

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Checks whether two substrings represent equal strings. Usually accessed via the == operator.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Two substrings do not need to have the same underlying string or the same start and end positions; instead, they are equal if they contain the same sequence of characters.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          @[export lean_substring_beq]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Instances For

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Checks whether two substrings have the same position and content.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            The two substrings do not need to have the same underlying string for this check to succeed.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Instances For

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Returns the longest common prefix of two substrings.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              The returned substring uses the same underlying string as s.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Instances For

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Returns the longest common suffix of two substrings.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                The returned substring uses the same underlying string as s.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Instances For

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  If pre is a prefix of s, returns the remainder. Returns none otherwise.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  The substring pre is a prefix of s if there exists a t : Substring such that s.toString = pre.toString ++ t.toString. If so, the result is the substring of s without the prefix.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Instances For

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    If suff is a suffix of s, returns the remainder. Returns none otherwise.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    The substring suff is a suffix of s if there exists a t : Substring such that s.toString = t.toString ++ suff.toString. If so, the result the substring of s without the suffix.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      @[inline]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      def String.drop (s : String) (n : Nat) :

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Removes the specified number of characters (Unicode code points) from the start of the string.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      If n is greater than s.length, returns "".

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      • "red green blue".drop 4 = "green blue"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      • "red green blue".drop 10 = "blue"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      • "red green blue".drop 50 = ""
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        @[export lean_string_drop]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Removes the specified number of characters (Unicode code points) from the end of the string.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          If n is greater than s.length, returns "".

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            @[export lean_string_dropright]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              @[inline]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              def String.take (s : String) (n : Nat) :

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Creates a new string that contains the first n characters (Unicode code points) of s.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              If n is greater than s.length, returns s.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              • "red green blue".take 3 = "red"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              • "red green blue".take 1 = "r"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              • "red green blue".take 0 = ""
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              • "red green blue".take 100 = "red green blue"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Creates a new string that contains the last n characters (Unicode code points) of s.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                If n is greater than s.length, returns s.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[inline]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  def String.takeWhile (s : String) (p : CharBool) :

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Creates a new string that contains the longest prefix of s in which p returns true for all characters.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  • "red green blue".takeWhile (·.isLetter) = "red"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  • "red green blue".takeWhile (· == 'r') = "r"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  • "red green blue".takeWhile (· != 'n') = "red gree"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  • "red green blue".takeWhile (fun _ => true) = "red green blue"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    @[inline]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    def String.dropWhile (s : String) (p : CharBool) :

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Creates a new string by removing the longest prefix from s in which p returns true for all characters.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    • "red green blue".dropWhile (·.isLetter) = " green blue"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    • "red green blue".dropWhile (· == 'r') = "ed green blue"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    • "red green blue".dropWhile (· != 'n') = "n blue"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    • "red green blue".dropWhile (fun _ => true) = ""
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Creates a new string that contains the longest suffix of s in which p returns true for all characters.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Creates a new string by removing the longest suffix from s in which p returns true for all characters.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Checks whether the first string (s) begins with the second (pre).

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          String.isPrefix is a version that takes the potential prefix before the string.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            @[inline]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            def String.endsWith (s post : String) :

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Checks whether the first string (s) ends with the second (post).

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Removes trailing whitespace from a string.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              “Whitespace” is defined as characters for which Char.isWhitespace returns true.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Removes leading whitespace from a string.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                “Whitespace” is defined as characters for which Char.isWhitespace returns true.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Removes leading and trailing whitespace from a string.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  “Whitespace” is defined as characters for which Char.isWhitespace returns true.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  • "abc".trim = "abc"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  • " abc".trim = "abc"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  • "abc \t ".trim = "abc"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  • " abc ".trim = "abc"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  • "abc\ndef\n".trim = "abc\ndef"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    @[export lean_string_trim]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      @[inline]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      def String.Pos.Raw.nextWhile (s : String) (p : CharBool) (i : Raw) :

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Repeatedly increments a position in a string, as if by String.next, while the predicate p returns true for the character at the position. Stops incrementing at the end of the string or when p returns false for the current character.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        @[reducible, inline, deprecated String.Pos.Raw.nextWhile (since := "2025-10-10")]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        abbrev String.nextWhile (s : String) (p : CharBool) (i : Pos.Raw) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          @[export lean_string_nextwhile]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            @[inline]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            def String.Pos.Raw.nextUntil (s : String) (p : CharBool) (i : Raw) :

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Repeatedly increments a position in a string, as if by String.next, while the predicate p returns false for the character at the position. Stops incrementing at the end of the string or when p returns true for the current character.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              @[deprecated String.Pos.Raw.nextUntil (since := "2025-10-10")]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              def String.nextUntil (s : String) (p : CharBool) (i : Pos.Raw) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Replaces each character in s with the result of applying Char.toUpper to it.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Char.toUpper has no effect on characters outside of the range 'a''z'.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Replaces each character in s with the result of applying Char.toLower to it.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Char.toLower has no effect on characters outside of the range 'A''Z'.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Replaces the first character in s with the result of applying Char.toUpper to it. Returns the empty string if the string is empty.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Char.toUpper has no effect on characters outside of the range 'a''z'.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      @[export lean_string_capitalize]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        @[inline]

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Replaces the first character in s with the result of applying Char.toLower to it. Returns the empty string if the string is empty.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Char.toLower has no effect on characters outside of the range 'A''Z'.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Instances For

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          If pre is a prefix of s, returns the remainder. Returns none otherwise.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          The string pre is a prefix of s if there exists a t : String such that s = pre ++ t. If so, the result is some t.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Use String.stripPrefix to return the string unchanged when pre is not a prefix.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Instances For

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            If suff is a suffix of s, returns the remainder. Returns none otherwise.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            The string suff is a suffix of s if there exists a t : String such that s = t ++ suff. If so, the result is some t.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Use String.stripSuffix to return the string unchanged when suff is not a suffix.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Instances For

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              If pre is a prefix of s, returns the remainder. Returns s unmodified otherwise.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              The string pre is a prefix of s if there exists a t : String such that s = pre ++ t. If so, the result is t. Otherwise, it is s.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Use String.dropPrefix? to return none when pre is not a prefix.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Instances For

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                If suff is a suffix of s, returns the remainder. Returns s unmodified otherwise.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                The string suff is a suffix of s if there exists a t : String such that s = t ++ suff. If so, the result is t. Otherwise, it is s.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Use String.dropSuffix? to return none when suff is not a suffix.

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Examples:

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  theorem String.ext {s₁ s₂ : String} (h : s₁.data = s₂.data) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  s₁ = s₂
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  theorem String.ext_iff {s₁ s₂ : String} :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  s₁ = s₂ s₁.data = s₂.data
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[simp]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[simp]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[simp]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[simp]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[simp]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[simp]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  theorem String.data_push {s : String} (c : Char) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  (s.push c).data = s.data ++ [c]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[simp]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  theorem String.length_push {s : String} (c : Char) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  (s.push c).length = s.length + 1
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[simp]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  theorem String.length_pushn {s : String} (c : Char) (n : Nat) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  (s.pushn c n).length = s.length + n
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[simp]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  theorem String.length_append (s t : String) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  (s ++ t).length = s.length + t.length
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  theorem String.lt_iff {s t : String} :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  s < t s.data < t.data
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  theorem String.Pos.Raw.byteIdx_mk (n : Nat) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  { byteIdx := n }.byteIdx = n
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[simp]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[simp]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  theorem String.Pos.Raw.mk_byteIdx (p : Raw) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  { byteIdx := p.byteIdx } = p
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[deprecated String.Pos.Raw.byteIdx_offsetBy (since := "2025-10-08")]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  theorem String.Pos.Raw.add_byteIdx {p₁ p₂ : Raw} :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  (p₂.offsetBy p₁).byteIdx = p₁.byteIdx + p₂.byteIdx
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[deprecated String.Pos.Raw.byteIdx_offsetBy (since := "2025-10-08")]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  theorem String.Pos.Raw.add_eq {p₁ p₂ : Raw} :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  p₂.offsetBy p₁ = { byteIdx := p₁.byteIdx + p₂.byteIdx }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[deprecated String.Pos.Raw.byteIdx_unoffsetBy (since := "2025-10-08")]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  theorem String.Pos.Raw.sub_byteIdx (p₁ p₂ : Raw) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  (p₁.unoffsetBy p₂).byteIdx = p₁.byteIdx - p₂.byteIdx
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[deprecated String.Pos.Raw.byteIdx_add_char (since := "2025-10-10")]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  theorem String.Pos.Raw.add_char_eq (p : Raw) (c : Char) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  p + c = { byteIdx := p.byteIdx + c.utf8Size }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[deprecated String.Pos.Raw.add_char_eq (since := "2025-10-10")]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  theorem String.Pos.Raw.addChar_eq (p : Raw) (c : Char) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  p + c = { byteIdx := p.byteIdx + c.utf8Size }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[deprecated String.Pos.Raw.byteIdx_zero_add_char (since := "2025-10-10")]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  theorem String.Pos.Raw.zero_add_char_eq (c : Char) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  0 + c = { byteIdx := c.utf8Size }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[deprecated String.Pos.Raw.zero_add_char_eq (since := "2025-10-10")]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  theorem String.Pos.Raw.zero_addChar_eq (c : Char) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  0 + c = { byteIdx := c.utf8Size }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  theorem String.Pos.Raw.add_char_right_comm (p : Raw) (c₁ c₂ : Char) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  p + c₁ + c₂ = p + c₂ + c₁
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[deprecated String.Pos.Raw.add_char_right_comm (since := "2025-10-10")]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  theorem String.Pos.Raw.addChar_right_comm (p : Raw) (c₁ c₂ : Char) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  p + c₁ + c₂ = p + c₂ + c₁
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  theorem String.Pos.Raw.ne_of_gt {i₁ i₂ : Raw} (h : i₁ < i₂) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  i₂ i₁
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[deprecated String.Pos.Raw.byteIdx_add_string (since := "2025-10-10")]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  @[reducible, inline, deprecated String.Pos.Raw.byteIdx_addString (since := "2025-03-18")]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    theorem String.Pos.Raw.addString_eq (p : Raw) (s : String) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    p + s = { byteIdx := p.byteIdx + s.utf8ByteSize }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    @[deprecated String.Pos.Raw.byteIdx_zero_add_string (since := "2025-10-10")]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    @[reducible, inline, deprecated String.Pos.Raw.byteIdx_zero_addString (since := "2025-03-18")]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Equations
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Instances For
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      @[deprecated String.Pos.Raw.zero_add_string_eq (since := "2025-10-10")]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      theorem String.Pos.Raw.zero_addString_eq (s : String) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      0 + s = { byteIdx := s.utf8ByteSize }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      @[simp]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      theorem String.Pos.Raw.mk_le_mk {i₁ i₂ : Nat} :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      { byteIdx := i₁ } { byteIdx := i₂ } i₁ i₂
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      @[simp]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      theorem String.Pos.Raw.mk_lt_mk {i₁ i₂ : Nat} :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      { byteIdx := i₁ } < { byteIdx := i₂ } i₁ < i₂
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      @[simp]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      theorem String.Pos.Raw.get!_eq_get (s : String) (p : Raw) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      get! s p = get s p
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      @[simp]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      theorem String.Pos.Raw.get'_eq (s : String) (p : Raw) (h : ¬atEnd s p = true) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      get' s p h = get s p
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      @[simp]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      theorem String.Pos.Raw.next'_eq (s : String) (p : Raw) (h : ¬atEnd s p = true) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      next' s p h = next s p
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      @[deprecated String.Pos.Raw.get!_eq_get (since := "2025-10-14")]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      @[deprecated String.Pos.Raw.lt_next (since := "2025-10-10")]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      theorem String.lt_next' (s : String) (p : Pos.Raw) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      @[simp]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      theorem String.Pos.Raw.prev_zero (s : String) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      prev s 0 = 0
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      @[deprecated String.Pos.Raw.prev_zero (since := "2025-10-10")]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      theorem String.prev_zero (s : String) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      @[deprecated String.Pos.Raw.get'_eq (since := "2025-10-14")]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      theorem String.get'_eq (s : String) (p : Pos.Raw) (h : ¬Pos.Raw.atEnd s p = true) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      @[deprecated String.Pos.Raw.next'_eq (since := "2025-10-14")]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      @[simp]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      @[simp]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      theorem Substring.prev_zero (s : Substring) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      s.prev 0 = 0
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      @[simp]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      theorem Substring.prevn_zero (s : Substring) (n : Nat) :
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      s.prevn n 0 = 0